mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-25 19:20:46 +00:00
67ed6945fd
NAM and Napalm can now share their con, def, and rts files if the one for their respective game is not present because the con and rts files are identical. Also, decapitalize two string literals missed in r2540. git-svn-id: https://svn.eduke32.com/eduke32@2726 1a8010ca-5511-0410-912e-c29ae57300e0
309 lines
7.3 KiB
C
309 lines
7.3 KiB
C
//
|
|
// Common non-engine code/data for EDuke32 and Mapster32
|
|
//
|
|
|
|
#include "compat.h"
|
|
#include "build.h"
|
|
#include "scriptfile.h"
|
|
#include "cache1d.h"
|
|
#include "kplib.h"
|
|
#include "baselayer.h"
|
|
|
|
#include "common.h"
|
|
#include "common_game.h"
|
|
|
|
int32_t g_gameType = 0;
|
|
|
|
// grp/con/def handling
|
|
|
|
char *defaultgamegrp[GAMECOUNT] = { "DUKE3D.GRP", "NAM.GRP", "NAPALM.GRP", "WW2GI.GRP" };
|
|
char *defaultdeffilename[GAMECOUNT] = { "duke3d.def", "nam.def", "napalm.def", "ww2gi.def" };
|
|
char *defaultconfilename = "GAME.CON";
|
|
char *defaultgameconfilename[GAMECOUNT] = { "EDUKE.CON", "NAM.CON", "NAPALM.CON", "WW2GI.CON" };
|
|
|
|
// g_grpNamePtr can ONLY point to a malloc'd block (length BMAX_PATH)
|
|
char *g_grpNamePtr = NULL;
|
|
// g_defNamePtr can ONLY point to a malloc'd block (length BMAX_PATH)
|
|
char *g_defNamePtr = NULL;
|
|
// g_scriptNamePtr can ONLY point to a malloc'd block (length BMAX_PATH)
|
|
char *g_scriptNamePtr = NULL;
|
|
|
|
|
|
void clearGrpNamePtr(void)
|
|
{
|
|
if (g_grpNamePtr != NULL)
|
|
Bfree(g_grpNamePtr);
|
|
// g_grpNamePtr assumed to be assigned to right after
|
|
}
|
|
|
|
void clearDefNamePtr(void)
|
|
{
|
|
if (g_defNamePtr != NULL)
|
|
Bfree(g_defNamePtr);
|
|
// g_defNamePtr assumed to be assigned to right after
|
|
}
|
|
|
|
void clearScriptNamePtr(void)
|
|
{
|
|
if (g_scriptNamePtr != NULL)
|
|
Bfree(g_scriptNamePtr);
|
|
// g_scriptNamePtr assumed to be assigned to right after
|
|
}
|
|
|
|
char *G_DefaultGrpFile(void)
|
|
{
|
|
if (DUKE)
|
|
return defaultgamegrp[GAME_DUKE];
|
|
// order is important for the following three because GAMEFLAG_NAM overlaps all
|
|
else if (NAPALM)
|
|
return defaultgamegrp[GAME_NAPALM];
|
|
else if (WW2GI)
|
|
return defaultgamegrp[GAME_WW2GI];
|
|
else if (NAM)
|
|
return defaultgamegrp[GAME_NAM];
|
|
|
|
return defaultgamegrp[0];
|
|
}
|
|
char *G_DefaultDefFile(void)
|
|
{
|
|
if (DUKE)
|
|
return defaultdeffilename[GAME_DUKE];
|
|
else if (WW2GI)
|
|
return defaultdeffilename[GAME_WW2GI];
|
|
else if (NAPALM)
|
|
{
|
|
if ((kopen4load(defaultdeffilename[GAME_NAPALM],0) < 0) && (kopen4load(defaultdeffilename[GAME_NAM],0) >= 0))
|
|
return defaultdeffilename[GAME_NAM]; // NAM/Napalm Sharing
|
|
else
|
|
return defaultdeffilename[GAME_NAPALM];
|
|
}
|
|
else if (NAM)
|
|
{
|
|
if ((kopen4load(defaultdeffilename[GAME_NAM],0) < 0) && (kopen4load(defaultdeffilename[GAME_NAPALM],0) >= 0))
|
|
return defaultdeffilename[GAME_NAPALM]; // NAM/Napalm Sharing
|
|
else
|
|
return defaultdeffilename[GAME_NAM];
|
|
}
|
|
|
|
return defaultdeffilename[0];
|
|
}
|
|
char *G_DefaultConFile(void)
|
|
{
|
|
if (DUKE && (kopen4load(defaultgameconfilename[GAME_DUKE],0) >= 0))
|
|
return defaultgameconfilename[GAME_DUKE];
|
|
else if (WW2GI && (kopen4load(defaultgameconfilename[GAME_WW2GI],0) >= 0))
|
|
return defaultgameconfilename[GAME_WW2GI];
|
|
else if (NAPALM)
|
|
{
|
|
if (kopen4load(defaultgameconfilename[GAME_NAPALM],0) < 0)
|
|
{
|
|
if (kopen4load(defaultgameconfilename[GAME_NAM],0) >= 0)
|
|
return defaultgameconfilename[GAME_NAM]; // NAM/Napalm Sharing
|
|
}
|
|
else
|
|
return defaultgameconfilename[GAME_NAPALM];
|
|
}
|
|
else if (NAM)
|
|
{
|
|
if (kopen4load(defaultgameconfilename[GAME_NAM],0) < 0)
|
|
{
|
|
if (kopen4load(defaultgameconfilename[GAME_NAPALM],0) >= 0)
|
|
return defaultgameconfilename[GAME_NAPALM]; // NAM/Napalm Sharing
|
|
}
|
|
else
|
|
return defaultgameconfilename[GAME_NAM];
|
|
}
|
|
|
|
return defaultconfilename;
|
|
}
|
|
|
|
char *G_GrpFile(void)
|
|
{
|
|
if (g_grpNamePtr == NULL)
|
|
return G_DefaultGrpFile();
|
|
else
|
|
return g_grpNamePtr;
|
|
}
|
|
char *G_DefFile(void)
|
|
{
|
|
if (g_defNamePtr == NULL)
|
|
return G_DefaultDefFile();
|
|
else
|
|
return g_defNamePtr;
|
|
}
|
|
char *G_ConFile(void)
|
|
{
|
|
if (g_scriptNamePtr == NULL)
|
|
return G_DefaultConFile();
|
|
else
|
|
return g_scriptNamePtr;
|
|
}
|
|
|
|
//////////
|
|
|
|
struct strllist *CommandPaths, *CommandGrps;
|
|
|
|
void G_AddGroup(const char *buffer)
|
|
{
|
|
char buf[BMAX_PATH];
|
|
|
|
struct strllist *s = Bcalloc(1,sizeof(struct strllist));
|
|
|
|
Bstrcpy(buf, buffer);
|
|
|
|
if (Bstrchr(buf,'.') == 0)
|
|
Bstrcat(buf,".grp");
|
|
|
|
s->str = Bstrdup(buf);
|
|
|
|
if (CommandGrps)
|
|
{
|
|
struct strllist *t;
|
|
for (t = CommandGrps; t->next; t=t->next) ;
|
|
t->next = s;
|
|
return;
|
|
}
|
|
CommandGrps = s;
|
|
}
|
|
|
|
void G_AddPath(const char *buffer)
|
|
{
|
|
struct strllist *s = Bcalloc(1,sizeof(struct strllist));
|
|
s->str = Bstrdup(buffer);
|
|
|
|
if (CommandPaths)
|
|
{
|
|
struct strllist *t;
|
|
for (t = CommandPaths; t->next; t=t->next) ;
|
|
t->next = s;
|
|
return;
|
|
}
|
|
CommandPaths = s;
|
|
}
|
|
|
|
//////////
|
|
|
|
int32_t getatoken(scriptfile *sf, const tokenlist *tl, int32_t ntokens)
|
|
{
|
|
char *tok;
|
|
int32_t i;
|
|
|
|
if (!sf) return T_ERROR;
|
|
tok = scriptfile_gettoken(sf);
|
|
if (!tok) return T_EOF;
|
|
|
|
for (i=ntokens-1; i>=0; i--)
|
|
{
|
|
if (!Bstrcasecmp(tok, tl[i].text))
|
|
return tl[i].tokenid;
|
|
}
|
|
return T_ERROR;
|
|
}
|
|
|
|
//////////
|
|
|
|
// checks from path and in ZIPs, returns 1 if NOT found
|
|
int32_t check_file_exist(const char *fn)
|
|
{
|
|
int32_t opsm = pathsearchmode;
|
|
char *tfn;
|
|
|
|
pathsearchmode = 1;
|
|
if (findfrompath(fn,&tfn) < 0)
|
|
{
|
|
char buf[BMAX_PATH];
|
|
|
|
Bstrcpy(buf,fn);
|
|
kzfindfilestart(buf);
|
|
if (!kzfindfile(buf))
|
|
{
|
|
initprintf("Error: file \"%s\" does not exist\n",fn);
|
|
pathsearchmode = opsm;
|
|
return 1;
|
|
}
|
|
}
|
|
else Bfree(tfn);
|
|
pathsearchmode = opsm;
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
//// FILE NAME / DIRECTORY LISTS ////
|
|
void fnlist_clearnames(fnlist_t *fnl)
|
|
{
|
|
klistfree(fnl->finddirs);
|
|
klistfree(fnl->findfiles);
|
|
|
|
fnl->finddirs = fnl->findfiles = NULL;
|
|
fnl->numfiles = fnl->numdirs = 0;
|
|
}
|
|
|
|
// dirflags, fileflags:
|
|
// -1 means "don't get dirs/files",
|
|
// otherwise ORed to flags for respective klistpath
|
|
int32_t fnlist_getnames(fnlist_t *fnl, const char *dirname, const char *pattern,
|
|
int32_t dirflags, int32_t fileflags)
|
|
{
|
|
CACHE1D_FIND_REC *r;
|
|
|
|
fnlist_clearnames(fnl);
|
|
|
|
if (dirflags != -1)
|
|
fnl->finddirs = klistpath(dirname, "*", CACHE1D_FIND_DIR|dirflags);
|
|
if (fileflags != -1)
|
|
fnl->findfiles = klistpath(dirname, pattern, CACHE1D_FIND_FILE|fileflags);
|
|
|
|
for (r=fnl->finddirs; r; r=r->next)
|
|
fnl->numdirs++;
|
|
for (r=fnl->findfiles; r; r=r->next)
|
|
fnl->numfiles++;
|
|
|
|
return(0);
|
|
}
|
|
|
|
|
|
// loads all group (grp, zip, pk3) files in the given directory
|
|
void G_LoadGroupsInDir(const char *dirname)
|
|
{
|
|
static const char *extensions[3] = { "*.grp", "*.zip", "*.pk3" };
|
|
|
|
char buf[BMAX_PATH];
|
|
int32_t i;
|
|
|
|
fnlist_t fnlist = FNLIST_INITIALIZER;
|
|
|
|
for (i=0; i<3; i++)
|
|
{
|
|
CACHE1D_FIND_REC *rec;
|
|
|
|
fnlist_getnames(&fnlist, dirname, extensions[i], -1, 0);
|
|
|
|
for (rec=fnlist.findfiles; rec; rec=rec->next)
|
|
{
|
|
Bsnprintf(buf, sizeof(buf), "%s/%s", dirname, rec->name);
|
|
initprintf("Using group file \"%s\".\n", buf);
|
|
initgroupfile(buf);
|
|
}
|
|
|
|
fnlist_clearnames(&fnlist);
|
|
}
|
|
}
|
|
|
|
void G_DoAutoload(const char *dirname)
|
|
{
|
|
char buf[BMAX_PATH];
|
|
|
|
Bsnprintf(buf, sizeof(buf), "autoload/%s", dirname);
|
|
G_LoadGroupsInDir(buf);
|
|
}
|
|
|
|
////
|
|
|
|
// returns a buffer of size BMAX_PATH
|
|
char *dup_filename(const char *fn)
|
|
{
|
|
char *buf = Bmalloc(BMAX_PATH);
|
|
|
|
return Bstrncpyz(buf, fn, BMAX_PATH);
|
|
}
|