]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/waypoints.qc
Merge branch 'master' into terencehill/hud_fixes
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / waypoints.qc
index ca209f9ca7ab4877c3ef0036c2d3756cf076a06f..184710818c1aac266a32e620695cd97fbbd66b1f 100644 (file)
@@ -1,14 +1,16 @@
 #include "waypoints.qh"
-#include "../_all.qh"
 
 #include "bot.qh"
 #include "navigation.qh"
 
+#include <common/state.qh>
+
 #include "../antilag.qh"
 
-#include "../../common/constants.qh"
+#include <common/constants.qh>
 
-#include "../../warpzonelib/util_server.qh"
+#include <lib/warpzone/common.qh>
+#include <lib/warpzone/util_server.qh>
 
 // create a new spawnfunc_waypoint and automatically link it to other waypoints, and link
 // them back to it as well
@@ -27,9 +29,8 @@ entity waypoint_spawn(vector m1, vector m2, float f)
                w = find(w, classname, "waypoint");
        }
 
-       w = spawn();
+       w = new(waypoint);
        w.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
-       w.classname = "waypoint";
        w.wpflags = f;
        setorigin(w, (m1 + m2) * 0.5);
        setsize(w, m1 - w.origin, m2 - w.origin);
@@ -38,7 +39,7 @@ entity waypoint_spawn(vector m1, vector m2, float f)
 
        if(!w.wpisbox)
        {
-               setsize(w, PL_MIN - '1 1 0', PL_MAX + '1 1 0');
+               setsize(w, STAT(PL_MIN, NULL) - '1 1 0', STAT(PL_MAX, NULL) + '1 1 0');
                if(!move_out_of_solid(w))
                {
                        if(!(f & WAYPOINTFLAG_GENERATED))
@@ -66,7 +67,7 @@ entity waypoint_spawn(vector m1, vector m2, float f)
        {
                m1 = w.mins;
                m2 = w.maxs;
-               setmodel(w, "models/runematch/rune.mdl"); w.effects = EF_LOWPRECISION;
+               setmodel(w, MDL_WAYPOINT); w.effects = EF_LOWPRECISION;
                setsize(w, m1, m2);
                if (w.wpflags & WAYPOINTFLAG_ITEM)
                        w.colormod = '1 0 0';
@@ -162,7 +163,7 @@ void waypoint_addlink(entity from, entity to)
 // (precompile a list of all reachable waypoints from this spawnfunc_waypoint)
 // (SLOW!)
 void waypoint_think()
-{
+{SELFPARAM();
        entity e;
        vector sv, sm1, sm2, ev, em1, em2, dv;
 
@@ -200,7 +201,7 @@ void waypoint_think()
                        ev.z = bound(em1_z, ev.z, em2_z);
                        dv = ev - sv;
                        dv.z = 0;
-                       if (vlen(dv) >= 1050) // max search distance in XY
+                       if(vdist(dv, >=, 1050)) // max search distance in XY
                        {
                                ++relink_lengthculled;
                                continue;
@@ -208,7 +209,7 @@ void waypoint_think()
                        navigation_testtracewalk = 0;
                        if (!self.wpisbox)
                        {
-                               tracebox(sv - PL_MIN.z * '0 0 1', PL_MIN, PL_MAX, sv, false, self);
+                               tracebox(sv - STAT(PL_MIN, NULL).z * '0 0 1', STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), sv, false, self);
                                if (!trace_startsolid)
                                {
                                        //dprint("sv deviation", vtos(trace_endpos - sv), "\n");
@@ -217,7 +218,7 @@ void waypoint_think()
                        }
                        if (!e.wpisbox)
                        {
-                               tracebox(ev - PL_MIN.z * '0 0 1', PL_MIN, PL_MAX, ev, false, e);
+                               tracebox(ev - STAT(PL_MIN, NULL).z * '0 0 1', STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), ev, false, e);
                                if (!trace_startsolid)
                                {
                                        //dprint("ev deviation", vtos(trace_endpos - ev), "\n");
@@ -226,11 +227,11 @@ void waypoint_think()
                        }
                        //traceline(self.origin, e.origin, false, world);
                        //if (trace_fraction == 1)
-                       if (!self.wpisbox && tracewalk(self, sv, PL_MIN, PL_MAX, ev, MOVE_NOMONSTERS))
+                       if (!self.wpisbox && tracewalk(self, sv, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), ev, MOVE_NOMONSTERS))
                                waypoint_addlink(self, e);
                        else
                                relink_walkculled += 0.5;
-                       if (!e.wpisbox && tracewalk(e, ev, PL_MIN, PL_MAX, sv, MOVE_NOMONSTERS))
+                       if (!e.wpisbox && tracewalk(e, ev, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), sv, MOVE_NOMONSTERS))
                                waypoint_addlink(e, self);
                        else
                                relink_walkculled += 0.5;
@@ -269,7 +270,7 @@ void waypoint_schedulerelink(entity wp)
                vector m1, m2;
                m1 = wp.mins;
                m2 = wp.maxs;
-               setmodel(wp, "models/runematch/rune.mdl"); wp.effects = EF_LOWPRECISION;
+               setmodel(wp, MDL_WAYPOINT); wp.effects = EF_LOWPRECISION;
                setsize(wp, m1, m2);
                if (wp.wpflags & WAYPOINTFLAG_ITEM)
                        wp.colormod = '1 0 0';
@@ -293,12 +294,12 @@ void waypoint_schedulerelink(entity wp)
 }
 
 // spawnfunc_waypoint map entity
-void spawnfunc_waypoint()
+spawnfunc(waypoint)
 {
-       setorigin(self, self.origin);
+       setorigin(this, this.origin);
        // schedule a relink after other waypoints have had a chance to spawn
-       waypoint_clearlinks(self);
-       //waypoint_schedulerelink(self);
+       waypoint_clearlinks(this);
+       //waypoint_schedulerelink(this);
 }
 
 // remove a spawnfunc_waypoint, and schedule all neighbors to relink
@@ -451,11 +452,7 @@ float waypoint_load_links()
 
        fclose(file);
 
-       LOG_TRACE("loaded ");
-       LOG_TRACE(ftos(c));
-       LOG_TRACE(" waypoint links from maps/");
-       LOG_TRACE(mapname);
-       LOG_TRACE(".waypoints.cache\n");
+       LOG_TRACE("loaded ", ftos(c), " waypoint links from maps/", mapname, ".waypoints.cache\n");
 
        botframe_cachedwaypointlinks = true;
        return true;
@@ -475,9 +472,7 @@ void waypoint_load_links_hardwired()
 
        if (file < 0)
        {
-               LOG_TRACE("waypoint links load from ");
-               LOG_TRACE(filename);
-               LOG_TRACE(" failed\n");
+               LOG_TRACE("waypoint links load from ", filename, " failed\n");
                return;
        }
 
@@ -548,11 +543,7 @@ void waypoint_load_links_hardwired()
 
        fclose(file);
 
-       LOG_TRACE("loaded ");
-       LOG_TRACE(ftos(c));
-       LOG_TRACE(" waypoint links from maps/");
-       LOG_TRACE(mapname);
-       LOG_TRACE(".waypoints.hardwired\n");
+       LOG_TRACE("loaded ", ftos(c), " waypoint links from maps/", mapname, ".waypoints.hardwired\n");
 }
 
 entity waypoint_get_link(entity w, float i)
@@ -712,26 +703,18 @@ float waypoint_loadall()
                                cwb = cwb + 1;
                }
                fclose(file);
-               LOG_TRACE("loaded ");
-               LOG_TRACE(ftos(cwp));
-               LOG_TRACE(" waypoints and ");
-               LOG_TRACE(ftos(cwb));
-               LOG_TRACE(" wayboxes from maps/");
-               LOG_TRACE(mapname);
-               LOG_TRACE(".waypoints\n");
+               LOG_TRACE("loaded ", ftos(cwp), " waypoints and ", ftos(cwb), " wayboxes from maps/", mapname, ".waypoints\n");
        }
        else
        {
-               LOG_TRACE("waypoint load from ");
-               LOG_TRACE(filename);
-               LOG_TRACE(" failed\n");
+               LOG_TRACE("waypoint load from ", filename, " failed\n");
        }
        return cwp + cwb;
 }
 
 vector waypoint_fixorigin(vector position)
 {
-       tracebox(position + '0 0 1' * (1 - PL_MIN.z), PL_MIN, PL_MAX, position + '0 0 -512', MOVE_NOMONSTERS, world);
+       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, world);
        if(trace_fraction < 1)
                position = trace_endpos;
        //traceline(position, position + '0 0 -512', MOVE_NOMONSTERS, world);
