largest_team_player_count = player_count;
}
}
+ TeamBalance_Destroy(balance);
//PrintToChatAll(sprintf("Smallest team: %f", smallest_team_index));
//PrintToChatAll(sprintf("Largest team: %f", largest_team_index));
//PrintToChatAll(sprintf("Smallest team players: %f", smallest_team_player_count));
{
return;
}
- entity source_team = TeamBalance_GetTeamFromIndex(balance,
- largest_team_index);
- if (source_team.m_num_bots == 0)
- {
- TeamBalance_Destroy(balance);
- return;
- }
- TeamBalance_Destroy(balance);
- entity lowest_bot = NULL;
- if (MUTATOR_CALLHOOK(TeamBalance_GetPlayerForTeamSwitch, largest_team_index,
- smallest_team_index, true))
- {
- lowest_bot = M_ARGV(3, entity);
- }
- else
- {
- float lowest_score = FLOAT_MAX;
- FOREACH_CLIENT(IS_BOT_CLIENT(it) && (Entity_GetTeamIndex(it) ==
- largest_team_index),
- {
- float temp_score = PlayerScore_Get(it, SP_SCORE);
- if (temp_score >= lowest_score)
- {
- continue;
- }
- //PrintToChatAll(sprintf("Found %s with lowest score, checking allowed teams", it.netname));
- balance = TeamBalance_CheckAllowedTeams(it);
- if (TeamBalance_IsTeamAllowed(balance, smallest_team_index))
- {
- //PrintToChatAll("Allowed");
- lowest_bot = it;
- lowest_score = temp_score;
- }
- else
- {
- //PrintToChatAll("Not allowed");
- }
- TeamBalance_Destroy(balance);
- });
- }
+ entity lowest_bot = TeamBalance_GetPlayerForTeamSwitch(largest_team_index,
+ smallest_team_index, true);
if (lowest_bot == NULL)
{
//PrintToChatAll("No bot found");
KillPlayerForTeamChange(lowest_bot);
}
+entity TeamBalance_GetPlayerForTeamSwitch(int source_team_index,
+ int destination_team_index, bool is_bot)
+{
+ if (MUTATOR_CALLHOOK(TeamBalance_GetPlayerForTeamSwitch, source_team_index,
+ destination_team_index, is_bot))
+ {
+ return M_ARGV(3, entity);
+ }
+ entity lowest_player = NULL;
+ float lowest_score = FLOAT_MAX;
+ FOREACH_CLIENT(Entity_GetTeamIndex(it) == source_team_index,
+ {
+ if (IS_BOT_CLIENT(it) != is_bot)
+ {
+ continue;
+ }
+ float temp_score = PlayerScore_Get(it, SP_SCORE);
+ if (temp_score >= lowest_score)
+ {
+ continue;
+ }
+ //PrintToChatAll(sprintf(
+ // "Found %s with lowest score, checking allowed teams", it.netname));
+ entity balance = TeamBalance_CheckAllowedTeams(it);
+ if (TeamBalance_IsTeamAllowed(balance, source_team_index))
+ {
+ //PrintToChatAll("Allowed");
+ lowest_player = it;
+ lowest_score = temp_score;
+ }
+ else
+ {
+ //PrintToChatAll("Not allowed");
+ }
+ TeamBalance_Destroy(balance);
+ });
+ return lowest_player;
+}
+
bool TeamBalance_IsTeamAllowedInternal(entity balance, int index)
{
return balance.m_team_balance_team[index - 1].m_num_players !=
/// \brief Switches a bot from one team to another if teams are not balanced.
void TeamBalance_AutoBalanceBots();
+/// \brief Returns the player who is the most suitable for switching between
+/// the given teams.
+/// \param[in] source_team_index Index of the team to search in.
+/// \param[in] destination_team_index Index of the team to switch to.
+/// \param[in] is_bot True to search for bot, false for human.
+/// \return Player who is the most suitable for switching between the given
+/// teams or NULL if not found.
+entity TeamBalance_GetPlayerForTeamSwitch(int source_team_index,
+ int destination_team_index, bool is_bot);
+
// ============================ Internal API ==================================
/// \brief Returns whether the team change to the specified team is allowed.