X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fserver%2Fmapvoting.qc;h=ac64f630ff1d5181372a33c21fb4e67bde03588a;hp=051968eb00c488cbef6ebc9d53f2dcca818a9fca;hb=HEAD;hpb=451aded981645abb3712580d339ce630e7d730e4 diff --git a/qcsrc/server/mapvoting.qc b/qcsrc/server/mapvoting.qc index 051968eb0..b9d19f611 100644 --- a/qcsrc/server/mapvoting.qc +++ b/qcsrc/server/mapvoting.qc @@ -12,7 +12,6 @@ #include #include #include -#include #include // definitions @@ -203,16 +202,7 @@ void MapVote_AddVotable(string nextMap, bool isSuggestion) 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); @@ -225,6 +215,9 @@ void MapVote_AddVotableMaps(int nmax, int smax) MapVote_AddVotable(GetNextMap(), false); } +string voted_gametype_string; +Gametype voted_gametype; +Gametype match_gametype; void MapVote_Init() { int nmax, smax; @@ -252,16 +245,6 @@ void MapVote_Init() 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); @@ -274,6 +257,16 @@ void MapVote_Init() 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. + string gametype_custom_string = ""; + if (gametype_custom_enabled) + gametype_custom_string = loaded_gametype_custom_string; + if (match_gametype) + GameTypeVote_SetGametype(match_gametype, gametype_custom_string, true); } void MapVote_SendPicture(entity to, int id) @@ -394,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(MapInfo_CurrentGametype())); + 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 @@ -500,6 +498,7 @@ bool MapVote_Finished(int mappos) Map_Goto_SetStr(autocvar_nextmap); Map_Goto(0); alreadychangedlevel = true; + strfree(voted_gametype_string); return true; } else @@ -553,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; @@ -691,8 +695,17 @@ void MapVote_Think() { if (time > mapvote_winner_time + 1) { + if (voted_gametype) + { + // clear match_gametype so that GameTypeVote_SetGametype + // prints the game type switch message + match_gametype = NULL; + GameTypeVote_SetGametype(voted_gametype, voted_gametype_string, true); + } + Map_Goto_SetStr(mapvote_maps[mapvote_winner]); Map_Goto(0); + strfree(voted_gametype_string); } return; } @@ -746,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; @@ -762,7 +792,9 @@ bool GameTypeVote_SetGametype(Gametype type) // 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 { @@ -772,11 +804,7 @@ bool GameTypeVote_SetGametype(Gametype type) return false; } - //localcmd("gametype ", MapInfo_Type_ToString(type), "\n"); - cvar_set("g_maplist", MapInfo_ListAllowedMaps(type, MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()) ); - if(autocvar_g_maplist_shuffle) - ShuffleMaplist(); return true; } @@ -787,13 +815,16 @@ bool GameTypeVote_Finished(int pos) 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 = GameTypeVote_Type_FromString(mapvote_maps[pos]); + strcpy(voted_gametype_string, mapvote_maps[pos]); - if ( !GameTypeVote_SetGametype(GameTypeVote_Type_FromString(mapvote_maps[pos])) ) - { - LOG_TRACE("Selected gametype is not supported by any map"); - } + 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 + if (mapvote_maps_flags[pos] & GTV_CUSTOM) + cvar_set("_sv_vote_gametype_custom", voted_gametype_string); gametypevote_finished = true; @@ -856,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;