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 if (trace_startsolid) // hit ceiling above org
429 // reduce stepwalk height
430 tracebox(org, m1, m2, org + stepheightvec, movemode, e);
431 tracebox(trace_endpos, m1, m2, move + eZ * (trace_endpos.z - move.z), movemode, e);
433 else //if (trace_fraction < 1)
435 tracebox(org + jumpstepheightvec, m1, m2, move + jumpstepheightvec, movemode, e);
436 if (trace_startsolid) // hit ceiling above org
438 // reduce jumpstepwalk height
439 tracebox(org, m1, m2, org + jumpstepheightvec, movemode, e);
440 tracebox(trace_endpos, m1, m2, move + eZ * (trace_endpos.z - move.z), movemode, e);
444 if (trace_fraction < 1)
446 vector v = trace_endpos;
447 v.z = org.z + jumpheight_vec.z;
448 if(navigation_checkladders(e, v, m1, m2, end, end2, movemode))
450 if(autocvar_bot_debug_tracewalk)
453 debugnodestatus(v, DEBUG_NODE_SUCCESS);
456 //print("tracewalk: ", vtos(start), " can reach ", vtos(end), "\n");
460 if(autocvar_bot_debug_tracewalk)
461 debugnodestatus(trace_endpos, DEBUG_NODE_WARNING);
463 traceline( org, move, movemode, e);
465 if ( trace_ent.classname == "door_rotating" || trace_ent.classname == "door")
469 while(trace_ent.classname == "door_rotating" || trace_ent.classname == "door")
471 nextmove = move + (flatdir * stepdist);
472 traceline( move, nextmove, movemode, e);
475 flatdist = vlen(vec2(end - move));
479 if(autocvar_bot_debug_tracewalk)
480 debugnodestatus(trace_endpos, DEBUG_NODE_FAIL);
482 //print("tracewalk: ", vtos(start), " hit something when trying to reach ", vtos(end), "\n");
483 //te_explosion(trace_endpos);
484 //print(ftos(e.dphitcontentsmask), "\n");
485 return false; // failed
503 // trace down from stepheight as far as possible and move there,
504 // if this starts in solid we try again without the stepup, and
505 // if that also fails we assume it is a wall
506 // (this is the same logic as the Quake walkmove function used)
507 tracebox(move, m1, m2, move + '0 0 -65536', movemode, e);
515 if(autocvar_bot_debug_tracewalk)
517 debugnode(e, trace_endpos);
518 debugnodestatus(org, DEBUG_NODE_FAIL);
521 //print("tracewalk: ", vtos(start), " hits a hazard when trying to reach ", vtos(end), "\n");
526 if(org.z > move.z - 1 || !SUBMERGED(org))
528 nav_action = NAV_WALK;
532 // ended up submerged while walking
533 if(autocvar_bot_debug_tracewalk)
536 RESURFACE_LIMITED(org, move.z);
537 nav_action = NAV_SWIM_ONWATER;
542 //print("tracewalk: ", vtos(start), " did not arrive at ", vtos(end), " but at ", vtos(org), "\n");
544 // moved but didn't arrive at the intended destination
545 if(autocvar_bot_debug_tracewalk)
546 debugnodestatus(org, DEBUG_NODE_FAIL);
551 /////////////////////////////////////////////////////////////////////////////
553 /////////////////////////////////////////////////////////////////////////////
555 // completely empty the goal stack, used when deciding where to go
556 void navigation_clearroute(entity this)
558 this.goalcurrent_prev = this.goalcurrent;
559 this.goalcurrent_distance = 10000000;
560 this.goalcurrent_distance_time = 0;
561 //print("bot ", etos(this), " clear\n");
562 this.goalentity = NULL;
563 this.goalcurrent = NULL;
564 this.goalstack01 = NULL;
565 this.goalstack02 = NULL;
566 this.goalstack03 = NULL;
567 this.goalstack04 = NULL;
568 this.goalstack05 = NULL;
569 this.goalstack06 = NULL;
570 this.goalstack07 = NULL;
571 this.goalstack08 = NULL;
572 this.goalstack09 = NULL;
573 this.goalstack10 = NULL;
574 this.goalstack11 = NULL;
575 this.goalstack12 = NULL;
576 this.goalstack13 = NULL;
577 this.goalstack14 = NULL;
578 this.goalstack15 = NULL;
579 this.goalstack16 = NULL;
580 this.goalstack17 = NULL;
581 this.goalstack18 = NULL;
582 this.goalstack19 = NULL;
583 this.goalstack20 = NULL;
584 this.goalstack21 = NULL;
585 this.goalstack22 = NULL;
586 this.goalstack23 = NULL;
587 this.goalstack24 = NULL;
588 this.goalstack25 = NULL;
589 this.goalstack26 = NULL;
590 this.goalstack27 = NULL;
591 this.goalstack28 = NULL;
592 this.goalstack29 = NULL;
593 this.goalstack30 = NULL;
594 this.goalstack31 = NULL;
597 // add a new goal at the beginning of the stack
598 // (in other words: add a new prerequisite before going to the later goals)
599 // NOTE: when a waypoint is added, the WP gets pushed first, then the
600 // next-closest WP on the shortest path to the WP
601 // That means, if the stack overflows, the bot will know how to do the FIRST 32
602 // steps to the goal, and then recalculate the path.
603 void navigation_pushroute(entity this, entity e)
605 this.goalcurrent_prev = this.goalcurrent;
606 this.goalcurrent_distance = 10000000;
607 this.goalcurrent_distance_time = 0;
608 //print("bot ", etos(this), " push ", etos(e), "\n");
609 if(this.goalstack31 == this.goalentity)
610 this.goalentity = NULL;
611 this.goalstack31 = this.goalstack30;
612 this.goalstack30 = this.goalstack29;
613 this.goalstack29 = this.goalstack28;
614 this.goalstack28 = this.goalstack27;
615 this.goalstack27 = this.goalstack26;
616 this.goalstack26 = this.goalstack25;
617 this.goalstack25 = this.goalstack24;
618 this.goalstack24 = this.goalstack23;
619 this.goalstack23 = this.goalstack22;
620 this.goalstack22 = this.goalstack21;
621 this.goalstack21 = this.goalstack20;
622 this.goalstack20 = this.goalstack19;
623 this.goalstack19 = this.goalstack18;
624 this.goalstack18 = this.goalstack17;
625 this.goalstack17 = this.goalstack16;
626 this.goalstack16 = this.goalstack15;
627 this.goalstack15 = this.goalstack14;
628 this.goalstack14 = this.goalstack13;
629 this.goalstack13 = this.goalstack12;
630 this.goalstack12 = this.goalstack11;
631 this.goalstack11 = this.goalstack10;
632 this.goalstack10 = this.goalstack09;
633 this.goalstack09 = this.goalstack08;
634 this.goalstack08 = this.goalstack07;
635 this.goalstack07 = this.goalstack06;
636 this.goalstack06 = this.goalstack05;
637 this.goalstack05 = this.goalstack04;
638 this.goalstack04 = this.goalstack03;
639 this.goalstack03 = this.goalstack02;
640 this.goalstack02 = this.goalstack01;
641 this.goalstack01 = this.goalcurrent;
642 this.goalcurrent = e;
645 // remove first goal from stack
646 // (in other words: remove a prerequisite for reaching the later goals)
647 // (used when a spawnfunc_waypoint is reached)
648 void navigation_poproute(entity this)
650 this.goalcurrent_prev = this.goalcurrent;
651 this.goalcurrent_distance = 10000000;
652 this.goalcurrent_distance_time = 0;
653 //print("bot ", etos(this), " pop\n");
654 if(this.goalcurrent == this.goalentity)
655 this.goalentity = NULL;
656 this.goalcurrent = this.goalstack01;
657 this.goalstack01 = this.goalstack02;
658 this.goalstack02 = this.goalstack03;
659 this.goalstack03 = this.goalstack04;
660 this.goalstack04 = this.goalstack05;
661 this.goalstack05 = this.goalstack06;
662 this.goalstack06 = this.goalstack07;
663 this.goalstack07 = this.goalstack08;
664 this.goalstack08 = this.goalstack09;
665 this.goalstack09 = this.goalstack10;
666 this.goalstack10 = this.goalstack11;
667 this.goalstack11 = this.goalstack12;
668 this.goalstack12 = this.goalstack13;
669 this.goalstack13 = this.goalstack14;
670 this.goalstack14 = this.goalstack15;
671 this.goalstack15 = this.goalstack16;
672 this.goalstack16 = this.goalstack17;
673 this.goalstack17 = this.goalstack18;
674 this.goalstack18 = this.goalstack19;
675 this.goalstack19 = this.goalstack20;
676 this.goalstack20 = this.goalstack21;
677 this.goalstack21 = this.goalstack22;
678 this.goalstack22 = this.goalstack23;
679 this.goalstack23 = this.goalstack24;
680 this.goalstack24 = this.goalstack25;
681 this.goalstack25 = this.goalstack26;
682 this.goalstack26 = this.goalstack27;
683 this.goalstack27 = this.goalstack28;
684 this.goalstack28 = this.goalstack29;
685 this.goalstack29 = this.goalstack30;
686 this.goalstack30 = this.goalstack31;
687 this.goalstack31 = NULL;
690 // walking to wp (walkfromwp == false) v2 and v2_height will be used as
691 // waypoint destination coordinates instead of v (only useful for box waypoints)
692 // for normal waypoints v2 == v and v2_height == 0
693 float navigation_waypoint_will_link(vector v, vector org, entity ent, vector v2, float v2_height, float walkfromwp, float bestdist)
695 if (vdist(v - org, <, bestdist))
697 traceline(v, org, true, ent);
698 if (trace_fraction == 1)
702 if (tracewalk(ent, v, PL_MIN_CONST, PL_MAX_CONST, org, 0, bot_navigation_movemode))
707 if (tracewalk(ent, org, PL_MIN_CONST, PL_MAX_CONST, v2, v2_height, bot_navigation_movemode))
715 // find the spawnfunc_waypoint near a dynamic goal such as a dropped weapon
716 entity navigation_findnearestwaypoint_withdist_except(entity ent, float walkfromwp, float bestdist, entity except)
718 vector pm1 = ent.origin + ent.mins;
719 vector pm2 = ent.origin + ent.maxs;
721 // do two scans, because box test is cheaper
722 IL_EACH(g_waypoints, it != ent && it != except,
724 if(boxesoverlap(pm1, pm2, it.absmin, it.absmax))
728 vector org = ent.origin + 0.5 * (ent.mins + ent.maxs);
729 org.z = ent.origin.z + ent.mins.z - PL_MIN_CONST.z; // player height
730 // TODO possibly make other code have the same support for bboxes
732 org = org + ent.tag_entity.origin;
733 if (navigation_testtracewalk)
740 if(!autocvar_g_waypointeditor && !ent.navigation_dynamicgoal)
742 waypoint_clearlinks(ent); // initialize wpXXmincost fields
743 IL_EACH(g_waypoints, it != ent,
745 if(walkfromwp && (it.wpflags & WAYPOINTFLAG_NORELINK))
748 SET_TRACEWALK_DESTCOORDS_2(it, org, v, v2, v2_height);
749 if(navigation_waypoint_will_link(v, org, ent, v2, v2_height, walkfromwp, 1050))
750 navigation_item_addlink(it, ent);
754 // box check failed, try walk
755 IL_EACH(g_waypoints, it != ent,
757 if(walkfromwp && (it.wpflags & WAYPOINTFLAG_NORELINK))
759 SET_TRACEWALK_DESTCOORDS_2(it, org, v, v2, v2_height);
760 if(navigation_waypoint_will_link(v, org, ent, v2, v2_height, walkfromwp, bestdist))
762 bestdist = vlen(v - org);
768 entity navigation_findnearestwaypoint(entity ent, float walkfromwp)
770 entity wp = navigation_findnearestwaypoint_withdist_except(ent, walkfromwp, 1050, NULL);
771 if (autocvar_g_waypointeditor_auto)
773 entity wp2 = navigation_findnearestwaypoint_withdist_except(ent, walkfromwp, 1050, wp);
775 wp.wpflags |= WAYPOINTFLAG_PROTECTED;
780 // finds the waypoints near the bot initiating a navigation query
781 float navigation_markroutes_nearestwaypoints(entity this, float maxdist)
784 //navigation_testtracewalk = true;
787 IL_EACH(g_waypoints, !it.wpconsidered,
789 SET_TRACEWALK_DESTCOORDS(it, this.origin, v, v_height);
791 vector diff = v - this.origin;
792 diff.z = max(0, diff.z);
793 if(vdist(diff, <, maxdist))
795 it.wpconsidered = true;
796 if (tracewalk(this, this.origin, this.mins, this.maxs, v, v_height, bot_navigation_movemode))
798 it.wpnearestpoint = v;
799 it.wpcost = waypoint_gettravelcost(this.origin, v, SUBMERGED(this.origin), SUBMERGED(v)) + it.dmg;
806 //navigation_testtracewalk = false;
810 // updates a path link if a spawnfunc_waypoint link is better than the current one
811 void navigation_markroutes_checkwaypoint(entity w, entity wp, float cost, vector p)
817 m1 = wp.origin + wp.mins;
818 m2 = wp.origin + wp.maxs;
819 v.x = bound(m1_x, p.x, m2_x);
820 v.y = bound(m1_y, p.y, m2_y);
821 v.z = bound(m1_z, p.z, m2_z);
825 if (w.wpflags & WAYPOINTFLAG_TELEPORT)
826 cost += w.wp00mincost; // assuming teleport has exactly one destination
828 cost += waypoint_gettravelcost(p, v, SUBMERGED(p), SUBMERGED(v));
829 if (wp.wpcost > cost)
834 wp.wpnearestpoint = v;
838 // queries the entire spawnfunc_waypoint network for pathes leading away from the bot
839 void navigation_markroutes(entity this, entity fixed_source_waypoint)
844 IL_EACH(g_waypoints, true,
846 it.wpconsidered = false;
847 it.wpnearestpoint = '0 0 0';
848 it.wpcost = 10000000;
853 if(fixed_source_waypoint)
855 fixed_source_waypoint.wpconsidered = true;
856 fixed_source_waypoint.wpnearestpoint = fixed_source_waypoint.origin + 0.5 * (fixed_source_waypoint.mins + fixed_source_waypoint.maxs);
857 fixed_source_waypoint.wpcost = fixed_source_waypoint.dmg;
858 fixed_source_waypoint.wpfire = 1;
859 fixed_source_waypoint.enemy = NULL;
863 // try a short range search for the nearest waypoints, and expand the search repeatedly if none are found
864 // as this search is expensive we will use lower values if the bot is on the air
865 float increment, maxdistance;
866 if(IS_ONGROUND(this))
877 for(int j = increment; !navigation_markroutes_nearestwaypoints(this, j) && j < maxdistance; j += increment);
880 bool searching = true;
884 IL_EACH(g_waypoints, it.wpfire,
889 p = it.wpnearestpoint;
891 wp = it.wp00;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp00mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
892 wp = it.wp01;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp01mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
893 wp = it.wp02;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp02mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
894 wp = it.wp03;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp03mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
895 wp = it.wp04;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp04mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
896 wp = it.wp05;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp05mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
897 wp = it.wp06;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp06mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
898 wp = it.wp07;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp07mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
899 wp = it.wp08;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp08mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
900 wp = it.wp09;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp09mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
901 wp = it.wp10;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp10mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
902 wp = it.wp11;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp11mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
903 wp = it.wp12;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp12mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
904 wp = it.wp13;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp13mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
905 wp = it.wp14;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp14mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
906 wp = it.wp15;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp15mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
907 wp = it.wp16;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp16mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
908 wp = it.wp17;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp17mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
909 wp = it.wp18;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp18mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
910 wp = it.wp19;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp19mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
911 wp = it.wp20;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp20mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
912 wp = it.wp21;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp21mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
913 wp = it.wp22;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp22mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
914 wp = it.wp23;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp23mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
915 wp = it.wp24;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp24mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
916 wp = it.wp25;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp25mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
917 wp = it.wp26;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp26mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
918 wp = it.wp27;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp27mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
919 wp = it.wp28;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp28mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
920 wp = it.wp29;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp29mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
921 wp = it.wp30;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp30mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
922 wp = it.wp31;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp31mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
923 }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
928 // queries the entire spawnfunc_waypoint network for pathes leading to the bot
929 void navigation_markroutes_inverted(entity fixed_source_waypoint)
933 IL_EACH(g_waypoints, true,
935 it.wpconsidered = false;
936 it.wpnearestpoint = '0 0 0';
937 it.wpcost = 10000000;
942 if(fixed_source_waypoint)
944 fixed_source_waypoint.wpconsidered = true;
945 fixed_source_waypoint.wpnearestpoint = fixed_source_waypoint.origin + 0.5 * (fixed_source_waypoint.mins + fixed_source_waypoint.maxs);
946 fixed_source_waypoint.wpcost = fixed_source_waypoint.dmg; // the cost to get from X to fixed_source_waypoint
947 fixed_source_waypoint.wpfire = 1;
948 fixed_source_waypoint.enemy = NULL;
952 error("need to start with a waypoint\n");
955 bool searching = true;
959 IL_EACH(g_waypoints, it.wpfire,
963 cost = it.wpcost; // cost to walk from it to home
964 p = it.wpnearestpoint;
966 IL_EACH(g_waypoints, it != wp,
968 if(!waypoint_islinked(it, wp))
970 cost2 = cost + it.dmg;
971 navigation_markroutes_checkwaypoint(wp, it, cost2, p);
977 // updates the best goal according to a weighted calculation of travel cost and item value of a new proposed item
978 void navigation_routerating(entity this, entity e, float f, float rangebias)
986 rangebias = waypoint_getlinearcost(rangebias);
987 f = waypoint_getlinearcost(f);
991 bool rate_wps = false;
992 if((e.flags & FL_INWATER) || (e.flags & FL_PARTIALGROUND))
997 traceline(e.origin, e.origin + '0 0 -1500', true, NULL);
998 int t = pointcontents(trace_endpos + '0 0 1');
999 if(t != CONTENT_SOLID )
1001 if(t == CONTENT_WATER || t == CONTENT_SLIME || t == CONTENT_LAVA)
1003 else if(tracebox_hits_trigger_hurt(e.origin, e.mins, e.maxs, trace_endpos))
1010 entity theEnemy = e;
1011 entity best_wp = NULL;
1012 float best_dist = 10000;
1013 IL_EACH(g_waypoints, vdist(it.origin - theEnemy.origin, <, 500)
1014 && vdist(it.origin - this.origin, >, 100)
1015 && !(it.wpflags & WAYPOINTFLAG_TELEPORT),
1017 float dist = vlen(it.origin - theEnemy.origin);
1018 if (dist < best_dist)
1030 vector goal_org = (e.absmin + e.absmax) * 0.5;
1032 //print("routerating ", etos(e), " = ", ftos(f), " - ", ftos(rangebias), "\n");
1034 // Evaluate path using jetpack
1036 if(this.items & IT_JETPACK)
1037 if(autocvar_bot_ai_navigation_jetpack)
1038 if(vdist(this.origin - goal_org, >, autocvar_bot_ai_navigation_jetpack_mindistance))
1040 vector pointa, pointb;
1042 LOG_DEBUG("jetpack ai: evaluating path for ", e.classname);
1045 traceline(this.origin, this.origin + '0 0 65535', MOVE_NORMAL, this);
1046 pointa = trace_endpos - '0 0 1';
1049 traceline(goal_org, goal_org + '0 0 65535', MOVE_NORMAL, e);
1050 pointb = trace_endpos - '0 0 1';
1052 // Can I see these two points from the sky?
1053 traceline(pointa, pointb, MOVE_NORMAL, this);
1055 if(trace_fraction==1)
1057 LOG_DEBUG("jetpack ai: can bridge these two points");
1059 // Lower the altitude of these points as much as possible
1060 float zdistance, xydistance, cost, t, fuel;
1061 vector down, npa, npb;
1063 down = '0 0 -1' * (STAT(PL_MAX, this).z - STAT(PL_MIN, this).z) * 10;
1066 npa = pointa + down;
1067 npb = pointb + down;
1069 if(npa.z<=this.absmax.z)
1072 if(npb.z<=e.absmax.z)
1075 traceline(npa, npb, MOVE_NORMAL, this);
1076 if(trace_fraction==1)
1082 while(trace_fraction == 1);
1085 // Rough estimation of fuel consumption
1086 // (ignores acceleration and current xyz velocity)
1087 xydistance = vlen(pointa - pointb);
1088 zdistance = fabs(pointa.z - this.origin.z);
1090 t = zdistance / autocvar_g_jetpack_maxspeed_up;
1091 t += xydistance / autocvar_g_jetpack_maxspeed_side;
1092 fuel = t * autocvar_g_jetpack_fuel * 0.8;
1094 LOG_DEBUG("jetpack ai: required fuel ", ftos(fuel), " this.ammo_fuel ", ftos(this.ammo_fuel));
1097 if(this.ammo_fuel>fuel)
1100 // (as onground costs calculation is mostly based on distances, here we do the same establishing some relationship
1101 // - between air and ground speeds)
1103 cost = xydistance / (autocvar_g_jetpack_maxspeed_side/autocvar_sv_maxspeed);
1104 cost += zdistance / (autocvar_g_jetpack_maxspeed_up/autocvar_sv_maxspeed);
1107 // Compare against other goals
1108 f = f * rangebias / (rangebias + cost);
1110 if (navigation_bestrating < f)
1112 LOG_DEBUG("jetpack path: added goal ", e.classname, " (with rating ", ftos(f), ")");
1113 navigation_bestrating = f;
1114 navigation_bestgoal = e;
1115 this.navigation_jetpack_goal = e;
1116 this.navigation_jetpack_point = pointb;
1124 //te_wizspike(e.origin);
1127 // update the cached spawnfunc_waypoint link on a dynamic item entity
1128 if(e.classname == "waypoint" && !(e.wpflags & WAYPOINTFLAG_PERSONAL))
1134 if(autocvar_g_waypointeditor && e.nearestwaypointtimeout >= 0 && time > e.nearestwaypointtimeout)
1135 e.nearestwaypoint = NULL;
1137 if ((!e.nearestwaypoint || e.navigation_dynamicgoal)
1138 && e.nearestwaypointtimeout >= 0 && time > e.nearestwaypointtimeout)
1140 nwp = navigation_findnearestwaypoint(e, true);
1143 e.nearestwaypoint = nwp;
1145 vector m1 = nwp.absmin, m2 = nwp.absmax;
1146 m1.x = nwp.origin.x; m1.y = nwp.origin.y;
1147 m2.x = nwp.origin.x; m2.y = nwp.origin.y;
1148 vector ve = (e.absmin - e.absmax) * 0.5;
1149 ve.x = bound(m1.x, ve.x, m2.x);
1150 ve.y = bound(m1.y, ve.y, m2.y);
1151 ve.z = bound(m1.z, ve.z, m2.z);
1153 m1 = e.absmin; m2 = e.absmax;
1154 m1.x = e.origin.x; m1.y = e.origin.y;
1155 m2.x = e.origin.x; m2.y = e.origin.y;
1156 vector vnwp = nwp.origin;
1157 vnwp.x = bound(m1.x, vnwp.x, m2.x);
1158 vnwp.y = bound(m1.y, vnwp.y, m2.y);
1159 vnwp.z = bound(m1.z, vnwp.z, m2.z);
1160 e.nearestwaypoint_dist = vlen(ve - vnwp);
1164 LOG_DEBUG("FAILED to find a nearest waypoint to '", e.classname, "' #", etos(e));
1166 if(!e.navigation_dynamicgoal)
1167 e.blacklisted = true;
1171 LOG_DEBUG("The entity '", e.classname, "' is going to be excluded from path finding during this match");
1176 if(e.navigation_dynamicgoal)
1177 e.nearestwaypointtimeout = time + 2;
1178 else if(autocvar_g_waypointeditor)
1179 e.nearestwaypointtimeout = time + 3 + random() * 2;
1181 nwp = e.nearestwaypoint;
1184 LOG_DEBUG("-- checking ", e.classname, " (with cost ", ftos(nwp.wpcost), ")");
1186 if (nwp.wpcost < 10000000)
1188 //te_wizspike(nwp.wpnearestpoint);
1189 float cost = nwp.wpcost + waypoint_gettravelcost(nwp.wpnearestpoint, goal_org, SUBMERGED(nwp.wpnearestpoint), SUBMERGED(goal_org));
1190 LOG_DEBUG(e.classname, " ", ftos(f), "/(1+", ftos(cost), "/", ftos(rangebias), ") = ");
1191 f = f * rangebias / (rangebias + cost);
1192 LOG_DEBUG("considering ", e.classname, " (with rating ", ftos(f), ")");
1193 if (navigation_bestrating < f)
1195 LOG_DEBUG("ground path: added goal ", e.classname, " (with rating ", ftos(f), ")");
1196 navigation_bestrating = f;
1197 navigation_bestgoal = e;
1202 // adds an item to the the goal stack with the path to a given item
1203 bool navigation_routetogoal(entity this, entity e, vector startposition)
1205 // if there is no goal, just exit
1209 if(e.wpflags & WAYPOINTFLAG_TELEPORT)
1211 // force teleport destination as route destination
1216 this.goalentity = e;
1218 // put the entity on the goal stack
1219 //print("routetogoal ", etos(e), "\n");
1220 navigation_pushroute(this, e);
1222 if(e.classname == "waypoint" && !(e.wpflags & WAYPOINTFLAG_PERSONAL))
1224 this.wp_goal_prev1 = this.wp_goal_prev0;
1225 this.wp_goal_prev0 = e;
1229 if(e==this.navigation_jetpack_goal)
1232 // if it can reach the goal there is nothing more to do
1233 vector dest = (e.absmin + e.absmax) * 0.5;
1234 dest.z = e.absmin.z;
1235 float dest_height = e.absmax.z - e.absmin.z;
1236 if (tracewalk(this, startposition, STAT(PL_MIN, this), STAT(PL_MAX, this), dest, dest_height, bot_navigation_movemode))
1239 entity nearest_wp = NULL;
1240 // see if there are waypoints describing a path to the item
1241 if(e.classname != "waypoint" || (e.wpflags & WAYPOINTFLAG_PERSONAL))
1243 e = e.nearestwaypoint;
1247 e = e.enemy; // we already have added it, so...
1252 if(nearest_wp && nearest_wp.enemy)
1254 // often path can be optimized by not adding the nearest waypoint
1255 if (this.goalentity.nearestwaypoint_dist < 8)
1256 e = nearest_wp.enemy;
1259 if (this.goalentity.navigation_dynamicgoal)
1261 vector dest = (this.goalentity.absmin + this.goalentity.absmax) * 0.5;
1262 dest.z = this.goalentity.absmin.z;
1263 float dest_height = this.goalentity.absmax.z - this.goalentity.absmin.z;
1264 if(tracewalk(this, nearest_wp.enemy.origin, STAT(PL_MIN, this), STAT(PL_MAX, this), dest, dest_height, bot_navigation_movemode))
1265 e = nearest_wp.enemy;
1267 else if(navigation_item_islinked(nearest_wp.enemy, this.goalentity))
1268 e = nearest_wp.enemy;
1274 // add the spawnfunc_waypoint to the path
1275 navigation_pushroute(this, e);
1285 // removes any currently touching waypoints from the goal stack
1286 // (this is how bots detect if they reached a goal)
1287 void navigation_poptouchedgoals(entity this)
1289 if(this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT)
1291 // make sure jumppad is really hit, don't rely on distance based checks
1292 // as they may report a touch even if it didn't really happen
1293 if(this.lastteleporttime > 0
1294 && time - this.lastteleporttime < ((this.goalcurrent.wpflags & WAYPOINTFLAG_PERSONAL) ? 2 : 0.15))
1296 if(this.aistatus & AI_STATUS_WAYPOINT_PERSONAL_GOING)
1297 if(this.goalcurrent.wpflags & WAYPOINTFLAG_PERSONAL && this.goalcurrent.owner==this)
1299 this.aistatus &= ~AI_STATUS_WAYPOINT_PERSONAL_GOING;
1300 this.aistatus |= AI_STATUS_WAYPOINT_PERSONAL_REACHED;
1302 navigation_poproute(this);
1308 // If for some reason the bot is closer to the next goal, pop the current one
1309 if(this.goalstack01 && !wasfreed(this.goalstack01))
1310 if(vlen2(this.goalcurrent.origin - this.origin) > vlen2(this.goalstack01.origin - this.origin))
1311 if(checkpvs(this.origin + this.view_ofs, this.goalstack01))
1313 vector dest = (this.goalstack01.absmin + this.goalstack01.absmax) * 0.5;
1314 dest.z = this.goalstack01.absmin.z;
1315 float dest_height = this.goalstack01.absmax.z - this.goalstack01.absmin.z;
1316 if(tracewalk(this, this.origin, this.mins, this.maxs, dest, dest_height, bot_navigation_movemode))
1318 LOG_DEBUG("path optimized for ", this.netname, ", removed a goal from the queue");
1319 navigation_poproute(this);
1320 // TODO this may also be a nice idea to do "early" (e.g. by
1321 // manipulating the vlen() comparisons) to shorten paths in
1322 // general - this would make bots walk more "on rails" than
1323 // "zigzagging" which they currently do with sufficiently
1324 // random-like waypoints, and thus can make a nice bot
1325 // personality property
1329 // Loose goal touching check when running
1330 if(this.aistatus & AI_STATUS_RUNNING)
1331 if(this.goalcurrent.classname=="waypoint")
1332 if(vdist(vec2(this.velocity), >=, autocvar_sv_maxspeed)) // if -really- running
1334 if(vdist(this.origin - this.goalcurrent.origin, <, 150))
1336 traceline(this.origin + this.view_ofs , this.goalcurrent.origin, true, NULL);
1337 if(trace_fraction==1)
1339 // Detect personal waypoints
1340 if(this.aistatus & AI_STATUS_WAYPOINT_PERSONAL_GOING)
1341 if(this.goalcurrent.wpflags & WAYPOINTFLAG_PERSONAL && this.goalcurrent.owner==this)
1343 this.aistatus &= ~AI_STATUS_WAYPOINT_PERSONAL_GOING;
1344 this.aistatus |= AI_STATUS_WAYPOINT_PERSONAL_REACHED;
1347 navigation_poproute(this);
1352 while (this.goalcurrent && !IS_PLAYER(this.goalcurrent))
1354 vector gc_min = this.goalcurrent.absmin;
1355 vector gc_max = this.goalcurrent.absmax;
1356 if(this.goalcurrent.classname == "waypoint" && !this.goalcurrent.wpisbox)
1358 gc_min = this.goalcurrent.origin - '1 1 1' * 12;
1359 gc_max = this.goalcurrent.origin + '1 1 1' * 12;
1361 if(!boxesoverlap(this.absmin, this.absmax, gc_min, gc_max))
1364 // Detect personal waypoints
1365 if(this.aistatus & AI_STATUS_WAYPOINT_PERSONAL_GOING)
1366 if(this.goalcurrent.wpflags & WAYPOINTFLAG_PERSONAL && this.goalcurrent.owner==this)
1368 this.aistatus &= ~AI_STATUS_WAYPOINT_PERSONAL_GOING;
1369 this.aistatus |= AI_STATUS_WAYPOINT_PERSONAL_REACHED;
1372 navigation_poproute(this);
1376 // begin a goal selection session (queries spawnfunc_waypoint network)
1377 void navigation_goalrating_start(entity this)
1379 if(this.aistatus & AI_STATUS_STUCK)
1382 this.navigation_jetpack_goal = NULL;
1383 navigation_bestrating = -1;
1384 navigation_clearroute(this);
1385 navigation_bestgoal = NULL;
1386 navigation_markroutes(this, NULL);
1389 // ends a goal selection session (updates goal stack to the best goal)
1390 void navigation_goalrating_end(entity this)
1392 if(this.aistatus & AI_STATUS_STUCK)
1395 navigation_routetogoal(this, navigation_bestgoal, this.origin);
1396 LOG_DEBUG("best goal ", this.goalcurrent.classname);
1398 // If the bot got stuck then try to reach the farthest waypoint
1399 if (!this.goalentity && autocvar_bot_wander_enable)
1401 if (!(this.aistatus & AI_STATUS_STUCK))
1403 LOG_DEBUG(this.netname, " cannot walk to any goal");
1404 this.aistatus |= AI_STATUS_STUCK;
1409 void botframe_updatedangerousobjects(float maxupdate)
1411 vector m1, m2, v, o;
1414 IL_EACH(g_waypoints, true,
1419 IL_EACH(g_bot_dodge, it.bot_dodge,
1422 v.x = bound(m1_x, v.x, m2_x);
1423 v.y = bound(m1_y, v.y, m2_y);
1424 v.z = bound(m1_z, v.z, m2_z);
1425 o = (it.absmin + it.absmax) * 0.5;
1426 d = waypoint_getlinearcost(it.bot_dodgerating) - waypoint_gettravelcost(o, v, SUBMERGED(o), SUBMERGED(v));
1429 traceline(o, v, true, NULL);
1430 if (trace_fraction == 1)
1431 danger = danger + d;
1441 void navigation_unstuck(entity this)
1443 float search_radius = 1000;
1445 if (!autocvar_bot_wander_enable)
1448 if (!bot_waypoint_queue_owner)
1450 LOG_DEBUG(this.netname, " stuck, taking over the waypoints queue");
1451 bot_waypoint_queue_owner = this;
1452 bot_waypoint_queue_bestgoal = NULL;
1453 bot_waypoint_queue_bestgoalrating = 0;
1456 if(bot_waypoint_queue_owner!=this)
1459 if (bot_waypoint_queue_goal)
1461 // evaluate the next goal on the queue
1462 float d = vlen2(this.origin - bot_waypoint_queue_goal.origin);
1463 LOG_DEBUG(this.netname, " evaluating ", bot_waypoint_queue_goal.classname, " with distance ", ftos(d));
1464 vector dest = (bot_waypoint_queue_goal.absmin + bot_waypoint_queue_goal.absmax) * 0.5;
1465 dest.z = bot_waypoint_queue_goal.absmin.z;
1466 float dest_height = bot_waypoint_queue_goal.absmax.z - bot_waypoint_queue_goal.absmin.z;
1467 if(tracewalk(bot_waypoint_queue_goal, this.origin, STAT(PL_MIN, this), STAT(PL_MAX, this), dest, dest_height, bot_navigation_movemode))
1469 if( d > bot_waypoint_queue_bestgoalrating)
1471 bot_waypoint_queue_bestgoalrating = d;
1472 bot_waypoint_queue_bestgoal = bot_waypoint_queue_goal;
1475 bot_waypoint_queue_goal = bot_waypoint_queue_goal.bot_waypoint_queue_nextgoal;
1477 if (!bot_waypoint_queue_goal)
1479 if (bot_waypoint_queue_bestgoal)
1481 LOG_DEBUG(this.netname, " stuck, reachable waypoint found, heading to it");
1482 navigation_routetogoal(this, bot_waypoint_queue_bestgoal, this.origin);
1483 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
1484 this.aistatus &= ~AI_STATUS_STUCK;
1488 LOG_DEBUG(this.netname, " stuck, cannot walk to any waypoint at all");
1491 bot_waypoint_queue_owner = NULL;
1496 if(bot_strategytoken!=this)
1499 // build a new queue
1500 LOG_DEBUG(this.netname, " stuck, scanning reachable waypoints within ", ftos(search_radius)," qu");
1502 entity first = NULL;
1504 FOREACH_ENTITY_RADIUS(this.origin, search_radius, it.classname == "waypoint" && !(it.wpflags & WAYPOINTFLAG_GENERATED),
1506 if(bot_waypoint_queue_goal)
1507 bot_waypoint_queue_goal.bot_waypoint_queue_nextgoal = it;
1511 bot_waypoint_queue_goal = it;
1512 bot_waypoint_queue_goal.bot_waypoint_queue_nextgoal = NULL;
1516 bot_waypoint_queue_goal = first;
1519 LOG_DEBUG(this.netname, " stuck, cannot walk to any waypoint at all");
1520 bot_waypoint_queue_owner = NULL;
1525 // Support for debugging tracewalk visually
1527 void debugresetnodes()
1529 debuglastnode = '0 0 0';
1532 void debugnode(entity this, vector node)
1534 if (!IS_PLAYER(this))
1537 if(debuglastnode=='0 0 0')
1539 debuglastnode = node;
1543 te_lightning2(NULL, node, debuglastnode);
1544 debuglastnode = node;
1547 void debugnodestatus(vector position, float status)
1553 case DEBUG_NODE_SUCCESS:
1556 case DEBUG_NODE_WARNING:
1559 case DEBUG_NODE_FAIL:
1566 te_customflash(position, 40, 2, c);
1569 // Support for debugging the goal stack visually
1572 .vector lastposition;
1574 // Debug the goal stack visually
1575 void debuggoalstack(entity this)
1580 if(this.goalcounter==0)goal=this.goalcurrent;
1581 else if(this.goalcounter==1)goal=this.goalstack01;
1582 else if(this.goalcounter==2)goal=this.goalstack02;
1583 else if(this.goalcounter==3)goal=this.goalstack03;
1584 else if(this.goalcounter==4)goal=this.goalstack04;
1585 else if(this.goalcounter==5)goal=this.goalstack05;
1586 else if(this.goalcounter==6)goal=this.goalstack06;
1587 else if(this.goalcounter==7)goal=this.goalstack07;
1588 else if(this.goalcounter==8)goal=this.goalstack08;
1589 else if(this.goalcounter==9)goal=this.goalstack09;
1590 else if(this.goalcounter==10)goal=this.goalstack10;
1591 else if(this.goalcounter==11)goal=this.goalstack11;
1592 else if(this.goalcounter==12)goal=this.goalstack12;
1593 else if(this.goalcounter==13)goal=this.goalstack13;
1594 else if(this.goalcounter==14)goal=this.goalstack14;
1595 else if(this.goalcounter==15)goal=this.goalstack15;
1596 else if(this.goalcounter==16)goal=this.goalstack16;
1597 else if(this.goalcounter==17)goal=this.goalstack17;
1598 else if(this.goalcounter==18)goal=this.goalstack18;
1599 else if(this.goalcounter==19)goal=this.goalstack19;
1600 else if(this.goalcounter==20)goal=this.goalstack20;
1601 else if(this.goalcounter==21)goal=this.goalstack21;
1602 else if(this.goalcounter==22)goal=this.goalstack22;
1603 else if(this.goalcounter==23)goal=this.goalstack23;
1604 else if(this.goalcounter==24)goal=this.goalstack24;
1605 else if(this.goalcounter==25)goal=this.goalstack25;
1606 else if(this.goalcounter==26)goal=this.goalstack26;
1607 else if(this.goalcounter==27)goal=this.goalstack27;
1608 else if(this.goalcounter==28)goal=this.goalstack28;
1609 else if(this.goalcounter==29)goal=this.goalstack29;
1610 else if(this.goalcounter==30)goal=this.goalstack30;
1611 else if(this.goalcounter==31)goal=this.goalstack31;
1616 this.goalcounter = 0;
1617 this.lastposition='0 0 0';
1621 if(this.lastposition=='0 0 0')
1624 org = this.lastposition;
1627 go = ( goal.absmin + goal.absmax ) * 0.5;
1628 te_lightning2(NULL, org, go);
1629 this.lastposition = go;