]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/default/navigation.qc
Fix stat references on non-player entities
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / default / navigation.qc
index 5ab07b1a8f505367b596606afa70c5b3a67b280f..2a2f7753daf2cd22008bd4f776816bc5568fc14e 100644 (file)
@@ -7,9 +7,10 @@
 
 #include <common/t_items.qh>
 
-#include <common/items/all.qh>
+#include <common/items/_mod.qh>
 
 #include <common/constants.qh>
+#include <common/net_linked.qh>
 #include <common/triggers/trigger/jumppads.qh>
 
 .float speed;
@@ -359,12 +360,12 @@ float navigation_waypoint_will_link(vector v, vector org, entity ent, float walk
                {
                        if (walkfromwp)
                        {
-                               if (tracewalk(ent, v, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), org, bot_navigation_movemode))
+                               if (tracewalk(ent, v, PL_MIN_CONST, PL_MAX_CONST, org, bot_navigation_movemode))
                                        return true;
                        }
                        else
                        {
-                               if (tracewalk(ent, org, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), v, bot_navigation_movemode))
+                               if (tracewalk(ent, org, PL_MIN_CONST, PL_MAX_CONST, v, bot_navigation_movemode))
                                        return true;
                        }
                }
@@ -386,7 +387,7 @@ entity navigation_findnearestwaypoint_withdist_except(entity ent, float walkfrom
        });
 
        vector org = ent.origin + 0.5 * (ent.mins + ent.maxs);
-       org.z = ent.origin.z + ent.mins.z - STAT(PL_MIN, NULL).z; // player height
+       org.z = ent.origin.z + ent.mins.z - PL_MIN_CONST.z; // player height
        // TODO possibly make other code have the same support for bboxes
        if(ent.tag_entity)
                org = org + ent.tag_entity.origin;
