From 76024896b02780253ba0cb65e941a430d39303ca Mon Sep 17 00:00:00 2001 From: Andrei Drexler Date: Fri, 10 Jun 2022 19:26:14 +0300 Subject: [PATCH] Don't spawn monsters when starting map with nomonsters 1 --- Quake/host_cmd.c | 13 +++++++++++++ Quake/pr_edict.c | 23 ++++++++++++++++++++++- Quake/server.h | 1 + Quake/sv_main.c | 3 +++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Quake/host_cmd.c b/Quake/host_cmd.c index b57347ff7..1472887e6 100644 --- a/Quake/host_cmd.c +++ b/Quake/host_cmd.c @@ -27,6 +27,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #endif extern cvar_t pausable; +extern cvar_t nomonsters; int current_skill; @@ -1043,6 +1044,12 @@ static void Host_Savegame_f (void) return; } + if (sv.nomonsters) + { + Con_Printf ("Can't save when using \"nomonsters\".\n"); + return; + } + if (cl.intermission) { Con_Printf ("Can't save in intermission.\n"); @@ -1149,6 +1156,12 @@ static void Host_Loadgame_f (void) return; } + if (nomonsters.value) + { + Con_Warning ("\"%s\" disabled automatically.\n", nomonsters.name); + Cvar_SetValueQuick (&nomonsters, 0.f); + } + cls.demonum = -1; // stop demo loop in case this fails q_snprintf (name, sizeof(name), "%s/%s", com_gamedir, Cmd_Argv(1)); diff --git a/Quake/pr_edict.c b/Quake/pr_edict.c index 4888482af..ada808c38 100644 --- a/Quake/pr_edict.c +++ b/Quake/pr_edict.c @@ -993,6 +993,7 @@ to call ED_CallSpawnFunctions () to let the objects initialize themselves. */ void ED_LoadFromFile (const char *data) { + const char *classname; dfunction_t *func; edict_t *ent = NULL; int inhibit = 0; @@ -1045,8 +1046,16 @@ void ED_LoadFromFile (const char *data) continue; } + classname = PR_GetString (ent->v.classname); + if (sv.nomonsters && !Q_strncmp (classname, "monster_", 8)) + { + ED_Free (ent); + inhibit++; + continue; + } + // look for the spawn function - func = ED_FindFunction ( PR_GetString(ent->v.classname) ); + func = ED_FindFunction (classname); if (!func) { @@ -1262,6 +1271,17 @@ void PR_LoadProgs (void) pr_effects_mask = PR_FindSupportedEffects (); } +/* +=============== +ED_Nomonsters_f +=============== +*/ +static void ED_Nomonsters_f (cvar_t *cvar) +{ + if (cvar->value) + Con_Warning ("\"%s\" can break gameplay.\n", cvar->name); +} + /* =============== @@ -1275,6 +1295,7 @@ void PR_Init (void) Cmd_AddCommand ("edictcount", ED_Count); Cmd_AddCommand ("profile", PR_Profile_f); Cvar_RegisterVariable (&nomonsters); + Cvar_SetCallback (&nomonsters, ED_Nomonsters_f); Cvar_RegisterVariable (&gamecfg); Cvar_RegisterVariable (&scratch1); Cvar_RegisterVariable (&scratch2); diff --git a/Quake/server.h b/Quake/server.h index 2842a2758..001ee4ba6 100644 --- a/Quake/server.h +++ b/Quake/server.h @@ -46,6 +46,7 @@ typedef struct qboolean paused; qboolean loadgame; // handle connections specially + qboolean nomonsters; // server started with 'nomonsters' cvar active double time; diff --git a/Quake/sv_main.c b/Quake/sv_main.c index 4212f1cca..100151a10 100644 --- a/Quake/sv_main.c +++ b/Quake/sv_main.c @@ -33,6 +33,8 @@ int sv_protocol = PROTOCOL_FITZQUAKE; //johnfitz extern qboolean pr_alpha_supported; //johnfitz extern int pr_effects_mask; +extern cvar_t nomonsters; + //============================================================================ /* @@ -1537,6 +1539,7 @@ void SV_SpawnServer (const char *server) sv.state = ss_loading; sv.paused = false; + sv.nomonsters = (nomonsters.value != 0.f); sv.time = 1.0;