@@ -807,7 +790,7 @@ void waypoint_spawnforteleporter(entity e, vector destination, float timetaken)
        waypoint_spawnforteleporter_boxes(e, e.absmin, e.absmax, destination, destination, timetaken);
 }
 
-entity waypoint_spawnpersonal(vector position)
+entity waypoint_spawnpersonal(entity this, vector position)
 {
        entity w;
 
@@ -819,7 +802,7 @@ entity waypoint_spawnpersonal(vector position)
        w = waypoint_spawn(position, position, WAYPOINTFLAG_GENERATED | WAYPOINTFLAG_PERSONAL);
        w.nearestwaypoint = world;
        w.nearestwaypointtimeout = 0;
-       w.owner = self;
+       w.owner = this;
 
        waypoint_schedulerelink(w);
 
@@ -828,23 +811,20 @@ entity waypoint_spawnpersonal(vector position)
 
 void botframe_showwaypointlinks()
 {
-       entity player, head, w;
+       entity head, w;
        if (time < botframe_waypointeditorlightningtime)
                return;
        botframe_waypointeditorlightningtime = time + 0.5;
-       player = find(world, classname, "player");
-       while (player)
-       {
-               if (!player.isbot)
-               if (player.flags & FL_ONGROUND || player.waterlevel > WATERLEVEL_NONE)
+       FOREACH_CLIENT(IS_PLAYER(it) && !it.isbot, LAMBDA(
+               if(IS_ONGROUND(it) || it.waterlevel > WATERLEVEL_NONE)
                {
                        //navigation_testtracewalk = true;
-                       head = navigation_findnearestwaypoint(player, false);
+                       head = navigation_findnearestwaypoint(it, false);
                //      print("currently selected WP is ", etos(head), "\n");
                        //navigation_testtracewalk = false;
                        if (head)
                        {
-                               w = head     ;if (w) te_lightning2(world, w.origin, player.origin);
+                               w = head     ;if (w) te_lightning2(world, w.origin, it.origin);
                                w = head.wp00;if (w) te_lightning2(world, w.origin, head.origin);
                                w = head.wp01;if (w) te_lightning2(world, w.origin, head.origin);
                                w = head.wp02;if (w) te_lightning2(world, w.origin, head.origin);
@@ -879,13 +859,12 @@ void botframe_showwaypointlinks()
                                w = head.wp31;if (w) te_lightning2(world, w.origin, head.origin);
                        }
                }
-               player = find(player, classname, "player");
-       }
+       ));
 }
 
 float botframe_autowaypoints_fixdown(vector v)
 {
-       tracebox(v, PL_MIN, PL_MAX, v + '0 0 -64', MOVE_NOMONSTERS, world);
+       tracebox(v, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), v + '0 0 -64', MOVE_NOMONSTERS, world);
        if(trace_fraction >= 1)
                return 0;
        return 1;
@@ -1006,7 +985,7 @@ float botframe_autowaypoints_fix_from(entity p, float walkfromwp, entity wp, .en
                }
 
                t = (tmin + tmax) * 0.5;
-               o = antilag_takebackorigin(p, time - t);
+               o = antilag_takebackorigin(p, CS(p), time - t);
                if(!botframe_autowaypoints_fixdown(o))
                        return -2;
                o = trace_endpos;
@@ -1130,7 +1109,7 @@ void botframe_deleteuselesswaypoints()
                                        goto next;
                                }
                        }
-:next
+LABEL(next)
                }
        }
        // d) The waypoint is a dead end. Dead end waypoints must be kept as
@@ -1152,16 +1131,12 @@ void botframe_deleteuselesswaypoints()
 
 void botframe_autowaypoints()
 {
-       entity p;
-       FOR_EACH_REALPLAYER(p)
-       {
-               if(p.deadflag)
-                       continue;
+       FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && !IS_DEAD(it), LAMBDA(
                // going back is broken, so only fix waypoints to walk TO the player
                //botframe_autowaypoints_fix(p, false, botframe_autowaypoints_lastwp0);
-               botframe_autowaypoints_fix(p, true, botframe_autowaypoints_lastwp1);
+               botframe_autowaypoints_fix(it, true, botframe_autowaypoints_lastwp1);
                //te_explosion(p.botframe_autowaypoints_lastwp0.origin);
-       }
+       ));
 
        if (autocvar_g_waypointeditor_auto >= 2) {
                botframe_deleteuselesswaypoints();