]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/waypoints.qc
Clean up some player loops
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / waypoints.qc
index 627c622d2554de6f9b3a6015f5d8ffaebb2e7066..998f08c785e73b9966cd016921bf31c58d026e6a 100644 (file)
@@ -1,14 +1,14 @@
 #include "waypoints.qh"
-#include "../_all.qh"
 
 #include "bot.qh"
 #include "navigation.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 +27,9 @@ entity waypoint_spawn(vector m1, vector m2, float f)
                w = find(w, classname, "waypoint");
        }
 
-       w = spawn();
+       w = new(waypoint);
+       make_pure(w);
        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,12 +38,12 @@ 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))
                        {
-                               dprint("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), "\n");
                                remove(w);
                                return world;
                        }
@@ -51,7 +51,7 @@ entity waypoint_spawn(vector m1, vector m2, float f)
                        {
                                if(autocvar_developer)
                                {
-                                       print("A generated waypoint is stuck in solid at ", vtos(w.origin), "\n");
+                                       LOG_INFO("A generated waypoint is stuck in solid at ", vtos(w.origin), "\n");
                                        backtrace("Waypoint stuck");
                                }
                        }
@@ -66,7 +66,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 +162,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;
 
@@ -208,7 +208,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 +217,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 +226,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 +269,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,7 +293,7 @@ void waypoint_schedulerelink(entity wp)
 }
 
 // spawnfunc_waypoint map entity
-void spawnfunc_waypoint()
+spawnfunc(waypoint)
 {
        setorigin(self, self.origin);
        // schedule a relink after other waypoints have had a chance to spawn
@@ -381,9 +381,9 @@ float waypoint_load_links()
 
        if (file < 0)
        {
-               dprint("waypoint links load from ");
-               dprint(filename);
-               dprint(" failed\n");
+               LOG_TRACE("waypoint links load from ");
+               LOG_TRACE(filename);
+               LOG_TRACE(" failed\n");
                return false;
        }
 
@@ -419,7 +419,7 @@ float waypoint_load_links()
 
                        if(!found)
                        {
-                               dprint("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),"\n");
                                continue;
                        }
 
@@ -441,7 +441,7 @@ float waypoint_load_links()
 
                if(!found)
                {
-                       dprint("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),"\n");
                        continue;
                }
 
@@ -451,11 +451,7 @@ float waypoint_load_links()
 
        fclose(file);
 
-       dprint("loaded ");
-       dprint(ftos(c));
-       dprint(" waypoint links from maps/");
-       dprint(mapname);
-       dprint(".waypoints.cache\n");
+       LOG_TRACE("loaded ", ftos(c), " waypoint links from maps/", mapname, ".waypoints.cache\n");
 
        botframe_cachedwaypointlinks = true;
        return true;
@@ -475,9 +471,7 @@ void waypoint_load_links_hardwired()
 
        if (file < 0)
        {
-               dprint("waypoint links load from ");
-               dprint(filename);
-               dprint(" failed\n");
+               LOG_TRACE("waypoint links load from ", filename, " failed\n");
                return;
        }
 
@@ -515,7 +509,7 @@ void waypoint_load_links_hardwired()
 
                        if(!found)
                        {
-                               print(strcat("NOTICE: Can not find waypoint at ", vtos(wp_from_pos), ". Path skipped\n"));
+                               LOG_INFO(strcat("NOTICE: Can not find waypoint at ", vtos(wp_from_pos), ". Path skipped\n"));
                                continue;
                        }
                }
@@ -536,7 +530,7 @@ void waypoint_load_links_hardwired()
 
                if(!found)
                {
-                       print(strcat("NOTICE: Can not find waypoint at ", vtos(wp_to_pos), ". Path skipped\n"));
+                       LOG_INFO(strcat("NOTICE: Can not find waypoint at ", vtos(wp_to_pos), ". Path skipped\n"));
                        continue;
                }
 
@@ -548,11 +542,7 @@ void waypoint_load_links_hardwired()
 
        fclose(file);
 
-       dprint("loaded ");
-       dprint(ftos(c));
-       dprint(" waypoint links from maps/");
-       dprint(mapname);
-       dprint(".waypoints.hardwired\n");
+       LOG_TRACE("loaded ", ftos(c), " waypoint links from maps/", mapname, ".waypoints.hardwired\n");
 }
 
 entity waypoint_get_link(entity w, float i)
@@ -606,9 +596,9 @@ void waypoint_save_links()
        file = fopen(filename, FILE_WRITE);
        if (file < 0)
        {
-               print("waypoint links save to ");
-               print(filename);
-               print(" failed\n");
+               LOG_INFO("waypoint links save to ");
+               LOG_INFO(filename);
+               LOG_INFO(" failed\n");
        }
        c = 0;
        w = findchain(classname, "waypoint");
@@ -630,11 +620,11 @@ void waypoint_save_links()
        fclose(file);
        botframe_cachedwaypointlinks = true;
 
-       print("saved ");
-       print(ftos(c));
-       print(" waypoints links to maps/");
-       print(mapname);
-       print(".waypoints.cache\n");
+       LOG_INFO("saved ");
+       LOG_INFO(ftos(c));
+       LOG_INFO(" waypoints links to maps/");
+       LOG_INFO(mapname);
+       LOG_INFO(".waypoints.cache\n");
 }
 
 // save waypoints to gamedir/data/maps/mapname.waypoints
