6 #include "scores_rules.qh"
10 #include "command/vote.qh"
12 #include "mutators/_mod.qh"
14 #include "../common/deathtypes/all.qh"
15 #include "../common/gamemodes/_mod.qh"
16 #include "../common/teams.qh"
18 /// \brief Describes a state of team balance entity.
21 TEAM_BALANCE_UNINITIALIZED, ///< The team balance has not been initialized.
22 /// \brief TeamBalance_CheckAllowedTeams has been called.
23 TEAM_BALANCE_TEAMS_CHECKED,
24 /// \brief TeamBalance_GetTeamCounts has been called.
25 TEAM_BALANCE_TEAM_COUNTS_FILLED
28 /// \brief Indicates that the player is not allowed to join a team.
29 const int TEAM_NOT_ALLOWED = -1;
31 .int m_team_balance_state; ///< Holds the state of the team balance entity.
32 .entity m_team_balance_team[NUM_TEAMS]; ///< ???
34 .float m_team_score; ///< The score of the team.
35 .int m_num_players; ///< Number of players (both humans and bots) in a team.
36 .int m_num_bots; ///< Number of bots in a team.
37 .int m_num_players_alive; ///< Number of alive players in a team.
38 .int m_num_control_points; ///< Number of control points owned by a team.
39 .entity m_lowest_human; ///< Human with the lowest score in a team.
40 .entity m_lowest_bot; ///< Bot with the lowest score in a team.
42 entity g_team_entities[NUM_TEAMS]; ///< Holds global team entities.
44 STATIC_INIT(g_team_entities)
46 for (int i = 0; i < NUM_TEAMS; ++i)
48 g_team_entities[i] = spawn();
52 entity Team_GetTeamFromIndex(int index)
54 if (!Team_IsValidIndex(index))
56 LOG_FATALF("Team_GetTeamFromIndex: Index is invalid: %f", index);
58 return g_team_entities[index - 1];
61 entity Team_GetTeam(int team_num)
63 if (!Team_IsValidTeam(team_num))
65 LOG_FATALF("Team_GetTeam: Value is invalid: %f", team_num);
67 return g_team_entities[Team_TeamToIndex(team_num) - 1];
70 float Team_GetTeamScore(entity team_)
72 return team_.m_team_score;
75 void Team_SetTeamScore(entity team_, float score)
77 team_.m_team_score = score;
80 int Team_GetNumberOfAlivePlayers(entity team_)
82 return team_.m_num_players_alive;
85 void Team_SetNumberOfAlivePlayers(entity team_, int number)
87 team_.m_num_players_alive = number;
90 int Team_GetNumberOfAliveTeams()
93 for (int i = 0; i < NUM_TEAMS; ++i)
95 if (g_team_entities[i].m_num_players_alive > 0)
103 int Team_GetNumberOfControlPoints(entity team_)
105 return team_.m_num_control_points;
108 void Team_SetNumberOfControlPoints(entity team_, int number)
110 team_.m_num_control_points = number;
113 int Team_GetNumberOfTeamsWithControlPoints()
116 for (int i = 0; i < NUM_TEAMS; ++i)
118 if (g_team_entities[i].m_num_control_points > 0)
126 void setcolor(entity this, int clr)
129 this.clientcolors = clr;
130 this.team = (clr & 15) + 1;
132 builtin_setcolor(this, clr);
136 bool Entity_HasValidTeam(entity this)
138 return Team_IsValidTeam(this.team);
141 int Entity_GetTeamIndex(entity this)
143 return Team_TeamToIndex(this.team);
146 entity Entity_GetTeam(entity this)
148 int index = Entity_GetTeamIndex(this);
149 if (!Team_IsValidIndex(index))
153 return Team_GetTeamFromIndex(index);
156 void SetPlayerColors(entity player, float _color)
158 float pants = _color & 0x0F;
159 float shirt = _color & 0xF0;
162 setcolor(player, 16 * pants + pants);
166 setcolor(player, shirt + pants);
170 bool Player_SetTeamIndex(entity player, int index)
172 int new_team = Team_IndexToTeam(index);
173 if (player.team == new_team)
175 // This is important when players join the game and one of their color
176 // matches the team color while other doesn't. For example [BOT]Lion.
177 SetPlayerColors(player, new_team - 1);
180 int old_index = Team_TeamToIndex(player.team);
181 if (MUTATOR_CALLHOOK(Player_ChangeTeam, player, old_index, index) == true)
183 // Mutator has blocked team change.
186 SetPlayerColors(player, new_team - 1);
187 MUTATOR_CALLHOOK(Player_ChangedTeam, player, old_index, index);
191 bool SetPlayerTeam(entity player, int destination_team_index,
192 int source_team_index, bool no_print)
194 if (!Player_SetTeamIndex(player, destination_team_index))
198 LogTeamchange(player.playerid, player.team, TEAM_CHANGE_MANUAL);
203 bprint(playername(player, false), "^7 has changed from ",
204 Team_IndexToColoredFullName(source_team_index), "^7 to ",
205 Team_IndexToColoredFullName(destination_team_index), "\n");
209 bool MoveToTeam(entity client, int team_index, int type)
211 int lockteams_backup = lockteams; // backup any team lock
212 lockteams = 0; // disable locked teams
213 PlayerScore_Clear(client);
214 if (!Player_SetTeamIndex(client, team_index))
216 lockteams = lockteams_backup; // restore the team lock
219 KillPlayerForTeamChange(client);
220 lockteams = lockteams_backup; // restore the team lock
221 LogTeamchange(client.playerid, client.team, type);
225 void KillPlayerForTeamChange(entity player)
231 if (MUTATOR_CALLHOOK(Player_ChangeTeamKill, player) == true)
235 Damage(player, player, player, 100000, DEATH_TEAMCHANGE.m_id, DMG_NOWEP,
236 player.origin, '0 0 0');
239 void LogTeamchange(float player_id, float team_number, int type)
241 if(!autocvar_sv_eventlog)
247 GameLogEcho(strcat(":team:", ftos(player_id), ":", ftos(team_number), ":", ftos(type)));
250 entity TeamBalance_CheckAllowedTeams(entity for_whom)
252 entity balance = spawn();
253 for (int i = 0; i < NUM_TEAMS; ++i)
255 entity team_ = balance.m_team_balance_team[i] = spawn();
256 team_.m_team_score = g_team_entities[i].m_team_score;
257 team_.m_num_players = TEAM_NOT_ALLOWED;
258 team_.m_num_bots = 0;
259 team_.m_lowest_human = NULL;
260 team_.m_lowest_bot = NULL;
264 string teament_name = string_null;
265 bool mutator_returnvalue = MUTATOR_CALLHOOK(TeamBalance_CheckAllowedTeams,
266 teams_mask, teament_name, for_whom);
267 teams_mask = M_ARGV(0, float);
268 teament_name = M_ARGV(1, string);
269 if (mutator_returnvalue)
271 for (int i = 0; i < NUM_TEAMS; ++i)
273 if (teams_mask & BIT(i))
275 balance.m_team_balance_team[i].m_num_players = 0;
282 entity head = find(NULL, classname, teament_name);
285 if (Team_IsValidTeam(head.team))
287 TeamBalance_GetTeam(balance, head.team).m_num_players = 0;
289 head = find(head, classname, teament_name);
293 // TODO: Balance quantity of bots across > 2 teams when bot_vs_human is set (and remove next line)
294 if (AvailableTeams() == 2)
295 if (autocvar_bot_vs_human && for_whom)
297 if (autocvar_bot_vs_human > 0)
299 // find last team available
300 if (IS_BOT_CLIENT(for_whom))
302 if (TeamBalance_IsTeamAllowedInternal(balance, 4))
304 TeamBalance_BanTeamsExcept(balance, 4);
306 else if (TeamBalance_IsTeamAllowedInternal(balance, 3))
308 TeamBalance_BanTeamsExcept(balance, 3);
312 TeamBalance_BanTeamsExcept(balance, 2);
314 // no further cases, we know at least 2 teams exist
318 if (TeamBalance_IsTeamAllowedInternal(balance, 1))
320 TeamBalance_BanTeamsExcept(balance, 1);
322 else if (TeamBalance_IsTeamAllowedInternal(balance, 2))
324 TeamBalance_BanTeamsExcept(balance, 2);
328 TeamBalance_BanTeamsExcept(balance, 3);
330 // no further cases, bots have one of the teams
335 // find first team available
336 if (IS_BOT_CLIENT(for_whom))
338 if (TeamBalance_IsTeamAllowedInternal(balance, 1))
340 TeamBalance_BanTeamsExcept(balance, 1);
342 else if (TeamBalance_IsTeamAllowedInternal(balance, 2))
344 TeamBalance_BanTeamsExcept(balance, 2);
348 TeamBalance_BanTeamsExcept(balance, 3);
350 // no further cases, we know at least 2 teams exist
354 if (TeamBalance_IsTeamAllowedInternal(balance, 4))
356 TeamBalance_BanTeamsExcept(balance, 4);
358 else if (TeamBalance_IsTeamAllowedInternal(balance, 3))
360 TeamBalance_BanTeamsExcept(balance, 3);
364 TeamBalance_BanTeamsExcept(balance, 2);
366 // no further cases, bots have one of the teams
373 balance.m_team_balance_state = TEAM_BALANCE_TEAMS_CHECKED;
377 // if player has a forced team, ONLY allow that one
378 for (int i = 1; i <= NUM_TEAMS; ++i)
380 if (for_whom.team_forced == Team_IndexToTeam(i) &&
381 TeamBalance_IsTeamAllowedInternal(balance, i))
383 TeamBalance_BanTeamsExcept(balance, i);
387 balance.m_team_balance_state = TEAM_BALANCE_TEAMS_CHECKED;
391 void TeamBalance_Destroy(entity balance)
397 for (int i = 0; i < NUM_TEAMS; ++i)
399 remove(balance.(m_team_balance_team[i]));
404 int TeamBalance_GetAllowedTeams(entity balance)
408 LOG_FATAL("TeamBalance_GetAllowedTeams: Team balance entity is NULL.");
410 if (balance.m_team_balance_state == TEAM_BALANCE_UNINITIALIZED)
412 LOG_FATAL("TeamBalance_GetAllowedTeams: "
413 "Team balance entity is not initialized.");
416 for (int i = 1; i <= NUM_TEAMS; ++i)
418 if (TeamBalance_IsTeamAllowedInternal(balance, i))
420 result |= Team_IndexToBit(i);
426 bool TeamBalance_IsTeamAllowed(entity balance, int index)
430 LOG_FATAL("TeamBalance_IsTeamAllowed: Team balance entity is NULL.");
432 if (balance.m_team_balance_state == TEAM_BALANCE_UNINITIALIZED)
434 LOG_FATAL("TeamBalance_IsTeamAllowed: "
435 "Team balance entity is not initialized.");
437 if (!Team_IsValidIndex(index))
439 LOG_FATALF("TeamBalance_IsTeamAllowed: Team index is invalid: %f",
442 return TeamBalance_IsTeamAllowedInternal(balance, index);
445 void TeamBalance_GetTeamCounts(entity balance, entity ignore)
449 LOG_FATAL("TeamBalance_GetTeamCounts: Team balance entity is NULL.");
451 if (balance.m_team_balance_state == TEAM_BALANCE_UNINITIALIZED)
453 LOG_FATAL("TeamBalance_GetTeamCounts: "
454 "Team balance entity is not initialized.");
456 if (MUTATOR_CALLHOOK(TeamBalance_GetTeamCounts) == true)
458 // Mutator has overriden the configuration.
459 for (int i = 1; i <= NUM_TEAMS; ++i)
461 entity team_ = TeamBalance_GetTeamFromIndex(balance, i);
462 if (TeamBalanceTeam_IsAllowed(team_))
464 MUTATOR_CALLHOOK(TeamBalance_GetTeamCount, i, ignore,
465 team_.m_num_players, team_.m_num_bots, team_.m_lowest_human,
467 team_.m_num_players = M_ARGV(2, float);
468 team_.m_num_bots = M_ARGV(3, float);
469 team_.m_lowest_human = M_ARGV(4, entity);
470 team_.m_lowest_bot = M_ARGV(5, entity);
476 // Manually count all players.
484 if (IS_PLAYER(it) || it.caplayer)
488 else if (it.team_forced > 0)
490 team_num = it.team_forced; // reserve the spot
496 if (!Team_IsValidTeam(team_num))
500 entity team_ = TeamBalance_GetTeam(balance, team_num);
501 if (!TeamBalanceTeam_IsAllowed(team_))
505 ++team_.m_num_players;
506 if (IS_BOT_CLIENT(it))
510 float temp_score = PlayerScore_Get(it, SP_SCORE);
511 if (!IS_BOT_CLIENT(it))
513 if (team_.m_lowest_human == NULL)
515 team_.m_lowest_human = it;
518 if (temp_score < PlayerScore_Get(team_.m_lowest_human,
521 team_.m_lowest_human = it;
525 if (team_.m_lowest_bot == NULL)
527 team_.m_lowest_bot = it;
530 if (temp_score < PlayerScore_Get(team_.m_lowest_bot, SP_SCORE))
532 team_.m_lowest_bot = it;
537 // if the player who has a forced team has not joined yet, reserve the spot
538 if (autocvar_g_campaign)
540 if (Team_IsValidIndex(autocvar_g_campaign_forceteam))
542 entity team_ = TeamBalance_GetTeamFromIndex(balance,
543 autocvar_g_campaign_forceteam);
544 if (team_.m_num_players == team_.m_num_bots)
546 ++team_.m_num_players;
550 balance.m_team_balance_state = TEAM_BALANCE_TEAM_COUNTS_FILLED;
553 int TeamBalance_GetNumberOfPlayers(entity balance, int index)
557 LOG_FATAL("TeamBalance_GetNumberOfPlayers: "
558 "Team balance entity is NULL.");
560 if (balance.m_team_balance_state != TEAM_BALANCE_TEAM_COUNTS_FILLED)
562 LOG_FATAL("TeamBalance_GetNumberOfPlayers: "
563 "TeamBalance_GetTeamCounts has not been called.");
565 if (!Team_IsValidIndex(index))
567 LOG_FATALF("TeamBalance_GetNumberOfPlayers: Team index is invalid: %f",
570 return balance.m_team_balance_team[index - 1].m_num_players;
573 int TeamBalance_FindBestTeam(entity balance, entity player, bool ignore_player)
577 LOG_FATAL("TeamBalance_FindBestTeam: Team balance entity is NULL.");
579 if (balance.m_team_balance_state == TEAM_BALANCE_UNINITIALIZED)
581 LOG_FATAL("TeamBalance_FindBestTeam: "
582 "Team balance entity is not initialized.");
584 // count how many players are in each team
587 TeamBalance_GetTeamCounts(balance, player);
591 TeamBalance_GetTeamCounts(balance, NULL);
593 int team_bits = TeamBalance_FindBestTeams(balance, player, true);
596 LOG_FATALF("TeamBalance_FindBestTeam: No teams available for %s\n",
597 MapInfo_Type_ToString(MapInfo_CurrentGametype()));
599 RandomSelection_Init();
600 for (int i = 1; i <= NUM_TEAMS; ++i)
602 if (team_bits & Team_IndexToBit(i))
604 RandomSelection_AddFloat(i, 1, 1);
607 return RandomSelection_chosen_float;
610 int TeamBalance_FindBestTeams(entity balance, entity player, bool use_score)
614 LOG_FATAL("TeamBalance_FindBestTeams: Team balance entity is NULL.");
616 if (balance.m_team_balance_state != TEAM_BALANCE_TEAM_COUNTS_FILLED)
618 LOG_FATAL("TeamBalance_FindBestTeams: "
619 "TeamBalance_GetTeamCounts has not been called.");
621 if (MUTATOR_CALLHOOK(TeamBalance_FindBestTeams, player) == true)
623 return M_ARGV(1, float);
626 int previous_team = 0;
627 for (int i = 1; i <= NUM_TEAMS; ++i)
629 if (!TeamBalance_IsTeamAllowedInternal(balance, i))
633 if (previous_team == 0)
635 team_bits = Team_IndexToBit(i);
639 int compare = TeamBalance_CompareTeams(balance, i, previous_team,
641 if (compare == TEAMS_COMPARE_LESS)
643 team_bits = Team_IndexToBit(i);
647 if (compare == TEAMS_COMPARE_EQUAL)
649 team_bits |= Team_IndexToBit(i);
656 void TeamBalance_JoinBestTeam(entity this, bool force_best_team)
658 // don't join a team if we're not playing a team game
664 // find out what teams are available
665 entity balance = TeamBalance_CheckAllowedTeams(this);
667 // if we don't care what team they end up on, put them on whatever team they entered as.
668 // if they're not on a valid team, then let other code put them on the smallest team
669 if (!force_best_team)
671 int selected_team_index = -1;
672 for (int i = 1; i <= NUM_TEAMS; ++i)
674 if (TeamBalance_IsTeamAllowedInternal(balance, i) &&
675 (Team_TeamToIndex(this.team) == i))
677 selected_team_index = i;
682 if (Team_IsValidIndex(selected_team_index))
684 Player_SetTeamIndex(this, selected_team_index);
685 LogTeamchange(this.playerid, this.team, TEAM_CHANGE_AUTO_RELAXED);
686 TeamBalance_Destroy(balance);
690 // otherwise end up on the smallest team (handled below)
691 if (this.bot_forced_team)
693 TeamBalance_Destroy(balance);
696 int best_team_index = TeamBalance_FindBestTeam(balance, this, true);
697 int old_team_index = Team_TeamToIndex(this.team);
698 PlayerScore_Clear(this);
699 Player_SetTeamIndex(this, best_team_index);
700 LogTeamchange(this.playerid, this.team, TEAM_CHANGE_AUTO);
701 if ((old_team_index != -1) && !IS_BOT_CLIENT(this))
703 TeamBalance_AutoBalanceBots(balance, old_team_index, best_team_index);
705 KillPlayerForTeamChange(this);
706 TeamBalance_Destroy(balance);
709 int TeamBalance_CompareTeams(entity balance, int team_index_a, int team_index_b,
710 entity player, bool use_score)
714 LOG_FATAL("TeamBalance_CompareTeams: Team balance entity is NULL.");
716 if (balance.m_team_balance_state != TEAM_BALANCE_TEAM_COUNTS_FILLED)
718 LOG_FATAL("TeamBalance_CompareTeams: "
719 "TeamBalance_GetTeamCounts has not been called.");
721 if (!Team_IsValidIndex(team_index_a))
723 LOG_FATALF("TeamBalance_CompareTeams: team_index_a is invalid: %f",
726 if (!Team_IsValidIndex(team_index_b))
728 LOG_FATALF("TeamBalance_CompareTeams: team_index_b is invalid: %f",
731 if (team_index_a == team_index_b)
733 return TEAMS_COMPARE_EQUAL;
735 entity team_a = TeamBalance_GetTeamFromIndex(balance, team_index_a);
736 entity team_b = TeamBalance_GetTeamFromIndex(balance, team_index_b);
737 return TeamBalance_CompareTeamsInternal(team_a, team_b, player, use_score);
740 void TeamBalance_AutoBalanceBots(entity balance, int source_team_index,
741 int destination_team_index)
745 LOG_FATAL("TeamBalance_AutoBalanceBots: Team balance entity is NULL.");
747 if (balance.m_team_balance_state != TEAM_BALANCE_TEAM_COUNTS_FILLED)
749 LOG_FATAL("TeamBalance_AutoBalanceBots: "
750 "TeamBalance_GetTeamCounts has not been called.");
752 if (!Team_IsValidIndex(source_team_index))
754 LOG_WARNF("AutoBalanceBots: Source team index is invalid: %f",
758 if (!Team_IsValidIndex(destination_team_index))
760 LOG_WARNF("AutoBalanceBots: Destination team index is invalid: %f",
761 destination_team_index);
764 if (!autocvar_g_balance_teams ||
765 !autocvar_g_balance_teams_prevent_imbalance)
769 entity source_team = TeamBalance_GetTeamFromIndex(balance,
771 if (!TeamBalanceTeam_IsAllowed(source_team))
775 entity destination_team = TeamBalance_GetTeamFromIndex(balance,
776 destination_team_index);
777 if ((destination_team.m_num_players <= source_team.m_num_players) ||
778 (destination_team.m_lowest_bot == NULL))
782 Player_SetTeamIndex(destination_team.m_lowest_bot, source_team_index);
783 KillPlayerForTeamChange(destination_team.m_lowest_bot);
786 bool TeamBalance_IsTeamAllowedInternal(entity balance, int index)
788 return balance.m_team_balance_team[index - 1].m_num_players !=
792 void TeamBalance_BanTeamsExcept(entity balance, int index)
794 for (int i = 1; i <= NUM_TEAMS; ++i)
798 balance.m_team_balance_team[i - 1].m_num_players = TEAM_NOT_ALLOWED;
803 entity TeamBalance_GetTeamFromIndex(entity balance, int index)
805 if (!Team_IsValidIndex(index))
807 LOG_FATALF("TeamBalance_GetTeamFromIndex: Index is invalid: %f", index);
809 return balance.m_team_balance_team[index - 1];
812 entity TeamBalance_GetTeam(entity balance, int team_num)
814 return TeamBalance_GetTeamFromIndex(balance, Team_TeamToIndex(team_num));
817 bool TeamBalanceTeam_IsAllowed(entity team_)
819 return team_.m_num_players != TEAM_NOT_ALLOWED;
822 int TeamBalanceTeam_GetNumberOfPlayers(entity team_)
824 return team_.m_num_players;
827 int TeamBalanceTeam_GetNumberOfBots(entity team_)
829 return team_.m_num_bots;
832 entity TeamBalanceTeam_GetLowestHuman(entity team_)
834 return team_.m_lowest_human;
837 entity TeamBalanceTeam_GetLowestBot(entity team_)
839 return team_.m_lowest_bot;
842 int TeamBalance_CompareTeamsInternal(entity team_a, entity team_b,
843 entity player, bool use_score)
845 if (team_a == team_b)
847 return TEAMS_COMPARE_EQUAL;
849 if (!TeamBalanceTeam_IsAllowed(team_a) ||
850 !TeamBalanceTeam_IsAllowed(team_b))
852 return TEAMS_COMPARE_INVALID;
854 int num_players_team_a = team_a.m_num_players;
855 int num_players_team_b = team_b.m_num_players;
856 if (IS_REAL_CLIENT(player) && bots_would_leave)
858 num_players_team_a -= team_a.m_num_bots;
859 num_players_team_b -= team_b.m_num_bots;
861 if (num_players_team_a < num_players_team_b)
863 return TEAMS_COMPARE_LESS;
865 if (num_players_team_a > num_players_team_b)
867 return TEAMS_COMPARE_GREATER;
871 return TEAMS_COMPARE_EQUAL;
873 if (team_a.m_team_score < team_b.m_team_score)
875 return TEAMS_COMPARE_LESS;
877 if (team_a.m_team_score > team_b.m_team_score)
879 return TEAMS_COMPARE_GREATER;
881 return TEAMS_COMPARE_EQUAL;
884 void SV_ChangeTeam(entity this, float _color)
886 int source_color, destination_color;
887 int source_team_index, destination_team_index;
889 // in normal deathmatch we can just apply the color and we're done
891 SetPlayerColors(this, _color);
895 // since this is an engine function, and gamecode doesn't have any calls earlier than this, do the connecting message here
896 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_CONNECTING, this.netname);
903 source_color = this.clientcolors & 0x0F;
904 destination_color = _color & 0x0F;
906 source_team_index = Team_TeamToIndex(source_color + 1);
907 destination_team_index = Team_TeamToIndex(destination_color + 1);
909 if (destination_team_index == -1)
914 entity balance = TeamBalance_CheckAllowedTeams(this);
916 if (destination_team_index == 1 && !TeamBalance_IsTeamAllowedInternal(
919 destination_team_index = 4;
921 if (destination_team_index == 4 && !TeamBalance_IsTeamAllowedInternal(
924 destination_team_index = 3;
926 if (destination_team_index == 3 && !TeamBalance_IsTeamAllowedInternal(
929 destination_team_index = 2;
931 if (destination_team_index == 2 && !TeamBalance_IsTeamAllowedInternal(
934 destination_team_index = 1;
937 // not changing teams
938 if (source_color == destination_color)
940 SetPlayerTeam(this, destination_team_index, source_team_index, true);
941 TeamBalance_Destroy(balance);
945 if((autocvar_g_campaign) || (autocvar_g_changeteam_banned && CS(this).wasplayer)) {
946 Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_TEAMCHANGE_NOTALLOWED);
947 return; // changing teams is not allowed
950 // autocvar_g_balance_teams_prevent_imbalance only makes sense if autocvar_g_balance_teams is on, as it makes the team selection dialog pointless
951 if (autocvar_g_balance_teams && autocvar_g_balance_teams_prevent_imbalance)
953 TeamBalance_GetTeamCounts(balance, this);
954 if ((Team_IndexToBit(destination_team_index) &
955 TeamBalance_FindBestTeams(balance, this, false)) == 0)
957 Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_TEAMCHANGE_LARGERTEAM);
958 TeamBalance_Destroy(balance);
962 if (IS_PLAYER(this) && source_team_index != destination_team_index)
964 // reduce frags during a team change
965 PlayerScore_Clear(this);
967 if (!SetPlayerTeam(this, destination_team_index, source_team_index,
970 TeamBalance_Destroy(balance);
973 TeamBalance_AutoBalanceBots(balance, source_team_index,
974 destination_team_index);
975 if (!IS_PLAYER(this) || (source_team_index == destination_team_index))
977 TeamBalance_Destroy(balance);
980 KillPlayerForTeamChange(this);
981 TeamBalance_Destroy(balance);