Server: load singleplayer.dat or deathmatch.dat when appropriate in RuleC_Init

This commit is contained in:
Marco Cawthorne 2025-01-02 19:02:26 -08:00
parent d41b90c081
commit 5cf55b8271
5 changed files with 18 additions and 32 deletions

View file

@ -3,13 +3,3 @@ Game_Worldspawn(void)
{ {
} }
void
Game_InitRules(void)
{
if (cvar("sv_playerslots") == 1 || cvar("coop") == 1) {
g_grMode = ncGameRules::InitFromProgs("progs/singleplayer.dat");
} else {
g_grMode = ncGameRules::InitFromProgs("progs/deathmatch.dat");
}
}

View file

@ -121,7 +121,7 @@ public:
/** Returns the title of the gamemode running. */ /** Returns the title of the gamemode running. */
virtual string Title(void); virtual string Title(void);
nonvirtual ncGameRules InitFromProgs(string pathToProgs); nonvirtual ncGameRules CreateRules(void);
/* spectator */ /* spectator */
/* /*
@ -139,6 +139,7 @@ private:
/* our currently running mode */ /* our currently running mode */
ncGameRules g_grMode; ncGameRules g_grMode;
var float g_ruleCProgs; var float g_ruleCProgs;
var string g_ruleCName;
#define CGameRules ncGameRules #define CGameRules ncGameRules
#define RULEMAP(x, y, z) x.y = externvalue(g_ruleCProgs, z); if (!x.y) { x.y = ncGameRules::y; } #define RULEMAP(x, y, z) x.y = externvalue(g_ruleCProgs, z); if (!x.y) { x.y = ncGameRules::y; }

View file

@ -418,27 +418,17 @@ ncGameRules::ChatMessageTeam(ncClient cl, string strMessage)
string string
ncGameRules::Title(void) ncGameRules::Title(void)
{ {
string gameType = cvars.GetString("g_gametype"); if (STRING_SET(g_ruleCName)) {
return g_ruleCName;
if (STRING_SET(gameType)) {
return gameType;
} }
return "Default"; return "Default";
} }
ncGameRules ncGameRules
ncGameRules::InitFromProgs(string pathToProgs) ncGameRules::CreateRules(void)
{ {
ncGameRules newRule; ncGameRules newRule = spawn(ncGameRules);
/* No progs .dat, exit out */
if (fileExists(pathToProgs) == false) {
NSError("Progs at %S does not exist.", pathToProgs);
return (__NULL__);
}
newRule = spawn(ncGameRules);
if (g_ruleCProgs) { if (g_ruleCProgs) {
RULEMAP(newRule, ClientCommand, "CodeCallback_ClientCommand") RULEMAP(newRule, ClientCommand, "CodeCallback_ClientCommand")
@ -460,5 +450,6 @@ ncGameRules::InitFromProgs(string pathToProgs)
RULEMAP(newRule, Title, "CodeCallback_Title") RULEMAP(newRule, Title, "CodeCallback_Title")
} }
serverinfo.SetString("mode", newRule.Title());
return (newRule); return (newRule);
} }

View file

@ -402,10 +402,7 @@ initents(void)
BodyQue_Init(); BodyQue_Init();
if (!g_grMode) { g_grMode = ncGameRules::CreateRules();
Game_InitRules();
serverinfo.SetString("mode", g_grMode.Title());
}
Game_Worldspawn(); Game_Worldspawn();
Decals_Init(); Decals_Init();

View file

@ -51,7 +51,15 @@ void
RuleC_Init(void) RuleC_Init(void)
{ {
string gameType = cvars.GetString("g_gametype"); string gameType = cvars.GetString("g_gametype");
string pathToProgs = strcat("progs/", gameType, ".dat"); string pathToProgs;
if (!STRING_SET(gameType)) {
bool isCoop = cvars.GetBool("coop");
bool isSingle = (cvars.GetInteger("sv_playerslots") <= 1) ? (true) : (false);
g_ruleCName = gameType = (isSingle || isCoop) == (true) ? "singleplayer" : "deathmatch";
}
pathToProgs = strcat("progs/", gameType, ".dat");
/* No progs .dat, exit out */ /* No progs .dat, exit out */
if (fileExists(pathToProgs) == false) { if (fileExists(pathToProgs) == false) {
@ -72,8 +80,7 @@ RuleC_Init(void)
} else { } else {
NSError("%S does not have a main function.", pathToProgs); NSError("%S does not have a main function.", pathToProgs);
} }
} }
} }
void void