float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float movemode)
{
- local vector org;
- local vector move;
- local vector dir;
- local float dist;
- local float totaldist;
- local float stepdist;
- local float yaw;
- local float ignorehazards;
- local float swimming;
+ vector org;
+ vector move;
+ vector dir;
+ float dist;
+ float totaldist;
+ float stepdist;
+ float yaw;
+ float ignorehazards;
+ float swimming;
if(autocvar_bot_debug_tracewalk)
{
dir = normalize(move);
stepdist = 32;
ignorehazards = FALSE;
+ swimming = FALSE;
// Analyze starting point
traceline(start, start, MOVE_NORMAL, e);
if (trace_fraction < 1)
{
// check if we can walk over this obstacle, possibly by jumpstepping
- tracebox(org + jumpstepheightvec, m1, m2, move + jumpstepheightvec, movemode, e);
+ tracebox(org + stepheightvec, m1, m2, move + stepheightvec, movemode, e);
if (trace_fraction < 1 || trace_startsolid)
{
- 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")
+ tracebox(org + jumpstepheightvec, m1, m2, move + jumpstepheightvec, movemode, e);
+ if (trace_fraction < 1 || trace_startsolid)
{
- local vector nextmove;
- move = trace_endpos;
- while(trace_ent.classname == "door_rotating" || trace_ent.classname == "door")
+ 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")
{
- nextmove = move + (dir * stepdist);
- traceline( move, nextmove, movemode, e);
- move = nextmove;
+ vector nextmove;
+ move = trace_endpos;
+ while(trace_ent.classname == "door_rotating" || trace_ent.classname == "door")
+ {
+ nextmove = move + (dir * stepdist);
+ traceline( move, nextmove, movemode, e);
+ move = nextmove;
+ }
}
- }
- else
- {
- if(autocvar_bot_debug_tracewalk)
- debugnodestatus(trace_endpos, DEBUG_NODE_FAIL);
+ else
+ {
+ if(autocvar_bot_debug_tracewalk)
+ debugnodestatus(trace_endpos, DEBUG_NODE_FAIL);
- //print("tracewalk: ", vtos(start), " hit something when trying to reach ", vtos(end), "\n");
- //te_explosion(trace_endpos);
- //print(ftos(e.dphitcontentsmask), "\n");
- return FALSE; // failed
+ //print("tracewalk: ", vtos(start), " hit something when trying to reach ", vtos(end), "\n");
+ //te_explosion(trace_endpos);
+ //print(ftos(e.dphitcontentsmask), "\n");
+ return FALSE; // failed
+ }
}
+ else
+ move = trace_endpos;
}
else
move = trace_endpos;
// moved successfully
if(swimming)
{
- local float c;
+ float c;
c = pointcontents(org + '0 0 1');
if not(c == CONTENT_WATER || c == CONTENT_LAVA || c == CONTENT_SLIME)
swimming = FALSE;
debugnodestatus(org, DEBUG_NODE_FAIL);
return FALSE;
-};
+}
/////////////////////////////////////////////////////////////////////////////
// goal stack
self.goalstack29 = world;
self.goalstack30 = world;
self.goalstack31 = world;
-};
+}
// add a new goal at the beginning of the stack
// (in other words: add a new prerequisite before going to the later goals)
self.goalstack02 = self.goalstack01;
self.goalstack01 = self.goalcurrent;
self.goalcurrent = e;
-};
+}
// remove first goal from stack
// (in other words: remove a prerequisite for reaching the later goals)
self.goalstack29 = self.goalstack30;
self.goalstack30 = self.goalstack31;
self.goalstack31 = world;
-};
+}
+
+float navigation_waypoint_will_link(vector v, vector org, entity ent, float walkfromwp, float bestdist)
+{
+ float dist;
+ dist = vlen(v - org);
+ if (bestdist > dist)
+ {
+ traceline(v, org, TRUE, ent);
+ if (trace_fraction == 1)
+ {
+ if (walkfromwp)
+ {
+ if (tracewalk(ent, v, PL_MIN, PL_MAX, org, bot_navigation_movemode))
+ return TRUE;
+ }
+ else
+ {
+ if (tracewalk(ent, org, PL_MIN, PL_MAX, v, bot_navigation_movemode))
+ return TRUE;
+ }
+ }
+ }
+ return FALSE;
+}
// find the spawnfunc_waypoint near a dynamic goal such as a dropped weapon
-entity navigation_findnearestwaypoint(entity ent, float walkfromwp)
+entity navigation_findnearestwaypoint_withdist(entity ent, float walkfromwp, float bestdist)
{
- local entity waylist, w, best;
- local float dist, bestdist;
- local vector v, org, pm1, pm2;
+ entity waylist, w, best;
+ vector v, org, pm1, pm2;
+
pm1 = ent.origin + ent.mins;
pm2 = ent.origin + ent.maxs;
waylist = findchain(classname, "waypoint");
te_plasmaburn(org);
best = world;
- bestdist = 1050;
// box check failed, try walk
w = waylist;
{
if (w.wpisbox)
{
- local vector wm1, wm2;
+ vector wm1, wm2;
wm1 = w.origin + w.mins;
wm2 = w.origin + w.maxs;
v_x = bound(wm1_x, org_x, wm2_x);
}
else
v = w.origin;
- dist = vlen(v - org);
- if (bestdist > dist)
+ if(navigation_waypoint_will_link(v, org, ent, walkfromwp, bestdist))
{
- traceline(v, org, TRUE, ent);
- if (trace_fraction == 1)
- {
- if (walkfromwp)
- {
- //print("^1can I reach ", vtos(org), " from ", vtos(v), "?\n");
- if (tracewalk(ent, v, PL_MIN, PL_MAX, org, bot_navigation_movemode))
- {
- bestdist = dist;
- best = w;
- }
- }
- else
- {
- if (tracewalk(ent, org, PL_MIN, PL_MAX, v, bot_navigation_movemode))
- {
- bestdist = dist;
- best = w;
- }
- }
- }
+ bestdist = vlen(v - org);
+ best = w;
}
}
w = w.chain;
}
return best;
}
+entity navigation_findnearestwaypoint(entity ent, float walkfromwp)
+{
+ return navigation_findnearestwaypoint_withdist(ent, walkfromwp, 1050);
+}
// finds the waypoints near the bot initiating a navigation query
float navigation_markroutes_nearestwaypoints(entity waylist, float maxdist)
{
- local entity head;
- local vector v, m1, m2, diff;
- local float c;
+ entity head;
+ vector v, m1, m2, diff;
+ float c;
// navigation_testtracewalk = TRUE;
c = 0;
head = waylist;
// 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)
{
- local vector m1;
- local vector m2;
- local vector v;
+ vector m1;
+ vector m2;
+ vector v;
if (wp.wpisbox)
{
m1 = wp.absmin;
wp.wpfire = 1;
wp.wpnearestpoint = v;
}
-};
+}
// queries the entire spawnfunc_waypoint network for pathes leading away from the bot
void navigation_markroutes(entity fixed_source_waypoint)
{
- local entity w, wp, waylist;
- local float searching, cost, cost2;
- local vector p;
+ entity w, wp, waylist;
+ float searching, cost, cost2;
+ vector p;
w = waylist = findchain(classname, "waypoint");
while (w)
{
{
// try a short range search for the nearest waypoints, and expand the search repeatedly if none are found
// as this search is expensive we will use lower values if the bot is on the air
- local float i, increment, maxdistance;
+ float i, increment, maxdistance;
if(self.flags & FL_ONGROUND)
{
increment = 750;
w = w.chain;
}
}
-};
+}
// queries the entire spawnfunc_waypoint network for pathes leading to the bot
void navigation_markroutes_inverted(entity fixed_source_waypoint)
{
- local entity w, wp, waylist;
- local float searching, cost, cost2;
- local vector p;
+ entity w, wp, waylist;
+ float searching, cost, cost2;
+ vector p;
w = waylist = findchain(classname, "waypoint");
while (w)
{
w = w.chain;
}
}
-};
+}
// updates the best goal according to a weighted calculation of travel cost and item value of a new proposed item
void navigation_routerating(entity e, float f, float rangebias)
if (!e)
return;
+ if(e.blacklisted)
+ return;
+
o = (e.absmin + e.absmax) * 0.5;
+
//print("routerating ", etos(e), " = ", ftos(f), " - ", ftos(rangebias), "\n");
// Evaluate path using jetpack
// dprint("jetpack ai: can bridge these two points\n");
// Lower the altitude of these points as much as possible
- local float zdistance, xydistance, cost, t, fuel;
- local vector down, npa, npb;
+ float zdistance, xydistance, cost, t, fuel;
+ vector down, npa, npb;
down = '0 0 -1' * (PL_MAX_z - PL_MIN_z) * 10;
}
else
{
+ float search;
+
+ search = TRUE;
+
+ if(e.flags & FL_ITEM)
+ {
+ if not(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)
{
nwp = navigation_findnearestwaypoint(e, TRUE);
if(nwp)
e.nearestwaypoint = nwp;
else
+ {
dprint("FAILED to find a nearest waypoint to '", e.classname, "' #", etos(e), "\n");
+ if(e.flags & FL_ITEM)
+ e.blacklisted = TRUE;
+ else if (e.flags & FL_WEAPON)
+ {
+ if(e.classname != "droppedweapon")
+ e.blacklisted = TRUE;
+ }
+
+ if(e.blacklisted)
+ {
+ dprint("The entity '", e.classname, "' is going to be excluded from path finding during this match\n");
+ return;
+ }
+ }
+
// TODO: Cleaner solution, probably handling this timeout from ctf.qc
if(e.classname=="item_flag_team")
e.nearestwaypointtimeout = time + 2;
}
}
//dprint("\n");
-};
+}
// adds an item to the the goal stack with the path to a given item
float navigation_routetogoal(entity e, vector startposition)
}
return FALSE;
-};
+}
// removes any currently touching waypoints from the goal stack
// (this is how bots detect if they reached a goal)
void navigation_poptouchedgoals()
{
- local vector org, m1, m2;
+ vector org, m1, m2;
org = self.origin;
m1 = org + self.mins;
m2 = org + self.maxs;
}
}
+ // If for some reason the bot is closer to the next goal, pop the current one
+ if(self.goalstack01)
+ if(vlen(self.goalcurrent.origin - self.origin) > vlen(self.goalstack01.origin - self.origin))
+ if(checkpvs(self.origin + self.view_ofs, self.goalstack01))
+ if(tracewalk(self, self.origin, self.mins, self.maxs, (self.goalstack01.absmin + self.goalstack01.absmax) * 0.5, bot_navigation_movemode))
+ {
+ /// dprint("path optimized for ", self.netname, ", removed a goal from the queue\n");
+ navigation_poproute();
+ // 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
+ }
+
+ // 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(self.goalcurrent.classname=="player")
+ navigation_poproute();
+
+ // aid for detecting jump pads better (distance based check fails sometimes)
+ if(self.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT && self.jumppadcount > 0 )
+ navigation_poproute();
+
// Loose goal touching check when running
if(self.aistatus & AI_STATUS_RUNNING)
+ if(self.speed >= autocvar_sv_maxspeed) // if -really- running
if(self.goalcurrent.classname=="waypoint")
{
if(vlen(self.origin - self.goalcurrent.origin)<150)
navigation_clearroute();
navigation_bestgoal = world;
navigation_markroutes(world);
-};
+}
// ends a goal selection session (updates goal stack to the best goal)
void navigation_goalrating_end()
self.navigation_hasgoals = FALSE; // Reset this value
}
-};
+}
void botframe_updatedangerousobjects(float maxupdate)
{
- local entity head, bot_dodgelist;
- local vector m1, m2, v, o;
- local float c, d, danger;
+ entity head, bot_dodgelist;
+ vector m1, m2, v, o;
+ float c, d, danger;
c = 0;
bot_dodgelist = findchainfloat(bot_dodge, TRUE);
botframe_dangerwaypoint = find(botframe_dangerwaypoint, classname, "waypoint");
break;
botframe_dangerwaypoint = find(botframe_dangerwaypoint, classname, "waypoint");
}
-};
+}
void navigation_unstuck()
{
// Debug the goal stack visually
void debuggoalstack()
{
- local entity goal;
- local vector org, go;
+ entity goal;
+ vector org, go;
if(self.goalcounter==0)goal=self.goalcurrent;
else if(self.goalcounter==1)goal=self.goalstack01;
else if(self.goalcounter==29)goal=self.goalstack29;
else if(self.goalcounter==30)goal=self.goalstack30;
else if(self.goalcounter==31)goal=self.goalstack31;
+ else goal=world;
if(goal==world)
{