]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Make sure active custom gametype is not kept on the next map after manual gametype...
authorterencehill <piuntn@gmail.com>
Thu, 21 Mar 2024 18:24:58 +0000 (19:24 +0100)
committerterencehill <piuntn@gmail.com>
Thu, 21 Mar 2024 18:55:02 +0000 (19:55 +0100)
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
qcsrc/server/mapvoting.qc
qcsrc/server/mapvoting.qh
qcsrc/server/world.qc
qcsrc/server/world.qh

index 3fdb1f968c5b75b96363643c1286837850d67ab4..5a38ea404572bba6890f24c6d9e8df9f51296169 100644 (file)
@@ -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");
 
index 1a6e24960d535912b456804d2d3fb03ada3c0efe..dce3afee58d8137ff5c0a741ec4e0ea0c1ce7eaa 100644 (file)
@@ -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());
index 36578740c07fff735e11041ce9811d1284727484..41c41060db75a131077e9496829fb6712c642cb5 100644 (file)
@@ -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);
index 48ef7727373450a62d7703ac4845afbd30ecef69..b6fbe0d85f3796c649a639dabcf31b2a9cb11c53 100644 (file)
@@ -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("");
index a5e848d45dbd8d4c951f5ab5ca02e2fed1aa3960..6348c72f6072a5862fdcb0ede96c7b981f7d48f3 100644 (file)
@@ -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;