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;
}
else
v = wp.origin;
- cost2 = cost2 + vlen(v - p);
+ cost2 += waypoint_getdistancecost(p, v);
if (wp.wpcost > cost2)
{
wp.wpcost = cost2;
if(e.blacklisted)
return;
+ rangebias = waypoint_getdistancecost_simple(rangebias);
+ f = waypoint_getdistancecost_simple(f);
+
if (IS_PLAYER(e))
{
bool rate_wps = false;
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);
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)
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;
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!)
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();