From 7a9f7cb4ce2401ad0b4fd56b2e4ec81107e0d240 Mon Sep 17 00:00:00 2001 From: terencehill Date: Wed, 13 Jun 2018 19:29:37 +0200 Subject: [PATCH] Bot AI: try to anticipate (and optimize) path finding when path gets shortened too --- qcsrc/server/bot/default/havocbot/havocbot.qc | 7 ++++++- qcsrc/server/bot/default/navigation.qc | 11 +++++++---- qcsrc/server/bot/default/navigation.qh | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/qcsrc/server/bot/default/havocbot/havocbot.qc b/qcsrc/server/bot/default/havocbot/havocbot.qc index 429254a5e..40cff2753 100644 --- a/qcsrc/server/bot/default/havocbot/havocbot.qc +++ b/qcsrc/server/bot/default/havocbot/havocbot.qc @@ -772,7 +772,12 @@ void havocbot_movetogoal(entity this) if (this.goalcurrent == this.goalentity && this.goalentity_lock_timeout > time) locked_goal = true; - navigation_shortenpath(this); + if (navigation_shortenpath(this)) + { + if (vdist(this.origin - this.goalcurrent_prev.origin, <, 50) + && navigation_goalrating_timeout_can_be_anticipated(this)) + navigation_goalrating_timeout_force(this); + } bool goalcurrent_can_be_removed = false; if (IS_MOVABLE(this.goalcurrent)) diff --git a/qcsrc/server/bot/default/navigation.qc b/qcsrc/server/bot/default/navigation.qc index 228ec30de..7ece113e6 100644 --- a/qcsrc/server/bot/default/navigation.qc +++ b/qcsrc/server/bot/default/navigation.qc @@ -1507,12 +1507,12 @@ bool navigation_routetogoal(entity this, entity e, vector startposition) } // shorten path by removing intermediate goals -void navigation_shortenpath(entity this) +bool navigation_shortenpath(entity this) { if (!this.goalstack01 || wasfreed(this.goalstack01)) - return; + return false; if (this.bot_tracewalk_time > time) - return; + return false; this.bot_tracewalk_time = max(time, this.bot_tracewalk_time) + 0.25; bool cut_allowed = false; @@ -1551,8 +1551,9 @@ void navigation_shortenpath(entity this) navigation_poproute(this); } while (this.goalcurrent != next); + return true; } - return; + return false; } } @@ -1573,8 +1574,10 @@ void navigation_shortenpath(entity this) { LOG_DEBUG("path optimized for ", this.netname, ", removed a goal from the queue"); navigation_poproute(this); + return true; } } + return false; } // removes any currently touching waypoints from the goal stack diff --git a/qcsrc/server/bot/default/navigation.qh b/qcsrc/server/bot/default/navigation.qh index 80498b691..233ae9ae7 100644 --- a/qcsrc/server/bot/default/navigation.qh +++ b/qcsrc/server/bot/default/navigation.qh @@ -115,7 +115,7 @@ void navigation_markroutes_checkwaypoint(entity w, entity wp, float cost2, vecto void navigation_markroutes(entity this, entity fixed_source_waypoint); void navigation_markroutes_inverted(entity fixed_source_waypoint); void navigation_routerating(entity this, entity e, float f, float rangebias); -void navigation_shortenpath(entity this); +bool navigation_shortenpath(entity this); int navigation_poptouchedgoals(entity this); void navigation_goalrating_start(entity this); void navigation_goalrating_end(entity this); -- 2.39.2