From 5d3b698d64dc4cbd9c17d77c271e31f8e359543e Mon Sep 17 00:00:00 2001 From: terencehill Date: Sat, 4 Mar 2017 15:10:16 +0100 Subject: [PATCH] Bot path finding: when possible (often) optimize path by not adding the nearest waypoint of the goal --- qcsrc/server/bot/default/navigation.qc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/qcsrc/server/bot/default/navigation.qc b/qcsrc/server/bot/default/navigation.qc index 20a3a9149..65ba4d00b 100644 --- a/qcsrc/server/bot/default/navigation.qc +++ b/qcsrc/server/bot/default/navigation.qc @@ -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 -- 2.39.2