]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/waypoints.qc
Merge branch 'master' into divVerent/waypointeditor-auto
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / waypoints.qc
index 58c512b2758b679461d2016dac04c4348cdc5a8b..33ff6b39b2e7a8290024b4d2a76a57d74c96a2b1 100644 (file)
@@ -411,10 +411,10 @@ float waypoint_load_links()
 
                        if(!found)
                        {
-                               // can't find that waypoint
-                               fclose(file);
-                               return FALSE;
+                               dprint("waypoint_load_links: couldn't find 'from' waypoint at ", vtos(wp_from.origin),"\n");
+                               continue;
                        }
+
                }
 
                // Search "to" waypoint
@@ -433,9 +433,8 @@ float waypoint_load_links()
 
                if(!found)
                {
-                       // can't find that waypoint
-                       fclose(file);
-                       return FALSE;
+                       dprint("waypoint_load_links: couldn't find 'to' waypoint at ", vtos(wp_to.origin),"\n");
+                       continue;
                }
 
                ++c;
@@ -539,6 +538,8 @@ void waypoint_load_links_hardwired()
 
                ++c;
                waypoint_addlink(wp_from, wp_to);
+               wp_from.wphardwired = TRUE;
+               wp_to.wphardwired = TRUE;
        }
 
        fclose(file);
@@ -894,6 +895,7 @@ float botframe_autowaypoints_createwp(vector v, entity p, .entity fld)
        {
                // if a matching spawnfunc_waypoint already exists, don't add a duplicate
                if (boxesoverlap(v - '32 32 32', v + '32 32 32', w.absmin, w.absmax))
+               //if (boxesoverlap(v - '4 4 4', v + '4 4 4', w.absmin, w.absmax))
                        return 0;
                w = find(w, classname, "waypoint");
        }
@@ -924,26 +926,63 @@ float botframe_autowaypoints_fix_from(entity p, float walkfromwp, entity wp, .en
 
        if(wp)
        {
-               // if nearest WP from here is linked to wp, everything is fine
-               w = navigation_findnearestwaypoint(p, walkfromwp);
-               if(w != wp)
+               // if any WP w fulfills wp -> w -> porg, then switch from wp to w
+
+               // if wp -> porg, then OK
+               float maxdist;
+               if(navigation_waypoint_will_link(wp.origin, porg, p, walkfromwp, 1050))
+               {
+                       // we may find a better one
+                       maxdist = vlen(wp.origin - porg);
+               }
+               else
                {
-                       if(navigation_waypoint_will_link(w.origin, wp.origin, p, walkfromwp, 1050))
+                       // accept any "good"
+                       maxdist = 2100;
+               }
+
+               float bestdist;
+               bestdist = maxdist;
+               w = find(world, classname, "waypoint");
+               while (w)
+               {
+                       if(w != wp && !(w.wpflags & WAYPOINTFLAG_NORELINK))
                        {
-                               print("update chain from ", etos(p.fld), " to new nearest WP ", etos(w), "\n");
-                               p.fld = w;
-                               return 0;
+                               float d;
+                               d = vlen(wp.origin - w.origin) + vlen(w.origin - porg);
+                               if(d < bestdist)
+                                       if(navigation_waypoint_will_link(wp.origin, w.origin, p, walkfromwp, 1050))
+                                               if(navigation_waypoint_will_link(w.origin, porg, p, walkfromwp, 1050))
+                                               {
+                                                       bestdist = d;
+                                                       p.fld = w;
+                                               }
                        }
+                       w = find(w, classname, "waypoint");
                }
-               if(navigation_waypoint_will_link(p.origin, wp.origin, p, walkfromwp, 1050))
+               if(bestdist < maxdist)
                {
+                       print("update chain to new nearest WP ", etos(p.fld), "\n");
+                       return 0;
+               }
+
+               if(bestdist < 2100)
+               {
+                       // we know maxdist < 2100
+                       // so wp -> porg is still valid
+                       // all is good
                        p.fld = wp;
                        return 0;
                }
+
+               // otherwise, no existing WP can fix our issues
        }
        else
        {
+               save = p.origin;
+               setorigin(p, porg);
                w = navigation_findnearestwaypoint(p, walkfromwp);
+               setorigin(p, save);
                if(w)
                {
                        p.fld = w;
@@ -1032,7 +1071,9 @@ void botframe_autowaypoints()
        {
                if(p.deadflag)
                        continue;
-               botframe_autowaypoints_fix(p, FALSE, botframe_autowaypoints_lastwp0);
+               // 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);
+               //te_explosion(p.botframe_autowaypoints_lastwp0.origin);
        }
 }