+ if (IS_PLAYER(e))
+ {
+ bool rate_wps = false;
+ if((e.flags & FL_INWATER) || (e.flags & FL_PARTIALGROUND))
+ rate_wps = true;
+
+ if(!IS_ONGROUND(e))
+ {
+ traceline(e.origin, e.origin + '0 0 -1500', true, NULL);
+ int t = pointcontents(trace_endpos + '0 0 1');
+ if(t != CONTENT_SOLID )
+ {
+ if(t == CONTENT_WATER || t == CONTENT_SLIME || t == CONTENT_LAVA)
+ rate_wps = true;
+ else if(tracebox_hits_trigger_hurt(e.origin, e.mins, e.maxs, trace_endpos))
+ return;
+ }
+ }
+
+ if(rate_wps)
+ {
+ entity theEnemy = e;
+ entity best_wp = NULL;
+ float best_dist = 10000;
+ IL_EACH(g_waypoints, vdist(it.origin - theEnemy.origin, <, 500)
+ && vdist(it.origin - this.origin, >, 100)
+ && !(it.wpflags & WAYPOINTFLAG_TELEPORT),
+ {
+ float dist = vlen(it.origin - theEnemy.origin);
+ if (dist < best_dist)
+ {
+ best_wp = it;
+ best_dist = dist;
+ }
+ });
+ if (!best_wp)
+ return;
+ e = best_wp;
+ }
+ }
+
+ vector o = (e.absmin + e.absmax) * 0.5;