]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Bot AI: if bot is closer to player than next waypoint clear route and directly chase...
authorterencehill <piuntn@gmail.com>
Fri, 10 Nov 2017 12:48:03 +0000 (13:48 +0100)
committerterencehill <piuntn@gmail.com>
Fri, 10 Nov 2017 13:13:00 +0000 (14:13 +0100)
qcsrc/server/bot/default/navigation.qc

index 98403bc4d34535e4f5c53dc46a4cad72eefa1fa3..36e5843f64824a278fe818ea4fbe84b25caac471 100644 (file)
@@ -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
+                       }
                }
        }