Currently custom gametypes can only be set after the game is over thus the gametype command doesn't support them
Gametype t = MapInfo_Type_FromString(s, false, false);
if (t)
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");
else
bprint("Failed to switch to ", s, ": this game type does not exist!\n");
MapVote_AddVotable(GetNextMap(), false);
}
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;
string voted_gametype_string;
Gametype voted_gametype;
Gametype match_gametype;
// 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.
// 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;
- GameTypeVote_ApplyGameType(match_gametype, loaded_gametype_custom_string);
+ GameTypeVote_SetGametype(match_gametype, gametype_custom_string, true);
}
void MapVote_SendPicture(entity to, int id)
}
void MapVote_SendPicture(entity to, int id)
currentPlace = 0;
currentVotes = -1;
string current_gametype_string;
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());
current_gametype_string = loaded_gametype_custom_string;
else
current_gametype_string = MapInfo_Type_ToString(MapInfo_CurrentGametype());
- // clear match_gametype so that GameTypeVote_ApplyGameType
+ // clear match_gametype so that GameTypeVote_SetGametype
// prints the game type switch message
match_gametype = NULL;
// 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]);
}
Map_Goto_SetStr(mapvote_maps[mapvote_winner]);
-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;
if (MapInfo_CurrentGametype() == type)
return true;
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);
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");
voted_gametype = GameTypeVote_Type_FromString(mapvote_maps[pos]);
strcpy(voted_gametype_string, mapvote_maps[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
// save to a cvar so it can be applied back when gametype is temporary
// changed on gametype vote end of the next game
if ( mapvote_count > 0 )
strunzone(mapvote_maps[0]);
string current_gametype_string;
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());
current_gametype_string = loaded_gametype_custom_string;
else
current_gametype_string = MapInfo_Type_ToString(MapInfo_CurrentGametype());
void MapVote_Spawn();
void MapVote_Think();
void MapVote_SendPicture(entity to, int id);
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);
float GameTypeVote_Start();
float GameTypeVote_Finished(int pos);
string GameTypeVote_MapInfo_FixName(string m);
MapInfo_ClearTemps();
strcpy(loaded_gametype_custom_string, autocvar__sv_vote_gametype_custom);
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("");
cvar_set("_sv_vote_gametype_custom", ""); // clear it immediately so it can't get stuck
cache_mutatormsg = strzone("");
string modname;
string autocvar__sv_vote_gametype_custom;
string modname;
string autocvar__sv_vote_gametype_custom;
+bool gametype_custom_enabled;
string loaded_gametype_custom_string;
string record_type;
string loaded_gametype_custom_string;
string record_type;