]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
fix shuffleteams
authorMartin Taibr <taibr.martin@gmail.com>
Fri, 25 Nov 2016 22:52:42 +0000 (23:52 +0100)
committerMartin Taibr <taibr.martin@gmail.com>
Fri, 25 Nov 2016 22:52:42 +0000 (23:52 +0100)
qcsrc/server/command/sv_cmd.qc
qcsrc/server/command/sv_cmd.qh

index 1e5fedbcb65b79d209fff4de1fd2e7b11045a861..b9ac09f1960d2bbcc0eb65248ef59147fe5d5fc3 100644 (file)
@@ -34,7 +34,6 @@ void PutObserverInServer(entity this);
 
 // =====================================================
 //  Server side game commands code, reworked by Samual
-//  Last updated: December 29th, 2011
 // =====================================================
 
 //  used by GameCommand_make_mapinfo()
@@ -1326,90 +1325,27 @@ void GameCommand_shuffleteams(float request)
        {
                case CMD_REQUEST_COMMAND:
                {
-                       if (teamplay)
-                       {
-                               float t_teams, t_players, team_color;
-
-                               // count the total amount of players and total amount of teams
-                               t_players = 0;
-                               t_teams = 0;
-                               FOREACH_CLIENT(IS_PLAYER(it) || it.caplayer, LAMBDA(
-                                       CheckAllowedTeams(it);
-
-                                       if (c1 >= 0) t_teams = max(1, t_teams);
-                                       if (c2 >= 0) t_teams = max(2, t_teams);
-                                       if (c3 >= 0) t_teams = max(3, t_teams);
-                                       if (c4 >= 0) t_teams = max(4, t_teams);
-
-                                       ++t_players;
-                               ));
-
-                               // build a list of the players in a random order
-                               FOREACH_CLIENT(IS_PLAYER(it) || it.caplayer, LAMBDA(
-                                       for ( ; ; )
-                                       {
-                                               int idx = bound(1, floor(random() * maxclients) + 1, maxclients);
-
-                                               if (shuffleteams_players[idx])
-                                               {
-                                                       continue;  // a player is already assigned to this slot
-                                               }
-                                               else
-                                               {
-                                                       shuffleteams_players[idx] = etof(it);
-                                                       break;
-                                               }
-                                       }
-                               ));
-
-                               // finally, from the list made earlier, re-join the players in different order.
-                               for (int i = 1; i <= t_teams; ++i)
-                               {
-                                       // find out how many players to assign to this team
-                                       int pnum = (t_players / t_teams);
-                                       pnum = ((i == 1) ? ceil(pnum) : floor(pnum));
-
-                                       team_color = Team_NumberToTeam(i);
-
-                                       // sort through the random list of players made earlier
-                                       for (int z = 1; z <= maxclients; ++z)
-                                       {
-                                               if (!(shuffleteams_teams[i] >= pnum))
-                                               {
-                                                       if (!(shuffleteams_players[z])) continue;  // not a player, move on to next random slot
-
-                                                       entity e = NULL;
-                                                       if(VerifyClientNumber(shuffleteams_players[z]))
-                                                               e = edict_num(shuffleteams_players[z]);
-
-                                                       if(!e) continue; // unverified
-
-                                                       if (e.team != team_color) MoveToTeam(e, team_color, 6);
-
-                                                       shuffleteams_players[z] = 0;
-                                                       shuffleteams_teams[i] = shuffleteams_teams[i] + 1;
-                                               }
-                                               else
-                                               {
-                                                       break;  // move on to next team
-                                               }
-                                       }
-                               }
-
-                               bprint("Successfully shuffled the players around randomly.\n");
-
-                               // clear the buffers now
-                               for (int i = 0; i < SHUFFLETEAMS_MAX_PLAYERS; ++i)
-                                       shuffleteams_players[i] = 0;
-
-                               for (int i = 0; i < SHUFFLETEAMS_MAX_TEAMS; ++i)
-                                       shuffleteams_teams[i] = 0;
-                       }
-                       else
+                       if (!teamplay)
                        {
                                LOG_INFO("Can't shuffle teams when currently not playing a team game.\n");
+                               return;
                        }
 
+                       int number_of_teams = 0;
+                       CheckAllowedTeams(NULL);
+                       if (c1 >= 0) number_of_teams = max(1, number_of_teams);
+                       if (c2 >= 0) number_of_teams = max(2, number_of_teams);
+                       if (c3 >= 0) number_of_teams = max(3, number_of_teams);
+                       if (c4 >= 0) number_of_teams = max(4, number_of_teams);
+
+                       int team_index = 0;
+                       FOREACH_CLIENT_RANDOM(IS_PLAYER(it) || it.caplayer, LAMBDA(
+                               int target_team_number = Team_NumberToTeam(team_index + 1);
+                               if (it.team != target_team_number) MoveToTeam(it, target_team_number, 6);
+                               team_index = (team_index + 1) % number_of_teams;
+                       ));
+
+                       bprint("Successfully shuffled the players around randomly.\n");
                        return;
                }
 
index 29db3ee4df20d5edd5c4f4614ca5fccc1f5b16b9..00e216c921855757b9a5aa87c23cfe5362fdbf9b 100644 (file)
@@ -2,17 +2,11 @@
 
 // =================================================
 //  Declarations for server side game commands
-//  Last updated: December 25th, 2011
 // =================================================
 
 string GotoMap(string m);
 
 void race_deleteTime(string map, float pos);
 
-const float SHUFFLETEAMS_MAX_PLAYERS = 255;
-const float SHUFFLETEAMS_MAX_TEAMS = 4;
-float shuffleteams_players[SHUFFLETEAMS_MAX_PLAYERS]; // maximum of 255 player slots
-float shuffleteams_teams[SHUFFLETEAMS_MAX_TEAMS];     // maximum of 4 teams
-
 // used by common/command/generic.qc:GenericCommand_dumpcommands to list all commands into a .txt file
 void GameCommand_macro_write_aliases(float fh);