]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/navigation.qc
Merge branch 'master' into Mario/vaporizer_damage
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / navigation.qc
index 0f4c330ed8882b2037a6e99bb5f7652d76a421bb..72729ec8671bdbcf8a264295188ba89531f00b7d 100644 (file)
@@ -1,9 +1,20 @@
+#include "navigation.qh"
+#include "../_all.qh"
+
+#include "bot.qh"
+#include "waypoints.qh"
+
+#include "../t_items.qh"
+
+#include "../../common/constants.qh"
+#include "../../common/triggers/trigger/jumppads.qh"
+
 void bot_debug(string input)
 {
        switch(autocvar_bot_debug)
        {
-               case 1: dprint(input); break;
-               case 2: print(input); break;
+               case 1: LOG_TRACE(input); break;
+               case 2: LOG_INFO(input); break;
        }
 }
 
@@ -29,25 +40,25 @@ 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);
        stepdist = 32;
-       ignorehazards = FALSE;
-       swimming = FALSE;
+       ignorehazards = false;
+       swimming = false;
 
        // Analyze starting point
        traceline(start, start, MOVE_NORMAL, e);
        if (trace_dpstartcontents & (DPCONTENTS_SLIME | DPCONTENTS_LAVA))
-               ignorehazards = TRUE;
+               ignorehazards = true;
        else
        {
                traceline( start, start + '0 0 -65536', MOVE_NORMAL, e);
                if (trace_dpstartcontents & (DPCONTENTS_SLIME | DPCONTENTS_LAVA))
                {
-                       ignorehazards = TRUE;
-                       swimming = TRUE;
+                       ignorehazards = true;
+                       swimming = true;
                }
        }
        tracebox(start, m1, m2, start, MOVE_NOMONSTERS, e);
@@ -58,7 +69,7 @@ float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float
                        debugnodestatus(start, DEBUG_NODE_FAIL);
 
                //print("tracewalk: ", vtos(start), " is a bad start\n");
-               return FALSE;
+               return false;
        }
 
        // Movement loop
@@ -73,7 +84,7 @@ float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float
                                debugnodestatus(org, DEBUG_NODE_SUCCESS);
 
                        //print("tracewalk: ", vtos(start), " can reach ", vtos(end), "\n");
-                       return TRUE;
+                       return true;
                }
                if(autocvar_bot_debug_tracewalk)
                        debugnode(org);
@@ -93,7 +104,7 @@ float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float
                                        debugnodestatus(org, DEBUG_NODE_FAIL);
 
                                //print("tracewalk: ", vtos(start), " hits a hazard when trying to reach ", vtos(end), "\n");
-                               return FALSE;
+                               return false;
                        }
                }
                if (trace_dpstartcontents & DPCONTENTS_LIQUIDSMASK)
@@ -106,9 +117,9 @@ float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float
 
                        if (trace_fraction < 1)
                        {
-                               swimming = TRUE;
+                               swimming = true;
                                org = trace_endpos - normalize(org - trace_endpos) * stepdist;
-                               for(; 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);
@@ -122,7 +133,7 @@ float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float
                                        if(autocvar_bot_debug_tracewalk)
                                                debugnodestatus(org, DEBUG_NODE_FAIL);
 
-                                       return FALSE;
+                                       return false;
                                        //print("tracewalk: ", vtos(start), " failed under water\n");
                                }
                                continue;
@@ -173,7 +184,7 @@ float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float
                                                        //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
+                                                       return false; // failed
                                                }
                                        }
                                        else
@@ -197,7 +208,7 @@ float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float
                                float c;
                                c = pointcontents(org + '0 0 1');
                                if (!(c == CONTENT_WATER || c == CONTENT_LAVA || c == CONTENT_SLIME))
-                                       swimming = FALSE;
+                                       swimming = false;
                                else
                                        continue;
                        }
@@ -212,7 +223,7 @@ float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float
        if(autocvar_bot_debug_tracewalk)
                debugnodestatus(org, DEBUG_NODE_FAIL);
 
-       return FALSE;
+       return false;
 }
 
 /////////////////////////////////////////////////////////////////////////////
@@ -223,7 +234,7 @@ float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float
 void navigation_clearroute()
 {
        //print("bot ", etos(self), " clear\n");
-       self.navigation_hasgoals = FALSE;
+       self.navigation_hasgoals = false;
        self.goalcurrent = world;
        self.goalstack01 = world;
        self.goalstack02 = world;
@@ -347,22 +358,22 @@ float navigation_waypoint_will_link(vector v, vector org, entity ent, float walk
        dist = vlen(v - org);
        if (bestdist > dist)
        {
-               traceline(v, org, TRUE, ent);
+               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;
+                                       return true;
                        }
                        else
                        {
                                if (tracewalk(ent, org, PL_MIN, PL_MAX, v, bot_navigation_movemode))
-                                       return TRUE;
+                                       return true;
                        }
                }
        }
