1 #include "navigation.qh"
6 #include "waypoints.qh"
8 #include <common/t_items.qh>
10 #include <common/items/_mod.qh>
12 #include <common/constants.qh>
13 #include <common/net_linked.qh>
14 #include <common/triggers/trigger/jumppads.qh>
18 void navigation_dynamicgoal_init(entity this, bool initially_static)
20 this.navigation_dynamicgoal = true;
21 this.bot_basewaypoint = this.nearestwaypoint;
23 this.nearestwaypointtimeout = -1;
25 this.nearestwaypointtimeout = time;
28 void navigation_dynamicgoal_set(entity this)
30 this.nearestwaypointtimeout = time;
33 void navigation_dynamicgoal_unset(entity this)
35 if(this.bot_basewaypoint)
36 this.nearestwaypoint = this.bot_basewaypoint;
37 this.nearestwaypointtimeout = -1;
40 bool navigation_checkladders(entity e, vector org, vector m1, vector m2, vector end, vector end2, int movemode)
42 IL_EACH(g_ladders, it.classname == "func_ladder",
45 if(boxesoverlap(org + m1 + '-1 -1 -1', org + m2 + '1 1 1', it.absmin, it.absmax))
46 if(boxesoverlap(end, end2, it.absmin + (m1 - eZ * m1.z - '1 1 0'), it.absmax + (m2 - eZ * m2.z + '1 1 0')))
49 top.z = it.absmax.z + (PL_MAX_CONST.z - PL_MIN_CONST.z);
50 tracebox(org, m1, m2, top, movemode, e);
51 if(trace_fraction == 1)
58 vector resurface_limited(vector org, float lim, vector m1)
60 if (WETFEET(org + eZ * (lim - org.z)))
64 float RES_min_h = org.z;
65 float RES_max_h = lim;
67 org.z = 0.5 * (RES_min_h + RES_max_h);
72 } while (RES_max_h - RES_min_h >= 1);
77 #define RESURFACE_LIMITED(org, lim) org = resurface_limited(org, lim, m1)
80 #define NAV_SWIM_ONWATER 1
81 #define NAV_SWIM_UNDERWATER 2
83 // rough simulation of walking from one point to another to test if a path
84 // can be traveled, used for waypoint linking and havocbot
85 // if end_height is > 0 destination is any point in the vertical segment [end, end + end_height * eZ]
86 bool tracewalk(entity e, vector start, vector m1, vector m2, vector end, float end_height, float movemode)
88 if(autocvar_bot_debug_tracewalk)
95 vector flatdir = end - start;
97 float flatdist = vlen(flatdir);
98 flatdir = normalize(flatdir);
100 bool ignorehazards = false;
103 // Analyze starting point
104 traceline(start, start, MOVE_NORMAL, e);
105 if (trace_dpstartcontents & (DPCONTENTS_SLIME | DPCONTENTS_LAVA))
106 ignorehazards = true;
108 tracebox(start, m1, m2, start, MOVE_NOMONSTERS, e);
109 if (trace_startsolid)
112 if(autocvar_bot_debug_tracewalk)
113 debugnodestatus(start, DEBUG_NODE_FAIL);
115 //print("tracewalk: ", vtos(start), " is a bad start\n");
121 end2.z += end_height;
123 vector fixed_end = end;
126 if (flatdist > 0 && WETFEET(org))
129 nav_action = NAV_SWIM_UNDERWATER;
132 // tracebox down by player's height
133 // useful to know if water level is so low that bot can still walk
134 tracebox(org, m1, m2, org - eZ * (m2.z - m1.z), movemode, e);
135 if (SUBMERGED(trace_endpos))
138 nav_action = NAV_SWIM_UNDERWATER;
141 nav_action = NAV_WALK;
145 nav_action = NAV_WALK;
153 if (org.z > end2.z + 1)
155 tracebox(org, m1, m2, end2, movemode, e);
157 if (org.z > end2.z + 1)
160 else if (org.z < end.z - 1)
162 tracebox(org, m1, m2, org - jumpheight_vec, movemode, e);
163 if (SUBMERGED(trace_endpos))
164 RESURFACE_LIMITED(trace_endpos, end.z);
165 else if (trace_endpos.z > org.z - jumpheight_vec.z)
166 tracebox(trace_endpos, m1, m2, trace_endpos + jumpheight_vec, movemode, e);
168 if (org.z < end.z - 1)
175 if(autocvar_bot_debug_tracewalk)
178 debugnodestatus(org, DEBUG_NODE_SUCCESS);
181 //print("tracewalk: ", vtos(start), " can reach ", vtos(end), "\n");
186 if(autocvar_bot_debug_tracewalk)
192 if(nav_action == NAV_SWIM_UNDERWATER || (nav_action == NAV_SWIM_ONWATER && org.z > end2.z))
194 // can't use movement direction here to calculate move because of
195 // precision errors especially when direction has a high enough z value
196 //water_dir = normalize(water_end - org);
197 //move = org + water_dir * stepdist;
198 fixed_end.z = bound(end.z, org.z, end2.z);
199 if (stepdist > flatdist)
201 if (stepdist == flatdist) {
205 move = org + (fixed_end - org) * (stepdist / flatdist);
206 flatdist = vlen(vec2(fixed_end - move));
209 else // horiz. direction
211 if (stepdist > flatdist)
213 flatdist -= stepdist;
214 move = org + flatdir * stepdist;
217 if(nav_action == NAV_SWIM_ONWATER)
219 tracebox(org, m1, m2, move, movemode, e); // swim
222 if (trace_fraction < 1)
225 tracebox(org + stepheightvec, m1, m2, move + stepheightvec, movemode, e);
227 if (trace_fraction < 1 || trace_startsolid) // can't jump obstacle out of water
229 if(navigation_checkladders(e, trace_endpos, m1, m2, end, end2, movemode))
231 if(autocvar_bot_debug_tracewalk)
233 debugnode(e, trace_endpos);
234 debugnodestatus(trace_endpos, DEBUG_NODE_SUCCESS);
237 //print("tracewalk: ", vtos(start), " can reach ", vtos(end), "\n");
241 if(autocvar_bot_debug_tracewalk)
242 debugnodestatus(trace_endpos, DEBUG_NODE_FAIL);
245 //print("tracewalk: ", vtos(start), " hit something when trying to reach ", vtos(end), "\n");
256 if (org.z <= move.z) // going horiz.
258 tracebox(trace_endpos, m1, m2, move, movemode, e);
260 nav_action = NAV_WALK;
265 if (org.z <= move.z) // going horiz.
268 nav_action = NAV_SWIM_ONWATER;
274 nav_action = NAV_SWIM_UNDERWATER;
276 nav_action = NAV_SWIM_ONWATER;
279 else if(nav_action == NAV_SWIM_UNDERWATER)
281 if (move.z >= org.z) // swimming upwards or horiz.
283 tracebox(org, m1, m2, move, movemode, e); // swim
285 bool stepswimmed = false;
288 if (trace_fraction < 1)
291 vector stepswim_move = move + stepheightvec;
292 if (flatdist > 0 && stepswim_move.z > end2.z) // don't allow stepswim to go higher than destination
293 stepswim_move.z = end2.z;
295 tracebox(org + stepheightvec, m1, m2, stepswim_move, movemode, e);
298 if (trace_startsolid)
300 if(autocvar_bot_debug_tracewalk)
301 debugnodestatus(org, DEBUG_NODE_FAIL);
303 //print("tracewalk: ", vtos(start), " hit something when trying to reach ", vtos(end), "\n");
307 if (trace_fraction < 1)
309 float org_z_prev = org.z;
310 RESURFACE_LIMITED(org, end2.z);
311 if(org.z == org_z_prev)
313 if(autocvar_bot_debug_tracewalk)
314 debugnodestatus(org, DEBUG_NODE_FAIL);
316 //print("tracewalk: ", vtos(start), " can't reach ", vtos(end), "\n");
320 nav_action = NAV_SWIM_UNDERWATER;
322 nav_action = NAV_SWIM_ONWATER;
324 // we didn't advance horiz. in this step, flatdist decrease should be reverted
325 // but we can do it properly right now... apply this workaround instead
343 if (!WETFEET(trace_endpos))
345 tracebox(trace_endpos, m1, m2, trace_endpos - eZ * (stepdist + (m2.z - m1.z)), movemode, e);
346 // if stepswimmed we'll land on the obstacle, avoid the SUBMERGED check
347 if (!stepswimmed && SUBMERGED(trace_endpos))
349 RESURFACE_LIMITED(trace_endpos, end2.z);
351 nav_action = NAV_SWIM_ONWATER;
357 nav_action = NAV_WALK;
363 nav_action = NAV_SWIM_UNDERWATER;
366 else //if (move.z < org.z) // swimming downwards
368 tracebox(org, m1, m2, move, movemode, e); // swim
371 if (trace_fraction < 1)
374 tracebox(org + stepheightvec, m1, m2, move + stepheightvec, movemode, e);
377 if (trace_fraction < 1 || trace_startsolid) // can't jump obstacle out of water
379 if(autocvar_bot_debug_tracewalk)
380 debugnodestatus(move, DEBUG_NODE_FAIL);
382 //print("tracewalk: ", vtos(start), " hit something when trying to reach ", vtos(end), "\n");
394 if (trace_endpos.z > org.z && !SUBMERGED(trace_endpos))
396 // stepswim caused upwards direction
397 tracebox(trace_endpos, m1, m2, trace_endpos - stepheightvec, movemode, e);
398 if (!SUBMERGED(trace_endpos))
401 nav_action = NAV_WALK;
408 nav_action = NAV_SWIM_UNDERWATER;
412 else if(nav_action == NAV_WALK)
415 tracebox(org, m1, m2, move, movemode, e);
417 if(autocvar_bot_debug_tracewalk)
418 debugnode(e, trace_endpos);
421 if (trace_fraction < 1)
423 // check if we can walk over this obstacle, possibly by jumpstepping
424 tracebox(org + stepheightvec, m1, m2, move + stepheightvec, movemode, e);
425 if (trace_fraction < 1 || trace_startsolid)
427 tracebox(org + jumpstepheightvec, m1, m2, move + jumpstepheightvec, movemode, e);
428 if (trace_fraction < 1 || trace_startsolid)
430 vector v = trace_endpos - jumpstepheightvec + jumpheight_vec;
431 if(navigation_checkladders(e, v, m1, m2, end, end2, movemode))
433 if(autocvar_bot_debug_tracewalk)
436 debugnodestatus(v, DEBUG_NODE_SUCCESS);
439 //print("tracewalk: ", vtos(start), " can reach ", vtos(end), "\n");
443 if(autocvar_bot_debug_tracewalk)
444 debugnodestatus(trace_endpos, DEBUG_NODE_WARNING);
446 traceline( org, move, movemode, e);
448 if ( trace_ent.classname == "door_rotating" || trace_ent.classname == "door")
452 while(trace_ent.classname == "door_rotating" || trace_ent.classname == "door")
454 nextmove = move + (flatdir * stepdist);
455 traceline( move, nextmove, movemode, e);
458 flatdist = vlen(vec2(end - move));
462 if(autocvar_bot_debug_tracewalk)
463 debugnodestatus(trace_endpos, DEBUG_NODE_FAIL);
465 //print("tracewalk: ", vtos(start), " hit something when trying to reach ", vtos(end), "\n");
466 //te_explosion(trace_endpos);
467 //print(ftos(e.dphitcontentsmask), "\n");
468 return false; // failed
486 // trace down from stepheight as far as possible and move there,
487 // if this starts in solid we try again without the stepup, and
488 // if that also fails we assume it is a wall
489 // (this is the same logic as the Quake walkmove function used)
490 tracebox(move, m1, m2, move + '0 0 -65536', movemode, e);
498 if(autocvar_bot_debug_tracewalk)
500 debugnode(e, trace_endpos);
501 debugnodestatus(org, DEBUG_NODE_FAIL);
504 //print("tracewalk: ", vtos(start), " hits a hazard when trying to reach ", vtos(end), "\n");
509 if(org.z > move.z - 1 || !SUBMERGED(org))
511 nav_action = NAV_WALK;
515 // ended up submerged while walking
516 if(autocvar_bot_debug_tracewalk)
519 RESURFACE_LIMITED(org, move.z);
520 nav_action = NAV_SWIM_ONWATER;
525 //print("tracewalk: ", vtos(start), " did not arrive at ", vtos(end), " but at ", vtos(org), "\n");
527 // moved but didn't arrive at the intended destination
528 if(autocvar_bot_debug_tracewalk)
529 debugnodestatus(org, DEBUG_NODE_FAIL);
534 /////////////////////////////////////////////////////////////////////////////
536 /////////////////////////////////////////////////////////////////////////////
538 // completely empty the goal stack, used when deciding where to go
539 void navigation_clearroute(entity this)
541 this.goalcurrent_prev = this.goalcurrent;
542 this.goalcurrent_distance = 10000000;
543 this.goalcurrent_distance_time = 0;
544 //print("bot ", etos(this), " clear\n");
545 this.goalentity = NULL;
546 this.goalcurrent = NULL;
547 this.goalstack01 = NULL;
548 this.goalstack02 = NULL;
549 this.goalstack03 = NULL;
550 this.goalstack04 = NULL;
551 this.goalstack05 = NULL;
552 this.goalstack06 = NULL;
553 this.goalstack07 = NULL;
554 this.goalstack08 = NULL;
555 this.goalstack09 = NULL;
556 this.goalstack10 = NULL;
557 this.goalstack11 = NULL;
558 this.goalstack12 = NULL;
559 this.goalstack13 = NULL;
560 this.goalstack14 = NULL;
561 this.goalstack15 = NULL;
562 this.goalstack16 = NULL;
563 this.goalstack17 = NULL;
564 this.goalstack18 = NULL;
565 this.goalstack19 = NULL;
566 this.goalstack20 = NULL;
567 this.goalstack21 = NULL;
568 this.goalstack22 = NULL;
569 this.goalstack23 = NULL;
570 this.goalstack24 = NULL;
571 this.goalstack25 = NULL;
572 this.goalstack26 = NULL;
573 this.goalstack27 = NULL;
574 this.goalstack28 = NULL;
575 this.goalstack29 = NULL;
576 this.goalstack30 = NULL;
577 this.goalstack31 = NULL;
580 // add a new goal at the beginning of the stack
581 // (in other words: add a new prerequisite before going to the later goals)
582 // NOTE: when a waypoint is added, the WP gets pushed first, then the
583 // next-closest WP on the shortest path to the WP
584 // That means, if the stack overflows, the bot will know how to do the FIRST 32
585 // steps to the goal, and then recalculate the path.
586 void navigation_pushroute(entity this, entity e)
588 this.goalcurrent_prev = this.goalcurrent;
589 this.goalcurrent_distance = 10000000;
590 this.goalcurrent_distance_time = 0;
591 //print("bot ", etos(this), " push ", etos(e), "\n");
592 if(this.goalstack31 == this.goalentity)
593 this.goalentity = NULL;
594 this.goalstack31 = this.goalstack30;
595 this.goalstack30 = this.goalstack29;
596 this.goalstack29 = this.goalstack28;
597 this.goalstack28 = this.goalstack27;
598 this.goalstack27 = this.goalstack26;
599 this.goalstack26 = this.goalstack25;
600 this.goalstack25 = this.goalstack24;
601 this.goalstack24 = this.goalstack23;
602 this.goalstack23 = this.goalstack22;
603 this.goalstack22 = this.goalstack21;
604 this.goalstack21 = this.goalstack20;
605 this.goalstack20 = this.goalstack19;
606 this.goalstack19 = this.goalstack18;
607 this.goalstack18 = this.goalstack17;
608 this.goalstack17 = this.goalstack16;
609 this.goalstack16 = this.goalstack15;
610 this.goalstack15 = this.goalstack14;
611 this.goalstack14 = this.goalstack13;
612 this.goalstack13 = this.goalstack12;
613 this.goalstack12 = this.goalstack11;
614 this.goalstack11 = this.goalstack10;
615 this.goalstack10 = this.goalstack09;
616 this.goalstack09 = this.goalstack08;
617 this.goalstack08 = this.goalstack07;
618 this.goalstack07 = this.goalstack06;
619 this.goalstack06 = this.goalstack05;
620 this.goalstack05 = this.goalstack04;
621 this.goalstack04 = this.goalstack03;
622 this.goalstack03 = this.goalstack02;
623 this.goalstack02 = this.goalstack01;
624 this.goalstack01 = this.goalcurrent;
625 this.goalcurrent = e;
628 // remove first goal from stack
629 // (in other words: remove a prerequisite for reaching the later goals)
630 // (used when a spawnfunc_waypoint is reached)
631 void navigation_poproute(entity this)
633 this.goalcurrent_prev = this.goalcurrent;
634 this.goalcurrent_distance = 10000000;
635 this.goalcurrent_distance_time = 0;
636 //print("bot ", etos(this), " pop\n");
637 if(this.goalcurrent == this.goalentity)
638 this.goalentity = NULL;
639 this.goalcurrent = this.goalstack01;
640 this.goalstack01 = this.goalstack02;
641 this.goalstack02 = this.goalstack03;
642 this.goalstack03 = this.goalstack04;
643 this.goalstack04 = this.goalstack05;
644 this.goalstack05 = this.goalstack06;
645 this.goalstack06 = this.goalstack07;
646 this.goalstack07 = this.goalstack08;
647 this.goalstack08 = this.goalstack09;
648 this.goalstack09 = this.goalstack10;
649 this.goalstack10 = this.goalstack11;
650 this.goalstack11 = this.goalstack12;
651 this.goalstack12 = this.goalstack13;
652 this.goalstack13 = this.goalstack14;
653 this.goalstack14 = this.goalstack15;
654 this.goalstack15 = this.goalstack16;
655 this.goalstack16 = this.goalstack17;
656 this.goalstack17 = this.goalstack18;
657 this.goalstack18 = this.goalstack19;
658 this.goalstack19 = this.goalstack20;
659 this.goalstack20 = this.goalstack21;
660 this.goalstack21 = this.goalstack22;
661 this.goalstack22 = this.goalstack23;
662 this.goalstack23 = this.goalstack24;
663 this.goalstack24 = this.goalstack25;
664 this.goalstack25 = this.goalstack26;
665 this.goalstack26 = this.goalstack27;
666 this.goalstack27 = this.goalstack28;
667 this.goalstack28 = this.goalstack29;
668 this.goalstack29 = this.goalstack30;
669 this.goalstack30 = this.goalstack31;
670 this.goalstack31 = NULL;
673 // walking to wp (walkfromwp == false) v2 and v2_height will be used as
674 // waypoint destination coordinates instead of v (only useful for box waypoints)
675 // for normal waypoints v2 == v and v2_height == 0
676 float navigation_waypoint_will_link(vector v, vector org, entity ent, vector v2, float v2_height, float walkfromwp, float bestdist)
678 if (vdist(v - org, <, bestdist))
680 traceline(v, org, true, ent);
681 if (trace_fraction == 1)
685 if (tracewalk(ent, v, PL_MIN_CONST, PL_MAX_CONST, org, 0, bot_navigation_movemode))
690 if (tracewalk(ent, org, PL_MIN_CONST, PL_MAX_CONST, v2, v2_height, bot_navigation_movemode))
698 // find the spawnfunc_waypoint near a dynamic goal such as a dropped weapon
699 entity navigation_findnearestwaypoint_withdist_except(entity ent, float walkfromwp, float bestdist, entity except)
701 vector pm1 = ent.origin + ent.mins;
702 vector pm2 = ent.origin + ent.maxs;
704 // do two scans, because box test is cheaper
705 IL_EACH(g_waypoints, it != ent && it != except,
707 if(boxesoverlap(pm1, pm2, it.absmin, it.absmax))
711 vector org = ent.origin + 0.5 * (ent.mins + ent.maxs);
712 org.z = ent.origin.z + ent.mins.z - PL_MIN_CONST.z; // player height
713 // TODO possibly make other code have the same support for bboxes
715 org = org + ent.tag_entity.origin;
716 if (navigation_testtracewalk)
723 if(!autocvar_g_waypointeditor && !ent.navigation_dynamicgoal)
725 waypoint_clearlinks(ent); // initialize wpXXmincost fields
726 IL_EACH(g_waypoints, it != ent,
728 if(walkfromwp && (it.wpflags & WAYPOINTFLAG_NORELINK))
731 SET_TRACEWALK_DESTCOORDS_2(it, org, v, v2, v2_height);
732 if(navigation_waypoint_will_link(v, org, ent, v2, v2_height, walkfromwp, 1050))
733 navigation_item_addlink(it, ent);
737 // box check failed, try walk
738 IL_EACH(g_waypoints, it != ent,
740 if(walkfromwp && (it.wpflags & WAYPOINTFLAG_NORELINK))
742 SET_TRACEWALK_DESTCOORDS_2(it, org, v, v2, v2_height);
743 if(navigation_waypoint_will_link(v, org, ent, v2, v2_height, walkfromwp, bestdist))
745 bestdist = vlen(v - org);
751 entity navigation_findnearestwaypoint(entity ent, float walkfromwp)
753 entity wp = navigation_findnearestwaypoint_withdist_except(ent, walkfromwp, 1050, NULL);
754 if (autocvar_g_waypointeditor_auto)
756 entity wp2 = navigation_findnearestwaypoint_withdist_except(ent, walkfromwp, 1050, wp);
758 wp.wpflags |= WAYPOINTFLAG_PROTECTED;
763 // finds the waypoints near the bot initiating a navigation query
764 float navigation_markroutes_nearestwaypoints(entity this, float maxdist)
767 //navigation_testtracewalk = true;
770 IL_EACH(g_waypoints, !it.wpconsidered,
772 SET_TRACEWALK_DESTCOORDS(it, this.origin, v, v_height);
774 vector diff = v - this.origin;
775 diff.z = max(0, diff.z);
776 if(vdist(diff, <, maxdist))
778 it.wpconsidered = true;
779 if (tracewalk(this, this.origin, this.mins, this.maxs, v, v_height, bot_navigation_movemode))
781 it.wpnearestpoint = v;
782 it.wpcost = waypoint_gettravelcost(this.origin, v, SUBMERGED(this.origin), SUBMERGED(v)) + it.dmg;
789 //navigation_testtracewalk = false;
793 // updates a path link if a spawnfunc_waypoint link is better than the current one
794 void navigation_markroutes_checkwaypoint(entity w, entity wp, float cost, vector p)
800 m1 = wp.origin + wp.mins;
801 m2 = wp.origin + wp.maxs;
802 v.x = bound(m1_x, p.x, m2_x);
803 v.y = bound(m1_y, p.y, m2_y);
804 v.z = bound(m1_z, p.z, m2_z);
808 if (w.wpflags & WAYPOINTFLAG_TELEPORT)
809 cost += w.wp00mincost; // assuming teleport has exactly one destination
811 cost += waypoint_gettravelcost(p, v, SUBMERGED(p), SUBMERGED(v));
812 if (wp.wpcost > cost)
817 wp.wpnearestpoint = v;
821 // queries the entire spawnfunc_waypoint network for pathes leading away from the bot
822 void navigation_markroutes(entity this, entity fixed_source_waypoint)
827 IL_EACH(g_waypoints, true,
829 it.wpconsidered = false;
830 it.wpnearestpoint = '0 0 0';
831 it.wpcost = 10000000;
836 if(fixed_source_waypoint)
838 fixed_source_waypoint.wpconsidered = true;
839 fixed_source_waypoint.wpnearestpoint = fixed_source_waypoint.origin + 0.5 * (fixed_source_waypoint.mins + fixed_source_waypoint.maxs);
840 fixed_source_waypoint.wpcost = fixed_source_waypoint.dmg;
841 fixed_source_waypoint.wpfire = 1;
842 fixed_source_waypoint.enemy = NULL;
846 // try a short range search for the nearest waypoints, and expand the search repeatedly if none are found
847 // as this search is expensive we will use lower values if the bot is on the air
848 float increment, maxdistance;
849 if(IS_ONGROUND(this))
860 for(int j = increment; !navigation_markroutes_nearestwaypoints(this, j) && j < maxdistance; j += increment);
863 bool searching = true;
867 IL_EACH(g_waypoints, it.wpfire,
872 p = it.wpnearestpoint;
874 wp = it.wp00;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp00mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
875 wp = it.wp01;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp01mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
876 wp = it.wp02;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp02mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
877 wp = it.wp03;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp03mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
878 wp = it.wp04;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp04mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
879 wp = it.wp05;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp05mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
880 wp = it.wp06;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp06mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
881 wp = it.wp07;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp07mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
882 wp = it.wp08;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp08mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
883 wp = it.wp09;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp09mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
884 wp = it.wp10;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp10mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
885 wp = it.wp11;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp11mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
886 wp = it.wp12;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp12mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
887 wp = it.wp13;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp13mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
888 wp = it.wp14;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp14mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
889 wp = it.wp15;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp15mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
890 wp = it.wp16;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp16mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
891 wp = it.wp17;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp17mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
892 wp = it.wp18;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp18mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
893 wp = it.wp19;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp19mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
894 wp = it.wp20;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp20mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
895 wp = it.wp21;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp21mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
896 wp = it.wp22;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp22mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
897 wp = it.wp23;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp23mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
898 wp = it.wp24;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp24mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
899 wp = it.wp25;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp25mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
900 wp = it.wp26;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp26mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
901 wp = it.wp27;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp27mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
902 wp = it.wp28;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp28mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
903 wp = it.wp29;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp29mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
904 wp = it.wp30;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp30mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
905 wp = it.wp31;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp31mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
906 }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
911 // queries the entire spawnfunc_waypoint network for pathes leading to the bot
912 void navigation_markroutes_inverted(entity fixed_source_waypoint)
916 IL_EACH(g_waypoints, true,
918 it.wpconsidered = false;
919 it.wpnearestpoint = '0 0 0';
920 it.wpcost = 10000000;
925 if(fixed_source_waypoint)
927 fixed_source_waypoint.wpconsidered = true;
928 fixed_source_waypoint.wpnearestpoint = fixed_source_waypoint.origin + 0.5 * (fixed_source_waypoint.mins + fixed_source_waypoint.maxs);
929 fixed_source_waypoint.wpcost = fixed_source_waypoint.dmg; // the cost to get from X to fixed_source_waypoint
930 fixed_source_waypoint.wpfire = 1;
931 fixed_source_waypoint.enemy = NULL;
935 error("need to start with a waypoint\n");
938 bool searching = true;
942 IL_EACH(g_waypoints, it.wpfire,
946 cost = it.wpcost; // cost to walk from it to home
947 p = it.wpnearestpoint;
949 IL_EACH(g_waypoints, it != wp,
951 if(!waypoint_islinked(it, wp))
953 cost2 = cost + it.dmg;
954 navigation_markroutes_checkwaypoint(wp, it, cost2, p);
960 // updates the best goal according to a weighted calculation of travel cost and item value of a new proposed item
961 void navigation_routerating(entity this, entity e, float f, float rangebias)
969 rangebias = waypoint_getlinearcost(rangebias);
970 f = waypoint_getlinearcost(f);
974 bool rate_wps = false;
975 if((e.flags & FL_INWATER) || (e.flags & FL_PARTIALGROUND))
980 traceline(e.origin, e.origin + '0 0 -1500', true, NULL);
981 int t = pointcontents(trace_endpos + '0 0 1');
982 if(t != CONTENT_SOLID )
984 if(t == CONTENT_WATER || t == CONTENT_SLIME || t == CONTENT_LAVA)
986 else if(tracebox_hits_trigger_hurt(e.origin, e.mins, e.maxs, trace_endpos))
994 entity best_wp = NULL;
995 float best_dist = 10000;
996 IL_EACH(g_waypoints, vdist(it.origin - theEnemy.origin, <, 500)
997 && vdist(it.origin - this.origin, >, 100)
998 && !(it.wpflags & WAYPOINTFLAG_TELEPORT),
1000 float dist = vlen(it.origin - theEnemy.origin);
1001 if (dist < best_dist)
1013 vector goal_org = (e.absmin + e.absmax) * 0.5;
1015 //print("routerating ", etos(e), " = ", ftos(f), " - ", ftos(rangebias), "\n");
1017 // Evaluate path using jetpack
1019 if(this.items & IT_JETPACK)
1020 if(autocvar_bot_ai_navigation_jetpack)
1021 if(vdist(this.origin - goal_org, >, autocvar_bot_ai_navigation_jetpack_mindistance))
1023 vector pointa, pointb;
1025 LOG_DEBUG("jetpack ai: evaluating path for ", e.classname);
1028 traceline(this.origin, this.origin + '0 0 65535', MOVE_NORMAL, this);
1029 pointa = trace_endpos - '0 0 1';
1032 traceline(goal_org, goal_org + '0 0 65535', MOVE_NORMAL, e);
1033 pointb = trace_endpos - '0 0 1';
1035 // Can I see these two points from the sky?
1036 traceline(pointa, pointb, MOVE_NORMAL, this);
1038 if(trace_fraction==1)
1040 LOG_DEBUG("jetpack ai: can bridge these two points");
1042 // Lower the altitude of these points as much as possible
1043 float zdistance, xydistance, cost, t, fuel;
1044 vector down, npa, npb;
1046 down = '0 0 -1' * (STAT(PL_MAX, this).z - STAT(PL_MIN, this).z) * 10;
1049 npa = pointa + down;
1050 npb = pointb + down;
1052 if(npa.z<=this.absmax.z)
1055 if(npb.z<=e.absmax.z)
1058 traceline(npa, npb, MOVE_NORMAL, this);
1059 if(trace_fraction==1)
1065 while(trace_fraction == 1);
1068 // Rough estimation of fuel consumption
1069 // (ignores acceleration and current xyz velocity)
1070 xydistance = vlen(pointa - pointb);
1071 zdistance = fabs(pointa.z - this.origin.z);
1073 t = zdistance / autocvar_g_jetpack_maxspeed_up;
1074 t += xydistance / autocvar_g_jetpack_maxspeed_side;
1075 fuel = t * autocvar_g_jetpack_fuel * 0.8;
1077 LOG_DEBUG("jetpack ai: required fuel ", ftos(fuel), " this.ammo_fuel ", ftos(this.ammo_fuel));
1080 if(this.ammo_fuel>fuel)
1083 // (as onground costs calculation is mostly based on distances, here we do the same establishing some relationship
1084 // - between air and ground speeds)
1086 cost = xydistance / (autocvar_g_jetpack_maxspeed_side/autocvar_sv_maxspeed);
1087 cost += zdistance / (autocvar_g_jetpack_maxspeed_up/autocvar_sv_maxspeed);
1090 // Compare against other goals
1091 f = f * rangebias / (rangebias + cost);
1093 if (navigation_bestrating < f)
1095 LOG_DEBUG("jetpack path: added goal ", e.classname, " (with rating ", ftos(f), ")");
1096 navigation_bestrating = f;
1097 navigation_bestgoal = e;
1098 this.navigation_jetpack_goal = e;
1099 this.navigation_jetpack_point = pointb;
1107 //te_wizspike(e.origin);
1110 // update the cached spawnfunc_waypoint link on a dynamic item entity
1111 if(e.classname == "waypoint" && !(e.wpflags & WAYPOINTFLAG_PERSONAL))
1117 if(autocvar_g_waypointeditor && e.nearestwaypointtimeout >= 0 && time > e.nearestwaypointtimeout)
1118 e.nearestwaypoint = NULL;
1120 if ((!e.nearestwaypoint || e.navigation_dynamicgoal)
1121 && e.nearestwaypointtimeout >= 0 && time > e.nearestwaypointtimeout)
1123 nwp = navigation_findnearestwaypoint(e, true);
1126 e.nearestwaypoint = nwp;
1128 vector m1 = nwp.absmin, m2 = nwp.absmax;
1129 m1.x = nwp.origin.x; m1.y = nwp.origin.y;
1130 m2.x = nwp.origin.x; m2.y = nwp.origin.y;
1131 vector ve = (e.absmin - e.absmax) * 0.5;
1132 ve.x = bound(m1.x, ve.x, m2.x);
1133 ve.y = bound(m1.y, ve.y, m2.y);
1134 ve.z = bound(m1.z, ve.z, m2.z);
1136 m1 = e.absmin; m2 = e.absmax;
1137 m1.x = e.origin.x; m1.y = e.origin.y;
1138 m2.x = e.origin.x; m2.y = e.origin.y;
1139 vector vnwp = nwp.origin;
1140 vnwp.x = bound(m1.x, vnwp.x, m2.x);
1141 vnwp.y = bound(m1.y, vnwp.y, m2.y);
1142 vnwp.z = bound(m1.z, vnwp.z, m2.z);
1143 e.nearestwaypoint_dist = vlen(ve - vnwp);
1147 LOG_DEBUG("FAILED to find a nearest waypoint to '", e.classname, "' #", etos(e));
1149 if(!e.navigation_dynamicgoal)
1150 e.blacklisted = true;
1154 LOG_DEBUG("The entity '", e.classname, "' is going to be excluded from path finding during this match");
1159 if(e.navigation_dynamicgoal)
1160 e.nearestwaypointtimeout = time + 2;
1161 else if(autocvar_g_waypointeditor)
1162 e.nearestwaypointtimeout = time + 3 + random() * 2;
1164 nwp = e.nearestwaypoint;
1167 LOG_DEBUG("-- checking ", e.classname, " (with cost ", ftos(nwp.wpcost), ")");
1169 if (nwp.wpcost < 10000000)
1171 //te_wizspike(nwp.wpnearestpoint);
1172 float cost = nwp.wpcost + waypoint_gettravelcost(nwp.wpnearestpoint, goal_org, SUBMERGED(nwp.wpnearestpoint), SUBMERGED(goal_org));
1173 LOG_DEBUG(e.classname, " ", ftos(f), "/(1+", ftos(cost), "/", ftos(rangebias), ") = ");
1174 f = f * rangebias / (rangebias + cost);
1175 LOG_DEBUG("considering ", e.classname, " (with rating ", ftos(f), ")");
1176 if (navigation_bestrating < f)
1178 LOG_DEBUG("ground path: added goal ", e.classname, " (with rating ", ftos(f), ")");
1179 navigation_bestrating = f;
1180 navigation_bestgoal = e;
1185 // adds an item to the the goal stack with the path to a given item
1186 bool navigation_routetogoal(entity this, entity e, vector startposition)
1188 // if there is no goal, just exit
1192 if(e.wpflags & WAYPOINTFLAG_TELEPORT)
1194 // force teleport destination as route destination
1199 this.goalentity = e;
1201 // put the entity on the goal stack
1202 //print("routetogoal ", etos(e), "\n");
1203 navigation_pushroute(this, e);
1205 if(e.classname == "waypoint" && !(e.wpflags & WAYPOINTFLAG_PERSONAL))
1207 this.wp_goal_prev1 = this.wp_goal_prev0;
1208 this.wp_goal_prev0 = e;
1212 if(e==this.navigation_jetpack_goal)
1215 // if it can reach the goal there is nothing more to do
1216 vector dest = (e.absmin + e.absmax) * 0.5;
1217 dest.z = e.absmin.z;
1218 float dest_height = e.absmax.z - e.absmin.z;
1219 if (tracewalk(this, startposition, STAT(PL_MIN, this), STAT(PL_MAX, this), dest, dest_height, bot_navigation_movemode))
1222 entity nearest_wp = NULL;
1223 // see if there are waypoints describing a path to the item
1224 if(e.classname != "waypoint" || (e.wpflags & WAYPOINTFLAG_PERSONAL))
1226 e = e.nearestwaypoint;
1230 e = e.enemy; // we already have added it, so...
1235 if(nearest_wp && nearest_wp.enemy)
1237 // often path can be optimized by not adding the nearest waypoint
1238 if (this.goalentity.nearestwaypoint_dist < 8)
1239 e = nearest_wp.enemy;
1242 if (this.goalentity.navigation_dynamicgoal)
1244 vector dest = (this.goalentity.absmin + this.goalentity.absmax) * 0.5;
1245 dest.z = this.goalentity.absmin.z;
1246 float dest_height = this.goalentity.absmax.z - this.goalentity.absmin.z;
1247 if(tracewalk(this, nearest_wp.enemy.origin, STAT(PL_MIN, this), STAT(PL_MAX, this), dest, dest_height, bot_navigation_movemode))
1248 e = nearest_wp.enemy;
1250 else if(navigation_item_islinked(nearest_wp.enemy, this.goalentity))
1251 e = nearest_wp.enemy;
1257 // add the spawnfunc_waypoint to the path
1258 navigation_pushroute(this, e);
1268 // removes any currently touching waypoints from the goal stack
1269 // (this is how bots detect if they reached a goal)
1270 void navigation_poptouchedgoals(entity this)
1272 if(this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT)
1274 // make sure jumppad is really hit, don't rely on distance based checks
1275 // as they may report a touch even if it didn't really happen
1276 if(this.lastteleporttime > 0
1277 && time - this.lastteleporttime < ((this.goalcurrent.wpflags & WAYPOINTFLAG_PERSONAL) ? 2 : 0.15))
1279 if(this.aistatus & AI_STATUS_WAYPOINT_PERSONAL_GOING)
1280 if(this.goalcurrent.wpflags & WAYPOINTFLAG_PERSONAL && this.goalcurrent.owner==this)
1282 this.aistatus &= ~AI_STATUS_WAYPOINT_PERSONAL_GOING;
1283 this.aistatus |= AI_STATUS_WAYPOINT_PERSONAL_REACHED;
1285 navigation_poproute(this);
1291 // If for some reason the bot is closer to the next goal, pop the current one
1292 if(this.goalstack01 && !wasfreed(this.goalstack01))
1293 if(vlen2(this.goalcurrent.origin - this.origin) > vlen2(this.goalstack01.origin - this.origin))
1294 if(checkpvs(this.origin + this.view_ofs, this.goalstack01))
1296 vector dest = (this.goalstack01.absmin + this.goalstack01.absmax) * 0.5;
1297 dest.z = this.goalstack01.absmin.z;
1298 float dest_height = this.goalstack01.absmax.z - this.goalstack01.absmin.z;
1299 if(tracewalk(this, this.origin, this.mins, this.maxs, dest, dest_height, bot_navigation_movemode))
1301 LOG_DEBUG("path optimized for ", this.netname, ", removed a goal from the queue");
1302 navigation_poproute(this);
1303 // TODO this may also be a nice idea to do "early" (e.g. by
1304 // manipulating the vlen() comparisons) to shorten paths in
1305 // general - this would make bots walk more "on rails" than
1306 // "zigzagging" which they currently do with sufficiently
1307 // random-like waypoints, and thus can make a nice bot
1308 // personality property
1312 // Loose goal touching check when running
1313 if(this.aistatus & AI_STATUS_RUNNING)
1314 if(this.goalcurrent.classname=="waypoint")
1315 if(vdist(vec2(this.velocity), >=, autocvar_sv_maxspeed)) // if -really- running
1317 if(vdist(this.origin - this.goalcurrent.origin, <, 150))
1319 traceline(this.origin + this.view_ofs , this.goalcurrent.origin, true, NULL);
1320 if(trace_fraction==1)
1322 // Detect personal waypoints
1323 if(this.aistatus & AI_STATUS_WAYPOINT_PERSONAL_GOING)
1324 if(this.goalcurrent.wpflags & WAYPOINTFLAG_PERSONAL && this.goalcurrent.owner==this)
1326 this.aistatus &= ~AI_STATUS_WAYPOINT_PERSONAL_GOING;
1327 this.aistatus |= AI_STATUS_WAYPOINT_PERSONAL_REACHED;
1330 navigation_poproute(this);
1335 while (this.goalcurrent && !IS_PLAYER(this.goalcurrent))
1337 vector gc_min = this.goalcurrent.absmin;
1338 vector gc_max = this.goalcurrent.absmax;
1339 if(this.goalcurrent.classname == "waypoint" && !this.goalcurrent.wpisbox)
1341 gc_min = this.goalcurrent.origin - '1 1 1' * 12;
1342 gc_max = this.goalcurrent.origin + '1 1 1' * 12;
1344 if(!boxesoverlap(this.absmin, this.absmax, gc_min, gc_max))
1347 // Detect personal waypoints
1348 if(this.aistatus & AI_STATUS_WAYPOINT_PERSONAL_GOING)
1349 if(this.goalcurrent.wpflags & WAYPOINTFLAG_PERSONAL && this.goalcurrent.owner==this)
1351 this.aistatus &= ~AI_STATUS_WAYPOINT_PERSONAL_GOING;
1352 this.aistatus |= AI_STATUS_WAYPOINT_PERSONAL_REACHED;
1355 navigation_poproute(this);
1359 // begin a goal selection session (queries spawnfunc_waypoint network)
1360 void navigation_goalrating_start(entity this)
1362 if(this.aistatus & AI_STATUS_STUCK)
1365 this.navigation_jetpack_goal = NULL;
1366 navigation_bestrating = -1;
1367 navigation_clearroute(this);
1368 navigation_bestgoal = NULL;
1369 navigation_markroutes(this, NULL);
1372 // ends a goal selection session (updates goal stack to the best goal)
1373 void navigation_goalrating_end(entity this)
1375 if(this.aistatus & AI_STATUS_STUCK)
1378 navigation_routetogoal(this, navigation_bestgoal, this.origin);
1379 LOG_DEBUG("best goal ", this.goalcurrent.classname);
1381 // If the bot got stuck then try to reach the farthest waypoint
1382 if (!this.goalentity && autocvar_bot_wander_enable)
1384 if (!(this.aistatus & AI_STATUS_STUCK))
1386 LOG_DEBUG(this.netname, " cannot walk to any goal");
1387 this.aistatus |= AI_STATUS_STUCK;
1392 void botframe_updatedangerousobjects(float maxupdate)
1394 vector m1, m2, v, o;
1397 IL_EACH(g_waypoints, true,
1402 IL_EACH(g_bot_dodge, it.bot_dodge,
1405 v.x = bound(m1_x, v.x, m2_x);
1406 v.y = bound(m1_y, v.y, m2_y);
1407 v.z = bound(m1_z, v.z, m2_z);
1408 o = (it.absmin + it.absmax) * 0.5;
1409 d = waypoint_getlinearcost(it.bot_dodgerating) - waypoint_gettravelcost(o, v, SUBMERGED(o), SUBMERGED(v));
1412 traceline(o, v, true, NULL);
1413 if (trace_fraction == 1)
1414 danger = danger + d;
1424 void navigation_unstuck(entity this)
1426 float search_radius = 1000;
1428 if (!autocvar_bot_wander_enable)
1431 if (!bot_waypoint_queue_owner)
1433 LOG_DEBUG(this.netname, " stuck, taking over the waypoints queue");
1434 bot_waypoint_queue_owner = this;
1435 bot_waypoint_queue_bestgoal = NULL;
1436 bot_waypoint_queue_bestgoalrating = 0;
1439 if(bot_waypoint_queue_owner!=this)
1442 if (bot_waypoint_queue_goal)
1444 // evaluate the next goal on the queue
1445 float d = vlen2(this.origin - bot_waypoint_queue_goal.origin);
1446 LOG_DEBUG(this.netname, " evaluating ", bot_waypoint_queue_goal.classname, " with distance ", ftos(d));
1447 vector dest = (bot_waypoint_queue_goal.absmin + bot_waypoint_queue_goal.absmax) * 0.5;
1448 dest.z = bot_waypoint_queue_goal.absmin.z;
1449 float dest_height = bot_waypoint_queue_goal.absmax.z - bot_waypoint_queue_goal.absmin.z;
1450 if(tracewalk(bot_waypoint_queue_goal, this.origin, STAT(PL_MIN, this), STAT(PL_MAX, this), dest, dest_height, bot_navigation_movemode))
1452 if( d > bot_waypoint_queue_bestgoalrating)
1454 bot_waypoint_queue_bestgoalrating = d;
1455 bot_waypoint_queue_bestgoal = bot_waypoint_queue_goal;
1458 bot_waypoint_queue_goal = bot_waypoint_queue_goal.bot_waypoint_queue_nextgoal;
1460 if (!bot_waypoint_queue_goal)
1462 if (bot_waypoint_queue_bestgoal)
1464 LOG_DEBUG(this.netname, " stuck, reachable waypoint found, heading to it");
1465 navigation_routetogoal(this, bot_waypoint_queue_bestgoal, this.origin);
1466 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
1467 this.aistatus &= ~AI_STATUS_STUCK;
1471 LOG_DEBUG(this.netname, " stuck, cannot walk to any waypoint at all");
1474 bot_waypoint_queue_owner = NULL;
1479 if(bot_strategytoken!=this)
1482 // build a new queue
1483 LOG_DEBUG(this.netname, " stuck, scanning reachable waypoints within ", ftos(search_radius)," qu");
1485 entity first = NULL;
1487 FOREACH_ENTITY_RADIUS(this.origin, search_radius, it.classname == "waypoint" && !(it.wpflags & WAYPOINTFLAG_GENERATED),
1489 if(bot_waypoint_queue_goal)
1490 bot_waypoint_queue_goal.bot_waypoint_queue_nextgoal = it;
1494 bot_waypoint_queue_goal = it;
1495 bot_waypoint_queue_goal.bot_waypoint_queue_nextgoal = NULL;
1499 bot_waypoint_queue_goal = first;
1502 LOG_DEBUG(this.netname, " stuck, cannot walk to any waypoint at all");
1503 bot_waypoint_queue_owner = NULL;
1508 // Support for debugging tracewalk visually
1510 void debugresetnodes()
1512 debuglastnode = '0 0 0';
1515 void debugnode(entity this, vector node)
1517 if (!IS_PLAYER(this))
1520 if(debuglastnode=='0 0 0')
1522 debuglastnode = node;
1526 te_lightning2(NULL, node, debuglastnode);
1527 debuglastnode = node;
1530 void debugnodestatus(vector position, float status)
1536 case DEBUG_NODE_SUCCESS:
1539 case DEBUG_NODE_WARNING:
1542 case DEBUG_NODE_FAIL:
1549 te_customflash(position, 40, 2, c);
1552 // Support for debugging the goal stack visually
1555 .vector lastposition;
1557 // Debug the goal stack visually
1558 void debuggoalstack(entity this)
1563 if(this.goalcounter==0)goal=this.goalcurrent;
1564 else if(this.goalcounter==1)goal=this.goalstack01;
1565 else if(this.goalcounter==2)goal=this.goalstack02;
1566 else if(this.goalcounter==3)goal=this.goalstack03;
1567 else if(this.goalcounter==4)goal=this.goalstack04;
1568 else if(this.goalcounter==5)goal=this.goalstack05;
1569 else if(this.goalcounter==6)goal=this.goalstack06;
1570 else if(this.goalcounter==7)goal=this.goalstack07;
1571 else if(this.goalcounter==8)goal=this.goalstack08;
1572 else if(this.goalcounter==9)goal=this.goalstack09;
1573 else if(this.goalcounter==10)goal=this.goalstack10;
1574 else if(this.goalcounter==11)goal=this.goalstack11;
1575 else if(this.goalcounter==12)goal=this.goalstack12;
1576 else if(this.goalcounter==13)goal=this.goalstack13;
1577 else if(this.goalcounter==14)goal=this.goalstack14;
1578 else if(this.goalcounter==15)goal=this.goalstack15;
1579 else if(this.goalcounter==16)goal=this.goalstack16;
1580 else if(this.goalcounter==17)goal=this.goalstack17;
1581 else if(this.goalcounter==18)goal=this.goalstack18;
1582 else if(this.goalcounter==19)goal=this.goalstack19;
1583 else if(this.goalcounter==20)goal=this.goalstack20;
1584 else if(this.goalcounter==21)goal=this.goalstack21;
1585 else if(this.goalcounter==22)goal=this.goalstack22;
1586 else if(this.goalcounter==23)goal=this.goalstack23;
1587 else if(this.goalcounter==24)goal=this.goalstack24;
1588 else if(this.goalcounter==25)goal=this.goalstack25;
1589 else if(this.goalcounter==26)goal=this.goalstack26;
1590 else if(this.goalcounter==27)goal=this.goalstack27;
1591 else if(this.goalcounter==28)goal=this.goalstack28;
1592 else if(this.goalcounter==29)goal=this.goalstack29;
1593 else if(this.goalcounter==30)goal=this.goalstack30;
1594 else if(this.goalcounter==31)goal=this.goalstack31;
1599 this.goalcounter = 0;
1600 this.lastposition='0 0 0';
1604 if(this.lastposition=='0 0 0')
1607 org = this.lastposition;
1610 go = ( goal.absmin + goal.absmax ) * 0.5;
1611 te_lightning2(NULL, org, go);
1612 this.lastposition = go;