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 #define IN_LAVA(pos) (cont = pointcontents(pos), (cont == CONTENT_LAVA || cont == CONTENT_SLIME))
59 #define IN_LIQUID(pos) (cont = pointcontents(pos), (cont == CONTENT_WATER || cont == CONTENT_LAVA || cont == CONTENT_SLIME))
60 #define SUBMERGED(pos) IN_LIQUID(pos + autocvar_sv_player_viewoffset)
61 #define WETFEET(pos) IN_LIQUID(pos + eZ * (m1.z + 1))
63 vector resurface_limited(vector org, float lim, vector m1)
66 if (WETFEET(org + eZ * (lim - org.z)))
70 float RES_min_h = org.z;
71 float RES_max_h = lim;
73 org.z = 0.5 * (RES_min_h + RES_max_h);
78 } while (RES_max_h - RES_min_h >= 1);
83 #define RESURFACE_LIMITED(org, lim) org = resurface_limited(org, lim, m1)
86 #define NAV_SWIM_ONWATER 1
87 #define NAV_SWIM_UNDERWATER 2
89 // rough simulation of walking from one point to another to test if a path
90 // can be traveled, used for waypoint linking and havocbot
91 // if end_height is > 0 destination is any point in the vertical segment [end, end + end_height * eZ]
92 bool tracewalk(entity e, vector start, vector m1, vector m2, vector end, float end_height, float movemode)
94 if(autocvar_bot_debug_tracewalk)
101 vector flatdir = end - start;
103 float flatdist = vlen(flatdir);
104 flatdir = normalize(flatdir);
106 bool ignorehazards = false;
110 // Analyze starting point
111 traceline(start, start, MOVE_NORMAL, e);
112 if (trace_dpstartcontents & (DPCONTENTS_SLIME | DPCONTENTS_LAVA))
113 ignorehazards = true;
115 tracebox(start, m1, m2, start, MOVE_NOMONSTERS, e);
116 if (trace_startsolid)
119 if(autocvar_bot_debug_tracewalk)
120 debugnodestatus(start, DEBUG_NODE_FAIL);
122 //print("tracewalk: ", vtos(start), " is a bad start\n");
128 end2.z += end_height;
130 vector fixed_end = end;
133 if (flatdist > 0 && WETFEET(org))
136 nav_action = NAV_SWIM_UNDERWATER;
139 // tracebox down by player's height
140 // useful to know if water level is so low that bot can still walk
141 tracebox(org, m1, m2, org - eZ * (m2.z - m1.z), movemode, e);
142 if (SUBMERGED(trace_endpos))
145 nav_action = NAV_SWIM_UNDERWATER;
148 nav_action = NAV_WALK;
152 nav_action = NAV_WALK;
160 if (org.z > end2.z + 1)
162 tracebox(org, m1, m2, end2, movemode, e);
164 if (org.z > end2.z + 1)
167 else if (org.z < end.z - 1)
169 tracebox(org, m1, m2, org - jumpheight_vec, movemode, e);
170 if (SUBMERGED(trace_endpos))
171 RESURFACE_LIMITED(trace_endpos, end.z);
172 else if (trace_endpos.z > org.z - jumpheight_vec.z)
173 tracebox(trace_endpos, m1, m2, trace_endpos + jumpheight_vec, movemode, e);
175 if (org.z < end.z - 1)
182 if(autocvar_bot_debug_tracewalk)
185 debugnodestatus(org, DEBUG_NODE_SUCCESS);
188 //print("tracewalk: ", vtos(start), " can reach ", vtos(end), "\n");
193 if(autocvar_bot_debug_tracewalk)
199 if(nav_action == NAV_SWIM_UNDERWATER || (nav_action == NAV_SWIM_ONWATER && org.z > end2.z))
201 // can't use movement direction here to calculate move because of
202 // precision errors especially when direction has a high enough z value
203 //water_dir = normalize(water_end - org);
204 //move = org + water_dir * stepdist;
205 fixed_end.z = bound(end.z, org.z, end2.z);
206 if (stepdist > flatdist)
208 if (stepdist == flatdist) {
212 move = org + (fixed_end - org) * (stepdist / flatdist);
213 flatdist = vlen(vec2(fixed_end - move));
216 else // horiz. direction
218 if (stepdist > flatdist)
220 flatdist -= stepdist;
221 move = org + flatdir * stepdist;
224 if(nav_action == NAV_SWIM_ONWATER)
226 tracebox(org, m1, m2, move, movemode, e); // swim
229 if (trace_fraction < 1)
232 tracebox(org + stepheightvec, m1, m2, move + stepheightvec, movemode, e);
234 if (trace_fraction < 1 || trace_startsolid) // can't jump obstacle out of water
236 if(navigation_checkladders(e, trace_endpos, m1, m2, end, end2, movemode))
238 if(autocvar_bot_debug_tracewalk)
240 debugnode(e, trace_endpos);
241 debugnodestatus(trace_endpos, DEBUG_NODE_SUCCESS);
244 //print("tracewalk: ", vtos(start), " can reach ", vtos(end), "\n");
248 if(autocvar_bot_debug_tracewalk)
249 debugnodestatus(trace_endpos, DEBUG_NODE_FAIL);
252 //print("tracewalk: ", vtos(start), " hit something when trying to reach ", vtos(end), "\n");
263 if (org.z <= move.z) // going horiz.
265 tracebox(trace_endpos, m1, m2, move, movemode, e);
267 nav_action = NAV_WALK;
272 if (org.z <= move.z) // going horiz.
275 nav_action = NAV_SWIM_ONWATER;
281 nav_action = NAV_SWIM_UNDERWATER;
283 nav_action = NAV_SWIM_ONWATER;
286 else if(nav_action == NAV_SWIM_UNDERWATER)
288 if (move.z >= org.z) // swimming upwards or horiz.
290 tracebox(org, m1, m2, move, movemode, e); // swim
292 bool stepswimmed = false;
295 if (trace_fraction < 1)
298 vector stepswim_move = move + stepheightvec;
299 if (flatdist > 0 && stepswim_move.z > end2.z) // don't allow stepswim to go higher than destination
300 stepswim_move.z = end2.z;
302 tracebox(org + stepheightvec, m1, m2, stepswim_move, movemode, e);
305 if (trace_startsolid)
307 if(autocvar_bot_debug_tracewalk)
308 debugnodestatus(org, DEBUG_NODE_FAIL);
310 //print("tracewalk: ", vtos(start), " hit something when trying to reach ", vtos(end), "\n");
314 if (trace_fraction < 1)
316 float org_z_prev = org.z;
317 RESURFACE_LIMITED(org, end2.z);
318 if(org.z == org_z_prev)
320 if(autocvar_bot_debug_tracewalk)
321 debugnodestatus(org, DEBUG_NODE_FAIL);
323 //print("tracewalk: ", vtos(start), " can't reach ", vtos(end), "\n");
327 nav_action = NAV_SWIM_UNDERWATER;
329 nav_action = NAV_SWIM_ONWATER;
331 // we didn't advance horiz. in this step, flatdist decrease should be reverted
332 // but we can do it properly right now... apply this workaround instead
350 if (!WETFEET(trace_endpos))
352 tracebox(trace_endpos, m1, m2, trace_endpos - eZ * (stepdist + (m2.z - m1.z)), movemode, e);
353 // if stepswimmed we'll land on the obstacle, avoid the SUBMERGED check
354 if (!stepswimmed && SUBMERGED(trace_endpos))
356 RESURFACE_LIMITED(trace_endpos, end2.z);
358 nav_action = NAV_SWIM_ONWATER;
364 nav_action = NAV_WALK;
370 nav_action = NAV_SWIM_UNDERWATER;
373 else //if (move.z < org.z) // swimming downwards
375 tracebox(org, m1, m2, move, movemode, e); // swim
378 if (trace_fraction < 1)
381 tracebox(org + stepheightvec, m1, m2, move + stepheightvec, movemode, e);
384 if (trace_fraction < 1 || trace_startsolid) // can't jump obstacle out of water
386 if(autocvar_bot_debug_tracewalk)
387 debugnodestatus(move, DEBUG_NODE_FAIL);
389 //print("tracewalk: ", vtos(start), " hit something when trying to reach ", vtos(end), "\n");
401 if (trace_endpos.z > org.z && !SUBMERGED(trace_endpos))
403 // stepswim caused upwards direction
404 tracebox(trace_endpos, m1, m2, trace_endpos - stepheightvec, movemode, e);
405 if (!SUBMERGED(trace_endpos))
408 nav_action = NAV_WALK;
415 nav_action = NAV_SWIM_UNDERWATER;
419 else if(nav_action == NAV_WALK)
422 tracebox(org, m1, m2, move, movemode, e);
424 if(autocvar_bot_debug_tracewalk)
425 debugnode(e, trace_endpos);
428 if (trace_fraction < 1)
430 // check if we can walk over this obstacle, possibly by jumpstepping
431 tracebox(org + stepheightvec, m1, m2, move + stepheightvec, movemode, e);
432 if (trace_fraction < 1 || trace_startsolid)
434 tracebox(org + jumpstepheightvec, m1, m2, move + jumpstepheightvec, movemode, e);
435 if (trace_fraction < 1 || trace_startsolid)
437 vector v = trace_endpos - jumpstepheightvec + jumpheight_vec;
438 if(navigation_checkladders(e, v, m1, m2, end, end2, movemode))
440 if(autocvar_bot_debug_tracewalk)
443 debugnodestatus(v, DEBUG_NODE_SUCCESS);
446 //print("tracewalk: ", vtos(start), " can reach ", vtos(end), "\n");
450 if(autocvar_bot_debug_tracewalk)
451 debugnodestatus(trace_endpos, DEBUG_NODE_WARNING);
453 traceline( org, move, movemode, e);
455 if ( trace_ent.classname == "door_rotating" || trace_ent.classname == "door")
459 while(trace_ent.classname == "door_rotating" || trace_ent.classname == "door")
461 nextmove = move + (flatdir * stepdist);
462 traceline( move, nextmove, movemode, e);
465 flatdist = vlen(vec2(end - move));
469 if(autocvar_bot_debug_tracewalk)
470 debugnodestatus(trace_endpos, DEBUG_NODE_FAIL);
472 //print("tracewalk: ", vtos(start), " hit something when trying to reach ", vtos(end), "\n");
473 //te_explosion(trace_endpos);
474 //print(ftos(e.dphitcontentsmask), "\n");
475 return false; // failed
493 // trace down from stepheight as far as possible and move there,
494 // if this starts in solid we try again without the stepup, and
495 // if that also fails we assume it is a wall
496 // (this is the same logic as the Quake walkmove function used)
497 tracebox(move, m1, m2, move + '0 0 -65536', movemode, e);
505 if(autocvar_bot_debug_tracewalk)
507 debugnode(e, trace_endpos);
508 debugnodestatus(org, DEBUG_NODE_FAIL);
511 //print("tracewalk: ", vtos(start), " hits a hazard when trying to reach ", vtos(end), "\n");
516 if(org.z > move.z - 1 || !SUBMERGED(org))
518 nav_action = NAV_WALK;
522 // ended up submerged while walking
523 if(autocvar_bot_debug_tracewalk)
526 RESURFACE_LIMITED(org, move.z);
527 nav_action = NAV_SWIM_ONWATER;
532 //print("tracewalk: ", vtos(start), " did not arrive at ", vtos(end), " but at ", vtos(org), "\n");
534 // moved but didn't arrive at the intended destination
535 if(autocvar_bot_debug_tracewalk)
536 debugnodestatus(org, DEBUG_NODE_FAIL);
541 /////////////////////////////////////////////////////////////////////////////
543 /////////////////////////////////////////////////////////////////////////////
545 // completely empty the goal stack, used when deciding where to go
546 void navigation_clearroute(entity this)
548 this.goalcurrent_prev = this.goalcurrent;
549 this.goalcurrent_distance = 10000000;
550 this.goalcurrent_distance_time = 0;
551 //print("bot ", etos(this), " clear\n");
552 this.goalentity = NULL;
553 this.goalcurrent = NULL;
554 this.goalstack01 = NULL;
555 this.goalstack02 = NULL;
556 this.goalstack03 = NULL;
557 this.goalstack04 = NULL;
558 this.goalstack05 = NULL;
559 this.goalstack06 = NULL;
560 this.goalstack07 = NULL;
561 this.goalstack08 = NULL;
562 this.goalstack09 = NULL;
563 this.goalstack10 = NULL;
564 this.goalstack11 = NULL;
565 this.goalstack12 = NULL;
566 this.goalstack13 = NULL;
567 this.goalstack14 = NULL;
568 this.goalstack15 = NULL;
569 this.goalstack16 = NULL;
570 this.goalstack17 = NULL;
571 this.goalstack18 = NULL;
572 this.goalstack19 = NULL;
573 this.goalstack20 = NULL;
574 this.goalstack21 = NULL;
575 this.goalstack22 = NULL;
576 this.goalstack23 = NULL;
577 this.goalstack24 = NULL;
578 this.goalstack25 = NULL;
579 this.goalstack26 = NULL;
580 this.goalstack27 = NULL;
581 this.goalstack28 = NULL;
582 this.goalstack29 = NULL;
583 this.goalstack30 = NULL;
584 this.goalstack31 = NULL;
587 // add a new goal at the beginning of the stack
588 // (in other words: add a new prerequisite before going to the later goals)
589 // NOTE: when a waypoint is added, the WP gets pushed first, then the
590 // next-closest WP on the shortest path to the WP
591 // That means, if the stack overflows, the bot will know how to do the FIRST 32
592 // steps to the goal, and then recalculate the path.
593 void navigation_pushroute(entity this, entity e)
595 this.goalcurrent_prev = this.goalcurrent;
596 this.goalcurrent_distance = 10000000;
597 this.goalcurrent_distance_time = 0;
598 //print("bot ", etos(this), " push ", etos(e), "\n");
599 if(this.goalstack31 == this.goalentity)
600 this.goalentity = NULL;
601 this.goalstack31 = this.goalstack30;
602 this.goalstack30 = this.goalstack29;
603 this.goalstack29 = this.goalstack28;
604 this.goalstack28 = this.goalstack27;
605 this.goalstack27 = this.goalstack26;
606 this.goalstack26 = this.goalstack25;
607 this.goalstack25 = this.goalstack24;
608 this.goalstack24 = this.goalstack23;
609 this.goalstack23 = this.goalstack22;
610 this.goalstack22 = this.goalstack21;
611 this.goalstack21 = this.goalstack20;
612 this.goalstack20 = this.goalstack19;
613 this.goalstack19 = this.goalstack18;
614 this.goalstack18 = this.goalstack17;
615 this.goalstack17 = this.goalstack16;
616 this.goalstack16 = this.goalstack15;
617 this.goalstack15 = this.goalstack14;
618 this.goalstack14 = this.goalstack13;
619 this.goalstack13 = this.goalstack12;
620 this.goalstack12 = this.goalstack11;
621 this.goalstack11 = this.goalstack10;
622 this.goalstack10 = this.goalstack09;
623 this.goalstack09 = this.goalstack08;
624 this.goalstack08 = this.goalstack07;
625 this.goalstack07 = this.goalstack06;
626 this.goalstack06 = this.goalstack05;
627 this.goalstack05 = this.goalstack04;
628 this.goalstack04 = this.goalstack03;
629 this.goalstack03 = this.goalstack02;
630 this.goalstack02 = this.goalstack01;
631 this.goalstack01 = this.goalcurrent;
632 this.goalcurrent = e;
635 // remove first goal from stack
636 // (in other words: remove a prerequisite for reaching the later goals)
637 // (used when a spawnfunc_waypoint is reached)
638 void navigation_poproute(entity this)
640 this.goalcurrent_prev = this.goalcurrent;
641 this.goalcurrent_distance = 10000000;
642 this.goalcurrent_distance_time = 0;
643 //print("bot ", etos(this), " pop\n");
644 if(this.goalcurrent == this.goalentity)
645 this.goalentity = NULL;
646 this.goalcurrent = this.goalstack01;
647 this.goalstack01 = this.goalstack02;
648 this.goalstack02 = this.goalstack03;
649 this.goalstack03 = this.goalstack04;
650 this.goalstack04 = this.goalstack05;
651 this.goalstack05 = this.goalstack06;
652 this.goalstack06 = this.goalstack07;
653 this.goalstack07 = this.goalstack08;
654 this.goalstack08 = this.goalstack09;
655 this.goalstack09 = this.goalstack10;
656 this.goalstack10 = this.goalstack11;
657 this.goalstack11 = this.goalstack12;
658 this.goalstack12 = this.goalstack13;
659 this.goalstack13 = this.goalstack14;
660 this.goalstack14 = this.goalstack15;
661 this.goalstack15 = this.goalstack16;
662 this.goalstack16 = this.goalstack17;
663 this.goalstack17 = this.goalstack18;
664 this.goalstack18 = this.goalstack19;
665 this.goalstack19 = this.goalstack20;
666 this.goalstack20 = this.goalstack21;
667 this.goalstack21 = this.goalstack22;
668 this.goalstack22 = this.goalstack23;
669 this.goalstack23 = this.goalstack24;
670 this.goalstack24 = this.goalstack25;
671 this.goalstack25 = this.goalstack26;
672 this.goalstack26 = this.goalstack27;
673 this.goalstack27 = this.goalstack28;
674 this.goalstack28 = this.goalstack29;
675 this.goalstack29 = this.goalstack30;
676 this.goalstack30 = this.goalstack31;
677 this.goalstack31 = NULL;
680 // walking to wp (walkfromwp == false) v2 and v2_height will be used as
681 // waypoint destination coordinates instead of v (only useful for box waypoints)
682 // for normal waypoints v2 == v and v2_height == 0
683 float navigation_waypoint_will_link(vector v, vector org, entity ent, vector v2, float v2_height, float walkfromwp, float bestdist)
685 if (vdist(v - org, <, bestdist))
687 traceline(v, org, true, ent);
688 if (trace_fraction == 1)
692 if (tracewalk(ent, v, PL_MIN_CONST, PL_MAX_CONST, org, 0, bot_navigation_movemode))
697 if (tracewalk(ent, org, PL_MIN_CONST, PL_MAX_CONST, v2, v2_height, bot_navigation_movemode))
705 // find the spawnfunc_waypoint near a dynamic goal such as a dropped weapon
706 entity navigation_findnearestwaypoint_withdist_except(entity ent, float walkfromwp, float bestdist, entity except)
708 vector pm1 = ent.origin + ent.mins;
709 vector pm2 = ent.origin + ent.maxs;
711 // do two scans, because box test is cheaper
712 IL_EACH(g_waypoints, it != ent && it != except,
714 if(boxesoverlap(pm1, pm2, it.absmin, it.absmax))
718 vector org = ent.origin + 0.5 * (ent.mins + ent.maxs);
719 org.z = ent.origin.z + ent.mins.z - PL_MIN_CONST.z; // player height
720 // TODO possibly make other code have the same support for bboxes
722 org = org + ent.tag_entity.origin;
723 if (navigation_testtracewalk)
730 if(!autocvar_g_waypointeditor && !ent.navigation_dynamicgoal)
732 waypoint_clearlinks(ent); // initialize wpXXmincost fields
733 IL_EACH(g_waypoints, it != ent,
735 if(walkfromwp && (it.wpflags & WAYPOINTFLAG_NORELINK))
738 SET_TRACEWALK_DESTCOORDS_2(it, org, v, v2, v2_height);
739 if(navigation_waypoint_will_link(v, org, ent, v2, v2_height, walkfromwp, 1050))
740 navigation_item_addlink(it, ent);
744 // box check failed, try walk
745 IL_EACH(g_waypoints, it != ent,
747 if(walkfromwp && (it.wpflags & WAYPOINTFLAG_NORELINK))
749 SET_TRACEWALK_DESTCOORDS_2(it, org, v, v2, v2_height);
750 if(navigation_waypoint_will_link(v, org, ent, v2, v2_height, walkfromwp, bestdist))
752 bestdist = vlen(v - org);
758 entity navigation_findnearestwaypoint(entity ent, float walkfromwp)
760 entity wp = navigation_findnearestwaypoint_withdist_except(ent, walkfromwp, 1050, NULL);
761 if (autocvar_g_waypointeditor_auto)
763 entity wp2 = navigation_findnearestwaypoint_withdist_except(ent, walkfromwp, 1050, wp);
765 wp.wpflags |= WAYPOINTFLAG_PROTECTED;
770 // finds the waypoints near the bot initiating a navigation query
771 float navigation_markroutes_nearestwaypoints(entity this, float maxdist)
774 //navigation_testtracewalk = true;
777 IL_EACH(g_waypoints, !it.wpconsidered,
779 SET_TRACEWALK_DESTCOORDS(it, this.origin, v, v_height);
781 vector diff = v - this.origin;
782 diff.z = max(0, diff.z);
783 if(vdist(diff, <, maxdist))
785 it.wpconsidered = true;
786 if (tracewalk(this, this.origin, this.mins, this.maxs, v, v_height, bot_navigation_movemode))
788 it.wpnearestpoint = v;
789 it.wpcost = waypoint_gettravelcost(this.origin, v) + it.dmg;
796 //navigation_testtracewalk = false;
800 // updates a path link if a spawnfunc_waypoint link is better than the current one
801 void navigation_markroutes_checkwaypoint(entity w, entity wp, float cost, vector p)
807 m1 = wp.origin + wp.mins;
808 m2 = wp.origin + wp.maxs;
809 v.x = bound(m1_x, p.x, m2_x);
810 v.y = bound(m1_y, p.y, m2_y);
811 v.z = bound(m1_z, p.z, m2_z);
815 if (w.wpflags & WAYPOINTFLAG_TELEPORT)
816 cost += w.wp00mincost; // assuming teleport has exactly one destination
818 cost += waypoint_gettravelcost(p, v);
819 if (wp.wpcost > cost)
824 wp.wpnearestpoint = v;
828 // queries the entire spawnfunc_waypoint network for pathes leading away from the bot
829 void navigation_markroutes(entity this, entity fixed_source_waypoint)
834 IL_EACH(g_waypoints, true,
836 it.wpconsidered = false;
837 it.wpnearestpoint = '0 0 0';
838 it.wpcost = 10000000;
843 if(fixed_source_waypoint)
845 fixed_source_waypoint.wpconsidered = true;
846 fixed_source_waypoint.wpnearestpoint = fixed_source_waypoint.origin + 0.5 * (fixed_source_waypoint.mins + fixed_source_waypoint.maxs);
847 fixed_source_waypoint.wpcost = fixed_source_waypoint.dmg;
848 fixed_source_waypoint.wpfire = 1;
849 fixed_source_waypoint.enemy = NULL;
853 // try a short range search for the nearest waypoints, and expand the search repeatedly if none are found
854 // as this search is expensive we will use lower values if the bot is on the air
855 float increment, maxdistance;
856 if(IS_ONGROUND(this))
867 for(int j = increment; !navigation_markroutes_nearestwaypoints(this, j) && j < maxdistance; j += increment);
870 bool searching = true;
874 IL_EACH(g_waypoints, it.wpfire,
879 p = it.wpnearestpoint;
881 wp = it.wp00;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp00mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
882 wp = it.wp01;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp01mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
883 wp = it.wp02;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp02mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
884 wp = it.wp03;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp03mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
885 wp = it.wp04;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp04mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
886 wp = it.wp05;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp05mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
887 wp = it.wp06;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp06mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
888 wp = it.wp07;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp07mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
889 wp = it.wp08;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp08mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
890 wp = it.wp09;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp09mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
891 wp = it.wp10;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp10mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
892 wp = it.wp11;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp11mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
893 wp = it.wp12;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp12mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
894 wp = it.wp13;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp13mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
895 wp = it.wp14;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp14mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
896 wp = it.wp15;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp15mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
897 wp = it.wp16;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp16mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
898 wp = it.wp17;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp17mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
899 wp = it.wp18;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp18mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
900 wp = it.wp19;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp19mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
901 wp = it.wp20;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp20mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
902 wp = it.wp21;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp21mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
903 wp = it.wp22;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp22mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
904 wp = it.wp23;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp23mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
905 wp = it.wp24;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp24mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
906 wp = it.wp25;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp25mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
907 wp = it.wp26;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp26mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
908 wp = it.wp27;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp27mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
909 wp = it.wp28;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp28mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
910 wp = it.wp29;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp29mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
911 wp = it.wp30;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp30mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
912 wp = it.wp31;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp31mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
913 }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
918 // queries the entire spawnfunc_waypoint network for pathes leading to the bot
919 void navigation_markroutes_inverted(entity fixed_source_waypoint)
923 IL_EACH(g_waypoints, true,
925 it.wpconsidered = false;
926 it.wpnearestpoint = '0 0 0';
927 it.wpcost = 10000000;
932 if(fixed_source_waypoint)
934 fixed_source_waypoint.wpconsidered = true;
935 fixed_source_waypoint.wpnearestpoint = fixed_source_waypoint.origin + 0.5 * (fixed_source_waypoint.mins + fixed_source_waypoint.maxs);
936 fixed_source_waypoint.wpcost = fixed_source_waypoint.dmg; // the cost to get from X to fixed_source_waypoint
937 fixed_source_waypoint.wpfire = 1;
938 fixed_source_waypoint.enemy = NULL;
942 error("need to start with a waypoint\n");
945 bool searching = true;
949 IL_EACH(g_waypoints, it.wpfire,
953 cost = it.wpcost; // cost to walk from it to home
954 p = it.wpnearestpoint;
956 IL_EACH(g_waypoints, it != wp,
958 if(!waypoint_islinked(it, wp))
960 cost2 = cost + it.dmg;
961 navigation_markroutes_checkwaypoint(wp, it, cost2, p);
967 // updates the best goal according to a weighted calculation of travel cost and item value of a new proposed item
968 void navigation_routerating(entity this, entity e, float f, float rangebias)
976 rangebias = waypoint_getlinearcost(rangebias);
977 f = waypoint_getlinearcost(f);
981 bool rate_wps = false;
982 if((e.flags & FL_INWATER) || (e.flags & FL_PARTIALGROUND))
987 traceline(e.origin, e.origin + '0 0 -1500', true, NULL);
988 int t = pointcontents(trace_endpos + '0 0 1');
989 if(t != CONTENT_SOLID )
991 if(t == CONTENT_WATER || t == CONTENT_SLIME || t == CONTENT_LAVA)
993 else if(tracebox_hits_trigger_hurt(e.origin, e.mins, e.maxs, trace_endpos))
1000 entity theEnemy = e;
1001 entity best_wp = NULL;
1002 float best_dist = 10000;
1003 IL_EACH(g_waypoints, vdist(it.origin - theEnemy.origin, <, 500)
1004 && vdist(it.origin - this.origin, >, 100)
1005 && !(it.wpflags & WAYPOINTFLAG_TELEPORT),
1007 float dist = vlen(it.origin - theEnemy.origin);
1008 if (dist < best_dist)
1020 vector goal_org = (e.absmin + e.absmax) * 0.5;
1022 //print("routerating ", etos(e), " = ", ftos(f), " - ", ftos(rangebias), "\n");
1024 // Evaluate path using jetpack
1026 if(this.items & IT_JETPACK)
1027 if(autocvar_bot_ai_navigation_jetpack)
1028 if(vdist(this.origin - goal_org, >, autocvar_bot_ai_navigation_jetpack_mindistance))
1030 vector pointa, pointb;
1032 LOG_DEBUG("jetpack ai: evaluating path for ", e.classname);
1035 traceline(this.origin, this.origin + '0 0 65535', MOVE_NORMAL, this);
1036 pointa = trace_endpos - '0 0 1';
1039 traceline(goal_org, goal_org + '0 0 65535', MOVE_NORMAL, e);
1040 pointb = trace_endpos - '0 0 1';
1042 // Can I see these two points from the sky?
1043 traceline(pointa, pointb, MOVE_NORMAL, this);
1045 if(trace_fraction==1)
1047 LOG_DEBUG("jetpack ai: can bridge these two points");
1049 // Lower the altitude of these points as much as possible
1050 float zdistance, xydistance, cost, t, fuel;
1051 vector down, npa, npb;
1053 down = '0 0 -1' * (STAT(PL_MAX, this).z - STAT(PL_MIN, this).z) * 10;
1056 npa = pointa + down;
1057 npb = pointb + down;
1059 if(npa.z<=this.absmax.z)
1062 if(npb.z<=e.absmax.z)
1065 traceline(npa, npb, MOVE_NORMAL, this);
1066 if(trace_fraction==1)
1072 while(trace_fraction == 1);
1075 // Rough estimation of fuel consumption
1076 // (ignores acceleration and current xyz velocity)
1077 xydistance = vlen(pointa - pointb);
1078 zdistance = fabs(pointa.z - this.origin.z);
1080 t = zdistance / autocvar_g_jetpack_maxspeed_up;
1081 t += xydistance / autocvar_g_jetpack_maxspeed_side;
1082 fuel = t * autocvar_g_jetpack_fuel * 0.8;
1084 LOG_DEBUG("jetpack ai: required fuel ", ftos(fuel), " this.ammo_fuel ", ftos(this.ammo_fuel));
1087 if(this.ammo_fuel>fuel)
1090 // (as onground costs calculation is mostly based on distances, here we do the same establishing some relationship
1091 // - between air and ground speeds)
1093 cost = xydistance / (autocvar_g_jetpack_maxspeed_side/autocvar_sv_maxspeed);
1094 cost += zdistance / (autocvar_g_jetpack_maxspeed_up/autocvar_sv_maxspeed);
1097 // Compare against other goals
1098 f = f * rangebias / (rangebias + cost);
1100 if (navigation_bestrating < f)
1102 LOG_DEBUG("jetpack path: added goal ", e.classname, " (with rating ", ftos(f), ")");
1103 navigation_bestrating = f;
1104 navigation_bestgoal = e;
1105 this.navigation_jetpack_goal = e;
1106 this.navigation_jetpack_point = pointb;
1114 //te_wizspike(e.origin);
1117 // update the cached spawnfunc_waypoint link on a dynamic item entity
1118 if(e.classname == "waypoint" && !(e.wpflags & WAYPOINTFLAG_PERSONAL))
1124 if(autocvar_g_waypointeditor && e.nearestwaypointtimeout >= 0 && time > e.nearestwaypointtimeout)
1125 e.nearestwaypoint = NULL;
1127 if ((!e.nearestwaypoint || e.navigation_dynamicgoal)
1128 && e.nearestwaypointtimeout >= 0 && time > e.nearestwaypointtimeout)
1130 nwp = navigation_findnearestwaypoint(e, true);
1133 e.nearestwaypoint = nwp;
1135 vector m1 = nwp.absmin, m2 = nwp.absmax;
1136 m1.x = nwp.origin.x; m1.y = nwp.origin.y;
1137 m2.x = nwp.origin.x; m2.y = nwp.origin.y;
1138 vector ve = (e.absmin - e.absmax) * 0.5;
1139 ve.x = bound(m1.x, ve.x, m2.x);
1140 ve.y = bound(m1.y, ve.y, m2.y);
1141 ve.z = bound(m1.z, ve.z, m2.z);
1143 m1 = e.absmin; m2 = e.absmax;
1144 m1.x = e.origin.x; m1.y = e.origin.y;
1145 m2.x = e.origin.x; m2.y = e.origin.y;
1146 vector vnwp = nwp.origin;
1147 vnwp.x = bound(m1.x, vnwp.x, m2.x);
1148 vnwp.y = bound(m1.y, vnwp.y, m2.y);
1149 vnwp.z = bound(m1.z, vnwp.z, m2.z);
1150 e.nearestwaypoint_dist = vlen(ve - vnwp);
1154 LOG_DEBUG("FAILED to find a nearest waypoint to '", e.classname, "' #", etos(e));
1156 if(!e.navigation_dynamicgoal)
1157 e.blacklisted = true;
1161 LOG_DEBUG("The entity '", e.classname, "' is going to be excluded from path finding during this match");
1166 if(e.navigation_dynamicgoal)
1167 e.nearestwaypointtimeout = time + 2;
1168 else if(autocvar_g_waypointeditor)
1169 e.nearestwaypointtimeout = time + 3 + random() * 2;
1171 nwp = e.nearestwaypoint;
1174 LOG_DEBUG("-- checking ", e.classname, " (with cost ", ftos(nwp.wpcost), ")");
1176 if (nwp.wpcost < 10000000)
1178 //te_wizspike(nwp.wpnearestpoint);
1179 float cost = nwp.wpcost + waypoint_gettravelcost(nwp.wpnearestpoint, goal_org);
1180 LOG_DEBUG(e.classname, " ", ftos(f), "/(1+", ftos(cost), "/", ftos(rangebias), ") = ");
1181 f = f * rangebias / (rangebias + cost);
1182 LOG_DEBUG("considering ", e.classname, " (with rating ", ftos(f), ")");
1183 if (navigation_bestrating < f)
1185 LOG_DEBUG("ground path: added goal ", e.classname, " (with rating ", ftos(f), ")");
1186 navigation_bestrating = f;
1187 navigation_bestgoal = e;
1192 // adds an item to the the goal stack with the path to a given item
1193 bool navigation_routetogoal(entity this, entity e, vector startposition)
1195 // if there is no goal, just exit
1199 if(e.wpflags & WAYPOINTFLAG_TELEPORT)
1201 // force teleport destination as route destination
1206 this.goalentity = e;
1208 // put the entity on the goal stack
1209 //print("routetogoal ", etos(e), "\n");
1210 navigation_pushroute(this, e);
1212 if(e.classname == "waypoint" && !(e.wpflags & WAYPOINTFLAG_PERSONAL))
1214 this.wp_goal_prev1 = this.wp_goal_prev0;
1215 this.wp_goal_prev0 = e;
1219 if(e==this.navigation_jetpack_goal)
1222 // if it can reach the goal there is nothing more to do
1223 vector dest = (e.absmin + e.absmax) * 0.5;
1224 dest.z = e.absmin.z;
1225 float dest_height = e.absmax.z - e.absmin.z;
1226 if (tracewalk(this, startposition, STAT(PL_MIN, this), STAT(PL_MAX, this), dest, dest_height, bot_navigation_movemode))
1229 entity nearest_wp = NULL;
1230 // see if there are waypoints describing a path to the item
1231 if(e.classname != "waypoint" || (e.wpflags & WAYPOINTFLAG_PERSONAL))
1233 e = e.nearestwaypoint;
1237 e = e.enemy; // we already have added it, so...
1242 if(nearest_wp && nearest_wp.enemy)
1244 // often path can be optimized by not adding the nearest waypoint
1245 if (this.goalentity.nearestwaypoint_dist < 8)
1246 e = nearest_wp.enemy;
1249 if (this.goalentity.navigation_dynamicgoal)
1251 vector dest = (this.goalentity.absmin + this.goalentity.absmax) * 0.5;
1252 dest.z = this.goalentity.absmin.z;
1253 float dest_height = this.goalentity.absmax.z - this.goalentity.absmin.z;
1254 if(tracewalk(this, nearest_wp.enemy.origin, STAT(PL_MIN, this), STAT(PL_MAX, this), dest, dest_height, bot_navigation_movemode))
1255 e = nearest_wp.enemy;
1257 else if(navigation_item_islinked(nearest_wp.enemy, this.goalentity))
1258 e = nearest_wp.enemy;
1264 // add the spawnfunc_waypoint to the path
1265 navigation_pushroute(this, e);
1275 // removes any currently touching waypoints from the goal stack
1276 // (this is how bots detect if they reached a goal)
1277 void navigation_poptouchedgoals(entity this)
1279 if(this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT)
1281 // make sure jumppad is really hit, don't rely on distance based checks
1282 // as they may report a touch even if it didn't really happen
1283 if(this.lastteleporttime > 0
1284 && time - this.lastteleporttime < ((this.goalcurrent.wpflags & WAYPOINTFLAG_PERSONAL) ? 2 : 0.15))
1286 if(this.aistatus & AI_STATUS_WAYPOINT_PERSONAL_GOING)
1287 if(this.goalcurrent.wpflags & WAYPOINTFLAG_PERSONAL && this.goalcurrent.owner==this)
1289 this.aistatus &= ~AI_STATUS_WAYPOINT_PERSONAL_GOING;
1290 this.aistatus |= AI_STATUS_WAYPOINT_PERSONAL_REACHED;
1292 navigation_poproute(this);
1298 // If for some reason the bot is closer to the next goal, pop the current one
1299 if(this.goalstack01 && !wasfreed(this.goalstack01))
1300 if(vlen2(this.goalcurrent.origin - this.origin) > vlen2(this.goalstack01.origin - this.origin))
1301 if(checkpvs(this.origin + this.view_ofs, this.goalstack01))
1303 vector dest = (this.goalstack01.absmin + this.goalstack01.absmax) * 0.5;
1304 dest.z = this.goalstack01.absmin.z;
1305 float dest_height = this.goalstack01.absmax.z - this.goalstack01.absmin.z;
1306 if(tracewalk(this, this.origin, this.mins, this.maxs, dest, dest_height, bot_navigation_movemode))
1308 LOG_DEBUG("path optimized for ", this.netname, ", removed a goal from the queue");
1309 navigation_poproute(this);
1310 // TODO this may also be a nice idea to do "early" (e.g. by
1311 // manipulating the vlen() comparisons) to shorten paths in
1312 // general - this would make bots walk more "on rails" than
1313 // "zigzagging" which they currently do with sufficiently
1314 // random-like waypoints, and thus can make a nice bot
1315 // personality property
1319 // Loose goal touching check when running
1320 if(this.aistatus & AI_STATUS_RUNNING)
1321 if(this.goalcurrent.classname=="waypoint")
1322 if(vdist(vec2(this.velocity), >=, autocvar_sv_maxspeed)) // if -really- running
1324 if(vdist(this.origin - this.goalcurrent.origin, <, 150))
1326 traceline(this.origin + this.view_ofs , this.goalcurrent.origin, true, NULL);
1327 if(trace_fraction==1)
1329 // Detect personal waypoints
1330 if(this.aistatus & AI_STATUS_WAYPOINT_PERSONAL_GOING)
1331 if(this.goalcurrent.wpflags & WAYPOINTFLAG_PERSONAL && this.goalcurrent.owner==this)
1333 this.aistatus &= ~AI_STATUS_WAYPOINT_PERSONAL_GOING;
1334 this.aistatus |= AI_STATUS_WAYPOINT_PERSONAL_REACHED;
1337 navigation_poproute(this);
1342 while (this.goalcurrent && !IS_PLAYER(this.goalcurrent))
1344 vector gc_min = this.goalcurrent.absmin;
1345 vector gc_max = this.goalcurrent.absmax;
1346 if(this.goalcurrent.classname == "waypoint" && !this.goalcurrent.wpisbox)
1348 gc_min = this.goalcurrent.origin - '1 1 1' * 12;
1349 gc_max = this.goalcurrent.origin + '1 1 1' * 12;
1351 if(!boxesoverlap(this.absmin, this.absmax, gc_min, gc_max))
1354 // Detect personal waypoints
1355 if(this.aistatus & AI_STATUS_WAYPOINT_PERSONAL_GOING)
1356 if(this.goalcurrent.wpflags & WAYPOINTFLAG_PERSONAL && this.goalcurrent.owner==this)
1358 this.aistatus &= ~AI_STATUS_WAYPOINT_PERSONAL_GOING;
1359 this.aistatus |= AI_STATUS_WAYPOINT_PERSONAL_REACHED;
1362 navigation_poproute(this);
1366 // begin a goal selection session (queries spawnfunc_waypoint network)
1367 void navigation_goalrating_start(entity this)
1369 if(this.aistatus & AI_STATUS_STUCK)
1372 this.navigation_jetpack_goal = NULL;
1373 navigation_bestrating = -1;
1374 navigation_clearroute(this);
1375 navigation_bestgoal = NULL;
1376 navigation_markroutes(this, NULL);
1379 // ends a goal selection session (updates goal stack to the best goal)
1380 void navigation_goalrating_end(entity this)
1382 if(this.aistatus & AI_STATUS_STUCK)
1385 navigation_routetogoal(this, navigation_bestgoal, this.origin);
1386 LOG_DEBUG("best goal ", this.goalcurrent.classname);
1388 // If the bot got stuck then try to reach the farthest waypoint
1389 if (!this.goalentity && autocvar_bot_wander_enable)
1391 if (!(this.aistatus & AI_STATUS_STUCK))
1393 LOG_DEBUG(this.netname, " cannot walk to any goal");
1394 this.aistatus |= AI_STATUS_STUCK;
1399 void botframe_updatedangerousobjects(float maxupdate)
1401 vector m1, m2, v, o;
1404 IL_EACH(g_waypoints, true,
1409 IL_EACH(g_bot_dodge, it.bot_dodge,
1412 v.x = bound(m1_x, v.x, m2_x);
1413 v.y = bound(m1_y, v.y, m2_y);
1414 v.z = bound(m1_z, v.z, m2_z);
1415 o = (it.absmin + it.absmax) * 0.5;
1416 d = waypoint_getlinearcost(it.bot_dodgerating) - waypoint_gettravelcost(o, v);
1419 traceline(o, v, true, NULL);
1420 if (trace_fraction == 1)
1421 danger = danger + d;
1431 void navigation_unstuck(entity this)
1433 float search_radius = 1000;
1435 if (!autocvar_bot_wander_enable)
1438 if (!bot_waypoint_queue_owner)
1440 LOG_DEBUG(this.netname, " stuck, taking over the waypoints queue");
1441 bot_waypoint_queue_owner = this;
1442 bot_waypoint_queue_bestgoal = NULL;
1443 bot_waypoint_queue_bestgoalrating = 0;
1446 if(bot_waypoint_queue_owner!=this)
1449 if (bot_waypoint_queue_goal)
1451 // evaluate the next goal on the queue
1452 float d = vlen2(this.origin - bot_waypoint_queue_goal.origin);
1453 LOG_DEBUG(this.netname, " evaluating ", bot_waypoint_queue_goal.classname, " with distance ", ftos(d));
1454 vector dest = (bot_waypoint_queue_goal.absmin + bot_waypoint_queue_goal.absmax) * 0.5;
1455 dest.z = bot_waypoint_queue_goal.absmin.z;
1456 float dest_height = bot_waypoint_queue_goal.absmax.z - bot_waypoint_queue_goal.absmin.z;
1457 if(tracewalk(bot_waypoint_queue_goal, this.origin, STAT(PL_MIN, this), STAT(PL_MAX, this), dest, dest_height, bot_navigation_movemode))
1459 if( d > bot_waypoint_queue_bestgoalrating)
1461 bot_waypoint_queue_bestgoalrating = d;
1462 bot_waypoint_queue_bestgoal = bot_waypoint_queue_goal;
1465 bot_waypoint_queue_goal = bot_waypoint_queue_goal.bot_waypoint_queue_nextgoal;
1467 if (!bot_waypoint_queue_goal)
1469 if (bot_waypoint_queue_bestgoal)
1471 LOG_DEBUG(this.netname, " stuck, reachable waypoint found, heading to it");
1472 navigation_routetogoal(this, bot_waypoint_queue_bestgoal, this.origin);
1473 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
1474 this.aistatus &= ~AI_STATUS_STUCK;
1478 LOG_DEBUG(this.netname, " stuck, cannot walk to any waypoint at all");
1481 bot_waypoint_queue_owner = NULL;
1486 if(bot_strategytoken!=this)
1489 // build a new queue
1490 LOG_DEBUG(this.netname, " stuck, scanning reachable waypoints within ", ftos(search_radius)," qu");
1492 entity first = NULL;
1494 FOREACH_ENTITY_RADIUS(this.origin, search_radius, it.classname == "waypoint" && !(it.wpflags & WAYPOINTFLAG_GENERATED),
1496 if(bot_waypoint_queue_goal)
1497 bot_waypoint_queue_goal.bot_waypoint_queue_nextgoal = it;
1501 bot_waypoint_queue_goal = it;
1502 bot_waypoint_queue_goal.bot_waypoint_queue_nextgoal = NULL;
1506 bot_waypoint_queue_goal = first;
1509 LOG_DEBUG(this.netname, " stuck, cannot walk to any waypoint at all");
1510 bot_waypoint_queue_owner = NULL;
1515 // Support for debugging tracewalk visually
1517 void debugresetnodes()
1519 debuglastnode = '0 0 0';
1522 void debugnode(entity this, vector node)
1524 if (!IS_PLAYER(this))
1527 if(debuglastnode=='0 0 0')
1529 debuglastnode = node;
1533 te_lightning2(NULL, node, debuglastnode);
1534 debuglastnode = node;
1537 void debugnodestatus(vector position, float status)
1543 case DEBUG_NODE_SUCCESS:
1546 case DEBUG_NODE_WARNING:
1549 case DEBUG_NODE_FAIL:
1556 te_customflash(position, 40, 2, c);
1559 // Support for debugging the goal stack visually
1562 .vector lastposition;
1564 // Debug the goal stack visually
1565 void debuggoalstack(entity this)
1570 if(this.goalcounter==0)goal=this.goalcurrent;
1571 else if(this.goalcounter==1)goal=this.goalstack01;
1572 else if(this.goalcounter==2)goal=this.goalstack02;
1573 else if(this.goalcounter==3)goal=this.goalstack03;
1574 else if(this.goalcounter==4)goal=this.goalstack04;
1575 else if(this.goalcounter==5)goal=this.goalstack05;
1576 else if(this.goalcounter==6)goal=this.goalstack06;
1577 else if(this.goalcounter==7)goal=this.goalstack07;
1578 else if(this.goalcounter==8)goal=this.goalstack08;
1579 else if(this.goalcounter==9)goal=this.goalstack09;
1580 else if(this.goalcounter==10)goal=this.goalstack10;
1581 else if(this.goalcounter==11)goal=this.goalstack11;
1582 else if(this.goalcounter==12)goal=this.goalstack12;
1583 else if(this.goalcounter==13)goal=this.goalstack13;
1584 else if(this.goalcounter==14)goal=this.goalstack14;
1585 else if(this.goalcounter==15)goal=this.goalstack15;
1586 else if(this.goalcounter==16)goal=this.goalstack16;
1587 else if(this.goalcounter==17)goal=this.goalstack17;
1588 else if(this.goalcounter==18)goal=this.goalstack18;
1589 else if(this.goalcounter==19)goal=this.goalstack19;
1590 else if(this.goalcounter==20)goal=this.goalstack20;
1591 else if(this.goalcounter==21)goal=this.goalstack21;
1592 else if(this.goalcounter==22)goal=this.goalstack22;
1593 else if(this.goalcounter==23)goal=this.goalstack23;
1594 else if(this.goalcounter==24)goal=this.goalstack24;
1595 else if(this.goalcounter==25)goal=this.goalstack25;
1596 else if(this.goalcounter==26)goal=this.goalstack26;
1597 else if(this.goalcounter==27)goal=this.goalstack27;
1598 else if(this.goalcounter==28)goal=this.goalstack28;
1599 else if(this.goalcounter==29)goal=this.goalstack29;
1600 else if(this.goalcounter==30)goal=this.goalstack30;
1601 else if(this.goalcounter==31)goal=this.goalstack31;
1606 this.goalcounter = 0;
1607 this.lastposition='0 0 0';
1611 if(this.lastposition=='0 0 0')
1614 org = this.lastposition;
1617 go = ( goal.absmin + goal.absmax ) * 0.5;
1618 te_lightning2(NULL, org, go);
1619 this.lastposition = go;