]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/mapvoting.qc
Transifex autosync
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mapvoting.qc
index 995fd60029afdaf7a524a9ad0f28b74825aee91c..b9d19f611dfdd61f6beae00b05181161cd7872d6 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, gametype_custom_string);
+               GameTypeVote_SetGametype(match_gametype, gametype_custom_string, true);
 }
 
 void MapVote_SendPicture(entity to, int id)
@@ -399,7 +387,12 @@ bool MapVote_SendEntity(entity this, entity to, int sf)
                {
                        // map vote but gametype has been chosen via voting screen
                        WriteByte(MSG_ENTITY, BIT(1)); // gametypevote_flags
-                       WriteString(MSG_ENTITY, MapInfo_Type_ToText(voted_gametype));
+                       string voted_gametype_name;
+                       if (voted_gametype_string == MapInfo_Type_ToString(voted_gametype))
+                               voted_gametype_name = MapInfo_Type_ToText(voted_gametype);
+                       else
+                               voted_gametype_name = cvar_string(strcat("sv_vote_gametype_", voted_gametype_string, "_name"));
+                       WriteString(MSG_ENTITY, voted_gametype_name);
                }
                else
                        WriteByte(MSG_ENTITY, 0); // map vote
@@ -559,11 +552,16 @@ bool MapVote_CheckRules_2()
        RandomSelection_Init();
        currentPlace = 0;
        currentVotes = -1;
+       string current_gametype_string;
+       if (gametype_custom_enabled)
+               current_gametype_string = loaded_gametype_custom_string;
+       else
+               current_gametype_string = MapInfo_Type_ToString(MapInfo_CurrentGametype());
        for(i = 0; i < mapvote_count_real; ++i)
                if ( mapvote_maps_flags[i] & GTV_AVAILABLE )
                {
                        RandomSelection_AddFloat(i, 1, mapvote_selections[i]);
-                       if ( gametypevote && mapvote_maps[i] == MapInfo_Type_ToString(MapInfo_CurrentGametype()) )
+                       if ( gametypevote && mapvote_maps[i] == current_gametype_string )
                        {
                                currentVotes = mapvote_selections[i];
                                currentPlace = i;
@@ -699,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]);
@@ -761,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;
 
@@ -804,7 +819,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
@@ -872,7 +887,12 @@ bool GameTypeVote_Start()
        {
                if ( mapvote_count > 0 )
                        strunzone(mapvote_maps[0]);
-               mapvote_maps[0] = strzone(MapInfo_Type_ToString(MapInfo_CurrentGametype()));
+               string current_gametype_string;
+               if (gametype_custom_enabled)
+                       current_gametype_string = loaded_gametype_custom_string;
+               else
+                       current_gametype_string = MapInfo_Type_ToString(MapInfo_CurrentGametype());
+               mapvote_maps[0] = strzone(current_gametype_string);
                //GameTypeVote_Finished(0);
                MapVote_Finished(0);
                return false;