]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/mutators/mutator_new_toys.qc
Move footsteps to the mutator system
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / mutator_new_toys.qc
index 461272e7e9f63b976b5e7b6cde3694ee71db9096..89ad13c5380775439b1a186e05ff93c81dba8141 100644 (file)
@@ -43,8 +43,8 @@ In "replace random" mode, Nex will have the default replacement "nex rifle".
 
 This mutator's replacements run BEFORE regular weaponreplace!
 
-       The New Toys guns do NOT get a spawn function, so they can only ever be spawned
-       when this mutator is active.
+The New Toys guns do NOT get a spawn function, so they can only ever be spawned
+when this mutator is active.
 
 Likewise, warmup, give all, give ALL and impulse 99 will not give them unless
 this mutator is active.
@@ -58,15 +58,20 @@ Outside this mutator, they still can be spawned by:
 This mutator performs the default replacements on the DEFAULTS of the
 start weapon selection.
 
-       These weapons appear in the menu's priority list, BUT get a suffix
-       "(Mutator weapon)".
+These weapons appear in the menu's priority list, BUT get a suffix
+"(Mutator weapon)".
 
-       Picking up a "new toys" weapon will not play standard weapon pickup sound, but
-       roflsound "New toys, new toys!" sound.
+Picking up a "new toys" weapon will not play standard weapon pickup sound, but
+roflsound "New toys, new toys!" sound.
 
 */
 
-float autocvar_g_new_toys_autoreplace = 2; // 0 = never, 1 = always, 2 = random
+.string new_toys;
+
+float autocvar_g_new_toys_autoreplace;
+#define NT_AUTOREPLACE_NEVER 0
+#define NT_AUTOREPLACE_ALWAYS 1
+#define NT_AUTOREPLACE_RANDOM 2
 
 MUTATOR_HOOKFUNCTION(nt_SetModname)
 {
@@ -74,6 +79,20 @@ MUTATOR_HOOKFUNCTION(nt_SetModname)
        return 0;
 }
 
+float nt_IsNewToy(float w)
+{
+       switch(w)
+       {
+               case WEP_SEEKER:
+               case WEP_MINE_LAYER:
+               case WEP_HLAC:
+               case WEP_RIFLE:
+                       return TRUE;
+               default:
+                       return FALSE;
+       }
+}
+
 string nt_GetFullReplacement(string w)
 {
        switch(w)
@@ -88,12 +107,12 @@ string nt_GetFullReplacement(string w)
 
 string nt_GetReplacement(string w, float m)
 {
-       if(m == 0)
+       if(m == NT_AUTOREPLACE_NEVER)
                return w;
        string s = nt_GetFullReplacement(w);
        if not(s)
                return w;
-       if(m == 2)
+       if(m == NT_AUTOREPLACE_RANDOM)
                s = strcat(w, " ", s);
        return s;
 }
@@ -150,15 +169,11 @@ MUTATOR_HOOKFUNCTION(nt_SetWeaponreplace)
                // map defined replacement:
                ret_string = self.new_toys;
        }
-       else if(autocvar_g_new_toys_autoreplace)
+       else
        {
                // auto replacement:
                ret_string = nt_GetReplacement(other.netname, autocvar_g_new_toys_autoreplace);
        }
-       else
-       {
-               ret_string = other.netname;
-       }
 
        // apply regular weaponreplace
        ret_string = W_Apply_Weaponreplace(ret_string);
@@ -166,29 +181,46 @@ MUTATOR_HOOKFUNCTION(nt_SetWeaponreplace)
        return 0;
 }
 
+MUTATOR_HOOKFUNCTION(nt_FilterItem)
+{
+       if(nt_IsNewToy(self.weapon))
+               self.item_pickupsound = "weapons/weaponpickup_new_toys.wav";
+       return 0;
+}
+
 MUTATOR_DEFINITION(mutator_new_toys)
 {
        MUTATOR_HOOK(SetModname, nt_SetModname, CBC_ORDER_ANY);
        MUTATOR_HOOK(SetStartItems, nt_SetStartItems, CBC_ORDER_ANY);
        MUTATOR_HOOK(SetWeaponreplace, nt_SetWeaponreplace, CBC_ORDER_LAST);
+       MUTATOR_HOOK(FilterItem, nt_FilterItem, CBC_ORDER_ANY);
 
        MUTATOR_ONADD
        {
                if(time > 1) // game loads at time 1
                        error("This cannot be added at runtime\n");
 
-               // mark all guns as ok to use by e.g. impulse 99
+               precache_sound("weapons/weaponpickup_new_toys.wav");
+
+               // mark the guns as ok to use by e.g. impulse 99
                float i;
                for(i = WEP_FIRST; i <= WEP_LAST; ++i)
-               {
-                       entity e = get_weaponinfo(i);
-                       if(e.weapon)
-                               e.spawnflags &~= WEP_FLAG_MUTATORBLOCKED;
-               }
+                       if(nt_IsNewToy(i))
+                               get_weaponinfo(i).spawnflags &~= WEP_FLAG_MUTATORBLOCKED;
        }
+
+       MUTATOR_ONROLLBACK_OR_REMOVE
+       {
+               float i;
+               for(i = WEP_FIRST; i <= WEP_LAST; ++i)
+                       if(nt_IsNewToy(i))
+                               get_weaponinfo(i).spawnflags |= WEP_FLAG_MUTATORBLOCKED;
+       }
+
        MUTATOR_ONREMOVE
        {
-               error("This cannot be removed at runtime\n");
+               print("This cannot be removed at runtime\n");
+               return -1;
        }
 
        return 0;