]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Improved MoveToTeam.
authorLyberta <lyberta@lyberta.net>
Sun, 18 Mar 2018 10:14:51 +0000 (13:14 +0300)
committerLyberta <lyberta@lyberta.net>
Sun, 18 Mar 2018 10:14:51 +0000 (13:14 +0300)
qcsrc/server/command/sv_cmd.qc
qcsrc/server/defs.qh
qcsrc/server/player.qc
qcsrc/server/player.qh
qcsrc/server/teamplay.qc
qcsrc/server/teamplay.qh

index aac3210398ca96b6593269756dae58ea41d71e3c..71a359fcf777d641ddbc180d8b32e5dc9a323d59 100644 (file)
@@ -1138,7 +1138,7 @@ void GameCommand_moveplayer(float request, float argc)
 
                                                                // If so, lets continue and finally move the player
                                                                client.team_forced = 0;
-                                                               if (MoveToTeam(client, team_id, 6))
+                                                               if (MoveToTeam(client, Team_TeamToIndex(team_id), 6))
                                                                {
                                                                        successful = strcat(successful, (successful ? ", " : ""), playername(client, false));
                                                                        LOG_INFO("Player ", ftos(GetFilteredNumber(t)), " (", playername(client, false), ") has been moved to the ", Team_ColoredFullName(team_id), "^7.");
@@ -1421,8 +1421,11 @@ void GameCommand_shuffleteams(float request)
 
                        int team_index = 0;
                        FOREACH_CLIENT_RANDOM(IS_PLAYER(it) || it.caplayer, {
-                               int target_team_number = Team_IndexToTeam(team_index + 1);
-                               if (it.team != target_team_number) MoveToTeam(it, target_team_number, 6);
+                               int target_team_index = team_index + 1;
+                               if (Entity_GetTeamIndex(it) != target_team_index)
+                               {
+                                       MoveToTeam(it, target_team_index, 6);
+                               }
                                team_index = (team_index + 1) % number_of_teams;
                        });
 
index af8c3a052ed9517f41482a0253160341f4ed01f2..5befffee4558164437c881ab0194d020adf6897b 100644 (file)
@@ -231,8 +231,6 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, int d
 // WEAPONTODO
 #define DMG_NOWEP (weaponentities[0])
 
-float lockteams;
-
 float sv_maxidle;
 float sv_maxidle_spectatorsareidle;
 int sv_maxidle_slots;
index 65eaf16a88441394f7dc69f02c6b2dcb0bf16f46..2a8710137554406ebbd6a2a256e6357c701bb8a9 100644 (file)
@@ -664,21 +664,6 @@ void PlayerDamage(entity this, entity inflictor, entity attacker, float damage,
        }
 }
 
-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 (!Player_SetTeamIndex(client, Team_TeamToIndex(team_colour)))
-       {
-               return false;
-       }
-       KillPlayerForTeamChange(client);
-       lockteams = lockteams_backup;  // restore the team lock
-       LogTeamchange(client.playerid, client.team, type);
-       return true;
-}
-
 /** print(), but only print if the server is not local */
 void dedicated_print(string input)
 {
index ee073ccb4498a960b757409fd055cec5d3c8062d..f462a1a52febb157ccb50aff5209f2d56fe10c02 100644 (file)
@@ -69,13 +69,6 @@ void calculate_player_respawn_time(entity this);
 
 void ClientKill_Now_TeamChange(entity this);
 
-/// \brief Moves player to the specified team.
-/// \param[in,out] client Client to move.
-/// \param[in] team_colour Color of the team.
-/// \param[in] type ???
-/// \return True on success, false otherwise.
-bool MoveToTeam(entity client, float team_colour, float type);
-
 void PlayerDamage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force);
 
 int Say(entity source, float teamsay, entity privatesay, string msgin, float floodcontrol);
index ffa1399d4748bf1935f75da9efca1946d7fffd95..51e360a1978d6d508985438cbd632a036b240c89 100644 (file)
@@ -222,6 +222,22 @@ bool SetPlayerTeam(entity player, int destination_team_index,
        return true;
 }
 
+bool MoveToTeam(entity client, int team_index, int type)
+{
+       int lockteams_backup = lockteams;  // backup any team lock
+       lockteams = 0;  // disable locked teams
+       TeamchangeFrags(client);  // move the players frags
+       if (!Player_SetTeamIndex(client, team_index))
+       {
+               lockteams = lockteams_backup;  // restore the team lock
+               return false;
+       }
+       KillPlayerForTeamChange(client);
+       lockteams = lockteams_backup;  // restore the team lock
+       LogTeamchange(client.playerid, client.team, type);
+       return true;
+}
+
 void KillPlayerForTeamChange(entity player)
 {
        if (IS_DEAD(player))
index 396a45d89aae98fb929c8a6a742b5b44412ca938..a7fc34b56facac35cd8b8fd45608824738a2d4a5 100644 (file)
@@ -1,5 +1,9 @@
 #pragma once
 
+bool lockteams;
+
+// ========================== Global teams API ================================
+
 /// \brief Returns the global team entity at the given index.
 /// \param[in] index Index of the team.
 /// \return Global team entity at the given index.
@@ -11,6 +15,8 @@ entity Team_GetTeamFromIndex(int index);
 /// \return Global team entity that corresponds to the given TEAM_NUM value.
 entity Team_GetTeam(int team_num);
 
+// ========================= Team specific API ================================
+
 /// \brief Returns the score of the team.
 /// \param[in] team_ Team entity.
 /// \return Score of the team.
@@ -53,6 +59,8 @@ void TeamchangeFrags(entity e);
 
 void LogTeamchange(float player_id, float team_number, float type);
 
+// ======================= Entity specific API ================================
+
 void setcolor(entity this, int clr);
 
 /// \brief Returns whether the given entity belongs to a valid team.
@@ -87,6 +95,13 @@ bool Player_SetTeamIndex(entity player, int index);
 bool SetPlayerTeam(entity player, int destination_team_index,
        int source_team_index, bool no_print);
 
+/// \brief Moves player to the specified team.
+/// \param[in,out] client Client to move.
+/// \param[in] team_index Index of the team.
+/// \param[in] type ???
+/// \return True on success, false otherwise.
+bool MoveToTeam(entity client, int team_index, float type);
+
 /// \brief Kills player as a result of team change.
 /// \param[in,out] player Player to kill.
 void KillPlayerForTeamChange(entity player);