]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Assume bot can walk from wp A to item X if wp A is linked to wp B and wp B origin...
authorterencehill <piuntn@gmail.com>
Fri, 28 Apr 2017 16:40:30 +0000 (18:40 +0200)
committerterencehill <piuntn@gmail.com>
Fri, 28 Apr 2017 16:40:30 +0000 (18:40 +0200)
qcsrc/server/bot/default/navigation.qc
qcsrc/server/bot/default/navigation.qh

index d3f6752e4363077171e6a1af6df29a26b134d5fd..596e277c6565499204c8c81e91aece8eef96c010 100644 (file)
@@ -837,7 +837,26 @@ void navigation_routerating(entity this, entity e, float f, float rangebias)
                {
                        nwp = navigation_findnearestwaypoint(e, true);
                        if(nwp)
+                       {
                                e.nearestwaypoint = nwp;
+
+                               vector m1 = nwp.absmin, m2 = nwp.absmax;
+                               m1.x = nwp.origin.x; m1.y = nwp.origin.y;
+                               m2.x = nwp.origin.x; m2.y = nwp.origin.y;
+                               vector ve = (e.absmin - e.absmax) * 0.5;
+                               ve.x = bound(m1.x, ve.x, m2.x);
+                               ve.y = bound(m1.y, ve.y, m2.y);
+                               ve.z = bound(m1.z, ve.z, m2.z);
+
+                               m1 = e.absmin; m2 = e.absmax;
+                               m1.x = e.origin.x; m1.y = e.origin.y;
+                               m2.x = e.origin.x; m2.y = e.origin.y;
+                               vector vnwp = nwp.origin;
+                               vnwp.x = bound(m1.x, vnwp.x, m2.x);
+                               vnwp.y = bound(m1.y, vnwp.y, m2.y);
+                               vnwp.z = bound(m1.z, vnwp.z, m2.z);
+                               e.nearestwaypoint_dist = vlen(ve - vnwp);
+                       }
                        else
                        {
                                LOG_DEBUG("FAILED to find a nearest waypoint to '", e.classname, "' #", etos(e));
@@ -920,7 +939,8 @@ bool navigation_routetogoal(entity this, entity e, vector startposition)
        if(nearest_wp && nearest_wp.enemy)
        {
                // often path can be optimized by not adding the nearest waypoint
-               if(tracewalk(this, nearest_wp.enemy.origin, STAT(PL_MIN, this), STAT(PL_MAX, this), (this.goalentity.absmin + this.goalentity.absmax) * 0.5, bot_navigation_movemode))
+               if (this.goalentity.nearestwaypoint_dist < 8
+                       || tracewalk(this, nearest_wp.enemy.origin, STAT(PL_MIN, this), STAT(PL_MAX, this), (this.goalentity.absmin + this.goalentity.absmax) * 0.5, bot_navigation_movemode))
                        e = nearest_wp.enemy;
        }
 
index 8f1f03ad1933f9512a2f96126d82ab8770002233..49152e81f66e7e7b0df001e6cfb506aa456801b1 100644 (file)
@@ -22,12 +22,14 @@ entity navigation_bestgoal;
 .entity goalstack20, goalstack21, goalstack22, goalstack23;
 .entity goalstack24, goalstack25, goalstack26, goalstack27;
 .entity goalstack28, goalstack29, goalstack30, goalstack31;
+
 .entity nearestwaypoint;
+.float nearestwaypoint_dist;
+.float nearestwaypointtimeout;
 
 .entity wp_goal_prev0;
 .entity wp_goal_prev1;
 
-.float nearestwaypointtimeout;
 .float lastteleporttime;
 
 .float blacklisted;