]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Loopify loops
authorMario <mario@smbclan.net>
Thu, 24 Dec 2015 00:37:42 +0000 (10:37 +1000)
committerMario <mario@smbclan.net>
Thu, 24 Dec 2015 00:37:42 +0000 (10:37 +1000)
qcsrc/common/gamemodes/gamemode/onslaught/onslaught.qc
qcsrc/common/mutators/mutator/new_toys/new_toys.qc

index 9cafd1a23a60c070906bac2c4fc0de68684264ed..485fc1b7cef1845d5c804b5caca93f225938f778 100644 (file)
@@ -1330,7 +1330,6 @@ void havocbot_goalrating_ons_offenseitems(float ratingscale, vector org, float s
 {SELFPARAM();
        entity head;
        float t, c;
-       int i;
        bool needarmor = false, needweapons = false;
 
        // Needs armor/health?
@@ -1339,13 +1338,11 @@ void havocbot_goalrating_ons_offenseitems(float ratingscale, vector org, float s
 
        // Needs weapons?
        c = 0;
-       for(i = WEP_FIRST; i <= WEP_LAST ; ++i)
-       {
-               // Find weapon
-               if(self.weapons & WepSet_FromWeapon(Weapons_from(i)))
-               if(++c>=4)
+       FOREACH(Weapons, it != WEP_Null, LAMBDA(
+               if(self.weapons & (it.m_wepset))
+               if(++c >= 4)
                        break;
-       }
+       ));
 
        if(c<4)
                needweapons = true;
index 2f4510a3fd971badc9e6a3edd38864c416cf58c4..ab0567d3a3fb54d8d3ff7f9314135a43aaeae6c0 100644 (file)
@@ -160,7 +160,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;
@@ -168,26 +168,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 == WEP_Null) 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;