]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/default/waypoints.qc
Merge branch 'terencehill/bot_waypoints' into terencehill/bot_ai
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / default / waypoints.qc
index c3b67a378fef08ac1a7823ceeb7064f049ef86a3..fa82d926b63e92776cfd293dbebccf15ba20ad04 100644 (file)
@@ -179,19 +179,12 @@ void waypoint_setupmodel(entity wp)
                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)
 entity waypoint_spawn(vector m1, vector m2, float f)
 {
-       if(!(f & WAYPOINTFLAG_PERSONAL))
+       if(!(f & (WAYPOINTFLAG_PERSONAL | WAYPOINTFLAG_GENERATED)) && m1 == m2)
        {
-               vector em1 = m1, em2 = m2;
-               if (!(f & WAYPOINTFLAG_GENERATED) && m1 == m2)
-               {
-                       em1 = m1 - '8 8 8';
-                       em2 = m2 + '8 8 8';
-               }
+               vector em1 = m1 - '8 8 8';
+               vector em2 = m2 + '8 8 8';
                IL_EACH(g_waypoints, boxesoverlap(em1, em2, it.absmin, it.absmax),
                {
                        return it;
@@ -583,8 +576,12 @@ void waypoint_think(entity this)
                                continue;
                        }
 
-                       SET_TRACEWALK_DESTCOORDS_2(this, it.origin, sv, sv2, sv2_height);
-                       SET_TRACEWALK_DESTCOORDS_2(it, this.origin, ev, ev2, ev2_height);
+                       sv = set_tracewalk_dest_2(this, it.origin);
+                       sv2 = tracewalk_dest;
+                       sv2_height = tracewalk_dest_height;
+                       ev = set_tracewalk_dest_2(it, this.origin);
+                       ev2 = tracewalk_dest;
+                       ev2_height = tracewalk_dest_height;
 
                        dv = ev - sv;
                        dv.z = 0;
@@ -682,22 +679,32 @@ void waypoint_schedulerelinkall()
        waypoint_load_links_hardwired();
 }
 
+#define GET_GAMETYPE_EXTENSION() ((g_race) ? ".race" : "")
+
 // Load waypoint links from file
 bool waypoint_load_links()
 {
-       string filename, s;
+       string s;
        float file, tokens, c = 0, found;
        entity wp_from = NULL, wp_to;
        vector wp_to_pos, wp_from_pos;
-       filename = strcat("maps/", mapname);
-       filename = strcat(filename, ".waypoints.cache");
+
+       string gt_ext = GET_GAMETYPE_EXTENSION();
+
+       string filename = sprintf("maps/%s.waypoints.cache", strcat(mapname, gt_ext));
        file = fopen(filename, FILE_READ);
 
+       if (gt_ext != "" && file < 0)
+       {
+               // if race waypoint file doesn't exist load the default one
+               filename = sprintf("maps/%s.waypoints.cache", mapname);
+               file = fopen(filename, FILE_READ);
+       }
+
        if (file < 0)
        {
-               LOG_TRACE("waypoint links load from ");
-               LOG_TRACE(filename);
-               LOG_TRACE(" failed");
+               LOG_TRACE("waypoint links load from ", filename, " failed");
+               waypoint_schedulerelinkall();
                return false;
        }
 
@@ -717,7 +724,20 @@ bool waypoint_load_links()
                        else
                        {
                                if(ver < WAYPOINT_VERSION)
-                                       return false;
+                               {
+                                       LOG_TRACE("waypoint links for this map are outdated.");
+                                       if (g_assault)
+                                       {
+                                               LOG_TRACE("Assault waypoint links need to be manually updated in the editor");
+                                       }
+                                       else
+                                       {
+                                               LOG_TRACE("automatically updating...");
+                                               waypoint_schedulerelinkall();
+                                               fclose(file);
+                                               return false;
+                                       }
+                               }
                                parse_comments = false;
                        }
                }
@@ -728,6 +748,7 @@ bool waypoint_load_links()
                {
                        // bad file format
                        fclose(file);
+                       waypoint_schedulerelinkall(); // link all the autogenerated waypoints (teleporters)
                        return false;
                }
 
@@ -755,7 +776,6 @@ bool waypoint_load_links()
                                LOG_TRACE("waypoint_load_links: couldn't find 'from' waypoint at ", vtos(wp_from_pos));
                                continue;
                        }
-
                }
 
                // Search "to" waypoint
@@ -784,7 +804,19 @@ bool waypoint_load_links()
 
        fclose(file);
 
