]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
More work was needed to complete transition to travel cost expressed in time rather...
authorterencehill <piuntn@gmail.com>
Sun, 23 Apr 2017 12:56:41 +0000 (14:56 +0200)
committerterencehill <piuntn@gmail.com>
Fri, 28 Apr 2017 16:33:08 +0000 (18:33 +0200)
qcsrc/server/bot/default/navigation.qc
qcsrc/server/bot/default/waypoints.qc
qcsrc/server/bot/default/waypoints.qh

index 6fafa9d473cdd3b2aeab617c188e11868372a260..e1debd404f23fd6573b5fcbe947260726f361e0e 100644 (file)
@@ -496,7 +496,7 @@ float navigation_markroutes_nearestwaypoints(entity this, float maxdist)
                        if (tracewalk(this, this.origin, this.mins, this.maxs, v, bot_navigation_movemode))
                        {
                                it.wpnearestpoint = v;
-                               it.wpcost = vlen(v - this.origin) + it.dmg;
+                               it.wpcost = waypoint_getdistancecost(this.origin, v) + it.dmg;
                                it.wpfire = 1;
                                it.enemy = NULL;
                                c = c + 1;
@@ -523,7 +523,7 @@ void navigation_markroutes_checkwaypoint(entity w, entity wp, float cost2, vecto
        }
        else
                v = wp.origin;
-       cost2 = cost2 + vlen(v - p);
+       cost2 += waypoint_getdistancecost(p, v);
        if (wp.wpcost > cost2)
        {
                wp.wpcost = cost2;
@@ -688,6 +688,9 @@ void navigation_routerating(entity this, entity e, float f, float rangebias)
        if(e.blacklisted)
                return;
 
+       rangebias = waypoint_getdistancecost_simple(rangebias);
+       f = waypoint_getdistancecost_simple(f);
+
        if (IS_PLAYER(e))
        {
                bool rate_wps = false;
@@ -1085,7 +1088,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 = it.bot_dodgerating - vlen(o - v);
+                       d = waypoint_getdistancecost_simple(it.bot_dodgerating) - waypoint_getdistancecost(o, v);
                        if (d > 0)
                        {
                                traceline(o, v, true, NULL);
index 93ab1efe74310349b96ba654ffe319ddee978ea8..46db36198554d226dc59ebaa6a81da65ef32af9e 100644 (file)
@@ -368,19 +368,29 @@ bool waypoint_islinked(entity from, entity to)
        return false;
 }
 
-// add a new link to the spawnfunc_waypoint, replacing the furthest link it already has
-void waypoint_addlink(entity from, entity to)
+float waypoint_getdistancecost_simple(float dist)
 {
-       float c;
+       return dist / autocvar_sv_maxspeed;
+}
 
-       if (from == to)
-               return;
-       if (from.wpflags & WAYPOINTFLAG_NORELINK)
-               return;
+float waypoint_getdistancecost(vector from, vector to)
+{
+       float c = waypoint_getdistancecost_simple(vlen(to - from));
 
-       if (waypoint_islinked(from, to))
-               return;
+       float height = from.z - to.z;
+       if(height > 0 && autocvar_sv_gravity > 0)
+       {
+               float height_cost = sqrt(height / autocvar_sv_gravity);
+               float xydist = vlen(vec2(to - from));
+               float xydist_cost = xydist / autocvar_sv_maxspeed;
+               if(max(height_cost, xydist_cost) < c)
+                       c = max(height_cost, xydist_cost);
+       }
+       return c;
+}
 
+float waypoint_getlinkcost(entity from, entity to)
+{
        vector v1 = from.origin;
        vector v2 = to.origin;
        if (to.wpisbox || from.wpisbox)
@@ -399,17 +409,20 @@ void waypoint_addlink(entity from, entity to)
                v2_y = bound(m1_y, v2_y, m2_y);
                v2_z = bound(m1_z, v2_z, m2_z);
        }
-       c = vlen(v2 - v1) / autocvar_sv_maxspeed;
+       return waypoint_getdistancecost(v1, v2);
+}
 
-       float height = v1.z - v2.z;
-       if(height > 0 && autocvar_sv_gravity > 0)
-       {
-               float height_cost = sqrt(height / autocvar_sv_gravity);
-               float xydist = vlen((v2 - eZ * v2.z) - (v1 - eZ * v1.z));
-               float xydist_cost = xydist / autocvar_sv_maxspeed;
-               if(max(height_cost, xydist_cost) < c)
-                       c = max(height_cost, xydist_cost);
-       }
+// add a new link to the spawnfunc_waypoint, replacing the furthest link it already has
+// if c == -1 automatically determine cost of the link
+void waypoint_addlink_customcost(entity from, entity to, float c)
+{
+       if (from == to || waypoint_islinked(from, to))
+               return;
+       if (c == -1 && (from.wpflags & WAYPOINTFLAG_NORELINK))
+               return;
+
+       if(c == -1)
+               c = waypoint_getlinkcost(from, to);
 
        if (from.wp31mincost < c) return;
        if (from.wp30mincost < c) {from.wp31 = to;from.wp31mincost = c;return;} from.wp31 = from.wp30;from.wp31mincost = from.wp30mincost;
@@ -446,6 +459,11 @@ void waypoint_addlink(entity from, entity to)
        from.wp00 = to;from.wp00mincost = c;return;
 }
 
+void waypoint_addlink(entity from, entity to)
+{
+       waypoint_addlink_customcost(from, to, -1);
+}
+
 // relink this spawnfunc_waypoint
 // (precompile a list of all reachable waypoints from this spawnfunc_waypoint)
 // (SLOW!)
index 5a976d2c3bad823f8476a2440a7302bfe51a9a37..bc19fa780f39612e9c2ce361401ceb983511368d 100644 (file)
@@ -31,11 +31,15 @@ float botframe_cachedwaypointlinks;
 spawnfunc(waypoint);
 void waypoint_removelink(entity from, entity to);
 bool waypoint_islinked(entity from, entity to);
+void waypoint_addlink_customcost(entity from, entity to, float c);
 void waypoint_addlink(entity from, entity to);
 void waypoint_think(entity this);
 void waypoint_clearlinks(entity wp);
 void waypoint_schedulerelink(entity wp);
 
+float waypoint_getdistancecost(vector v1, vector v2);
+float waypoint_getdistancecost_simple(float dist);
+
 void waypoint_remove_fromeditor(entity pl);
 void waypoint_remove(entity wp);
 void waypoint_schedulerelinkall();