| 1 |
// |
| 2 |
// Copyright(C) 2023 by Ryan Krafnick |
| 3 |
// |
| 4 |
// This program is free software; you can redistribute it and/or |
| 5 |
// modify it under the terms of the GNU General Public License |
| 6 |
// as published by the Free Software Foundation; either version 2 |
| 7 |
// of the License, or (at your option) any later version. |
| 8 |
// |
| 9 |
// This program is distributed in the hope that it will be useful, |
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
// GNU General Public License for more details. |
| 13 |
// |
| 14 |
// DESCRIPTION: |
| 15 |
// DSDA Episode |
| 16 |
// |
| 17 |
|
| 18 |
#include "doomstat.h" |
| 19 |
#include "lprintf.h" |
| 20 |
#include "w_wad.h" |
| 21 |
#include "z_zone.h" |
| 22 |
|
| 23 |
#include "dsda/mapinfo.h" |
| 24 |
#include "dsda/mapinfo/doom/parser.h" |
| 25 |
|
| 26 |
#include "episode.h" |
| 27 |
|
| 28 |
dsda_episode_t* episodes; |
| 29 |
size_t num_episodes; |
| 30 |
|
| 31 |
static void dsda_DetermineEpisodeMap(dsda_episode_t* episode) { |
| 32 |
if (!dsda_NameToMap(episode->map_lump, &episode->start_episode, &episode->start_map)) |
| 33 |
I_Error("Cannot evaluate start map for episode %s", episode->name ? episode->name : |
| 34 |
episode->pic_name ? episode->pic_name : |
| 35 |
"UNKNOWN"); |
| 36 |
} |
| 37 |
|
| 38 |
void dsda_AddOriginalEpisodes(void) { |
| 39 |
if (heretic) { |
| 40 |
dsda_AddEpisode("e1m1", "CITY OF THE DAMNED", NULL, 'c', true); |
| 41 |
dsda_AddEpisode("e2m1", "HELL'S MAW", NULL, 'h', true); |
| 42 |
dsda_AddEpisode("e3m1", "THE DOME OF D'SPARIL", NULL, 't', true); |
| 43 |
|
| 44 |
if (gamemode == retail) { |
| 45 |
dsda_AddEpisode("e4m1", "THE OSSUARY", NULL, 't', true); |
| 46 |
dsda_AddEpisode("e5m1", "THE STAGNANT DEMESNE", NULL, 't', true); |
| 47 |
} |
| 48 |
} |
| 49 |
else if (hexen) { |
| 50 |
dsda_AddEpisode("map01", "FIGHTER", NULL, 'f', true); |
| 51 |
dsda_AddEpisode("map01", "CLERIC", NULL, 'c', true); |
| 52 |
dsda_AddEpisode("map01", "MAGE", NULL, 'm', true); |
| 53 |
} |
| 54 |
else if (gamemode != commercial && gamemission != tc_chex) { |
| 55 |
dsda_AddEpisode("e1m1", NULL, "M_EPI1", 'k', true); |
| 56 |
dsda_AddEpisode("e2m1", NULL, "M_EPI2", 't', true); |
| 57 |
dsda_AddEpisode("e3m1", NULL, "M_EPI3", 'i', true); |
| 58 |
|
| 59 |
if (gamemode == retail && (compatibility_level >= ultdoom_compatibility || W_PWADLumpNameExists("E4M1"))) |
| 60 |
dsda_AddEpisode("e4m1", NULL, "M_EPI4", 't', true); |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
void dsda_AddCustomEpisodes(void) { |
| 65 |
int i; |
| 66 |
|
| 67 |
if (!doom_mapinfo.loaded) |
| 68 |
return; |
| 69 |
|
| 70 |
// TODO: umapinfo edits episodes while parsing the lump, |
| 71 |
// so we add the originals before loading info lumps, |
| 72 |
// but we want to validate existence in the scope of mapinfo, |
| 73 |
// so we start from scratch again... |
| 74 |
dsda_ClearEpisodes(); |
| 75 |
|
| 76 |
if (!doom_mapinfo.episodes_cleared) |
| 77 |
dsda_AddOriginalEpisodes(); |
| 78 |
|
| 79 |
for (i = 0; i < doom_mapinfo.num_episodes; ++i) |
| 80 |
dsda_AddEpisode( |
| 81 |
doom_mapinfo.episodes[i].map_lump, |
| 82 |
doom_mapinfo.episodes[i].name, |
| 83 |
doom_mapinfo.episodes[i].pic_name, |
| 84 |
doom_mapinfo.episodes[i].key, |
| 85 |
false |
| 86 |
); |
| 87 |
} |
| 88 |
|
| 89 |
void dsda_ClearEpisodes(void) { |
| 90 |
int i; |
| 91 |
|
| 92 |
for (i = 0; i < num_episodes; ++i) { |
| 93 |
Z_Free(episodes[i].map_lump); |
| 94 |
Z_Free(episodes[i].name); |
| 95 |
Z_Free(episodes[i].pic_name); |
| 96 |
} |
| 97 |
|
| 98 |
Z_Free(episodes); |
| 99 |
episodes = NULL; |
| 100 |
num_episodes = 0; |
| 101 |
} |
| 102 |
|
| 103 |
void dsda_AddEpisode(const char* map_lump, const char* name, |
| 104 |
const char* pic_name, char key, dboolean vanilla) { |
| 105 |
++num_episodes; |
| 106 |
episodes = Z_Realloc(episodes, num_episodes * sizeof(*episodes)); |
| 107 |
|
| 108 |
episodes[num_episodes - 1].map_lump = map_lump ? Z_Strdup(map_lump) : NULL; |
| 109 |
episodes[num_episodes - 1].name = name ? Z_Strdup(name) : NULL; |
| 110 |
episodes[num_episodes - 1].pic_name = pic_name ? Z_Strdup(pic_name) : NULL; |
| 111 |
episodes[num_episodes - 1].key = key; |
| 112 |
episodes[num_episodes - 1].vanilla = vanilla; |
| 113 |
|
| 114 |
dsda_DetermineEpisodeMap(&episodes[num_episodes - 1]); |
| 115 |
} |