From 51369ee6ac98e95c88acc463b69a2e8dbb68f783 Mon Sep 17 00:00:00 2001 From: terencehill Date: Fri, 10 Nov 2017 13:48:03 +0100 Subject: [PATCH] Bot AI: if bot is closer to player than next waypoint clear route and directly chase the player --- qcsrc/server/bot/default/navigation.qc | 44 +++++++++++++++----------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/qcsrc/server/bot/default/navigation.qc b/qcsrc/server/bot/default/navigation.qc index 98403bc4d..36e5843f6 100644 --- a/qcsrc/server/bot/default/navigation.qc +++ b/qcsrc/server/bot/default/navigation.qc @@ -1531,26 +1531,34 @@ int navigation_poptouchedgoals(entity this) } // If for some reason the bot is closer to the next goal, pop the current one - if(this.goalstack01 && !wasfreed(this.goalstack01)) - if(random() < 0.7) // randomness should help on certain hard paths with climbs and tight corners - if(vlen2(this.goalcurrent.origin - this.goalstack01.origin) > vlen2(this.goalstack01.origin - this.origin)) - if(checkpvs(this.origin + this.view_ofs, this.goalstack01)) + // randomness should help to get unstuck bot on certain hard paths with climbs and tight corners + if (this.goalstack01 && !wasfreed(this.goalstack01) && random() < 0.7) { - set_tracewalk_dest(this.goalstack01, this.origin, false); - if(tracewalk(this, this.origin, this.mins, this.maxs, - tracewalk_dest, tracewalk_dest_height, bot_navigation_movemode)) + entity next = IS_PLAYER(this.goalentity) ? this.goalentity : this.goalstack01; + if (vlen2(this.goalcurrent.origin - next.origin) > vlen2(next.origin - this.origin) + && checkpvs(this.origin + this.view_ofs, next)) { - LOG_DEBUG("path optimized for ", this.netname, ", removed a goal from the queue"); - navigation_poproute(this); - ++removed_goals; - if(this.goalcurrent && this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT) - return removed_goals; - // TODO this may also be a nice idea to do "early" (e.g. by - // manipulating the vlen() comparisons) to shorten paths in - // general - this would make bots walk more "on rails" than - // "zigzagging" which they currently do with sufficiently - // random-like waypoints, and thus can make a nice bot - // personality property + set_tracewalk_dest(next, this.origin, true); + if (trace_ent == this || tracewalk(this, this.origin, this.mins, this.maxs, + tracewalk_dest, tracewalk_dest_height, bot_navigation_movemode)) + { + LOG_DEBUG("path optimized for ", this.netname, ", removed a goal from the queue"); + do + { + // loop clears the whole route if next is a player + navigation_poproute(this); + ++removed_goals; + } + while (this.goalcurrent == next); + if (this.goalcurrent && this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT) + return removed_goals; + // TODO this may also be a nice idea to do "early" (e.g. by + // manipulating the vlen() comparisons) to shorten paths in + // general - this would make bots walk more "on rails" than + // "zigzagging" which they currently do with sufficiently + // random-like waypoints, and thus can make a nice bot + // personality property + } } } -- 2.39.2