// 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;
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)
FOREACH_ENTITY_CLASS("func_ladder", true,
{
if(boxesoverlap(org + jumpheight_vec + m1 + '-1 -1 -1', org + jumpheight_vec + m2 + '1 1 1', it.absmin, it.absmax))
- if(boxesoverlap(end, end, it.absmin + (m1 - eZ * m1.z - '1 1 0'), it.absmax + (m2 - eZ * m2.z + '1 1 0')))
+ 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 (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;
}
}
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 = waypoint_getdistancecost(this.origin, v) + it.dmg;
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 (this.goalentity.nearestwaypoint_dist < 8
- || (!this.goalentity.navigation_dynamicgoal && navigation_item_islinked(nearest_wp.enemy, this.goalentity))
- || (this.goalentity.navigation_dynamicgoal && 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 (;;)
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
// 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)
{
++relink_lengthculled;
continue;
}
+ float sv_deviation = 0;
+ float ev_deviation = 0;
navigation_testtracewalk = 0;
if (!this.wpisbox)
{
if (!trace_startsolid)
{
//dprint("sv deviation", vtos(trace_endpos - sv), "\n");
+ sv_deviation = trace_endpos.z + 1 - sv.z;
sv = trace_endpos + '0 0 1';
}
}
if (!trace_startsolid)
{
//dprint("ev deviation", vtos(trace_endpos - ev), "\n");
+ ev_deviation = trace_endpos.z + 1 - ev.z;
ev = trace_endpos + '0 0 1';
}
}
//traceline(this.origin, it.origin, false, NULL);
//if (trace_fraction == 1)
- if (!this.wpisbox && tracewalk(this, sv, PL_MIN_CONST, PL_MAX_CONST, ev, MOVE_NOMONSTERS))
- waypoint_addlink(this, it);
- else
+ if (this.wpisbox)
relink_walkculled += 0.5;
- if (!it.wpisbox && tracewalk(it, ev, PL_MIN_CONST, PL_MAX_CONST, sv, MOVE_NOMONSTERS))
- waypoint_addlink(it, this);
else
+ {
+ vector dest = ev;
+ dest.z = em1.z + ev_deviation;
+ float dest_height = em2.z - em1.z;
+ if(tracewalk(this, sv, PL_MIN_CONST, PL_MAX_CONST, dest, dest_height, MOVE_NOMONSTERS))
+ waypoint_addlink(this, it);
+ else
+ relink_walkculled += 0.5;
+ }
+
+ if (it.wpisbox)
relink_walkculled += 0.5;
+ else
+ {
+ vector dest = sv;
+ dest.z = sm1.z + sv_deviation;
+ float dest_height = sm2.z - sm1.z;
+ if(tracewalk(it, ev, PL_MIN_CONST, PL_MAX_CONST, dest, dest_height, MOVE_NOMONSTERS))
+ waypoint_addlink(it, this);
+ else
+ relink_walkculled += 0.5;
+ }
}
});
navigation_testtracewalk = 0;