]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/mapvoting.qc
sv_q3compat_changehitbox: use correct model scale and offset
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mapvoting.qc
index c73f97da961643c4cbe3b791e93dea3b880e73f1..caa7a3c502b98854997fed6dea4fb202eea6c3ab 100644 (file)
@@ -337,6 +337,8 @@ void GameTypeVote_SendOption(int i)
        }
 }
 
+int mapvote_winner;
+float mapvote_winner_time;
 bool MapVote_SendEntity(entity this, entity to, int sf)
 {
        int i;
@@ -344,6 +346,9 @@ bool MapVote_SendEntity(entity this, entity to, int sf)
        if(sf & 1)
                sf &= ~2; // if we send 1, we don't need to also send 2
 
+       if (!mapvote_winner_time)
+               sf &= ~8; // no winner yet
+
        WriteHeader(MSG_ENTITY, ENT_CLIENT_MAPVOTE);
        WriteByte(MSG_ENTITY, sf);
 
@@ -361,13 +366,13 @@ bool MapVote_SendEntity(entity this, entity to, int sf)
                if ( gametypevote )
                {
                        // gametype vote
-                       WriteByte(MSG_ENTITY, 1);
+                       WriteByte(MSG_ENTITY, BIT(0)); // gametypevote_flags
                        WriteString(MSG_ENTITY, autocvar_nextmap);
                }
                else if ( autocvar_sv_vote_gametype )
                {
                        // map vote but gametype has been chosen via voting screen
-                       WriteByte(MSG_ENTITY, 2);
+                       WriteByte(MSG_ENTITY, BIT(1)); // gametypevote_flags
                        WriteString(MSG_ENTITY, MapInfo_Type_ToText(MapInfo_CurrentGametype()));
                }
                else
@@ -401,6 +406,11 @@ bool MapVote_SendEntity(entity this, entity to, int sf)
                WriteByte(MSG_ENTITY, to.mapvote);
        }
 
+       if(sf & 8)
+       {
+               WriteByte(MSG_ENTITY, mapvote_winner + 1);
+       }
+
        return true;
 }
 
@@ -419,6 +429,13 @@ void MapVote_TouchVotes(entity voter)
        mapvote_ent.SendFlags |= 4;
 }
 
+void MapVote_Winner(int mappos)
+{
+       mapvote_ent.SendFlags |= 8;
+       mapvote_winner_time = time;
+       mapvote_winner = mappos;
+}
+
 bool MapVote_Finished(int mappos)
 {
        if(alreadychangedlevel)
@@ -470,8 +487,7 @@ bool MapVote_Finished(int mappos)
                return false;
        }
 
-       Map_Goto_SetStr(mapvote_maps[mappos]);
-       Map_Goto(0);
+       MapVote_Winner(mappos);
        alreadychangedlevel = true;
 
        return true;
@@ -520,14 +536,14 @@ bool MapVote_CheckRules_2()
                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] == MapInfo_Type_ToString(MapInfo_CurrentGametype()) )
                        {
                                currentVotes = mapvote_selections[i];
                                currentPlace = i;
                        }
                }
        firstPlaceVotes = RandomSelection_best_priority;
-       if ( autocvar_sv_vote_gametype_default_current && firstPlaceVotes == 0 )
+       if (gametypevote && autocvar_sv_vote_gametype_default_current && firstPlaceVotes == 0)
                firstPlace = currentPlace;
        else
                firstPlace = RandomSelection_chosen_float;
@@ -548,8 +564,12 @@ bool MapVote_CheckRules_2()
        if(firstPlace == -1)
                error("No first place in map vote... WTF?");
 
-       if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
+       if(secondPlace == -1 || time > mapvote_timeout
+               || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes
+               || mapvote_selections[mapvote_count - 1] == mapvote_voters)
+       {
                return MapVote_Finished(firstPlace);
+       }
 
        if(mapvote_keeptwotime)
                if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
@@ -585,7 +605,6 @@ bool MapVote_CheckRules_2()
 
 void MapVote_Tick()
 {
-
        MapVote_CheckRules_1(); // count
        if(MapVote_CheckRules_2()) // decide
                return;
@@ -647,6 +666,16 @@ void MapVote_Think()
        if(!mapvote_run)
                return;
 
+       if (mapvote_winner_time)
+       {
+               if (time > mapvote_winner_time + 1)
+               {
+                       Map_Goto_SetStr(mapvote_maps[mapvote_winner]);
+                       Map_Goto(0);
+               }
+               return;
+       }
+
        if(alreadychangedlevel)
                return;
 
@@ -655,6 +684,8 @@ void MapVote_Think()
        //dprint("tick\n");
 
        mapvote_nextthink = time + 0.5;
+       if (mapvote_nextthink > mapvote_timeout - 0.1) // make sure there's no delay when map vote times out
+               mapvote_nextthink = mapvote_timeout + 0.001;
 
        if(!mapvote_initialized)
        {
@@ -798,7 +829,7 @@ bool GameTypeVote_Start()
 
        mapvote_count_real = mapvote_count;
 
-       gametypevote = 1;
+       gametypevote = true;
 
        if ( really_available == 0 )
        {