From: TimePath Date: Sun, 27 Aug 2017 08:34:53 +0000 (+1000) Subject: GameRules: simplify assigning teams bitmask X-Git-Tag: xonotic-v0.8.5~2501^2~3 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=2b44eaacadad415ca88acf919baf4180f7add34d;p=xonotic%2Fxonotic-data.pk3dir.git GameRules: simplify assigning teams bitmask --- diff --git a/qcsrc/server/mutators/mutator/gamemode_assault.qc b/qcsrc/server/mutators/mutator/gamemode_assault.qc index d1d8538f9..e839546d8 100644 --- a/qcsrc/server/mutators/mutator/gamemode_assault.qc +++ b/qcsrc/server/mutators/mutator/gamemode_assault.qc @@ -618,10 +618,7 @@ MUTATOR_HOOKFUNCTION(as, ReadyRestart_Deny) // scoreboard setup void assault_ScoreRules() { - int teams = 0; - teams |= BIT(0); - teams |= BIT(1); // always red vs blue - + int teams = BITS(2); // always red vs blue GameRules_scoring(teams, SFL_SORT_PRIO_SECONDARY, SFL_SORT_PRIO_SECONDARY, { field_team(ST_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY); field(SP_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY); diff --git a/qcsrc/server/mutators/mutator/gamemode_ca.qh b/qcsrc/server/mutators/mutator/gamemode_ca.qh index 6d4786ee5..5a4a9f843 100644 --- a/qcsrc/server/mutators/mutator/gamemode_ca.qh +++ b/qcsrc/server/mutators/mutator/gamemode_ca.qh @@ -33,17 +33,9 @@ REGISTER_MUTATOR(ca, false) ca_teams = autocvar_g_ca_teams_override; if (ca_teams < 2) ca_teams = cvar("g_ca_teams"); // read the cvar directly as it gets written earlier in the same frame - ca_teams = bound(2, ca_teams, 4); - int teams = 0; - if(ca_teams >= 1) teams |= BIT(0); - if(ca_teams >= 2) teams |= BIT(1); - if(ca_teams >= 3) teams |= BIT(2); - if(ca_teams >= 4) teams |= BIT(3); - - ca_teams = teams; // now set it? - - GameRules_scoring(teams, SFL_SORT_PRIO_PRIMARY, 0, { + ca_teams = BITS(bound(2, ca_teams, 4)); + GameRules_scoring(ca_teams, SFL_SORT_PRIO_PRIMARY, 0, { field_team(ST_CA_ROUNDS, "rounds", SFL_SORT_PRIO_PRIMARY); }); diff --git a/qcsrc/server/mutators/mutator/gamemode_freezetag.qc b/qcsrc/server/mutators/mutator/gamemode_freezetag.qc index eeb6fd0e5..88afaa755 100644 --- a/qcsrc/server/mutators/mutator/gamemode_freezetag.qc +++ b/qcsrc/server/mutators/mutator/gamemode_freezetag.qc @@ -7,13 +7,6 @@ float autocvar_g_freezetag_round_timelimit; int autocvar_g_freezetag_teams_override; float autocvar_g_freezetag_warmup; -void freezetag_ScoreRules(int teams) -{ - GameRules_scoring(teams, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, { - field(SP_FREEZETAG_REVIVALS, "revivals", 0); - }); -} - void freezetag_count_alive_players() { total_players = redalive = bluealive = yellowalive = pinkalive = 0; @@ -579,16 +572,11 @@ void freezetag_Initialize() freezetag_teams = autocvar_g_freezetag_teams_override; if(freezetag_teams < 2) freezetag_teams = cvar("g_freezetag_teams"); // read the cvar directly as it gets written earlier in the same frame - freezetag_teams = bound(2, freezetag_teams, 4); - - int teams = 0; - if(freezetag_teams >= 1) teams |= BIT(0); - if(freezetag_teams >= 2) teams |= BIT(1); - if(freezetag_teams >= 3) teams |= BIT(2); - if(freezetag_teams >= 4) teams |= BIT(3); - freezetag_teams = teams; // now set it? - freezetag_ScoreRules(freezetag_teams); + freezetag_teams = BITS(bound(2, freezetag_teams, 4)); + GameRules_scoring(freezetag_teams, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, { + field(SP_FREEZETAG_REVIVALS, "revivals", 0); + }); round_handler_Spawn(freezetag_CheckTeams, freezetag_CheckWinner, func_null); round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit); diff --git a/qcsrc/server/mutators/mutator/gamemode_invasion.qc b/qcsrc/server/mutators/mutator/gamemode_invasion.qc index 48c1e2dc7..1b8b77ae0 100644 --- a/qcsrc/server/mutators/mutator/gamemode_invasion.qc +++ b/qcsrc/server/mutators/mutator/gamemode_invasion.qc @@ -576,14 +576,7 @@ void invasion_DelayedInit(entity this) // Do this check with a delay so we can w if(autocvar_g_invasion_teams) { - invasion_teams = bound(2, autocvar_g_invasion_teams, 4); - int teams = 0; - if(invasion_teams >= 1) teams |= BIT(0); - if(invasion_teams >= 2) teams |= BIT(1); - if(invasion_teams >= 3) teams |= BIT(2); - if(invasion_teams >= 4) teams |= BIT(3); - - invasion_teams = teams; // now set it? + invasion_teams = BITS(bound(2, autocvar_g_invasion_teams, 4)); } else invasion_teams = 0; diff --git a/qcsrc/server/mutators/mutator/gamemode_keyhunt.qc b/qcsrc/server/mutators/mutator/gamemode_keyhunt.qc index 49de90ab1..864290301 100644 --- a/qcsrc/server/mutators/mutator/gamemode_keyhunt.qc +++ b/qcsrc/server/mutators/mutator/gamemode_keyhunt.qc @@ -986,15 +986,7 @@ void kh_Initialize() // sets up th KH environment kh_teams = autocvar_g_keyhunt_teams_override; if(kh_teams < 2) kh_teams = cvar("g_keyhunt_teams"); // read the cvar directly as it gets written earlier in the same frame - kh_teams = bound(2, kh_teams, 4); - - int teams = 0; - if(kh_teams >= 1) teams |= BIT(0); - if(kh_teams >= 2) teams |= BIT(1); - if(kh_teams >= 3) teams |= BIT(2); - if(kh_teams >= 4) teams |= BIT(3); - - kh_teams = teams; // now set it? + kh_teams = BITS(bound(2, kh_teams, 4)); // make a KH entity for controlling the game kh_controller = spawn(); diff --git a/qcsrc/server/mutators/mutator/gamemode_race.qc b/qcsrc/server/mutators/mutator/gamemode_race.qc index c3dddab16..2f581d8c4 100644 --- a/qcsrc/server/mutators/mutator/gamemode_race.qc +++ b/qcsrc/server/mutators/mutator/gamemode_race.qc @@ -440,14 +440,7 @@ void rc_SetLimits() if(autocvar_g_race_teams) { GameRules_teams(true); - race_teams = bound(2, autocvar_g_race_teams, 4); - int teams = 0; - if(race_teams >= 1) teams |= BIT(0); - if(race_teams >= 2) teams |= BIT(1); - if(race_teams >= 3) teams |= BIT(2); - if(race_teams >= 4) teams |= BIT(3); - - race_teams = teams; // now set it? + race_teams = BITS(bound(2, autocvar_g_race_teams, 4)); } else race_teams = 0; diff --git a/qcsrc/server/mutators/mutator/gamemode_tdm.qc b/qcsrc/server/mutators/mutator/gamemode_tdm.qc index 101f57fcc..aad319328 100644 --- a/qcsrc/server/mutators/mutator/gamemode_tdm.qc +++ b/qcsrc/server/mutators/mutator/gamemode_tdm.qc @@ -36,16 +36,9 @@ void tdm_DelayedInit(entity this) LOG_TRACE("No \"tdm_team\" entities found on this map, creating them anyway."); int numteams = autocvar_g_tdm_teams_override; - if(numteams < 2) { numteams = autocvar_g_tdm_teams; } - numteams = bound(2, numteams, 4); - - int teams = 0; - if(numteams >= 1) teams |= BIT(0); - if(numteams >= 2) teams |= BIT(1); - if(numteams >= 3) teams |= BIT(2); - if(numteams >= 4) teams |= BIT(3); + int teams = BITS(bound(2, numteams, 4)); if(teams & BIT(0)) tdm_SpawnTeam("Red", NUM_TEAM_1); if(teams & BIT(1))