mousepos = mousepos*0.5 + getmousepos();
*/
- for(entity e = NULL; (e = nextent(e)); ) if (e.draw) {
- WITH(entity, self, e, e.draw(e));
- }
+ FOREACH_ENTITY(it.draw, LAMBDA(WITH(entity, self, it, it.draw(it))));
addentities(MASK_NORMAL | MASK_ENGINE | MASK_ENGINEVIEWMODELS);
renderscene();
} else */
// draw 2D entities
- for (entity e = NULL; (e = nextent(e)); ) if (e.draw2d) {
- WITH(entity, self, e, e.draw2d(e));
- }
+ FOREACH_ENTITY(it.draw2d, LAMBDA(WITH(entity, self, it, it.draw2d(it))));
Draw_ShowNames_All();
Debug_Draw();
static int debugdraw_frame;
++debugdraw_frame;
const int size = 8;
- for (entity e1 = NULL; (e1 = nextent(e1)); )
- {
- if (e1.debugdraw_last == debugdraw_frame) continue;
+ FOREACH_ENTITY(true, LAMBDA(
+ if (it.debugdraw_last == debugdraw_frame) continue;
int ofs = 0;
- for (entity e = findradius(e1.origin, 100); e; e = e.chain)
+ for (entity e = findradius(it.origin, 100); e; e = e.chain)
{
if (e.debugdraw_last == debugdraw_frame) continue;
e.debugdraw_last = debugdraw_frame;
size * '1 1 0', rgb, 0.5, DRAWFLAG_NORMAL);
++ofs;
}
- }
+ ));
}
#endif
float Item_ItemsTime_UpdateTime(entity e, float t)
{
bool isavailable = (t == 0);
- if (e.weapons & WEPSET_SUPERWEAPONS)
- {
- for (entity head = world; (head = nextent(head)); )
- {
- if (clienttype(head) != CLIENTTYPE_NOTACLIENT || !(head.weapons & WEPSET_SUPERWEAPONS) || head.instanceOfWeapon)
- continue;
- if (e == head)
- continue;
-
- if (head.scheduledrespawntime <= time)
- isavailable = true;
- else if (t == 0 || head.scheduledrespawntime < t)
- t = head.scheduledrespawntime;
- }
- }
- else
- {
- for (entity head = world; (head = nextent(head)); )
- {
- if (head.itemdef != e.itemdef)
- continue;
- if (e == head)
- continue;
-
- if (head.scheduledrespawntime <= time)
- isavailable = true;
- else if (t == 0 || head.scheduledrespawntime < t)
- t = head.scheduledrespawntime;
- }
- }
+ FOREACH_ENTITY(it.itemdef == e.itemdef || ((it.weapons & WEPSET_SUPERWEAPONS) && clienttype(it) == CLIENTTYPE_NOTACLIENT), LAMBDA(
+ if (e == it) continue;
+ if (it.scheduledrespawntime <= time)
+ isavailable = true;
+ else if (t == 0 || it.scheduledrespawntime < t)
+ t = it.scheduledrespawntime;
+ ));
if (isavailable)
t = -t; // let know the client there's another available item
return t;
Item_ItemsTime_ResetTimes();
// ALL the times need to be reset before .reset()ing each item
// since Item_Reset schedules respawn of superweapons and powerups
- for (entity e = NULL; (e = nextent(e)); )
- if (IS_NOT_A_CLIENT(e))
- {
- setself(e);
- if (self.reset)
- Item_ItemsTime_SetTime(self, 0);
- }
+ FOREACH_ENTITY(IS_NOT_A_CLIENT(it), LAMBDA(
+ if (it.reset) Item_ItemsTime_SetTime(it, 0);
+ ));
Item_ItemsTime_SetTimesForAllPlayers();
}
return true;
}
-void load_unit_settings(entity ent, float is_reload)
+void load_unit_settings(entity ent, bool is_reload)
{SELFPARAM();
string unitname = ent.netname;
string sbase;
}
void turrets_manager_think()
-{SELFPARAM();
- self.nextthink = time + 1;
+{
+ SELFPARAM();
+ this.nextthink = time + 1;
- entity e;
if (autocvar_g_turrets_reloadcvars == 1)
{
- e = nextent(world);
- while (e)
- {
- if (IS_TURRET(e))
- {
- load_unit_settings(e,1);
- Turret tur = get_turretinfo(self.m_id);
- tur.tr_think(tur);
- }
-
- e = nextent(e);
- }
- cvar_set("g_turrets_reloadcvars","0");
+ FOREACH_ENTITY(IS_TURRET(it), LAMBDA(
+ load_unit_settings(it, true);
+ Turret tur = get_turretinfo(it.m_id);
+ tur.tr_think(tur);
+ ));
+ cvar_set("g_turrets_reloadcvars", "0");
}
}
} \
while (0)
+#if defined(CSQC)
+ entity(.entity fld, entity match, .entity tofield) findchainentity_tofield = #403;
+#elif defined(SVQC)
+ entity(.entity fld, entity match, .entity tofield) findchainentity_tofield = #403;
+#elif defined(MENUQC)
+ entity(.entity fld, entity match, .entity tofield) findchainentity_tofield = #27;
+#endif
+
+.entity _FOREACH_ENTITY_fld;
+.entity _FOREACH_ENTITY_next;
+
+#define FOREACH_ENTITY_UNORDERED(cond, body) \
+ do { \
+ int i = 0; \
+ for (entity it = findchainentity_tofield(_FOREACH_ENTITY_fld, NULL, _FOREACH_ENTITY_next); it; (it = it._FOREACH_ENTITY_next, ++i)) \
+ { \
+ if (cond) { body } \
+ } \
+ } \
+ while (0)
+
+#define FOREACH_ENTITY_ORDERED(cond, body) \
+ do { \
+ int i = 0; \
+ for (entity it = NULL; (it = nextent(it)); ++i) \
+ { \
+ if (cond) { body } \
+ } \
+ } \
+ while (0)
+
+#define FOREACH_ENTITY(cond, body) FOREACH_ENTITY_UNORDERED(cond, body)
+
#define FOREACH(list, cond, body) FOREACH_LIST(list, enemy, cond, body)
#endif
}
void WarpZone_StartFrame()
-{SELFPARAM();
- entity e;
- if(warpzone_initialized == 0)
+{
+ SELFPARAM();
+ if (!warpzone_initialized)
{
- warpzone_initialized = 1;
- for(setself(warpzone_first); self; setself(self.warpzone_next))
+ warpzone_initialized = true;
+ for (setself(warpzone_first); self; setself(self.warpzone_next))
WarpZone_InitStep_FindOriginTarget();
- for(setself(warpzone_position_first); self; setself(self.warpzone_next))
+ for (setself(warpzone_position_first); self; setself(self.warpzone_next))
WarpZonePosition_InitStep_FindTarget();
- for(setself(warpzone_first); self; setself(self.warpzone_next))
+ for (setself(warpzone_first); self; setself(self.warpzone_next))
WarpZone_InitStep_UpdateTransform();
setself(this);
WarpZones_Reconnect();
WarpZone_PostInitialize_Callback();
}
- entity oldother;
- oldother = other;
- for(e = world; (e = nextent(e)); )
+ entity oldother = other;
+ for (entity e = world; (e = nextent(e)); )
{
- if(warpzone_warpzones_exist) { WarpZone_StoreProjectileData(e); }
-
- if(IS_REAL_CLIENT(e))
+ if (warpzone_warpzones_exist) WarpZone_StoreProjectileData(e);
+ if (IS_REAL_CLIENT(e))
{
- if(e.solid == SOLID_NOT) // not spectating?
- if(e.movetype == MOVETYPE_NOCLIP || e.movetype == MOVETYPE_FLY || e.movetype == MOVETYPE_FLY_WORLDONLY) // not spectating? (this is to catch observers)
+ if (e.solid == SOLID_NOT) // not spectating?
+ if (e.movetype == MOVETYPE_NOCLIP || e.movetype == MOVETYPE_FLY || e.movetype == MOVETYPE_FLY_WORLDONLY) // not spectating? (this is to catch observers)
{
other = e; // player
// warpzones
- if(warpzone_warpzones_exist) {
- setself(WarpZone_Find(e.origin + e.mins, e.origin + e.maxs));
- if(self)
- if(!WarpZoneLib_ExactTrigger_Touch())
- if(WarpZone_PlaneDist(self, e.origin + e.view_ofs) <= 0)
- WarpZone_Teleport(self, e, -1, 0); } // NOT triggering targets by this!
+ if (warpzone_warpzones_exist) {
+ setself(WarpZone_Find(e.origin + e.mins, e.origin + e.maxs));
+ if (self)
+ if (!WarpZoneLib_ExactTrigger_Touch())
+ if (WarpZone_PlaneDist(self, e.origin + e.view_ofs) <= 0)
+ WarpZone_Teleport(self, e, -1, 0); // NOT triggering targets by this!
+ }
// teleporters
setself(Teleport_Find(e.origin + e.mins, e.origin + e.maxs));
- if(self)
- if(!WarpZoneLib_ExactTrigger_Touch())
+ if (self)
+ if (!WarpZoneLib_ExactTrigger_Touch())
Simple_TeleportPlayer(self, other); // NOT triggering targets by this!
}
}
-
- if(IS_NOT_A_CLIENT(e))
+ else if (IS_NOT_A_CLIENT(e))
{
- if(warpzone_warpzones_exist)
- for (; (e = nextent(e)); )
+ if (warpzone_warpzones_exist)
+ while ((e = nextent(e)))
WarpZone_StoreProjectileData(e);
break;
}
}
.float warpzone_reconnecting;
-float visible_to_some_client(entity ent)
+bool visible_to_some_client(entity ent)
{
- entity e;
- for(e = nextent(world); !IS_NOT_A_CLIENT(e); e = nextent(e))
- if(IS_PLAYER(e) && IS_REAL_CLIENT(e))
- if(checkpvs(e.origin + e.view_ofs, ent))
- return 1;
- return 0;
+ FOREACH_ENTITY(!IS_NOT_A_CLIENT(it), LAMBDA(
+ if (IS_PLAYER(it) && IS_REAL_CLIENT(it) && checkpvs(it.origin + it.view_ofs, ent)) return true;
+ ));
+ return false;
}
void trigger_warpzone_reconnect_use()
{SELFPARAM();
if (argc == 1)
{
LOG_INFO(_("Available options:\n"));
- float i;
- entity e;
- string s;
- for (i = 0, e = NULL; (e = nextent(e)); )
- if (e.classname != "vtbl" && e.name != "")
+ FOREACH_ENTITY_ORDERED(it.name != "", LAMBDA(
+ if (it.classname == "vtbl") continue;
+ string s = it.name;
+ if (filter)
{
- s = e.name;
- if (filter)
- {
- if (substring(s, 0, strlen(filter)) != filter) continue;
- s = substring(s, strlen(filter), strlen(s) - strlen(filter));
- }
- LOG_INFO(strcat(" ", s, "\n"));
- ++i;
+ if (!startsWith(s, filter)) continue;
+ s = substring(s, strlen(filter), strlen(s) - strlen(filter));
}
+ LOG_INFOF(" %s\n", s);
+ ));
}
else if (argc == 2 && !isdemo()) // don't allow this command in demos
{
void Shutdown()
{
m_hide();
- for (entity e = NULL; (e = nextent(e)); )
- {
- if (e.classname == "vtbl") continue;
- if (e.destroy) e.destroy(e);
- }
+ FOREACH_ENTITY_ORDERED(it.destroy, LAMBDA(
+ if (it.classname == "vtbl") continue;
+ it.destroy(it);
+ ));
}
void m_focus_item_chain(entity outermost, entity innermost)
MUTATOR_CALLHOOK(reset_map_global);
- for (entity e = world; (e = nextent(e)); )
- {
- if (IS_NOT_A_CLIENT(e))
+ FOREACH_ENTITY_ORDERED(IS_NOT_A_CLIENT(it), LAMBDA(
+ if (it.reset)
{
- if (e.reset)
- {
- WITH(entity, self, e, e.reset(e));
- continue;
- }
- if (e.team_saved) e.team = e.team_saved;
- if (e.flags & FL_PROJECTILE) remove(e); // remove any projectiles left
+ WITH(entity, self, it, it.reset(it));
+ continue;
}
- }
+ if (it.team_saved) it.team = it.team_saved;
+ if (it.flags & FL_PROJECTILE) remove(it); // remove any projectiles left
+ ));
// Waypoints and assault start come LAST
- for (entity e = world; (e = nextent(e)); )
- {
- setself(e);
- if (IS_NOT_A_CLIENT(self))
- {
- if (self.reset2)
- {
- self.reset2();
- continue;
- }
- }
- }
+ FOREACH_ENTITY_ORDERED(IS_NOT_A_CLIENT(it), LAMBDA(
+ if (it.reset2) WITH(entity, self, it, it.reset2());
+ ));
entity e;
FOR_EACH_PLAYER(e)
compressShortVector_init();
- entity head;
- head = nextent(world);
maxclients = 0;
- while(head)
+ for (entity head = nextent(world); head; head = nextent(head))
{
++maxclients;
- head = nextent(head);
}
server_is_dedicated = (stof(cvar_defstring("is_dedicated")) ? true : false);
else
assault_attacker_team = NUM_TEAM_1;
- entity ent;
- for(ent = world; (ent = nextent(ent)); )
- {
- if(clienttype(ent) == CLIENTTYPE_NOTACLIENT)
- {
- if(ent.team_saved == NUM_TEAM_1)
- ent.team_saved = NUM_TEAM_2;
- else if(ent.team_saved == NUM_TEAM_2)
- ent.team_saved = NUM_TEAM_1;
- }
- }
+ FOREACH_ENTITY(clienttype(it) == CLIENTTYPE_NOTACLIENT, LAMBDA(
+ if (it.team_saved == NUM_TEAM_1) it.team_saved = NUM_TEAM_2;
+ else if (it.team_saved == NUM_TEAM_2) it.team_saved = NUM_TEAM_1;
+ ));
// reset the level with a countdown
cvar_set("timelimit", ftos(ceil(time - game_starttime) / 60));