summaryrefslogtreecommitdiff
path: root/src/d_iwad.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/d_iwad.c')
-rw-r--r--src/d_iwad.c361
1 files changed, 59 insertions, 302 deletions
diff --git a/src/d_iwad.c b/src/d_iwad.c
index ea0d29d0..ab1dd823 100644
--- a/src/d_iwad.c
+++ b/src/d_iwad.c
@@ -29,9 +29,9 @@
#include <ctype.h>
#include <string.h>
-#include "deh_main.h"
-#include "doomdef.h"
-#include "doomstat.h"
+#include "deh_str.h"
+#include "doomkeys.h"
+#include "d_iwad.h"
#include "i_system.h"
#include "m_argv.h"
#include "m_config.h"
@@ -39,6 +39,19 @@
#include "w_wad.h"
#include "z_zone.h"
+static iwad_t iwads[] =
+{
+ { "doom2.wad", doom2, commercial, "Doom II" },
+ { "plutonia.wad", pack_plut, commercial, "Final Doom: Plutonia Experiment" },
+ { "tnt.wad", pack_tnt, commercial, "Final Doom: TNT: Evilution" },
+ { "doom.wad", doom, retail, "Doom" },
+ { "doom1.wad", doom, shareware, "Doom Shareware" },
+ { "chex.wad", doom, shareware, "Chex Quest" },
+ { "heretic.wad", heretic, retail, "Heretic" },
+ { "heretic1.wad", heretic, shareware, "Heretic Shareware" },
+ { "hexen.wad", hexen, commercial, "Hexen" },
+};
+
// Array of locations to search for IWAD files
//
// "128 IWAD search directories should be enough for anybody".
@@ -157,6 +170,8 @@ static char *steam_install_subdirs[] =
"steamapps\\common\\doom 2\\base",
"steamapps\\common\\final doom\\base",
"steamapps\\common\\ultimate doom\\base",
+ "steamapps\\common\\hexen\\base",
+ "steamapps\\common\\heretic shadow of the serpent riders\\base"
};
static char *GetRegistryString(registry_value_t *reg_val)
@@ -315,29 +330,6 @@ static void CheckDOSDefaults(void)
#endif
-static struct
-{
- char *name;
- GameMission_t mission;
-} iwads[] = {
- {"doom2.wad", doom2},
- {"plutonia.wad", pack_plut},
- {"tnt.wad", pack_tnt},
- {"doom.wad", doom},
- {"doom1.wad", doom},
- {"chex.wad", doom},
-};
-
-// Hack for chex quest mode
-
-static void CheckChex(char *iwad_name)
-{
- if (!strcmp(iwad_name, "chex.wad"))
- {
- gameversion = exe_chex;
- }
-}
-
// Returns true if the specified path is a path to a file
// of the specified name.
@@ -397,19 +389,23 @@ static char *CheckDirectoryHasIWAD(char *dir, char *iwadname)
// Search a directory to try to find an IWAD
// Returns the location of the IWAD if found, otherwise NULL.
-static char *SearchDirectoryForIWAD(char *dir)
+static char *SearchDirectoryForIWAD(char *dir, int mask, GameMission_t *mission)
{
char *filename;
size_t i;
for (i=0; i<arrlen(iwads); ++i)
{
+ if (((1 << iwads[i].mission) & mask) == 0)
+ {
+ continue;
+ }
+
filename = CheckDirectoryHasIWAD(dir, DEH_String(iwads[i].name));
if (filename != NULL)
{
- CheckChex(iwads[i].name);
- gamemission = iwads[i].mission;
+ *mission = iwads[i].mission;
return filename;
}
@@ -421,16 +417,22 @@ static char *SearchDirectoryForIWAD(char *dir)
// When given an IWAD with the '-iwad' parameter,
// attempt to identify it by its name.
-static void IdentifyIWADByName(char *name)
+static GameMission_t IdentifyIWADByName(char *name, int mask)
{
size_t i;
+ GameMission_t mission;
+
+ mission = none;
- gamemission = none;
-
for (i=0; i<arrlen(iwads); ++i)
{
char *iwadname;
+ // Only use supported missions:
+
+ if (((1 << iwads[i].mission) & mask) == 0)
+ continue;
+
iwadname = DEH_String(iwads[i].name);
if (strlen(name) < strlen(iwadname))
@@ -441,16 +443,17 @@ static void IdentifyIWADByName(char *name)
if (!strcasecmp(name + strlen(name) - strlen(iwadname),
iwadname))
{
- CheckChex(iwads[i].name);
- gamemission = iwads[i].mission;
+ mission = iwads[i].mission;
break;
}
}
+
+ return mission;
}
//
// Add directories from the list in the DOOMWADPATH environment variable.
-//
+//
static void AddDoomWadPath(void)
{
@@ -637,7 +640,7 @@ char *D_TryFindWADByName(char *filename)
// should be executed (notably loading PWADs).
//
-char *D_FindIWAD(void)
+char *D_FindIWAD(int mask, GameMission_t *mission)
{
char *result;
char *iwadfile;
@@ -667,7 +670,7 @@ char *D_FindIWAD(void)
I_Error("IWAD file '%s' not found!", iwadfile);
}
- IdentifyIWADByName(result);
+ *mission = IdentifyIWADByName(result, mask);
}
else
{
@@ -679,293 +682,47 @@ char *D_FindIWAD(void)
for (i=0; result == NULL && i<num_iwad_dirs; ++i)
{
- result = SearchDirectoryForIWAD(iwad_dirs[i]);
+ result = SearchDirectoryForIWAD(iwad_dirs[i], mask, mission);
}
}
return result;
}
-//
-// Get the IWAD name used for savegames.
-//
+// Find all IWADs in the IWAD search path matching the given mask.
-static char *SaveGameIWADName(void)
+iwad_t **D_FindAllIWADs(int mask)
{
- size_t i;
+ iwad_t **result;
+ int result_len;
+ char *filename;
+ int i;
- // Chex quest hack
+ result = malloc(sizeof(iwad_t *) * (arrlen(iwads) + 1));
+ result_len = 0;
- if (gameversion == exe_chex)
- {
- return "chex.wad";
- }
-
- // Find what subdirectory to use for savegames
- //
- // They should be stored in something like
- // ~/.chocolate-doom/savegames/doom.wad/
- //
- // The directory depends on the IWAD, so that savegames for
- // different IWADs are kept separate.
- //
- // Note that we match on gamemission rather than on IWAD name.
- // This ensures that doom1.wad and doom.wad saves are stored
- // in the same place.
+ // Try to find all IWADs
for (i=0; i<arrlen(iwads); ++i)
{
- if (gamemission == iwads[i].mission)
+ if (((1 << iwads[i].mission) & mask) == 0)
{
- return iwads[i].name;
- }
- }
-
- return NULL;
-}
-//
-// SetSaveGameDir
-//
-// Chooses the directory used to store saved games.
-//
-
-void D_SetSaveGameDir(void)
-{
- char *iwad_name;
-
- if (!strcmp(configdir, ""))
- {
- // Use the current directory, just like configdir.
-
- savegamedir = strdup("");
- }
- else
- {
- // Directory for savegames
-
- iwad_name = SaveGameIWADName();
-
- if (iwad_name == NULL)
- {
- iwad_name = "unknown.wad";
- }
-
- savegamedir = Z_Malloc(strlen(configdir) + 30, PU_STATIC, 0);
- sprintf(savegamedir, "%ssavegames%c", configdir,
- DIR_SEPARATOR);
-
- M_MakeDirectory(savegamedir);
-
- sprintf(savegamedir + strlen(savegamedir), "%s%c",
- iwad_name, DIR_SEPARATOR);
-
- M_MakeDirectory(savegamedir);
- }
-}
-
-// Strings for dehacked replacements of the startup banner
-//
-// These are from the original source: some of them are perhaps
-// not used in any dehacked patches
-
-static char *banners[] =
-{
- // doom1.wad
- " "
- "DOOM Shareware Startup v%i.%i"
- " ",
- // doom.wad
- " "
- "DOOM Registered Startup v%i.%i"
- " ",
- // Registered DOOM uses this
- " "
- "DOOM System Startup v%i.%i"
- " ",
- // doom.wad (Ultimate DOOM)
- " "
- "The Ultimate DOOM Startup v%i.%i"
- " ",
- // doom2.wad
- " "
- "DOOM 2: Hell on Earth v%i.%i"
- " ",
- // tnt.wad
- " "
- "DOOM 2: TNT - Evilution v%i.%i"
- " ",
- // plutonia.wad
- " "
- "DOOM 2: Plutonia Experiment v%i.%i"
- " ",
-};
-
-//
-// Get game name: if the startup banner has been replaced, use that.
-// Otherwise, use the name given
-//
-
-static char *GetGameName(char *gamename)
-{
- size_t i;
- char *deh_sub;
-
- for (i=0; i<arrlen(banners); ++i)
- {
- // Has the banner been replaced?
-
- deh_sub = DEH_String(banners[i]);
-
- if (deh_sub != banners[i])
- {
- // Has been replaced
- // We need to expand via printf to include the Doom version
- // number
- // We also need to cut off spaces to get the basic name
-
- gamename = Z_Malloc(strlen(deh_sub) + 10, PU_STATIC, 0);
- sprintf(gamename, deh_sub, DOOM_VERSION / 100, DOOM_VERSION % 100);
-
- while (gamename[0] != '\0' && isspace(gamename[0]))
- strcpy(gamename, gamename+1);
-
- while (gamename[0] != '\0' && isspace(gamename[strlen(gamename)-1]))
- gamename[strlen(gamename) - 1] = '\0';
-
- return gamename;
- }
- }
-
- return gamename;
-}
-
-
-//
-// Find out what version of Doom is playing.
-//
-
-void D_IdentifyVersion(void)
-{
- // gamemission is set up by the D_FindIWAD function. But if
- // we specify '-iwad', we have to identify using
- // IdentifyIWADByName. However, if the iwad does not match
- // any known IWAD name, we may have a dilemma. Try to
- // identify by its contents.
-
- if (gamemission == none)
- {
- unsigned int i;
-
- for (i=0; i<numlumps; ++i)
- {
- if (!strncasecmp(lumpinfo[i].name, "MAP01", 8))
- {
- gamemission = doom2;
- break;
- }
- else if (!strncasecmp(lumpinfo[i].name, "E1M1", 8))
- {
- gamemission = doom;
- break;
- }
- }
-
- if (gamemission == none)
- {
- // Still no idea. I don't think this is going to work.
-
- I_Error("Unknown or invalid IWAD file.");
- }
- }
-
- // Make sure gamemode is set up correctly
-
- if (gamemission == doom)
- {
- // Doom 1. But which version?
-
- if (W_CheckNumForName("E4M1") > 0)
- {
- // Ultimate Doom
-
- gamemode = retail;
- }
- else if (W_CheckNumForName("E3M1") > 0)
- {
- gamemode = registered;
- }
- else
- {
- gamemode = shareware;
+ continue;
}
- }
- else
- {
- // Doom 2 of some kind.
-
- gamemode = commercial;
- }
-}
-
-// Set the gamedescription string
-void D_SetGameDescription(void)
-{
- gamedescription = "Unknown";
-
- if (gamemission == doom)
- {
- // Doom 1. But which version?
+ filename = D_FindWADByName(iwads[i].name);
- if (gamemode == retail)
- {
- // Ultimate Doom
-
- gamedescription = GetGameName("The Ultimate DOOM");
- }
- else if (gamemode == registered)
- {
- gamedescription = GetGameName("DOOM Registered");
- }
- else if (gamemode == shareware)
+ if (filename != NULL)
{
- gamedescription = GetGameName("DOOM Shareware");
+ result[result_len] = &iwads[i];
+ ++result_len;
}
}
- else
- {
- // Doom 2 of some kind. But which mission?
-
- if (gamemission == doom2)
- gamedescription = GetGameName("DOOM 2: Hell on Earth");
- else if (gamemission == pack_plut)
- gamedescription = GetGameName("DOOM 2: Plutonia Experiment");
- else if (gamemission == pack_tnt)
- gamedescription = GetGameName("DOOM 2: TNT - Evilution");
- }
-}
-// Clever hack: Setup can invoke Doom to determine which IWADs are installed.
-// Doom searches install paths and exits with the return code being a
-// bitmask of the installed IWAD files.
+ // End of list
-void D_FindInstalledIWADs(void)
-{
- unsigned int i;
- int result;
-
- BuildIWADDirList();
+ result[result_len] = NULL;
- result = 0;
-
- for (i=0; i<arrlen(iwads); ++i)
- {
- if (D_FindWADByName(iwads[i].name) != NULL)
- {
- result |= 1 << i;
- }
- }
-
- exit(result);
+ return result;
}