#include "bot.qh"
#include "waypoints.qh"
-#include "../../common/t_items.qh"
+#include <common/t_items.qh>
-#include "../../common/items/all.qh"
+#include <common/items/all.qh>
-#include "../../common/constants.qh"
-#include "../../common/triggers/trigger/jumppads.qh"
+#include <common/constants.qh>
+#include <common/triggers/trigger/jumppads.qh>
.float speed;
-void bot_debug(string input)
-{
- switch(autocvar_bot_debug)
- {
- case 1: LOG_TRACE(input); break;
- case 2: LOG_INFO(input); break;
- }
-}
-
// rough simulation of walking from one point to another to test if a path
// can be traveled, used for waypoint linking and havocbot
/////////////////////////////////////////////////////////////////////////////
// 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;
- self.goalstack01 = world;
- self.goalstack02 = world;
- self.goalstack03 = world;
- self.goalstack04 = world;
- self.goalstack05 = world;
- self.goalstack06 = world;
- self.goalstack07 = world;
- self.goalstack08 = world;
- self.goalstack09 = world;
- self.goalstack10 = world;
- self.goalstack11 = world;
- self.goalstack12 = world;
- self.goalstack13 = world;
- self.goalstack14 = world;
- self.goalstack15 = world;
- self.goalstack16 = world;
- self.goalstack17 = world;
- self.goalstack18 = world;
- self.goalstack19 = world;
- self.goalstack20 = world;
- self.goalstack21 = world;
- self.goalstack22 = world;
- self.goalstack23 = world;
- self.goalstack24 = world;
- self.goalstack25 = world;
- self.goalstack26 = world;
- self.goalstack27 = world;
- self.goalstack28 = world;
- self.goalstack29 = world;
- self.goalstack30 = world;
- self.goalstack31 = world;
+void navigation_clearroute(entity this)
+{
+ //print("bot ", etos(this), " clear\n");
+ this.navigation_hasgoals = false;
+ this.goalcurrent = world;
+ this.goalstack01 = world;
+ this.goalstack02 = world;
+ this.goalstack03 = world;
+ this.goalstack04 = world;
+ this.goalstack05 = world;
+ this.goalstack06 = world;
+ this.goalstack07 = world;
+ this.goalstack08 = world;
+ this.goalstack09 = world;
+ this.goalstack10 = world;
+ this.goalstack11 = world;
+ this.goalstack12 = world;
+ this.goalstack13 = world;
+ this.goalstack14 = world;
+ this.goalstack15 = world;
+ this.goalstack16 = world;
+ this.goalstack17 = world;
+ this.goalstack18 = world;
+ this.goalstack19 = world;
+ this.goalstack20 = world;
+ this.goalstack21 = world;
+ this.goalstack22 = world;
+ this.goalstack23 = world;
+ this.goalstack24 = world;
+ this.goalstack25 = world;
+ this.goalstack26 = world;
+ this.goalstack27 = world;
+ this.goalstack28 = world;
+ this.goalstack29 = world;
+ this.goalstack30 = world;
+ this.goalstack31 = world;
}
// add a new goal at the beginning of the stack
// next-closest WP on the shortest path to the WP
// 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;
- self.goalstack29 = self.goalstack28;
- self.goalstack28 = self.goalstack27;
- self.goalstack27 = self.goalstack26;
- self.goalstack26 = self.goalstack25;
- self.goalstack25 = self.goalstack24;
- self.goalstack24 = self.goalstack23;
- self.goalstack23 = self.goalstack22;
- self.goalstack22 = self.goalstack21;
- self.goalstack21 = self.goalstack20;
- self.goalstack20 = self.goalstack19;
- self.goalstack19 = self.goalstack18;
- self.goalstack18 = self.goalstack17;
- self.goalstack17 = self.goalstack16;
- self.goalstack16 = self.goalstack15;
- self.goalstack15 = self.goalstack14;
- self.goalstack14 = self.goalstack13;
- self.goalstack13 = self.goalstack12;
- self.goalstack12 = self.goalstack11;
- self.goalstack11 = self.goalstack10;
- self.goalstack10 = self.goalstack09;
- self.goalstack09 = self.goalstack08;
- self.goalstack08 = self.goalstack07;
- self.goalstack07 = self.goalstack06;
- self.goalstack06 = self.goalstack05;
- self.goalstack05 = self.goalstack04;
- self.goalstack04 = self.goalstack03;
- self.goalstack03 = self.goalstack02;
- self.goalstack02 = self.goalstack01;
- self.goalstack01 = self.goalcurrent;
- self.goalcurrent = e;
+void navigation_pushroute(entity this, entity e)
+{
+ //print("bot ", etos(this), " push ", etos(e), "\n");
+ this.goalstack31 = this.goalstack30;
+ this.goalstack30 = this.goalstack29;
+ this.goalstack29 = this.goalstack28;
+ this.goalstack28 = this.goalstack27;
+ this.goalstack27 = this.goalstack26;
+ this.goalstack26 = this.goalstack25;
+ this.goalstack25 = this.goalstack24;
+ this.goalstack24 = this.goalstack23;
+ this.goalstack23 = this.goalstack22;
+ this.goalstack22 = this.goalstack21;
+ this.goalstack21 = this.goalstack20;
+ this.goalstack20 = this.goalstack19;
+ this.goalstack19 = this.goalstack18;
+ this.goalstack18 = this.goalstack17;
+ this.goalstack17 = this.goalstack16;
+ this.goalstack16 = this.goalstack15;
+ this.goalstack15 = this.goalstack14;
+ this.goalstack14 = this.goalstack13;
+ this.goalstack13 = this.goalstack12;
+ this.goalstack12 = this.goalstack11;
+ this.goalstack11 = this.goalstack10;
+ this.goalstack10 = this.goalstack09;
+ this.goalstack09 = this.goalstack08;
+ this.goalstack08 = this.goalstack07;
+ this.goalstack07 = this.goalstack06;
+ this.goalstack06 = this.goalstack05;
+ this.goalstack05 = this.goalstack04;
+ this.goalstack04 = this.goalstack03;
+ this.goalstack03 = this.goalstack02;
+ this.goalstack02 = this.goalstack01;
+ this.goalstack01 = this.goalcurrent;
+ this.goalcurrent = e;
}
// remove first goal from stack
{
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;
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;
+bool navigation_routetogoal(entity this, entity e, vector startposition)
+{
+ this.goalentity = e;
// if there is no goal, just exit
if (!e)
return false;
- self.navigation_hasgoals = true;
+ this.navigation_hasgoals = true;
// put the entity on the goal stack
//print("routetogoal ", etos(e), "\n");
- navigation_pushroute(e);
+ navigation_pushroute(this, e);
if(g_jetpack)
- if(e==self.navigation_jetpack_goal)
+ if(e==this.navigation_jetpack_goal)
return true;
// if it can reach the goal there is nothing more to do
- if (tracewalk(self, 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, 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
for (;;)
{
// add the spawnfunc_waypoint to the path
- navigation_pushroute(e);
+ navigation_pushroute(this, e);
e = e.enemy;
if(e==world)
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
self.navigation_jetpack_goal = world;
navigation_bestrating = -1;
self.navigation_hasgoals = false;
- navigation_clearroute();
+ navigation_clearroute(self);
navigation_bestgoal = world;
navigation_markroutes(world);
}
if(self.aistatus & AI_STATUS_STUCK)
return;
- navigation_routetogoal(navigation_bestgoal, self.origin);
- bot_debug(strcat("best goal ", self.goalcurrent.classname , "\n"));
+ navigation_routetogoal(self, navigation_bestgoal, self.origin);
+ 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();
+void navigation_unstuck(entity this)
+{
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"));
- bot_waypoint_queue_owner = self;
+ LOG_DEBUG(strcat(this.netname, " sutck, taking over the waypoints queue\n"));
+ bot_waypoint_queue_owner = this;
bot_waypoint_queue_bestgoal = world;
bot_waypoint_queue_bestgoalrating = 0;
}
- if(bot_waypoint_queue_owner!=self)
+ if(bot_waypoint_queue_owner!=this)
return;
if (bot_waypoint_queue_goal)
{
// 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, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), bot_waypoint_queue_goal.origin, bot_navigation_movemode))
+ float d = vlen(this.origin - bot_waypoint_queue_goal.origin);
+ LOG_DEBUG(strcat(this.netname, " evaluating ", bot_waypoint_queue_goal.classname, " with distance ", ftos(d), "\n"));
+ entity oldself = self;
+ setself(this); // tracewalk has questionable use of self
+ 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( d > bot_waypoint_queue_bestgoalrating)
{
bot_waypoint_queue_bestgoal = bot_waypoint_queue_goal;
}
}
+ setself(oldself);
bot_waypoint_queue_goal = bot_waypoint_queue_goal.bot_waypoint_queue_nextgoal;
if (!bot_waypoint_queue_goal)
{
if (bot_waypoint_queue_bestgoal)
{
- bot_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;
+ LOG_DEBUG(strcat(this.netname, " stuck, reachable waypoint found, heading to it\n"));
+ navigation_routetogoal(this, bot_waypoint_queue_bestgoal, this.origin);
+ this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
+ this.aistatus &= ~AI_STATUS_STUCK;
}
else
{
- bot_debug(strcat(self.netname, " stuck, cannot walk to any waypoint at all\n"));
+ LOG_DEBUG(strcat(this.netname, " stuck, cannot walk to any waypoint at all\n"));
}
bot_waypoint_queue_owner = world;
}
else
{
- if(bot_strategytoken!=self)
+ if(bot_strategytoken!=this)
return;
// build a new queue
- bot_debug(strcat(self.netname, " stuck, scanning reachable waypoints within ", ftos(search_radius)," qu\n"));
+ LOG_DEBUG(strcat(this.netname, " stuck, scanning reachable waypoints within ", ftos(search_radius)," qu\n"));
entity head, first;
first = world;
- head = findradius(self.origin, search_radius);
+ head = findradius(this.origin, search_radius);
while(head)
{
bot_waypoint_queue_goal = first;
else
{
- bot_debug(strcat(self.netname, " stuck, cannot walk to any waypoint at all\n"));
+ LOG_DEBUG(strcat(this.netname, " stuck, cannot walk to any waypoint at all\n"));
bot_waypoint_queue_owner = world;
}
}
.vector lastposition;
// Debug the goal stack visually
-void debuggoalstack()
-{SELFPARAM();
+void debuggoalstack(entity this)
+{
entity goal;
vector org, go;
- if(self.goalcounter==0)goal=self.goalcurrent;
- else if(self.goalcounter==1)goal=self.goalstack01;
- else if(self.goalcounter==2)goal=self.goalstack02;
- else if(self.goalcounter==3)goal=self.goalstack03;
- else if(self.goalcounter==4)goal=self.goalstack04;
- else if(self.goalcounter==5)goal=self.goalstack05;
- else if(self.goalcounter==6)goal=self.goalstack06;
- else if(self.goalcounter==7)goal=self.goalstack07;
- else if(self.goalcounter==8)goal=self.goalstack08;
- else if(self.goalcounter==9)goal=self.goalstack09;
- else if(self.goalcounter==10)goal=self.goalstack10;
- else if(self.goalcounter==11)goal=self.goalstack11;
- else if(self.goalcounter==12)goal=self.goalstack12;
- else if(self.goalcounter==13)goal=self.goalstack13;
- else if(self.goalcounter==14)goal=self.goalstack14;
- else if(self.goalcounter==15)goal=self.goalstack15;
- else if(self.goalcounter==16)goal=self.goalstack16;
- else if(self.goalcounter==17)goal=self.goalstack17;
- else if(self.goalcounter==18)goal=self.goalstack18;
- else if(self.goalcounter==19)goal=self.goalstack19;
- else if(self.goalcounter==20)goal=self.goalstack20;
- else if(self.goalcounter==21)goal=self.goalstack21;
- else if(self.goalcounter==22)goal=self.goalstack22;
- else if(self.goalcounter==23)goal=self.goalstack23;
- else if(self.goalcounter==24)goal=self.goalstack24;
- else if(self.goalcounter==25)goal=self.goalstack25;
- else if(self.goalcounter==26)goal=self.goalstack26;
- else if(self.goalcounter==27)goal=self.goalstack27;
- else if(self.goalcounter==28)goal=self.goalstack28;
- else if(self.goalcounter==29)goal=self.goalstack29;
- else if(self.goalcounter==30)goal=self.goalstack30;
- else if(self.goalcounter==31)goal=self.goalstack31;
+ if(this.goalcounter==0)goal=this.goalcurrent;
+ else if(this.goalcounter==1)goal=this.goalstack01;
+ else if(this.goalcounter==2)goal=this.goalstack02;
+ else if(this.goalcounter==3)goal=this.goalstack03;
+ else if(this.goalcounter==4)goal=this.goalstack04;
+ else if(this.goalcounter==5)goal=this.goalstack05;
+ else if(this.goalcounter==6)goal=this.goalstack06;
+ else if(this.goalcounter==7)goal=this.goalstack07;
+ else if(this.goalcounter==8)goal=this.goalstack08;
+ else if(this.goalcounter==9)goal=this.goalstack09;
+ else if(this.goalcounter==10)goal=this.goalstack10;
+ else if(this.goalcounter==11)goal=this.goalstack11;
+ else if(this.goalcounter==12)goal=this.goalstack12;
+ else if(this.goalcounter==13)goal=this.goalstack13;
+ else if(this.goalcounter==14)goal=this.goalstack14;
+ else if(this.goalcounter==15)goal=this.goalstack15;
+ else if(this.goalcounter==16)goal=this.goalstack16;
+ else if(this.goalcounter==17)goal=this.goalstack17;
+ else if(this.goalcounter==18)goal=this.goalstack18;
+ else if(this.goalcounter==19)goal=this.goalstack19;
+ else if(this.goalcounter==20)goal=this.goalstack20;
+ else if(this.goalcounter==21)goal=this.goalstack21;
+ else if(this.goalcounter==22)goal=this.goalstack22;
+ else if(this.goalcounter==23)goal=this.goalstack23;
+ else if(this.goalcounter==24)goal=this.goalstack24;
+ else if(this.goalcounter==25)goal=this.goalstack25;
+ else if(this.goalcounter==26)goal=this.goalstack26;
+ else if(this.goalcounter==27)goal=this.goalstack27;
+ else if(this.goalcounter==28)goal=this.goalstack28;
+ else if(this.goalcounter==29)goal=this.goalstack29;
+ else if(this.goalcounter==30)goal=this.goalstack30;
+ else if(this.goalcounter==31)goal=this.goalstack31;
else goal=world;
if(goal==world)
{
- self.goalcounter = 0;
- self.lastposition='0 0 0';
+ this.goalcounter = 0;
+ this.lastposition='0 0 0';
return;
}
- if(self.lastposition=='0 0 0')
- org = self.origin;
+ if(this.lastposition=='0 0 0')
+ org = this.origin;
else
- org = self.lastposition;
+ org = this.lastposition;
go = ( goal.absmin + goal.absmax ) * 0.5;
te_lightning2(world, org, go);
- self.lastposition = go;
+ this.lastposition = go;
- self.goalcounter++;
+ this.goalcounter++;
}