]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Travel cost calculation: avoid SUBMERGED checks for enemies and non-box waypoints...
authorterencehill <piuntn@gmail.com>
Wed, 26 Jul 2017 14:26:18 +0000 (16:26 +0200)
committerterencehill <piuntn@gmail.com>
Wed, 26 Jul 2017 14:26:18 +0000 (16:26 +0200)
qcsrc/server/bot/default/navigation.qc
qcsrc/server/bot/default/waypoints.qc
qcsrc/server/bot/default/waypoints.qh

index d787cbb876224c597400c10d7934b99b9114bdcd..37b1acf54306683557f7911609ce1841bcc05229 100644 (file)
@@ -797,7 +797,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, SUBMERGED(this.origin), SUBMERGED(v)) + it.dmg;
+                               it.wpcost = waypoint_gettravelcost(this.origin, v, this, it) + it.dmg;
                                it.wpfire = 1;
                                it.enemy = NULL;
                                c = c + 1;
@@ -826,7 +826,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, SUBMERGED(p), SUBMERGED(v));
+               cost += waypoint_gettravelcost(p, v, w, wp);
        if (wp.wpcost > cost)
        {
                wp.wpcost = cost;
@@ -1187,7 +1187,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, SUBMERGED(nwp.wpnearestpoint), SUBMERGED(goal_org));
+               float cost = nwp.wpcost + waypoint_gettravelcost(nwp.wpnearestpoint, goal_org, nwp, e);
                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), ")");
@@ -1412,11 +1412,13 @@ void botframe_updatedangerousobjects(float maxupdate)
        vector m1, m2, v, o;
        float c, d, danger;
        c = 0;
+       entity wp_cur;
        IL_EACH(g_waypoints, true,
        {
                danger = 0;
                m1 = it.absmin;
                m2 = it.absmax;
+               wp_cur = it;
                IL_EACH(g_bot_dodge, it.bot_dodge,
                {
                        v = it.origin;
@@ -1424,7 +1426,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, SUBMERGED(o), SUBMERGED(v));
+                       d = waypoint_getlinearcost(it.bot_dodgerating) - waypoint_gettravelcost(o, v, it, wp_cur);
                        if (d > 0)
                        {
                                traceline(o, v, true, NULL);
index 21ce90556f0ac6a9c8c6812e9d6f9bb1b8cc450c..9e37d825934d20231863cda1139c0ca65b3ef4ef 100644 (file)
@@ -227,6 +227,11 @@ entity waypoint_spawn(vector m1, vector m2, float f)
                        }
                }
                setsize(w, '0 0 0', '0 0 0');
+
+               // can't apply the same logic to box waypoints because often they are
+               // inside some solid and SUBMERGED check would fail even if submerged
+               if(SUBMERGED(w.origin))
+                       w.waterlevel = WATERLEVEL_SUBMERGED;
        }
 
        waypoint_clearlinks(w);
@@ -450,8 +455,20 @@ float waypoint_getlinearcost_underwater(float dist)
        return dist / (autocvar_sv_maxspeed * 0.7);
 }
 
-float waypoint_gettravelcost(vector from, vector to, bool submerged_from, bool submerged_to)
+float waypoint_gettravelcost(vector from, vector to, entity from_ent, entity to_ent)
 {
+       bool submerged_from;
+       if((from_ent.classname == "waypoint" && !from_ent.wpisbox) || from_ent.classname == "player")
+               submerged_from = (from_ent.waterlevel == WATERLEVEL_SUBMERGED);
+       else
+               submerged_from = SUBMERGED(from);
+
+       bool submerged_to;
+       if((to_ent.classname == "waypoint" && !to_ent.wpisbox) || to_ent.classname == "player")
+               submerged_to = (to_ent.waterlevel == WATERLEVEL_SUBMERGED);
+       else
+               submerged_to = SUBMERGED(to);
+
        if (submerged_from && submerged_to)
                return waypoint_getlinearcost_underwater(vlen(to - from));
 
@@ -489,7 +506,7 @@ float waypoint_getlinkcost(entity from, entity to)
                v2.y = bound(m1.y, v1.y, m2.y);
                v2.z = bound(m1.z, v1.z, m2.z);
        }
-       return waypoint_gettravelcost(v1, v2, SUBMERGED(v1), SUBMERGED(v2));
+       return waypoint_gettravelcost(v1, v2, from, to);
 }
 
 // add a new link to the spawnfunc_waypoint, replacing the furthest link it already has
index 22e192cb2728f84e14829f37fa1252ca870ee196..02dc7b163a0fa7d72ce34c9f09dd7c05f1b1fab0 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, bool submerged_from, bool submerged_to);
+float waypoint_gettravelcost(vector from, vector to, entity from_ent, entity to_ent);
 float waypoint_getlinearcost(float dist);
 void waypoint_updatecost_foralllinks();