]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/teamplay.qc
Merge branch 'master' into Lyberta/TeamplayOverhaul2
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / teamplay.qc
index f16846294ca48376de00d8172fbfc0874e7fc369..1959fe369791811fd19385308acb52e3795df9be 100644 (file)
@@ -751,22 +751,37 @@ int TeamBalance_FindBestTeams(entity balance, entity player, bool use_score)
 void TeamBalance_JoinBestTeam(entity this)
 {
        //PrintToChatAll(sprintf("JoinBestTeam: %s", this.netname));
-       // don't join a team if we're not playing a team game
        if (!teamplay)
        {
                return;
        }
-
-       // find out what teams are available
-       entity balance = TeamBalance_CheckAllowedTeams(this);
-
        if (this.bot_forced_team)
        {
+               return;
+       }
+       int old_team_index = Team_TeamToIndex(this.team);
+       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 ((old_team_index != -1) && !IS_BOT_CLIENT(this))
+               {
+                       TeamBalance_AutoBalanceBots(forced_team_index, old_team_index);
+               }
                return;
        }
        int best_team_index = TeamBalance_FindBestTeam(balance, this, true);
-       int old_team_index = Team_TeamToIndex(this.team);
        TeamBalance_Destroy(balance);
        PlayerScore_Clear(this);
        if (!SetPlayerTeam(this, best_team_index, TEAM_CHANGE_AUTO))
@@ -1060,5 +1075,9 @@ void SV_ChangeTeam(entity this, float _color)
        {
                return;
        }
+       if (source_team_index == -1)
+       {
+               return;
+       }
        TeamBalance_AutoBalanceBots(destination_team_index, source_team_index);
 }