]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
GameRules: simplify assigning teams bitmask
authorTimePath <andrew.hardaker1995@gmail.com>
Sun, 27 Aug 2017 08:34:53 +0000 (18:34 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Sun, 27 Aug 2017 08:34:53 +0000 (18:34 +1000)
qcsrc/server/mutators/mutator/gamemode_assault.qc
qcsrc/server/mutators/mutator/gamemode_ca.qh
qcsrc/server/mutators/mutator/gamemode_freezetag.qc
qcsrc/server/mutators/mutator/gamemode_invasion.qc
qcsrc/server/mutators/mutator/gamemode_keyhunt.qc
qcsrc/server/mutators/mutator/gamemode_race.qc
qcsrc/server/mutators/mutator/gamemode_tdm.qc

index d1d8538f98c8179379a2cc74e1c085de76aa7181..e839546d8dbe34390e5fa171f40bd54b442492b2 100644 (file)
@@ -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);
index 6d4786ee529acbf5d78cb70dc459acfde7e4cd0d..5a4a9f8438ead67bbb81d9a0d47e73f5ac9c72ee 100644 (file)
@@ -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);
         });
 
index eeb6fd0e5a6b61d7034c752fb524d2bc602b47bb..88afaa755d7b9f995419411e912d431b7d4ec166 100644 (file)
@@ -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);
index 48c1e2dc7a31d48cf51b58c61e030d1bed714559..1b8b77ae078158e566fb34a87c754701436175d3 100644 (file)
@@ -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;
index 49de90ab138269c856cb8372f742ef1146213624..864290301dc6c4d2a52cf0f4b1010077ec5b5516 100644 (file)
@@ -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();
index c3dddab166bbe6c7de2d9a2466d5d7102381460f..2f581d8c433af0c6b8047e71ab7571825eb7ceba 100644 (file)
@@ -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;
index 101f57fcc4d6efb96ecd5d2ed5157b0065c29060..aad31932884556dff7b4a7b6f1a186dcbf15e44c 100644 (file)
@@ -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))