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_check_submerged_state(entity ent, vector pos)
44 submerged = (ent.waterlevel == WATERLEVEL_SUBMERGED);
45 else if(ent.nav_submerged_state != SUBMERGED_UNDEFINED)
46 submerged = (ent.nav_submerged_state == SUBMERGED_YES);
49 submerged = SUBMERGED(pos);
50 // NOTE: SUBMERGED check of box waypoint origin may fail even if origin
51 // is actually submerged because often they are inside some solid.
52 // That's why submerged state is saved now that we know current pos is
53 // not stuck in solid (previous tracewalk call to this pos was successfully)
54 if(!ent.navigation_dynamicgoal)
55 ent.nav_submerged_state = (submerged) ? SUBMERGED_YES : SUBMERGED_NO;
60 bool navigation_checkladders(entity e, vector org, vector m1, vector m2, vector end, vector end2, int movemode)
62 IL_EACH(g_ladders, it.classname == "func_ladder",
65 if(boxesoverlap(org + m1 + '-1 -1 -1', org + m2 + '1 1 1', it.absmin, it.absmax))
66 if(boxesoverlap(end, end2, it.absmin + vec2(m1) + '-1 -1 0', it.absmax + vec2(m2) + '1 1 0'))
69 top.z = it.absmax.z + (PL_MAX_CONST.z - PL_MIN_CONST.z);
70 tracebox(org, m1, m2, top, movemode, e);
71 if(trace_fraction == 1)
78 vector resurface_limited(vector org, float lim, vector m1)
80 if (WETFEET(org + eZ * (lim - org.z)))
84 float RES_min_h = org.z;
85 float RES_max_h = lim;
87 org.z = 0.5 * (RES_min_h + RES_max_h);
92 } while (RES_max_h - RES_min_h >= 1);
97 #define RESURFACE_LIMITED(org, lim) org = resurface_limited(org, lim, m1)
100 #define NAV_SWIM_ONWATER 1
101 #define NAV_SWIM_UNDERWATER 2
103 // rough simulation of walking from one point to another to test if a path
104 // can be traveled, used for waypoint linking and havocbot
105 // if end_height is > 0 destination is any point in the vertical segment [end, end + end_height * eZ]
106 bool tracewalk(entity e, vector start, vector m1, vector m2, vector end, float end_height, float movemode)
108 if(autocvar_bot_debug_tracewalk)
115 vector flatdir = end - start;
117 float flatdist = vlen(flatdir);
118 flatdir = normalize(flatdir);
120 bool ignorehazards = false;
123 // Analyze starting point
124 traceline(start, start, MOVE_NORMAL, e);
125 if (trace_dpstartcontents & (DPCONTENTS_SLIME | DPCONTENTS_LAVA))
126 ignorehazards = true;
128 tracebox(start, m1, m2, start, MOVE_NOMONSTERS, e);
129 if (trace_startsolid)
132 if(autocvar_bot_debug_tracewalk)
133 debugnodestatus(start, DEBUG_NODE_FAIL);
135 //print("tracewalk: ", vtos(start), " is a bad start\n");
141 end2.z += end_height;
143 vector fixed_end = end;
146 if (flatdist > 0 && WETFEET(org))
149 nav_action = NAV_SWIM_UNDERWATER;
152 // tracebox down by player's height
153 // useful to know if water level is so low that bot can still walk
154 tracebox(org, m1, m2, org - eZ * (m2.z - m1.z), movemode, e);
155 if (SUBMERGED(trace_endpos))
158 nav_action = NAV_SWIM_UNDERWATER;
161 nav_action = NAV_WALK;
165 nav_action = NAV_WALK;
173 if (org.z > end2.z + 1)
175 tracebox(org, m1, m2, end2, movemode, e);
177 if (org.z > end2.z + 1)
180 else if (org.z < end.z - 1)
182 tracebox(org, m1, m2, org - jumpheight_vec, movemode, e);
183 if (SUBMERGED(trace_endpos))
185 vector v = trace_endpos;
186 tracebox(v, m1, m2, end, movemode, e);
187 if(trace_endpos.z >= end.z - 1)
189 RESURFACE_LIMITED(v, trace_endpos.z);
193 else if (trace_endpos.z > org.z - jumpheight_vec.z)
194 tracebox(trace_endpos, m1, m2, trace_endpos + jumpheight_vec, movemode, e);
196 if (org.z < end.z - 1)
203 if(autocvar_bot_debug_tracewalk)
206 debugnodestatus(org, DEBUG_NODE_SUCCESS);
209 //print("tracewalk: ", vtos(start), " can reach ", vtos(end), "\n");
214 if(autocvar_bot_debug_tracewalk)
220 if (stepdist > flatdist)
222 if(nav_action == NAV_SWIM_UNDERWATER || (nav_action == NAV_SWIM_ONWATER && org.z > end2.z))
224 // can't use movement direction here to calculate move because of
225 // precision errors especially when direction has a high enough z value
226 //water_dir = normalize(water_end - org);
227 //move = org + water_dir * stepdist;
228 fixed_end.z = bound(end.z, org.z, end2.z);
229 if (stepdist == flatdist) {
233 move = org + (fixed_end - org) * (stepdist / flatdist);
234 flatdist = vlen(vec2(fixed_end - move));
237 else // horiz. direction
239 flatdist -= stepdist;
240 move = org + flatdir * stepdist;
243 if(nav_action == NAV_SWIM_ONWATER)
245 tracebox(org, m1, m2, move, movemode, e); // swim
248 if (trace_fraction < 1)
251 tracebox(org + stepheightvec, m1, m2, move + stepheightvec, movemode, e);
253 if (trace_fraction < 1 || trace_startsolid) // can't jump obstacle out of water
256 if(navigation_checkladders(e, org, m1, m2, end, end2, movemode))
258 if(autocvar_bot_debug_tracewalk)
261 debugnodestatus(org, DEBUG_NODE_SUCCESS);
264 //print("tracewalk: ", vtos(start), " can reach ", vtos(end), "\n");
268 if(autocvar_bot_debug_tracewalk)
269 debugnodestatus(org, DEBUG_NODE_FAIL);
272 //print("tracewalk: ", vtos(start), " hit something when trying to reach ", vtos(end), "\n");
283 if (org.z <= move.z) // going horiz.
285 tracebox(trace_endpos, m1, m2, move, movemode, e);
287 nav_action = NAV_WALK;
292 if (org.z <= move.z) // going horiz.
295 nav_action = NAV_SWIM_ONWATER;
301 nav_action = NAV_SWIM_UNDERWATER;
303 nav_action = NAV_SWIM_ONWATER;
306 else if(nav_action == NAV_SWIM_UNDERWATER)
308 if (move.z >= org.z) // swimming upwards or horiz.
310 tracebox(org, m1, m2, move, movemode, e); // swim
312 bool stepswum = false;
315 if (trace_fraction < 1)
318 vector stepswim_move = move + stepheightvec;
319 if (flatdist > 0 && stepswim_move.z > end2.z + stepheightvec.z) // don't allow stepswim to go higher than destination
320 stepswim_move.z = end2.z;
322 tracebox(org + stepheightvec, m1, m2, stepswim_move, movemode, e);
325 if (trace_startsolid)
327 if(autocvar_bot_debug_tracewalk)
328 debugnodestatus(org, DEBUG_NODE_FAIL);
330 //print("tracewalk: ", vtos(start), " hit something when trying to reach ", vtos(end), "\n");
334 if (trace_fraction < 1)
336 float org_z_prev = org.z;
337 RESURFACE_LIMITED(org, end2.z);
338 if(org.z == org_z_prev)
340 if(autocvar_bot_debug_tracewalk)
341 debugnodestatus(org, DEBUG_NODE_FAIL);
343 //print("tracewalk: ", vtos(start), " can't reach ", vtos(end), "\n");
347 nav_action = NAV_SWIM_UNDERWATER;
349 nav_action = NAV_SWIM_ONWATER;
351 // we didn't advance horiz. in this step, flatdist decrease should be reverted
352 // but we can't do it properly right now... apply this workaround instead
370 if (!WETFEET(trace_endpos))
372 tracebox(trace_endpos, m1, m2, trace_endpos - eZ * (stepdist + (m2.z - m1.z)), movemode, e);
373 // if stepswum we'll land on the obstacle, avoid the SUBMERGED check
374 if (!stepswum && SUBMERGED(trace_endpos))
376 RESURFACE_LIMITED(trace_endpos, end2.z);
378 nav_action = NAV_SWIM_ONWATER;
384 nav_action = NAV_WALK;
390 nav_action = NAV_SWIM_UNDERWATER;
393 else //if (move.z < org.z) // swimming downwards
395 tracebox(org, m1, m2, move, movemode, e); // swim
398 if (trace_fraction < 1)
401 tracebox(org + stepheightvec, m1, m2, move + stepheightvec, movemode, e);
404 if (trace_fraction < 1 || trace_startsolid) // can't jump obstacle out of water
406 if(autocvar_bot_debug_tracewalk)
407 debugnodestatus(move, DEBUG_NODE_FAIL);
409 //print("tracewalk: ", vtos(start), " hit something when trying to reach ", vtos(end), "\n");
421 if (trace_endpos.z > org.z && !SUBMERGED(trace_endpos))
423 // stepswim caused upwards direction
424 tracebox(trace_endpos, m1, m2, trace_endpos - stepheightvec, movemode, e);
425 if (!SUBMERGED(trace_endpos))
428 nav_action = NAV_WALK;
435 nav_action = NAV_SWIM_UNDERWATER;
439 else if(nav_action == NAV_WALK)
442 tracebox(org, m1, m2, move, movemode, e);
444 if(autocvar_bot_debug_tracewalk)
445 debugnode(e, trace_endpos);
448 if (trace_fraction < 1)
450 // check if we can walk over this obstacle, possibly by jumpstepping
451 tracebox(org + stepheightvec, m1, m2, move + stepheightvec, movemode, e);
452 if (trace_fraction < 1 || trace_startsolid)
454 if (trace_startsolid) // hit ceiling above org
456 // reduce stepwalk height
457 tracebox(org, m1, m2, org + stepheightvec, movemode, e);
458 tracebox(trace_endpos, m1, m2, move + eZ * (trace_endpos.z - move.z), movemode, e);
460 else //if (trace_fraction < 1)
462 tracebox(org + jumpstepheightvec, m1, m2, move + jumpstepheightvec, movemode, e);
463 if (trace_startsolid) // hit ceiling above org
465 // reduce jumpstepwalk height
466 tracebox(org, m1, m2, org + jumpstepheightvec, movemode, e);
467 tracebox(trace_endpos, m1, m2, move + eZ * (trace_endpos.z - move.z), movemode, e);
471 if (trace_fraction < 1)
473 vector v = trace_endpos;
474 v.z = org.z + jumpheight_vec.z;
475 if(navigation_checkladders(e, v, m1, m2, end, end2, movemode))
477 if(autocvar_bot_debug_tracewalk)
480 debugnodestatus(v, DEBUG_NODE_SUCCESS);
483 //print("tracewalk: ", vtos(start), " can reach ", vtos(end), "\n");
487 if(autocvar_bot_debug_tracewalk)
488 debugnodestatus(trace_endpos, DEBUG_NODE_WARNING);
490 traceline( org, move, movemode, e);
492 if ( trace_ent.classname == "door_rotating" || trace_ent.classname == "door")
496 while(trace_ent.classname == "door_rotating" || trace_ent.classname == "door")
498 nextmove = move + (flatdir * stepdist);
499 traceline( move, nextmove, movemode, e);
502 flatdist = vlen(vec2(end - move));
506 if(autocvar_bot_debug_tracewalk)
507 debugnodestatus(trace_endpos, DEBUG_NODE_FAIL);
509 //print("tracewalk: ", vtos(start), " hit something when trying to reach ", vtos(end), "\n");
510 //te_explosion(trace_endpos);
511 //print(ftos(e.dphitcontentsmask), "\n");
512 return false; // failed
524 // trace down from stepheight as far as possible and move there,
525 // if this starts in solid we try again without the stepup, and
526 // if that also fails we assume it is a wall
527 // (this is the same logic as the Quake walkmove function used)
528 tracebox(move, m1, m2, move + '0 0 -65536', movemode, e);
536 if(autocvar_bot_debug_tracewalk)
538 debugnode(e, trace_endpos);
539 debugnodestatus(org, DEBUG_NODE_FAIL);
542 //print("tracewalk: ", vtos(start), " hits a hazard when trying to reach ", vtos(end), "\n");
549 if(move.z >= end2.z && org.z < end2.z)
554 if(org.z > move.z - 1 || !SUBMERGED(org))
556 nav_action = NAV_WALK;
560 // ended up submerged while walking
561 if(autocvar_bot_debug_tracewalk)
564 RESURFACE_LIMITED(org, move.z);
565 nav_action = NAV_SWIM_ONWATER;
570 //print("tracewalk: ", vtos(start), " did not arrive at ", vtos(end), " but at ", vtos(org), "\n");
572 // moved but didn't arrive at the intended destination
573 if(autocvar_bot_debug_tracewalk)
574 debugnodestatus(org, DEBUG_NODE_FAIL);
579 /////////////////////////////////////////////////////////////////////////////
581 /////////////////////////////////////////////////////////////////////////////
583 // completely empty the goal stack, used when deciding where to go
584 void navigation_clearroute(entity this)
586 this.goalcurrent_prev = this.goalcurrent;
587 this.goalcurrent_distance = 10000000;
588 this.goalcurrent_distance_time = 0;
589 //print("bot ", etos(this), " clear\n");
590 this.goalentity = NULL;
591 this.goalcurrent = NULL;
592 this.goalstack01 = NULL;
593 this.goalstack02 = NULL;
594 this.goalstack03 = NULL;
595 this.goalstack04 = NULL;
596 this.goalstack05 = NULL;
597 this.goalstack06 = NULL;
598 this.goalstack07 = NULL;
599 this.goalstack08 = NULL;
600 this.goalstack09 = NULL;
601 this.goalstack10 = NULL;
602 this.goalstack11 = NULL;
603 this.goalstack12 = NULL;
604 this.goalstack13 = NULL;
605 this.goalstack14 = NULL;
606 this.goalstack15 = NULL;
607 this.goalstack16 = NULL;
608 this.goalstack17 = NULL;
609 this.goalstack18 = NULL;
610 this.goalstack19 = NULL;
611 this.goalstack20 = NULL;
612 this.goalstack21 = NULL;
613 this.goalstack22 = NULL;
614 this.goalstack23 = NULL;
615 this.goalstack24 = NULL;
616 this.goalstack25 = NULL;
617 this.goalstack26 = NULL;
618 this.goalstack27 = NULL;
619 this.goalstack28 = NULL;
620 this.goalstack29 = NULL;
621 this.goalstack30 = NULL;
622 this.goalstack31 = NULL;
625 // add a new goal at the beginning of the stack
626 // (in other words: add a new prerequisite before going to the later goals)
627 // NOTE: when a waypoint is added, the WP gets pushed first, then the
628 // next-closest WP on the shortest path to the WP
629 // That means, if the stack overflows, the bot will know how to do the FIRST 32
630 // steps to the goal, and then recalculate the path.
631 void navigation_pushroute(entity this, entity e)
633 this.goalcurrent_prev = this.goalcurrent;
634 this.goalcurrent_distance = 10000000;
635 this.goalcurrent_distance_time = 0;
636 //print("bot ", etos(this), " push ", etos(e), "\n");
637 if(this.goalstack31 == this.goalentity)
638 this.goalentity = NULL;
639 this.goalstack31 = this.goalstack30;
640 this.goalstack30 = this.goalstack29;
641 this.goalstack29 = this.goalstack28;
642 this.goalstack28 = this.goalstack27;
643 this.goalstack27 = this.goalstack26;
644 this.goalstack26 = this.goalstack25;
645 this.goalstack25 = this.goalstack24;
646 this.goalstack24 = this.goalstack23;
647 this.goalstack23 = this.goalstack22;
648 this.goalstack22 = this.goalstack21;
649 this.goalstack21 = this.goalstack20;
650 this.goalstack20 = this.goalstack19;
651 this.goalstack19 = this.goalstack18;
652 this.goalstack18 = this.goalstack17;
653 this.goalstack17 = this.goalstack16;
654 this.goalstack16 = this.goalstack15;
655 this.goalstack15 = this.goalstack14;
656 this.goalstack14 = this.goalstack13;
657 this.goalstack13 = this.goalstack12;
658 this.goalstack12 = this.goalstack11;
659 this.goalstack11 = this.goalstack10;
660 this.goalstack10 = this.goalstack09;
661 this.goalstack09 = this.goalstack08;
662 this.goalstack08 = this.goalstack07;
663 this.goalstack07 = this.goalstack06;
664 this.goalstack06 = this.goalstack05;
665 this.goalstack05 = this.goalstack04;
666 this.goalstack04 = this.goalstack03;
667 this.goalstack03 = this.goalstack02;
668 this.goalstack02 = this.goalstack01;
669 this.goalstack01 = this.goalcurrent;
670 this.goalcurrent = e;
673 // remove first goal from stack
674 // (in other words: remove a prerequisite for reaching the later goals)
675 // (used when a spawnfunc_waypoint is reached)
676 void navigation_poproute(entity this)
678 this.goalcurrent_prev = this.goalcurrent;
679 this.goalcurrent_distance = 10000000;
680 this.goalcurrent_distance_time = 0;
681 //print("bot ", etos(this), " pop\n");
682 if(this.goalcurrent == this.goalentity)
683 this.goalentity = NULL;
684 this.goalcurrent = this.goalstack01;
685 this.goalstack01 = this.goalstack02;
686 this.goalstack02 = this.goalstack03;
687 this.goalstack03 = this.goalstack04;
688 this.goalstack04 = this.goalstack05;
689 this.goalstack05 = this.goalstack06;
690 this.goalstack06 = this.goalstack07;
691 this.goalstack07 = this.goalstack08;
692 this.goalstack08 = this.goalstack09;
693 this.goalstack09 = this.goalstack10;
694 this.goalstack10 = this.goalstack11;
695 this.goalstack11 = this.goalstack12;
696 this.goalstack12 = this.goalstack13;
697 this.goalstack13 = this.goalstack14;
698 this.goalstack14 = this.goalstack15;
699 this.goalstack15 = this.goalstack16;
700 this.goalstack16 = this.goalstack17;
701 this.goalstack17 = this.goalstack18;
702 this.goalstack18 = this.goalstack19;
703 this.goalstack19 = this.goalstack20;
704 this.goalstack20 = this.goalstack21;
705 this.goalstack21 = this.goalstack22;
706 this.goalstack22 = this.goalstack23;
707 this.goalstack23 = this.goalstack24;
708 this.goalstack24 = this.goalstack25;
709 this.goalstack25 = this.goalstack26;
710 this.goalstack26 = this.goalstack27;
711 this.goalstack27 = this.goalstack28;
712 this.goalstack28 = this.goalstack29;
713 this.goalstack29 = this.goalstack30;
714 this.goalstack30 = this.goalstack31;
715 this.goalstack31 = NULL;
718 // walking to wp (walkfromwp == false) v2 and v2_height will be used as
719 // waypoint destination coordinates instead of v (only useful for box waypoints)
720 // for normal waypoints v2 == v and v2_height == 0
721 float navigation_waypoint_will_link(vector v, vector org, entity ent, vector v2, float v2_height, float walkfromwp, float bestdist)
723 if (vdist(v - org, <, bestdist))
725 traceline(v, org, true, ent);
726 if (trace_fraction == 1)
730 if (tracewalk(ent, v, PL_MIN_CONST, PL_MAX_CONST, org, 0, bot_navigation_movemode))
735 if (tracewalk(ent, org, PL_MIN_CONST, PL_MAX_CONST, v2, v2_height, bot_navigation_movemode))
743 // find the spawnfunc_waypoint near a dynamic goal such as a dropped weapon
744 entity navigation_findnearestwaypoint_withdist_except(entity ent, float walkfromwp, float bestdist, entity except)
746 vector pm1 = ent.origin + ent.mins;
747 vector pm2 = ent.origin + ent.maxs;
749 // do two scans, because box test is cheaper
750 IL_EACH(g_waypoints, it != ent && it != except,
752 if(boxesoverlap(pm1, pm2, it.absmin, it.absmax))
756 vector org = ent.origin;
759 org += 0.5 * (ent.mins + ent.maxs);
760 org.z = ent.origin.z + ent.mins.z - PL_MIN_CONST.z; // player height
762 // TODO possibly make other code have the same support for bboxes
764 org = org + ent.tag_entity.origin;
765 if (navigation_testtracewalk)
772 if(!autocvar_g_waypointeditor && !ent.navigation_dynamicgoal)
774 waypoint_clearlinks(ent); // initialize wpXXmincost fields
775 IL_EACH(g_waypoints, it != ent,
777 if(walkfromwp && (it.wpflags & WAYPOINTFLAG_NORELINK))
780 SET_TRACEWALK_DESTCOORDS_2(it, org, v, v2, v2_height);
781 if(navigation_waypoint_will_link(v, org, ent, v2, v2_height, walkfromwp, 1050))
782 navigation_item_addlink(it, ent);
786 // box check failed, try walk
787 IL_EACH(g_waypoints, it != ent,
789 if(walkfromwp && (it.wpflags & WAYPOINTFLAG_NORELINK))
791 SET_TRACEWALK_DESTCOORDS_2(it, org, v, v2, v2_height);
792 if(navigation_waypoint_will_link(v, org, ent, v2, v2_height, walkfromwp, bestdist))
794 bestdist = vlen(v - org);
800 entity navigation_findnearestwaypoint(entity ent, float walkfromwp)
802 entity wp = navigation_findnearestwaypoint_withdist_except(ent, walkfromwp, 1050, NULL);
803 if (autocvar_g_waypointeditor_auto)
805 entity wp2 = navigation_findnearestwaypoint_withdist_except(ent, walkfromwp, 1050, wp);
807 wp.wpflags |= WAYPOINTFLAG_PROTECTED;
812 // finds the waypoints near the bot initiating a navigation query
813 float navigation_markroutes_nearestwaypoints(entity this, float maxdist)
816 //navigation_testtracewalk = true;
819 IL_EACH(g_waypoints, !it.wpconsidered,
821 SET_TRACEWALK_DESTCOORDS(it, this.origin, v, v_height);
823 vector diff = v - this.origin;
824 diff.z = max(0, diff.z);
825 if(vdist(diff, <, maxdist))
827 it.wpconsidered = true;
828 if (tracewalk(this, this.origin, this.mins, this.maxs, v, v_height, bot_navigation_movemode))
830 it.wpnearestpoint = v;
831 it.wpcost = waypoint_gettravelcost(this.origin, v, this, it) + it.dmg;
838 //navigation_testtracewalk = false;
842 // updates a path link if a spawnfunc_waypoint link is better than the current one
843 void navigation_markroutes_checkwaypoint(entity w, entity wp, float cost, vector p)
849 m1 = wp.origin + wp.mins;
850 m2 = wp.origin + wp.maxs;
851 v.x = bound(m1_x, p.x, m2_x);
852 v.y = bound(m1_y, p.y, m2_y);
853 v.z = bound(m1_z, p.z, m2_z);
857 if (w.wpflags & WAYPOINTFLAG_TELEPORT)
858 cost += w.wp00mincost; // assuming teleport has exactly one destination
860 cost += waypoint_gettravelcost(p, v, w, wp);
861 if (wp.wpcost > cost)
866 wp.wpnearestpoint = v;
870 // queries the entire spawnfunc_waypoint network for pathes leading away from the bot
871 void navigation_markroutes(entity this, entity fixed_source_waypoint)
876 IL_EACH(g_waypoints, true,
878 it.wpconsidered = false;
879 it.wpnearestpoint = '0 0 0';
880 it.wpcost = 10000000;
885 if(fixed_source_waypoint)
887 fixed_source_waypoint.wpconsidered = true;
888 fixed_source_waypoint.wpnearestpoint = fixed_source_waypoint.origin + 0.5 * (fixed_source_waypoint.mins + fixed_source_waypoint.maxs);
889 fixed_source_waypoint.wpcost = fixed_source_waypoint.dmg;
890 fixed_source_waypoint.wpfire = 1;
891 fixed_source_waypoint.enemy = NULL;
895 // try a short range search for the nearest waypoints, and expand the search repeatedly if none are found
896 // as this search is expensive we will use lower values if the bot is on the air
897 float increment, maxdistance;
898 if(IS_ONGROUND(this))
909 for(int j = increment; !navigation_markroutes_nearestwaypoints(this, j) && j < maxdistance; j += increment);
912 bool searching = true;
916 IL_EACH(g_waypoints, it.wpfire,
921 p = it.wpnearestpoint;
923 wp = it.wp00;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp00mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
924 wp = it.wp01;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp01mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
925 wp = it.wp02;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp02mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
926 wp = it.wp03;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp03mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
927 wp = it.wp04;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp04mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
928 wp = it.wp05;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp05mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
929 wp = it.wp06;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp06mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
930 wp = it.wp07;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp07mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
931 wp = it.wp08;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp08mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
932 wp = it.wp09;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp09mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
933 wp = it.wp10;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp10mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
934 wp = it.wp11;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp11mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
935 wp = it.wp12;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp12mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
936 wp = it.wp13;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp13mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
937 wp = it.wp14;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp14mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
938 wp = it.wp15;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp15mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
939 wp = it.wp16;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp16mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
940 wp = it.wp17;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp17mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
941 wp = it.wp18;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp18mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
942 wp = it.wp19;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp19mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
943 wp = it.wp20;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp20mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
944 wp = it.wp21;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp21mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
945 wp = it.wp22;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp22mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
946 wp = it.wp23;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp23mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
947 wp = it.wp24;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp24mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
948 wp = it.wp25;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp25mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
949 wp = it.wp26;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp26mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
950 wp = it.wp27;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp27mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
951 wp = it.wp28;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp28mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
952 wp = it.wp29;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp29mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
953 wp = it.wp30;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp30mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
954 wp = it.wp31;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + it.wp31mincost) navigation_markroutes_checkwaypoint(it, wp, cost2, p);
955 }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
960 // queries the entire spawnfunc_waypoint network for pathes leading to the bot
961 void navigation_markroutes_inverted(entity fixed_source_waypoint)
965 IL_EACH(g_waypoints, true,
967 it.wpconsidered = false;
968 it.wpnearestpoint = '0 0 0';
969 it.wpcost = 10000000;
974 if(fixed_source_waypoint)
976 fixed_source_waypoint.wpconsidered = true;
977 fixed_source_waypoint.wpnearestpoint = fixed_source_waypoint.origin + 0.5 * (fixed_source_waypoint.mins + fixed_source_waypoint.maxs);
978 fixed_source_waypoint.wpcost = fixed_source_waypoint.dmg; // the cost to get from X to fixed_source_waypoint
979 fixed_source_waypoint.wpfire = 1;
980 fixed_source_waypoint.enemy = NULL;
984 error("need to start with a waypoint\n");
987 bool searching = true;
991 IL_EACH(g_waypoints, it.wpfire,
995 cost = it.wpcost; // cost to walk from it to home
996 p = it.wpnearestpoint;
998 IL_EACH(g_waypoints, it != wp,
1000 if(!waypoint_islinked(it, wp))
1002 cost2 = cost + it.dmg;
1003 navigation_markroutes_checkwaypoint(wp, it, cost2, p);
1009 // updates the best goal according to a weighted calculation of travel cost and item value of a new proposed item
1010 void navigation_routerating(entity this, entity e, float f, float rangebias)
1018 rangebias = waypoint_getlinearcost(rangebias);
1019 f = waypoint_getlinearcost(f);
1023 bool rate_wps = false;
1024 if((e.flags & FL_INWATER) || (e.flags & FL_PARTIALGROUND))
1029 traceline(e.origin, e.origin + '0 0 -1500', true, NULL);
1030 int t = pointcontents(trace_endpos + '0 0 1');
1031 if(t != CONTENT_SOLID )
1033 if(t == CONTENT_WATER || t == CONTENT_SLIME || t == CONTENT_LAVA)
1035 else if(tracebox_hits_trigger_hurt(e.origin, e.mins, e.maxs, trace_endpos))
1042 entity theEnemy = e;
1043 entity best_wp = NULL;
1044 float best_dist = 10000;
1045 IL_EACH(g_waypoints, vdist(it.origin - theEnemy.origin, <, 500)
1046 && vdist(it.origin - this.origin, >, 100)
1047 && !(it.wpflags & WAYPOINTFLAG_TELEPORT),
1049 float dist = vlen(it.origin - theEnemy.origin);
1050 if (dist < best_dist)
1062 vector goal_org = (e.absmin + e.absmax) * 0.5;
1064 //print("routerating ", etos(e), " = ", ftos(f), " - ", ftos(rangebias), "\n");
1066 // Evaluate path using jetpack
1068 if(this.items & IT_JETPACK)
1069 if(autocvar_bot_ai_navigation_jetpack)
1070 if(vdist(this.origin - goal_org, >, autocvar_bot_ai_navigation_jetpack_mindistance))
1072 vector pointa, pointb;
1074 LOG_DEBUG("jetpack ai: evaluating path for ", e.classname);
1077 traceline(this.origin, this.origin + '0 0 65535', MOVE_NORMAL, this);
1078 pointa = trace_endpos - '0 0 1';
1081 traceline(goal_org, goal_org + '0 0 65535', MOVE_NORMAL, e);
1082 pointb = trace_endpos - '0 0 1';
1084 // Can I see these two points from the sky?
1085 traceline(pointa, pointb, MOVE_NORMAL, this);
1087 if(trace_fraction==1)
1089 LOG_DEBUG("jetpack ai: can bridge these two points");
1091 // Lower the altitude of these points as much as possible
1092 float zdistance, xydistance, cost, t, fuel;
1093 vector down, npa, npb;
1095 down = '0 0 -1' * (STAT(PL_MAX, this).z - STAT(PL_MIN, this).z) * 10;
1098 npa = pointa + down;
1099 npb = pointb + down;
1101 if(npa.z<=this.absmax.z)
1104 if(npb.z<=e.absmax.z)
1107 traceline(npa, npb, MOVE_NORMAL, this);
1108 if(trace_fraction==1)
1114 while(trace_fraction == 1);
1117 // Rough estimation of fuel consumption
1118 // (ignores acceleration and current xyz velocity)
1119 xydistance = vlen(pointa - pointb);
1120 zdistance = fabs(pointa.z - this.origin.z);
1122 t = zdistance / autocvar_g_jetpack_maxspeed_up;
1123 t += xydistance / autocvar_g_jetpack_maxspeed_side;
1124 fuel = t * autocvar_g_jetpack_fuel * 0.8;
1126 LOG_DEBUG("jetpack ai: required fuel ", ftos(fuel), " this.ammo_fuel ", ftos(this.ammo_fuel));
1129 if(this.ammo_fuel>fuel)
1132 // (as onground costs calculation is mostly based on distances, here we do the same establishing some relationship
1133 // - between air and ground speeds)
1135 cost = xydistance / (autocvar_g_jetpack_maxspeed_side/autocvar_sv_maxspeed);
1136 cost += zdistance / (autocvar_g_jetpack_maxspeed_up/autocvar_sv_maxspeed);
1139 // Compare against other goals
1140 f = f * rangebias / (rangebias + cost);
1142 if (navigation_bestrating < f)
1144 LOG_DEBUG("jetpack path: added goal ", e.classname, " (with rating ", ftos(f), ")");
1145 navigation_bestrating = f;
1146 navigation_bestgoal = e;
1147 this.navigation_jetpack_goal = e;
1148 this.navigation_jetpack_point = pointb;
1156 //te_wizspike(e.origin);
1159 // update the cached spawnfunc_waypoint link on a dynamic item entity
1160 if(e.classname == "waypoint" && !(e.wpflags & WAYPOINTFLAG_PERSONAL))
1166 if(autocvar_g_waypointeditor && e.nearestwaypointtimeout >= 0 && time > e.nearestwaypointtimeout)
1167 e.nearestwaypoint = NULL;
1169 if ((!e.nearestwaypoint || e.navigation_dynamicgoal)
1170 && e.nearestwaypointtimeout >= 0 && time > e.nearestwaypointtimeout)
1172 nwp = navigation_findnearestwaypoint(e, true);
1175 e.nearestwaypoint = nwp;
1177 vector m1 = nwp.absmin, m2 = nwp.absmax;
1178 m1.x = nwp.origin.x; m1.y = nwp.origin.y;
1179 m2.x = nwp.origin.x; m2.y = nwp.origin.y;
1180 vector ve = (e.absmin - e.absmax) * 0.5;
1181 ve.x = bound(m1.x, ve.x, m2.x);
1182 ve.y = bound(m1.y, ve.y, m2.y);
1183 ve.z = bound(m1.z, ve.z, m2.z);
1185 m1 = e.absmin; m2 = e.absmax;
1186 m1.x = e.origin.x; m1.y = e.origin.y;
1187 m2.x = e.origin.x; m2.y = e.origin.y;
1188 vector vnwp = nwp.origin;
1189 vnwp.x = bound(m1.x, vnwp.x, m2.x);
1190 vnwp.y = bound(m1.y, vnwp.y, m2.y);
1191 vnwp.z = bound(m1.z, vnwp.z, m2.z);
1192 e.nearestwaypoint_dist = vlen(ve - vnwp);
1196 LOG_DEBUG("FAILED to find a nearest waypoint to '", e.classname, "' #", etos(e));
1198 if(!e.navigation_dynamicgoal)
1199 e.blacklisted = true;
1203 LOG_DEBUG("The entity '", e.classname, "' is going to be excluded from path finding during this match");
1208 if(e.navigation_dynamicgoal)
1209 e.nearestwaypointtimeout = time + 2;
1210 else if(autocvar_g_waypointeditor)
1211 e.nearestwaypointtimeout = time + 3 + random() * 2;
1213 nwp = e.nearestwaypoint;
1216 LOG_DEBUG("-- checking ", e.classname, " (with cost ", ftos(nwp.wpcost), ")");
1218 if (nwp.wpcost < 10000000)
1220 //te_wizspike(nwp.wpnearestpoint);
1221 float cost = nwp.wpcost + waypoint_gettravelcost(nwp.wpnearestpoint, goal_org, nwp, e);
1222 LOG_DEBUG(e.classname, " ", ftos(f), "/(1+", ftos(cost), "/", ftos(rangebias), ") = ");
1223 f = f * rangebias / (rangebias + cost);
1224 LOG_DEBUG("considering ", e.classname, " (with rating ", ftos(f), ")");
1225 if (navigation_bestrating < f)
1227 LOG_DEBUG("ground path: added goal ", e.classname, " (with rating ", ftos(f), ")");
1228 navigation_bestrating = f;
1229 navigation_bestgoal = e;
1234 // adds an item to the the goal stack with the path to a given item
1235 bool navigation_routetogoal(entity this, entity e, vector startposition)
1237 // if there is no goal, just exit
1241 if(e.wpflags & WAYPOINTFLAG_TELEPORT)
1243 // force teleport destination as route destination
1248 this.goalentity = e;
1250 // put the entity on the goal stack
1251 //print("routetogoal ", etos(e), "\n");
1252 navigation_pushroute(this, e);
1254 if(e.classname == "waypoint" && !(e.wpflags & WAYPOINTFLAG_PERSONAL))
1256 this.wp_goal_prev1 = this.wp_goal_prev0;
1257 this.wp_goal_prev0 = e;
1261 if(e==this.navigation_jetpack_goal)
1264 // if it can reach the goal there is nothing more to do
1267 SET_TRACEWALK_DESTCOORDS(e, e.origin, dest, dest_height);
1268 if (tracewalk(this, startposition, STAT(PL_MIN, this), STAT(PL_MAX, this), dest, dest_height, bot_navigation_movemode))
1271 entity nearest_wp = NULL;
1272 // see if there are waypoints describing a path to the item
1273 if(e.classname != "waypoint" || (e.wpflags & WAYPOINTFLAG_PERSONAL))
1275 e = e.nearestwaypoint;
1279 e = e.enemy; // we already have added it, so...
1284 if(nearest_wp && nearest_wp.enemy)
1286 // often path can be optimized by not adding the nearest waypoint
1287 if (this.goalentity.nearestwaypoint_dist < 8)
1288 e = nearest_wp.enemy;
1291 if (this.goalentity.navigation_dynamicgoal)
1293 SET_TRACEWALK_DESTCOORDS(e, e.origin, dest, dest_height);
1294 if(tracewalk(this, nearest_wp.enemy.origin, STAT(PL_MIN, this), STAT(PL_MAX, this), dest, dest_height, bot_navigation_movemode))
1295 e = nearest_wp.enemy;
1297 else if(navigation_item_islinked(nearest_wp.enemy, this.goalentity))
1298 e = nearest_wp.enemy;
1304 // add the spawnfunc_waypoint to the path
1305 navigation_pushroute(this, e);
1315 // removes any currently touching waypoints from the goal stack
1316 // (this is how bots detect if they reached a goal)
1317 void navigation_poptouchedgoals(entity this)
1319 if(this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT)
1321 // make sure jumppad is really hit, don't rely on distance based checks
1322 // as they may report a touch even if it didn't really happen
1323 if(this.lastteleporttime > 0
1324 && time - this.lastteleporttime < ((this.goalcurrent.wpflags & WAYPOINTFLAG_PERSONAL) ? 2 : 0.15))
1326 if(this.aistatus & AI_STATUS_WAYPOINT_PERSONAL_GOING)
1327 if(this.goalcurrent.wpflags & WAYPOINTFLAG_PERSONAL && this.goalcurrent.owner==this)
1329 this.aistatus &= ~AI_STATUS_WAYPOINT_PERSONAL_GOING;
1330 this.aistatus |= AI_STATUS_WAYPOINT_PERSONAL_REACHED;
1332 navigation_poproute(this);
1338 // If for some reason the bot is closer to the next goal, pop the current one
1339 if(this.goalstack01 && !wasfreed(this.goalstack01))
1340 if(vlen2(this.goalcurrent.origin - this.origin) > vlen2(this.goalstack01.origin - this.origin))
1341 if(checkpvs(this.origin + this.view_ofs, this.goalstack01))
1343 vector dest = (this.goalstack01.absmin + this.goalstack01.absmax) * 0.5;
1344 dest.z = this.goalstack01.absmin.z;
1345 float dest_height = this.goalstack01.absmax.z - this.goalstack01.absmin.z;
1346 if(tracewalk(this, this.origin, this.mins, this.maxs, dest, dest_height, bot_navigation_movemode))
1348 LOG_DEBUG("path optimized for ", this.netname, ", removed a goal from the queue");
1349 navigation_poproute(this);
1350 if(this.goalcurrent && this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT)
1352 // TODO this may also be a nice idea to do "early" (e.g. by
1353 // manipulating the vlen() comparisons) to shorten paths in
1354 // general - this would make bots walk more "on rails" than
1355 // "zigzagging" which they currently do with sufficiently
1356 // random-like waypoints, and thus can make a nice bot
1357 // personality property
1361 // Loose goal touching check when running
1362 if(this.aistatus & AI_STATUS_RUNNING)
1363 if(this.goalcurrent.classname=="waypoint")
1364 if(vdist(vec2(this.velocity), >=, autocvar_sv_maxspeed)) // if -really- running
1366 if(vdist(this.origin - this.goalcurrent.origin, <, 150))
1368 traceline(this.origin + this.view_ofs , this.goalcurrent.origin, true, NULL);
1369 if(trace_fraction==1)
1371 // Detect personal waypoints
1372 if(this.aistatus & AI_STATUS_WAYPOINT_PERSONAL_GOING)
1373 if(this.goalcurrent.wpflags & WAYPOINTFLAG_PERSONAL && this.goalcurrent.owner==this)
1375 this.aistatus &= ~AI_STATUS_WAYPOINT_PERSONAL_GOING;
1376 this.aistatus |= AI_STATUS_WAYPOINT_PERSONAL_REACHED;
1379 navigation_poproute(this);
1380 if(this.goalcurrent && this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT)
1386 while (this.goalcurrent && !IS_PLAYER(this.goalcurrent))
1388 vector gc_min = this.goalcurrent.absmin;
1389 vector gc_max = this.goalcurrent.absmax;
1390 if(this.goalcurrent.classname == "waypoint" && !this.goalcurrent.wpisbox)
1392 gc_min = this.goalcurrent.origin - '1 1 1' * 12;
1393 gc_max = this.goalcurrent.origin + '1 1 1' * 12;
1395 if(!boxesoverlap(this.absmin, this.absmax, gc_min, gc_max))
1398 // Detect personal waypoints
1399 if(this.aistatus & AI_STATUS_WAYPOINT_PERSONAL_GOING)
1400 if(this.goalcurrent.wpflags & WAYPOINTFLAG_PERSONAL && this.goalcurrent.owner==this)
1402 this.aistatus &= ~AI_STATUS_WAYPOINT_PERSONAL_GOING;
1403 this.aistatus |= AI_STATUS_WAYPOINT_PERSONAL_REACHED;
1406 navigation_poproute(this);
1407 if(this.goalcurrent && this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT)
1412 // begin a goal selection session (queries spawnfunc_waypoint network)
1413 void navigation_goalrating_start(entity this)
1415 if(this.aistatus & AI_STATUS_STUCK)
1418 this.navigation_jetpack_goal = NULL;
1419 navigation_bestrating = -1;
1420 navigation_clearroute(this);
1421 navigation_bestgoal = NULL;
1422 navigation_markroutes(this, NULL);
1425 // ends a goal selection session (updates goal stack to the best goal)
1426 void navigation_goalrating_end(entity this)
1428 if(this.aistatus & AI_STATUS_STUCK)
1431 navigation_routetogoal(this, navigation_bestgoal, this.origin);
1432 LOG_DEBUG("best goal ", this.goalcurrent.classname);
1434 // If the bot got stuck then try to reach the farthest waypoint
1435 if (!this.goalentity && autocvar_bot_wander_enable)
1437 if (!(this.aistatus & AI_STATUS_STUCK))
1439 LOG_DEBUG(this.netname, " cannot walk to any goal");
1440 this.aistatus |= AI_STATUS_STUCK;
1445 void botframe_updatedangerousobjects(float maxupdate)
1447 vector m1, m2, v, o;
1451 IL_EACH(g_waypoints, true,
1457 IL_EACH(g_bot_dodge, it.bot_dodge,
1460 v.x = bound(m1_x, v.x, m2_x);
1461 v.y = bound(m1_y, v.y, m2_y);
1462 v.z = bound(m1_z, v.z, m2_z);
1463 o = (it.absmin + it.absmax) * 0.5;
1464 d = waypoint_getlinearcost(it.bot_dodgerating) - waypoint_gettravelcost(o, v, it, wp_cur);
1467 traceline(o, v, true, NULL);
1468 if (trace_fraction == 1)
1469 danger = danger + d;
1479 void navigation_unstuck(entity this)
1481 float search_radius = 1000;
1483 if (!autocvar_bot_wander_enable)
1486 if (!bot_waypoint_queue_owner)
1488 LOG_DEBUG(this.netname, " stuck, taking over the waypoints queue");
1489 bot_waypoint_queue_owner = this;
1490 bot_waypoint_queue_bestgoal = NULL;
1491 bot_waypoint_queue_bestgoalrating = 0;
1494 if(bot_waypoint_queue_owner!=this)
1497 if (bot_waypoint_queue_goal)
1499 // evaluate the next goal on the queue
1500 float d = vlen2(this.origin - bot_waypoint_queue_goal.origin);
1501 LOG_DEBUG(this.netname, " evaluating ", bot_waypoint_queue_goal.classname, " with distance ", ftos(d));
1502 vector dest = (bot_waypoint_queue_goal.absmin + bot_waypoint_queue_goal.absmax) * 0.5;
1503 dest.z = bot_waypoint_queue_goal.absmin.z;
1504 float dest_height = bot_waypoint_queue_goal.absmax.z - bot_waypoint_queue_goal.absmin.z;
1505 if(tracewalk(bot_waypoint_queue_goal, this.origin, STAT(PL_MIN, this), STAT(PL_MAX, this), dest, dest_height, bot_navigation_movemode))
1507 if( d > bot_waypoint_queue_bestgoalrating)
1509 bot_waypoint_queue_bestgoalrating = d;
1510 bot_waypoint_queue_bestgoal = bot_waypoint_queue_goal;
1513 bot_waypoint_queue_goal = bot_waypoint_queue_goal.bot_waypoint_queue_nextgoal;
1515 if (!bot_waypoint_queue_goal)
1517 if (bot_waypoint_queue_bestgoal)
1519 LOG_DEBUG(this.netname, " stuck, reachable waypoint found, heading to it");
1520 navigation_routetogoal(this, bot_waypoint_queue_bestgoal, this.origin);
1521 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
1522 this.aistatus &= ~AI_STATUS_STUCK;
1526 LOG_DEBUG(this.netname, " stuck, cannot walk to any waypoint at all");
1529 bot_waypoint_queue_owner = NULL;
1534 if(bot_strategytoken!=this)
1537 // build a new queue
1538 LOG_DEBUG(this.netname, " stuck, scanning reachable waypoints within ", ftos(search_radius)," qu");
1540 entity first = NULL;
1542 FOREACH_ENTITY_RADIUS(this.origin, search_radius, it.classname == "waypoint" && !(it.wpflags & WAYPOINTFLAG_GENERATED),
1544 if(bot_waypoint_queue_goal)
1545 bot_waypoint_queue_goal.bot_waypoint_queue_nextgoal = it;
1549 bot_waypoint_queue_goal = it;
1550 bot_waypoint_queue_goal.bot_waypoint_queue_nextgoal = NULL;
1554 bot_waypoint_queue_goal = first;
1557 LOG_DEBUG(this.netname, " stuck, cannot walk to any waypoint at all");
1558 bot_waypoint_queue_owner = NULL;
1563 // Support for debugging tracewalk visually
1565 void debugresetnodes()
1567 debuglastnode = '0 0 0';
1570 void debugnode(entity this, vector node)
1572 if (!IS_PLAYER(this))
1575 if(debuglastnode=='0 0 0')
1577 debuglastnode = node;
1581 te_lightning2(NULL, node, debuglastnode);
1582 debuglastnode = node;
1585 void debugnodestatus(vector position, float status)
1591 case DEBUG_NODE_SUCCESS:
1594 case DEBUG_NODE_WARNING:
1597 case DEBUG_NODE_FAIL:
1604 te_customflash(position, 40, 2, c);
1607 // Support for debugging the goal stack visually
1610 .vector lastposition;
1612 // Debug the goal stack visually
1613 void debuggoalstack(entity this)
1618 if(this.goalcounter==0)goal=this.goalcurrent;
1619 else if(this.goalcounter==1)goal=this.goalstack01;
1620 else if(this.goalcounter==2)goal=this.goalstack02;
1621 else if(this.goalcounter==3)goal=this.goalstack03;
1622 else if(this.goalcounter==4)goal=this.goalstack04;
1623 else if(this.goalcounter==5)goal=this.goalstack05;
1624 else if(this.goalcounter==6)goal=this.goalstack06;
1625 else if(this.goalcounter==7)goal=this.goalstack07;
1626 else if(this.goalcounter==8)goal=this.goalstack08;
1627 else if(this.goalcounter==9)goal=this.goalstack09;
1628 else if(this.goalcounter==10)goal=this.goalstack10;
1629 else if(this.goalcounter==11)goal=this.goalstack11;
1630 else if(this.goalcounter==12)goal=this.goalstack12;
1631 else if(this.goalcounter==13)goal=this.goalstack13;
1632 else if(this.goalcounter==14)goal=this.goalstack14;
1633 else if(this.goalcounter==15)goal=this.goalstack15;
1634 else if(this.goalcounter==16)goal=this.goalstack16;
1635 else if(this.goalcounter==17)goal=this.goalstack17;
1636 else if(this.goalcounter==18)goal=this.goalstack18;
1637 else if(this.goalcounter==19)goal=this.goalstack19;
1638 else if(this.goalcounter==20)goal=this.goalstack20;
1639 else if(this.goalcounter==21)goal=this.goalstack21;
1640 else if(this.goalcounter==22)goal=this.goalstack22;
1641 else if(this.goalcounter==23)goal=this.goalstack23;
1642 else if(this.goalcounter==24)goal=this.goalstack24;
1643 else if(this.goalcounter==25)goal=this.goalstack25;
1644 else if(this.goalcounter==26)goal=this.goalstack26;
1645 else if(this.goalcounter==27)goal=this.goalstack27;
1646 else if(this.goalcounter==28)goal=this.goalstack28;
1647 else if(this.goalcounter==29)goal=this.goalstack29;
1648 else if(this.goalcounter==30)goal=this.goalstack30;
1649 else if(this.goalcounter==31)goal=this.goalstack31;
1654 this.goalcounter = 0;
1655 this.lastposition='0 0 0';
1659 if(this.lastposition=='0 0 0')
1662 org = this.lastposition;
1665 go = ( goal.absmin + goal.absmax ) * 0.5;
1666 te_lightning2(NULL, org, go);
1667 this.lastposition = go;