]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/default/waypoints.qc
Use the constants for player hitbox size when applicable (should fix observer hitbox)
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / default / waypoints.qc
index 84995d1c7d5613b1b9f925dc8bba4aca769394c4..1e03bf5e1bd651e086ee22fdeef485bf76621ae6 100644 (file)
 #include "../../antilag.qh"
 
 #include <common/constants.qh>
+#include <common/net_linked.qh>
 
 #include <lib/warpzone/common.qh>
 #include <lib/warpzone/util_server.qh>
 
+void waypoint_setupmodel(entity wp)
+{
+       if (autocvar_g_waypointeditor)
+       {
+               // TODO: add some sort of visible box in edit mode for box waypoints
+               vector m1 = wp.mins;
+               vector m2 = wp.maxs;
+               setmodel(wp, MDL_WAYPOINT);
+               setsize(wp, m1, m2);
+               wp.effects = EF_LOWPRECISION;
+               if (wp.wpflags & WAYPOINTFLAG_ITEM)
+                       wp.colormod = '1 0 0';
+               else if (wp.wpflags & WAYPOINTFLAG_GENERATED)
+                       wp.colormod = '1 1 0';
+               else
+                       wp.colormod = '1 1 1';
+       }
+       else
+               wp.model = "";
+}
+
 // create a new spawnfunc_waypoint and automatically link it to other waypoints, and link
 // them back to it as well
 // (suitable for spawnfunc_waypoint editor)
@@ -34,17 +56,17 @@ entity waypoint_spawn(vector m1, vector m2, float f)
        w.solid = SOLID_TRIGGER;
        setorigin(w, (m1 + m2) * 0.5);
        setsize(w, m1 - w.origin, m2 - w.origin);
-       if (vlen(w.size) > 0)
+       if (w.size)
                w.wpisbox = true;
 
        if(!w.wpisbox)
        {
-               setsize(w, STAT(PL_MIN, NULL) - '1 1 0', STAT(PL_MAX, NULL) + '1 1 0');
+               setsize(w, PL_MIN_CONST - '1 1 0', PL_MAX_CONST + '1 1 0');
                if(!move_out_of_solid(w))
                {
                        if(!(f & WAYPOINTFLAG_GENERATED))
                        {
-                               LOG_TRACE("Killed a waypoint that was stuck in solid at ", vtos(w.origin), "\n");
+                               LOG_TRACE("Killed a waypoint that was stuck in solid at ", vtos(w.origin));
                                delete(w);
                                return NULL;
                        }
@@ -63,21 +85,7 @@ entity waypoint_spawn(vector m1, vector m2, float f)
        waypoint_clearlinks(w);
        //waypoint_schedulerelink(w);
 
-       if (autocvar_g_waypointeditor)
-       {
-               m1 = w.mins;
-               m2 = w.maxs;
-               setmodel(w, MDL_WAYPOINT); w.effects = EF_LOWPRECISION;
-               setsize(w, m1, m2);
-               if (w.wpflags & WAYPOINTFLAG_ITEM)
-                       w.colormod = '1 0 0';
-               else if (w.wpflags & WAYPOINTFLAG_GENERATED)
-                       w.colormod = '1 1 0';
-               else
-                       w.colormod = '1 1 1';
-       }
-       else
-               w.model = "";
+       waypoint_setupmodel(w);
 
        return w;
 }
@@ -208,7 +216,7 @@ void waypoint_think(entity this)
                        navigation_testtracewalk = 0;
                        if (!this.wpisbox)
                        {
-                               tracebox(sv - STAT(PL_MIN, NULL).z * '0 0 1', STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), sv, false, this);
+                               tracebox(sv - PL_MIN_CONST.z * '0 0 1', PL_MIN_CONST, PL_MAX_CONST, sv, false, this);
                                if (!trace_startsolid)
                                {
                                        //dprint("sv deviation", vtos(trace_endpos - sv), "\n");
@@ -217,7 +225,7 @@ void waypoint_think(entity this)
                        }
                        if (!it.wpisbox)
                        {
-                               tracebox(ev - STAT(PL_MIN, NULL).z * '0 0 1', STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), ev, false, it);
+                               tracebox(ev - PL_MIN_CONST.z * '0 0 1', PL_MIN_CONST, PL_MAX_CONST, ev, false, it);
                                if (!trace_startsolid)
                                {
                                        //dprint("ev deviation", vtos(trace_endpos - ev), "\n");
@@ -226,11 +234,11 @@ void waypoint_think(entity this)
                        }
                        //traceline(this.origin, it.origin, false, NULL);
                        //if (trace_fraction == 1)
-                       if (!this.wpisbox && tracewalk(this, sv, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), ev, MOVE_NOMONSTERS))
+                       if (!this.wpisbox && tracewalk(this, sv, PL_MIN_CONST, PL_MAX_CONST, ev, MOVE_NOMONSTERS))
                                waypoint_addlink(this, it);
                        else
                                relink_walkculled += 0.5;
-                       if (!it.wpisbox && tracewalk(it, ev, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), sv, MOVE_NOMONSTERS))
+                       if (!it.wpisbox && tracewalk(it, ev, PL_MIN_CONST, PL_MAX_CONST, sv, MOVE_NOMONSTERS))
                                waypoint_addlink(it, this);
                        else
                                relink_walkculled += 0.5;
