]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Teamplay: Abstracted forced teams.
authorLyberta <lyberta@lyberta.net>
Wed, 25 Jul 2018 22:18:57 +0000 (01:18 +0300)
committerLyberta <lyberta@lyberta.net>
Wed, 25 Jul 2018 22:18:57 +0000 (01:18 +0300)
qcsrc/common/minigames/sv_minigames.qc
qcsrc/server/autocvars.qh
qcsrc/server/client.qc
qcsrc/server/command/cmd.qc
qcsrc/server/command/sv_cmd.qc
qcsrc/server/defs.qh
qcsrc/server/teamplay.qc
qcsrc/server/teamplay.qh

index 5c6af26615dc5f71363dfb9286eab23da294a859..af74e6a5a6c601902c1da414b0a24d8d46f356b4 100644 (file)
@@ -9,7 +9,7 @@ void player_clear_minigame(entity player)
                set_movetype(player, MOVETYPE_WALK);
        else
                set_movetype(player, MOVETYPE_FLY_WORLDONLY);
                set_movetype(player, MOVETYPE_WALK);
        else
                set_movetype(player, MOVETYPE_FLY_WORLDONLY);
-       player.team_forced = 0;
+       Player_SetForcedTeamIndex(player, TEAM_FORCE_DEFAULT);
 }
 
 void minigame_rmplayer(entity minigame_session, entity player)
 }
 
 void minigame_rmplayer(entity minigame_session, entity player)
@@ -150,7 +150,7 @@ int minigame_addplayer(entity minigame_session, entity player)
                        PutObserverInServer(player);
                }
                if ( autocvar_sv_minigames_observer == 2 )
                        PutObserverInServer(player);
                }
                if ( autocvar_sv_minigames_observer == 2 )
-                       player.team_forced = -1;
+                       Player_SetForcedTeamIndex(player, TEAM_FORCE_SPECTATOR);
 
                minigame_resend(minigame_session);
        }
 
                minigame_resend(minigame_session);
        }
index 7d73a73a8b7e65086756c1e261a1b9edcacd3b90..5f5731e2df01bf36fac22ad0a0615e3e90de5ec2 100644 (file)
@@ -124,11 +124,7 @@ int autocvar_g_chat_nospectators;
 bool autocvar_g_chat_teamcolors;
 bool autocvar_g_chat_tellprivacy;
 bool autocvar_g_forced_respawn;
 bool autocvar_g_chat_teamcolors;
 bool autocvar_g_chat_tellprivacy;
 bool autocvar_g_forced_respawn;
-string autocvar_g_forced_team_blue;
-string autocvar_g_forced_team_otherwise;
-string autocvar_g_forced_team_pink;
-string autocvar_g_forced_team_red;
-string autocvar_g_forced_team_yellow;
+string autocvar_g_forced_team_otherwise; // TODO: Move to teamplay.qc
 #define autocvar_g_friendlyfire cvar("g_friendlyfire")
 #define autocvar_g_friendlyfire_virtual cvar("g_friendlyfire_virtual")
 #define autocvar_g_friendlyfire_virtual_force cvar("g_friendlyfire_virtual_force")
 #define autocvar_g_friendlyfire cvar("g_friendlyfire")
 #define autocvar_g_friendlyfire_virtual cvar("g_friendlyfire_virtual")
 #define autocvar_g_friendlyfire_virtual_force cvar("g_friendlyfire_virtual_force")
index c356c359fc9f6041eb93ab770b5f4a7839d28afb..5251ee55f95c38b1327f88a926c78fa4f88e6876 100644 (file)
@@ -1263,38 +1263,7 @@ void ClientConnect(entity this)
        TRANSMUTE(Client, this);
        CS(this).version_nagtime = time + 10 + random() * 10;
 
        TRANSMUTE(Client, this);
        CS(this).version_nagtime = time + 10 + random() * 10;
 