@@ -712,26 +702,18 @@ float waypoint_loadall()
                                cwb = cwb + 1;
                }
                fclose(file);
-               dprint("loaded ");
-               dprint(ftos(cwp));
-               dprint(" waypoints and ");
-               dprint(ftos(cwb));
-               dprint(" wayboxes from maps/");
-               dprint(mapname);
-               dprint(".waypoints\n");
+               LOG_TRACE("loaded ", ftos(cwp), " waypoints and ", ftos(cwb), " wayboxes from maps/", mapname, ".waypoints\n");
        }
        else
        {
-               dprint("waypoint load from ");
-               dprint(filename);
-               dprint(" 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);
@@ -808,7 +790,7 @@ void waypoint_spawnforteleporter(entity e, vector destination, float timetaken)
 }
 
 entity waypoint_spawnpersonal(vector position)
-{
+{SELFPARAM();
        entity w;
 
        // drop the waypoint to a proper location:
@@ -828,23 +810,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 +858,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;
@@ -967,7 +945,7 @@ float botframe_autowaypoints_fix_from(entity p, float walkfromwp, entity wp, .en
                }
                if(bestdist < maxdist)
                {
-                       print("update chain to new nearest WP ", etos(p.(fld)), "\n");
+                       LOG_INFO("update chain to new nearest WP ", etos(p.(fld)), "\n");
                        return 0;
                }
 
@@ -1046,7 +1024,7 @@ float botframe_autowaypoints_fix_from(entity p, float walkfromwp, entity wp, .en
                tmax = t;
        }
 
-       print("spawning a waypoint for connecting to ", etos(wp), "\n");
+       LOG_INFO("spawning a waypoint for connecting to ", etos(wp), "\n");
        botframe_autowaypoints_createwp(o, p, fld, 0);
        return 1;
 }
@@ -1062,7 +1040,7 @@ void botframe_autowaypoints_fix(entity p, float walkfromwp, .entity fld)
        if(r != -1)
                return;
 
-       print("emergency: got no good nearby WP to build a link from, starting a new chain\n");
+       LOG_INFO("emergency: got no good nearby WP to build a link from, starting a new chain\n");
        if(!botframe_autowaypoints_fixdown(p.origin))
                return; // shouldn't happen, caught above
        botframe_autowaypoints_createwp(trace_endpos, p, fld, WAYPOINTFLAG_PROTECTED);
@@ -1140,7 +1118,7 @@ void botframe_deleteuselesswaypoints()
        {
                if (!(w.wpflags & (WAYPOINTFLAG_USEFUL | WAYPOINTFLAG_DEAD_END)))
                {
-                       printf("Removed a waypoint at %v. Try again for more!\n", w.origin);
+                       LOG_INFOF("Removed a waypoint at %v. Try again for more!\n", w.origin);
                        te_explosion(w.origin);
                        waypoint_remove(w);
                        break;
@@ -1152,16 +1130,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) && it.deadflag == DEAD_NO, 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();