@@ -263,24 +271,9 @@ void waypoint_schedulerelink(entity wp)
 {
        if (wp == NULL)
                return;
-       // TODO: add some sort of visible box in edit mode for box waypoints
-       if (autocvar_g_waypointeditor)
-       {
-               vector m1, m2;
-               m1 = wp.mins;
-               m2 = wp.maxs;
-               setmodel(wp, MDL_WAYPOINT); wp.effects = EF_LOWPRECISION;
-               setsize(wp, m1, m2);
-               if (wp.wpflags & WAYPOINTFLAG_ITEM)
-                       wp.colormod = '1 0 0';
-               else if (wp.wpflags & WAYPOINTFLAG_GENERATED)
-                       wp.colormod = '1 1 0';
-               else
-                       wp.colormod = '1 1 1';
-       }
-       else
-               wp.model = "";
-       wp.wpisbox = vlen(wp.size) > 0;
+
+       waypoint_setupmodel(wp);
+       wp.wpisbox = vdist(wp.size, >, 0);
        wp.enemy = NULL;
        if (!(wp.wpflags & WAYPOINTFLAG_PERSONAL))
                wp.owner = NULL;
@@ -378,7 +371,7 @@ float waypoint_load_links()
        {
                LOG_TRACE("waypoint links load from ");
                LOG_TRACE(filename);
-               LOG_TRACE(" failed\n");
+               LOG_TRACE(" failed");
                return false;
        }
 
@@ -414,7 +407,7 @@ float waypoint_load_links()
 
                        if(!found)
                        {
-                               LOG_TRACE("waypoint_load_links: couldn't find 'from' waypoint at ", vtos(wp_from.origin),"\n");
+                               LOG_TRACE("waypoint_load_links: couldn't find 'from' waypoint at ", vtos(wp_from.origin));
                                continue;
                        }
 
@@ -436,7 +429,7 @@ float waypoint_load_links()
 
                if(!found)
                {
-                       LOG_TRACE("waypoint_load_links: couldn't find 'to' waypoint at ", vtos(wp_to.origin),"\n");
+                       LOG_TRACE("waypoint_load_links: couldn't find 'to' waypoint at ", vtos(wp_to.origin));
                        continue;
                }
 
@@ -446,7 +439,7 @@ float waypoint_load_links()
 
        fclose(file);
 
-       LOG_TRACE("loaded ", ftos(c), " waypoint links from maps/", mapname, ".waypoints.cache\n");
+       LOG_TRACE("loaded ", ftos(c), " waypoint links from maps/", mapname, ".waypoints.cache");
 
        botframe_cachedwaypointlinks = true;
        return true;
@@ -466,7 +459,7 @@ void waypoint_load_links_hardwired()
 
        if (file < 0)
        {
-               LOG_TRACE("waypoint links load from ", filename, " failed\n");
+               LOG_TRACE("waypoint links load from ", filename, " failed");
                return;
        }
 
@@ -537,7 +530,7 @@ void waypoint_load_links_hardwired()
 
        fclose(file);
 
-       LOG_TRACE("loaded ", ftos(c), " waypoint links from maps/", mapname, ".waypoints.hardwired\n");
+       LOG_TRACE("loaded ", ftos(c), " waypoint links from maps/", mapname, ".waypoints.hardwired");
 }
 
 entity waypoint_get_link(entity w, float i)
@@ -681,18 +674,18 @@ float waypoint_loadall()
                                cwb = cwb + 1;
                }
                fclose(file);
-               LOG_TRACE("loaded ", ftos(cwp), " waypoints and ", ftos(cwb), " wayboxes from maps/", mapname, ".waypoints\n");
+               LOG_TRACE("loaded ", ftos(cwp), " waypoints and ", ftos(cwb), " wayboxes from maps/", mapname, ".waypoints");
        }
        else
        {
-               LOG_TRACE("waypoint load from ", filename, " failed\n");
+               LOG_TRACE("waypoint load from ", filename, " failed");
        }
        return cwp + cwb;
 }
 
 vector waypoint_fixorigin(vector position)
 {
-       tracebox(position + '0 0 1' * (1 - STAT(PL_MIN, NULL).z), STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), position + '0 0 -512', MOVE_NOMONSTERS, NULL);
+       tracebox(position + '0 0 1' * (1 - PL_MIN_CONST.z), PL_MIN_CONST, PL_MAX_CONST, position + '0 0 -512', MOVE_NOMONSTERS, NULL);
        if(trace_fraction < 1)
                position = trace_endpos;
        //traceline(position, position + '0 0 -512', MOVE_NOMONSTERS, NULL);
@@ -840,7 +833,7 @@ void botframe_showwaypointlinks()
 
 float botframe_autowaypoints_fixdown(vector v)
 {
-       tracebox(v, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), v + '0 0 -64', MOVE_NOMONSTERS, NULL);
+       tracebox(v, PL_MIN_CONST, PL_MAX_CONST, v + '0 0 -64', MOVE_NOMONSTERS, NULL);
        if(trace_fraction >= 1)
                return 0;
        return 1;
@@ -1012,7 +1005,7 @@ void botframe_autowaypoints_fix(entity p, float walkfromwp, .entity fld)
 
 void botframe_deleteuselesswaypoints()
 {
-       FOREACH_ENTITY_FLOAT(bot_pickup, true,
+       IL_EACH(g_items, it.bot_pickup,
        {
                // NOTE: this protects waypoints if they're the ONLY nearest
                // waypoint. That's the intention.