]> 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 b13f183c7e77c5337c1d0ad6f53f435f6c881216..3387fdfef8fdcc1b4e5711cb9d3c165c979782b2 100644 (file)
@@ -204,7 +204,7 @@ float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float
                debugnodestatus(org, DEBUG_NODE_FAIL);
 
        return FALSE;
-};
+}
 
 /////////////////////////////////////////////////////////////////////////////
 // goal stack
@@ -247,7 +247,7 @@ void navigation_clearroute()
        self.goalstack29 = world;
        self.goalstack30 = world;
        self.goalstack31 = world;
-};
+}
 
 // add a new goal at the beginning of the stack
 // (in other words: add a new prerequisite before going to the later goals)
@@ -290,7 +290,7 @@ void navigation_pushroute(entity e)
        self.goalstack02 = self.goalstack01;
        self.goalstack01 = self.goalcurrent;
        self.goalcurrent = e;
-};
+}
 
 // remove first goal from stack
 // (in other words: remove a prerequisite for reaching the later goals)
@@ -330,14 +330,39 @@ void navigation_poproute()
        self.goalstack29 = self.goalstack30;
        self.goalstack30 = self.goalstack31;
        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)
@@ -482,7 +490,7 @@ void navigation_markroutes_checkwaypoint(entity w, entity wp, float cost2, vecto
                wp.wpfire = 1;
                wp.wpnearestpoint = v;
        }
-};
+}
 
 // queries the entire spawnfunc_waypoint network for pathes leading away from the bot
 void navigation_markroutes(entity fixed_source_waypoint)
@@ -578,7 +586,7 @@ void navigation_markroutes(entity fixed_source_waypoint)
                        w = w.chain;
                }
        }
-};
+}
 
 // queries the entire spawnfunc_waypoint network for pathes leading to the bot
 void navigation_markroutes_inverted(entity fixed_source_waypoint)
@@ -641,7 +649,7 @@ void navigation_markroutes_inverted(entity fixed_source_waypoint)
                        w = w.chain;
                }
        }
-};
+}
 
 // updates the best goal according to a weighted calculation of travel cost and item value of a new proposed item
 void navigation_routerating(entity e, float f, float rangebias)
@@ -825,7 +833,7 @@ void navigation_routerating(entity e, float f, float rangebias)
                }
        }
        //dprint("\n");
-};
+}
 
 // adds an item to the the goal stack with the path to a given item
 float navigation_routetogoal(entity e, vector startposition)
@@ -870,7 +878,7 @@ float navigation_routetogoal(entity e, vector startposition)
        }
 
        return FALSE;
-};
+}
 
 // removes any currently touching waypoints from the goal stack
 // (this is how bots detect if they reached a goal)
@@ -971,7 +979,7 @@ void navigation_goalrating_start()
        navigation_clearroute();
        navigation_bestgoal = world;
        navigation_markroutes(world);
-};
+}
 
 // ends a goal selection session (updates goal stack to the best goal)
 void navigation_goalrating_end()
@@ -994,7 +1002,7 @@ void navigation_goalrating_end()
 
                self.navigation_hasgoals = FALSE; // Reset this value
        }
-};
+}
 
 void botframe_updatedangerousobjects(float maxupdate)
 {
@@ -1032,7 +1040,7 @@ void botframe_updatedangerousobjects(float maxupdate)
                        break;
                botframe_dangerwaypoint = find(botframe_dangerwaypoint, classname, "waypoint");
        }
-};
+}
 
 void navigation_unstuck()
 {