-       // identify the right forced team
-       if (autocvar_g_campaign)
-       {
-               if (IS_REAL_CLIENT(this)) // only players, not bots
-               {
-                       switch (autocvar_g_campaign_forceteam)
-                       {
-                               case 1: this.team_forced = NUM_TEAM_1; break;
-                               case 2: this.team_forced = NUM_TEAM_2; break;
-                               case 3: this.team_forced = NUM_TEAM_3; break;
-                               case 4: this.team_forced = NUM_TEAM_4; break;
-                               default: this.team_forced = 0;
-                       }
-               }
-       }
-       else if (PlayerInList(this, autocvar_g_forced_team_red))    this.team_forced = NUM_TEAM_1;
-       else if (PlayerInList(this, autocvar_g_forced_team_blue))   this.team_forced = NUM_TEAM_2;
-       else if (PlayerInList(this, autocvar_g_forced_team_yellow)) this.team_forced = NUM_TEAM_3;
-       else if (PlayerInList(this, autocvar_g_forced_team_pink))   this.team_forced = NUM_TEAM_4;
-       else switch (autocvar_g_forced_team_otherwise)
-       {
-               default: this.team_forced = 0; break;
-               case "red": this.team_forced = NUM_TEAM_1; break;
-               case "blue": this.team_forced = NUM_TEAM_2; break;
-               case "yellow": this.team_forced = NUM_TEAM_3; break;
-               case "pink": this.team_forced = NUM_TEAM_4; break;
-               case "spectate":
-               case "spectator":
-                       this.team_forced = -1;
-                       break;
-       }
-       if (!teamplay && this.team_forced > 0) this.team_forced = 0;
+       Player_DetermineForcedTeam(this);
 
        int playerid_save = this.playerid;
        this.playerid = 0; // silent
 
        int playerid_save = this.playerid;
        this.playerid = 0; // silent
@@ -2107,7 +2076,7 @@ void ShowRespawnCountdown(entity this)
 .bool team_selected;
 bool ShowTeamSelection(entity this)
 {
 .bool team_selected;
 bool ShowTeamSelection(entity this)
 {
-       if(!teamplay || autocvar_g_campaign || autocvar_g_balance_teams || this.team_selected || (CS(this).wasplayer && autocvar_g_changeteam_banned) || this.team_forced > 0)
+       if (!teamplay || autocvar_g_campaign || autocvar_g_balance_teams || this.team_selected || (CS(this).wasplayer && autocvar_g_changeteam_banned) || Player_HasRealForcedTeam(this))
                return false;
        stuffcmd(this, "menu_showteamselect\n");
        return true;
                return false;
        stuffcmd(this, "menu_showteamselect\n");
        return true;
@@ -2155,7 +2124,7 @@ int nJoinAllowed(entity this, entity ignore)
                        return 0;
        }
 
                        return 0;
        }
 
-       if(this && this.team_forced < 0)
+       if(this && (Player_GetForcedTeamIndex(this) == TEAM_FORCE_SPECTATOR))
                return 0; // forced spectators can never join
 
        // TODO simplify this
                return 0; // forced spectators can never join
 
        // TODO simplify this