-       LOG_TRACE("loaded ", ftos(c), " waypoint links from maps/", mapname, ".waypoints.cache");
+       LOG_TRACE("loaded ", ftos(c), " waypoint links from ", filename);
+
+       bool scheduled = false;
+       IL_EACH(g_waypoints, it.wpflags & WAYPOINTFLAG_ITEM,
+       {
+               if (!it.wp00)
+               {
+                       waypoint_schedulerelink(it);
+                       scheduled = true;
+               }
+       });
+       if (scheduled)
+               return false;
 
        botframe_cachedwaypointlinks = true;
        return true;
@@ -792,14 +824,23 @@ bool waypoint_load_links()
 
 void waypoint_load_or_remove_links_hardwired(bool removal_mode)
 {
-       string filename, s;
+       string s;
        float file, tokens, c = 0, found;
        entity wp_from = NULL, wp_to;
        vector wp_to_pos, wp_from_pos;
-       filename = strcat("maps/", mapname);
-       filename = strcat(filename, ".waypoints.hardwired");
+
+       string gt_ext = GET_GAMETYPE_EXTENSION();
+
+       string filename = sprintf("maps/%s.waypoints.hardwired", strcat(mapname, gt_ext));
        file = fopen(filename, FILE_READ);
 
+       if (gt_ext != "" && file < 0)
+       {
+               // if race waypoint file doesn't exist load the default one
+               filename = sprintf("maps/%s.waypoints.hardwired", mapname);
+               file = fopen(filename, FILE_READ);
+       }
+
        botframe_loadedforcedlinks = true;
 
        if (file < 0)
@@ -886,8 +927,8 @@ void waypoint_load_or_remove_links_hardwired(bool removal_mode)
 
        fclose(file);
 
-       if(!removal_mode)
-               LOG_TRACE("loaded ", ftos(c), " waypoint links from maps/", mapname, ".waypoints.hardwired");
+       LOG_TRACE(((removal_mode) ? "unloaded " : "loaded "),
+               ftos(c), " waypoint links from maps/", mapname, ".waypoints.hardwired");
 }
 
 entity waypoint_get_link(entity w, float i)
@@ -936,7 +977,9 @@ 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);
+       string gt_ext = GET_GAMETYPE_EXTENSION();
+
+       string filename = sprintf("maps/%s.waypoints.cache", strcat(mapname, gt_ext));
        int file = fopen(filename, FILE_WRITE);
        if (file < 0)
        {
@@ -961,9 +1004,10 @@ void waypoint_save_links()
                }
        });
        fclose(file);
+
        botframe_cachedwaypointlinks = true;
 
-       LOG_INFOF("saved %d waypoint links to maps/%s.waypoints.cache", c, mapname);
+       LOG_INFOF("saved %d waypoint links to %s", c, filename);
 
        waypoint_load_links_hardwired();
 }
@@ -971,7 +1015,9 @@ void waypoint_save_links()
 // save waypoints to gamedir/data/maps/mapname.waypoints
 void waypoint_saveall()
 {
-       string filename = sprintf("maps/%s.waypoints", mapname);
+       string gt_ext = GET_GAMETYPE_EXTENSION();
+
+       string filename = sprintf("maps/%s.waypoints", strcat(mapname, gt_ext));
        int file = fopen(filename, FILE_WRITE);
        if (file < 0)
        {
@@ -1007,23 +1053,29 @@ void waypoint_saveall()
        waypoint_save_links();
        botframe_loadedforcedlinks = false;
 
-       LOG_INFOF("saved %d waypoints to maps/%s.waypoints", c, mapname);
+       LOG_INFOF("saved %d waypoints to %s", c, filename);
 }
 
 // load waypoints from file
 float waypoint_loadall()
 {
-       string filename, s;
+       string s;
        float file, cwp, cwb, fl;
        vector m1, m2;
        cwp = 0;
        cwb = 0;
-       filename = strcat("maps/", mapname);
-       filename = strcat(filename, ".waypoints");
+
+       string gt_ext = GET_GAMETYPE_EXTENSION();
+
+       string filename = sprintf("maps/%s.waypoints", strcat(mapname, gt_ext));
        file = fopen(filename, FILE_READ);
 
-       bool parse_comments = true;
-       float ver = 0;
+       if (gt_ext != "" && file < 0)
+       {
+               // if race waypoint file doesn't exist load the default one
+               filename = sprintf("maps/%s.waypoints", mapname);
+               file = fopen(filename, FILE_READ);
+       }
 
        if (file < 0)
        {
@@ -1031,6 +1083,9 @@ float waypoint_loadall()
                return 0;
        }
 
+       bool parse_comments = true;
+       float ver = 0;
+
        while ((s = fgets(file)))
        {
                if(parse_comments)
@@ -1044,7 +1099,10 @@ float waypoint_loadall()
                        else
                        {
                                if(floor(ver) < floor(WAYPOINT_VERSION))
+                               {
                                        LOG_TRACE("waypoints for this map are outdated");
+                                       LOG_TRACE("please update them in the editor");
+                               }
                                parse_comments = false;
                        }
                }