]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Reduce travel cost of underwater paths
authorterencehill <piuntn@gmail.com>
Mon, 24 Jul 2017 13:56:24 +0000 (15:56 +0200)
committerterencehill <piuntn@gmail.com>
Mon, 24 Jul 2017 13:56:24 +0000 (15:56 +0200)
qcsrc/server/bot/default/bot.qh
qcsrc/server/bot/default/navigation.qc
qcsrc/server/bot/default/waypoints.qc
qcsrc/server/bot/default/waypoints.qh

index b72fad9bd600248601794130a2cf0f505c110991..ea37ccf8ff6d417833b365aaad3b4e20ecaff1a3 100644 (file)
@@ -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
  */
index e5dc6cb5bea80e4d8c680f2fff0c90d2e6d668a6..8710c4c2a6a1f2828a17f2d5045d18a2ffbf05e3 100644 (file)
@@ -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);
index 436220d698aff0fc108c0fd1d1c166af484c0c17..d130e863a5cb0a45b091d5236e1f8f76738aaad6 100644 (file)
@@ -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
index f772d046c7f1afb1f7dafa5646139cd773357e0d..22e192cb2728f84e14829f37fa1252ca870ee196 100644 (file)
@@ -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();