From: terencehill Date: Mon, 24 Jul 2017 13:56:24 +0000 (+0200) Subject: Reduce travel cost of underwater paths X-Git-Tag: xonotic-v0.8.5~2378^2~123 X-Git-Url: http://git.xonotic.org/?a=commitdiff_plain;h=c3b4d31e5b2236f42770292c4ac3962b60bb9e1d;p=xonotic%2Fxonotic-data.pk3dir.git Reduce travel cost of underwater paths --- diff --git a/qcsrc/server/bot/default/bot.qh b/qcsrc/server/bot/default/bot.qh index b72fad9bd..ea37ccf8f 100644 --- a/qcsrc/server/bot/default/bot.qh +++ b/qcsrc/server/bot/default/bot.qh @@ -78,6 +78,12 @@ float botframe_nextdangertime; float bot_cvar_nextthink; float bot_ignore_bots; // let bots not attack other bots (only works in non-teamplay) +int _content_type; +#define IN_LAVA(pos) (_content_type = pointcontents(pos), (_content_type == CONTENT_LAVA || _content_type == CONTENT_SLIME)) +#define IN_LIQUID(pos) (_content_type = pointcontents(pos), (_content_type == CONTENT_WATER || _content_type == CONTENT_LAVA || _content_type == CONTENT_SLIME)) +#define SUBMERGED(pos) IN_LIQUID(pos + autocvar_sv_player_viewoffset) +#define WETFEET(pos) IN_LIQUID(pos + eZ * (m1.z + 1)) + /* * Functions */ diff --git a/qcsrc/server/bot/default/navigation.qc b/qcsrc/server/bot/default/navigation.qc index e5dc6cb5b..8710c4c2a 100644 --- a/qcsrc/server/bot/default/navigation.qc +++ b/qcsrc/server/bot/default/navigation.qc @@ -55,14 +55,8 @@ bool navigation_checkladders(entity e, vector org, vector m1, vector m2, vector return false; } -#define IN_LAVA(pos) (cont = pointcontents(pos), (cont == CONTENT_LAVA || cont == CONTENT_SLIME)) -#define IN_LIQUID(pos) (cont = pointcontents(pos), (cont == CONTENT_WATER || cont == CONTENT_LAVA || cont == CONTENT_SLIME)) -#define SUBMERGED(pos) IN_LIQUID(pos + autocvar_sv_player_viewoffset) -#define WETFEET(pos) IN_LIQUID(pos + eZ * (m1.z + 1)) - vector resurface_limited(vector org, float lim, vector m1) { - int cont; if (WETFEET(org + eZ * (lim - org.z))) org.z = lim; else @@ -104,7 +98,6 @@ bool tracewalk(entity e, vector start, vector m1, vector m2, vector end, float e flatdir = normalize(flatdir); float stepdist = 32; bool ignorehazards = false; - int cont; int nav_action; // Analyze starting point @@ -786,7 +779,7 @@ float navigation_markroutes_nearestwaypoints(entity this, float maxdist) if (tracewalk(this, this.origin, this.mins, this.maxs, v, v_height, bot_navigation_movemode)) { it.wpnearestpoint = v; - it.wpcost = waypoint_gettravelcost(this.origin, v) + it.dmg; + it.wpcost = waypoint_gettravelcost(this.origin, v, SUBMERGED(this.origin), SUBMERGED(v)) + it.dmg; it.wpfire = 1; it.enemy = NULL; c = c + 1; @@ -815,7 +808,7 @@ void navigation_markroutes_checkwaypoint(entity w, entity wp, float cost, vector if (w.wpflags & WAYPOINTFLAG_TELEPORT) cost += w.wp00mincost; // assuming teleport has exactly one destination else - cost += waypoint_gettravelcost(p, v); + cost += waypoint_gettravelcost(p, v, SUBMERGED(p), SUBMERGED(v)); if (wp.wpcost > cost) { wp.wpcost = cost; @@ -1176,7 +1169,7 @@ void navigation_routerating(entity this, entity e, float f, float rangebias) if (nwp.wpcost < 10000000) { //te_wizspike(nwp.wpnearestpoint); - float cost = nwp.wpcost + waypoint_gettravelcost(nwp.wpnearestpoint, goal_org); + float cost = nwp.wpcost + waypoint_gettravelcost(nwp.wpnearestpoint, goal_org, SUBMERGED(nwp.wpnearestpoint), SUBMERGED(goal_org)); LOG_DEBUG(e.classname, " ", ftos(f), "/(1+", ftos(cost), "/", ftos(rangebias), ") = "); f = f * rangebias / (rangebias + cost); LOG_DEBUG("considering ", e.classname, " (with rating ", ftos(f), ")"); @@ -1413,7 +1406,7 @@ void botframe_updatedangerousobjects(float maxupdate) v.y = bound(m1_y, v.y, m2_y); v.z = bound(m1_z, v.z, m2_z); o = (it.absmin + it.absmax) * 0.5; - d = waypoint_getlinearcost(it.bot_dodgerating) - waypoint_gettravelcost(o, v); + d = waypoint_getlinearcost(it.bot_dodgerating) - waypoint_gettravelcost(o, v, SUBMERGED(o), SUBMERGED(v)); if (d > 0) { traceline(o, v, true, NULL); diff --git a/qcsrc/server/bot/default/waypoints.qc b/qcsrc/server/bot/default/waypoints.qc index 436220d69..d130e863a 100644 --- a/qcsrc/server/bot/default/waypoints.qc +++ b/qcsrc/server/bot/default/waypoints.qc @@ -444,9 +444,17 @@ float waypoint_getlinearcost(float dist) return dist / (autocvar_sv_maxspeed * 1.25); return dist / autocvar_sv_maxspeed; } +float waypoint_getlinearcost_underwater(float dist) +{ + // NOTE: this value is hardcoded on the engine too, see SV_WaterMove + return dist / (autocvar_sv_maxspeed * 0.7); +} -float waypoint_gettravelcost(vector from, vector to) +float waypoint_gettravelcost(vector from, vector to, bool submerged_from, bool submerged_to) { + if (submerged_from && submerged_to) + return waypoint_getlinearcost_underwater(vlen(to - from)); + float c = waypoint_getlinearcost(vlen(to - from)); float height = from.z - to.z; @@ -457,6 +465,9 @@ float waypoint_gettravelcost(vector from, vector to) if(height_cost > c) c = height_cost; } + + if (submerged_from || submerged_to) + return (c + waypoint_getlinearcost_underwater(vlen(to - from))) / 2; return c; } @@ -478,7 +489,7 @@ float waypoint_getlinkcost(entity from, entity to) v2_y = bound(m1_y, v2_y, m2_y); v2_z = bound(m1_z, v2_z, m2_z); } - return waypoint_gettravelcost(v1, v2); + return waypoint_gettravelcost(v1, v2, SUBMERGED(v1), SUBMERGED(v2)); } // add a new link to the spawnfunc_waypoint, replacing the furthest link it already has diff --git a/qcsrc/server/bot/default/waypoints.qh b/qcsrc/server/bot/default/waypoints.qh index f772d046c..22e192cb2 100644 --- a/qcsrc/server/bot/default/waypoints.qh +++ b/qcsrc/server/bot/default/waypoints.qh @@ -39,7 +39,7 @@ void waypoint_clearlinks(entity wp); void waypoint_schedulerelink(entity wp); float waypoint_getlinkcost(entity from, entity to); -float waypoint_gettravelcost(vector v1, vector v2); +float waypoint_gettravelcost(vector v1, vector v2, bool submerged_from, bool submerged_to); float waypoint_getlinearcost(float dist); void waypoint_updatecost_foralllinks();