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;
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;
}
void Dump_Items()
{
- FOREACH(ITEMS, 0, ITEM_COUNT, true, LAMBDA({
+ FOREACH(ITEMS, true, LAMBDA(
ITEM_HANDLE(Show, it);
- }));
+ ));
}
#endif
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
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
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;
}
float MapInfo_Type_FromString(string t)
{
- entity e;
if(t == "nexball")
{
print("MapInfo_Type_FromString (probably ", MapInfo_Map_bspname, "): using deprecated name '", 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");
}
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;
}
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)
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));
[[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
{
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;
}
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;
}