]> 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 d98a9ab79b6ef09f8d8a0794579436799fd948c6..2e40f09601bf5763edb90a9d82e0ffe31e9efa60 100644 (file)
@@ -1,17 +1,22 @@
-void bot_debug(string input)
-{
-       switch(autocvar_bot_debug)
-       {
-               case 1: dprint(input); break;
-               case 2: print(input); break;
-       }
-}
+#include "navigation.qh"
+
+#include "bot.qh"
+#include "waypoints.qh"
+
+#include <common/t_items.qh>
+
+#include <common/items/all.qh>
+
+#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;
@@ -29,7 +34,7 @@ float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float
        }
 
        move = end - start;
-       move_z = 0;
+       move.z = 0;
        org = start;
        dist = totaldist = vlen(move);
        dir = normalize(move);
@@ -64,7 +69,7 @@ float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float
        // Movement loop
        yaw = vectoyaw(move);
        move = end - org;
-       for(0;;)
+       for (;;)
        {
                if (boxesoverlap(end, end, org + m1 + '-1 -1 -1', org + m2 + '1 1 1'))
                {
@@ -108,7 +113,7 @@ float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float
                        {
                                swimming = true;
                                org = trace_endpos - normalize(org - trace_endpos) * stepdist;
-                               for(0; org.z < end.z + self.maxs.z; org.z += stepdist)
+                               for (; org.z < end.z + self.maxs.z; org.z += stepdist)
                                {
                                                if(autocvar_bot_debug_tracewalk)
                                                        debugnode(org);
@@ -221,7 +226,7 @@ float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float
 
 // 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;
@@ -265,7 +270,7 @@ void navigation_clearroute()
 // 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;
@@ -305,7 +310,7 @@ void navigation_pushroute(entity e)
 // (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;
@@ -352,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;
                        }
                }
@@ -387,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;
@@ -408,9 +413,9 @@ entity navigation_findnearestwaypoint_withdist_except(entity ent, float walkfrom
                                vector wm1, wm2;
                                wm1 = w.origin + w.mins;
                                wm2 = w.origin + w.maxs;
-                               v_x = bound(wm1_x, org.x, wm2_x);
-                               v_y = bound(wm1_y, org.y, wm2_y);
-                               v_z = bound(wm1_z, org.z, wm2_z);
+                               v.x = bound(wm1_x, org.x, wm2_x);
+                               v.y = bound(wm1_y, org.y, wm2_y);
+                               v.z = bound(wm1_z, org.z, wm2_z);
                        }
                        else
                                v = w.origin;
@@ -438,7 +443,7 @@ entity navigation_findnearestwaypoint(entity ent, float walkfromwp)
 
 // 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;
@@ -454,14 +459,14 @@ float navigation_markroutes_nearestwaypoints(entity waylist, float maxdist)
                                m1 = head.origin + head.mins;
                                m2 = head.origin + head.maxs;
                                v = self.origin;
-                               v_x = bound(m1_x, v.x, m2_x);
-                               v_y = bound(m1_y, v.y, m2_y);
-                               v_z = bound(m1_z, v.z, m2_z);
+                               v.x = bound(m1_x, v.x, m2_x);
+                               v.y = bound(m1_y, v.y, m2_y);
+                               v.z = bound(m1_z, v.z, m2_z);
                        }
                        else
                                v = head.origin;
                        diff = v - self.origin;
-                       diff_z = max(0, diff.z);
+                       diff.z = max(0, diff.z);
                        if (vlen(diff) < maxdist)
                        {
                                head.wpconsidered = true;
@@ -491,9 +496,9 @@ void navigation_markroutes_checkwaypoint(entity w, entity wp, float cost2, vecto
        {
                m1 = wp.absmin;
                m2 = wp.absmax;
-               v_x = bound(m1_x, p.x, m2_x);
-               v_y = bound(m1_y, p.y, m2_y);
-               v_z = bound(m1_z, p.z, m2_z);
+               v.x = bound(m1_x, p.x, m2_x);
+               v.y = bound(m1_y, p.y, m2_y);
+               v.z = bound(m1_z, p.z, m2_z);
        }
        else
                v = wp.origin;
@@ -509,7 +514,7 @@ void navigation_markroutes_checkwaypoint(entity w, entity wp, float cost2, vecto
 
 // 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;
@@ -537,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;
@@ -668,7 +673,7 @@ void navigation_markroutes_inverted(entity fixed_source_waypoint)
 
 // 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)
@@ -689,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);
@@ -704,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;
@@ -741,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)
@@ -759,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;
@@ -805,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;
@@ -817,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;
                                }
                        }
@@ -831,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;
                }
@@ -850,7 +855,7 @@ void navigation_routerating(entity e, float f, float rangebias)
 
 // 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
@@ -868,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
@@ -880,7 +885,7 @@ float navigation_routetogoal(entity e, vector startposition)
        if(e == world)
                return false;
 
-       for(0;;)
+       for (;;)
        {
                // add the spawnfunc_waypoint to the path
                navigation_pushroute(e);
@@ -896,7 +901,7 @@ float navigation_routetogoal(entity e, vector startposition)
 // 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;
@@ -924,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
@@ -982,7 +987,7 @@ void navigation_poptouchedgoals()
 
 // begin a goal selection session (queries spawnfunc_waypoint network)
 void navigation_goalrating_start()
-{
+{SELFPARAM();
        if(self.aistatus & AI_STATUS_STUCK)
                return;
 
@@ -996,12 +1001,12 @@ void navigation_goalrating_start()
 
 // 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)
@@ -1009,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;
                }
 
@@ -1034,9 +1039,9 @@ void botframe_updatedangerousobjects(float maxupdate)
                while (head)
                {
                        v = head.origin;
-                       v_x = bound(m1_x, v.x, m2_x);
-                       v_y = bound(m1_y, v.y, m2_y);
-                       v_z = bound(m1_z, v.z, m2_z);
+                       v.x = bound(m1_x, v.x, m2_x);
+                       v.y = bound(m1_y, v.y, m2_y);
+                       v.z = bound(m1_z, v.z, m2_z);
                        o = (head.absmin + head.absmax) * 0.5;
                        d = head.bot_dodgerating - vlen(o - v);
                        if (d > 0)
@@ -1056,7 +1061,7 @@ void botframe_updatedangerousobjects(float maxupdate)
 }
 
 void navigation_unstuck()
-{
+{SELFPARAM();
        float search_radius = 1000;
 
        if (!autocvar_bot_wander_enable)
@@ -1064,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;
@@ -1077,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)
                        {
@@ -1092,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;
@@ -1111,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;
 
@@ -1139,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;
                }
        }
@@ -1153,7 +1158,7 @@ void debugresetnodes()
 }
 
 void debugnode(vector node)
-{
+{SELFPARAM();
        if (!IS_PLAYER(self))
                return;
 
@@ -1196,7 +1201,7 @@ void debugnodestatus(vector position, float status)
 
 // Debug the goal stack visually
 void debuggoalstack()
-{
+{SELFPARAM();
        entity goal;
        vector org, go;