X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fserver%2Fbot%2Fnavigation.qc;h=d80f8336c8ba179bd52e862bc2807181d92efebc;hp=9160c1133ab4ba9e50bcb3972dea7492918d85fd;hb=e921ae9f86a09d0a20cd4c72b44e6d71d25975ea;hpb=a7794afc2db05650096d9c22e55cb1ca6d82aa9b diff --git a/qcsrc/server/bot/navigation.qc b/qcsrc/server/bot/navigation.qc index 9160c1133..d80f8336c 100644 --- a/qcsrc/server/bot/navigation.qc +++ b/qcsrc/server/bot/navigation.qc @@ -29,25 +29,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,7 +58,7 @@ 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 @@ -73,7 +73,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 +93,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 +106,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(; 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); @@ -117,12 +117,12 @@ float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float break; } - if not (pointcontents(org + '0 0 1') == CONTENT_EMPTY) + if(pointcontents(org + '0 0 1') != CONTENT_EMPTY) { 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 +173,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 @@ -196,8 +196,8 @@ float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float { float c; c = pointcontents(org + '0 0 1'); - if not(c == CONTENT_WATER || c == CONTENT_LAVA || c == CONTENT_SLIME) - swimming = FALSE; + if (!(c == CONTENT_WATER || c == CONTENT_LAVA || c == CONTENT_SLIME)) + swimming = false; else continue; } @@ -212,7 +212,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; } ///////////////////////////////////////////////////////////////////////////// @@ -223,7 +223,7 @@ float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float void navigation_clearroute() { //print("bot ", etos(self), " clear\n"); - self.navigation_hasgoals = FALSE; + self.navigation_hasgoals = false; self.goalcurrent = world; self.goalstack01 = world; self.goalstack02 = world; @@ -347,26 +347,26 @@ 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 -entity navigation_findnearestwaypoint_withdist(entity ent, float walkfromwp, float bestdist) +entity navigation_findnearestwaypoint_withdist_except(entity ent, float walkfromwp, float bestdist, entity except) { entity waylist, w, best; vector v, org, pm1, pm2; @@ -380,14 +380,14 @@ entity navigation_findnearestwaypoint_withdist(entity ent, float walkfromwp, flo while (w) { // if object is touching spawnfunc_waypoint - if(w != ent) + if(w != ent && w != except) if (boxesoverlap(pm1, pm2, w.absmin, w.absmax)) return w; w = w.chain; } 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 +408,9 @@ entity navigation_findnearestwaypoint_withdist(entity ent, float walkfromwp, flo 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; @@ -426,7 +426,14 @@ entity navigation_findnearestwaypoint_withdist(entity ent, float walkfromwp, flo } entity navigation_findnearestwaypoint(entity ent, float walkfromwp) { - return navigation_findnearestwaypoint_withdist(ent, walkfromwp, 1050); + entity wp = navigation_findnearestwaypoint_withdist_except(ent, walkfromwp, 1050, world); + if (autocvar_g_waypointeditor_auto) + { + entity wp2 = navigation_findnearestwaypoint_withdist_except(ent, walkfromwp, 1050, wp); + if (wp && !wp2) + wp.wpflags |= WAYPOINTFLAG_PROTECTED; + } + return wp; } // finds the waypoints near the bot initiating a navigation query @@ -435,7 +442,7 @@ float navigation_markroutes_nearestwaypoints(entity waylist, float maxdist) entity head; vector v, m1, m2, diff; float c; -// navigation_testtracewalk = TRUE; +// navigation_testtracewalk = true; c = 0; head = waylist; while (head) @@ -447,17 +454,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; @@ -470,7 +477,7 @@ float navigation_markroutes_nearestwaypoints(entity waylist, float maxdist) } head = head.chain; } - //navigation_testtracewalk = FALSE; + //navigation_testtracewalk = false; return c; } @@ -484,9 +491,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,7 +516,7 @@ void navigation_markroutes(entity fixed_source_waypoint) w = waylist = findchain(classname, "waypoint"); while (w) { - w.wpconsidered = FALSE; + w.wpconsidered = false; w.wpnearestpoint = '0 0 0'; w.wpcost = 10000000; w.wpfire = 0; @@ -519,7 +526,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; @@ -544,16 +551,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 @@ -801,11 +808,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) @@ -848,9 +855,9 @@ float navigation_routetogoal(entity e, vector startposition) // 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"); @@ -858,11 +865,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)) @@ -871,7 +878,7 @@ float navigation_routetogoal(entity e, vector startposition) e = e.enemy; // we already have added it, so... if(e == world) - return FALSE; + return false; for (;;) { @@ -883,7 +890,7 @@ float navigation_routetogoal(entity e, vector startposition) break; } - return FALSE; + return false; } // removes any currently touching waypoints from the goal stack @@ -943,7 +950,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 @@ -981,7 +988,7 @@ void navigation_goalrating_start() self.navigation_jetpack_goal = world; navigation_bestrating = -1; - self.navigation_hasgoals = FALSE; + self.navigation_hasgoals = false; navigation_clearroute(); navigation_bestgoal = world; navigation_markroutes(world); @@ -997,16 +1004,16 @@ void navigation_goalrating_end() bot_debug(strcat("best goal ", self.goalcurrent.classname , "\n")); // If the bot got stuck then try to reach the farthest waypoint - if not (self.navigation_hasgoals) + if (!self.navigation_hasgoals) if (autocvar_bot_wander_enable) { - if not(self.aistatus & AI_STATUS_STUCK) + if (!(self.aistatus & AI_STATUS_STUCK)) { bot_debug(strcat(self.netname, " cannot walk to any goal\n")); self.aistatus |= AI_STATUS_STUCK; } - self.navigation_hasgoals = FALSE; // Reset this value + self.navigation_hasgoals = false; // Reset this value } } @@ -1016,7 +1023,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) { @@ -1027,14 +1034,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; } @@ -1052,10 +1059,10 @@ void navigation_unstuck() { float search_radius = 1000; - if not(autocvar_bot_wander_enable) + if (!autocvar_bot_wander_enable) return; - if not(bot_waypoint_queue_owner) + if (!bot_waypoint_queue_owner) { bot_debug(strcat(self.netname, " sutck, taking over the waypoints queue\n")); bot_waypoint_queue_owner = self; @@ -1081,7 +1088,7 @@ void navigation_unstuck() } bot_waypoint_queue_goal = bot_waypoint_queue_goal.bot_waypoint_queue_nextgoal; - if not(bot_waypoint_queue_goal) + if (!bot_waypoint_queue_goal) { if (bot_waypoint_queue_bestgoal) { @@ -1147,7 +1154,7 @@ void debugresetnodes() void debugnode(vector node) { - if not(IS_PLAYER(self)) + if (!IS_PLAYER(self)) return; if(debuglastnode=='0 0 0')