1 #include "mapvoting.qh"
3 #include <common/constants.qh>
4 #include <common/mapinfo.qh>
5 #include <common/net_linked.qh>
6 #include <common/playerstats.qh>
7 #include <common/state.qh>
8 #include <common/stats.qh>
9 #include <common/util.qh>
10 #include <common/weapons/_all.qh>
11 #include <server/client.qh>
12 #include <server/command/cmd.qh>
13 #include <server/command/getreplies.qh>
14 #include <server/gamelog.qh>
15 #include <server/world.qh>
19 float mapvote_nextthink;
20 float mapvote_keeptwotime;
21 float mapvote_timeout;
22 const int MAPVOTE_SCREENSHOT_DIRS_COUNT = 4;
23 string mapvote_screenshot_dirs[MAPVOTE_SCREENSHOT_DIRS_COUNT];
24 int mapvote_screenshot_dirs_count;
27 int mapvote_count_real;
28 string mapvote_maps[MAPVOTE_COUNT];
29 int mapvote_maps_screenshot_dir[MAPVOTE_COUNT];
30 string mapvote_maps_pakfile[MAPVOTE_COUNT];
31 bool mapvote_maps_suggested[MAPVOTE_COUNT];
32 string mapvote_suggestions[MAPVOTE_COUNT];
33 int mapvote_suggestion_ptr;
35 int mapvote_selections[MAPVOTE_COUNT];
36 int mapvote_maps_flags[MAPVOTE_COUNT];
45 * Returns the gamtype ID from its name, if type_name isn't a real gametype it
46 * checks for sv_vote_gametype_(type_name)_type
48 Gametype GameTypeVote_Type_FromString(string type_name)
50 Gametype type = MapInfo_Type_FromString(type_name, false, false);
52 type = MapInfo_Type_FromString(cvar_string(
53 strcat("sv_vote_gametype_",type_name,"_type")), false, false);
57 int GameTypeVote_AvailabilityStatus(string type_name)
59 int flag = GTV_FORBIDDEN;
61 Gametype type = MapInfo_Type_FromString(type_name, false, false);
64 type = MapInfo_Type_FromString(cvar_string(
65 strcat("sv_vote_gametype_",type_name,"_type")), false, false);
72 if ( autocvar_nextmap != "" )
74 if ( !MapInfo_Get_ByName(autocvar_nextmap, false, NULL) )
76 if (!(MapInfo_Map_supportedGametypes & type.m_flags))
80 return flag | GTV_AVAILABLE;
83 int GameTypeVote_GetMask()
85 int n, j, gametype_mask;
86 n = tokenizebyseparator(autocvar_sv_vote_gametype_options, " ");
87 n = min(MAPVOTE_COUNT, n);
89 for(j = 0; j < n; ++j)
90 gametype_mask |= GameTypeVote_Type_FromString(argv(j)).m_flags;
92 if (gametype_mask == 0)
93 gametype_mask |= MapInfo_CurrentGametype().m_flags;
98 string GameTypeVote_MapInfo_FixName(string m)
100 if ( autocvar_sv_vote_gametype )
103 _MapInfo_FilterGametype(GameTypeVote_GetMask(), 0, MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
105 return MapInfo_FixName(m);
108 void MapVote_ClearAllVotes()
110 FOREACH_CLIENT(true, { it.mapvote = 0; });
113 void MapVote_UnzoneStrings()
115 for(int j = 0; j < mapvote_count; ++j)
117 strfree(mapvote_maps[j]);
118 strfree(mapvote_maps_pakfile[j]);
122 string MapVote_Suggest(entity this, string m)
126 return "That's not how to use this command.";
127 if(!autocvar_g_maplist_votable_suggestions)
128 return "Suggestions are not accepted on this server.";
129 if(mapvote_initialized)
131 return "Can't suggest - voting is already in progress!";
132 m = GameTypeVote_MapInfo_FixName(m);
134 return "The map you suggested is not available on this server.";
135 if(!autocvar_g_maplist_votable_suggestions_override_mostrecent)
137 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
139 if (!autocvar_sv_vote_gametype)
140 if(!MapInfo_CheckMap(m))
141 return "The map you suggested does not support the current game mode.";
142 for(i = 0; i < mapvote_suggestion_ptr; ++i)
143 if(mapvote_suggestions[i] == m)
144 return "This map was already suggested.";
145 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
147 i = floor(random() * mapvote_suggestion_ptr);
151 i = mapvote_suggestion_ptr;
152 mapvote_suggestion_ptr += 1;
154 if(mapvote_suggestions[i] != "")
155 strunzone(mapvote_suggestions[i]);
156 mapvote_suggestions[i] = strzone(m);
157 if(autocvar_sv_eventlog)
158 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(this.playerid)));
159 return strcat("Suggestion of ", m, " accepted.");
162 void MapVote_AddVotable(string nextMap, bool isSuggestion)
165 string pakfile, mapfile;
169 for(j = 0; j < mapvote_count; ++j)
170 if(mapvote_maps[j] == nextMap)
172 // suggestions might be no longer valid/allowed after gametype switch!
174 if(!MapInfo_CheckMap(nextMap))
176 mapvote_maps[mapvote_count] = strzone(nextMap);
177 mapvote_maps_suggested[mapvote_count] = isSuggestion;
179 pakfile = string_null;
180 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
182 mapfile = strcat(mapvote_screenshot_dirs[i], "/", nextMap);
183 pakfile = whichpack(strcat(mapfile, ".tga"));
185 pakfile = whichpack(strcat(mapfile, ".jpg"));
187 pakfile = whichpack(strcat(mapfile, ".png"));
191 if(i >= mapvote_screenshot_dirs_count)
192 i = 0; // FIXME maybe network this error case, as that means there is no mapshot on the server?
193 for(o = strstrofs(pakfile, "/", 0)+1; o > 0; o = strstrofs(pakfile, "/", 0)+1)
194 pakfile = substring(pakfile, o, -1);
196 mapvote_maps_screenshot_dir[mapvote_count] = i;
197 mapvote_maps_pakfile[mapvote_count] = strzone(pakfile);
198 mapvote_maps_flags[mapvote_count] = GTV_AVAILABLE;
203 void MapVote_AddVotableMaps(int nmax, int smax)
205 int available_maps = Maplist_Init();
206 int max_attempts = available_maps;
207 if (available_maps >= 2)
208 max_attempts = min(available_maps * 5, 100);
210 if (smax && mapvote_suggestion_ptr)
211 for(int i = 0; i < max_attempts && mapvote_count < smax; ++i)
212 MapVote_AddVotable(mapvote_suggestions[floor(random() * mapvote_suggestion_ptr)], true);
214 for (int i = 0; i < max_attempts && mapvote_count < nmax; ++i)
215 MapVote_AddVotable(GetNextMap(), false);
218 bool GameTypeVote_SetGametype(Gametype type);
220 // gametype_name can be the name of a custom gametype based on Gametype type
221 void GameTypeVote_ApplyGameType(Gametype type, string gametype_name)
223 if (gametype_name == "")
224 gametype_name = MapInfo_Type_ToString(type);
226 localcmd("sv_vote_gametype_hook_all\n");
227 localcmd("sv_vote_gametype_hook_", gametype_name, "\n");
229 if (!GameTypeVote_SetGametype(type))
230 LOG_TRACE("Selected gametype is not supported by any map");
233 string voted_gametype_string;
234 Gametype voted_gametype;
235 Gametype match_gametype;
240 MapVote_ClearAllVotes();
241 MapVote_UnzoneStrings();
244 mapvote_detail = !autocvar_g_maplist_votable_nodetail;
245 mapvote_abstain = boolean(autocvar_g_maplist_votable_abstain);
248 nmax = min(MAPVOTE_COUNT - 1, autocvar_g_maplist_votable);
250 nmax = min(MAPVOTE_COUNT, autocvar_g_maplist_votable);
251 smax = min3(nmax, autocvar_g_maplist_votable_suggestions, mapvote_suggestion_ptr);
253 // we need this for AddVotable, as that cycles through the screenshot dirs
254 mapvote_screenshot_dirs_count = tokenize_console(autocvar_g_maplist_votable_screenshot_dir);
255 if(mapvote_screenshot_dirs_count == 0)
256 mapvote_screenshot_dirs_count = tokenize_console("maps levelshots");
257 mapvote_screenshot_dirs_count = min(mapvote_screenshot_dirs_count, MAPVOTE_SCREENSHOT_DIRS_COUNT);
258 for(int i = 0; i < mapvote_screenshot_dirs_count; ++i)
259 mapvote_screenshot_dirs[i] = strzone(argv(i));
261 MapVote_AddVotableMaps(nmax, smax);
263 mapvote_count_real = mapvote_count;
265 MapVote_AddVotable("don't care", false);
267 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
269 mapvote_keeptwotime = time + autocvar_g_maplist_votable_keeptwotime;
270 mapvote_timeout = time + autocvar_g_maplist_votable_timeout;
271 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
272 mapvote_keeptwotime = 0;
276 // If match_gametype is set it means voted_gametype has just been applied (on game type vote end).
277 // In this case apply back match_gametype here so that the "restart" command, if called,
278 // properly restarts the map applying the current game type.
279 // Applying voted_gametype before map vote start is needed to properly initialize map vote.
281 GameTypeVote_ApplyGameType(match_gametype, gametype_custom_string);
284 void MapVote_SendPicture(entity to, int id)
287 WriteHeader(MSG_ONE, TE_CSQC_PICTURE);
288 WriteByte(MSG_ONE, id);
289 WritePicture(MSG_ONE, strcat(mapvote_screenshot_dirs[mapvote_maps_screenshot_dir[id]], "/", mapvote_maps[id]), 3072);
293 void MapVote_WriteMask()
295 if ( mapvote_count < 24 )
298 for(int j = 0; j < mapvote_count; ++j)
300 if(mapvote_maps_flags[j] & GTV_AVAILABLE)
304 if(mapvote_count < 8)
305 WriteByte(MSG_ENTITY, mask);
306 else if (mapvote_count < 16)
307 WriteShort(MSG_ENTITY,mask);
309 WriteLong(MSG_ENTITY, mask);
313 for (int j = 0; j < mapvote_count; ++j)
314 WriteByte(MSG_ENTITY, mapvote_maps_flags[j]);
319 * Sends a single map vote option to the client
321 void MapVote_SendOption(int i)
324 if(mapvote_abstain && i == mapvote_count - 1)
326 WriteString(MSG_ENTITY, ""); // abstain needs no text
327 WriteString(MSG_ENTITY, ""); // abstain needs no pack
328 WriteByte(MSG_ENTITY, 0); // abstain needs no screenshot dir
332 WriteString(MSG_ENTITY, mapvote_maps[i]);
333 WriteString(MSG_ENTITY, mapvote_maps_pakfile[i]);
334 WriteByte(MSG_ENTITY, mapvote_maps_screenshot_dir[i]);
339 * Sends a single gametype vote option to the client
341 void GameTypeVote_SendOption(int i)
344 if(mapvote_abstain && i == mapvote_count - 1)
346 WriteString(MSG_ENTITY, ""); // abstain needs no text
347 WriteByte(MSG_ENTITY, GTV_AVAILABLE);
351 string type_name = mapvote_maps[i];
352 WriteString(MSG_ENTITY, type_name);
353 WriteByte(MSG_ENTITY, mapvote_maps_flags[i]);
354 if ( mapvote_maps_flags[i] & GTV_CUSTOM )
356 WriteString(MSG_ENTITY, cvar_string(
357 strcat("sv_vote_gametype_",type_name,"_name")));
358 WriteString(MSG_ENTITY, cvar_string(
359 strcat("sv_vote_gametype_",type_name,"_description")));
360 WriteString(MSG_ENTITY, cvar_string(
361 strcat("sv_vote_gametype_",type_name,"_type")));
367 float mapvote_winner_time;
368 bool MapVote_SendEntity(entity this, entity to, int sf)
373 sf &= ~2; // if we send 1, we don't need to also send 2
375 if (!mapvote_winner_time)
376 sf &= ~8; // no winner yet
378 WriteHeader(MSG_ENTITY, ENT_CLIENT_MAPVOTE);
379 WriteByte(MSG_ENTITY, sf);
383 // flag 1 == initialization
384 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
385 WriteString(MSG_ENTITY, mapvote_screenshot_dirs[i]);
386 WriteString(MSG_ENTITY, "");
387 WriteByte(MSG_ENTITY, mapvote_count);
388 WriteByte(MSG_ENTITY, mapvote_abstain);
389 WriteByte(MSG_ENTITY, mapvote_detail);
390 WriteCoord(MSG_ENTITY, mapvote_timeout);
395 WriteByte(MSG_ENTITY, BIT(0)); // gametypevote_flags
396 WriteString(MSG_ENTITY, autocvar_nextmap);
398 else if ( autocvar_sv_vote_gametype )
400 // map vote but gametype has been chosen via voting screen
401 WriteByte(MSG_ENTITY, BIT(1)); // gametypevote_flags
402 string voted_gametype_name;
403 if (voted_gametype_string == MapInfo_Type_ToString(voted_gametype))
404 voted_gametype_name = MapInfo_Type_ToText(voted_gametype);
406 voted_gametype_name = cvar_string(strcat("sv_vote_gametype_", voted_gametype_string, "_name"));
407 WriteString(MSG_ENTITY, voted_gametype_name);
410 WriteByte(MSG_ENTITY, 0); // map vote
414 // Send data for the vote options
415 for(i = 0; i < mapvote_count; ++i)
418 GameTypeVote_SendOption(i);
420 MapVote_SendOption(i);
426 // flag 2 == update of mask
433 for(i = 0; i < mapvote_count; ++i)
434 if ( mapvote_maps_flags[i] & GTV_AVAILABLE )
435 WriteByte(MSG_ENTITY, mapvote_selections[i]);
437 WriteByte(MSG_ENTITY, to.mapvote);
442 WriteByte(MSG_ENTITY, mapvote_winner + 1);
450 Net_LinkEntity(mapvote_ent = new(mapvote_ent), false, 0, MapVote_SendEntity);
453 void MapVote_TouchMask()
455 mapvote_ent.SendFlags |= 2;
458 void MapVote_TouchVotes(entity voter)
460 mapvote_ent.SendFlags |= 4;
463 void MapVote_Winner(int mappos)
465 mapvote_ent.SendFlags |= 8;
466 mapvote_winner_time = time;
467 mapvote_winner = mappos;
470 bool MapVote_Finished(int mappos)
472 if(alreadychangedlevel)
479 if(autocvar_sv_eventlog)
481 result = strcat(":vote:finished:", mapvote_maps[mappos]);
482 result = strcat(result, ":", ftos(mapvote_selections[mappos]), "::");
483 didntvote = mapvote_voters;
484 for(i = 0; i < mapvote_count; ++i)
485 if(mapvote_maps_flags[i] & GTV_AVAILABLE )
487 didntvote -= mapvote_selections[i];
490 result = strcat(result, ":", mapvote_maps[i]);
491 result = strcat(result, ":", ftos(mapvote_selections[i]));
494 result = strcat(result, ":didn't vote:", ftos(didntvote));
497 if(mapvote_maps_suggested[mappos])
498 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]));
501 FOREACH_CLIENT(IS_REAL_CLIENT(it), { FixClientCvars(it); });
505 if ( GameTypeVote_Finished(mappos) )
507 gametypevote = false;
508 if(autocvar_nextmap != "")
510 Map_Goto_SetStr(autocvar_nextmap);
512 alreadychangedlevel = true;
513 strfree(voted_gametype_string);
522 MapVote_Winner(mappos);
523 alreadychangedlevel = true;
528 void MapVote_CheckRules_1()
530 for (int i = 0; i < mapvote_count; ++i)
531 if (mapvote_maps_flags[i] & GTV_AVAILABLE)
533 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
534 mapvote_selections[i] = 0;
538 FOREACH_CLIENT(IS_REAL_CLIENT(it), {
542 int idx = it.mapvote - 1;
543 //dprint("Player ", it.netname, " vote = ", ftos(idx), "\n");
544 ++mapvote_selections[idx];
549 bool MapVote_CheckRules_2()
552 int firstPlace, secondPlace, currentPlace;
553 int firstPlaceVotes, secondPlaceVotes, currentVotes;
554 int mapvote_voters_real;
557 if(mapvote_count_real == 1)
558 return MapVote_Finished(0);
560 mapvote_voters_real = mapvote_voters;
562 mapvote_voters_real -= mapvote_selections[mapvote_count - 1];
564 RandomSelection_Init();
567 for(i = 0; i < mapvote_count_real; ++i)
568 if ( mapvote_maps_flags[i] & GTV_AVAILABLE )
570 RandomSelection_AddFloat(i, 1, mapvote_selections[i]);
571 if ( gametypevote && mapvote_maps[i] == MapInfo_Type_ToString(MapInfo_CurrentGametype()) )
573 currentVotes = mapvote_selections[i];
577 firstPlaceVotes = RandomSelection_best_priority;
578 if (gametypevote && autocvar_sv_vote_gametype_default_current && firstPlaceVotes == 0)
579 firstPlace = currentPlace;
581 firstPlace = RandomSelection_chosen_float;
583 //dprint("First place: ", ftos(firstPlace), "\n");
584 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
586 RandomSelection_Init();
587 for(i = 0; i < mapvote_count_real; ++i)
589 if ( mapvote_maps_flags[i] & GTV_AVAILABLE )
590 RandomSelection_AddFloat(i, 1, mapvote_selections[i]);
591 secondPlace = RandomSelection_chosen_float;
592 secondPlaceVotes = RandomSelection_best_priority;
593 //dprint("Second place: ", ftos(secondPlace), "\n");
594 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
597 error("No first place in map vote... WTF?");
599 if(secondPlace == -1 || time > mapvote_timeout
600 || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes
601 || mapvote_selections[mapvote_count - 1] == mapvote_voters)
603 return MapVote_Finished(firstPlace);
606 if(mapvote_keeptwotime)
607 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
610 mapvote_keeptwotime = 0;
611 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
612 result = strcat(result, ":", ftos(firstPlaceVotes));
613 result = strcat(result, ":", mapvote_maps[secondPlace]);
614 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
615 int didntvote = mapvote_voters;
616 for(i = 0; i < mapvote_count; ++i)
618 didntvote -= mapvote_selections[i];
622 result = strcat(result, ":", mapvote_maps[i]);
623 result = strcat(result, ":", ftos(mapvote_selections[i]));
624 if(i < mapvote_count_real)
626 mapvote_maps_flags[i] &= ~GTV_AVAILABLE;
630 result = strcat(result, ":didn't vote:", ftos(didntvote));
631 if(autocvar_sv_eventlog)
640 MapVote_CheckRules_1(); // count
641 if(MapVote_CheckRules_2()) // decide
645 FOREACH_CLIENT(true, {
646 if(!IS_REAL_CLIENT(it))
648 // apply the same special health value to bots too for consistency's sake
649 if(GetResource(it, RES_HEALTH) != 2342)
650 SetResourceExplicit(it, RES_HEALTH, 2342);
653 // hide scoreboard again
654 if(GetResource(it, RES_HEALTH) != 2342)
656 SetResourceExplicit(it, RES_HEALTH, 2342); // health in the voting phase
660 WriteByte(MSG_ONE, SVC_FINALE);
661 WriteString(MSG_ONE, "");
664 // clear possibly invalid votes
665 if ( !(mapvote_maps_flags[it.mapvote-1] & GTV_AVAILABLE) )
667 // use impulses as new vote
668 if(CS(it).impulse >= 1 && CS(it).impulse <= mapvote_count)
669 if( mapvote_maps_flags[CS(it).impulse - 1] & GTV_AVAILABLE )
671 it.mapvote = CS(it).impulse;
672 MapVote_TouchVotes(it);
680 MapVote_CheckRules_1(); // just count
685 // if mapvote is already running, don't do this initialization again
686 if(mapvote_run) { return; }
688 // don't start mapvote until after playerstats gamereport is sent
689 if(PlayerStats_GameReport_DelayMapVote) { return; }
692 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1))
701 if (mapvote_winner_time)
703 if (time > mapvote_winner_time + 1)
707 // clear match_gametype so that GameTypeVote_ApplyGameType
708 // prints the game type switch message
709 match_gametype = NULL;
710 GameTypeVote_ApplyGameType(voted_gametype, voted_gametype_string);
713 Map_Goto_SetStr(mapvote_maps[mapvote_winner]);
715 strfree(voted_gametype_string);
720 if(alreadychangedlevel)
723 if(time < mapvote_nextthink)
727 mapvote_nextthink = time + 0.5;
728 if (mapvote_nextthink > mapvote_timeout - 0.1) // make sure there's no delay when map vote times out
729 mapvote_nextthink = mapvote_timeout + 0.001;
731 if(!mapvote_initialized)
733 if(autocvar_rescan_pending == 1)
735 cvar_set("rescan_pending", "2");
736 localcmd("fs_rescan\nrescan_pending 3\n");
739 else if(autocvar_rescan_pending == 2)
743 else if(autocvar_rescan_pending == 3)
745 // now build missing mapinfo files
746 if(!MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1))
749 // we're done, start the timer
750 cvar_set("rescan_pending", "0");
753 mapvote_initialized = true;
754 if(DoNextMapOverride(0))
756 if(!autocvar_g_maplist_votable || player_count <= 0)
762 if(autocvar_sv_vote_gametype) { GameTypeVote_Start(); }
763 else if(autocvar_nextmap == "") { MapVote_Init(); }
769 bool GameTypeVote_SetGametype(Gametype type)
771 if (MapInfo_CurrentGametype() == type)
774 Gametype tsave = MapInfo_CurrentGametype();
776 MapInfo_SwitchGameType(type);
779 MapInfo_FilterGametype(type, MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
780 if(MapInfo_count > 0)
782 // update lsmaps in case the gametype changed, this way people can easily list maps for it
783 if(lsmaps_reply != "") { strunzone(lsmaps_reply); }
784 lsmaps_reply = strzone(getlsmaps());
786 if (!match_gametype) // don't show this msg if we are temporarily switching game type
787 bprint("Game type successfully switched to ", MapInfo_Type_ToString(type), "\n");
791 bprint("Cannot use this game type: no map for it found\n");
792 MapInfo_SwitchGameType(tsave);
793 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
797 cvar_set("g_maplist", MapInfo_ListAllowedMaps(type, MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()) );
802 bool gametypevote_finished;
803 bool GameTypeVote_Finished(int pos)
805 if(!gametypevote || gametypevote_finished)
808 match_gametype = MapInfo_CurrentGametype();
809 voted_gametype = GameTypeVote_Type_FromString(mapvote_maps[pos]);
810 strcpy(voted_gametype_string, mapvote_maps[pos]);
812 GameTypeVote_ApplyGameType(voted_gametype, voted_gametype_string);
814 // save to a cvar so it can be applied back when gametype is temporary
815 // changed on gametype vote end of the next game
816 if (mapvote_maps_flags[pos] & GTV_CUSTOM)
817 cvar_set("_sv_vote_gametype_custom", voted_gametype_string);
819 gametypevote_finished = true;
824 bool GameTypeVote_AddVotable(string nextMode)
826 if ( nextMode == "" || GameTypeVote_Type_FromString(nextMode) == NULL )
829 for(int j = 0; j < mapvote_count; ++j)
830 if(mapvote_maps[j] == nextMode)
833 mapvote_maps[mapvote_count] = strzone(nextMode);
834 mapvote_maps_suggested[mapvote_count] = false;
836 mapvote_maps_screenshot_dir[mapvote_count] = 0;
837 mapvote_maps_pakfile[mapvote_count] = strzone("");
838 mapvote_maps_flags[mapvote_count] = GameTypeVote_AvailabilityStatus(nextMode);
846 bool GameTypeVote_Start()
848 MapVote_ClearAllVotes();
849 MapVote_UnzoneStrings();
852 mapvote_timeout = time + autocvar_sv_vote_gametype_timeout;
853 mapvote_abstain = false;
854 mapvote_detail = !autocvar_g_maplist_votable_nodetail;
856 int n = tokenizebyseparator(autocvar_sv_vote_gametype_options, " ");
857 n = min(MAPVOTE_COUNT, n);
859 int really_available, which_available;
860 really_available = 0;
861 which_available = -1;
862 for(int j = 0; j < n; ++j)
864 if ( GameTypeVote_AddVotable(argv(j)) )
865 if ( mapvote_maps_flags[j] & GTV_AVAILABLE )
872 mapvote_count_real = mapvote_count;
876 if ( really_available == 0 )
878 if ( mapvote_count > 0 )
879 strunzone(mapvote_maps[0]);
880 mapvote_maps[0] = strzone(MapInfo_Type_ToString(MapInfo_CurrentGametype()));
881 //GameTypeVote_Finished(0);
885 if ( really_available == 1 )
887 //GameTypeVote_Finished(which_available);
888 MapVote_Finished(which_available);
892 mapvote_count_real = mapvote_count;
894 mapvote_keeptwotime = time + autocvar_sv_vote_gametype_keeptwotime;
895 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
896 mapvote_keeptwotime = 0;