.float speed;
+void navigation_dynamicgoal_init(entity this, bool initially_static)
+{
+ this.navigation_dynamicgoal = true;
+ this.bot_basewaypoint = this.nearestwaypoint;
+ if(initially_static)
+ this.nearestwaypointtimeout = -1;
+ else
+ this.nearestwaypointtimeout = time;
+}
+
+void navigation_dynamicgoal_set(entity this)
+{
+ this.nearestwaypointtimeout = time;
+}
+
+void navigation_dynamicgoal_unset(entity this)
+{
+ if(this.bot_basewaypoint)
+ this.nearestwaypoint = this.bot_basewaypoint;
+ this.nearestwaypointtimeout = -1;
+}
+
// rough simulation of walking from one point to another to test if a path
// can be traveled, used for waypoint linking and havocbot
float dist;
float totaldist;
float stepdist;
- float yaw;
float ignorehazards;
float swimming;
}
// Movement loop
- yaw = vectoyaw(move);
move = end - org;
for (;;)
{
if (trace_fraction < 1)
{
swimming = true;
- org = trace_endpos - normalize(org - trace_endpos) * stepdist;
+ org = trace_endpos + normalize(org - trace_endpos) * stepdist;
for (; org.z < end.z + e.maxs.z; org.z += stepdist)
{
- if(autocvar_bot_debug_tracewalk)
- debugnode(e, org);
+ if(autocvar_bot_debug_tracewalk)
+ debugnode(e, org);
- if(pointcontents(org) == CONTENT_EMPTY)
- break;
+ if(pointcontents(org) == CONTENT_EMPTY)
+ break;
}
if(pointcontents(org + '0 0 1') != CONTENT_EMPTY)
tracebox(org + jumpstepheightvec, m1, m2, move + jumpstepheightvec, movemode, e);
if (trace_fraction < 1 || trace_startsolid)
{
+ bool ladder_found = false;
+ 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')))
+ 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);
- // check for doors
traceline( org, move, movemode, e);
+
if ( trace_ent.classname == "door_rotating" || trace_ent.classname == "door")
{
vector nextmove;
void navigation_clearroute(entity this)
{
//print("bot ", etos(this), " clear\n");
- this.navigation_hasgoals = false;
+ this.goalentity = NULL;
this.goalcurrent = NULL;
this.goalstack01 = NULL;
this.goalstack02 = NULL;
void navigation_pushroute(entity this, entity e)
{
//print("bot ", etos(this), " push ", etos(e), "\n");
+ if(this.goalstack31 == this.goalentity)
+ this.goalentity = NULL;
this.goalstack31 = this.goalstack30;
this.goalstack30 = this.goalstack29;
this.goalstack29 = this.goalstack28;
void navigation_poproute(entity this)
{
//print("bot ", etos(this), " pop\n");
+ if(this.goalcurrent == this.goalentity)
+ this.goalentity = NULL;
this.goalcurrent = this.goalstack01;
this.goalstack01 = this.goalstack02;
this.goalstack02 = this.goalstack03;
{
if (walkfromwp)
{
- if (tracewalk(ent, v, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), org, bot_navigation_movemode))
+ if (tracewalk(ent, v, PL_MIN_CONST, PL_MAX_CONST, org, bot_navigation_movemode))
return true;
}
else
{
- if (tracewalk(ent, org, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), v, bot_navigation_movemode))
+ if (tracewalk(ent, org, PL_MIN_CONST, PL_MAX_CONST, v, bot_navigation_movemode))
return true;
}
}
});
vector org = ent.origin + 0.5 * (ent.mins + ent.maxs);
- org.z = ent.origin.z + ent.mins.z - STAT(PL_MIN, NULL).z; // player height
+ org.z = ent.origin.z + ent.mins.z - PL_MIN_CONST.z; // player height
// TODO possibly make other code have the same support for bboxes
if(ent.tag_entity)
org = org + ent.tag_entity.origin;
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,
{
if (tracewalk(this, this.origin, this.mins, this.maxs, v, 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);
// updates the best goal according to a weighted calculation of travel cost and item value of a new proposed item
void navigation_routerating(entity this, entity e, float f, float rangebias)
{
- entity nwp;
- vector o;
if (!e)
return;
if(e.blacklisted)
return;
- o = (e.absmin + e.absmax) * 0.5;
+ rangebias = waypoint_getdistancecost_simple(rangebias);
+ f = waypoint_getdistancecost_simple(f);
+
+ if (IS_PLAYER(e))
+ {
+ bool rate_wps = false;
+ if((e.flags & FL_INWATER) || (e.flags & FL_PARTIALGROUND))
+ rate_wps = true;
+
+ if(!IS_ONGROUND(e))
+ {
+ traceline(e.origin, e.origin + '0 0 -1500', true, NULL);
+ int t = pointcontents(trace_endpos + '0 0 1');
+ if(t != CONTENT_SOLID )
+ {
+ if(t == CONTENT_WATER || t == CONTENT_SLIME || t == CONTENT_LAVA)
+ rate_wps = true;
+ else if(tracebox_hits_trigger_hurt(e.origin, e.mins, e.maxs, trace_endpos))
+ return;
+ }
+ }
+
+ if(rate_wps)
+ {
+ entity theEnemy = e;
+ entity best_wp = NULL;
+ float best_dist = 10000;
+ IL_EACH(g_waypoints, vdist(it.origin - theEnemy.origin, <, 500)
+ && vdist(it.origin - this.origin, >, 100)
+ && !(it.wpflags & WAYPOINTFLAG_TELEPORT),
+ {
+ float dist = vlen(it.origin - theEnemy.origin);
+ if (dist < best_dist)
+ {
+ best_wp = it;
+ best_dist = dist;
+ }
+ });
+ if (!best_wp)
+ return;
+ e = best_wp;
+ }
+ }
+
+ 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?
float zdistance, xydistance, cost, t, fuel;
vector down, npa, npb;
- down = '0 0 -1' * (STAT(PL_MAX, NULL).z - STAT(PL_MIN, NULL).z) * 10;
+ down = '0 0 -1' * (STAT(PL_MAX, this).z - STAT(PL_MIN, this).z) * 10;
do{
npa = pointa + down;
}
}
+ entity nwp;
//te_wizspike(e.origin);
//bprint(etos(e));
//bprint("\n");
}
else
{
- float search;
+ if(autocvar_g_waypointeditor && e.nearestwaypointtimeout >= 0 && time > e.nearestwaypointtimeout)
+ e.nearestwaypoint = NULL;
- search = true;
-
- if(e.flags & FL_ITEM)
- {
- if (!(e.flags & FL_WEAPON))
- if(e.nearestwaypoint)
- search = false;
- }
- else if (e.flags & FL_WEAPON)
- {
- if(e.classname != "droppedweapon")
- if(e.nearestwaypoint)
- search = false;
- }
-
- if(search)
- if (time > e.nearestwaypointtimeout)
+ if ((!e.nearestwaypoint || e.navigation_dynamicgoal)
+ && e.nearestwaypointtimeout >= 0 && time > e.nearestwaypointtimeout)
{
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(e.flags & FL_ITEM)
+ if(!e.navigation_dynamicgoal)
e.blacklisted = true;
- else if (e.flags & FL_WEAPON)
- {
- if(e.classname != "droppedweapon")
- e.blacklisted = true;
- }
if(e.blacklisted)
{
}
}
- // TODO: Cleaner solution, probably handling this timeout from ctf.qc
- if(e.classname=="item_flag_team")
+ if(e.navigation_dynamicgoal)
e.nearestwaypointtimeout = time + 2;
- else
- e.nearestwaypointtimeout = time + random() * 3 + 5;
+ else if(autocvar_g_waypointeditor)
+ e.nearestwaypointtimeout = time + 3 + random() * 2;
}
nwp = e.nearestwaypoint;
}
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)
{
// adds an item to the the goal stack with the path to a given item
bool navigation_routetogoal(entity this, entity e, vector startposition)
{
- this.goalentity = e;
-
// if there is no goal, just exit
if (!e)
return false;
- this.navigation_hasgoals = true;
+ this.goalentity = e;
// put the entity on the goal stack
//print("routetogoal ", etos(e), "\n");
navigation_pushroute(this, e);
+ if(e.classname == "waypoint" && !(e.wpflags & WAYPOINTFLAG_PERSONAL))
+ {
+ this.wp_goal_prev1 = this.wp_goal_prev0;
+ this.wp_goal_prev0 = e;
+ }
+
if(g_jetpack)
if(e==this.navigation_jetpack_goal)
return true;
// if it can reach the goal there is nothing more to do
- if (tracewalk(this, startposition, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), (e.absmin + e.absmax) * 0.5, bot_navigation_movemode))
+ if (tracewalk(this, startposition, STAT(PL_MIN, this), STAT(PL_MAX, this), (e.absmin + e.absmax) * 0.5, bot_navigation_movemode))
return true;
+ entity nearest_wp = NULL;
// see if there are waypoints describing a path to the item
if(e.classname != "waypoint" || (e.wpflags & WAYPOINTFLAG_PERSONAL))
+ {
e = e.nearestwaypoint;
+ nearest_wp = e;
+ }
else
e = e.enemy; // we already have added it, so...
if(e == NULL)
return false;
+ 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)))
+ e = nearest_wp.enemy;
+ }
+
for (;;)
{
// add the spawnfunc_waypoint to the path
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(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)
}
// If for some reason the bot is closer to the next goal, pop the current one
- if(this.goalstack01)
+ 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))
// personality property
}
- // HACK: remove players/bots as goals, they can lead a bot to unexpected places (cliffs, lava, etc)
- // TODO: rate waypoints near the targetted player at that moment, instead of the player itself
- if(IS_PLAYER(this.goalcurrent))
- navigation_poproute(this);
-
- // aid for detecting jump pads better (distance based check fails sometimes)
- if(this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT && this.jumppadcount > 0 )
- navigation_poproute(this);
-
// Loose goal touching check when running
if(this.aistatus & AI_STATUS_RUNNING)
- if(this.speed >= autocvar_sv_maxspeed) // if -really- 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))
{
}
}
- while (this.goalcurrent && boxesoverlap(m1, m2, this.goalcurrent.absmin, this.goalcurrent.absmax))
+ while (this.goalcurrent && !IS_PLAYER(this.goalcurrent))
{
+ vector gc_min = this.goalcurrent.absmin;
+ vector gc_max = this.goalcurrent.absmax;
+ if(this.goalcurrent.classname == "waypoint" && !this.goalcurrent.wpisbox)
+ {
+ 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))
+ break;
+
// Detect personal waypoints
if(this.aistatus & AI_STATUS_WAYPOINT_PERSONAL_GOING)
if(this.goalcurrent.wpflags & WAYPOINTFLAG_PERSONAL && this.goalcurrent.owner==this)
this.navigation_jetpack_goal = NULL;
navigation_bestrating = -1;
- this.navigation_hasgoals = false;
navigation_clearroute(this);
navigation_bestgoal = NULL;
navigation_markroutes(this, NULL);
LOG_DEBUG("best goal ", this.goalcurrent.classname);
// If the bot got stuck then try to reach the farthest waypoint
- if (!this.navigation_hasgoals)
- if (autocvar_bot_wander_enable)
+ if (!this.goalentity && autocvar_bot_wander_enable)
{
if (!(this.aistatus & AI_STATUS_STUCK))
{
LOG_DEBUG(this.netname, " cannot walk to any goal");
this.aistatus |= AI_STATUS_STUCK;
}
-
- this.navigation_hasgoals = false; // Reset this value
}
}
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, NULL), STAT(PL_MAX, NULL), bot_waypoint_queue_goal.origin, bot_navigation_movemode))
+ if(tracewalk(bot_waypoint_queue_goal, this.origin, STAT(PL_MIN, this), STAT(PL_MAX, this), bot_waypoint_queue_goal.origin, bot_navigation_movemode))
{
if( d > bot_waypoint_queue_bestgoalrating)
{