// TODO: tracewalk() should take care of this job (better path finding under water)
// if we don't have a goal and we're under water look for a waypoint near the "shore" and push it
if(IS_DEAD(this))
- if(this.goalcurrent==NULL)
- if(this.waterlevel==WATERLEVEL_SWIMMING || (this.aistatus & AI_STATUS_OUT_WATER))
+ if(!this.goalcurrent)
+ if(this.waterlevel == WATERLEVEL_SWIMMING || (this.aistatus & AI_STATUS_OUT_WATER))
{
// Look for the closest waypoint out of water
- entity newgoal, head;
- float bestdistance, distance;
-
- newgoal = NULL;
- bestdistance = 10000;
- for (head = findchain(classname, "waypoint"); head; head = head.chain)
+ entity newgoal = NULL;
+ FOREACH_ENTITY_CLASS("waypoint", vdist(it.origin - this.origin, <=, 10000),
{
- distance = vlen(head.origin - this.origin);
- if(distance>10000)
- continue;
-
- if(head.origin.z < this.origin.z)
+ if(it.origin.z < this.origin.z)
continue;
- if(head.origin.z - this.origin.z - this.view_ofs.z > 100)
+ if(it.origin.z - this.origin.z - this.view_ofs.z > 100)
continue;
- if (pointcontents(head.origin + head.maxs + '0 0 1') != CONTENT_EMPTY)
+ if (pointcontents(it.origin + it.maxs + '0 0 1') != CONTENT_EMPTY)
continue;
- traceline(this.origin + this.view_ofs , head.origin, true, head);
+ traceline(this.origin + this.view_ofs, ((it.absmin + it.absmax) * 0.5), true, this);
- if(trace_fraction<1)
+ if(trace_fraction < 1)
continue;
- if(distance<bestdistance)
- {
- newgoal = head;
- bestdistance = distance;
- }
- }
+ if(!newgoal || vlen2(it.origin - this.origin) < vlen2(newgoal.origin - this.origin))
+ newgoal = it;
+ });
if(newgoal)
{
{
if(fabs(this.velocity.z)<50)
{
- entity head, newgoal = NULL;
- float distance, bestdistance = 0;
-
- for (head = findchain(classname, "waypoint"); head; head = head.chain)
+ entity newgoal = NULL;
+ FOREACH_ENTITY_CLASS("waypoint", vdist(it.origin - this.origin, <, 1000),
{
+ traceline(this.origin + this.view_ofs, ((it.absmin + it.absmax) * 0.5), true, this);
- distance = vlen(head.origin - this.origin);
- if(distance>1000)
+ if(trace_fraction < 1)
continue;
- traceline(this.origin + this.view_ofs , ( ( head.absmin + head.absmax ) * 0.5 ), true, NULL);
-
- if(trace_fraction<1)
- continue;
-
- if(distance>bestdistance)
- {
- newgoal = head;
- bestdistance = distance;
- }
- }
+ if(!newgoal || vlen2(it.origin - this.origin) > vlen2(newgoal.origin - this.origin))
+ newgoal = it;
+ });
if(newgoal)
{
this.aistatus |= AI_STATUS_WAYPOINT_PERSONAL_LINKING;
// if pos is inside a teleport, then let's mark it as teleport waypoint
- entity head;
- for(head = NULL; (head = find(head, classname, "trigger_teleport")); )
+ FOREACH_ENTITY_CLASS("trigger_teleport", WarpZoneLib_BoxTouchesBrush(pos, pos, it, NULL),
{
- if(WarpZoneLib_BoxTouchesBrush(pos, pos, head, NULL))
- {
- wp.wpflags |= WAYPOINTFLAG_TELEPORT;
- this.lastteleporttime = 0;
- }
- }
+ wp.wpflags |= WAYPOINTFLAG_TELEPORT;
+ this.lastteleporttime = 0;
+ });
/*
if(wp.wpflags & WAYPOINTFLAG_TELEPORT)