]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Fix bots joining red and crashing when red team is unavailable
authorMario <mario@smbclan.net>
Thu, 23 Jun 2016 18:57:12 +0000 (04:57 +1000)
committerMario <mario@smbclan.net>
Thu, 23 Jun 2016 18:57:12 +0000 (04:57 +1000)
qcsrc/server/mutators/mutator/gamemode_ctf.qc
qcsrc/server/scores_rules.qc
qcsrc/server/teamplay.qc

index 03a61509ce1b4929e564abf1cc6c7eb5e40cd069..618e26501c623cd9485436cfb7cc1a7f56c02b14 100644 (file)
@@ -2577,14 +2577,21 @@ void ctf_DelayedInit(entity this) // Do this check with a delay so we can wait f
 
                switch(tmp_entity.team)
                {
-                       case NUM_TEAM_1: ctf_teams |= BIT(0); break;
-                       case NUM_TEAM_2: ctf_teams |= BIT(1); break;
-                       case NUM_TEAM_3: ctf_teams |= BIT(2); break;
-                       case NUM_TEAM_4: ctf_teams |= BIT(3); break;
+                       case NUM_TEAM_1: BITSET_ASSIGN(ctf_teams, BIT(0)); break;
+                       case NUM_TEAM_2: BITSET_ASSIGN(ctf_teams, BIT(1)); break;
+                       case NUM_TEAM_3: BITSET_ASSIGN(ctf_teams, BIT(2)); break;
+                       case NUM_TEAM_4: BITSET_ASSIGN(ctf_teams, BIT(3)); break;
                }
                if(tmp_entity.team == 0) { ctf_oneflag = true; }
        }
 
+       if(NumTeams(ctf_teams) < 2) // somehow, there's not enough flags!
+       {
+               ctf_teams = 0; // so set the default red and blue teams
+               BITSET_ASSIGN(ctf_teams, BIT(0));
+               BITSET_ASSIGN(ctf_teams, BIT(1));
+       }
+
        //ctf_teams = bound(2, ctf_teams, 4);
 
        // if no teams are found, spawn defaults
index b6846934fa684719b3f391038802d9d0d3586d43..a6786595f947b3059938b9df4e90489415211f37 100644 (file)
@@ -7,7 +7,7 @@ void CheckAllowedTeams (entity for_whom);
 
 int NumTeams(int teams)
 {
-       return (teams & BIT(0)) + (teams & BIT(1)) + (teams & BIT(2)) + (teams & BIT(3));
+       return boolean(teams & BIT(0)) + boolean(teams & BIT(1)) + boolean(teams & BIT(2)) + boolean(teams & BIT(3));
 }
 
 // NOTE: SP_ constants may not be >= MAX_SCORE; ST_constants may not be >= MAX_TEAMSCORE
index 742b9ef6d57314f07aa88bb40f105611b5b49615..921bf0cef80c8ec64c0b4f8f9d0b4aca3890545e 100644 (file)
@@ -424,8 +424,12 @@ float TeamSmallerEqThanTeam(float ta, float tb, entity e)
 // NOTE: Assumes CheckAllowedTeams has already been called!
 float FindSmallestTeam(entity pl, float ignore_pl)
 {
-       float totalteams, t;
-       totalteams = 0;
+       int totalteams = 0;
+       int t = 1; // initialize with a random team?
+       if(c4 >= 0) t = 4;
+       if(c3 >= 0) t = 3;
+       if(c2 >= 0) t = 2;
+       if(c1 >= 0) t = 1;
 
        // find out what teams are available
        //CheckAllowedTeams();
@@ -459,7 +463,8 @@ float FindSmallestTeam(entity pl, float ignore_pl)
 
        RandomSelection_Init();
 
-       t = 1;
+       if(TeamSmallerEqThanTeam(1, t, pl))
+               t = 1;
        if(TeamSmallerEqThanTeam(2, t, pl))
                t = 2;
        if(TeamSmallerEqThanTeam(3, t, pl))