From dd6b0feff614f38dd68149c7691ebb2d4a026ff2 Mon Sep 17 00:00:00 2001 From: terencehill Date: Wed, 26 Jul 2017 16:26:18 +0200 Subject: [PATCH] Travel cost calculation: avoid SUBMERGED checks for enemies and non-box waypoints, check waterlevel field instead (cheaper) --- qcsrc/server/bot/default/navigation.qc | 10 ++++++---- qcsrc/server/bot/default/waypoints.qc | 21 +++++++++++++++++++-- qcsrc/server/bot/default/waypoints.qh | 2 +- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/qcsrc/server/bot/default/navigation.qc b/qcsrc/server/bot/default/navigation.qc index d787cbb87..37b1acf54 100644 --- a/qcsrc/server/bot/default/navigation.qc +++ b/qcsrc/server/bot/default/navigation.qc @@ -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); diff --git a/qcsrc/server/bot/default/waypoints.qc b/qcsrc/server/bot/default/waypoints.qc index 21ce90556..9e37d8259 100644 --- a/qcsrc/server/bot/default/waypoints.qc +++ b/qcsrc/server/bot/default/waypoints.qc @@ -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 diff --git a/qcsrc/server/bot/default/waypoints.qh b/qcsrc/server/bot/default/waypoints.qh index 22e192cb2..02dc7b163 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, 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(); -- 2.39.2