#include <server/command/cmd.qh>
#include <server/command/getreplies.qh>
#include <server/gamelog.qh>
-#include <server/intermission.qh>
#include <server/world.qh>
// definitions
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 available_maps = Maplist_Init();
int max_attempts = available_maps;
if (available_maps >= 2)
max_attempts = min(available_maps * 5, 100);
MapVote_AddVotable(GetNextMap(), false);
}
+bool GameTypeVote_SetGametype(Gametype type);
+void GameTypeVote_ApplyGameType(Gametype type)
+{
+ localcmd("sv_vote_gametype_hook_all\n");
+ localcmd("sv_vote_gametype_hook_", MapInfo_Type_ToString(type), "\n");
+
+ if (!GameTypeVote_SetGametype(type))
+ LOG_TRACE("Selected gametype is not supported by any map");
+}
+
+Gametype voted_gametype;
+Gametype match_gametype;
void MapVote_Init()
{
int nmax, smax;
MapVote_AddVotableMaps(nmax, smax);
- if(mapvote_count == 0)
- {
- bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
- cvar_set("g_maplist", MapInfo_ListAllowedMaps(MapInfo_CurrentGametype(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
- if(autocvar_g_maplist_shuffle)
- ShuffleMaplist();
- localcmd("\nmenu_cmd sync\n");
- MapVote_AddVotableMaps(nmax, 0);
- }
-
mapvote_count_real = mapvote_count;
if(mapvote_abstain)
MapVote_AddVotable("don't care", false);
mapvote_keeptwotime = 0;
MapVote_Spawn();
+
+ // If match_gametype is set it means voted_gametype has just been applied (on game type vote end).
+ // 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.
+ if (match_gametype)
+ GameTypeVote_ApplyGameType(match_gametype);
}
void MapVote_SendPicture(entity to, int id)
{
// map vote but gametype has been chosen via voting screen
WriteByte(MSG_ENTITY, BIT(1)); // gametypevote_flags
- WriteString(MSG_ENTITY, MapInfo_Type_ToText(MapInfo_CurrentGametype()));
+ WriteString(MSG_ENTITY, MapInfo_Type_ToText(voted_gametype));
}
else
WriteByte(MSG_ENTITY, 0); // map vote
{
if (time > mapvote_winner_time + 1)
{
+ if (voted_gametype)
+ {
+ // clear match_gametype so that GameTypeVote_ApplyGameType
+ // prints the game type switch message
+ match_gametype = NULL;
+ GameTypeVote_ApplyGameType(voted_gametype);
+ }
+
Map_Goto_SetStr(mapvote_maps[mapvote_winner]);
Map_Goto(0);
}
// update lsmaps in case the gametype changed, this way people can easily list maps for it
if(lsmaps_reply != "") { strunzone(lsmaps_reply); }
lsmaps_reply = strzone(getlsmaps());
- bprint("Game type successfully switched to ", MapInfo_Type_ToString(type), "\n");
+
+ if (!match_gametype) // don't show this msg if we are temporarily switching game type
+ bprint("Game type successfully switched to ", MapInfo_Type_ToString(type), "\n");
}
else
{
}
cvar_set("g_maplist", MapInfo_ListAllowedMaps(type, MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()) );
- if(autocvar_g_maplist_shuffle)
- ShuffleMaplist();
return true;
}
if(!gametypevote || gametypevote_finished)
return false;
- localcmd("sv_vote_gametype_hook_all\n");
- localcmd("sv_vote_gametype_hook_", mapvote_maps[pos], "\n");
+ match_gametype = MapInfo_CurrentGametype();
+ voted_gametype = MapInfo_Type_FromString(mapvote_maps[pos], false, false);
- if ( !GameTypeVote_SetGametype(GameTypeVote_Type_FromString(mapvote_maps[pos])) )
- {
- LOG_TRACE("Selected gametype is not supported by any map");
- }
+ GameTypeVote_ApplyGameType(voted_gametype);
gametypevote_finished = true;