void TeamBalance_JoinBestTeam(entity this)
{
//PrintToChatAll(sprintf("JoinBestTeam: %s", this.netname));
- // don't join a team if we're not playing a team game
if (!teamplay)
{
return;
}
-
- // find out what teams are available
- entity balance = TeamBalance_CheckAllowedTeams(this);
-
if (this.bot_forced_team)
{
+ return;
+ }
+ int old_team_index = Team_TeamToIndex(this.team);
+ entity balance = TeamBalance_CheckAllowedTeams(this);
+ if (this.team_forced > 0)
+ {
+ int forced_team_index = Team_TeamToIndex(this.team_forced);
+ bool is_team_allowed = TeamBalance_IsTeamAllowedInternal(balance,
+ forced_team_index);
TeamBalance_Destroy(balance);
+ if (!is_team_allowed)
+ {
+ return;
+ }
+ if (!SetPlayerTeam(this, forced_team_index, TEAM_CHANGE_AUTO))
+ {
+ return;
+ }
+ if ((old_team_index != -1) && !IS_BOT_CLIENT(this))
+ {
+ TeamBalance_AutoBalanceBots(forced_team_index, old_team_index);
+ }
return;
}
int best_team_index = TeamBalance_FindBestTeam(balance, this, true);
- int old_team_index = Team_TeamToIndex(this.team);
TeamBalance_Destroy(balance);
PlayerScore_Clear(this);
if (!SetPlayerTeam(this, best_team_index, TEAM_CHANGE_AUTO))