From: Rudolf Polzer Date: Sun, 28 Aug 2011 19:12:36 +0000 (+0200) Subject: prevent some more waypoint spam X-Git-Tag: xonotic-v0.6.0~188^2~4^2~5 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=a33cea62b4773cc3b9a021f299c854aed65dacb7;p=xonotic%2Fxonotic-data.pk3dir.git prevent some more waypoint spam --- diff --git a/qcsrc/server/bot/waypoints.qc b/qcsrc/server/bot/waypoints.qc index c661b23ed..a214c660e 100644 --- a/qcsrc/server/bot/waypoints.qc +++ b/qcsrc/server/bot/waypoints.qc @@ -925,24 +925,56 @@ float botframe_autowaypoints_fix_from(entity p, float walkfromwp, entity wp, .en if(wp) { - // if nearest WP from here is linked to wp, everything is fine - // FIXME consider ALl waypoints for this, not just the nearest! - // i.e. all waypoints w for which wp -> w -> p works - w = navigation_findnearestwaypoint(p, walkfromwp); - if(w && 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 + { + // accept any "good" + maxdist = 2100; + } + + float bestdist; + bestdist = maxdist; + w = find(world, classname, "waypoint"); + while (w) { - if(navigation_waypoint_will_link(w.origin, wp.origin, p, walkfromwp, 1050)) + if(w != wp) { - 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(wp.origin, porg, p, walkfromwp, 1050)) + if(bestdist < maxdist) + { + print("update chain from ", etos(p.fld), " 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 {