]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/mutators/mutator_new_toys.qc
Merge remote-tracking branch 'origin/master' into terencehill/hud_code_restructure
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / mutator_new_toys.qc
index bdd214739cc5f493118a5ad001171337d62045c7..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,11 +58,11 @@ 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.
 
 */
 
@@ -79,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)
@@ -167,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)
+                       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)
-               {
-                       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_ONREMOVE
        {
-               error("This cannot be removed at runtime\n");
+               print("This cannot be removed at runtime\n");
+               return -1;
        }
 
        return 0;