if(!found)
{
- // can't find that waypoint
- fclose(file);
- return FALSE;
+ dprint("waypoint_load_links: couldn't find 'from' waypoint at ", vtos(wp_from.origin),"\n");
+ continue;
}
+
}
// Search "to" waypoint
if(!found)
{
- // can't find that waypoint
- fclose(file);
- return FALSE;
+ dprint("waypoint_load_links: couldn't find 'to' waypoint at ", vtos(wp_to.origin),"\n");
+ continue;
}
++c;
++c;
waypoint_addlink(wp_from, wp_to);
+ wp_from.wphardwired = TRUE;
+ wp_to.wphardwired = TRUE;
}
fclose(file);
{
// 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))
+ //if (boxesoverlap(v - '4 4 4', v + '4 4 4', w.absmin, w.absmax))
return 0;
w = find(w, classname, "waypoint");
}
if(wp)
{
- // if nearest WP from here is linked to wp, everything is fine
- w = navigation_findnearestwaypoint(p, walkfromwp);
- if(w != wp)
+ // if any WP w fulfills wp -> w -> porg, then switch from wp to w
+
+ // if wp -> porg, then OK
+ float maxdist;
+ if(navigation_waypoint_will_link(wp.origin, porg, p, walkfromwp, 1050))
+ {
+ // we may find a better one
+ maxdist = vlen(wp.origin - porg);
+ }
+ else
{
- if(navigation_waypoint_will_link(w.origin, wp.origin, p, walkfromwp, 1050))
+ // accept any "good"
+ maxdist = 2100;
+ }
+
+ float bestdist;
+ bestdist = maxdist;
+ w = find(world, classname, "waypoint");
+ while (w)
+ {
+ if(w != wp && !(w.wpflags & WAYPOINTFLAG_NORELINK))
{
- print("update chain from ", etos(p.fld), " to new nearest WP ", etos(w), "\n");
- p.fld = w;
- return 0;
+ float d;
+ d = vlen(wp.origin - w.origin) + vlen(w.origin - porg);
+ if(d < bestdist)
+ if(navigation_waypoint_will_link(wp.origin, w.origin, p, walkfromwp, 1050))
+ if(navigation_waypoint_will_link(w.origin, porg, p, walkfromwp, 1050))
+ {
+ bestdist = d;
+ p.fld = w;
+ }
}
+ w = find(w, classname, "waypoint");
}
- if(navigation_waypoint_will_link(p.origin, wp.origin, p, walkfromwp, 1050))
+ if(bestdist < maxdist)
{
+ print("update chain to new nearest WP ", etos(p.fld), "\n");
+ return 0;
+ }
+
+ if(bestdist < 2100)
+ {
+ // we know maxdist < 2100
+ // so wp -> porg is still valid
+ // all is good
p.fld = wp;
return 0;
}
+
+ // otherwise, no existing WP can fix our issues
}
else
{
+ save = p.origin;
+ setorigin(p, porg);
w = navigation_findnearestwaypoint(p, walkfromwp);
+ setorigin(p, save);
if(w)
{
p.fld = w;
{
if(p.deadflag)
continue;
- botframe_autowaypoints_fix(p, FALSE, botframe_autowaypoints_lastwp0);
+ // going back is broken, so only fix waypoints to walk TO the player
+ //botframe_autowaypoints_fix(p, FALSE, botframe_autowaypoints_lastwp0);
botframe_autowaypoints_fix(p, TRUE, botframe_autowaypoints_lastwp1);
+ //te_explosion(p.botframe_autowaypoints_lastwp0.origin);
}
}