]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Fixed many crashes in map voting screen related to gametypes with low amount of suppo...
authorterencehill <piuntn@gmail.com>
Sun, 4 Jun 2023 19:30:40 +0000 (19:30 +0000)
committerDr. Jaska <drjaska83@gmail.com>
Sun, 4 Jun 2023 19:30:40 +0000 (19:30 +0000)
qcsrc/server/intermission.qh
qcsrc/server/mapvoting.qc

index 667e08914c9d506ec488cae5d90d4e47e7b6d199..e3504829b57cdb27b11049c590432b336a240dbe 100644 (file)
@@ -22,6 +22,8 @@ void GotoNextMap(float reinit);
 
 bool Map_IsRecent(string m);
 
+bool Map_Check(int position, float pass);
+
 string GetNextMap();
 
 void ShuffleMaplist();
index caa7a3c502b98854997fed6dea4fb202eea6c3ab..d68b35f435bd0ecced8049fc5886ba0dab5c4dc2 100644 (file)
@@ -197,9 +197,32 @@ void MapVote_AddVotable(string nextMap, bool isSuggestion)
        mapvote_count += 1;
 }
 
+void MapVote_AddVotableMaps(int nmax, int smax)
+{
+       int available_maps = 0;
+       if (autocvar_g_maplist != "")
+       {
+               int c = tokenizebyseparator(autocvar_g_maplist, " ");
+               for (int i = 0; i < c; ++i)
+               {
+                       if (Map_Check(i, 1) || Map_Check(i, 2))
+                               ++available_maps;
+               }
+       }
+       int max_attempts = available_maps;
+       if (available_maps >= 2)
+               max_attempts = min(available_maps * 5, 100);
+
+       if (smax && mapvote_suggestion_ptr)
+               for(int i = 0; i < max_attempts && mapvote_count < smax; ++i)
+                       MapVote_AddVotable(mapvote_suggestions[floor(random() * mapvote_suggestion_ptr)], true);
+
+       for (int i = 0; i < max_attempts && mapvote_count < nmax; ++i)
+               MapVote_AddVotable(GetNextMap(), false);
+}
+
 void MapVote_Init()
 {
-       int i;
        int nmax, smax;
 
        MapVote_ClearAllVotes();
@@ -220,15 +243,10 @@ void MapVote_Init()
        if(mapvote_screenshot_dirs_count == 0)
                mapvote_screenshot_dirs_count = tokenize_console("maps levelshots");
        mapvote_screenshot_dirs_count = min(mapvote_screenshot_dirs_count, MAPVOTE_SCREENSHOT_DIRS_COUNT);
-       for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
+       for(int i = 0; i < mapvote_screenshot_dirs_count; ++i)
                mapvote_screenshot_dirs[i] = strzone(argv(i));
 
-       if(mapvote_suggestion_ptr)
-               for(i = 0; i < 100 && mapvote_count < smax; ++i)
-                       MapVote_AddVotable(mapvote_suggestions[floor(random() * mapvote_suggestion_ptr)], true);
-
-       for(i = 0; i < 100 && mapvote_count < nmax; ++i)
-               MapVote_AddVotable(GetNextMap(), false);
+       MapVote_AddVotableMaps(nmax, smax);
 
        if(mapvote_count == 0)
        {
@@ -237,8 +255,7 @@ void MapVote_Init()
                if(autocvar_g_maplist_shuffle)
                        ShuffleMaplist();
                localcmd("\nmenu_cmd sync\n");
-               for(i = 0; i < 100 && mapvote_count < nmax; ++i)
-                       MapVote_AddVotable(GetNextMap(), false);
+               MapVote_AddVotableMaps(nmax, 0);
        }
 
        mapvote_count_real = mapvote_count;