]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
gamemodes: prevent addition and removal at runtime with a single macro
authorTimePath <andrew.hardaker1995@gmail.com>
Sun, 27 Aug 2017 09:07:38 +0000 (19:07 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Sun, 27 Aug 2017 09:07:38 +0000 (19:07 +1000)
16 files changed:
qcsrc/common/gamemodes/gamemode/nexball/nexball.qc
qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qh
qcsrc/common/mutators/base.qh
qcsrc/server/mutators/mutator/gamemode_assault.qh
qcsrc/server/mutators/mutator/gamemode_ca.qh
qcsrc/server/mutators/mutator/gamemode_ctf.qc
qcsrc/server/mutators/mutator/gamemode_cts.qh
qcsrc/server/mutators/mutator/gamemode_deathmatch.qh
qcsrc/server/mutators/mutator/gamemode_domination.qh
qcsrc/server/mutators/mutator/gamemode_freezetag.qh
qcsrc/server/mutators/mutator/gamemode_invasion.qh
qcsrc/server/mutators/mutator/gamemode_keepaway.qh
qcsrc/server/mutators/mutator/gamemode_keyhunt.qh
qcsrc/server/mutators/mutator/gamemode_lms.qh
qcsrc/server/mutators/mutator/gamemode_race.qh
qcsrc/server/mutators/mutator/gamemode_tdm.qh

index 62280d7c24c80dd1806dbd026e11f9d782c505b2..f7784db18a23f9289fc90038cfc1e0171a13fb27 100644 (file)
@@ -1141,6 +1141,7 @@ MUTATOR_HOOKFUNCTION(nb, SendWaypoint)
 
 REGISTER_MUTATOR(nb, g_nexball)
 {
+    MUTATOR_STATIC();
        MUTATOR_ONADD
        {
                g_nexball_meter_period = autocvar_g_nexball_meter_period;
@@ -1168,17 +1169,7 @@ REGISTER_MUTATOR(nb, g_nexball)
        MUTATOR_ONROLLBACK_OR_REMOVE
        {
                WEP_NEXBALL.spawnflags |= WEP_FLAG_MUTATORBLOCKED;
-               // we actually cannot roll back nb_delayedinit here
-               // BUT: we don't need to! If this gets called, adding always
-               // succeeds.
        }
-
-       MUTATOR_ONREMOVE
-       {
-               LOG_INFO("This is a game type and it cannot be removed at runtime.");
-               return -1;
-       }
-
        return 0;
 }
 
index 7f2434915e7a67b6d6ed269e36ecb4d351d88014..c1cce29be7ec8b7bf051e8b49577e9600f99bd25 100644 (file)
@@ -5,29 +5,14 @@ void ons_Initialize();
 
 REGISTER_MUTATOR(ons, false)
 {
+    MUTATOR_STATIC();
        MUTATOR_ONADD
        {
-               if (time > 1) // game loads at time 1
-                       error("This is a game type and it cannot be added at runtime.");
                ons_Initialize();
 
                GameRules_teams(true);
                GameRules_limit_score(autocvar_g_onslaught_point_limit);
        }
-
-       MUTATOR_ONROLLBACK_OR_REMOVE
-       {
-               // we actually cannot roll back ons_Initialize here
-               // BUT: we don't need to! If this gets called, adding always
-               // succeeds.
-       }
-
-       MUTATOR_ONREMOVE
-       {
-               LOG_INFO("This is a game type and it cannot be removed at runtime.");
-               return -1;
-       }
-
        return false;
 }
 
index 7fc47ff9e0700ad512cd4d4c7497261afc715818..4f940c42b3c016f3e9131e0c6d3b213bc4d5497a 100644 (file)
@@ -280,6 +280,20 @@ STATIC_INIT_LATE(Mutators) {
 #define MUTATOR_ONADD                   if (mode == MUTATOR_ADDING)
 #define MUTATOR_ONREMOVE                if (mode == MUTATOR_REMOVING)
 #define MUTATOR_ONROLLBACK_OR_REMOVE    if (mode == MUTATOR_REMOVING || mode == MUTATOR_ROLLING_BACK)
+
+#define MUTATOR_STATIC() MACRO_BEGIN { \
+    MUTATOR_ONADD { \
+        /* game loads at time 1 */ \
+        if (time > 1) { \
+            error("This is a game type and it cannot be added at runtime."); \
+        } \
+    } \
+       MUTATOR_ONREMOVE { \
+               LOG_INFO("This is a game type and it cannot be removed at runtime."); \
+               return -1; \
+       } \
+} MACRO_END
+
 #define MUTATOR_ADD(name)               Mutator_Add(MUTATOR_##name)
 #define MUTATOR_REMOVE(name)            Mutator_Remove(MUTATOR_##name)
 #define MUTATOR_RETURNVALUE             CallbackChain_ReturnValue
index abe89ecca40e6fbbdef4b065a84a0d20eb98fa4d..0e279b8dc6254fa9d3b0122b0997db9d9a96471c 100644 (file)
@@ -6,28 +6,12 @@ void assault_ScoreRules();
 
 REGISTER_MUTATOR(as, false)
 {
-       GameRules_teams(true);
-
+    MUTATOR_STATIC();
        MUTATOR_ONADD
        {
-               if (time > 1) // game loads at time 1
-                       error("This is a game type and it cannot be added at runtime.");
+        GameRules_teams(true);
                assault_ScoreRules();
        }
-
-       MUTATOR_ONROLLBACK_OR_REMOVE
-       {
-               // we actually cannot roll back assault_Initialize here
-               // BUT: we don't need to! If this gets called, adding always
-               // succeeds.
-       }
-
-       MUTATOR_ONREMOVE
-       {
-               LOG_INFO("This is a game type and it cannot be removed at runtime.");
-               return -1;
-       }
-
        return 0;
 }
 
index 5a4a9f8438ead67bbb81d9a0d47e73f5ac9c72ee..bf4a453a3bf9d4fadbce34403be210ff8c3773c0 100644 (file)
@@ -23,11 +23,9 @@ bool ca_isEliminated(entity e);
 
 REGISTER_MUTATOR(ca, false)
 {
+    MUTATOR_STATIC();
        MUTATOR_ONADD
        {
-               // game loads at time 1
-               if (time > 1) error("This is a game type and it cannot be added at runtime.");
-
                allowed_to_spawn = true;
 
                ca_teams = autocvar_g_ca_teams_override;
@@ -50,13 +48,6 @@ REGISTER_MUTATOR(ca, false)
 
         GameRules_spawning_teams(autocvar_g_ca_team_spawns);
        }
-
-       MUTATOR_ONREMOVE
-       {
-               LOG_INFO("This is a game type and it cannot be removed at runtime.");
-               return -1;
-       }
-
        return 0;
 }
 
index 08162f7ab9b92920462e27b8d3312675e37c89f6..8e11e1d7890d61cfe3e53b0b40e9bf1abb2e6fd8 100644 (file)
@@ -6,30 +6,15 @@ void ctf_Initialize();
 
 REGISTER_MUTATOR(ctf, false)
 {
+    MUTATOR_STATIC();
        MUTATOR_ONADD
        {
-               if (time > 1) // game loads at time 1
-                       error("This is a game type and it cannot be added at runtime.");
                ctf_Initialize();
 
                GameRules_teams(true);
         GameRules_limit_score(autocvar_capturelimit_override);
         GameRules_limit_lead(autocvar_captureleadlimit_override);
        }
-
-       MUTATOR_ONROLLBACK_OR_REMOVE
-       {
-               // we actually cannot roll back ctf_Initialize here
-               // BUT: we don't need to! If this gets called, adding always
-               // succeeds.
-       }
-
-       MUTATOR_ONREMOVE
-       {
-               LOG_INFO("This is a game type and it cannot be removed at runtime.");
-               return -1;
-       }
-
        return 0;
 }
 #endif
index f81ed274aed1608aaef2facd20383e6bcb9c526e..c90919e6f4e7ed176c2740a63c6a4bb9c10575c8 100644 (file)
@@ -7,11 +7,9 @@ void cts_Initialize();
 
 REGISTER_MUTATOR(cts, false)
 {
+    MUTATOR_STATIC();
        MUTATOR_ONADD
        {
-               if (time > 1) // game loads at time 1
-                       error("This is a game type and it cannot be added at runtime.");
-
                g_race_qualifying = true;
                independent_players = 1;
         GameRules_limit_score(0);
@@ -19,20 +17,6 @@ REGISTER_MUTATOR(cts, false)
 
                cts_Initialize();
        }
-
-       MUTATOR_ONROLLBACK_OR_REMOVE
-       {
-               // we actually cannot roll back cts_Initialize here
-               // BUT: we don't need to! If this gets called, adding always
-               // succeeds.
-       }
-
-       MUTATOR_ONREMOVE
-       {
-               LOG_INFO("This is a game type and it cannot be removed at runtime.");
-               return -1;
-       }
-
        return 0;
 }
 
index d3cc197eafd40efd5ed884c50713e23f746223a8..f45b0800f39d8cfefb0f30ed49f59ab81256d46c 100644 (file)
@@ -4,24 +4,6 @@
 
 REGISTER_MUTATOR(dm, false)
 {
-       MUTATOR_ONADD
-       {
-               if (time > 1) // game loads at time 1
-                       error("This is a game type and it cannot be added at runtime.");
-       }
-
-       MUTATOR_ONROLLBACK_OR_REMOVE
-       {
-               // we actually cannot roll back dm_Initialize here
-               // BUT: we don't need to! If this gets called, adding always
-               // succeeds.
-       }
-
-       MUTATOR_ONREMOVE
-       {
-               error("This is a game type and it cannot be removed at runtime.");
-               return -1;
-       }
-
+    MUTATOR_STATIC();
        return 0;
 }
index 19ba2f9a3f34249632d87f3fac62c46000ab3ef8..8b4ca399bae9de5a5e0c200d4d934448f9db0b7d 100644 (file)
@@ -11,10 +11,9 @@ void dom_Initialize();
 
 REGISTER_MUTATOR(dom, false)
 {
+    MUTATOR_STATIC();
        MUTATOR_ONADD
        {
-               if (time > 1) // game loads at time 1
-                       error("This is a game type and it cannot be added at runtime.");
                dom_Initialize();
 
                int fraglimit_override = autocvar_g_domination_point_limit;
@@ -25,13 +24,6 @@ REGISTER_MUTATOR(dom, false)
         GameRules_limit_score(fraglimit_override);
         GameRules_limit_lead(autocvar_g_domination_point_leadlimit);
        }
-
-       MUTATOR_ONREMOVE
-       {
-               LOG_INFO("This is a game type and it cannot be removed at runtime.");
-               return -1;
-       }
-
        return 0;
 }
 
index 69b857758f7e2cd6f825a368f2e96317a6959301..b84a62201dc3fe100bdbb40773c7226bb6218548 100644 (file)
@@ -9,10 +9,9 @@ void freezetag_Initialize();
 
 REGISTER_MUTATOR(ft, false)
 {
+    MUTATOR_STATIC();
        MUTATOR_ONADD
        {
-               if (time > 1) // game loads at time 1
-                       error("This is a game type and it cannot be added at runtime.");
                freezetag_Initialize();
 
                GameRules_teams(true);
@@ -21,20 +20,6 @@ REGISTER_MUTATOR(ft, false)
 
         GameRules_spawning_teams(autocvar_g_freezetag_team_spawns);
        }
-
-       MUTATOR_ONROLLBACK_OR_REMOVE
-       {
-               // we actually cannot roll back freezetag_Initialize here
-               // BUT: we don't need to! If this gets called, adding always
-               // succeeds.
-       }
-
-       MUTATOR_ONREMOVE
-       {
-               LOG_INFO("This is a game type and it cannot be removed at runtime.");
-               return -1;
-       }
-
        return 0;
 }
 
index 1b5853d305fa25af43354ae890bc2847f59d8d01..e902b5ee60e5b9465449f77c3a193836e4a7cd0f 100644 (file)
@@ -11,10 +11,9 @@ void invasion_Initialize();
 
 REGISTER_MUTATOR(inv, false)
 {
+    MUTATOR_STATIC();
        MUTATOR_ONADD
        {
-               if (time > 1) // game loads at time 1
-                       error("This is a game type and it cannot be added at runtime.");
                g_invasion = true;
                invasion_Initialize();
 
@@ -28,20 +27,6 @@ REGISTER_MUTATOR(inv, false)
                        GameRules_spawning_teams(autocvar_g_invasion_team_spawns);
                }
        }
-
-       MUTATOR_ONROLLBACK_OR_REMOVE
-       {
-               // we actually cannot roll back invasion_Initialize here
-               // BUT: we don't need to! If this gets called, adding always
-               // succeeds.
-       }
-
-       MUTATOR_ONREMOVE
-       {
-               LOG_INFO("This is a game type and it cannot be removed at runtime.");
-               return -1;
-       }
-
        return 0;
 }
 
index a13ab83a555089681bd43974e221421980665c14..21cc3e46d3b62cc90dc610b7dc9bd71da1bf519c 100644 (file)
@@ -6,26 +6,11 @@ void ka_Initialize();
 
 REGISTER_MUTATOR(ka, false)
 {
+    MUTATOR_STATIC();
        MUTATOR_ONADD
        {
-               if (time > 1) // game loads at time 1
-                       error("This is a game type and it cannot be added at runtime.");
                ka_Initialize();
        }
-
-       MUTATOR_ONROLLBACK_OR_REMOVE
-       {
-               // we actually cannot roll back ka_Initialize here
-               // BUT: we don't need to! If this gets called, adding always
-               // succeeds.
-       }
-
-       MUTATOR_ONREMOVE
-       {
-               LOG_INFO("This is a game type and it cannot be removed at runtime.");
-               return -1;
-       }
-
        return false;
 }
 
index 5b0fb5bbbddcfda065e6cdb3576d6050cb013929..9e8ded5ac875095bb5ed8c7117c5a41160b9948f 100644 (file)
@@ -9,10 +9,9 @@ void kh_Initialize();
 
 REGISTER_MUTATOR(kh, false)
 {
+    MUTATOR_STATIC();
        MUTATOR_ONADD
        {
-               if (time > 1) // game loads at time 1
-                       error("This is a game type and it cannot be added at runtime.");
                kh_Initialize();
 
                GameRules_teams(true);
@@ -20,20 +19,6 @@ REGISTER_MUTATOR(kh, false)
         GameRules_limit_lead(autocvar_g_keyhunt_point_leadlimit);
         GameRules_spawning_teams(autocvar_g_keyhunt_team_spawns);
        }
-
-       MUTATOR_ONROLLBACK_OR_REMOVE
-       {
-               // we actually cannot roll back kh_Initialize here
-               // BUT: we don't need to! If this gets called, adding always
-               // succeeds.
-       }
-
-       MUTATOR_ONREMOVE
-       {
-               LOG_INFO("This is a game type and it cannot be removed at runtime.");
-               return -1;
-       }
-
        return 0;
 }
 
index 8c47c92b7c4a1bc1b5ac32a2dc348141902fff88..303dd3bd2f52993d75130d3c7b10c4c07594bff5 100644 (file)
@@ -8,29 +8,14 @@ void lms_Initialize();
 
 REGISTER_MUTATOR(lms, false)
 {
+    MUTATOR_STATIC();
        MUTATOR_ONADD
        {
-               if (time > 1) // game loads at time 1
-                       error("This is a game type and it cannot be added at runtime.");
                lms_Initialize();
 
         GameRules_limit_score(((!autocvar_g_lms_lives_override) ? -1 : autocvar_g_lms_lives_override));
         GameRules_limit_lead(0);
        }
-
-       MUTATOR_ONROLLBACK_OR_REMOVE
-       {
-               // we actually cannot roll back lms_Initialize here
-               // BUT: we don't need to! If this gets called, adding always
-               // succeeds.
-       }
-
-       MUTATOR_ONREMOVE
-       {
-               LOG_INFO("This is a game type and it cannot be removed at runtime.");
-               return -1;
-       }
-
        return 0;
 }
 
index ec71a62d178483d2277228801751f147d721504d..c1b700442fa13912c1e6075fbf48edb2a0be6849 100644 (file)
@@ -7,27 +7,11 @@ void race_Initialize();
 
 REGISTER_MUTATOR(rc, false)
 {
+    MUTATOR_STATIC();
        MUTATOR_ONADD
        {
-               if (time > 1) // game loads at time 1
-                       error("This is a game type and it cannot be added at runtime.");
-
                rc_SetLimits();
                race_Initialize();
        }
-
-       MUTATOR_ONROLLBACK_OR_REMOVE
-       {
-               // we actually cannot roll back race_Initialize here
-               // BUT: we don't need to! If this gets called, adding always
-               // succeeds.
-       }
-
-       MUTATOR_ONREMOVE
-       {
-               LOG_INFO("This is a game type and it cannot be removed at runtime.");
-               return -1;
-       }
-
        return 0;
 }
index bfff9cca1beda3dcf3ec226f0064fea8b239ada9..28331dfefc625f1278d33dad334600a6cf44a8a6 100644 (file)
@@ -9,10 +9,9 @@ void tdm_DelayedInit(entity this);
 
 REGISTER_MUTATOR(tdm, false)
 {
+    MUTATOR_STATIC();
        MUTATOR_ONADD
        {
-               if (time > 1) // game loads at time 1
-                       error("This is a game type and it cannot be added at runtime.");
                InitializeEntity(NULL, tdm_DelayedInit, INITPRIO_GAMETYPE);
 
                GameRules_teams(true);
@@ -20,19 +19,5 @@ REGISTER_MUTATOR(tdm, false)
         GameRules_limit_lead(autocvar_g_tdm_point_leadlimit);
         GameRules_spawning_teams(autocvar_g_tdm_team_spawns);
        }
-
-       MUTATOR_ONROLLBACK_OR_REMOVE
-       {
-               // we actually cannot roll back tdm_Initialize here
-               // BUT: we don't need to! If this gets called, adding always
-               // succeeds.
-       }
-
-       MUTATOR_ONREMOVE
-       {
-               LOG_INFO("This is a game type and it cannot be removed at runtime.");
-               return -1;
-       }
-
        return 0;
 }