@@ -662,7 +663,7 @@ void navigation_routerating(entity this, entity e, float f, float rangebias)
        {
                vector pointa, pointb;
 
-               LOG_DEBUG("jetpack ai: evaluating path for ", e.classname, "\n");
+               LOG_DEBUG("jetpack ai: evaluating path for ", e.classname);
 
                // Point A
                traceline(this.origin, this.origin + '0 0 65535', MOVE_NORMAL, this);
@@ -677,13 +678,13 @@ void navigation_routerating(entity this, entity e, float f, float rangebias)
 
                if(trace_fraction==1)
                {
-                       LOG_DEBUG("jetpack ai: can bridge these two points\n");
+                       LOG_DEBUG("jetpack ai: can bridge these two points");
 
                        // Lower the altitude of these points as much as possible
                        float zdistance, xydistance, cost, t, fuel;
                        vector down, npa, npb;
 
-                       down = '0 0 -1' * (STAT(PL_MAX, NULL).z - STAT(PL_MIN, NULL).z) * 10;
+                       down = '0 0 -1' * (STAT(PL_MAX, this).z - STAT(PL_MIN, this).z) * 10;
 
                        do{
                                npa = pointa + down;
@@ -714,7 +715,7 @@ void navigation_routerating(entity this, entity e, float f, float rangebias)
                        t += xydistance / autocvar_g_jetpack_maxspeed_side;
                        fuel = t * autocvar_g_jetpack_fuel * 0.8;
 
-                       LOG_DEBUG(strcat("jetpack ai: required fuel ", ftos(fuel), " this.ammo_fuel ", ftos(this.ammo_fuel), "\n"));
+                       LOG_DEBUG("jetpack ai: required fuel ", ftos(fuel), " this.ammo_fuel ", ftos(this.ammo_fuel));
 
                        // enough fuel ?
                        if(this.ammo_fuel>fuel)
@@ -732,7 +733,7 @@ void navigation_routerating(entity this, entity e, float f, float rangebias)
 
                                if (navigation_bestrating < f)
                                {
-                                       LOG_DEBUG(strcat("jetpack path: added goal ", e.classname, " (with rating ", ftos(f), ")\n"));
+                                       LOG_DEBUG("jetpack path: added goal ", e.classname, " (with rating ", ftos(f), ")");
                                        navigation_bestrating = f;
                                        navigation_bestgoal = e;
                                        this.navigation_jetpack_goal = e;
@@ -778,7 +779,7 @@ void navigation_routerating(entity this, entity e, float f, float rangebias)
                                e.nearestwaypoint = nwp;
                        else
                        {
-                               LOG_DEBUG(strcat("FAILED to find a nearest waypoint to '", e.classname, "' #", etos(e), "\n"));
+                               LOG_DEBUG("FAILED to find a nearest waypoint to '", e.classname, "' #", etos(e));
 
                                if(e.flags & FL_ITEM)
                                        e.blacklisted = true;
@@ -790,7 +791,7 @@ void navigation_routerating(entity this, entity e, float f, float rangebias)
 
                                if(e.blacklisted)
                                {
-                                       LOG_DEBUG(strcat("The entity '", e.classname, "' is going to be excluded from path finding during this match\n"));
+                                       LOG_DEBUG("The entity '", e.classname, "' is going to be excluded from path finding during this match");
                                        return;
                                }
                        }
@@ -804,17 +805,17 @@ void navigation_routerating(entity this, entity e, float f, float rangebias)
                nwp = e.nearestwaypoint;
        }
 
-       LOG_DEBUG(strcat("-- checking ", e.classname, " (with cost ", ftos(nwp.wpcost), ")\n"));
+       LOG_DEBUG("-- checking ", e.classname, " (with cost ", ftos(nwp.wpcost), ")");
        if (nwp)
        if (nwp.wpcost < 10000000)
        {
                //te_wizspike(nwp.wpnearestpoint);
-               LOG_DEBUG(strcat(e.classname, " ", ftos(f), "/(1+", ftos((nwp.wpcost + vlen(e.origin - nwp.wpnearestpoint))), "/", ftos(rangebias), ") = "));
+               LOG_DEBUG(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)));
-               LOG_DEBUG(strcat("considering ", e.classname, " (with rating ", ftos(f), ")\n"));
+               LOG_DEBUG("considering ", e.classname, " (with rating ", ftos(f), ")");
                if (navigation_bestrating < f)
                {
-                       LOG_DEBUG(strcat("ground path: added goal ", e.classname, " (with rating ", ftos(f), ")\n"));
+                       LOG_DEBUG("ground path: added goal ", e.classname, " (with rating ", ftos(f), ")");
                        navigation_bestrating = f;
                        navigation_bestgoal = e;
                }
@@ -841,7 +842,7 @@ bool navigation_routetogoal(entity this, entity e, vector startposition)
                return true;
 
        // if it can reach the goal there is nothing more to do
-       if (tracewalk(this, 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, this), STAT(PL_MAX, this), (e.absmin + e.absmax) * 0.5, bot_navigation_movemode))
                return true;
 
        // see if there are waypoints describing a path to the item
@@ -892,12 +893,12 @@ void navigation_poptouchedgoals(entity this)
        }
 
        // If for some reason the bot is closer to the next goal, pop the current one
-       if(this.goalstack01)
+       if(this.goalstack01 && !wasfreed(this.goalstack01))
        if(vlen2(this.goalcurrent.origin - this.origin) > vlen2(this.goalstack01.origin - this.origin))
        if(checkpvs(this.origin + this.view_ofs, this.goalstack01))
        if(tracewalk(this, this.origin, this.mins, this.maxs, (this.goalstack01.absmin + this.goalstack01.absmax) * 0.5, bot_navigation_movemode))
        {
-               LOG_DEBUG(strcat("path optimized for ", this.netname, ", removed a goal from the queue\n"));
+               LOG_DEBUG("path optimized for ", this.netname, ", removed a goal from the queue");
                navigation_poproute(this);
                // TODO this may also be a nice idea to do "early" (e.g. by
                // manipulating the vlen() comparisons) to shorten paths in
@@ -908,7 +909,7 @@ void navigation_poptouchedgoals(entity this)
        }
 
        // HACK: remove players/bots as goals, they can lead a bot to unexpected places (cliffs, lava, etc)
-       // TODO: rate waypoints near the targetted player at that moment, instead of the player itthis
+       // TODO: rate waypoints near the targetted player at that moment, instead of the player itself
        if(IS_PLAYER(this.goalcurrent))
                navigation_poproute(this);
 