-       return FALSE;
+       return false;
 }
 
 // find the spawnfunc_waypoint near a dynamic goal such as a dropped weapon
@@ -387,7 +398,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 - PL_MIN.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 +419,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;
@@ -442,7 +453,7 @@ float navigation_markroutes_nearestwaypoints(entity waylist, float maxdist)
        entity head;
        vector v, m1, m2, diff;
        float c;
-//     navigation_testtracewalk = TRUE;
+//     navigation_testtracewalk = true;
        c = 0;
        head = waylist;
        while (head)
@@ -454,17 +465,17 @@ 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;
+                               head.wpconsidered = true;
                                if (tracewalk(self, self.origin, self.mins, self.maxs, v, bot_navigation_movemode))
                                {
                                        head.wpnearestpoint = v;
@@ -477,7 +488,7 @@ float navigation_markroutes_nearestwaypoints(entity waylist, float maxdist)
                }
                head = head.chain;
        }
-       //navigation_testtracewalk = FALSE;
+       //navigation_testtracewalk = false;
        return c;
 }
 
@@ -491,9 +502,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;
@@ -516,7 +527,7 @@ void navigation_markroutes(entity fixed_source_waypoint)
        w = waylist = findchain(classname, "waypoint");
        while (w)
        {
-               w.wpconsidered = FALSE;
+               w.wpconsidered = false;
                w.wpnearestpoint = '0 0 0';
                w.wpcost = 10000000;
                w.wpfire = 0;
@@ -526,7 +537,7 @@ void navigation_markroutes(entity fixed_source_waypoint)
 
        if(fixed_source_waypoint)
        {
-               fixed_source_waypoint.wpconsidered = TRUE;
+               fixed_source_waypoint.wpconsidered = true;
                fixed_source_waypoint.wpnearestpoint = fixed_source_waypoint.origin + 0.5 * (fixed_source_waypoint.mins + fixed_source_waypoint.maxs);
                fixed_source_waypoint.wpcost = fixed_source_waypoint.dmg;
                fixed_source_waypoint.wpfire = 1;
@@ -551,16 +562,16 @@ void navigation_markroutes(entity fixed_source_waypoint)
                for(i=increment;!navigation_markroutes_nearestwaypoints(waylist, i)&&i<maxdistance;i+=increment);
        }
 
-       searching = TRUE;
+       searching = true;
        while (searching)
        {
-               searching = FALSE;
+               searching = false;
                w = waylist;
                while (w)
                {
                        if (w.wpfire)
                        {
-                               searching = TRUE;
+                               searching = true;
                                w.wpfire = 0;
                                cost = w.wpcost;
                                p = w.wpnearestpoint;
@@ -612,7 +623,7 @@ void navigation_markroutes_inverted(entity fixed_source_waypoint)
        w = waylist = findchain(classname, "waypoint");
        while (w)
        {
-               w.wpconsidered = FALSE;
+               w.wpconsidered = false;
                w.wpnearestpoint = '0 0 0';
                w.wpcost = 10000000;
                w.wpfire = 0;
@@ -622,7 +633,7 @@ void navigation_markroutes_inverted(entity fixed_source_waypoint)
 
        if(fixed_source_waypoint)
        {
-               fixed_source_waypoint.wpconsidered = TRUE;
+               fixed_source_waypoint.wpconsidered = true;
                fixed_source_waypoint.wpnearestpoint = fixed_source_waypoint.origin + 0.5 * (fixed_source_waypoint.mins + fixed_source_waypoint.maxs);
                fixed_source_waypoint.wpcost = fixed_source_waypoint.dmg; // the cost to get from X to fixed_source_waypoint
                fixed_source_waypoint.wpfire = 1;
@@ -633,16 +644,16 @@ void navigation_markroutes_inverted(entity fixed_source_waypoint)
                error("need to start with a waypoint\n");
        }
 
-       searching = TRUE;
+       searching = true;
        while (searching)
        {
-               searching = FALSE;
+               searching = false;
                w = waylist;
                while (w)
                {
                        if (w.wpfire)
                        {
-                               searching = TRUE;
+                               searching = true;
                                w.wpfire = 0;
                                cost = w.wpcost; // cost to walk from w to home
                                p = w.wpnearestpoint;
@@ -710,16 +721,16 @@ void navigation_routerating(entity e, float f, float rangebias)
                        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' * (PL_MAX.z - PL_MIN.z) * 10;
 
                        do{
                                npa = pointa + down;
                                npb = pointb + down;
 
-                               if(npa_z<=self.absmax_z)
+                               if(npa.z<=self.absmax.z)
                                        break;
 
-                               if(npb_z<=e.absmax_z)
+                               if(npb.z<=e.absmax.z)
                                        break;
 
                                traceline(npa, npb, MOVE_NORMAL, self);
@@ -735,7 +746,7 @@ void navigation_routerating(entity e, float f, float rangebias)
                        // Rough estimation of fuel consumption
                        // (ignores acceleration and current xyz velocity)
                        xydistance = vlen(pointa - pointb);
-                       zdistance = fabs(pointa_z - self.origin_z);
+                       zdistance = fabs(pointa.z - self.origin.z);
 
                        t = zdistance / autocvar_g_jetpack_maxspeed_up;
                        t += xydistance / autocvar_g_jetpack_maxspeed_side;
@@ -782,25 +793,25 @@ void navigation_routerating(entity e, float f, float rangebias)
        {
                float search;
 
-               search = TRUE;
+               search = true;
 
                if(e.flags & FL_ITEM)
                {
                        if (!(e.flags & FL_WEAPON))
                        if(e.nearestwaypoint)
-                               search = FALSE;
+                               search = false;
                }
                else if (e.flags & FL_WEAPON)
                {
                        if(e.classname != "droppedweapon")
                        if(e.nearestwaypoint)
-                               search = FALSE;
+                               search = false;
                }
 
                if(search)
                if (time > e.nearestwaypointtimeout)
                {
-                       nwp = navigation_findnearestwaypoint(e, TRUE);
+                       nwp = navigation_findnearestwaypoint(e, true);
                        if(nwp)
                                e.nearestwaypoint = nwp;
                        else
@@ -808,11 +819,11 @@ void navigation_routerating(entity e, float f, float rangebias)
                                bot_debug(strcat("FAILED to find a nearest waypoint to '", e.classname, "' #", etos(e), "\n"));
 
                                if(e.flags & FL_ITEM)
-                                       e.blacklisted = TRUE;
+                                       e.blacklisted = true;
                                else if (e.flags & FL_WEAPON)
                                {
                                        if(e.classname != "droppedweapon")
-                                               e.blacklisted = TRUE;
+                                               e.blacklisted = true;
                                }
 
                                if(e.blacklisted)
@@ -855,9 +866,9 @@ float navigation_routetogoal(entity e, vector startposition)
 
        // if there is no goal, just exit
        if (!e)
-               return FALSE;
+               return false;
 
-       self.navigation_hasgoals = TRUE;
+       self.navigation_hasgoals = true;
 
        // put the entity on the goal stack
        //print("routetogoal ", etos(e), "\n");
@@ -865,11 +876,11 @@ float navigation_routetogoal(entity e, vector startposition)
 
        if(g_jetpack)
        if(e==self.navigation_jetpack_goal)
-               return TRUE;
+               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))
-               return TRUE;
+               return true;
 
        // see if there are waypoints describing a path to the item
        if(e.classname != "waypoint" || (e.wpflags & WAYPOINTFLAG_PERSONAL))
@@ -878,7 +889,7 @@ float navigation_routetogoal(entity e, vector startposition)
                e = e.enemy; // we already have added it, so...
 
        if(e == world)
-               return FALSE;
+               return false;
 
        for (;;)
        {
@@ -890,7 +901,7 @@ float navigation_routetogoal(entity e, vector startposition)
                        break;
        }
 
-       return FALSE;
+       return false;
 }
 
 // removes any currently touching waypoints from the goal stack
@@ -950,7 +961,7 @@ void navigation_poptouchedgoals()
        {
                if(vlen(self.origin - self.goalcurrent.origin)<150)
                {
-                       traceline(self.origin + self.view_ofs , self.goalcurrent.origin, TRUE, world);
+                       traceline(self.origin + self.view_ofs , self.goalcurrent.origin, true, world);
                        if(trace_fraction==1)
                        {
                                // Detect personal waypoints
@@ -988,7 +999,7 @@ void navigation_goalrating_start()
 
        self.navigation_jetpack_goal = world;
        navigation_bestrating = -1;
-       self.navigation_hasgoals = FALSE;
+       self.navigation_hasgoals = false;
        navigation_clearroute();
        navigation_bestgoal = world;
        navigation_markroutes(world);
@@ -1013,7 +1024,7 @@ void navigation_goalrating_end()
                        self.aistatus |= AI_STATUS_STUCK;
                }
 
-               self.navigation_hasgoals = FALSE; // Reset this value
+               self.navigation_hasgoals = false; // Reset this value
        }
 }
 
@@ -1023,7 +1034,7 @@ void botframe_updatedangerousobjects(float maxupdate)
        vector m1, m2, v, o;
        float c, d, danger;
        c = 0;
-       bot_dodgelist = findchainfloat(bot_dodge, TRUE);
+       bot_dodgelist = findchainfloat(bot_dodge, true);
        botframe_dangerwaypoint = find(botframe_dangerwaypoint, classname, "waypoint");
        while (botframe_dangerwaypoint != world)
        {
@@ -1034,14 +1045,14 @@ 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)
                        {
-                               traceline(o, v, TRUE, world);
+                               traceline(o, v, true, world);
                                if (trace_fraction == 1)
                                        danger = danger + d;
                        }