]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/default/waypoints.qc
Merge branch 'martin-t/angles' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / default / waypoints.qc
index 059a2c8f63e69d3e4bcf192a04f1fd464007ecfc..c8a958ddbd0f2a0fca0cf8f3e7606d684ea77c7d 100644 (file)
@@ -1,5 +1,7 @@
 #include "waypoints.qh"
 
+#include <server/defs.qh>
+#include <server/miscfunctions.qh>
 #include "cvars.qh"
 
 #include "bot.qh"
@@ -462,7 +464,7 @@ float waypoint_load_links()
        return true;
 }
 
-void waypoint_load_links_hardwired()
+void waypoint_load_or_remove_links_hardwired(bool removal_mode)
 {
        string filename, s;
        float file, tokens, c = 0, found;
@@ -476,7 +478,8 @@ void waypoint_load_links_hardwired()
 
        if (file < 0)
        {
-               LOG_TRACE("waypoint links load from ", filename, " failed");
+               if(!removal_mode)
+                       LOG_TRACE("waypoint links load from ", filename, " failed");
                return;
        }
 
@@ -514,7 +517,8 @@ void waypoint_load_links_hardwired()
 
                        if(!found)
                        {
-                               LOG_INFO(strcat("NOTICE: Can not find waypoint at ", vtos(wp_from_pos), ". Path skipped\n"));
+                               if(!removal_mode)
+                                       LOG_INFO(strcat("NOTICE: Can not find waypoint at ", vtos(wp_from_pos), ". Path skipped\n"));
                                continue;
                        }
                }
@@ -535,11 +539,18 @@ void waypoint_load_links_hardwired()
 
                if(!found)
                {
-                       LOG_INFO(strcat("NOTICE: Can not find waypoint at ", vtos(wp_to_pos), ". Path skipped\n"));
+                       if(!removal_mode)
+                               LOG_INFO(strcat("NOTICE: Can not find waypoint at ", vtos(wp_to_pos), ". Path skipped\n"));
                        continue;
                }
 
                ++c;
+               if(removal_mode)
+               {
+                       waypoint_removelink(wp_from, wp_to);
+                       continue;
+               }
+
                waypoint_addlink(wp_from, wp_to);
                wp_from.wphardwired = true;
                wp_to.wphardwired = true;
@@ -547,9 +558,13 @@ void waypoint_load_links_hardwired()
 
        fclose(file);
 
-       LOG_TRACE("loaded ", ftos(c), " waypoint links from maps/", mapname, ".waypoints.hardwired");
+       if(!removal_mode)
+               LOG_TRACE("loaded ", ftos(c), " waypoint links from maps/", mapname, ".waypoints.hardwired");
 }
 
+void waypoint_load_links_hardwired() { waypoint_load_or_remove_links_hardwired(false); }
+void waypoint_remove_links_hardwired() { waypoint_load_or_remove_links_hardwired(true); }
+
 entity waypoint_get_link(entity w, float i)
 {
        switch(i)
@@ -593,6 +608,9 @@ entity waypoint_get_link(entity w, float i)
 // Save all waypoint links to a file
 void waypoint_save_links()
 {
+       // temporarily remove hardwired links so they don't get saved among normal links
+       waypoint_remove_links_hardwired();
+
        string filename = sprintf("maps/%s.waypoints.cache", mapname);
        int file = fopen(filename, FILE_WRITE);
        if (file < 0)
@@ -619,6 +637,8 @@ void waypoint_save_links()
        botframe_cachedwaypointlinks = true;
 
        LOG_INFOF("saved %d waypoint links to maps/%s.waypoints.cache\n", c, mapname);
+
+       waypoint_load_links_hardwired();
 }
 
 // save waypoints to gamedir/data/maps/mapname.waypoints
@@ -1113,12 +1133,12 @@ LABEL(next)
 
 void botframe_autowaypoints()
 {
-       FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && !IS_DEAD(it), LAMBDA(
+       FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && !IS_DEAD(it), {
                // going back is broken, so only fix waypoints to walk TO the player
                //botframe_autowaypoints_fix(p, false, botframe_autowaypoints_lastwp0);
                botframe_autowaypoints_fix(it, true, botframe_autowaypoints_lastwp1);
                //te_explosion(p.botframe_autowaypoints_lastwp0.origin);
-       ));
+       });
 
        if (autocvar_g_waypointeditor_auto >= 2) {
                botframe_deleteuselesswaypoints();