]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/navigation.qc
Replace `vector_[xyz]` with `vector.[xyz]` where possible
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / navigation.qc
index 9160c1133ab4ba9e50bcb3972dea7492918d85fd..8c244bf8b50e3b6d750059a82448a30dc336fee3 100644 (file)
@@ -64,7 +64,7 @@ float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float
        // Movement loop
        yaw = vectoyaw(move);
        move = end - org;
-       for (;;)
+       for(0;;)
        {
                if (boxesoverlap(end, end, org + m1 + '-1 -1 -1', org + m2 + '1 1 1'))
                {
@@ -108,7 +108,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(; org_z < end_z + self.maxs_z; org_z += stepdist)
+                               for(0; org.z < end.z + self.maxs.z; org.z += stepdist)
                                {
                                                if(autocvar_bot_debug_tracewalk)
                                                        debugnode(org);
@@ -117,7 +117,7 @@ float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float
                                                        break;
                                }
 
-                               if not (pointcontents(org + '0 0 1') == CONTENT_EMPTY)
+                               if(pointcontents(org + '0 0 1') != CONTENT_EMPTY)
                                {
                                        if(autocvar_bot_debug_tracewalk)
                                                debugnodestatus(org, DEBUG_NODE_FAIL);
@@ -196,7 +196,7 @@ float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float
                        {
                                float c;
                                c = pointcontents(org + '0 0 1');
-                               if not(c == CONTENT_WATER || c == CONTENT_LAVA || c == CONTENT_SLIME)
+                               if (!(c == CONTENT_WATER || c == CONTENT_LAVA || c == CONTENT_SLIME))
                                        swimming = FALSE;
                                else
                                        continue;
@@ -366,7 +366,7 @@ float navigation_waypoint_will_link(vector v, vector org, entity ent, float walk
 }
 
 // find the spawnfunc_waypoint near a dynamic goal such as a dropped weapon
-entity navigation_findnearestwaypoint_withdist(entity ent, float walkfromwp, float bestdist)
+entity navigation_findnearestwaypoint_withdist_except(entity ent, float walkfromwp, float bestdist, entity except)
 {
        entity waylist, w, best;
        vector v, org, pm1, pm2;
@@ -380,14 +380,14 @@ entity navigation_findnearestwaypoint_withdist(entity ent, float walkfromwp, flo
        while (w)
        {
                // if object is touching spawnfunc_waypoint
-               if(w != ent)
+               if(w != ent && w != except)
                        if (boxesoverlap(pm1, pm2, w.absmin, w.absmax))
                                return w;
                w = w.chain;
        }
 
        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 +408,9 @@ entity navigation_findnearestwaypoint_withdist(entity ent, float walkfromwp, flo
                                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;
@@ -426,7 +426,14 @@ entity navigation_findnearestwaypoint_withdist(entity ent, float walkfromwp, flo
 }
 entity navigation_findnearestwaypoint(entity ent, float walkfromwp)
 {
-       return navigation_findnearestwaypoint_withdist(ent, walkfromwp, 1050);
+       entity wp = navigation_findnearestwaypoint_withdist_except(ent, walkfromwp, 1050, world);
+       if (autocvar_g_waypointeditor_auto)
+       {
+               entity wp2 = navigation_findnearestwaypoint_withdist_except(ent, walkfromwp, 1050, wp);
+               if (wp && !wp2)
+                       wp.wpflags |= WAYPOINTFLAG_PROTECTED;
+       }
+       return wp;
 }
 
 // finds the waypoints near the bot initiating a navigation query
@@ -447,14 +454,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;
@@ -484,9 +491,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;
@@ -709,10 +716,10 @@ void navigation_routerating(entity e, float f, float rangebias)
                                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);
@@ -728,12 +735,12 @@ 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;
                        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"));
 
                        // enough fuel ?
@@ -779,7 +786,7 @@ void navigation_routerating(entity e, float f, float rangebias)
 
                if(e.flags & FL_ITEM)
                {
-                       if not(e.flags & FL_WEAPON)
+                       if (!(e.flags & FL_WEAPON))
                        if(e.nearestwaypoint)
                                search = FALSE;
                }
@@ -873,7 +880,7 @@ float navigation_routetogoal(entity e, vector startposition)
        if(e == world)
                return FALSE;
 
-       for (;;)
+       for(0;;)
        {
                // add the spawnfunc_waypoint to the path
                navigation_pushroute(e);
@@ -997,10 +1004,10 @@ void navigation_goalrating_end()
        bot_debug(strcat("best goal ", self.goalcurrent.classname , "\n"));
 
        // If the bot got stuck then try to reach the farthest waypoint
-       if not (self.navigation_hasgoals)
+       if (!self.navigation_hasgoals)
        if (autocvar_bot_wander_enable)
        {
-               if not(self.aistatus & AI_STATUS_STUCK)
+               if (!(self.aistatus & AI_STATUS_STUCK))
                {
                        bot_debug(strcat(self.netname, " cannot walk to any goal\n"));
                        self.aistatus |= AI_STATUS_STUCK;
@@ -1027,9 +1034,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)
@@ -1052,10 +1059,10 @@ void navigation_unstuck()
 {
        float search_radius = 1000;
 
-       if not(autocvar_bot_wander_enable)
+       if (!autocvar_bot_wander_enable)
                return;
 
-       if not(bot_waypoint_queue_owner)
+       if (!bot_waypoint_queue_owner)
        {
                bot_debug(strcat(self.netname, " sutck, taking over the waypoints queue\n"));
                bot_waypoint_queue_owner = self;
@@ -1081,7 +1088,7 @@ void navigation_unstuck()
                }
                bot_waypoint_queue_goal = bot_waypoint_queue_goal.bot_waypoint_queue_nextgoal;
 
-               if not(bot_waypoint_queue_goal)
+               if (!bot_waypoint_queue_goal)
                {
                        if (bot_waypoint_queue_bestgoal)
                        {
@@ -1147,7 +1154,7 @@ void debugresetnodes()
 
 void debugnode(vector node)
 {
-       if not(IS_PLAYER(self))
+       if (!IS_PLAYER(self))
                return;
 
        if(debuglastnode=='0 0 0')