// rough simulation of walking from one point to another to test if a path
// can be traveled, used for waypoint linking and havocbot
-
-bool tracewalk(entity e, vector start, vector m1, vector m2, vector end, float movemode)
+// if end_height is > 0 destination is any point in the vertical segment [end, end + end_height * eZ]
+bool tracewalk(entity e, vector start, vector m1, vector m2, vector end, float end_height, float movemode)
{
vector org;
vector move;
float stepdist;
float ignorehazards;
float swimming;
- entity tw_ladder = NULL;
if(autocvar_bot_debug_tracewalk)
{
return false;
}
+ vector end2 = end;
+ if(end_height)
+ end2.z += end_height;
// Movement loop
- move = end - org;
for (;;)
{
- if (boxesoverlap(end, end, org + m1 + '-1 -1 -1', org + m2 + '1 1 1'))
+ if (boxesoverlap(end, end2, org + m1 + '-1 -1 -1', org + m2 + '1 1 1'))
{
// Succeeded
if(autocvar_bot_debug_tracewalk)
tracebox(org + jumpstepheightvec, m1, m2, move + jumpstepheightvec, movemode, e);
if (trace_fraction < 1 || trace_startsolid)
{
+ bool ladder_found = false;
+ IL_EACH(g_ladders, it.classname == "func_ladder",
+ {
+ if(boxesoverlap(org + jumpheight_vec + m1 + '-1 -1 -1', org + jumpheight_vec + m2 + '1 1 1', it.absmin, it.absmax))
+ if(boxesoverlap(end, end2, it.absmin + (m1 - eZ * m1.z - '1 1 0'), it.absmax + (m2 - eZ * m2.z + '1 1 0')))
+ ladder_found = true; // can't return here ("Loop mutex held by tracewalk" error)
+ });
+ if(ladder_found)
+ {
+ if(autocvar_bot_debug_tracewalk)
+ debugnodestatus(end, DEBUG_NODE_SUCCESS);
+
+ //print("tracewalk: ", vtos(start), " can reach ", vtos(end), "\n");
+ return true;
+ }
+
if(autocvar_bot_debug_tracewalk)
debugnodestatus(trace_endpos, DEBUG_NODE_WARNING);
- IL_EACH(g_ladders, it.classname == "func_ladder",
- { it.solid = SOLID_BSP; });
-
traceline( org, move, movemode, e);
- IL_EACH(g_ladders, it.classname == "func_ladder",
- { it.solid = SOLID_TRIGGER; });
-
if ( trace_ent.classname == "door_rotating" || trace_ent.classname == "door")
{
vector nextmove;
move = nextmove;
}
}
- else if (trace_ent.classname == "func_ladder")
- {
- tw_ladder = trace_ent;
- vector ladder_bottom = trace_endpos - dir * m2.x;
- vector ladder_top = ladder_bottom;
- ladder_top.z = trace_ent.absmax.z + (-m1.z + 1);
- tracebox(ladder_bottom, m1, m2, ladder_top, movemode, e);
- if (trace_fraction < 1 || trace_startsolid)
- {
- if(autocvar_bot_debug_tracewalk)
- debugnodestatus(trace_endpos, DEBUG_NODE_FAIL);
-
- return false; // failed
- }
- org = ladder_top + dir * m2.x;
- move = org + dir * stepdist;
- continue;
- }
else
{
if(autocvar_bot_debug_tracewalk)
org = trace_endpos;
}
-
- if(tw_ladder && org.z < tw_ladder.absmax.z)
- {
- // stop tracewalk if destination height is lower than the top of the ladder
- // otherwise bot can't easily figure out climbing direction
- if(autocvar_bot_debug_tracewalk)
- debugnodestatus(org, DEBUG_NODE_FAIL);
-
- return false;
- }
}
//print("tracewalk: ", vtos(start), " did not arrive at ", vtos(end), " but at ", vtos(org), "\n");
// completely empty the goal stack, used when deciding where to go
void navigation_clearroute(entity this)
{
+ this.goalcurrent_prev = this.goalcurrent;
+ this.goalcurrent_distance = 10000000;
+ this.goalcurrent_distance_time = 0;
//print("bot ", etos(this), " clear\n");
this.goalentity = NULL;
this.goalcurrent = NULL;
// steps to the goal, and then recalculate the path.
void navigation_pushroute(entity this, entity e)
{
+ this.goalcurrent_prev = this.goalcurrent;
+ this.goalcurrent_distance = 10000000;
+ this.goalcurrent_distance_time = 0;
//print("bot ", etos(this), " push ", etos(e), "\n");
if(this.goalstack31 == this.goalentity)
this.goalentity = NULL;
// (used when a spawnfunc_waypoint is reached)
void navigation_poproute(entity this)
{
+ this.goalcurrent_prev = this.goalcurrent;
+ this.goalcurrent_distance = 10000000;
+ this.goalcurrent_distance_time = 0;
//print("bot ", etos(this), " pop\n");
if(this.goalcurrent == this.goalentity)
this.goalentity = NULL;
{
if (walkfromwp)
{
- if (tracewalk(ent, v, PL_MIN_CONST, PL_MAX_CONST, org, bot_navigation_movemode))
+ if (tracewalk(ent, v, PL_MIN_CONST, PL_MAX_CONST, org, 0, bot_navigation_movemode))
return true;
}
else
{
- if (tracewalk(ent, org, PL_MIN_CONST, PL_MAX_CONST, v, bot_navigation_movemode))
+ if (tracewalk(ent, org, PL_MIN_CONST, PL_MAX_CONST, v, 0, bot_navigation_movemode))
return true;
}
}
entity best = NULL;
vector v;
+ if(!autocvar_g_waypointeditor && !ent.navigation_dynamicgoal)
+ {
+ waypoint_clearlinks(ent); // initialize wpXXmincost fields
+ IL_EACH(g_waypoints, it != ent,
+ {
+ if(it.wpisbox)
+ {
+ vector wm1 = it.absmin;
+ vector wm2 = it.absmax;
+ v.x = bound(wm1_x, org.x, wm2_x);
+ v.y = bound(wm1_y, org.y, wm2_y);
+ v.z = bound(wm1_z, org.z, wm2_z);
+ }
+ else
+ v = it.origin;
+ if(navigation_waypoint_will_link(v, org, ent, walkfromwp, 1050))
+ navigation_item_addlink(it, ent);
+ });
+ }
+
// box check failed, try walk
IL_EACH(g_waypoints, it != ent,
{
float navigation_markroutes_nearestwaypoints(entity this, float maxdist)
{
vector v, m1, m2;
-// navigation_testtracewalk = true;
+ //navigation_testtracewalk = true;
int c = 0;
+ float v_height;
IL_EACH(g_waypoints, !it.wpconsidered,
{
if (it.wpisbox)
v = this.origin;
v.x = bound(m1_x, v.x, m2_x);
v.y = bound(m1_y, v.y, m2_y);
- v.z = bound(m1_z, v.z, m2_z);
+ v.z = m1.z;
+ v_height = m2.z - m1.z;
}
else
+ {
v = it.origin;
+ v_height = 0;
+ }
vector diff = v - this.origin;
diff.z = max(0, diff.z);
if(vdist(diff, <, maxdist))
{
it.wpconsidered = true;
- if (tracewalk(this, this.origin, this.mins, this.maxs, v, bot_navigation_movemode))
+ if (tracewalk(this, this.origin, this.mins, this.maxs, v, v_height, bot_navigation_movemode))
{
it.wpnearestpoint = v;
- it.wpcost = vlen(v - this.origin) + it.dmg;
+ it.wpcost = waypoint_getdistancecost(this.origin, v) + it.dmg;
it.wpfire = 1;
it.enemy = NULL;
c = c + 1;
}
// updates a path link if a spawnfunc_waypoint link is better than the current one
-void navigation_markroutes_checkwaypoint(entity w, entity wp, float cost2, vector p)
+void navigation_markroutes_checkwaypoint(entity w, entity wp, float cost, vector p)
{
vector m1;
vector m2;
}
else
v = wp.origin;
- cost2 = cost2 + vlen(v - p);
- if (wp.wpcost > cost2)
+ if (w.wpflags & WAYPOINTFLAG_TELEPORT)
+ cost += w.wp00mincost; // assuming teleport has exactly one destination
+ else
+ cost += waypoint_getdistancecost(p, v);
+ if (wp.wpcost > cost)
{
- wp.wpcost = cost2;
+ wp.wpcost = cost;
wp.enemy = w;
wp.wpfire = 1;
wp.wpnearestpoint = v;
cost = it.wpcost; // cost to walk from it to home
p = it.wpnearestpoint;
entity wp = it;
- IL_EACH(g_waypoints, true,
+ IL_EACH(g_waypoints, it != wp,
{
- if(wp != it.wp00) if(wp != it.wp01) if(wp != it.wp02) if(wp != it.wp03)
- if(wp != it.wp04) if(wp != it.wp05) if(wp != it.wp06) if(wp != it.wp07)
- if(wp != it.wp08) if(wp != it.wp09) if(wp != it.wp10) if(wp != it.wp11)
- if(wp != it.wp12) if(wp != it.wp13) if(wp != it.wp14) if(wp != it.wp15)
- if(wp != it.wp16) if(wp != it.wp17) if(wp != it.wp18) if(wp != it.wp19)
- if(wp != it.wp20) if(wp != it.wp21) if(wp != it.wp22) if(wp != it.wp23)
- if(wp != it.wp24) if(wp != it.wp25) if(wp != it.wp26) if(wp != it.wp27)
- if(wp != it.wp28) if(wp != it.wp29) if(wp != it.wp30) if(wp != it.wp31)
+ if(!waypoint_islinked(it, wp))
continue;
cost2 = cost + it.dmg;
navigation_markroutes_checkwaypoint(wp, it, cost2, p);
if(e.blacklisted)
return;
+ rangebias = waypoint_getdistancecost_simple(rangebias);
+ f = waypoint_getdistancecost_simple(f);
+
if (IS_PLAYER(e))
{
bool rate_wps = false;
}
}
- vector o = (e.absmin + e.absmax) * 0.5;
+ vector goal_org = (e.absmin + e.absmax) * 0.5;
//print("routerating ", etos(e), " = ", ftos(f), " - ", ftos(rangebias), "\n");
if(g_jetpack)
if(this.items & IT_JETPACK)
if(autocvar_bot_ai_navigation_jetpack)
- if(vdist(this.origin - o, >, autocvar_bot_ai_navigation_jetpack_mindistance))
+ if(vdist(this.origin - goal_org, >, autocvar_bot_ai_navigation_jetpack_mindistance))
{
vector pointa, pointb;
pointa = trace_endpos - '0 0 1';
// Point B
- traceline(o, o + '0 0 65535', MOVE_NORMAL, e);
+ traceline(goal_org, goal_org + '0 0 65535', MOVE_NORMAL, e);
pointb = trace_endpos - '0 0 1';
// Can I see these two points from the sky?
{
nwp = navigation_findnearestwaypoint(e, true);
if(nwp)
+ {
e.nearestwaypoint = nwp;
+
+ vector m1 = nwp.absmin, m2 = nwp.absmax;
+ m1.x = nwp.origin.x; m1.y = nwp.origin.y;
+ m2.x = nwp.origin.x; m2.y = nwp.origin.y;
+ vector ve = (e.absmin - e.absmax) * 0.5;
+ ve.x = bound(m1.x, ve.x, m2.x);
+ ve.y = bound(m1.y, ve.y, m2.y);
+ ve.z = bound(m1.z, ve.z, m2.z);
+
+ m1 = e.absmin; m2 = e.absmax;
+ m1.x = e.origin.x; m1.y = e.origin.y;
+ m2.x = e.origin.x; m2.y = e.origin.y;
+ vector vnwp = nwp.origin;
+ vnwp.x = bound(m1.x, vnwp.x, m2.x);
+ vnwp.y = bound(m1.y, vnwp.y, m2.y);
+ vnwp.z = bound(m1.z, vnwp.z, m2.z);
+ e.nearestwaypoint_dist = vlen(ve - vnwp);
+ }
else
{
LOG_DEBUG("FAILED to find a nearest waypoint to '", e.classname, "' #", etos(e));
if (nwp.wpcost < 10000000)
{
//te_wizspike(nwp.wpnearestpoint);
- LOG_DEBUG(e.classname, " ", ftos(f), "/(1+", ftos((nwp.wpcost + vlen(e.origin - nwp.wpnearestpoint))), "/", ftos(rangebias), ") = ");
- f = f * rangebias / (rangebias + (nwp.wpcost + vlen(o - nwp.wpnearestpoint)));
+ float cost = nwp.wpcost + waypoint_getdistancecost(nwp.wpnearestpoint, goal_org);
+ LOG_DEBUG(e.classname, " ", ftos(f), "/(1+", ftos(cost), "/", ftos(rangebias), ") = ");
+ f = f * rangebias / (rangebias + cost);
LOG_DEBUG("considering ", e.classname, " (with rating ", ftos(f), ")");
if (navigation_bestrating < f)
{
if (!e)
return false;
+ if(e.wpflags & WAYPOINTFLAG_TELEPORT)
+ {
+ // force teleport destination as route destination
+ e.wp00.enemy = e;
+ e = e.wp00;
+ }
+
this.goalentity = e;
// put the entity on the goal stack
return true;
// if it can reach the goal there is nothing more to do
- if (tracewalk(this, startposition, STAT(PL_MIN, this), STAT(PL_MAX, this), (e.absmin + e.absmax) * 0.5, bot_navigation_movemode))
+ vector dest = (e.absmin + e.absmax) * 0.5;
+ dest.z = e.absmin.z;
+ float dest_height = e.absmax.z - e.absmin.z;
+ if (tracewalk(this, startposition, STAT(PL_MIN, this), STAT(PL_MAX, this), dest, dest_height, bot_navigation_movemode))
return true;
entity nearest_wp = NULL;
if(nearest_wp && nearest_wp.enemy)
{
// often path can be optimized by not adding the nearest waypoint
- if(tracewalk(this, nearest_wp.enemy.origin, STAT(PL_MIN, this), STAT(PL_MAX, this), (this.goalentity.absmin + this.goalentity.absmax) * 0.5, bot_navigation_movemode))
+ if (this.goalentity.nearestwaypoint_dist < 8)
e = nearest_wp.enemy;
+ else
+ {
+ if (this.goalentity.navigation_dynamicgoal)
+ {
+ vector dest = (this.goalentity.absmin + this.goalentity.absmax) * 0.5;
+ dest.z = this.goalentity.absmin.z;
+ float dest_height = this.goalentity.absmax.z - this.goalentity.absmin.z;
+ if(tracewalk(this, nearest_wp.enemy.origin, STAT(PL_MIN, this), STAT(PL_MAX, this), dest, dest_height, bot_navigation_movemode))
+ e = nearest_wp.enemy;
+ }
+ else if(navigation_item_islinked(nearest_wp.enemy, this.goalentity))
+ e = nearest_wp.enemy;
+ }
}
for (;;)
// (this is how bots detect if they reached a goal)
void navigation_poptouchedgoals(entity this)
{
- vector org, m1, m2;
- org = this.origin;
- m1 = org + this.mins;
- m2 = org + this.maxs;
-
if(this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT)
{
// make sure jumppad is really hit, don't rely on distance based checks
// as they may report a touch even if it didn't really happen
- if(this.lastteleporttime>0)
- if(time - this.lastteleporttime < ((this.goalcurrent.wpflags & WAYPOINTFLAG_PERSONAL) ? 2 : 0.15))
+ if(this.lastteleporttime > 0
+ && time - this.lastteleporttime < ((this.goalcurrent.wpflags & WAYPOINTFLAG_PERSONAL) ? 2 : 0.15))
{
if(this.aistatus & AI_STATUS_WAYPOINT_PERSONAL_GOING)
if(this.goalcurrent.wpflags & WAYPOINTFLAG_PERSONAL && this.goalcurrent.owner==this)
this.aistatus |= AI_STATUS_WAYPOINT_PERSONAL_REACHED;
}
navigation_poproute(this);
- return;
}
+ else
+ return;
}
// If for some reason the bot is closer to the next goal, pop the current one
if(this.goalstack01 && !wasfreed(this.goalstack01))
if(vlen2(this.goalcurrent.origin - this.origin) > vlen2(this.goalstack01.origin - this.origin))
if(checkpvs(this.origin + this.view_ofs, this.goalstack01))
- if(tracewalk(this, this.origin, this.mins, this.maxs, (this.goalstack01.absmin + this.goalstack01.absmax) * 0.5, bot_navigation_movemode))
{
- LOG_DEBUG("path optimized for ", this.netname, ", removed a goal from the queue");
- navigation_poproute(this);
- // TODO this may also be a nice idea to do "early" (e.g. by
- // manipulating the vlen() comparisons) to shorten paths in
- // general - this would make bots walk more "on rails" than
- // "zigzagging" which they currently do with sufficiently
- // random-like waypoints, and thus can make a nice bot
- // personality property
+ vector dest = (this.goalstack01.absmin + this.goalstack01.absmax) * 0.5;
+ dest.z = this.goalstack01.absmin.z;
+ float dest_height = this.goalstack01.absmax.z - this.goalstack01.absmin.z;
+ if(tracewalk(this, this.origin, this.mins, this.maxs, dest, dest_height, bot_navigation_movemode))
+ {
+ LOG_DEBUG("path optimized for ", this.netname, ", removed a goal from the queue");
+ navigation_poproute(this);
+ // TODO this may also be a nice idea to do "early" (e.g. by
+ // manipulating the vlen() comparisons) to shorten paths in
+ // general - this would make bots walk more "on rails" than
+ // "zigzagging" which they currently do with sufficiently
+ // random-like waypoints, and thus can make a nice bot
+ // personality property
+ }
}
// Loose goal touching check when running
if(this.aistatus & AI_STATUS_RUNNING)
if(this.goalcurrent.classname=="waypoint")
- if(!(this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT))
if(vlen(this.velocity - eZ * this.velocity.z) >= autocvar_sv_maxspeed) // if -really- running
{
if(vdist(this.origin - this.goalcurrent.origin, <, 150))
gc_min = this.goalcurrent.origin - '1 1 1' * 12;
gc_max = this.goalcurrent.origin + '1 1 1' * 12;
}
- if(!boxesoverlap(m1, m2, gc_min, gc_max))
- break;
-
- if((this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT))
+ if(!boxesoverlap(this.absmin, this.absmax, gc_min, gc_max))
break;
// Detect personal waypoints
IL_EACH(g_waypoints, true,
{
danger = 0;
- m1 = it.mins;
- m2 = it.maxs;
+ m1 = it.absmin;
+ m2 = it.absmax;
IL_EACH(g_bot_dodge, it.bot_dodge,
{
v = it.origin;
v.y = bound(m1_y, v.y, m2_y);
v.z = bound(m1_z, v.z, m2_z);
o = (it.absmin + it.absmax) * 0.5;
- d = it.bot_dodgerating - vlen(o - v);
+ d = waypoint_getdistancecost_simple(it.bot_dodgerating) - waypoint_getdistancecost(o, v);
if (d > 0)
{
traceline(o, v, true, NULL);
// evaluate the next goal on the queue
float d = vlen2(this.origin - bot_waypoint_queue_goal.origin);
LOG_DEBUG(this.netname, " evaluating ", bot_waypoint_queue_goal.classname, " with distance ", ftos(d));
- if(tracewalk(bot_waypoint_queue_goal, this.origin, STAT(PL_MIN, this), STAT(PL_MAX, this), bot_waypoint_queue_goal.origin, bot_navigation_movemode))
+ vector dest = (bot_waypoint_queue_goal.absmin + bot_waypoint_queue_goal.absmax) * 0.5;
+ dest.z = bot_waypoint_queue_goal.absmin.z;
+ float dest_height = bot_waypoint_queue_goal.absmax.z - bot_waypoint_queue_goal.absmin.z;
+ if(tracewalk(bot_waypoint_queue_goal, this.origin, STAT(PL_MIN, this), STAT(PL_MAX, this), dest, dest_height, bot_navigation_movemode))
{
if( d > bot_waypoint_queue_bestgoalrating)
{