.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;
+ entity tw_ladder = NULL;
if(autocvar_bot_debug_tracewalk)
{
}
// Movement loop
- yaw = vectoyaw(move);
move = end - org;
for (;;)
{
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)
if(autocvar_bot_debug_tracewalk)
debugnodestatus(trace_endpos, DEBUG_NODE_WARNING);
- // check for doors
+ FOREACH_ENTITY_CLASS("func_ladder", true,
+ { it.solid = SOLID_BSP; });
+
traceline( org, move, movemode, e);
+
+ FOREACH_ENTITY_CLASS("func_ladder", true,
+ { 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");
void navigation_clearroute(entity this)
{
//print("bot ", etos(this), " clear\n");
- this.navigation_hasgoals = false;
this.goalentity = NULL;
this.goalcurrent = NULL;
this.goalstack01 = NULL;
}
else
{
- float search;
-
- 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)
{
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;
}
nwp = e.nearestwaypoint;
}
// 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");
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(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
m1 = org + this.mins;
m2 = org + this.maxs;
- while(this.goalcurrent && wasfreed(this.goalcurrent))
- navigation_poproute(this);
-
if(this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT)
{
// make sure jumppad is really hit, don't rely on distance based checks
}
}
- while (this.goalcurrent && !IS_PLAYER(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;
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
}
}