X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fbot%2Fnavigation.qc;h=99e3901b2b3cb095b771a89286c9b5ac1bcae721;hb=ef74e1ba8e890befb4a4892a96d244a66c05fd48;hp=8c244bf8b50e3b6d750059a82448a30dc336fee3;hpb=6c4f62990980e74d4a0963b7179c7c964f535398;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/bot/navigation.qc b/qcsrc/server/bot/navigation.qc index 8c244bf8b..99e3901b2 100644 --- a/qcsrc/server/bot/navigation.qc +++ b/qcsrc/server/bot/navigation.qc @@ -1,9 +1,20 @@ +#include "navigation.qh" +#include "../_all.qh" + +#include "bot.qh" +#include "waypoints.qh" + +#include "../t_items.qh" + +#include "../../common/constants.qh" +#include "../../common/triggers/trigger/jumppads.qh" + void bot_debug(string input) { switch(autocvar_bot_debug) { - case 1: dprint(input); break; - case 2: print(input); break; + case 1: LOG_TRACE(input); break; + case 2: LOG_INFO(input); break; } } @@ -11,7 +22,7 @@ void bot_debug(string input) // 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; @@ -29,25 +40,25 @@ float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float } move = end - start; - move_z = 0; + move.z = 0; org = start; dist = totaldist = vlen(move); dir = normalize(move); stepdist = 32; - ignorehazards = FALSE; - swimming = FALSE; + ignorehazards = false; + swimming = false; // Analyze starting point traceline(start, start, MOVE_NORMAL, e); if (trace_dpstartcontents & (DPCONTENTS_SLIME | DPCONTENTS_LAVA)) - ignorehazards = TRUE; + ignorehazards = true; else { traceline( start, start + '0 0 -65536', MOVE_NORMAL, e); if (trace_dpstartcontents & (DPCONTENTS_SLIME | DPCONTENTS_LAVA)) { - ignorehazards = TRUE; - swimming = TRUE; + ignorehazards = true; + swimming = true; } } tracebox(start, m1, m2, start, MOVE_NOMONSTERS, e); @@ -58,13 +69,13 @@ float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float debugnodestatus(start, DEBUG_NODE_FAIL); //print("tracewalk: ", vtos(start), " is a bad start\n"); - return FALSE; + return false; } // Movement loop yaw = vectoyaw(move); move = end - org; - for(0;;) + for (;;) { if (boxesoverlap(end, end, org + m1 + '-1 -1 -1', org + m2 + '1 1 1')) { @@ -73,7 +84,7 @@ float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float debugnodestatus(org, DEBUG_NODE_SUCCESS); //print("tracewalk: ", vtos(start), " can reach ", vtos(end), "\n"); - return TRUE; + return true; } if(autocvar_bot_debug_tracewalk) debugnode(org); @@ -93,7 +104,7 @@ float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float debugnodestatus(org, DEBUG_NODE_FAIL); //print("tracewalk: ", vtos(start), " hits a hazard when trying to reach ", vtos(end), "\n"); - return FALSE; + return false; } } if (trace_dpstartcontents & DPCONTENTS_LIQUIDSMASK) @@ -106,9 +117,9 @@ float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float if (trace_fraction < 1) { - swimming = TRUE; + swimming = true; org = trace_endpos - normalize(org - trace_endpos) * stepdist; - for(0; org.z < end.z + self.maxs.z; org.z += stepdist) + for (; org.z < end.z + self.maxs.z; org.z += stepdist) { if(autocvar_bot_debug_tracewalk) debugnode(org); @@ -122,7 +133,7 @@ float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float if(autocvar_bot_debug_tracewalk) debugnodestatus(org, DEBUG_NODE_FAIL); - return FALSE; + return false; //print("tracewalk: ", vtos(start), " failed under water\n"); } continue; @@ -173,7 +184,7 @@ float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float //print("tracewalk: ", vtos(start), " hit something when trying to reach ", vtos(end), "\n"); //te_explosion(trace_endpos); //print(ftos(e.dphitcontentsmask), "\n"); - return FALSE; // failed + return false; // failed } } else @@ -197,7 +208,7 @@ float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float float c; c = pointcontents(org + '0 0 1'); if (!(c == CONTENT_WATER || c == CONTENT_LAVA || c == CONTENT_SLIME)) - swimming = FALSE; + swimming = false; else continue; } @@ -212,7 +223,7 @@ float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float if(autocvar_bot_debug_tracewalk) debugnodestatus(org, DEBUG_NODE_FAIL); - return FALSE; + return false; } ///////////////////////////////////////////////////////////////////////////// @@ -221,9 +232,9 @@ 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.navigation_hasgoals = false; self.goalcurrent = world; self.goalstack01 = world; self.goalstack02 = world; @@ -265,7 +276,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; @@ -305,7 +316,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; @@ -347,22 +358,22 @@ float navigation_waypoint_will_link(vector v, vector org, entity ent, float walk dist = vlen(v - org); if (bestdist > dist) { - traceline(v, org, TRUE, ent); + 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; + return true; } else { if (tracewalk(ent, org, PL_MIN, PL_MAX, v, bot_navigation_movemode)) - return TRUE; + return true; } } } - return FALSE; + return false; } // find the spawnfunc_waypoint near a dynamic goal such as a dropped weapon @@ -387,7 +398,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 - PL_MIN.z; // player height // TODO possibly make other code have the same support for bboxes if(ent.tag_entity) org = org + ent.tag_entity.origin; @@ -408,9 +419,9 @@ entity navigation_findnearestwaypoint_withdist_except(entity ent, float walkfrom vector wm1, wm2; wm1 = w.origin + w.mins; wm2 = w.origin + w.maxs; - v_x = bound(wm1_x, org.x, wm2_x); - v_y = bound(wm1_y, org.y, wm2_y); - v_z = bound(wm1_z, org.z, wm2_z); + v.x = bound(wm1_x, org.x, wm2_x); + v.y = bound(wm1_y, org.y, wm2_y); + v.z = bound(wm1_z, org.z, wm2_z); } else v = w.origin; @@ -438,11 +449,11 @@ 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; -// navigation_testtracewalk = TRUE; +// navigation_testtracewalk = true; c = 0; head = waylist; while (head) @@ -454,17 +465,17 @@ float navigation_markroutes_nearestwaypoints(entity waylist, float maxdist) m1 = head.origin + head.mins; m2 = head.origin + head.maxs; v = self.origin; - v_x = bound(m1_x, v.x, m2_x); - v_y = bound(m1_y, v.y, m2_y); - v_z = bound(m1_z, v.z, m2_z); + v.x = bound(m1_x, v.x, m2_x); + v.y = bound(m1_y, v.y, m2_y); + v.z = bound(m1_z, v.z, m2_z); } else v = head.origin; diff = v - self.origin; - diff_z = max(0, diff.z); + diff.z = max(0, diff.z); if (vlen(diff) < maxdist) { - head.wpconsidered = TRUE; + head.wpconsidered = true; if (tracewalk(self, self.origin, self.mins, self.maxs, v, bot_navigation_movemode)) { head.wpnearestpoint = v; @@ -477,7 +488,7 @@ float navigation_markroutes_nearestwaypoints(entity waylist, float maxdist) } head = head.chain; } - //navigation_testtracewalk = FALSE; + //navigation_testtracewalk = false; return c; } @@ -491,9 +502,9 @@ void navigation_markroutes_checkwaypoint(entity w, entity wp, float cost2, vecto { m1 = wp.absmin; m2 = wp.absmax; - v_x = bound(m1_x, p.x, m2_x); - v_y = bound(m1_y, p.y, m2_y); - v_z = bound(m1_z, p.z, m2_z); + v.x = bound(m1_x, p.x, m2_x); + v.y = bound(m1_y, p.y, m2_y); + v.z = bound(m1_z, p.z, m2_z); } else v = wp.origin; @@ -509,14 +520,14 @@ 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; w = waylist = findchain(classname, "waypoint"); while (w) { - w.wpconsidered = FALSE; + w.wpconsidered = false; w.wpnearestpoint = '0 0 0'; w.wpcost = 10000000; w.wpfire = 0; @@ -526,7 +537,7 @@ void navigation_markroutes(entity fixed_source_waypoint) if(fixed_source_waypoint) { - fixed_source_waypoint.wpconsidered = TRUE; + fixed_source_waypoint.wpconsidered = true; fixed_source_waypoint.wpnearestpoint = fixed_source_waypoint.origin + 0.5 * (fixed_source_waypoint.mins + fixed_source_waypoint.maxs); fixed_source_waypoint.wpcost = fixed_source_waypoint.dmg; fixed_source_waypoint.wpfire = 1; @@ -551,16 +562,16 @@ void navigation_markroutes(entity fixed_source_waypoint) for(i=increment;!navigation_markroutes_nearestwaypoints(waylist, i)&&i e.nearestwaypointtimeout) { - nwp = navigation_findnearestwaypoint(e, TRUE); + nwp = navigation_findnearestwaypoint(e, true); if(nwp) e.nearestwaypoint = nwp; else @@ -808,11 +819,11 @@ void navigation_routerating(entity e, float f, float rangebias) bot_debug(strcat("FAILED to find a nearest waypoint to '", e.classname, "' #", etos(e), "\n")); if(e.flags & FL_ITEM) - e.blacklisted = TRUE; + e.blacklisted = true; else if (e.flags & FL_WEAPON) { if(e.classname != "droppedweapon") - e.blacklisted = TRUE; + e.blacklisted = true; } if(e.blacklisted) @@ -850,14 +861,14 @@ 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 if (!e) - return FALSE; + return false; - self.navigation_hasgoals = TRUE; + self.navigation_hasgoals = true; // put the entity on the goal stack //print("routetogoal ", etos(e), "\n"); @@ -865,11 +876,11 @@ float navigation_routetogoal(entity e, vector startposition) if(g_jetpack) if(e==self.navigation_jetpack_goal) - return TRUE; + 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)) - return TRUE; + return true; // see if there are waypoints describing a path to the item if(e.classname != "waypoint" || (e.wpflags & WAYPOINTFLAG_PERSONAL)) @@ -878,9 +889,9 @@ float navigation_routetogoal(entity e, vector startposition) e = e.enemy; // we already have added it, so... if(e == world) - return FALSE; + return false; - for(0;;) + for (;;) { // add the spawnfunc_waypoint to the path navigation_pushroute(e); @@ -890,13 +901,13 @@ float navigation_routetogoal(entity e, vector startposition) break; } - return FALSE; + return false; } // 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; @@ -950,7 +961,7 @@ void navigation_poptouchedgoals() { if(vlen(self.origin - self.goalcurrent.origin)<150) { - traceline(self.origin + self.view_ofs , self.goalcurrent.origin, TRUE, world); + traceline(self.origin + self.view_ofs , self.goalcurrent.origin, true, world); if(trace_fraction==1) { // Detect personal waypoints @@ -982,13 +993,13 @@ void navigation_poptouchedgoals() // begin a goal selection session (queries spawnfunc_waypoint network) void navigation_goalrating_start() -{ +{SELFPARAM(); if(self.aistatus & AI_STATUS_STUCK) return; self.navigation_jetpack_goal = world; navigation_bestrating = -1; - self.navigation_hasgoals = FALSE; + self.navigation_hasgoals = false; navigation_clearroute(); navigation_bestgoal = world; navigation_markroutes(world); @@ -996,7 +1007,7 @@ 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; @@ -1013,7 +1024,7 @@ void navigation_goalrating_end() self.aistatus |= AI_STATUS_STUCK; } - self.navigation_hasgoals = FALSE; // Reset this value + self.navigation_hasgoals = false; // Reset this value } } @@ -1023,7 +1034,7 @@ void botframe_updatedangerousobjects(float maxupdate) vector m1, m2, v, o; float c, d, danger; c = 0; - bot_dodgelist = findchainfloat(bot_dodge, TRUE); + bot_dodgelist = findchainfloat(bot_dodge, true); botframe_dangerwaypoint = find(botframe_dangerwaypoint, classname, "waypoint"); while (botframe_dangerwaypoint != world) { @@ -1034,14 +1045,14 @@ void botframe_updatedangerousobjects(float maxupdate) while (head) { v = head.origin; - v_x = bound(m1_x, v.x, m2_x); - v_y = bound(m1_y, v.y, m2_y); - v_z = bound(m1_z, v.z, m2_z); + v.x = bound(m1_x, v.x, m2_x); + v.y = bound(m1_y, v.y, m2_y); + v.z = bound(m1_z, v.z, m2_z); o = (head.absmin + head.absmax) * 0.5; d = head.bot_dodgerating - vlen(o - v); if (d > 0) { - traceline(o, v, TRUE, world); + traceline(o, v, true, world); if (trace_fraction == 1) danger = danger + d; } @@ -1056,7 +1067,7 @@ void botframe_updatedangerousobjects(float maxupdate) } void navigation_unstuck() -{ +{SELFPARAM(); float search_radius = 1000; if (!autocvar_bot_wander_enable) @@ -1153,7 +1164,7 @@ void debugresetnodes() } void debugnode(vector node) -{ +{SELFPARAM(); if (!IS_PLAYER(self)) return; @@ -1196,7 +1207,7 @@ void debugnodestatus(vector position, float status) // Debug the goal stack visually void debuggoalstack() -{ +{SELFPARAM(); entity goal; vector org, go;