From e500507587d07652456a28afc92890b4df45908b Mon Sep 17 00:00:00 2001 From: terencehill Date: Thu, 21 Mar 2024 19:24:58 +0100 Subject: [PATCH] Make sure active custom gametype is not kept on the next map after manual gametype command call (and map restart). Currently custom gametypes can only be set after the game is over thus the gametype command doesn't support them --- qcsrc/server/command/sv_cmd.qc | 6 +++- qcsrc/server/mapvoting.qc | 50 +++++++++++++++++++--------------- qcsrc/server/mapvoting.qh | 2 +- qcsrc/server/world.qc | 1 + qcsrc/server/world.qh | 1 + 5 files changed, 36 insertions(+), 24 deletions(-) diff --git a/qcsrc/server/command/sv_cmd.qc b/qcsrc/server/command/sv_cmd.qc index 3fdb1f968..5a38ea404 100644 --- a/qcsrc/server/command/sv_cmd.qc +++ b/qcsrc/server/command/sv_cmd.qc @@ -778,7 +778,11 @@ void GameCommand_gametype(int request, int argc) Gametype t = MapInfo_Type_FromString(s, false, false); if (t) - GameTypeVote_SetGametype(t); + { + // don't execute gametype hooks because they can change active + // gametype rules if executed during the game + GameTypeVote_SetGametype(t, "", false); + } else bprint("Failed to switch to ", s, ": this game type does not exist!\n"); diff --git a/qcsrc/server/mapvoting.qc b/qcsrc/server/mapvoting.qc index 1a6e24960..dce3afee5 100644 --- a/qcsrc/server/mapvoting.qc +++ b/qcsrc/server/mapvoting.qc @@ -215,21 +215,6 @@ void MapVote_AddVotableMaps(int nmax, int smax) MapVote_AddVotable(GetNextMap(), false); } -bool GameTypeVote_SetGametype(Gametype type); - -// gametype_name can be the name of a custom gametype based on Gametype type -void GameTypeVote_ApplyGameType(Gametype type, string gametype_name) -{ - if (gametype_name == "") - gametype_name = MapInfo_Type_ToString(type); - - localcmd("sv_vote_gametype_hook_all\n"); - localcmd("sv_vote_gametype_hook_", gametype_name, "\n"); - - if (!GameTypeVote_SetGametype(type)) - LOG_TRACE("Selected gametype is not supported by any map"); -} - string voted_gametype_string; Gametype voted_gametype; Gametype match_gametype; @@ -277,8 +262,11 @@ void MapVote_Init() // In this case apply back match_gametype here so that the "restart" command, if called, // properly restarts the map applying the current game type. // Applying voted_gametype before map vote start is needed to properly initialize map vote. + string gametype_custom_string = ""; + if (gametype_custom_enabled) + gametype_custom_string = loaded_gametype_custom_string; if (match_gametype) - GameTypeVote_ApplyGameType(match_gametype, loaded_gametype_custom_string); + GameTypeVote_SetGametype(match_gametype, gametype_custom_string, true); } void MapVote_SendPicture(entity to, int id) @@ -565,7 +553,7 @@ bool MapVote_CheckRules_2() currentPlace = 0; currentVotes = -1; string current_gametype_string; - if (loaded_gametype_custom_string != "") + if (gametype_custom_enabled) current_gametype_string = loaded_gametype_custom_string; else current_gametype_string = MapInfo_Type_ToString(MapInfo_CurrentGametype()); @@ -709,10 +697,10 @@ void MapVote_Think() { if (voted_gametype) { - // clear match_gametype so that GameTypeVote_ApplyGameType + // clear match_gametype so that GameTypeVote_SetGametype // prints the game type switch message match_gametype = NULL; - GameTypeVote_ApplyGameType(voted_gametype, voted_gametype_string); + GameTypeVote_SetGametype(voted_gametype, voted_gametype_string, true); } Map_Goto_SetStr(mapvote_maps[mapvote_winner]); @@ -771,8 +759,25 @@ void MapVote_Think() MapVote_Tick(); } -bool GameTypeVote_SetGametype(Gametype type) +// if gametype_string is "" then gametype_string is inferred from Gametype type +// otherwise gametype_string is the string (short name) of a custom gametype +bool GameTypeVote_SetGametype(Gametype type, string gametype_string, bool call_hooks) { + if (!call_hooks) + { + // custom gametype is disabled because gametype hooks can't be executed + gametype_custom_enabled = false; + } + else + { + if (gametype_string == "") + gametype_string = MapInfo_Type_ToString(type); + gametype_custom_enabled = (gametype_string != MapInfo_Type_ToString(type)); + + localcmd("sv_vote_gametype_hook_all\n"); + localcmd("sv_vote_gametype_hook_", gametype_string, "\n"); + } + if (MapInfo_CurrentGametype() == type) return true; @@ -796,6 +801,7 @@ bool GameTypeVote_SetGametype(Gametype type) bprint("Cannot use this game type: no map for it found\n"); MapInfo_SwitchGameType(tsave); MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0); + LOG_TRACE("Selected gametype is not supported by any map"); return false; } @@ -814,7 +820,7 @@ bool GameTypeVote_Finished(int pos) voted_gametype = GameTypeVote_Type_FromString(mapvote_maps[pos]); strcpy(voted_gametype_string, mapvote_maps[pos]); - GameTypeVote_ApplyGameType(voted_gametype, voted_gametype_string); + GameTypeVote_SetGametype(voted_gametype, voted_gametype_string, true); // save to a cvar so it can be applied back when gametype is temporary // changed on gametype vote end of the next game @@ -883,7 +889,7 @@ bool GameTypeVote_Start() if ( mapvote_count > 0 ) strunzone(mapvote_maps[0]); string current_gametype_string; - if (loaded_gametype_custom_string != "") + if (gametype_custom_enabled) current_gametype_string = loaded_gametype_custom_string; else current_gametype_string = MapInfo_Type_ToString(MapInfo_CurrentGametype()); diff --git a/qcsrc/server/mapvoting.qh b/qcsrc/server/mapvoting.qh index 36578740c..41c41060d 100644 --- a/qcsrc/server/mapvoting.qh +++ b/qcsrc/server/mapvoting.qh @@ -30,7 +30,7 @@ void MapVote_Start(); void MapVote_Spawn(); void MapVote_Think(); void MapVote_SendPicture(entity to, int id); -bool GameTypeVote_SetGametype(entity type); +bool GameTypeVote_SetGametype(Gametype type, string gametype_string, bool call_hooks); float GameTypeVote_Start(); float GameTypeVote_Finished(int pos); string GameTypeVote_MapInfo_FixName(string m); diff --git a/qcsrc/server/world.qc b/qcsrc/server/world.qc index 48ef77273..b6fbe0d85 100644 --- a/qcsrc/server/world.qc +++ b/qcsrc/server/world.qc @@ -737,6 +737,7 @@ void InitGameplayMode() MapInfo_ClearTemps(); strcpy(loaded_gametype_custom_string, autocvar__sv_vote_gametype_custom); + gametype_custom_enabled = (loaded_gametype_custom_string != ""); cvar_set("_sv_vote_gametype_custom", ""); // clear it immediately so it can't get stuck cache_mutatormsg = strzone(""); diff --git a/qcsrc/server/world.qh b/qcsrc/server/world.qh index a5e848d45..6348c72f6 100644 --- a/qcsrc/server/world.qh +++ b/qcsrc/server/world.qh @@ -49,6 +49,7 @@ float cvar_purechanges_count; string modname; string autocvar__sv_vote_gametype_custom; +bool gametype_custom_enabled; string loaded_gametype_custom_string; string record_type; -- 2.39.2