From: Lyberta Date: Sun, 11 Mar 2018 05:55:46 +0000 (+0300) Subject: Added Player_SetTeamIndex, removed SetPlayerTeamSimple. X-Git-Tag: xonotic-v0.8.5~1953^2~34 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=f779d25ddb79eba7b6ad60d6fa64611e870e881e;p=xonotic%2Fxonotic-data.pk3dir.git Added Player_SetTeamIndex, removed SetPlayerTeamSimple. --- diff --git a/qcsrc/server/player.qc b/qcsrc/server/player.qc index 06bdb1428..65eaf16a8 100644 --- a/qcsrc/server/player.qc +++ b/qcsrc/server/player.qc @@ -669,11 +669,11 @@ bool MoveToTeam(entity client, int team_colour, int type) int lockteams_backup = lockteams; // backup any team lock lockteams = 0; // disable locked teams TeamchangeFrags(client); // move the players frags - if (!SetPlayerTeamSimple(client, team_colour)) + if (!Player_SetTeamIndex(client, Team_TeamToIndex(team_colour))) { return false; } - Damage(client, client, client, 100000, DEATH_AUTOTEAMCHANGE.m_id, DMG_NOWEP, client.origin, '0 0 0'); // kill the player + KillPlayerForTeamChange(client); lockteams = lockteams_backup; // restore the team lock LogTeamchange(client.playerid, client.team, type); return true; diff --git a/qcsrc/server/teamplay.qc b/qcsrc/server/teamplay.qc index ff3abf755..e2b16cab9 100644 --- a/qcsrc/server/teamplay.qc +++ b/qcsrc/server/teamplay.qc @@ -245,48 +245,31 @@ void SetPlayerColors(entity player, float _color) } } -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 SetPlayerTeamSimple(entity player, int team_num) +bool Player_SetTeamIndex(entity player, int index) { - if (player.team == team_num) + int new_team = Team_IndexToTeam(index); + if (player.team == new_team) { // This is important when players join the game and one of their color // matches the team color while other doesn't. For example [BOT]Lion. - SetPlayerColors(player, team_num - 1); + SetPlayerColors(player, new_team - 1); return true; } - int old_team_index = Team_TeamToIndex(player.team); - int new_team_index = Team_TeamToIndex(team_num); - if (MUTATOR_CALLHOOK(Player_ChangeTeam, player, old_team_index, - new_team_index) == true) + int old_index = Team_TeamToIndex(player.team); + if (MUTATOR_CALLHOOK(Player_ChangeTeam, player, old_index, index) == true) { // Mutator has blocked team change. return false; } - SetPlayerColors(player, team_num - 1); - MUTATOR_CALLHOOK(Player_ChangedTeam, player, old_team_index, - new_team_index); + SetPlayerColors(player, new_team - 1); + MUTATOR_CALLHOOK(Player_ChangedTeam, player, old_index, index); return true; } bool SetPlayerTeam(entity player, int destination_team_index, int source_team_index, bool no_print) { - int team_num = Team_IndexToTeam(destination_team_index); - if (!SetPlayerTeamSimple(player, team_num)) + if (!Player_SetTeamIndex(player, destination_team_index)) { return false; } @@ -301,6 +284,20 @@ bool SetPlayerTeam(entity player, int destination_team_index, 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'); +} + entity TeamBalance_CheckAllowedTeams(entity for_whom) { entity balance = spawn(); @@ -722,20 +719,20 @@ void TeamBalance_JoinBestTeam(entity this, bool force_best_team) // if they're not on a valid team, then let other code put them on the smallest team if (!force_best_team) { - int selected_team_num = -1; + int selected_team_index = -1; for (int i = 1; i <= NUM_TEAMS; ++i) { - if (TeamBalance_IsTeamAllowedInternal(balance, i) && (this.team == - Team_IndexToTeam(i))) + if (TeamBalance_IsTeamAllowedInternal(balance, i) && + (Team_TeamToIndex(this.team) == i)) { - selected_team_num = this.team; + selected_team_index = i; break; } } - if (Team_IsValidTeam(selected_team_num)) + if (Team_IsValidIndex(selected_team_index)) { - SetPlayerTeamSimple(this, selected_team_num); + Player_SetTeamIndex(this, selected_team_index); LogTeamchange(this.playerid, this.team, 99); TeamBalance_Destroy(balance); return; @@ -748,10 +745,9 @@ void TeamBalance_JoinBestTeam(entity this, bool force_best_team) return; } int best_team_index = TeamBalance_FindBestTeam(balance, this, true); - int best_team_num = Team_IndexToTeam(best_team_index); int old_team_index = Team_TeamToIndex(this.team); TeamchangeFrags(this); - SetPlayerTeamSimple(this, best_team_num); + Player_SetTeamIndex(this, best_team_index); LogTeamchange(this.playerid, this.team, 2); // log auto join if ((old_team_index != -1) && !IS_BOT_CLIENT(this)) { @@ -834,8 +830,7 @@ void TeamBalance_AutoBalanceBots(entity balance, int source_team_index, { return; } - SetPlayerTeamSimple(destination_team.m_lowest_bot, - Team_IndexToTeam(source_team_index)); + Player_SetTeamIndex(destination_team.m_lowest_bot, source_team_index); KillPlayerForTeamChange(destination_team.m_lowest_bot); } diff --git a/qcsrc/server/teamplay.qh b/qcsrc/server/teamplay.qh index 6ac1df288..5d2c75dc7 100644 --- a/qcsrc/server/teamplay.qh +++ b/qcsrc/server/teamplay.qh @@ -47,15 +47,11 @@ int Entity_GetTeamIndex(entity this); void SetPlayerColors(entity player, float _color); -/// \brief Kills player as a result of team change. -/// \param[in,out] player Player to kill. -void KillPlayerForTeamChange(entity player); - -/// \brief Sets the team of the player. +/// \brief Sets the team of the player using its index. /// \param[in,out] player Player to adjust. -/// \param[in] team_num Team number to set. See TEAM_NUM constants. +/// \param[in] index Index of the team to set. /// \return True if team switch was successful, false otherwise. -bool SetPlayerTeamSimple(entity player, int team_num); +bool Player_SetTeamIndex(entity player, int index); /// \brief Sets the team of the player. /// \param[in,out] player Player to adjust. @@ -66,6 +62,10 @@ bool SetPlayerTeamSimple(entity player, int team_num); bool SetPlayerTeam(entity player, int destination_team_index, int source_team_index, bool no_print); +/// \brief Kills player as a result of team change. +/// \param[in,out] player Player to kill. +void KillPlayerForTeamChange(entity player); + // ========================= Team balance API ================================= /// \brief Checks whether the player can join teams according to global