From: terencehill Date: Sun, 23 Apr 2017 12:56:41 +0000 (+0200) Subject: More work was needed to complete transition to travel cost expressed in time rather... X-Git-Tag: xonotic-v0.8.5~2378^2~177 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=f849a39dd7731c7f2f44c3ae2ee67f03c4517077;p=xonotic%2Fxonotic-data.pk3dir.git More work was needed to complete transition to travel cost expressed in time rather than distance --- diff --git a/qcsrc/server/bot/default/navigation.qc b/qcsrc/server/bot/default/navigation.qc index 6fafa9d47..e1debd404 100644 --- a/qcsrc/server/bot/default/navigation.qc +++ b/qcsrc/server/bot/default/navigation.qc @@ -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); diff --git a/qcsrc/server/bot/default/waypoints.qc b/qcsrc/server/bot/default/waypoints.qc index 93ab1efe7..46db36198 100644 --- a/qcsrc/server/bot/default/waypoints.qc +++ b/qcsrc/server/bot/default/waypoints.qc @@ -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!) diff --git a/qcsrc/server/bot/default/waypoints.qh b/qcsrc/server/bot/default/waypoints.qh index 5a976d2c3..bc19fa780 100644 --- a/qcsrc/server/bot/default/waypoints.qh +++ b/qcsrc/server/bot/default/waypoints.qh @@ -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();