#include "navigation.qh"
-#include "../_all.qh"
#include "bot.qh"
#include "waypoints.qh"
-#include "../t_items.qh"
+#include <common/t_items.qh>
-#include "../../common/constants.qh"
+#include <common/items/all.qh>
-void bot_debug(string input)
-{
- switch(autocvar_bot_debug)
- {
- case 1: dprint(input); break;
- case 2: print(input); break;
- }
-}
+#include <common/constants.qh>
+#include <common/triggers/trigger/jumppads.qh>
+
+.float speed;
// rough simulation of walking from one point to another to test if a path
// can be traveled, used for waypoint linking and havocbot
float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float movemode)
-{
+{SELFPARAM();
vector org;
vector move;
vector dir;
// completely empty the goal stack, used when deciding where to go
void navigation_clearroute()
-{
+{SELFPARAM();
//print("bot ", etos(self), " clear\n");
self.navigation_hasgoals = false;
self.goalcurrent = world;
// That means, if the stack overflows, the bot will know how to do the FIRST 32
// steps to the goal, and then recalculate the path.
void navigation_pushroute(entity e)
-{
+{SELFPARAM();
//print("bot ", etos(self), " push ", etos(e), "\n");
self.goalstack31 = self.goalstack30;
self.goalstack30 = self.goalstack29;
// (in other words: remove a prerequisite for reaching the later goals)
// (used when a spawnfunc_waypoint is reached)
void navigation_poproute()
-{
+{SELFPARAM();
//print("bot ", etos(self), " pop\n");
self.goalcurrent = self.goalstack01;
self.goalstack01 = self.goalstack02;
{
if (walkfromwp)
{
- if (tracewalk(ent, v, PL_MIN, PL_MAX, org, bot_navigation_movemode))
+ if (tracewalk(ent, v, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), org, bot_navigation_movemode))
return true;
}
else
{
- if (tracewalk(ent, org, PL_MIN, PL_MAX, v, bot_navigation_movemode))
+ if (tracewalk(ent, org, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), v, bot_navigation_movemode))
return true;
}
}
}
org = ent.origin + 0.5 * (ent.mins + ent.maxs);
- org.z = ent.origin.z + ent.mins.z - PL_MIN_z; // player height
+ org.z = ent.origin.z + ent.mins.z - STAT(PL_MIN, NULL).z; // player height
// TODO possibly make other code have the same support for bboxes
if(ent.tag_entity)
org = org + ent.tag_entity.origin;
// finds the waypoints near the bot initiating a navigation query
float navigation_markroutes_nearestwaypoints(entity waylist, float maxdist)
-{
+{SELFPARAM();
entity head;
vector v, m1, m2, diff;
float c;
// queries the entire spawnfunc_waypoint network for pathes leading away from the bot
void navigation_markroutes(entity fixed_source_waypoint)
-{
+{SELFPARAM();
entity w, wp, waylist;
float searching, cost, cost2;
vector p;
// 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
float i, increment, maxdistance;
- if(self.flags & FL_ONGROUND)
+ if(IS_ONGROUND(self))
{
increment = 750;
maxdistance = 50000;
// 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)
-{
+{SELFPARAM();
entity nwp;
vector o;
if (!e)
{
vector pointa, pointb;
- bot_debug(strcat("jetpack ai: evaluating path for ", e.classname, "\n"));
+ LOG_DEBUG("jetpack ai: evaluating path for ", e.classname, "\n");
// Point A
traceline(self.origin, self.origin + '0 0 65535', MOVE_NORMAL, self);
if(trace_fraction==1)
{
- bot_debug("jetpack ai: can bridge these two points\n");
+ LOG_DEBUG("jetpack ai: can bridge these two points\n");
// Lower the altitude of these points as much as possible
float zdistance, xydistance, cost, t, fuel;
vector down, npa, npb;
- down = '0 0 -1' * (PL_MAX_z - PL_MIN_z) * 10;
+ down = '0 0 -1' * (STAT(PL_MAX, NULL).z - STAT(PL_MIN, NULL).z) * 10;
do{
npa = pointa + down;
t += xydistance / autocvar_g_jetpack_maxspeed_side;
fuel = t * autocvar_g_jetpack_fuel * 0.8;
- bot_debug(strcat("jetpack ai: required fuel ", ftos(fuel), " self.ammo_fuel ", ftos(self.ammo_fuel), "\n"));
+ LOG_DEBUG(strcat("jetpack ai: required fuel ", ftos(fuel), " self.ammo_fuel ", ftos(self.ammo_fuel), "\n"));
// enough fuel ?
if(self.ammo_fuel>fuel)
if (navigation_bestrating < f)
{
- bot_debug(strcat("jetpack path: added goal ", e.classname, " (with rating ", ftos(f), ")\n"));
+ LOG_DEBUG(strcat("jetpack path: added goal ", e.classname, " (with rating ", ftos(f), ")\n"));
navigation_bestrating = f;
navigation_bestgoal = e;
self.navigation_jetpack_goal = e;
e.nearestwaypoint = nwp;
else
{
- bot_debug(strcat("FAILED to find a nearest waypoint to '", e.classname, "' #", etos(e), "\n"));
+ LOG_DEBUG(strcat("FAILED to find a nearest waypoint to '", e.classname, "' #", etos(e), "\n"));
if(e.flags & FL_ITEM)
e.blacklisted = true;
if(e.blacklisted)
{
- bot_debug(strcat("The entity '", e.classname, "' is going to be excluded from path finding during this match\n"));
+ LOG_DEBUG(strcat("The entity '", e.classname, "' is going to be excluded from path finding during this match\n"));
return;
}
}
nwp = e.nearestwaypoint;
}
- bot_debug(strcat("-- checking ", e.classname, " (with cost ", ftos(nwp.wpcost), ")\n"));
+ LOG_DEBUG(strcat("-- checking ", e.classname, " (with cost ", ftos(nwp.wpcost), ")\n"));
if (nwp)
if (nwp.wpcost < 10000000)
{
//te_wizspike(nwp.wpnearestpoint);
- bot_debug(strcat(e.classname, " ", ftos(f), "/(1+", ftos((nwp.wpcost + vlen(e.origin - nwp.wpnearestpoint))), "/", ftos(rangebias), ") = "));
+ LOG_DEBUG(strcat(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)));
- bot_debug(strcat("considering ", e.classname, " (with rating ", ftos(f), ")\n"));
+ LOG_DEBUG(strcat("considering ", e.classname, " (with rating ", ftos(f), ")\n"));
if (navigation_bestrating < f)
{
- bot_debug(strcat("ground path: added goal ", e.classname, " (with rating ", ftos(f), ")\n"));
+ LOG_DEBUG(strcat("ground path: added goal ", e.classname, " (with rating ", ftos(f), ")\n"));
navigation_bestrating = f;
navigation_bestgoal = e;
}
// adds an item to the the goal stack with the path to a given item
float navigation_routetogoal(entity e, vector startposition)
-{
+{SELFPARAM();
self.goalentity = e;
// if there is no goal, just exit
return true;
// if it can reach the goal there is nothing more to do
- if (tracewalk(self, startposition, PL_MIN, PL_MAX, (e.absmin + e.absmax) * 0.5, bot_navigation_movemode))
+ if (tracewalk(self, startposition, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), (e.absmin + e.absmax) * 0.5, bot_navigation_movemode))
return true;
// see if there are waypoints describing a path to the item
// removes any currently touching waypoints from the goal stack
// (this is how bots detect if they reached a goal)
void navigation_poptouchedgoals()
-{
+{SELFPARAM();
vector org, m1, m2;
org = self.origin;
m1 = org + self.mins;
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))
{
- bot_debug(strcat("path optimized for ", self.netname, ", removed a goal from the queue\n"));
+ LOG_DEBUG(strcat("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
// begin a goal selection session (queries spawnfunc_waypoint network)
void navigation_goalrating_start()
-{
+{SELFPARAM();
if(self.aistatus & AI_STATUS_STUCK)
return;
// ends a goal selection session (updates goal stack to the best goal)
void navigation_goalrating_end()
-{
+{SELFPARAM();
if(self.aistatus & AI_STATUS_STUCK)
return;
navigation_routetogoal(navigation_bestgoal, self.origin);
- bot_debug(strcat("best goal ", self.goalcurrent.classname , "\n"));
+ LOG_DEBUG(strcat("best goal ", self.goalcurrent.classname , "\n"));
// If the bot got stuck then try to reach the farthest waypoint
if (!self.navigation_hasgoals)
{
if (!(self.aistatus & AI_STATUS_STUCK))
{
- bot_debug(strcat(self.netname, " cannot walk to any goal\n"));
+ LOG_DEBUG(strcat(self.netname, " cannot walk to any goal\n"));
self.aistatus |= AI_STATUS_STUCK;
}
}
void navigation_unstuck()
-{
+{SELFPARAM();
float search_radius = 1000;
if (!autocvar_bot_wander_enable)
if (!bot_waypoint_queue_owner)
{
- bot_debug(strcat(self.netname, " sutck, taking over the waypoints queue\n"));
+ LOG_DEBUG(strcat(self.netname, " sutck, taking over the waypoints queue\n"));
bot_waypoint_queue_owner = self;
bot_waypoint_queue_bestgoal = world;
bot_waypoint_queue_bestgoalrating = 0;
{
// evaluate the next goal on the queue
float d = vlen(self.origin - bot_waypoint_queue_goal.origin);
- bot_debug(strcat(self.netname, " evaluating ", bot_waypoint_queue_goal.classname, " with distance ", ftos(d), "\n"));
- if(tracewalk(bot_waypoint_queue_goal, self.origin, PL_MIN, PL_MAX, bot_waypoint_queue_goal.origin, bot_navigation_movemode))
+ LOG_DEBUG(strcat(self.netname, " evaluating ", bot_waypoint_queue_goal.classname, " with distance ", ftos(d), "\n"));
+ if(tracewalk(bot_waypoint_queue_goal, self.origin, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), bot_waypoint_queue_goal.origin, bot_navigation_movemode))
{
if( d > bot_waypoint_queue_bestgoalrating)
{
{
if (bot_waypoint_queue_bestgoal)
{
- bot_debug(strcat(self.netname, " stuck, reachable waypoint found, heading to it\n"));
+ LOG_DEBUG(strcat(self.netname, " stuck, reachable waypoint found, heading to it\n"));
navigation_routetogoal(bot_waypoint_queue_bestgoal, self.origin);
self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
self.aistatus &= ~AI_STATUS_STUCK;
}
else
{
- bot_debug(strcat(self.netname, " stuck, cannot walk to any waypoint at all\n"));
+ LOG_DEBUG(strcat(self.netname, " stuck, cannot walk to any waypoint at all\n"));
}
bot_waypoint_queue_owner = world;
return;
// build a new queue
- bot_debug(strcat(self.netname, " stuck, scanning reachable waypoints within ", ftos(search_radius)," qu\n"));
+ LOG_DEBUG(strcat(self.netname, " stuck, scanning reachable waypoints within ", ftos(search_radius)," qu\n"));
entity head, first;
bot_waypoint_queue_goal = first;
else
{
- bot_debug(strcat(self.netname, " stuck, cannot walk to any waypoint at all\n"));
+ LOG_DEBUG(strcat(self.netname, " stuck, cannot walk to any waypoint at all\n"));
bot_waypoint_queue_owner = world;
}
}
}
void debugnode(vector node)
-{
+{SELFPARAM();
if (!IS_PLAYER(self))
return;
// Debug the goal stack visually
void debuggoalstack()
-{
+{SELFPARAM();
entity goal;
vector org, go;