void navigation_unstuck()
{
+ float search_radius = 1000;
+
if not(autocvar_bot_wander_enable)
return;
- if not(navigation_wander_owner)
+ if not(bot_waypoint_queue_owner)
{
- dprint(self.netname, " taking over the waypoints queue\n");
- navigation_wander_owner = self;
- navigation_wander_bestgoal = world;
- navigation_wander_bestgoalrating = 0;
+ // dprint(self.netname, " sutck, taking over the waypoints queue\n");
+ bot_waypoint_queue_owner = self;
+ bot_waypoint_queue_bestgoal = world;
+ bot_waypoint_queue_bestgoalrating = 0;
}
- if(navigation_wander_owner!=self)
+ if(bot_waypoint_queue_owner!=self)
return;
- if (navigation_wander_goal)
+ if (bot_waypoint_queue_goal)
{
// evaluate the next goal on the queue
- float d = vlen(self.origin - navigation_wander_goal.origin);
- // dprint(self.netname, " evaluating ", navigation_wander_goal.classname, " with distance ", ftos(d), "\n");
- if(tracewalk(navigation_wander_goal, self.origin, PL_MIN, PL_MAX, navigation_wander_goal.origin, bot_navigation_movemode))
+ float d = vlen(self.origin - bot_waypoint_queue_goal.origin);
+ // dprint(self.netname, " evaluating ", bot_waypoint_queue_goal.classname, " with distance ", ftos(d), "\n");
+ if(tracewalk(bot_waypoint_queue_goal, self.origin, PL_MIN, PL_MAX, bot_waypoint_queue_goal.origin, bot_navigation_movemode))
{
- if( d > navigation_wander_bestgoalrating)
+ if( d > bot_waypoint_queue_bestgoalrating)
{
- navigation_wander_bestgoalrating = d;
- navigation_wander_bestgoal = navigation_wander_goal;
+ bot_waypoint_queue_bestgoalrating = d;
+ bot_waypoint_queue_bestgoal = bot_waypoint_queue_goal;
}
}
- navigation_wander_goal = navigation_wander_goal.navigation_wander_nextgoal;
+ bot_waypoint_queue_goal = bot_waypoint_queue_goal.bot_waypoint_queue_nextgoal;
- if not(navigation_wander_goal)
+ if not(bot_waypoint_queue_goal)
{
- if (navigation_wander_bestgoal)
+ if (bot_waypoint_queue_bestgoal)
{
- navigation_routetogoal(navigation_wander_bestgoal, self.origin);
+ dprint(self.netname, " stuck, reachable waypoint found, heading to it\n");
+ navigation_routetogoal(bot_waypoint_queue_bestgoal, self.origin);
self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
self.aistatus &~= AI_STATUS_STUCK;
}
else
{
- dprint(self.netname, " got BADLY stuck, giving up.\n");
+ dprint(self.netname, " stuck, cannot walk to any waypoint at all\n");
}
- navigation_wander_owner = world;
+ bot_waypoint_queue_owner = world;
}
}
else
return;
// build a new queue
- dprint(self.netname, " building a new wayoints queue\n");
+ dprint(self.netname, " stuck, scanning reachable waypoints within ", ftos(search_radius)," qu\n");
+
+ entity head, first;
- entity first, head, prev;
- head = findradius(self.origin, 1000);
+ first = world;
+ head = findradius(self.origin, search_radius);
while(head)
{
if(head.classname=="waypoint")
if(!(head.wpflags & WAYPOINTFLAG_GENERATED))
{
- if (first==world)
- {
- first = head;
- navigation_wander_goal = head;
- }
+ if(bot_waypoint_queue_goal)
+ bot_waypoint_queue_goal.bot_waypoint_queue_nextgoal = head;
else
- {
- prev = navigation_wander_goal;
- navigation_wander_goal = head;
- prev.navigation_wander_nextgoal = head;
- navigation_wander_goal.navigation_wander_nextgoal = world;
- }
+ first = head;
+
+ bot_waypoint_queue_goal = head;
+ bot_waypoint_queue_goal.bot_waypoint_queue_nextgoal = world;
}
head = head.chain;
}
if (first)
- navigation_wander_goal = first;
+ bot_waypoint_queue_goal = first;
else
{
- dprint(self.netname, " got BADLY stuck, giving up.\n");
+ dprint(self.netname, " stuck, cannot walk to any waypoint at all\n");
+ bot_waypoint_queue_owner = world;
}
}
}