6 #include "scores_rules.qh"
10 #include "command/vote.qh"
12 #include <server/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.
40 entity g_team_entities[NUM_TEAMS]; ///< Holds global team entities.
42 STATIC_INIT(g_team_entities)
44 for (int i = 0; i < NUM_TEAMS; ++i)
46 g_team_entities[i] = spawn();
50 entity Team_GetTeamFromIndex(int index)
52 if (!Team_IsValidIndex(index))
54 LOG_FATALF("Team_GetTeamFromIndex: Index is invalid: %f", index);
56 return g_team_entities[index - 1];
59 entity Team_GetTeam(int team_num)
61 if (!Team_IsValidTeam(team_num))
63 LOG_FATALF("Team_GetTeam: Value is invalid: %f", team_num);
65 return g_team_entities[Team_TeamToIndex(team_num) - 1];
68 float Team_GetTeamScore(entity team_ent)
70 return team_ent.m_team_score;
73 void Team_SetTeamScore(entity team_ent, float score)
75 team_ent.m_team_score = score;
78 int Team_GetNumberOfAlivePlayers(entity team_ent)
80 return team_ent.m_num_players_alive;
83 void Team_SetNumberOfAlivePlayers(entity team_ent, int number)
85 team_ent.m_num_players_alive = number;
88 int Team_GetNumberOfAliveTeams()
91 for (int i = 0; i < NUM_TEAMS; ++i)
93 if (g_team_entities[i].m_num_players_alive > 0)
101 int Team_GetNumberOfControlPoints(entity team_ent)
103 return team_ent.m_num_control_points;
106 void Team_SetNumberOfControlPoints(entity team_ent, int number)
108 team_ent.m_num_control_points = number;
111 int Team_GetNumberOfTeamsWithControlPoints()
114 for (int i = 0; i < NUM_TEAMS; ++i)
116 if (g_team_entities[i].m_num_control_points > 0)
124 void setcolor(entity this, int clr)
127 this.clientcolors = clr;
128 this.team = (clr & 15) + 1;
130 builtin_setcolor(this, clr);
134 bool Entity_HasValidTeam(entity this)
136 return Team_IsValidTeam(this.team);
139 int Entity_GetTeamIndex(entity this)
141 return Team_TeamToIndex(this.team);
144 entity Entity_GetTeam(entity this)
146 int index = Entity_GetTeamIndex(this);
147 if (!Team_IsValidIndex(index))
151 return Team_GetTeamFromIndex(index);
154 void SetPlayerColors(entity player, float _color)
156 float pants = _color & 0x0F;
157 float shirt = _color & 0xF0;
160 setcolor(player, 16 * pants + pants);
164 setcolor(player, shirt + pants);
168 bool Player_SetTeamIndex(entity player, int index)
170 int new_team = Team_IndexToTeam(index);
171 if (player.team == new_team)
175 // This is important when players join the game and one of their
176 // color matches the team color while other doesn't. For example
178 SetPlayerColors(player, new_team - 1);
182 int old_index = Team_TeamToIndex(player.team);
183 if (MUTATOR_CALLHOOK(Player_ChangeTeam, player, old_index, index) == true)
185 // Mutator has blocked team change.
194 SetPlayerColors(player, new_team - 1);
196 MUTATOR_CALLHOOK(Player_ChangedTeam, player, old_index, index);
200 bool SetPlayerTeam(entity player, int team_index, int type)
202 int old_team_index = Entity_GetTeamIndex(player);
203 if (!Player_SetTeamIndex(player, team_index))
207 LogTeamchange(player.playerid, player.team, type);
208 if (team_index != old_team_index)
210 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(player.team,
211 INFO_JOIN_PLAY_TEAM), player.netname);
212 KillPlayerForTeamChange(player);
217 bool MoveToTeam(entity client, int team_index, int type)
219 //PrintToChatAll(sprintf("MoveToTeam: %s, %f", client.netname, team_index));
220 int lockteams_backup = lockteams; // backup any team lock
221 lockteams = 0; // disable locked teams
222 PlayerScore_Clear(client);
223 if (!SetPlayerTeam(client, team_index, type))
225 lockteams = lockteams_backup; // restore the team lock
228 lockteams = lockteams_backup; // restore the team lock
232 void KillPlayerForTeamChange(entity player)
238 if (MUTATOR_CALLHOOK(Player_ChangeTeamKill, player) == true)
242 Damage(player, player, player, 100000, DEATH_TEAMCHANGE.m_id, DMG_NOWEP,
243 player.origin, '0 0 0');
246 void LogTeamchange(float player_id, float team_number, int type)
248 if(!autocvar_sv_eventlog)
254 GameLogEcho(strcat(":team:", ftos(player_id), ":", ftos(team_number), ":", ftos(type)));
257 entity TeamBalance_CheckAllowedTeams(entity for_whom)
259 entity balance = spawn();
260 for (int i = 0; i < NUM_TEAMS; ++i)
262 entity team_ent = balance.m_team_balance_team[i] = spawn();
263 team_ent.m_team_score = g_team_entities[i].m_team_score;
264 team_ent.m_num_players = TEAM_NOT_ALLOWED;
265 team_ent.m_num_bots = 0;
267 setthink(balance, TeamBalance_Destroy);
270 string teament_name = string_null;
271 bool mutator_returnvalue = MUTATOR_CALLHOOK(TeamBalance_CheckAllowedTeams,
272 teams_mask, teament_name, for_whom);
273 teams_mask = M_ARGV(0, float);
274 teament_name = M_ARGV(1, string);
275 if (mutator_returnvalue)
277 for (int i = 0; i < NUM_TEAMS; ++i)
279 if (teams_mask & BIT(i))
281 balance.m_team_balance_team[i].m_num_players = 0;
288 entity head = find(NULL, classname, teament_name);
291 if (Team_IsValidTeam(head.team))
293 TeamBalance_GetTeam(balance, head.team).m_num_players = 0;
295 head = find(head, classname, teament_name);
299 // TODO: Balance quantity of bots across > 2 teams when bot_vs_human is set (and remove next line)
300 if (AvailableTeams() == 2)
301 if (autocvar_bot_vs_human && for_whom)
303 if (autocvar_bot_vs_human > 0)
305 // find last team available
306 if (IS_BOT_CLIENT(for_whom))
308 if (TeamBalance_IsTeamAllowedInternal(balance, 4))
310 TeamBalance_BanTeamsExcept(balance, 4);
312 else if (TeamBalance_IsTeamAllowedInternal(balance, 3))
314 TeamBalance_BanTeamsExcept(balance, 3);
318 TeamBalance_BanTeamsExcept(balance, 2);
320 // no further cases, we know at least 2 teams exist
324 if (TeamBalance_IsTeamAllowedInternal(balance, 1))
326 TeamBalance_BanTeamsExcept(balance, 1);
328 else if (TeamBalance_IsTeamAllowedInternal(balance, 2))
330 TeamBalance_BanTeamsExcept(balance, 2);
334 TeamBalance_BanTeamsExcept(balance, 3);
336 // no further cases, bots have one of the teams
341 // find first team available
342 if (IS_BOT_CLIENT(for_whom))
344 if (TeamBalance_IsTeamAllowedInternal(balance, 1))
346 TeamBalance_BanTeamsExcept(balance, 1);
348 else if (TeamBalance_IsTeamAllowedInternal(balance, 2))
350 TeamBalance_BanTeamsExcept(balance, 2);
354 TeamBalance_BanTeamsExcept(balance, 3);
356 // no further cases, we know at least 2 teams exist
360 if (TeamBalance_IsTeamAllowedInternal(balance, 4))
362 TeamBalance_BanTeamsExcept(balance, 4);
364 else if (TeamBalance_IsTeamAllowedInternal(balance, 3))
366 TeamBalance_BanTeamsExcept(balance, 3);
370 TeamBalance_BanTeamsExcept(balance, 2);
372 // no further cases, bots have one of the teams
379 balance.m_team_balance_state = TEAM_BALANCE_TEAMS_CHECKED;
383 // if player has a forced team, ONLY allow that one
384 for (int i = 1; i <= NUM_TEAMS; ++i)
386 if (for_whom.team_forced == Team_IndexToTeam(i) &&
387 TeamBalance_IsTeamAllowedInternal(balance, i))
389 TeamBalance_BanTeamsExcept(balance, i);
393 balance.m_team_balance_state = TEAM_BALANCE_TEAMS_CHECKED;
397 void TeamBalance_Destroy(entity balance)
403 for (int i = 0; i < NUM_TEAMS; ++i)
405 delete(balance.(m_team_balance_team[i]));
410 int TeamBalance_GetAllowedTeams(entity balance)
414 LOG_FATAL("TeamBalance_GetAllowedTeams: Team balance entity is NULL.");
416 if (balance.m_team_balance_state == TEAM_BALANCE_UNINITIALIZED)
418 LOG_FATAL("TeamBalance_GetAllowedTeams: "
419 "Team balance entity is not initialized.");
422 for (int i = 1; i <= NUM_TEAMS; ++i)
424 if (TeamBalance_IsTeamAllowedInternal(balance, i))
426 result |= Team_IndexToBit(i);
432 bool TeamBalance_IsTeamAllowed(entity balance, int index)
436 LOG_FATAL("TeamBalance_IsTeamAllowed: Team balance entity is NULL.");
438 if (balance.m_team_balance_state == TEAM_BALANCE_UNINITIALIZED)
440 LOG_FATAL("TeamBalance_IsTeamAllowed: "
441 "Team balance entity is not initialized.");
443 if (!Team_IsValidIndex(index))
445 LOG_FATALF("TeamBalance_IsTeamAllowed: Team index is invalid: %f",
448 return TeamBalance_IsTeamAllowedInternal(balance, index);
451 void TeamBalance_GetTeamCounts(entity balance, entity ignore)
455 LOG_FATAL("TeamBalance_GetTeamCounts: Team balance entity is NULL.");
457 if (balance.m_team_balance_state == TEAM_BALANCE_UNINITIALIZED)
459 LOG_FATAL("TeamBalance_GetTeamCounts: "
460 "Team balance entity is not initialized.");
462 if (MUTATOR_CALLHOOK(TeamBalance_GetTeamCounts) == true)
464 // Mutator has overriden the configuration.
465 for (int i = 1; i <= NUM_TEAMS; ++i)
467 entity team_ent = TeamBalance_GetTeamFromIndex(balance, i);
468 if (TeamBalanceTeam_IsAllowed(team_ent))
470 MUTATOR_CALLHOOK(TeamBalance_GetTeamCount, i, ignore);
471 team_ent.m_num_players = M_ARGV(2, float);
472 team_ent.m_num_bots = M_ARGV(3, float);
478 // Manually count all players.
486 if (IS_PLAYER(it) || it.caplayer)
490 else if (it.team_forced > 0)
492 team_num = it.team_forced; // reserve the spot
498 if (!Team_IsValidTeam(team_num))
502 entity team_ent = TeamBalance_GetTeam(balance, team_num);
503 if (!TeamBalanceTeam_IsAllowed(team_ent))
507 ++team_ent.m_num_players;
508 if (IS_BOT_CLIENT(it))
510 ++team_ent.m_num_bots;
515 // if the player who has a forced team has not joined yet, reserve the spot
516 if (autocvar_g_campaign)
518 if (Team_IsValidIndex(autocvar_g_campaign_forceteam))
520 entity team_ent = TeamBalance_GetTeamFromIndex(balance,
521 autocvar_g_campaign_forceteam);
522 if (team_ent.m_num_players == team_ent.m_num_bots)
524 ++team_ent.m_num_players;
528 balance.m_team_balance_state = TEAM_BALANCE_TEAM_COUNTS_FILLED;
531 int TeamBalance_GetNumberOfPlayers(entity balance, int index)
535 LOG_FATAL("TeamBalance_GetNumberOfPlayers: "
536 "Team balance entity is NULL.");
538 if (balance.m_team_balance_state != TEAM_BALANCE_TEAM_COUNTS_FILLED)
540 LOG_FATAL("TeamBalance_GetNumberOfPlayers: "
541 "TeamBalance_GetTeamCounts has not been called.");
543 if (!Team_IsValidIndex(index))
545 LOG_FATALF("TeamBalance_GetNumberOfPlayers: Team index is invalid: %f",
548 return balance.m_team_balance_team[index - 1].m_num_players;
551 int TeamBalance_FindBestTeam(entity balance, entity player, bool ignore_player)
555 LOG_FATAL("TeamBalance_FindBestTeam: Team balance entity is NULL.");
557 if (balance.m_team_balance_state == TEAM_BALANCE_UNINITIALIZED)
559 LOG_FATAL("TeamBalance_FindBestTeam: "
560 "Team balance entity is not initialized.");
562 // count how many players are in each team
565 TeamBalance_GetTeamCounts(balance, player);
569 TeamBalance_GetTeamCounts(balance, NULL);
571 int team_bits = TeamBalance_FindBestTeams(balance, player, true);
574 LOG_FATALF("TeamBalance_FindBestTeam: No teams available for %s\n",
575 MapInfo_Type_ToString(MapInfo_CurrentGametype()));
577 RandomSelection_Init();
578 for (int i = 1; i <= NUM_TEAMS; ++i)
580 if (team_bits & Team_IndexToBit(i))
582 RandomSelection_AddFloat(i, 1, 1);
585 return RandomSelection_chosen_float;
588 int TeamBalance_FindBestTeams(entity balance, entity player, bool use_score)
592 LOG_FATAL("TeamBalance_FindBestTeams: Team balance entity is NULL.");
594 if (balance.m_team_balance_state != TEAM_BALANCE_TEAM_COUNTS_FILLED)
596 LOG_FATAL("TeamBalance_FindBestTeams: "
597 "TeamBalance_GetTeamCounts has not been called.");
599 if (MUTATOR_CALLHOOK(TeamBalance_FindBestTeams, player) == true)
601 return M_ARGV(1, float);
604 int previous_team = 0;
605 for (int i = 1; i <= NUM_TEAMS; ++i)
607 if (!TeamBalance_IsTeamAllowedInternal(balance, i))
611 if (previous_team == 0)
613 team_bits = Team_IndexToBit(i);
617 int compare = TeamBalance_CompareTeams(balance, i, previous_team,
619 if (compare == TEAMS_COMPARE_LESS)
621 team_bits = Team_IndexToBit(i);
625 if (compare == TEAMS_COMPARE_EQUAL)
627 team_bits |= Team_IndexToBit(i);
634 void TeamBalance_JoinBestTeam(entity this, bool force_best_team)
636 //PrintToChatAll(sprintf("JoinBestTeam: %s, %f", this.netname, force_best_team));
637 // don't join a team if we're not playing a team game
643 // find out what teams are available
644 entity balance = TeamBalance_CheckAllowedTeams(this);
646 // if we don't care what team they end up on, put them on whatever team they entered as.
647 // if they're not on a valid team, then let other code put them on the smallest team
648 if (!force_best_team)
650 int selected_team_index = -1;
651 for (int i = 1; i <= NUM_TEAMS; ++i)
653 if (TeamBalance_IsTeamAllowedInternal(balance, i) &&
654 (Team_TeamToIndex(this.team) == i))
656 selected_team_index = i;
661 if (Team_IsValidIndex(selected_team_index))
663 SetPlayerTeam(this, selected_team_index, TEAM_CHANGE_AUTO_RELAXED);
664 TeamBalance_Destroy(balance);
668 // otherwise end up on the smallest team (handled below)
669 if (this.bot_forced_team)
671 TeamBalance_Destroy(balance);
674 int best_team_index = TeamBalance_FindBestTeam(balance, this, true);
675 int old_team_index = Team_TeamToIndex(this.team);
676 TeamBalance_Destroy(balance);
677 PlayerScore_Clear(this);
678 if (!SetPlayerTeam(this, best_team_index, TEAM_CHANGE_AUTO))
682 if ((old_team_index != -1) && !IS_BOT_CLIENT(this))
684 TeamBalance_AutoBalanceBots(best_team_index, old_team_index);
688 int TeamBalance_CompareTeams(entity balance, int team_index_a, int team_index_b,
689 entity player, bool use_score)
693 LOG_FATAL("TeamBalance_CompareTeams: Team balance entity is NULL.");
695 if (balance.m_team_balance_state != TEAM_BALANCE_TEAM_COUNTS_FILLED)
697 LOG_FATAL("TeamBalance_CompareTeams: "
698 "TeamBalance_GetTeamCounts has not been called.");
700 if (!Team_IsValidIndex(team_index_a))
702 LOG_FATALF("TeamBalance_CompareTeams: team_index_a is invalid: %f",
705 if (!Team_IsValidIndex(team_index_b))
707 LOG_FATALF("TeamBalance_CompareTeams: team_index_b is invalid: %f",
710 if (team_index_a == team_index_b)
712 return TEAMS_COMPARE_EQUAL;
714 entity team_a = TeamBalance_GetTeamFromIndex(balance, team_index_a);
715 entity team_b = TeamBalance_GetTeamFromIndex(balance, team_index_b);
716 return TeamBalance_CompareTeamsInternal(team_a, team_b, player, use_score);
719 void TeamBalance_AutoBalanceBots(int source_team_index,
720 int destination_team_index)
722 if (!Team_IsValidIndex(source_team_index))
724 LOG_WARNF("TeamBalance_AutoBalanceBots: "
725 "Source team index is invalid: %f", source_team_index);
728 if (!Team_IsValidIndex(destination_team_index))
730 LOG_WARNF("TeamBalance_AutoBalanceBots: "
731 "Destination team index is invalid: %f", destination_team_index);
734 if (!autocvar_g_balance_teams ||
735 !autocvar_g_balance_teams_prevent_imbalance)
739 entity balance = TeamBalance_CheckAllowedTeams(NULL);
740 TeamBalance_GetTeamCounts(balance, NULL);
741 entity source_team = TeamBalance_GetTeamFromIndex(balance,
743 entity destination_team = TeamBalance_GetTeamFromIndex(balance,
744 destination_team_index);
745 if ((source_team.m_num_bots == 0) || (source_team.m_num_players <=
746 destination_team.m_num_players))
748 TeamBalance_Destroy(balance);
751 TeamBalance_Destroy(balance);
752 entity lowest_bot = NULL;
753 if (MUTATOR_CALLHOOK(TeamBalance_GetPlayerForTeamSwitch, source_team_index,
754 destination_team_index, true))
756 lowest_bot = M_ARGV(3, entity);
760 float lowest_score = FLOAT_MAX;
761 FOREACH_CLIENT(IS_BOT_CLIENT(it) && (Entity_GetTeamIndex(it) ==
764 float temp_score = PlayerScore_Get(it, SP_SCORE);
765 if (temp_score >= lowest_score)
769 balance = TeamBalance_CheckAllowedTeams(it);
770 if (TeamBalance_IsTeamAllowed(balance, destination_team_index))
773 lowest_score = temp_score;
775 TeamBalance_Destroy(balance);
778 if (lowest_bot == NULL)
782 if (!Player_SetTeamIndex(lowest_bot, destination_team_index))
786 KillPlayerForTeamChange(lowest_bot);
789 bool TeamBalance_IsTeamAllowedInternal(entity balance, int index)
791 return balance.m_team_balance_team[index - 1].m_num_players !=
795 void TeamBalance_BanTeamsExcept(entity balance, int index)
797 for (int i = 1; i <= NUM_TEAMS; ++i)
801 balance.m_team_balance_team[i - 1].m_num_players = TEAM_NOT_ALLOWED;
806 entity TeamBalance_GetTeamFromIndex(entity balance, int index)
808 if (!Team_IsValidIndex(index))
810 LOG_FATALF("TeamBalance_GetTeamFromIndex: Index is invalid: %f", index);
812 return balance.m_team_balance_team[index - 1];
815 entity TeamBalance_GetTeam(entity balance, int team_num)
817 return TeamBalance_GetTeamFromIndex(balance, Team_TeamToIndex(team_num));
820 bool TeamBalanceTeam_IsAllowed(entity team_ent)
822 return team_ent.m_num_players != TEAM_NOT_ALLOWED;
825 int TeamBalanceTeam_GetNumberOfPlayers(entity team_ent)
827 return team_ent.m_num_players;
830 int TeamBalanceTeam_GetNumberOfBots(entity team_ent)
832 return team_ent.m_num_bots;
835 int TeamBalance_CompareTeamsInternal(entity team_a, entity team_b,
836 entity player, bool use_score)
838 if (team_a == team_b)
840 return TEAMS_COMPARE_EQUAL;
842 if (!TeamBalanceTeam_IsAllowed(team_a) ||
843 !TeamBalanceTeam_IsAllowed(team_b))
845 return TEAMS_COMPARE_INVALID;
847 int num_players_team_a = team_a.m_num_players;
848 int num_players_team_b = team_b.m_num_players;
849 if (IS_REAL_CLIENT(player) && bots_would_leave)
851 num_players_team_a -= team_a.m_num_bots;
852 num_players_team_b -= team_b.m_num_bots;
854 if (num_players_team_a < num_players_team_b)
856 return TEAMS_COMPARE_LESS;
858 if (num_players_team_a > num_players_team_b)
860 return TEAMS_COMPARE_GREATER;
864 return TEAMS_COMPARE_EQUAL;
866 if (team_a.m_team_score < team_b.m_team_score)
868 return TEAMS_COMPARE_LESS;
870 if (team_a.m_team_score > team_b.m_team_score)
872 return TEAMS_COMPARE_GREATER;
874 return TEAMS_COMPARE_EQUAL;
877 // Called when the player connects or when they change their color with "color"
879 void SV_ChangeTeam(entity this, float _color)
881 //PrintToChatAll(sprintf("SV_ChangeTeam: %s, %f", this.netname, _color));
883 // in normal deathmatch we can just apply the color and we're done
885 SetPlayerColors(this, _color);
889 // since this is an engine function, and gamecode doesn't have any calls earlier than this, do the connecting message here
890 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_CONNECTING, this.netname);
897 int source_color, destination_color;
898 int source_team_index, destination_team_index;
900 source_color = this.clientcolors & 0x0F;
901 destination_color = _color & 0x0F;
903 source_team_index = Team_TeamToIndex(source_color + 1);
904 destination_team_index = Team_TeamToIndex(destination_color + 1);
906 if (destination_team_index == -1)
911 entity balance = TeamBalance_CheckAllowedTeams(this);
913 if (destination_team_index == 1 && !TeamBalance_IsTeamAllowedInternal(
916 destination_team_index = 4;
918 if (destination_team_index == 4 && !TeamBalance_IsTeamAllowedInternal(
921 destination_team_index = 3;
923 if (destination_team_index == 3 && !TeamBalance_IsTeamAllowedInternal(
926 destination_team_index = 2;
928 if (destination_team_index == 2 && !TeamBalance_IsTeamAllowedInternal(
931 destination_team_index = 1;
934 // not changing teams
935 if (source_color == destination_color)
937 SetPlayerTeam(this, destination_team_index, TEAM_CHANGE_MANUAL);
938 TeamBalance_Destroy(balance);
942 if((autocvar_g_campaign) || (autocvar_g_changeteam_banned && CS(this).wasplayer)) {
943 Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_TEAMCHANGE_NOTALLOWED);
944 return; // changing teams is not allowed
947 // autocvar_g_balance_teams_prevent_imbalance only makes sense if autocvar_g_balance_teams is on, as it makes the team selection dialog pointless
948 if (autocvar_g_balance_teams && autocvar_g_balance_teams_prevent_imbalance)
950 TeamBalance_GetTeamCounts(balance, this);
951 if ((Team_IndexToBit(destination_team_index) &
952 TeamBalance_FindBestTeams(balance, this, false)) == 0)
954 Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_TEAMCHANGE_LARGERTEAM);
955 TeamBalance_Destroy(balance);
959 TeamBalance_Destroy(balance);
960 if (IS_PLAYER(this) && source_team_index != destination_team_index)
962 // reduce frags during a team change
963 PlayerScore_Clear(this);
965 if (!SetPlayerTeam(this, destination_team_index, TEAM_CHANGE_MANUAL))
969 TeamBalance_AutoBalanceBots(destination_team_index, source_team_index);