X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fbot%2Fnavigation.qc;h=2e40f09601bf5763edb90a9d82e0ffe31e9efa60;hb=0ce2bdf81013a9a30117a5e3083d536ced038bb3;hp=ad0a8d761d4bdfff7a8aca640ebc8c6ddf8b8d51;hpb=2aed36e128f8f00da9c76f9e66baae89d5bb26b2;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/bot/navigation.qc b/qcsrc/server/bot/navigation.qc index ad0a8d761..2e40f0960 100644 --- a/qcsrc/server/bot/navigation.qc +++ b/qcsrc/server/bot/navigation.qc @@ -1,28 +1,22 @@ #include "navigation.qh" -#include "../_all.qh" #include "bot.qh" #include "waypoints.qh" -#include "../t_items.qh" +#include -#include "../../common/constants.qh" -#include "../../common/triggers/trigger/jumppads.qh" +#include -void bot_debug(string input) -{ - switch(autocvar_bot_debug) - { - case 1: dprint(input); break; - case 2: print(input); break; - } -} +#include +#include + +.float speed; // rough simulation of walking from one point to another to test if a path // can be traveled, used for waypoint linking and havocbot float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float movemode) -{ +{SELFPARAM(); vector org; vector move; vector dir; @@ -232,7 +226,7 @@ float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float // completely empty the goal stack, used when deciding where to go void navigation_clearroute() -{ +{SELFPARAM(); //print("bot ", etos(self), " clear\n"); self.navigation_hasgoals = false; self.goalcurrent = world; @@ -276,7 +270,7 @@ void navigation_clearroute() // That means, if the stack overflows, the bot will know how to do the FIRST 32 // steps to the goal, and then recalculate the path. void navigation_pushroute(entity e) -{ +{SELFPARAM(); //print("bot ", etos(self), " push ", etos(e), "\n"); self.goalstack31 = self.goalstack30; self.goalstack30 = self.goalstack29; @@ -316,7 +310,7 @@ void navigation_pushroute(entity e) // (in other words: remove a prerequisite for reaching the later goals) // (used when a spawnfunc_waypoint is reached) void navigation_poproute() -{ +{SELFPARAM(); //print("bot ", etos(self), " pop\n"); self.goalcurrent = self.goalstack01; self.goalstack01 = self.goalstack02; @@ -363,12 +357,12 @@ float navigation_waypoint_will_link(vector v, vector org, entity ent, float walk { if (walkfromwp) { - if (tracewalk(ent, v, PL_MIN, PL_MAX, org, bot_navigation_movemode)) + if (tracewalk(ent, v, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), org, bot_navigation_movemode)) return true; } else { - if (tracewalk(ent, org, PL_MIN, PL_MAX, v, bot_navigation_movemode)) + if (tracewalk(ent, org, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), v, bot_navigation_movemode)) return true; } } @@ -398,7 +392,7 @@ entity navigation_findnearestwaypoint_withdist_except(entity ent, float walkfrom } org = ent.origin + 0.5 * (ent.mins + ent.maxs); - org.z = ent.origin.z + ent.mins.z - PL_MIN.z; // player height + org.z = ent.origin.z + ent.mins.z - STAT(PL_MIN, NULL).z; // player height // TODO possibly make other code have the same support for bboxes if(ent.tag_entity) org = org + ent.tag_entity.origin; @@ -449,7 +443,7 @@ entity navigation_findnearestwaypoint(entity ent, float walkfromwp) // finds the waypoints near the bot initiating a navigation query float navigation_markroutes_nearestwaypoints(entity waylist, float maxdist) -{ +{SELFPARAM(); entity head; vector v, m1, m2, diff; float c; @@ -520,7 +514,7 @@ void navigation_markroutes_checkwaypoint(entity w, entity wp, float cost2, vecto // queries the entire spawnfunc_waypoint network for pathes leading away from the bot void navigation_markroutes(entity fixed_source_waypoint) -{ +{SELFPARAM(); entity w, wp, waylist; float searching, cost, cost2; vector p; @@ -548,7 +542,7 @@ void navigation_markroutes(entity fixed_source_waypoint) // try a short range search for the nearest waypoints, and expand the search repeatedly if none are found // as this search is expensive we will use lower values if the bot is on the air float i, increment, maxdistance; - if(self.flags & FL_ONGROUND) + if(IS_ONGROUND(self)) { increment = 750; maxdistance = 50000; @@ -679,7 +673,7 @@ void navigation_markroutes_inverted(entity fixed_source_waypoint) // 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) -{ +{SELFPARAM(); entity nwp; vector o; if (!e) @@ -700,7 +694,7 @@ void navigation_routerating(entity e, float f, float rangebias) { vector pointa, pointb; - bot_debug(strcat("jetpack ai: evaluating path for ", e.classname, "\n")); + LOG_DEBUG("jetpack ai: evaluating path for ", e.classname, "\n"); // Point A traceline(self.origin, self.origin + '0 0 65535', MOVE_NORMAL, self); @@ -715,13 +709,13 @@ void navigation_routerating(entity e, float f, float rangebias) if(trace_fraction==1) { - bot_debug("jetpack ai: can bridge these two points\n"); + LOG_DEBUG("jetpack ai: can bridge these two points\n"); // Lower the altitude of these points as much as possible float zdistance, xydistance, cost, t, fuel; vector down, npa, npb; - down = '0 0 -1' * (PL_MAX.z - PL_MIN.z) * 10; + down = '0 0 -1' * (STAT(PL_MAX, NULL).z - STAT(PL_MIN, NULL).z) * 10; do{ npa = pointa + down; @@ -752,7 +746,7 @@ void navigation_routerating(entity e, float f, float rangebias) t += xydistance / autocvar_g_jetpack_maxspeed_side; fuel = t * autocvar_g_jetpack_fuel * 0.8; - bot_debug(strcat("jetpack ai: required fuel ", ftos(fuel), " self.ammo_fuel ", ftos(self.ammo_fuel), "\n")); + LOG_DEBUG(strcat("jetpack ai: required fuel ", ftos(fuel), " self.ammo_fuel ", ftos(self.ammo_fuel), "\n")); // enough fuel ? if(self.ammo_fuel>fuel) @@ -770,7 +764,7 @@ void navigation_routerating(entity e, float f, float rangebias) if (navigation_bestrating < f) { - bot_debug(strcat("jetpack path: added goal ", e.classname, " (with rating ", ftos(f), ")\n")); + LOG_DEBUG(strcat("jetpack path: added goal ", e.classname, " (with rating ", ftos(f), ")\n")); navigation_bestrating = f; navigation_bestgoal = e; self.navigation_jetpack_goal = e; @@ -816,7 +810,7 @@ void navigation_routerating(entity e, float f, float rangebias) e.nearestwaypoint = nwp; else { - bot_debug(strcat("FAILED to find a nearest waypoint to '", e.classname, "' #", etos(e), "\n")); + LOG_DEBUG(strcat("FAILED to find a nearest waypoint to '", e.classname, "' #", etos(e), "\n")); if(e.flags & FL_ITEM) e.blacklisted = true; @@ -828,7 +822,7 @@ void navigation_routerating(entity e, float f, float rangebias) if(e.blacklisted) { - bot_debug(strcat("The entity '", e.classname, "' is going to be excluded from path finding during this match\n")); + LOG_DEBUG(strcat("The entity '", e.classname, "' is going to be excluded from path finding during this match\n")); return; } } @@ -842,17 +836,17 @@ void navigation_routerating(entity e, float f, float rangebias) nwp = e.nearestwaypoint; } - bot_debug(strcat("-- checking ", e.classname, " (with cost ", ftos(nwp.wpcost), ")\n")); + LOG_DEBUG(strcat("-- checking ", e.classname, " (with cost ", ftos(nwp.wpcost), ")\n")); if (nwp) if (nwp.wpcost < 10000000) { //te_wizspike(nwp.wpnearestpoint); - bot_debug(strcat(e.classname, " ", ftos(f), "/(1+", ftos((nwp.wpcost + vlen(e.origin - nwp.wpnearestpoint))), "/", ftos(rangebias), ") = ")); + LOG_DEBUG(strcat(e.classname, " ", ftos(f), "/(1+", ftos((nwp.wpcost + vlen(e.origin - nwp.wpnearestpoint))), "/", ftos(rangebias), ") = ")); f = f * rangebias / (rangebias + (nwp.wpcost + vlen(o - nwp.wpnearestpoint))); - bot_debug(strcat("considering ", e.classname, " (with rating ", ftos(f), ")\n")); + LOG_DEBUG(strcat("considering ", e.classname, " (with rating ", ftos(f), ")\n")); if (navigation_bestrating < f) { - bot_debug(strcat("ground path: added goal ", e.classname, " (with rating ", ftos(f), ")\n")); + LOG_DEBUG(strcat("ground path: added goal ", e.classname, " (with rating ", ftos(f), ")\n")); navigation_bestrating = f; navigation_bestgoal = e; } @@ -861,7 +855,7 @@ void navigation_routerating(entity e, float f, float rangebias) // adds an item to the the goal stack with the path to a given item float navigation_routetogoal(entity e, vector startposition) -{ +{SELFPARAM(); self.goalentity = e; // if there is no goal, just exit @@ -879,7 +873,7 @@ float navigation_routetogoal(entity e, vector startposition) return true; // if it can reach the goal there is nothing more to do - if (tracewalk(self, startposition, PL_MIN, PL_MAX, (e.absmin + e.absmax) * 0.5, bot_navigation_movemode)) + if (tracewalk(self, startposition, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), (e.absmin + e.absmax) * 0.5, bot_navigation_movemode)) return true; // see if there are waypoints describing a path to the item @@ -907,7 +901,7 @@ float navigation_routetogoal(entity e, vector startposition) // removes any currently touching waypoints from the goal stack // (this is how bots detect if they reached a goal) void navigation_poptouchedgoals() -{ +{SELFPARAM(); vector org, m1, m2; org = self.origin; m1 = org + self.mins; @@ -935,7 +929,7 @@ void navigation_poptouchedgoals() if(checkpvs(self.origin + self.view_ofs, self.goalstack01)) if(tracewalk(self, self.origin, self.mins, self.maxs, (self.goalstack01.absmin + self.goalstack01.absmax) * 0.5, bot_navigation_movemode)) { - bot_debug(strcat("path optimized for ", self.netname, ", removed a goal from the queue\n")); + LOG_DEBUG(strcat("path optimized for ", self.netname, ", removed a goal from the queue\n")); navigation_poproute(); // TODO this may also be a nice idea to do "early" (e.g. by // manipulating the vlen() comparisons) to shorten paths in @@ -993,7 +987,7 @@ void navigation_poptouchedgoals() // begin a goal selection session (queries spawnfunc_waypoint network) void navigation_goalrating_start() -{ +{SELFPARAM(); if(self.aistatus & AI_STATUS_STUCK) return; @@ -1007,12 +1001,12 @@ void navigation_goalrating_start() // ends a goal selection session (updates goal stack to the best goal) void navigation_goalrating_end() -{ +{SELFPARAM(); if(self.aistatus & AI_STATUS_STUCK) return; navigation_routetogoal(navigation_bestgoal, self.origin); - bot_debug(strcat("best goal ", self.goalcurrent.classname , "\n")); + LOG_DEBUG(strcat("best goal ", self.goalcurrent.classname , "\n")); // If the bot got stuck then try to reach the farthest waypoint if (!self.navigation_hasgoals) @@ -1020,7 +1014,7 @@ void navigation_goalrating_end() { if (!(self.aistatus & AI_STATUS_STUCK)) { - bot_debug(strcat(self.netname, " cannot walk to any goal\n")); + LOG_DEBUG(strcat(self.netname, " cannot walk to any goal\n")); self.aistatus |= AI_STATUS_STUCK; } @@ -1067,7 +1061,7 @@ void botframe_updatedangerousobjects(float maxupdate) } void navigation_unstuck() -{ +{SELFPARAM(); float search_radius = 1000; if (!autocvar_bot_wander_enable) @@ -1075,7 +1069,7 @@ void navigation_unstuck() if (!bot_waypoint_queue_owner) { - bot_debug(strcat(self.netname, " sutck, taking over the waypoints queue\n")); + LOG_DEBUG(strcat(self.netname, " sutck, taking over the waypoints queue\n")); bot_waypoint_queue_owner = self; bot_waypoint_queue_bestgoal = world; bot_waypoint_queue_bestgoalrating = 0; @@ -1088,8 +1082,8 @@ void navigation_unstuck() { // evaluate the next goal on the queue float d = vlen(self.origin - bot_waypoint_queue_goal.origin); - bot_debug(strcat(self.netname, " evaluating ", bot_waypoint_queue_goal.classname, " with distance ", ftos(d), "\n")); - if(tracewalk(bot_waypoint_queue_goal, self.origin, PL_MIN, PL_MAX, bot_waypoint_queue_goal.origin, bot_navigation_movemode)) + LOG_DEBUG(strcat(self.netname, " evaluating ", bot_waypoint_queue_goal.classname, " with distance ", ftos(d), "\n")); + if(tracewalk(bot_waypoint_queue_goal, self.origin, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), bot_waypoint_queue_goal.origin, bot_navigation_movemode)) { if( d > bot_waypoint_queue_bestgoalrating) { @@ -1103,14 +1097,14 @@ void navigation_unstuck() { if (bot_waypoint_queue_bestgoal) { - bot_debug(strcat(self.netname, " stuck, reachable waypoint found, heading to it\n")); + LOG_DEBUG(strcat(self.netname, " stuck, reachable waypoint found, heading to it\n")); navigation_routetogoal(bot_waypoint_queue_bestgoal, self.origin); self.bot_strategytime = time + autocvar_bot_ai_strategyinterval; self.aistatus &= ~AI_STATUS_STUCK; } else { - bot_debug(strcat(self.netname, " stuck, cannot walk to any waypoint at all\n")); + LOG_DEBUG(strcat(self.netname, " stuck, cannot walk to any waypoint at all\n")); } bot_waypoint_queue_owner = world; @@ -1122,7 +1116,7 @@ void navigation_unstuck() return; // build a new queue - bot_debug(strcat(self.netname, " stuck, scanning reachable waypoints within ", ftos(search_radius)," qu\n")); + LOG_DEBUG(strcat(self.netname, " stuck, scanning reachable waypoints within ", ftos(search_radius)," qu\n")); entity head, first; @@ -1150,7 +1144,7 @@ void navigation_unstuck() bot_waypoint_queue_goal = first; else { - bot_debug(strcat(self.netname, " stuck, cannot walk to any waypoint at all\n")); + LOG_DEBUG(strcat(self.netname, " stuck, cannot walk to any waypoint at all\n")); bot_waypoint_queue_owner = world; } } @@ -1164,7 +1158,7 @@ void debugresetnodes() } void debugnode(vector node) -{ +{SELFPARAM(); if (!IS_PLAYER(self)) return; @@ -1207,7 +1201,7 @@ void debugnodestatus(vector position, float status) // Debug the goal stack visually void debuggoalstack() -{ +{SELFPARAM(); entity goal; vector org, go;