]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Better team balance function names.
authorLyberta <lyberta@lyberta.net>
Thu, 8 Mar 2018 16:27:50 +0000 (19:27 +0300)
committerLyberta <lyberta@lyberta.net>
Thu, 8 Mar 2018 16:27:50 +0000 (19:27 +0300)
qcsrc/server/bot/default/bot.qc
qcsrc/server/client.qc
qcsrc/server/command/cmd.qc
qcsrc/server/command/sv_cmd.qc
qcsrc/server/teamplay.qc
qcsrc/server/teamplay.qh

index 2f579aaf8da187ff36cce89bb3fd851913946bd4..ec6ee35d339f35fef8c41c1ef705ac54146e5d84 100644 (file)
@@ -438,7 +438,7 @@ void bot_clientconnect(entity this)
        else if(this.bot_forced_team==4)
                this.team = NUM_TEAM_4;
        else
-               JoinBestTeam(this, true);
+               JoinBestTeamForBalance(this, true);
 
        havocbot_setupbot(this);
 }
index 48ea4c261d53bed840246686abfcba9543e55e77..4109818ab5baa09ea868152029bbad30681f48cb 100644 (file)
@@ -516,7 +516,7 @@ void PutPlayerInServer(entity this)
        accuracy_resend(this);
 
        if (this.team < 0)
