]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Bot path finding: when possible (often) optimize path by not adding the nearest waypo...
authorterencehill <piuntn@gmail.com>
Sat, 4 Mar 2017 14:10:16 +0000 (15:10 +0100)
committerterencehill <piuntn@gmail.com>
Sat, 4 Mar 2017 14:10:16 +0000 (15:10 +0100)
qcsrc/server/bot/default/navigation.qc

index 20a3a9149335289dfc0e58d088a2ecce7499c202..65ba4d00bfa4185877ace0ec08c0d4358557d819 100644 (file)
@@ -895,15 +895,26 @@ bool navigation_routetogoal(entity this, entity e, vector startposition)
        if (tracewalk(this, startposition, STAT(PL_MIN, this), STAT(PL_MAX, this), (e.absmin + e.absmax) * 0.5, bot_navigation_movemode))
                return true;
 
+       entity nearest_wp = NULL;
        // see if there are waypoints describing a path to the item
        if(e.classname != "waypoint" || (e.wpflags & WAYPOINTFLAG_PERSONAL))
+       {
                e = e.nearestwaypoint;
+               nearest_wp = e;
+       }
        else
                e = e.enemy; // we already have added it, so...
 
        if(e == NULL)
                return false;
 
+       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))
+                       e = nearest_wp.enemy;
+       }
+
        for (;;)
        {
                // add the spawnfunc_waypoint to the path