@@ -974,7 +975,7 @@ void navigation_goalrating_end(entity this)
                return;
 
        navigation_routetogoal(this, navigation_bestgoal, this.origin);
-       LOG_DEBUG(strcat("best goal ", this.goalcurrent.classname , "\n"));
+       LOG_DEBUG("best goal ", this.goalcurrent.classname);
 
        // If the bot got stuck then try to reach the farthest waypoint
        if (!this.navigation_hasgoals)
@@ -982,7 +983,7 @@ void navigation_goalrating_end(entity this)
        {
                if (!(this.aistatus & AI_STATUS_STUCK))
                {
-                       LOG_DEBUG(strcat(this.netname, " cannot walk to any goal\n"));
+                       LOG_DEBUG(this.netname, " cannot walk to any goal");
                        this.aistatus |= AI_STATUS_STUCK;
                }
 
@@ -1000,7 +1001,7 @@ void botframe_updatedangerousobjects(float maxupdate)
                danger = 0;
                m1 = it.mins;
                m2 = it.maxs;
-               FOREACH_ENTITY_FLOAT(bot_dodge, true,
+               IL_EACH(g_bot_dodge, it.bot_dodge,
                {
                        v = it.origin;
                        v.x = bound(m1_x, v.x, m2_x);
@@ -1031,7 +1032,7 @@ void navigation_unstuck(entity this)
 
        if (!bot_waypoint_queue_owner)
        {
-               LOG_DEBUG(strcat(this.netname, " sutck, taking over the waypoints queue\n"));
+               LOG_DEBUG(this.netname, " stuck, taking over the waypoints queue");
                bot_waypoint_queue_owner = this;
                bot_waypoint_queue_bestgoal = NULL;
                bot_waypoint_queue_bestgoalrating = 0;
@@ -1043,9 +1044,9 @@ void navigation_unstuck(entity this)
        if (bot_waypoint_queue_goal)
        {
                // evaluate the next goal on the queue
-               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"));
-               if(tracewalk(bot_waypoint_queue_goal, this.origin, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), bot_waypoint_queue_goal.origin, bot_navigation_movemode))
+               float d = vlen2(this.origin - bot_waypoint_queue_goal.origin);
+               LOG_DEBUG(this.netname, " evaluating ", bot_waypoint_queue_goal.classname, " with distance ", ftos(d));
+               if(tracewalk(bot_waypoint_queue_goal, this.origin, STAT(PL_MIN, this), STAT(PL_MAX, this), bot_waypoint_queue_goal.origin, bot_navigation_movemode))
                {
                        if( d > bot_waypoint_queue_bestgoalrating)
                        {
@@ -1059,14 +1060,14 @@ void navigation_unstuck(entity this)
                {
                        if (bot_waypoint_queue_bestgoal)
                        {
-                               LOG_DEBUG(strcat(this.netname, " stuck, reachable waypoint found, heading to it\n"));
+                               LOG_DEBUG(this.netname, " stuck, reachable waypoint found, heading to it");
                                navigation_routetogoal(this, bot_waypoint_queue_bestgoal, this.origin);
                                this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
                                this.aistatus &= ~AI_STATUS_STUCK;
                        }
                        else
                        {
-                               LOG_DEBUG(strcat(this.netname, " stuck, cannot walk to any waypoint at all\n"));
+                               LOG_DEBUG(this.netname, " stuck, cannot walk to any waypoint at all");
                        }
 
                        bot_waypoint_queue_owner = NULL;
@@ -1078,7 +1079,7 @@ void navigation_unstuck(entity this)
                        return;
 
                // build a new queue
-               LOG_DEBUG(strcat(this.netname, " stuck, scanning reachable waypoints within ", ftos(search_radius)," qu\n"));
+               LOG_DEBUG(this.netname, " stuck, scanning reachable waypoints within ", ftos(search_radius)," qu");
 
                entity first = NULL;
 
@@ -1097,7 +1098,7 @@ void navigation_unstuck(entity this)
                        bot_waypoint_queue_goal = first;
                else
                {
-                       LOG_DEBUG(strcat(this.netname, " stuck, cannot walk to any waypoint at all\n"));
+                       LOG_DEBUG(this.netname, " stuck, cannot walk to any waypoint at all");
                        bot_waypoint_queue_owner = NULL;
                }
        }