-               JoinBestTeam(this, true);
+               JoinBestTeamForBalance(this, true);
 
        entity spot = SelectSpawnPoint(this, false);
        if (!spot) {
@@ -903,7 +903,7 @@ void ClientKill_Now_TeamChange(entity this)
 {
        if(this.killindicator_teamchange == -1)
        {
-               JoinBestTeam( this, true );
+               JoinBestTeamForBalance(this, true);
        }
        else if(this.killindicator_teamchange == -2)
        {
@@ -1216,7 +1216,7 @@ void ClientConnect(entity this)
 
        int playerid_save = this.playerid;
        this.playerid = 0; // silent
-       JoinBestTeam(this, false); // if the team number is valid, keep it
+       JoinBestTeamForBalance(this, false); // if the team number is valid, keep it
        this.playerid = playerid_save;
 
        if (autocvar_sv_spectate || autocvar_g_campaign || this.team_forced < 0) {
@@ -2006,7 +2006,7 @@ void Join(entity this)
 
        if(!this.team_selected)
        if(autocvar_g_campaign || autocvar_g_balance_teams)
-               JoinBestTeam(this, true);
+               JoinBestTeamForBalance(this, true);
 
        if(autocvar_g_campaign)
                campaign_bots_may_start = true;
index 088925f100f2f3f47499a4be5a72bcac7861bf15..2314f71033c85bc664366607011b0714761eeb6a 100644 (file)
@@ -396,7 +396,7 @@ void ClientCommand_selectteam(entity caller, float request, float argc)
                        {
                                CheckAllowedTeams(caller);
                                GetTeamCounts(caller);
-                               if ((BIT(Team_TeamToNumber(selection) - 1) & FindBestTeams(caller, false)) == 0)
+                               if ((BIT(Team_TeamToNumber(selection) - 1) & FindBestTeamsForBalance(caller, false)) == 0)
                                {
                                        Send_Notification(NOTIF_ONE, caller, MSG_INFO, INFO_TEAMCHANGE_LARGERTEAM);
                                        return;
index 0e2d92557ef7fad21a13287a55c8e6ba3836741f..d7ede6af4b9e7b8bdb99d0175c8e05053a3f0d4f 100644 (file)
@@ -1073,7 +1073,7 @@ void GameCommand_moveplayer(float request, float argc)
                                                                else if (team_id == 0)  // auto team
                                                                {
                                                                        CheckAllowedTeams(client);
-                                                                       team_id = Team_NumberToTeam(FindBestTeam(client, false));
+                                                                       team_id = Team_NumberToTeam(FindBestTeamForBalance(client, false));
                                                                }
                                                                else
                                                                {
index 8b92f86b29d97874f7d96a009561c6b1015f7186..aa2a44b2920e41165fad693e2a676294cf3fa0e9 100644 (file)
@@ -595,93 +595,7 @@ bool SetPlayerTeam(entity player, int destination_team_index,
        return true;
 }
 
-bool IsTeamSmallerThanTeam(int team_index_a, int team_index_b, entity player,
-       bool use_score)
-{
-       if (!Team_IsValidIndex(team_index_a))
-       {
-               LOG_FATALF("IsTeamSmallerThanTeam: team_index_a is invalid: %f",
-                       team_index_a);
-       }
-       if (!Team_IsValidIndex(team_index_b))
-       {
-               LOG_FATALF("IsTeamSmallerThanTeam: team_index_b is invalid: %f",
-                       team_index_b);
-       }
-       if (team_index_a == team_index_b)
-       {
-               return false;
-       }
-       entity team_a = Team_GetTeamFromIndex(team_index_a);
-       entity team_b = Team_GetTeamFromIndex(team_index_b);
-       if (!Team_IsAllowed(team_a) || !Team_IsAllowed(team_b))
-       {
-               return false;
-       }
-       int num_players_team_a = team_a.m_num_players;
-       int num_players_team_b = team_b.m_num_players;
-       if (IS_REAL_CLIENT(player) && bots_would_leave)
-       {
-               num_players_team_a -= team_a.m_num_bots;
-               num_players_team_b -= team_b.m_num_bots;
-       }
-       if (!use_score)
-       {
-               return num_players_team_a < num_players_team_b;
-       }
-       if (num_players_team_a < num_players_team_b)
-       {
-               return true;
-       }
-       if (num_players_team_a > num_players_team_b)
-       {
-               return false;
-       }
-       return team_a.m_team_score < team_b.m_team_score;
-}
-
-bool IsTeamEqualToTeam(int team_index_a, int team_index_b, entity player,
-       bool use_score)
-{
-       if (!Team_IsValidIndex(team_index_a))
-       {
-               LOG_FATALF("IsTeamEqualToTeam: team_index_a is invalid: %f",
-                       team_index_a);
-       }
-       if (!Team_IsValidIndex(team_index_b))
-       {
-               LOG_FATALF("IsTeamEqualToTeam: team_index_b is invalid: %f",
-                       team_index_b);
-       }
-       if (team_index_a == team_index_b)
-       {
-               return true;
-       }
-       entity team_a = Team_GetTeamFromIndex(team_index_a);
-       entity team_b = Team_GetTeamFromIndex(team_index_b);
-       if (!Team_IsAllowed(team_a) || !Team_IsAllowed(team_b))
-       {
-               return false;
-       }
-       int num_players_team_a = team_a.m_num_players;
-       int num_players_team_b = team_b.m_num_players;
-       if (IS_REAL_CLIENT(player) && bots_would_leave)
-       {
-               num_players_team_a -= team_a.m_num_bots;
-               num_players_team_b -= team_b.m_num_bots;
-       }
-       if (!use_score)
-       {
-               return num_players_team_a == num_players_team_b;
-       }
-       if (num_players_team_a != num_players_team_b)
-       {
-               return false;
-       }
-       return team_a.m_team_score == team_b.m_team_score;
-}
-
-int FindBestTeams(entity player, bool use_score)
+int FindBestTeamsForBalance(entity player, bool use_score)
 {
        if (MUTATOR_CALLHOOK(FindBestTeams, player) == true)
        {
@@ -748,7 +662,7 @@ int FindBestTeams(entity player, bool use_score)
        return team_bits;
 }
 
-int FindBestTeam(entity player, float ignore_player)
+int FindBestTeamForBalance(entity player, float ignore_player)
 {
        // count how many players are in each team
        if (ignore_player)
@@ -759,7 +673,7 @@ int FindBestTeam(entity player, float ignore_player)
        {
                GetTeamCounts(NULL);
        }
-       int team_bits = FindBestTeams(player, true);
+       int team_bits = FindBestTeamsForBalance(player, true);
        if (team_bits == 0)
        {
                LOG_FATALF("FindBestTeam: No teams available for %s\n",
@@ -785,7 +699,7 @@ int FindBestTeam(entity player, float ignore_player)
        return RandomSelection_chosen_float;
 }
 
-void JoinBestTeam(entity this, bool force_best_team)
+void JoinBestTeamForBalance(entity this, bool force_best_team)
 {
        // don't join a team if we're not playing a team game
        if (!teamplay)
@@ -823,7 +737,7 @@ void JoinBestTeam(entity this, bool force_best_team)
        {
                return;
        }
-       int best_team_index = FindBestTeam(this, true);
+       int best_team_index = FindBestTeamForBalance(this, true);
        int best_team_num = Team_NumberToTeam(best_team_index);
        int old_team_index = Team_TeamToNumber(this.team);
        TeamchangeFrags(this);
@@ -836,6 +750,92 @@ void JoinBestTeam(entity this, bool force_best_team)
        KillPlayerForTeamChange(this);
 }
 
+bool IsTeamSmallerThanTeam(int team_index_a, int team_index_b, entity player,
+       bool use_score)
+{
+       if (!Team_IsValidIndex(team_index_a))
+       {
+               LOG_FATALF("IsTeamSmallerThanTeam: team_index_a is invalid: %f",
+                       team_index_a);
+       }
+       if (!Team_IsValidIndex(team_index_b))
+       {
+               LOG_FATALF("IsTeamSmallerThanTeam: team_index_b is invalid: %f",
+                       team_index_b);
+       }
+       if (team_index_a == team_index_b)
+       {
+               return false;
+       }
+       entity team_a = Team_GetTeamFromIndex(team_index_a);
+       entity team_b = Team_GetTeamFromIndex(team_index_b);
+       if (!Team_IsAllowed(team_a) || !Team_IsAllowed(team_b))
+       {
+               return false;
+       }
+       int num_players_team_a = team_a.m_num_players;
+       int num_players_team_b = team_b.m_num_players;
+       if (IS_REAL_CLIENT(player) && bots_would_leave)
+       {
+               num_players_team_a -= team_a.m_num_bots;
+               num_players_team_b -= team_b.m_num_bots;
+       }
+       if (!use_score)
+       {
+               return num_players_team_a < num_players_team_b;
+       }
+       if (num_players_team_a < num_players_team_b)
+       {
+               return true;
+       }
+       if (num_players_team_a > num_players_team_b)
+       {
+               return false;
+       }
+       return team_a.m_team_score < team_b.m_team_score;
+}
+
+bool IsTeamEqualToTeam(int team_index_a, int team_index_b, entity player,
+       bool use_score)
+{
+       if (!Team_IsValidIndex(team_index_a))
+       {
+               LOG_FATALF("IsTeamEqualToTeam: team_index_a is invalid: %f",
+                       team_index_a);
+       }
+       if (!Team_IsValidIndex(team_index_b))
+       {
+               LOG_FATALF("IsTeamEqualToTeam: team_index_b is invalid: %f",
+                       team_index_b);
+       }
+       if (team_index_a == team_index_b)
+       {
+               return true;
+       }
+       entity team_a = Team_GetTeamFromIndex(team_index_a);
+       entity team_b = Team_GetTeamFromIndex(team_index_b);
+       if (!Team_IsAllowed(team_a) || !Team_IsAllowed(team_b))
+       {
+               return false;
+       }
+       int num_players_team_a = team_a.m_num_players;
+       int num_players_team_b = team_b.m_num_players;
+       if (IS_REAL_CLIENT(player) && bots_would_leave)
+       {
+               num_players_team_a -= team_a.m_num_bots;
+               num_players_team_b -= team_b.m_num_bots;
+       }
+       if (!use_score)
+       {
+               return num_players_team_a == num_players_team_b;
+       }
+       if (num_players_team_a != num_players_team_b)
+       {
+               return false;
+       }
+       return team_a.m_team_score == team_b.m_team_score;
+}
+
 void SV_ChangeTeam(entity this, float _color)
 {
        int source_color, destination_color;
@@ -889,7 +889,7 @@ void SV_ChangeTeam(entity this, float _color)
        if (autocvar_g_balance_teams && autocvar_g_balance_teams_prevent_imbalance)
        {
                GetTeamCounts(this);
-               if ((BIT(destination_team_index - 1) & FindBestTeams(this, false)) == 0)
+               if ((BIT(destination_team_index - 1) & FindBestTeamsForBalance(this, false)) == 0)
                {
                        Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_TEAMCHANGE_LARGERTEAM);
                        return;
index 85dca1ac4f9da93ca3702596fbbca8ce164a7feb..71b73b240fde3785c4b03eed1aca6b9ca6c0fa7c 100644 (file)
@@ -118,6 +118,27 @@ bool SetPlayerTeamSimple(entity player, int team_num);
 bool SetPlayerTeam(entity player, int destination_team_index,
        int source_team_index, bool no_print);
 
+/// \brief Returns the bitmask of the teams that will make the game most
+/// balanced if the player joins any of them.
+/// \param[in] player Player to check.
+/// \param[in] use_score Whether to take into account team scores.
+/// \return Bitmask of the teams that will make the game most balanced if the
+/// player joins any of them.
+/// \note You need to call CheckAllowedTeams and GetTeamCounts before calling
+/// this function.
+int FindBestTeamsForBalance(entity player, bool use_score);
+
+/// \brief Finds the team that will make the game most balanced if the player
+/// joins it.
+/// \param[in] player Player to check.
+/// \param[in] ignore_player ???
+/// \return Index of the team that will make the game most balanced if the
+/// player joins it. If there are several equally good teams available, the
+/// function will pick a random one.
+int FindBestTeamForBalance(entity player, float ignore_player);
+
+void JoinBestTeamForBalance(entity this, bool force_best_team);
+
 /// \brief Returns whether one team is smaller than the other.
 /// \param[in] team_index_a Index of the first team.
 /// \param[in] team_index_b Index of the second team.
@@ -140,23 +161,6 @@ bool IsTeamSmallerThanTeam(int team_index_a, int team_index_b, entity player,
 bool IsTeamEqualToTeam(int team_index_a, int team_index_b, entity player,
        bool use_score);
 
-/// \brief Returns the bitmask of the best teams for the player to join.
-/// \param[in] player Player to check.
-/// \param[in] use_score Whether to take into account team scores.
-/// \return Bitmask of the best teams for the player to join.
-/// \note You need to call CheckAllowedTeams and GetTeamCounts before calling
-/// this function.
-int FindBestTeams(entity player, bool use_score);
-
-/// \brief Finds the best team for the player.
-/// \param[in] player Player to check.
-/// \param[in] ignore_player ???
-/// \return Index of the best team for the player. If there are several equally
-/// good teams available, the function will pick a random one.
-int FindBestTeam(entity player, float ignore_player);
-
-void JoinBestTeam(entity this, bool force_best_team);
-
 /// \brief Auto balances bots in teams after the player has changed team.
 /// \param[in] source_team_index Previous index of the team of the player.
 /// \param[in] destination_team_index Current index of the team of the player.