@@ -2707,7 +2676,7 @@ void PlayerPreThink (entity this)
                // don't do this in ClientConnect
                // many things can go wrong if a client is spawned as player on connection
                if (MUTATOR_CALLHOOK(AutoJoinOnConnection, this)
                // don't do this in ClientConnect
                // many things can go wrong if a client is spawned as player on connection
                if (MUTATOR_CALLHOOK(AutoJoinOnConnection, this)
-                       || (!(autocvar_sv_spectate || autocvar_g_campaign || this.team_forced < 0)
+                       || (!(autocvar_sv_spectate || autocvar_g_campaign || (Player_GetForcedTeamIndex(this) == TEAM_FORCE_SPECTATOR))
                                && (!teamplay || autocvar_g_balance_teams)))
                {
                        campaign_bots_may_start = true;
                                && (!teamplay || autocvar_g_balance_teams)))
                {
                        campaign_bots_may_start = true;
index 0e6781e374120ba2c964ff7edd444715cb13b729..30abb6848794221e08a675dc7b2cc251facd306d 100644 (file)
@@ -118,7 +118,7 @@ void ClientCommand_clientversion(entity caller, float request, float argc)  // i
                                        {
                                                // JoinBestTeam(caller, false, true);
                                        }
                                        {
                                                // JoinBestTeam(caller, false, true);
                                        }
-                                       else if (teamplay && !autocvar_sv_spectate && !(caller.team_forced > 0))
+                                       else if (teamplay && !autocvar_sv_spectate && !(Player_GetForcedTeamIndex(caller) > 0))
                                        {
                                                TRANSMUTE(Observer, caller);  // really?
                                                stuffcmd(caller, "menu_showteamselect\n");
                                        {
                                                TRANSMUTE(Observer, caller);  // really?
                                                stuffcmd(caller, "menu_showteamselect\n");
@@ -338,7 +338,7 @@ void ClientCommand_selectteam(entity caller, float request, float argc)
                                sprint(caller, "^7selectteam can only be used in teamgames\n");
                                return;
                        }
                                sprint(caller, "^7selectteam can only be used in teamgames\n");
                                return;
                        }
-                       if (caller.team_forced > 0)
+                       if (Player_GetForcedTeamIndex(caller) > 0)
                        {
                                sprint(caller, "^7selectteam can not be used as your team is forced\n");
                                return;
                        {
                                sprint(caller, "^7selectteam can not be used as your team is forced\n");
                                return;
index 9ba78c32a0546cce999d177a6649adfa8e0f42fb..8b8c345d8037f86822568be780091aaaf7ac224a 100644 (file)
@@ -1052,8 +1052,8 @@ void GameCommand_moveplayer(float request, float argc)
                                                        {
                                                                // set up
                                                                float team_id;
                                                        {
                                                                // set up
                                                                float team_id;
-                                                               float save = client.team_forced;
-                                                               client.team_forced = 0;
+                                                               int save = Player_GetForcedTeamIndex(client);
+                                                               Player_SetForcedTeamIndex(client, TEAM_FORCE_DEFAULT);
 
                                                                // find the team to move the player to
                                                                team_id = Team_ColorToTeam(destination);
 
                                                                // find the team to move the player to
                                                                team_id = Team_ColorToTeam(destination);
@@ -1073,7 +1073,7 @@ void GameCommand_moveplayer(float request, float argc)
                                                                {
                                                                        balance = TeamBalance_CheckAllowedTeams(client);
                                                                }
                                                                {
                                                                        balance = TeamBalance_CheckAllowedTeams(client);
                                                                }
-                                                               client.team_forced = save;
+                                                               Player_SetForcedTeamIndex(client, save);
 
                                                                // Check to see if the destination team is even available
                                                                switch (team_id)
 
                                                                // Check to see if the destination team is even available
                                                                switch (team_id)
@@ -1130,7 +1130,7 @@ void GameCommand_moveplayer(float request, float argc)
                                                                }
 
                                                                // If so, lets continue and finally move the player
                                                                }
 
                                                                // If so, lets continue and finally move the player
-                                                               client.team_forced = 0;
+                                                               Player_SetForcedTeamIndex(client, TEAM_FORCE_DEFAULT);
                                                                if (MoveToTeam(client, Team_TeamToIndex(team_id), 6))
                                                                {
                                                                        successful = strcat(successful, (successful ? ", " : ""), playername(client, false));
                                                                if (MoveToTeam(client, Team_TeamToIndex(team_id), 6))
                                                                {
                                                                        successful = strcat(successful, (successful ? ", " : ""), playername(client, false));
@@ -1312,7 +1312,7 @@ void GameCommand_shuffleteams(float request)
                        }
 
                        FOREACH_CLIENT(IS_PLAYER(it) || it.caplayer, {
                        }
 
                        FOREACH_CLIENT(IS_PLAYER(it) || it.caplayer, {
-                               if (it.team_forced) {
+                               if (Player_HasRealForcedTeam(it)) {
                                        // we could theoretically assign forced players to their teams
                                        // and shuffle the rest to fill the empty spots but in practise
                                        // either all players or none are gonna have forced teams
                                        // we could theoretically assign forced players to their teams
                                        // and shuffle the rest to fill the empty spots but in practise
                                        // either all players or none are gonna have forced teams
index d2a695aeb988c274df6e478527ae09cfbee8f753..908d99444887f43ebeef093a34039fc532d08089 100644 (file)
@@ -354,8 +354,6 @@ const float ACTIVE_TOGGLE   = 3;
 
 //float serverflags;
 
 
 //float serverflags;
 
-.float team_forced; // can be a team number to force a team, or 0 for default action, or -1 for forced spectator
-
 .float player_blocked;
 
 .float revival_time; // time at which player was last revived
 .float player_blocked;
 
 .float revival_time; // time at which player was last revived
index 400943a636b3ad5c0b22c0d4fe960b792f4c26f3..6b2778b0916c99a4cf0dadd1da21d9ac4e60d957 100644 (file)
@@ -28,6 +28,8 @@ enum
 /// \brief Indicates that the player is not allowed to join a team.
 const int TEAM_NOT_ALLOWED = -1;
 
 /// \brief Indicates that the player is not allowed to join a team.
 const int TEAM_NOT_ALLOWED = -1;
 
+.float team_forced; // can be a team number to force a team, or 0 for default action, or -1 for forced spectator
+
 .int m_team_balance_state; ///< Holds the state of the team balance entity.
 .entity m_team_balance_team[NUM_TEAMS]; ///< ???
 
 .int m_team_balance_state; ///< Holds the state of the team balance entity.
 .entity m_team_balance_team[NUM_TEAMS]; ///< ???
 
@@ -37,6 +39,11 @@ const int TEAM_NOT_ALLOWED = -1;
 .int m_num_players_alive; ///< Number of alive players in a team.
 .int m_num_control_points; ///< Number of control points owned by a team.
 
 .int m_num_players_alive; ///< Number of alive players in a team.
 .int m_num_control_points; ///< Number of control points owned by a team.
 
+string autocvar_g_forced_team_red;
+string autocvar_g_forced_team_blue;
+string autocvar_g_forced_team_yellow;
+string autocvar_g_forced_team_pink;
+
 entity g_team_entities[NUM_TEAMS]; ///< Holds global team entities.
 
 STATIC_INIT(g_team_entities)
 entity g_team_entities[NUM_TEAMS]; ///< Holds global team entities.
 
 STATIC_INIT(g_team_entities)
@@ -254,6 +261,96 @@ void LogTeamchange(float player_id, float team_number, int type)
        GameLogEcho(strcat(":team:", ftos(player_id), ":", ftos(team_number), ":", ftos(type)));
 }
 
        GameLogEcho(strcat(":team:", ftos(player_id), ":", ftos(team_number), ":", ftos(type)));
 }
 
+bool Player_HasRealForcedTeam(entity player)
+{
+       return player.team_forced > TEAM_FORCE_DEFAULT;
+}
+
+int Player_GetForcedTeamIndex(entity player)
+{
+       return player.team_forced;
+}
+
+void Player_SetForcedTeamIndex(entity player, int team_index)
+{
+       player.team_forced = team_index;
+}
+
+void Player_DetermineForcedTeam(entity player)
+{
+       if (autocvar_g_campaign)
+       {
+               if (IS_REAL_CLIENT(player)) // only players, not bots
+               {
+                       if (Team_IsValidIndex(autocvar_g_campaign_forceteam))
+                       {
+                               player.team_forced = autocvar_g_campaign_forceteam;
+                       }
+                       else
+                       {
+                               player.team_forced = TEAM_FORCE_DEFAULT;
+                       }
+               }
+       }
+       else if (PlayerInList(player, autocvar_g_forced_team_red))
+       {
+               player.team_forced = 1;
+       }
+       else if (PlayerInList(player, autocvar_g_forced_team_blue))
+       {
+               player.team_forced = 2;
+       }
+       else if (PlayerInList(player, autocvar_g_forced_team_yellow))
+       {
+               player.team_forced = 3;
+       }
+       else if (PlayerInList(player, autocvar_g_forced_team_pink))
+       {
+               player.team_forced = 4;
+       }
+       else
+       {
+               switch (autocvar_g_forced_team_otherwise)
+               {
+                       case "red":
+                       {
+                               player.team_forced = 1;
+                               break;
+                       }
+                       case "blue":
+                       {
+                               player.team_forced = 2;
+                               break;
+                       }
+                       case "yellow":
+                       {
+                               player.team_forced = 3;
+                               break;
+                       }
+                       case "pink":
+                       {
+                               player.team_forced = 4;
+                               break;
+                       }
+                       case "spectate":
+                       case "spectator":
+                       {
+                               player.team_forced = TEAM_FORCE_SPECTATOR;
+                               break;
+                       }
+                       default:
+                       {
+                               player.team_forced = TEAM_FORCE_DEFAULT;
+                               break;
+                       }
+               }
+       }
+       if (!teamplay && Player_HasRealForcedTeam(player))
+       {
+               player.team_forced = TEAM_FORCE_DEFAULT;
+       }
+}
+
 entity TeamBalance_CheckAllowedTeams(entity for_whom)
 {
        entity balance = spawn();
 entity TeamBalance_CheckAllowedTeams(entity for_whom)
 {
        entity balance = spawn();
@@ -383,7 +480,7 @@ entity TeamBalance_CheckAllowedTeams(entity for_whom)
        // if player has a forced team, ONLY allow that one
        for (int i = 1; i <= NUM_TEAMS; ++i)
        {
        // if player has a forced team, ONLY allow that one
        for (int i = 1; i <= NUM_TEAMS; ++i)
        {
-               if (for_whom.team_forced == Team_IndexToTeam(i) &&
+               if (for_whom.team_forced == i &&
                        TeamBalance_IsTeamAllowedInternal(balance, i))
                {
                        TeamBalance_BanTeamsExcept(balance, i);
                        TeamBalance_IsTeamAllowedInternal(balance, i))
                {
                        TeamBalance_BanTeamsExcept(balance, i);
@@ -487,9 +584,9 @@ void TeamBalance_GetTeamCounts(entity balance, entity ignore)
                        {
                                team_num = it.team;
                        }
                        {
                                team_num = it.team;
                        }
-                       else if (it.team_forced > 0)
+                       else if (Player_HasRealForcedTeam(it))
                        {
                        {
-                               team_num = it.team_forced; // reserve the spot
+                               team_num = Team_IndexToTeam(it.team_forced); // reserve the spot
                        }
                        else
                        {
                        }
                        else
                        {
index 776a80d329cf91d5917f1af4e1ba7275eb18a731..5e8b9fea718bcd22fab37eff9f39c3b64e382371 100644 (file)
@@ -110,6 +110,20 @@ enum
 
 void LogTeamchange(float player_id, float team_number, int type);
 
 
 void LogTeamchange(float player_id, float team_number, int type);
 
+enum
+{
+       TEAM_FORCE_SPECTATOR = -1,
+       TEAM_FORCE_DEFAULT = 0
+};
+
+bool Player_HasRealForcedTeam(entity player);
+
+int Player_GetForcedTeamIndex(entity player);
+
+void Player_SetForcedTeamIndex(entity player, int team_index);
+
+void Player_DetermineForcedTeam(entity player);
+
 // ========================= Team balance API =================================
 
 /// \brief Checks whether the player can join teams according to global
 // ========================= Team balance API =================================
 
 /// \brief Checks whether the player can join teams according to global