]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
more improvements - now it somewhat works, but still creates weird and too many waypoints
authorRudolf Polzer <divverent@xonotic.org>
Sun, 28 Aug 2011 17:51:32 +0000 (19:51 +0200)
committerRudolf Polzer <divverent@xonotic.org>
Sun, 28 Aug 2011 17:51:32 +0000 (19:51 +0200)
qcsrc/server/bot/navigation.qc
qcsrc/server/bot/waypoints.qc

index 71016d5032514af649d8c637244803c928c383a9..b0a7a41cf3ad01428f219829ce340ef793cc3b09 100644 (file)
@@ -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;
                        }
                }
index 5a0bb1e7c428ec69f236145e997ddbe618737f8d..58c512b2758b679461d2016dac04c4348cdc5a8b 100644 (file)
@@ -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);
        }