From: Rudolf Polzer Date: Sun, 28 Aug 2011 17:51:32 +0000 (+0200) Subject: more improvements - now it somewhat works, but still creates weird and too many waypoints X-Git-Tag: xonotic-v0.6.0~188^2~4^2~8 X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=commitdiff_plain;h=f1f9655d13a7ae275db0d622314cb96d8b55034c;ds=sidebyside more improvements - now it somewhat works, but still creates weird and too many waypoints --- diff --git a/qcsrc/server/bot/navigation.qc b/qcsrc/server/bot/navigation.qc index 71016d503..b0a7a41cf 100644 --- a/qcsrc/server/bot/navigation.qc +++ b/qcsrc/server/bot/navigation.qc @@ -354,7 +354,6 @@ float navigation_waypoint_will_link(vector v, vector org, entity ent, float walk 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; @@ -401,7 +400,7 @@ entity navigation_findnearestwaypoint_withdist(entity ent, float walkfromwp, flo v = w.origin; if(navigation_waypoint_will_link(v, org, ent, walkfromwp, bestdist)) { - bestdist = dist; + bestdist = vlen(v - org); best = w; } } diff --git a/qcsrc/server/bot/waypoints.qc b/qcsrc/server/bot/waypoints.qc index 5a0bb1e7c..58c512b27 100644 --- a/qcsrc/server/bot/waypoints.qc +++ b/qcsrc/server/bot/waypoints.qc @@ -885,6 +885,23 @@ float botframe_autowaypoints_fixdown(vector v) 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 @@ -986,8 +1003,7 @@ float botframe_autowaypoints_fix_from(entity p, float walkfromwp, entity wp, .en } 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; } @@ -1006,7 +1022,7 @@ void botframe_autowaypoints_fix(entity p, float walkfromwp, .entity fld) 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() { @@ -1016,8 +1032,6 @@ 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); }