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)
{
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)
{
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",
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)
{
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);
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;
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;
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.
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.