]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/mutators/mutator/new_toys/new_toys.qc
Fix up more mutator hooks
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / new_toys / new_toys.qc
index 2a0df8c642cce3b1157525e477675a64a833cb2e..236bb136f762c21ff573d940c73928db129d10b9 100644 (file)
@@ -77,16 +77,18 @@ REGISTER_MUTATOR(nt, cvar("g_new_toys") && !cvar("g_instagib") && !cvar("g_overk
                        error("This cannot be added at runtime\n");
 
                // mark the guns as ok to use by e.g. impulse 99
-               for(int i = WEP_FIRST; i <= WEP_LAST; ++i)
-                       if(nt_IsNewToy(i))
-                               Weapons_from(i).spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
+               FOREACH(Weapons, it != WEP_Null, LAMBDA(
+                       if(nt_IsNewToy(it.m_id))
+                               it.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
+               ));
        }
 
        MUTATOR_ONROLLBACK_OR_REMOVE
        {
-               for(int i = WEP_FIRST; i <= WEP_LAST; ++i)
-                       if(nt_IsNewToy(i))
-                               Weapons_from(i).spawnflags |= WEP_FLAG_MUTATORBLOCKED;
+               FOREACH(Weapons, it != WEP_Null, LAMBDA(
+                       if(nt_IsNewToy(it.m_id))
+                               it.spawnflags |= WEP_FLAG_MUTATORBLOCKED;
+               ));
        }
 
        MUTATOR_ONREMOVE
@@ -120,7 +122,6 @@ bool nt_IsNewToy(int w)
                case WEP_MINE_LAYER.m_id:
                case WEP_HLAC.m_id:
                case WEP_RIFLE.m_id:
-               case WEP_SHOCKWAVE.m_id:
                        return true;
                default:
                        return false;
@@ -158,7 +159,7 @@ MUTATOR_HOOKFUNCTION(nt, SetStartItems)
        // apply those bits that are set by start_weapon_defaultmask
        // same for warmup
 
-       float i, j, k, n;
+       float j, n;
 
        WepSet newdefault;
        WepSet warmup_newdefault;
@@ -166,27 +167,22 @@ MUTATOR_HOOKFUNCTION(nt, SetStartItems)
        newdefault = '0 0 0';
        warmup_newdefault = '0 0 0';
 
-       for(i = WEP_FIRST; i <= WEP_LAST; ++i)
-       {
-               entity e = Weapons_from(i);
-               if(!e.weapon)
-                       continue;
+       WepSet seti = '0 0 0';
 
-               n = tokenize_console(nt_GetReplacement(e.netname, autocvar_g_new_toys_autoreplace));
+       FOREACH(Weapons, it != WEP_Null, LAMBDA(
+               seti = it.m_wepset;
+               n = tokenize_console(nt_GetReplacement(it.netname, autocvar_g_new_toys_autoreplace));
 
-               for (j = 0; j < n; ++j)
-                       for (k = WEP_FIRST; k <= WEP_LAST; ++k)
-                       {
-                               Weapon w = Weapons_from(k);
-                               if (w.netname == argv(j))
+               for(j = 0; j < n; ++j)
+                       FOREACH(Weapons, it != WEP_Null, LAMBDA(
+                               if(it.netname == argv(j))
                                {
-                                       WepSet seti = e.m_wepset;
-                                       WepSet setk = w.m_wepset;
-                                       if (start_weapons & seti) newdefault |= setk;
-                                       if (warmup_start_weapons & seti) warmup_newdefault |= setk;
+                                       WepSet setk = it.m_wepset;
+                                       if(start_weapons & seti) newdefault |= setk;
+                                       if(warmup_start_weapons & seti) warmup_newdefault |= setk;
                                }
-                       }
-       }
+                       ));
+       ));
 
        newdefault &= start_weapons_defaultmask;
        start_weapons &= ~start_weapons_defaultmask;
@@ -220,11 +216,13 @@ MUTATOR_HOOKFUNCTION(nt, SetWeaponreplace)
 }
 
 MUTATOR_HOOKFUNCTION(nt, FilterItem)
-{SELFPARAM();
-       if(nt_IsNewToy(self.weapon) && autocvar_g_new_toys_use_pickupsound) {
-               self.item_pickupsound = string_null;
-               self.item_pickupsound_ent = SND_WEAPONPICKUP_NEW_TOYS;
+{
+       entity item = M_ARGV(0, entity);
+
+       if(nt_IsNewToy(item.weapon) && autocvar_g_new_toys_use_pickupsound) {
+               item.item_pickupsound = string_null;
+               item.item_pickupsound_ent = SND_WEAPONPICKUP_NEW_TOYS;
        }
-       return 0;
+       return false;
 }
 #endif