]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Update iterators
authorTimePath <andrew.hardaker1995@gmail.com>
Fri, 14 Aug 2015 04:40:42 +0000 (14:40 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Fri, 14 Aug 2015 04:40:42 +0000 (14:40 +1000)
qcsrc/client/hud.qc
qcsrc/client/waypointsprites.qc
qcsrc/common/items/all.qc
qcsrc/common/items/inventory.qh
qcsrc/common/mapinfo.qc
qcsrc/common/nades.qh
qcsrc/common/util-pre.qh
qcsrc/server/mutators/mutator_buffs.qc

index bd687c538f6763e8f79d3fdefba874c6f729bb3c..8ea4155ae939242d66e672238c16905ba1272439 100644 (file)
@@ -1403,12 +1403,9 @@ void HUD_Powerups(void)
        if(superTime)
                addPowerupItem("Superweapons", "superweapons", autocvar_hud_progressbar_superweapons_color, superTime, 30);
 
-       FOREACH(BUFFS, 0, BUFFS_COUNT,
-               it.m_itemid & allBuffs,
-               LAMBDA(
-                       addPowerupItem(it.m_prettyName, strcat("buff_", it.m_name), it.m_color, bound(0, getstatf(STAT_BUFF_TIME) - time, 99), 60);
-               )
-       );
+       FOREACH(BUFFS, it.m_itemid & allBuffs, LAMBDA(
+               addPowerupItem(it.m_prettyName, strcat("buff_", it.m_name), it.m_color, bound(0, getstatf(STAT_BUFF_TIME) - time, 99), 60);
+       ));
 
        if(!powerupItemsCount)
                return;
index de4e84d9e3c46a2bf1f04d0c04c0fd04a5df99f2..4a1ba2a1fae972e3306892711066b42de67365e4 100644 (file)
@@ -207,13 +207,10 @@ string spritelookuptext(string s)
        if (substring(s, 0, 5) == "buff-")
        {
                entity buff = BUFF_NULL;
-               FOREACH(BUFFS, 0, BUFFS_COUNT,
-                       it.m_sprite == s,
-                       LAMBDA({
-                               buff = it;
-                               break;
-                       })
-               );
+               FOREACH(BUFFS, it.m_sprite == s, LAMBDA(
+                       buff = it;
+                       break;
+               ));
                return buff.m_prettyName;
        }
 
index f221ab2d3f6a6bf1cb367540422bc35c2b43c9a1..fc225cdb7d40ecf648da2b802ecd504fba8631cc 100644 (file)
@@ -6,9 +6,9 @@
 
 void Dump_Items()
 {
-    FOREACH(ITEMS, 0, ITEM_COUNT, true, LAMBDA({
+    FOREACH(ITEMS, true, LAMBDA(
         ITEM_HANDLE(Show, it);
-    }));
+    ));
 }
 
 #endif
index 25590ea43cd45713a44bd1e6095e716bb22575b5..8b0d43305d9b243eb8eec33028079ebc4b125745 100644 (file)
@@ -15,12 +15,12 @@ class(Inventory) .int inv_items[MAX_ITEMS];
 void Inventory_Read(Inventory data)
 {
     const int bits = ReadInt24_t();
-    FOREACH(ITEMS, 0, ITEM_COUNT, bits & BIT(i), LAMBDA({
+    FOREACH(ITEMS, bits & BIT(i), LAMBDA(
         .int fld = inv_items[i];
         int prev = data.(fld);
         int next = data.(fld) = ReadByte();
         dprintf("%s: %.0f -> %.0f\n", ITEMS[i].m_name, prev, next);
-    }));
+    ));
 }
 #endif
 
@@ -28,14 +28,14 @@ void Inventory_Read(Inventory data)
 void Inventory_Write(Inventory data)
 {
     int bits = 0;
-    FOREACH(ITEMS, 0, ITEM_COUNT, true, LAMBDA({
+    FOREACH(ITEMS, true, LAMBDA(
         .int fld = inv_items[i];
         bits = BITSET(bits, BIT(i), data.inventory.(fld) != (data.inventory.(fld) = data.(fld)));
-    }));
+    ));
     WriteInt24_t(MSG_ENTITY, bits);
-    FOREACH(ITEMS, 0, ITEM_COUNT, bits & BIT(i), LAMBDA({
+    FOREACH(ITEMS, bits & BIT(i), LAMBDA(
         WriteByte(MSG_ENTITY, data.inv_items[i]);
-    }));
+    ));
 }
 #endif
 
index 33af1b3900ddf163bc14dd0844e6f03bcb9aec4b..0b851d53b0c5299c7625055d6f470f7925b90564 100644 (file)
@@ -602,19 +602,13 @@ void _MapInfo_Map_ApplyGametype(string s, int pWantedType, int pThisType, int lo
 
 string _MapInfo_GetDefaultEx(float t)
 {
-       entity e;
-       for(e = MAPINFO_TYPES_first; e; e = e.enemy)
-               if(t == e.items)
-                       return e.model2;
+       FOREACH(MAPINFO_TYPES, it.items == t, LAMBDA(return it.model2));
        return "";
 }
 
 float _MapInfo_GetTeamPlayBool(float t)
 {
-       entity e;
-       for(e = MAPINFO_TYPES_first; e; e = e.enemy)
-               if(t == e.items)
-                       return e.team;
+       FOREACH(MAPINFO_TYPES, it.items == t, LAMBDA(return it.team));
        return false;
 }
 
@@ -715,7 +709,6 @@ void _MapInfo_Map_ApplyGametypeEx(string s, int pWantedType, int pThisType)
 
 float MapInfo_Type_FromString(string t)
 {
-       entity e;
        if(t == "nexball")
        {
                print("MapInfo_Type_FromString (probably ", MapInfo_Map_bspname, "): using deprecated name '", t);
@@ -754,38 +747,27 @@ float MapInfo_Type_FromString(string t)
        }
        if(t == "all")
                return MAPINFO_TYPE_ALL;
-       for(e = MAPINFO_TYPES_first; e; e = e.enemy)
-               if(t == e.mdl)
-                       return e.items;
+       FOREACH(MAPINFO_TYPES, it.mdl == t, LAMBDA(return it.items));
        return 0;
 }
 
 string MapInfo_Type_Description(float t)
 {
-       entity e;
-       for(e = MAPINFO_TYPES_first; e; e = e.enemy)
-               if(t == e.items)
-                       return e.gametype_description;
+       FOREACH(MAPINFO_TYPES, it.items == t, LAMBDA(return it.gametype_description));
        return "";
 }
 
 string MapInfo_Type_ToString(float t)
 {
-       entity e;
        if(t == MAPINFO_TYPE_ALL)
                return "all";
-       for(e = MAPINFO_TYPES_first; e; e = e.enemy)
-               if(t == e.items)
-                       return e.mdl;
+       FOREACH(MAPINFO_TYPES, it.items == t, LAMBDA(return it.mdl));
        return "";
 }
 
 string MapInfo_Type_ToText(float t)
 {
-       entity e;
-       for(e = MAPINFO_TYPES_first; e; e = e.enemy)
-               if(t == e.items)
-                       return e.message;
+       FOREACH(MAPINFO_TYPES, it.items == t, LAMBDA(return it.message));
        /* xgettext:no-c-format */
        return _("@!#%'n Tuba Throwing");
 }
@@ -1289,14 +1271,9 @@ int MapInfo_CurrentFeatures()
 
 int MapInfo_CurrentGametype()
 {
-       entity e;
        int prev = cvar("gamecfg");
-       for(e = MAPINFO_TYPES_first; e; e = e.enemy)
-               if(cvar(e.netname))
-                       if(prev != e.items)
-                               return e.items;
-       if(prev)
-               return prev;
+       FOREACH(MAPINFO_TYPES, cvar(it.netname) && it.items != prev, LAMBDA(return it.items));
+       if (prev) return prev;
        return MAPINFO_TYPE_DEATHMATCH;
 }
 
@@ -1321,9 +1298,9 @@ float MapInfo_CheckMap(string s) // returns 0 if the map can't be played with th
 
 void MapInfo_SwitchGameType(int t)
 {
-       for (entity e = MAPINFO_TYPES_first; e; e = e.enemy) {
-               cvar_set(e.netname, (t == e.items) ? "1" : "0");
-       }
+       FOREACH(MAPINFO_TYPES, true, LAMBDA(
+               cvar_set(it.netname, (it.items == t) ? "1" : "0")
+       ));
 }
 
 void MapInfo_LoadMap(string s, float reinit)
index d029da43ecc34add6f6ac64a5477c3fd1392d91e..01eb7fff2c8e2730fa1a8eca1062571c4467c977 100644 (file)
@@ -95,32 +95,28 @@ REGISTER_NADE(MONSTER) {
 
 entity Nade_FromProjectile(float proj)
 {
-    for (int i = 0; i < NADES_COUNT; i++)
-    {
-        entity nade = NADES[i];
+    FOREACH(NADES, true, LAMBDA(
         for (int j = 0; j < 2; j++)
         {
-            if (nade.m_projectile[j] == proj) return nade;
+            if (it.m_projectile[j] == proj) return it;
         }
-    }
+    ));
     return NADE_TYPE_NULL;
 }
 
 string Nade_TrailEffect(float proj, float nade_team)
 {
-    for (int i = 0; i < NADES_COUNT; i++)
-    {
-        entity nade = NADES[i];
+    FOREACH(NADES, true, LAMBDA(
         for (int j = 0; j < 2; j++)
         {
-            if (nade.m_projectile[j] == proj)
+            if (it.m_projectile[j] == proj)
             {
-                string trail = nade.m_trail[j];
+                string trail = it.m_trail[j];
                 if (trail) return trail;
                 break;
             }
         }
-    }
+    ));
     switch (proj)
     {
         case PROJECTILE_NADE: return strcat("nade_", Static_Team_ColorName_Lower(nade_team));
index 18b46c8d321667e76d3a78896e4c9b23c3fc3c16..b96e78d514f6832d6c39cfae274e678b641761e9 100644 (file)
 [[deprecated("use true")]] [[alias("true")]] const bool TRUE;
 [[deprecated("use false")]] [[alias("false")]] const bool FALSE;
 
-#define FOREACH(arr, start, end, cond, body) do { \
-    for (int i = start; i < end; ++i) {     \
-        const noref entity it = arr[i];     \
-        if (cond) { body }                  \
-    }                                       \
+#define FOREACH_ARRAY(arr, start, end, cond, body) do { \
+    for (int i = start; i < end; ++i) {                 \
+        const noref entity it = arr[i];                 \
+        if (cond) { body }                              \
+    }                                                   \
 } while(0)
 
+#define FOREACH_LIST(list, next, cond, body) do {               \
+    noref int i = 0;                                            \
+    for (entity it = list##_first; it; (it = it.next, ++i)) {   \
+        if (cond) { body }                                      \
+    }                                                           \
+} while(0)
+
+#define FOREACH(list, cond, body) FOREACH_LIST(list, enemy, cond, body)
+
 #ifdef GMQCC
     #define OVERLOAD(F, ...) F##_##__VA_COUNT__(__VA_ARGS__)
 #else
index 877bca9f6bfa85aa0ad0dd22e851e1f149a859a9..170f59874fbb45803574bd10bd35d9993542946d 100644 (file)
@@ -10,12 +10,7 @@ entity buff_FirstFromFlags(int _buffs)
 {
        if (flags)
        {
-               FOREACH(BUFFS, 0, BUFFS_COUNT,
-                       it.m_itemid & _buffs,
-                       LAMBDA({
-                               return it;
-                       })
-               );
+               FOREACH(BUFFS, it.m_itemid & _buffs, LAMBDA(return it));
        }
        return BUFF_NULL;
 }
@@ -207,14 +202,11 @@ float buff_Available(entity buff)
 void buff_NewType(entity ent, float cb)
 {
        RandomSelection_Init();
-       FOREACH(BUFFS, 0, BUFFS_COUNT,
-               buff_Available(it),
-               LAMBDA({
-                       it.buff_seencount += 1;
-                       // if it's already been chosen, give it a lower priority
-                       RandomSelection_Add(world, it.m_itemid, string_null, 1, max(0.2, 1 / it.buff_seencount));
-               })
-       );
+       FOREACH(BUFFS, buff_Available(it), LAMBDA(
+               it.buff_seencount += 1;
+               // if it's already been chosen, give it a lower priority
+               RandomSelection_Add(world, it.m_itemid, string_null, 1, max(0.2, 1 / it.buff_seencount));
+       ));
        ent.buffs = RandomSelection_chosen_float;
 }