entity navigation_findnearestwaypoint_withdist(entity ent, float walkfromwp, float bestdist)
{
local entity waylist, w, best;
- local float dist;
local vector v, org, pm1, pm2;
pm1 = ent.origin + ent.mins;
pm2 = ent.origin + ent.maxs;
v = w.origin;
if(navigation_waypoint_will_link(v, org, ent, walkfromwp, bestdist))
{
- bestdist = dist;
+ bestdist = vlen(v - org);
best = w;
}
}
return 1;
}
+float botframe_autowaypoints_createwp(vector v, entity p, .entity fld)
+{
+ entity w;
+
+ w = find(world, classname, "waypoint");
+ while (w)
+ {
+ // if a matching spawnfunc_waypoint already exists, don't add a duplicate
+ if (boxesoverlap(v - '32 32 32', v + '32 32 32', w.absmin, w.absmax))
+ return 0;
+ w = find(w, classname, "waypoint");
+ }
+
+ waypoint_schedulerelink(p.fld = waypoint_spawn(v, v, 0));
+ return 1;
+}
+
// return value:
// 1 = WP created
// 0 = no action needed
}
print("spawning a waypoint for connecting to ", etos(wp), "\n");
- waypoint_schedulerelink(p.fld = waypoint_spawn(o, o, 0));
- print("new waypoint is ", etos(p.fld), "\n");
+ botframe_autowaypoints_createwp(o, p, fld);
return 1;
}
print("emergency: got no good nearby WP to build a link from, starting a new chain\n");
if(!botframe_autowaypoints_fixdown(p.origin))
return; // shouldn't happen, caught above
- waypoint_schedulerelink(p.fld = waypoint_spawn(trace_endpos, trace_endpos, 0));
+ botframe_autowaypoints_createwp(trace_endpos, p, fld);
}
void botframe_autowaypoints()
{
{
if(p.deadflag)
continue;
- if(!(p.flags & FL_ONGROUND))
- continue;
botframe_autowaypoints_fix(p, FALSE, botframe_autowaypoints_lastwp0);
botframe_autowaypoints_fix(p, TRUE, botframe_autowaypoints_lastwp1);
}