]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/navigation.qc
Merge remote-tracking branch 'origin/divVerent/new-laser-by-morphed'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / navigation.qc
index 6aa6ea2a17f8a32b4f22df6d5c702df0ee591bd6..3387fdfef8fdcc1b4e5711cb9d3c165c979782b2 100644 (file)
@@ -332,12 +332,37 @@ void navigation_poproute()
        self.goalstack31 = world;
 }
 
+float navigation_waypoint_will_link(vector v, vector org, entity ent, float walkfromwp, float bestdist)
+{
+       float dist;
+       dist = vlen(v - org);
+       if (bestdist > dist)
+       {
+               traceline(v, org, TRUE, ent);
+               if (trace_fraction == 1)
+               {
+                       if (walkfromwp)
+                       {
+                               if (tracewalk(ent, v, PL_MIN, PL_MAX, org, bot_navigation_movemode))
+                                       return TRUE;
+                       }
+                       else
+                       {
+                               if (tracewalk(ent, org, PL_MIN, PL_MAX, v, bot_navigation_movemode))
+                                       return TRUE;
+                       }
+               }
+       }
+       return FALSE;
+}
+
 // find the spawnfunc_waypoint near a dynamic goal such as a dropped weapon
-entity navigation_findnearestwaypoint(entity ent, float walkfromwp)
+entity navigation_findnearestwaypoint_withdist(entity ent, float walkfromwp, float bestdist)
 {
        entity waylist, w, best;
-       float dist, bestdist;
+       float dist;
        vector v, org, pm1, pm2;
+
        pm1 = ent.origin + ent.mins;
        pm2 = ent.origin + ent.maxs;
        waylist = findchain(classname, "waypoint");
@@ -362,7 +387,6 @@ entity navigation_findnearestwaypoint(entity ent, float walkfromwp)
                te_plasmaburn(org);
 
        best = world;
-       bestdist = 1050;
 
        // box check failed, try walk
        w = waylist;
@@ -382,36 +406,20 @@ entity navigation_findnearestwaypoint(entity ent, float walkfromwp)
                        }
                        else
                                v = w.origin;
-                       dist = vlen(v - org);
-                       if (bestdist > dist)
+                       if(navigation_waypoint_will_link(v, org, ent, walkfromwp, bestdist))
                        {
-                               traceline(v, org, TRUE, ent);
-                               if (trace_fraction == 1)
-                               {
-                                       if (walkfromwp)
-                                       {
-                                               //print("^1can I reach ", vtos(org), " from ", vtos(v), "?\n");
-                                               if (tracewalk(ent, v, PL_MIN, PL_MAX, org, bot_navigation_movemode))
-                                               {
-                                                       bestdist = dist;
-                                                       best = w;
-                                               }
-                                       }
-                                       else
-                                       {
-                                               if (tracewalk(ent, org, PL_MIN, PL_MAX, v, bot_navigation_movemode))
-                                               {
-                                                       bestdist = dist;
-                                                       best = w;
-                                               }
-                                       }
-                               }
+                               bestdist = vlen(v - org);
+                               best = w;
                        }
                }
                w = w.chain;
        }
        return best;
 }
+entity navigation_findnearestwaypoint(entity ent, float walkfromwp)
+{
+       return navigation_findnearestwaypoint_withdist(ent, walkfromwp, 1050);
+}
 
 // finds the waypoints near the bot initiating a navigation query
 float navigation_markroutes_nearestwaypoints(entity waylist, float maxdist)