]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/navigation.qc
Merge branch 'terencehill/menu_optimization' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / navigation.qc
index 99e3901b2b3cb095b771a89286c9b5ac1bcae721..2e40f09601bf5763edb90a9d82e0ffe31e9efa60 100644 (file)
@@ -1,22 +1,16 @@
 #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/triggers/trigger/jumppads.qh"
+#include <common/items/all.qh>
 
-void bot_debug(string input)
-{
-       switch(autocvar_bot_debug)
-       {
-               case 1: LOG_TRACE(input); break;
-               case 2: LOG_INFO(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
@@ -363,12 +357,12 @@ float navigation_waypoint_will_link(vector v, vector org, entity ent, float walk
                {
                        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;
                        }
                }
@@ -398,7 +392,7 @@ entity navigation_findnearestwaypoint_withdist_except(entity ent, float walkfrom
        }
 
        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;
@@ -548,7 +542,7 @@ void navigation_markroutes(entity fixed_source_waypoint)
                // 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;
@@ -700,7 +694,7 @@ void navigation_routerating(entity e, float f, float rangebias)
        {
                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);
@@ -715,13 +709,13 @@ void navigation_routerating(entity e, float f, float rangebias)
 
                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;
@@ -752,7 +746,7 @@ void navigation_routerating(entity e, float f, float rangebias)
                        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)
@@ -770,7 +764,7 @@ void navigation_routerating(entity e, float f, float rangebias)
 
                                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;
@@ -816,7 +810,7 @@ void navigation_routerating(entity e, float f, float rangebias)
                                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;
@@ -828,7 +822,7 @@ void navigation_routerating(entity e, float f, float rangebias)
 
                                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;
                                }
                        }
@@ -842,17 +836,17 @@ void navigation_routerating(entity e, float f, float rangebias)
                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;
                }
@@ -879,7 +873,7 @@ float navigation_routetogoal(entity e, vector startposition)
                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
@@ -935,7 +929,7 @@ void navigation_poptouchedgoals()
        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
@@ -1012,7 +1006,7 @@ void navigation_goalrating_end()
                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)
@@ -1020,7 +1014,7 @@ void navigation_goalrating_end()
        {
                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;
                }
 
@@ -1075,7 +1069,7 @@ void navigation_unstuck()
 
        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;
@@ -1088,8 +1082,8 @@ void navigation_unstuck()
        {
                // 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)
                        {
@@ -1103,14 +1097,14 @@ void navigation_unstuck()
                {
                        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;
@@ -1122,7 +1116,7 @@ void navigation_unstuck()
                        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;
 
@@ -1150,7 +1144,7 @@ void navigation_unstuck()
                        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;
                }
        }