From: Mario Date: Thu, 23 Jun 2016 18:57:12 +0000 (+1000) Subject: Fix bots joining red and crashing when red team is unavailable X-Git-Tag: xonotic-v0.8.2~700^2~10^2~6 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=ec0b13540050fc7b33b7a7bd1ddb6d07c329b4f3;p=xonotic%2Fxonotic-data.pk3dir.git Fix bots joining red and crashing when red team is unavailable --- diff --git a/qcsrc/server/mutators/mutator/gamemode_ctf.qc b/qcsrc/server/mutators/mutator/gamemode_ctf.qc index 03a61509c..618e26501 100644 --- a/qcsrc/server/mutators/mutator/gamemode_ctf.qc +++ b/qcsrc/server/mutators/mutator/gamemode_ctf.qc @@ -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 diff --git a/qcsrc/server/scores_rules.qc b/qcsrc/server/scores_rules.qc index b6846934f..a6786595f 100644 --- a/qcsrc/server/scores_rules.qc +++ b/qcsrc/server/scores_rules.qc @@ -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 diff --git a/qcsrc/server/teamplay.qc b/qcsrc/server/teamplay.qc index 742b9ef6d..921bf0cef 100644 --- a/qcsrc/server/teamplay.qc +++ b/qcsrc/server/teamplay.qc @@ -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))