{
return false;
}
- LogTeamchange(player.playerid, player.team, type);
+ LogTeamChange(player.playerid, player.team, type);
if (team_index != old_team_index)
{
+ PlayerScore_Clear(player);
if (team_index != -1)
{
Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(
player.netname);
}
KillPlayerForTeamChange(player);
+ if (!IS_BOT_CLIENT(player))
+ {
+ TeamBalance_AutoBalanceBots();
+ }
}
return true;
}
//PrintToChatAll(sprintf("MoveToTeam: %s, %f", client.netname, team_index));
int lockteams_backup = lockteams; // backup any team lock
lockteams = 0; // disable locked teams
- PlayerScore_Clear(client);
if (!SetPlayerTeam(client, team_index, type))
{
lockteams = lockteams_backup; // restore the team lock
return true;
}
-void KillPlayerForTeamChange(entity player)
-{
- if (IS_DEAD(player))
- {
- return;
- }
- if (MUTATOR_CALLHOOK(Player_ChangeTeamKill, player) == true)
- {
- return;
- }
- Damage(player, player, player, 100000, DEATH_TEAMCHANGE.m_id, DMG_NOWEP,
- player.origin, '0 0 0');
-}
-
-void LogTeamchange(float player_id, float team_number, int type)
-{
- if(!autocvar_sv_eventlog)
- return;
-
- if(player_id < 1)
- return;
-
- GameLogEcho(strcat(":team:", ftos(player_id), ":", ftos(team_number), ":", ftos(type)));
-}
-
bool Player_HasRealForcedTeam(entity player)
{
return player.team_forced > TEAM_FORCE_DEFAULT;
}
}
+void TeamBalance_JoinBestTeam(entity player)
+{
+ //PrintToChatAll(sprintf("TeamBalance_JoinBestTeam: %s", player.netname));
+ if (!teamplay)
+ {
+ return;
+ }
+ if (player.bot_forced_team)
+ {
+ return;
+ }
+ entity balance = TeamBalance_CheckAllowedTeams(player);
+ if (Player_HasRealForcedTeam(player))
+ {
+ int forced_team_index = player.team_forced;
+ bool is_team_allowed = TeamBalance_IsTeamAllowedInternal(balance,
+ forced_team_index);
+ TeamBalance_Destroy(balance);
+ if (!is_team_allowed)
+ {
+ return;
+ }
+ if (!SetPlayerTeam(player, forced_team_index, TEAM_CHANGE_AUTO))
+ {
+ return;
+ }
+ return;
+ }
+ int best_team_index = TeamBalance_FindBestTeam(balance, player, true);
+ TeamBalance_Destroy(balance);
+ if (!SetPlayerTeam(player, best_team_index, TEAM_CHANGE_AUTO))
+ {
+ return;
+ }
+}
+
entity TeamBalance_CheckAllowedTeams(entity for_whom)
{
entity balance = spawn();
return team_bits;
}
-void TeamBalance_JoinBestTeam(entity this)
-{
- //PrintToChatAll(sprintf("JoinBestTeam: %s", this.netname));
- if (!teamplay)
- {
- return;
- }
- if (this.bot_forced_team)
- {
- return;
- }
- entity balance = TeamBalance_CheckAllowedTeams(this);
- if (Player_HasRealForcedTeam(this))
- {
- int forced_team_index = 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 (!IS_BOT_CLIENT(this))
- {
- TeamBalance_AutoBalanceBots();
- }
- return;
- }
- int best_team_index = TeamBalance_FindBestTeam(balance, this, true);
- TeamBalance_Destroy(balance);
- PlayerScore_Clear(this);
- if (!SetPlayerTeam(this, best_team_index, TEAM_CHANGE_AUTO))
- {
- return;
- }
- if (!IS_BOT_CLIENT(this))
- {
- TeamBalance_AutoBalanceBots();
- }
-}
-
int TeamBalance_CompareTeams(entity balance, int team_index_a, int team_index_b,
entity player, bool use_score)
{
return lowest_player;
}
+void LogTeamChange(float player_id, float team_number, int type)
+{
+ if (!autocvar_sv_eventlog)
+ {
+ return;
+ }
+ if (player_id < 1)
+ {
+ return;
+ }
+ GameLogEcho(sprintf(":team:%f:%f:%f", player_id, team_number, type));
+}
+
+void KillPlayerForTeamChange(entity player)
+{
+ if (IS_DEAD(player))
+ {
+ return;
+ }
+ if (MUTATOR_CALLHOOK(Player_ChangeTeamKill, player) == true)
+ {
+ return;
+ }
+ Damage(player, player, player, 100000, DEATH_TEAMCHANGE.m_id, DMG_NOWEP,
+ player.origin, '0 0 0');
+}
+
bool TeamBalance_IsTeamAllowedInternal(entity balance, int index)
{
return balance.m_team_balance_team[index - 1].m_num_players !=
{
SetPlayerTeam(this, destination_team_index, TEAM_CHANGE_MANUAL);
TeamBalance_Destroy(balance);
- TeamBalance_AutoBalanceBots(); // Hack
return;
}
}
}
TeamBalance_Destroy(balance);
- if (IS_PLAYER(this) && source_team_index != destination_team_index)
- {
- // reduce frags during a team change
- PlayerScore_Clear(this);
- }
- if (!SetPlayerTeam(this, destination_team_index, TEAM_CHANGE_MANUAL))
- {
- return;
- }
- TeamBalance_AutoBalanceBots();
+ SetPlayerTeam(this, destination_team_index, TEAM_CHANGE_MANUAL);
}
/// \return True if team switch was successful, false otherwise.
bool Player_SetTeamIndex(entity player, int index);
+enum
+{
+ TEAM_CHANGE_AUTO = 2, ///< The team was selected by autobalance.
+ TEAM_CHANGE_MANUAL = 3, ///< Player has manually selected their team.
+ TEAM_CHANGE_SPECTATOR = 4 ///< Player is joining spectators. //TODO: Remove?
+};
+
/// \brief Sets the team of the player.
/// \param[in,out] player Player to adjust.
/// \param[in] team_index Index of the team to set.
-/// \param[in] type ???
+/// \param[in] type Type of the team change. See TEAM_CHANGE constants.
/// \return True if team switch was successful, false otherwise.
bool SetPlayerTeam(entity player, int team_index, int type);
/// \return True on success, false otherwise.
bool MoveToTeam(entity client, int team_index, int type);
-/// \brief Kills player as a result of team change.
-/// \param[in,out] player Player to kill.
-void KillPlayerForTeamChange(entity player);
-
-enum
-{
- TEAM_CHANGE_AUTO = 2,
- TEAM_CHANGE_MANUAL = 3,
- TEAM_CHANGE_SPECTATOR = 4
-};
-
-void LogTeamchange(float player_id, float team_number, int type);
-
enum
{
TEAM_FORCE_SPECTATOR = -1, ///< Force the player to spectator team.
// ========================= Team balance API =================================
+/// \brief Assigns the given player to a team that will make the game most
+/// balanced.
+/// \param[in,out] player Player to assign.
+void TeamBalance_JoinBestTeam(entity player);
+
/// \brief Checks whether the player can join teams according to global
/// configuration and mutator settings.
/// \param[in] for_whom Player to check for. Pass NULL for global rules.
/// function.
int TeamBalance_FindBestTeams(entity balance, entity player, bool use_score);
-void TeamBalance_JoinBestTeam(entity this);
-
/// \brief Describes the result of comparing teams.
enum
{
// ============================ Internal API ==================================
+void LogTeamChange(float player_id, float team_number, int type);
+
+/// \brief Kills player as a result of team change.
+/// \param[in,out] player Player to kill.
+void KillPlayerForTeamChange(entity player);
+
/// \brief Returns whether the team change to the specified team is allowed.
/// \param[in] balance Team balance entity.
/// \param[in] index Index of the team.