From eeb8ad0195560c8a8a8044998c4bc1b07a92cb59 Mon Sep 17 00:00:00 2001 From: terencehill Date: Fri, 28 Apr 2017 18:40:30 +0200 Subject: [PATCH] Assume bot can walk from wp A to item X if wp A is linked to wp B and wp B origin matches item X origin (with a very small tolerance) --- qcsrc/server/bot/default/navigation.qc | 22 +++++++++++++++++++++- qcsrc/server/bot/default/navigation.qh | 4 +++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/qcsrc/server/bot/default/navigation.qc b/qcsrc/server/bot/default/navigation.qc index d3f6752e4..596e277c6 100644 --- a/qcsrc/server/bot/default/navigation.qc +++ b/qcsrc/server/bot/default/navigation.qc @@ -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; } diff --git a/qcsrc/server/bot/default/navigation.qh b/qcsrc/server/bot/default/navigation.qh index 8f1f03ad1..49152e81f 100644 --- a/qcsrc/server/bot/default/navigation.qh +++ b/qcsrc/server/bot/default/navigation.qh @@ -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; -- 2.39.2