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.
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)
173 // This is important when players join the game and one of their color
174 // matches the team color while other doesn't. For example [BOT]Lion.
175 SetPlayerColors(player, new_team - 1);
178 int old_index = Team_TeamToIndex(player.team);
179 if (MUTATOR_CALLHOOK(Player_ChangeTeam, player, old_index, index) == true)
181 // Mutator has blocked team change.
184 SetPlayerColors(player, new_team - 1);
185 MUTATOR_CALLHOOK(Player_ChangedTeam, player, old_index, index);
189 bool SetPlayerTeam(entity player, int destination_team_index,
190 int source_team_index, bool no_print)
192 if (!Player_SetTeamIndex(player, destination_team_index))
196 LogTeamchange(player.playerid, player.team, TEAM_CHANGE_MANUAL);
201 bprint(playername(player, false), "^7 has changed from ",
202 Team_IndexToColoredFullName(source_team_index), "^7 to ",
203 Team_IndexToColoredFullName(destination_team_index), "\n");
207 bool MoveToTeam(entity client, int team_index, int type)
209 int lockteams_backup = lockteams; // backup any team lock
210 lockteams = 0; // disable locked teams
211 PlayerScore_Clear(client);
212 if (!Player_SetTeamIndex(client, team_index))
214 lockteams = lockteams_backup; // restore the team lock
217 KillPlayerForTeamChange(client);
218 lockteams = lockteams_backup; // restore the team lock
219 LogTeamchange(client.playerid, client.team, type);
223 void KillPlayerForTeamChange(entity player)
229 if (MUTATOR_CALLHOOK(Player_ChangeTeamKill, player) == true)
233 Damage(player, player, player, 100000, DEATH_TEAMCHANGE.m_id, DMG_NOWEP,
234 player.origin, '0 0 0');
237 void LogTeamchange(float player_id, float team_number, int type)
239 if(!autocvar_sv_eventlog)
245 GameLogEcho(strcat(":team:", ftos(player_id), ":", ftos(team_number), ":", ftos(type)));
248 entity TeamBalance_CheckAllowedTeams(entity for_whom)
250 entity balance = spawn();
251 for (int i = 0; i < NUM_TEAMS; ++i)
253 entity team_ent = balance.m_team_balance_team[i] = spawn();
254 team_ent.m_team_score = g_team_entities[i].m_team_score;
255 team_ent.m_num_players = TEAM_NOT_ALLOWED;
256 team_ent.m_num_bots = 0;
260 string teament_name = string_null;
261 bool mutator_returnvalue = MUTATOR_CALLHOOK(TeamBalance_CheckAllowedTeams,
262 teams_mask, teament_name, for_whom);
263 teams_mask = M_ARGV(0, float);
264 teament_name = M_ARGV(1, string);
265 if (mutator_returnvalue)
267 for (int i = 0; i < NUM_TEAMS; ++i)
269 if (teams_mask & BIT(i))
271 balance.m_team_balance_team[i].m_num_players = 0;
278 entity head = find(NULL, classname, teament_name);
281 if (Team_IsValidTeam(head.team))
283 TeamBalance_GetTeam(balance, head.team).m_num_players = 0;
285 head = find(head, classname, teament_name);
289 // TODO: Balance quantity of bots across > 2 teams when bot_vs_human is set (and remove next line)
290 if (AvailableTeams() == 2)
291 if (autocvar_bot_vs_human && for_whom)
293 if (autocvar_bot_vs_human > 0)
295 // find last team available
296 if (IS_BOT_CLIENT(for_whom))
298 if (TeamBalance_IsTeamAllowedInternal(balance, 4))
300 TeamBalance_BanTeamsExcept(balance, 4);
302 else if (TeamBalance_IsTeamAllowedInternal(balance, 3))
304 TeamBalance_BanTeamsExcept(balance, 3);
308 TeamBalance_BanTeamsExcept(balance, 2);
310 // no further cases, we know at least 2 teams exist
314 if (TeamBalance_IsTeamAllowedInternal(balance, 1))
316 TeamBalance_BanTeamsExcept(balance, 1);
318 else if (TeamBalance_IsTeamAllowedInternal(balance, 2))
320 TeamBalance_BanTeamsExcept(balance, 2);
324 TeamBalance_BanTeamsExcept(balance, 3);
326 // no further cases, bots have one of the teams
331 // find first team available
332 if (IS_BOT_CLIENT(for_whom))
334 if (TeamBalance_IsTeamAllowedInternal(balance, 1))
336 TeamBalance_BanTeamsExcept(balance, 1);
338 else if (TeamBalance_IsTeamAllowedInternal(balance, 2))
340 TeamBalance_BanTeamsExcept(balance, 2);
344 TeamBalance_BanTeamsExcept(balance, 3);
346 // no further cases, we know at least 2 teams exist
350 if (TeamBalance_IsTeamAllowedInternal(balance, 4))
352 TeamBalance_BanTeamsExcept(balance, 4);
354 else if (TeamBalance_IsTeamAllowedInternal(balance, 3))
356 TeamBalance_BanTeamsExcept(balance, 3);
360 TeamBalance_BanTeamsExcept(balance, 2);
362 // no further cases, bots have one of the teams
369 balance.m_team_balance_state = TEAM_BALANCE_TEAMS_CHECKED;
373 // if player has a forced team, ONLY allow that one
374 for (int i = 1; i <= NUM_TEAMS; ++i)
376 if (for_whom.team_forced == Team_IndexToTeam(i) &&
377 TeamBalance_IsTeamAllowedInternal(balance, i))
379 TeamBalance_BanTeamsExcept(balance, i);
383 balance.m_team_balance_state = TEAM_BALANCE_TEAMS_CHECKED;
387 void TeamBalance_Destroy(entity balance)
393 for (int i = 0; i < NUM_TEAMS; ++i)
395 delete(balance.(m_team_balance_team[i]));
400 int TeamBalance_GetAllowedTeams(entity balance)
404 LOG_FATAL("TeamBalance_GetAllowedTeams: Team balance entity is NULL.");
406 if (balance.m_team_balance_state == TEAM_BALANCE_UNINITIALIZED)
408 LOG_FATAL("TeamBalance_GetAllowedTeams: "
409 "Team balance entity is not initialized.");
412 for (int i = 1; i <= NUM_TEAMS; ++i)
414 if (TeamBalance_IsTeamAllowedInternal(balance, i))
416 result |= Team_IndexToBit(i);
422 bool TeamBalance_IsTeamAllowed(entity balance, int index)
426 LOG_FATAL("TeamBalance_IsTeamAllowed: Team balance entity is NULL.");
428 if (balance.m_team_balance_state == TEAM_BALANCE_UNINITIALIZED)
430 LOG_FATAL("TeamBalance_IsTeamAllowed: "
431 "Team balance entity is not initialized.");
433 if (!Team_IsValidIndex(index))
435 LOG_FATALF("TeamBalance_IsTeamAllowed: Team index is invalid: %f",
438 return TeamBalance_IsTeamAllowedInternal(balance, index);
441 void TeamBalance_GetTeamCounts(entity balance, entity ignore)
445 LOG_FATAL("TeamBalance_GetTeamCounts: Team balance entity is NULL.");
447 if (balance.m_team_balance_state == TEAM_BALANCE_UNINITIALIZED)
449 LOG_FATAL("TeamBalance_GetTeamCounts: "
450 "Team balance entity is not initialized.");
452 if (MUTATOR_CALLHOOK(TeamBalance_GetTeamCounts) == true)
454 // Mutator has overriden the configuration.
455 for (int i = 1; i <= NUM_TEAMS; ++i)
457 entity team_ent = TeamBalance_GetTeamFromIndex(balance, i);
458 if (TeamBalanceTeam_IsAllowed(team_ent))
460 MUTATOR_CALLHOOK(TeamBalance_GetTeamCount, i, ignore);
461 team_ent.m_num_players = M_ARGV(2, float);
462 team_ent.m_num_bots = M_ARGV(3, float);
468 // Manually count all players.
476 if (IS_PLAYER(it) || it.caplayer)
480 else if (it.team_forced > 0)
482 team_num = it.team_forced; // reserve the spot
488 if (!Team_IsValidTeam(team_num))
492 entity team_ent = TeamBalance_GetTeam(balance, team_num);
493 if (!TeamBalanceTeam_IsAllowed(team_ent))
497 ++team_ent.m_num_players;
498 if (IS_BOT_CLIENT(it))
500 ++team_ent.m_num_bots;
505 // if the player who has a forced team has not joined yet, reserve the spot
506 if (autocvar_g_campaign)
508 if (Team_IsValidIndex(autocvar_g_campaign_forceteam))
510 entity team_ent = TeamBalance_GetTeamFromIndex(balance,
511 autocvar_g_campaign_forceteam);
512 if (team_ent.m_num_players == team_ent.m_num_bots)
514 ++team_ent.m_num_players;
518 balance.m_team_balance_state = TEAM_BALANCE_TEAM_COUNTS_FILLED;
521 int TeamBalance_GetNumberOfPlayers(entity balance, int index)
525 LOG_FATAL("TeamBalance_GetNumberOfPlayers: "
526 "Team balance entity is NULL.");
528 if (balance.m_team_balance_state != TEAM_BALANCE_TEAM_COUNTS_FILLED)
530 LOG_FATAL("TeamBalance_GetNumberOfPlayers: "
531 "TeamBalance_GetTeamCounts has not been called.");
533 if (!Team_IsValidIndex(index))
535 LOG_FATALF("TeamBalance_GetNumberOfPlayers: Team index is invalid: %f",
538 return balance.m_team_balance_team[index - 1].m_num_players;
541 int TeamBalance_FindBestTeam(entity balance, entity player, bool ignore_player)
545 LOG_FATAL("TeamBalance_FindBestTeam: Team balance entity is NULL.");
547 if (balance.m_team_balance_state == TEAM_BALANCE_UNINITIALIZED)
549 LOG_FATAL("TeamBalance_FindBestTeam: "
550 "Team balance entity is not initialized.");
552 // count how many players are in each team
555 TeamBalance_GetTeamCounts(balance, player);
559 TeamBalance_GetTeamCounts(balance, NULL);
561 int team_bits = TeamBalance_FindBestTeams(balance, player, true);
564 LOG_FATALF("TeamBalance_FindBestTeam: No teams available for %s\n",
565 MapInfo_Type_ToString(MapInfo_CurrentGametype()));
567 RandomSelection_Init();
568 for (int i = 1; i <= NUM_TEAMS; ++i)
570 if (team_bits & Team_IndexToBit(i))
572 RandomSelection_AddFloat(i, 1, 1);
575 return RandomSelection_chosen_float;
578 int TeamBalance_FindBestTeams(entity balance, entity player, bool use_score)
582 LOG_FATAL("TeamBalance_FindBestTeams: Team balance entity is NULL.");
584 if (balance.m_team_balance_state != TEAM_BALANCE_TEAM_COUNTS_FILLED)
586 LOG_FATAL("TeamBalance_FindBestTeams: "
587 "TeamBalance_GetTeamCounts has not been called.");
589 if (MUTATOR_CALLHOOK(TeamBalance_FindBestTeams, player) == true)
591 return M_ARGV(1, float);
594 int previous_team = 0;
595 for (int i = 1; i <= NUM_TEAMS; ++i)
597 if (!TeamBalance_IsTeamAllowedInternal(balance, i))
601 if (previous_team == 0)
603 team_bits = Team_IndexToBit(i);
607 int compare = TeamBalance_CompareTeams(balance, i, previous_team,
609 if (compare == TEAMS_COMPARE_LESS)
611 team_bits = Team_IndexToBit(i);
615 if (compare == TEAMS_COMPARE_EQUAL)
617 team_bits |= Team_IndexToBit(i);
624 void TeamBalance_JoinBestTeam(entity this, bool force_best_team)
626 // don't join a team if we're not playing a team game
632 // find out what teams are available
633 entity balance = TeamBalance_CheckAllowedTeams(this);
635 // if we don't care what team they end up on, put them on whatever team they entered as.
636 // if they're not on a valid team, then let other code put them on the smallest team
637 if (!force_best_team)
639 int selected_team_index = -1;
640 for (int i = 1; i <= NUM_TEAMS; ++i)
642 if (TeamBalance_IsTeamAllowedInternal(balance, i) &&
643 (Team_TeamToIndex(this.team) == i))
645 selected_team_index = i;
650 if (Team_IsValidIndex(selected_team_index))
652 Player_SetTeamIndex(this, selected_team_index);
653 LogTeamchange(this.playerid, this.team, TEAM_CHANGE_AUTO_RELAXED);
654 TeamBalance_Destroy(balance);
658 // otherwise end up on the smallest team (handled below)
659 if (this.bot_forced_team)
661 TeamBalance_Destroy(balance);
664 int best_team_index = TeamBalance_FindBestTeam(balance, this, true);
665 int old_team_index = Team_TeamToIndex(this.team);
666 TeamBalance_Destroy(balance);
667 PlayerScore_Clear(this);
668 Player_SetTeamIndex(this, best_team_index);
669 LogTeamchange(this.playerid, this.team, TEAM_CHANGE_AUTO);
670 if ((old_team_index != -1) && !IS_BOT_CLIENT(this))
672 TeamBalance_AutoBalanceBots(best_team_index, old_team_index);
674 KillPlayerForTeamChange(this);
677 int TeamBalance_CompareTeams(entity balance, int team_index_a, int team_index_b,
678 entity player, bool use_score)
682 LOG_FATAL("TeamBalance_CompareTeams: Team balance entity is NULL.");
684 if (balance.m_team_balance_state != TEAM_BALANCE_TEAM_COUNTS_FILLED)
686 LOG_FATAL("TeamBalance_CompareTeams: "
687 "TeamBalance_GetTeamCounts has not been called.");
689 if (!Team_IsValidIndex(team_index_a))
691 LOG_FATALF("TeamBalance_CompareTeams: team_index_a is invalid: %f",
694 if (!Team_IsValidIndex(team_index_b))
696 LOG_FATALF("TeamBalance_CompareTeams: team_index_b is invalid: %f",
699 if (team_index_a == team_index_b)
701 return TEAMS_COMPARE_EQUAL;
703 entity team_a = TeamBalance_GetTeamFromIndex(balance, team_index_a);
704 entity team_b = TeamBalance_GetTeamFromIndex(balance, team_index_b);
705 return TeamBalance_CompareTeamsInternal(team_a, team_b, player, use_score);
708 void TeamBalance_AutoBalanceBots(int source_team_index,
709 int destination_team_index)
711 if (!Team_IsValidIndex(source_team_index))
713 LOG_WARNF("TeamBalance_AutoBalanceBots: "
714 "Source team index is invalid: %f", source_team_index);
717 if (!Team_IsValidIndex(destination_team_index))
719 LOG_WARNF("TeamBalance_AutoBalanceBots: "
720 "Destination team index is invalid: %f", destination_team_index);
723 if (!autocvar_g_balance_teams ||
724 !autocvar_g_balance_teams_prevent_imbalance)
728 entity balance = TeamBalance_CheckAllowedTeams(NULL);
729 TeamBalance_GetTeamCounts(balance, NULL);
730 entity source_team = TeamBalance_GetTeamFromIndex(balance,
732 entity destination_team = TeamBalance_GetTeamFromIndex(balance,
733 destination_team_index);
734 if ((source_team.m_num_bots == 0) || (source_team.m_num_players <=
735 destination_team.m_num_players))
737 TeamBalance_Destroy(balance);
740 TeamBalance_Destroy(balance);
741 entity lowest_bot = NULL;
742 if (MUTATOR_CALLHOOK(TeamBalance_GetPlayerForTeamSwitch, source_team_index,
743 destination_team_index, true))
745 lowest_bot = M_ARGV(3, entity);
749 float lowest_score = FLOAT_MAX;
750 FOREACH_CLIENT(IS_BOT_CLIENT(it) && (Entity_GetTeamIndex(it) ==
753 float temp_score = PlayerScore_Get(it, SP_SCORE);
754 if (temp_score >= lowest_score)
758 balance = TeamBalance_CheckAllowedTeams(it);
759 if (TeamBalance_IsTeamAllowed(balance, destination_team_index))
762 lowest_score = temp_score;
764 TeamBalance_Destroy(balance);
767 if (lowest_bot == NULL)
771 if (!Player_SetTeamIndex(lowest_bot, destination_team_index))
775 KillPlayerForTeamChange(lowest_bot);
778 bool TeamBalance_IsTeamAllowedInternal(entity balance, int index)
780 return balance.m_team_balance_team[index - 1].m_num_players !=
784 void TeamBalance_BanTeamsExcept(entity balance, int index)
786 for (int i = 1; i <= NUM_TEAMS; ++i)
790 balance.m_team_balance_team[i - 1].m_num_players = TEAM_NOT_ALLOWED;
795 entity TeamBalance_GetTeamFromIndex(entity balance, int index)
797 if (!Team_IsValidIndex(index))
799 LOG_FATALF("TeamBalance_GetTeamFromIndex: Index is invalid: %f", index);
801 return balance.m_team_balance_team[index - 1];
804 entity TeamBalance_GetTeam(entity balance, int team_num)
806 return TeamBalance_GetTeamFromIndex(balance, Team_TeamToIndex(team_num));
809 bool TeamBalanceTeam_IsAllowed(entity team_ent)
811 return team_ent.m_num_players != TEAM_NOT_ALLOWED;
814 int TeamBalanceTeam_GetNumberOfPlayers(entity team_ent)
816 return team_ent.m_num_players;
819 int TeamBalanceTeam_GetNumberOfBots(entity team_ent)
821 return team_ent.m_num_bots;
824 int TeamBalance_CompareTeamsInternal(entity team_a, entity team_b,
825 entity player, bool use_score)
827 if (team_a == team_b)
829 return TEAMS_COMPARE_EQUAL;
831 if (!TeamBalanceTeam_IsAllowed(team_a) ||
832 !TeamBalanceTeam_IsAllowed(team_b))
834 return TEAMS_COMPARE_INVALID;
836 int num_players_team_a = team_a.m_num_players;
837 int num_players_team_b = team_b.m_num_players;
838 if (IS_REAL_CLIENT(player) && bots_would_leave)
840 num_players_team_a -= team_a.m_num_bots;
841 num_players_team_b -= team_b.m_num_bots;
843 if (num_players_team_a < num_players_team_b)
845 return TEAMS_COMPARE_LESS;
847 if (num_players_team_a > num_players_team_b)
849 return TEAMS_COMPARE_GREATER;
853 return TEAMS_COMPARE_EQUAL;
855 if (team_a.m_team_score < team_b.m_team_score)
857 return TEAMS_COMPARE_LESS;
859 if (team_a.m_team_score > team_b.m_team_score)
861 return TEAMS_COMPARE_GREATER;
863 return TEAMS_COMPARE_EQUAL;
866 void SV_ChangeTeam(entity this, float _color)
868 int source_color, destination_color;
869 int source_team_index, destination_team_index;
871 // in normal deathmatch we can just apply the color and we're done
873 SetPlayerColors(this, _color);
877 // since this is an engine function, and gamecode doesn't have any calls earlier than this, do the connecting message here
878 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_CONNECTING, this.netname);
885 source_color = this.clientcolors & 0x0F;
886 destination_color = _color & 0x0F;
888 source_team_index = Team_TeamToIndex(source_color + 1);
889 destination_team_index = Team_TeamToIndex(destination_color + 1);
891 if (destination_team_index == -1)
896 entity balance = TeamBalance_CheckAllowedTeams(this);
898 if (destination_team_index == 1 && !TeamBalance_IsTeamAllowedInternal(
901 destination_team_index = 4;
903 if (destination_team_index == 4 && !TeamBalance_IsTeamAllowedInternal(
906 destination_team_index = 3;
908 if (destination_team_index == 3 && !TeamBalance_IsTeamAllowedInternal(
911 destination_team_index = 2;
913 if (destination_team_index == 2 && !TeamBalance_IsTeamAllowedInternal(
916 destination_team_index = 1;
919 // not changing teams
920 if (source_color == destination_color)
922 SetPlayerTeam(this, destination_team_index, source_team_index, true);
923 TeamBalance_Destroy(balance);
927 if((autocvar_g_campaign) || (autocvar_g_changeteam_banned && CS(this).wasplayer)) {
928 Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_TEAMCHANGE_NOTALLOWED);
929 return; // changing teams is not allowed
932 // autocvar_g_balance_teams_prevent_imbalance only makes sense if autocvar_g_balance_teams is on, as it makes the team selection dialog pointless
933 if (autocvar_g_balance_teams && autocvar_g_balance_teams_prevent_imbalance)
935 TeamBalance_GetTeamCounts(balance, this);
936 if ((Team_IndexToBit(destination_team_index) &
937 TeamBalance_FindBestTeams(balance, this, false)) == 0)
939 Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_TEAMCHANGE_LARGERTEAM);
940 TeamBalance_Destroy(balance);
944 TeamBalance_Destroy(balance);
945 if (IS_PLAYER(this) && source_team_index != destination_team_index)
947 // reduce frags during a team change
948 PlayerScore_Clear(this);
950 if (!SetPlayerTeam(this, destination_team_index, source_team_index,
955 TeamBalance_AutoBalanceBots(destination_team_index, source_team_index);
956 if (!IS_PLAYER(this) || (source_team_index == destination_team_index))
960 KillPlayerForTeamChange(this);