From fecf5616cc78f873ec2146c57e8b83da9f173a4c Mon Sep 17 00:00:00 2001 From: Lactozilla Date: Sat, 5 Aug 2023 22:15:38 -0300 Subject: [PATCH] Add gametype parameter to G_SetCustomExitVars and G_ExitLevel --- src/d_netcmd.c | 12 ++++++------ src/doomstat.h | 1 + src/g_game.c | 30 +++++++++++++++++++++++------- src/lua_baselib.c | 2 ++ 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index b16781504..d278643bd 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -2102,11 +2102,13 @@ static void Got_Mapcmd(UINT8 **cp, INT32 playernum) lastgametype = gametype; gametype = READUINT8(*cp); - G_SetGametype(gametype); // I fear putting that macro as an argument if (gametype < 0 || gametype >= gametypecount) gametype = lastgametype; - else if (gametype != lastgametype) + else + G_SetGametype(gametype); + + if (gametype != lastgametype) D_GameTypeChanged(lastgametype); // emulate consvar_t behavior for gametype skipprecutscene = ((flags & (1<<2)) != 0); @@ -4264,10 +4266,8 @@ void D_GameTypeChanged(INT32 lastgametype) } else if (!multiplayer && !netgame) { - G_SetGametype(GT_COOP); - // These shouldn't matter anymore - //CV_Set(&cv_itemrespawntime, cv_itemrespawntime.defaultvalue); - //CV_SetValue(&cv_itemrespawn, 0); + // Allow setting gametypes other than Co-Op in singleplayer + // G_SetGametype(GT_COOP); } // reset timelimit and pointlimit in race/coop, prevent stupid cheats diff --git a/src/doomstat.h b/src/doomstat.h index ad2cd87bd..18a97c670 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -245,6 +245,7 @@ extern textprompt_t *textprompts[MAX_PROMPTS]; // For the Custom Exit linedef. extern INT16 nextmapoverride; extern UINT8 skipstats; +extern INT16 nextgametype; extern UINT32 ssspheres; // Total # of spheres in a level diff --git a/src/g_game.c b/src/g_game.c index 429dfbc06..e57402683 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -151,6 +151,7 @@ textprompt_t *textprompts[MAX_PROMPTS]; INT16 nextmapoverride; UINT8 skipstats; +INT16 nextgametype = -1; // Pointers to each CTF flag mobj_t *flagmobjs[MAXTEAMS]; @@ -3618,7 +3619,7 @@ void G_UpdateTeamSelection(void) } // -// Sets a new gametype, also setting gametype rules accordingly. +// Sets a new gametype. // void G_SetGametype(INT16 gtype) { @@ -4263,6 +4264,13 @@ static void G_DoCompleted(void) nextmap = 1100-1; // No infinite loop for you } + INT16 gametype_to_use; + + if (nextgametype >= 0 && nextgametype < gametypecount) + gametype_to_use = nextgametype; + else + gametype_to_use = gametype; + // If nextmap is actually going to get used, make sure it points to // a map of the proper gametype -- skip levels that don't support // the current gametype. (Helps avoid playing boss levels in Race, @@ -4271,8 +4279,8 @@ static void G_DoCompleted(void) { if (nextmap >= 0 && nextmap < NUMMAPS) { - register INT16 cm = nextmap; - UINT32 tolflag = G_TOLFlag(gametype); + INT16 cm = nextmap; + UINT32 tolflag = G_TOLFlag(gametype_to_use); UINT8 visitedmap[(NUMMAPS+7)/8]; memset(visitedmap, 0, sizeof (visitedmap)); @@ -4352,7 +4360,7 @@ static void G_DoCompleted(void) if (cv_advancemap.value == 0) // Stay on same map. nextmap = prevmap; else if (cv_advancemap.value == 2) // Go to random map. - nextmap = RandMap(G_TOLFlag(gametype), prevmap); + nextmap = RandMap(G_TOLFlag(gametype_to_use), prevmap); } // We are committed to this map now. @@ -4361,7 +4369,6 @@ static void G_DoCompleted(void) if (nextmap < NUMMAPS && !mapheaderinfo[nextmap]) P_AllocMapHeader(nextmap); - // If the current gametype has no intermission screen set, then don't start it. Y_DetermineIntermissionType(); if ((skipstats && !modeattacking) || (modeattacking && stagefailed) || (intertype == int_none)) @@ -4427,12 +4434,21 @@ static void G_DoWorldDone(void) { if (server) { + INT16 gametype_to_use; + + if (nextgametype >= 0 && nextgametype < gametypecount) + gametype_to_use = nextgametype; + else + gametype_to_use = gametype; + if (gametyperules & GTR_CAMPAIGN) // don't reset player between maps - D_MapChange(nextmap+1, gametype, ultimatemode, false, 0, false, false); + D_MapChange(nextmap+1, gametype_to_use, ultimatemode, false, 0, false, false); else // resetplayer in match/chaos/tag/CTF/race for more equality - D_MapChange(nextmap+1, gametype, ultimatemode, true, 0, false, false); + D_MapChange(nextmap+1, gametype_to_use, ultimatemode, true, 0, false, false); + + nextgametype = -1; } gameaction = ga_nothing; diff --git a/src/lua_baselib.c b/src/lua_baselib.c index dbd7c8e4f..04a6fe49c 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -3890,11 +3890,13 @@ static int lib_gSetCustomExitVars(lua_State *L) nextmapoverride = 0; skipstats = 0; + nextgametype = -1; if (n >= 1) { nextmapoverride = (INT16)luaL_optinteger(L, 1, 0); skipstats = (INT16)luaL_optinteger(L, 2, 0); + nextgametype = (INT16)luaL_optinteger(L, 3, 0); } return 0;