Skip to content

Commit

Permalink
Extract episode management
Browse files Browse the repository at this point in the history
  • Loading branch information
kraflab committed Aug 2, 2023
1 parent 8199caa commit 874ff95
Show file tree
Hide file tree
Showing 9 changed files with 252 additions and 200 deletions.
2 changes: 2 additions & 0 deletions prboom2/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ set(COMMON_SRC
dsda/destructible.h
dsda/endoom.c
dsda/endoom.h
dsda/episode.c
dsda/episode.h
dsda/excmd.c
dsda/excmd.h
dsda/exdemo.c
Expand Down
91 changes: 91 additions & 0 deletions prboom2/src/dsda/episode.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//
// Copyright(C) 2023 by Ryan Krafnick
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// DESCRIPTION:
// DSDA Episode
//

#include "doomstat.h"
#include "lprintf.h"
#include "z_zone.h"

#include "dsda/mapinfo.h"

#include "episode.h"

dsda_episode_t* episodes;
size_t num_episodes;

static void dsda_DetermineEpisodeMap(dsda_episode_t* episode) {
if (!dsda_NameToMap(episode->map_lump, &episode->start_episode, &episode->start_map))
I_Error("Cannot evaluate start map for episode %s", episode->name ? episode->name :
episode->pic_name ? episode->pic_name :
"UNKNOWN");
}

void dsda_AddOriginalEpisodes(void) {
if (heretic) {
dsda_AddEpisode("e1m1", "CITY OF THE DAMNED", NULL, 'c', true);
dsda_AddEpisode("e2m1", "HELL'S MAW", NULL, 'h', true);
dsda_AddEpisode("e3m1", "THE DOME OF D'SPARIL", NULL, 't', true);

if (gamemode == retail) {
dsda_AddEpisode("e4m1", "THE OSSUARY", NULL, 't', true);
dsda_AddEpisode("e5m1", "THE STAGNANT DEMESNE", NULL, 't', true);
}
}
else if (hexen) {
dsda_AddEpisode("map01", "FIGHTER", NULL, 'f', true);
dsda_AddEpisode("map01", "CLERIC", NULL, 'c', true);
dsda_AddEpisode("map01", "MAGE", NULL, 'm', true);
}
else if (gamemode != commercial && gamemission != chex) {
dsda_AddEpisode("e1m1", NULL, "M_EPI1", 'k', true);
dsda_AddEpisode("e2m1", NULL, "M_EPI2", 't', true);
dsda_AddEpisode("e3m1", NULL, "M_EPI3", 'i', true);

if (gamemode == retail)
dsda_AddEpisode("e4m1", NULL, "M_EPI4", 't', true);
}
}

void dsda_AddCustomEpisodes(void) {
}

void dsda_ClearEpisodes(void) {
int i;

for (i = 0; i < num_episodes; ++i) {
Z_Free(episodes[i].map_lump);
Z_Free(episodes[i].name);
Z_Free(episodes[i].pic_name);
}

Z_Free(episodes);
episodes = NULL;
num_episodes = 0;
}

void dsda_AddEpisode(const char* map_lump, const char* name,
const char* pic_name, char key, dboolean vanilla) {
++num_episodes;
episodes = Z_Realloc(episodes, num_episodes * sizeof(*episodes));

episodes[num_episodes - 1].map_lump = map_lump ? Z_Strdup(map_lump) : NULL;
episodes[num_episodes - 1].name = name ? Z_Strdup(name) : NULL;
episodes[num_episodes - 1].pic_name = pic_name ? Z_Strdup(pic_name) : NULL;
episodes[num_episodes - 1].key = key;
episodes[num_episodes - 1].vanilla = vanilla;

dsda_DetermineEpisodeMap(&episodes[num_episodes - 1]);
}
42 changes: 42 additions & 0 deletions prboom2/src/dsda/episode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// Copyright(C) 2023 by Ryan Krafnick
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// DESCRIPTION:
// DSDA Episode
//

#ifndef __DSDA_EPISODE__
#define __DSDA_EPISODE__

#include "doomtype.h"

typedef struct {
char* map_lump;
char* name;
char* pic_name;
char key;
dboolean vanilla;
int start_map;
int start_episode;
} dsda_episode_t;

extern dsda_episode_t* episodes;
extern size_t num_episodes;

void dsda_AddOriginalEpisodes(void);
void dsda_AddCustomEpisodes(void);
void dsda_ClearEpisodes(void);
void dsda_AddEpisode(const char* map_lump, const char* name,
const char* pic_name, char key, dboolean vanilla);

#endif
5 changes: 5 additions & 0 deletions prboom2/src/dsda/mapinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "m_misc.h"

#include "dsda/args.h"
#include "dsda/episode.h"
#include "dsda/map_format.h"
#include "dsda/mapinfo/doom.h"
#include "dsda/mapinfo/hexen.h"
Expand Down Expand Up @@ -495,10 +496,14 @@ void dsda_PrepareFinale(int* behaviour) {
}

void dsda_LoadMapInfo(void) {
dsda_AddOriginalEpisodes();

dsda_DoomLoadMapInfo();
dsda_HexenLoadMapInfo();
dsda_ULoadMapInfo();
dsda_LegacyLoadMapInfo();

dsda_AddCustomEpisodes();
}

const char* dsda_ExitPic(void) {
Expand Down
3 changes: 1 addition & 2 deletions prboom2/src/g_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -2947,8 +2947,7 @@ void G_InitNew(int skill, int episode, int map, dboolean prepare)
if (episode < 1)
episode = 1;

// Disable all sanity checks if there are custom episode definitions. They do not make sense in this case.
if (!EpiCustom && !W_LumpNameExists(dsda_MapLumpName(episode, map)))
if (!W_LumpNameExists(dsda_MapLumpName(episode, map)))
{
if (heretic)
{
Expand Down
31 changes: 0 additions & 31 deletions prboom2/src/heretic/mn_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ extern menu_t OptionsDef;
extern menu_t SoundDef;
extern menu_t LoadDef;
extern menu_t SaveDef;
extern menuitem_t EpisodeMenu[];
extern menuitem_t SoundMenu[];
extern short EpiMenuMap[];
extern short EpiMenuEpi[];

void M_DrawThermo(int x, int y, int thermWidth, int thermDot);

Expand Down Expand Up @@ -101,29 +98,10 @@ void MN_Init(void)
SkillDef.x = 38;
SkillDef.y = 30;

EpisodeMenu[0].alttext = "CITY OF THE DAMNED";
EpisodeMenu[1].alttext = "HELL'S MAW";
EpisodeMenu[2].alttext = "THE DOME OF D'SPARIL";
EpisodeMenu[3].alttext = "THE OSSUARY";
EpisodeMenu[4].alttext = "THE STAGNANT DEMESNE";

if (gamemode == retail)
{
EpiMenuEpi[3] = 4;
EpiMenuEpi[4] = 5;
EpiMenuMap[3] = 1;
EpiMenuMap[4] = 1;
EpiDef.numitems = 5;
EpiDef.y -= ITEM_HEIGHT;
}
else
{
EpiMenuEpi[3] = -1;
EpiMenuEpi[4] = -1;
EpiMenuMap[3] = -1;
EpiMenuMap[4] = -1;
EpiDef.numitems = 3;
}
}
else
{
Expand All @@ -132,15 +110,6 @@ void MN_Init(void)

SkillDef.x = 120;
SkillDef.y = 44;

EpisodeMenu[0].alttext = "FIGHTER";
EpisodeMenu[1].alttext = "CLERIC";
EpisodeMenu[2].alttext = "MAGE";

EpiMenuEpi[1] = 1;
EpiMenuEpi[2] = 1;

EpiDef.numitems = 3;
}

SoundMenu[0].alttext = "SFX VOLUME";
Expand Down
2 changes: 0 additions & 2 deletions prboom2/src/m_cheat.c
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,6 @@ static void cheat_behold()
dsda_AddMessage(s_STSTR_BEHOLD);
}

extern int EpiCustom;

// 'clev' change-level cheat
static void cheat_clev(char buf[3])
{
Expand Down
Loading

0 comments on commit 874ff95

Please sign in to comment.