]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/default/waypoints.qc
Merge branch 'master' into terencehill/bot_waypoints
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / default / waypoints.qc
index 436220d698aff0fc108c0fd1d1c166af484c0c17..f08c32691683d03c8c8f4696153001683c8d6475 100644 (file)
@@ -269,7 +269,7 @@ void waypoint_spawn_fromeditor(entity pl)
        LABEL(add_wp);
        e = waypoint_spawn(org, org, 0);
        waypoint_schedulerelink(e);
-       bprint(strcat("Waypoint spawned at ", vtos(org), "\n"));
+       bprint(strcat("Waypoint spawned at ", vtos(e.origin), "\n"));
        if(sym)
        {
                org = waypoint_getSymmetricalOrigin(e.origin, ctf_flags);
@@ -444,9 +444,20 @@ float waypoint_getlinearcost(float dist)
                return dist / (autocvar_sv_maxspeed * 1.25);
        return dist / autocvar_sv_maxspeed;
 }
+float waypoint_getlinearcost_underwater(float dist)
+{
+       // NOTE: this value is hardcoded on the engine too, see SV_WaterMove
+       return dist / (autocvar_sv_maxspeed * 0.7);
+}
 
-float waypoint_gettravelcost(vector from, vector to)
+float waypoint_gettravelcost(vector from, vector to, entity from_ent, entity to_ent)
 {
+       bool submerged_from = navigation_check_submerged_state(from_ent, from);
+       bool submerged_to = navigation_check_submerged_state(to_ent, to);
+
+       if (submerged_from && submerged_to)
+               return waypoint_getlinearcost_underwater(vlen(to - from));
+
        float c = waypoint_getlinearcost(vlen(to - from));
 
        float height = from.z - to.z;
@@ -457,6 +468,9 @@ float waypoint_gettravelcost(vector from, vector to)
                if(height_cost > c)
                        c = height_cost;
        }
+
+       if (submerged_from || submerged_to)
+               return (c + waypoint_getlinearcost_underwater(vlen(to - from))) / 2;
        return c;
 }
 
@@ -466,19 +480,19 @@ float waypoint_getlinkcost(entity from, entity to)
        vector v2 = to.origin;
        if (from.wpisbox)
        {
-               vector m1 = to.absmin, m2 = to.absmax;
-               v1_x = bound(m1_x, v1_x, m2_x);
-               v1_y = bound(m1_y, v1_y, m2_y);
-               v1_z = bound(m1_z, v1_z, m2_z);
+               vector m1 = from.absmin, m2 = from.absmax;
+               v1.x = bound(m1.x, v2.x, m2.x);
+               v1.y = bound(m1.y, v2.y, m2.y);
+               v1.z = bound(m1.z, v2.z, m2.z);
        }
        if (to.wpisbox)
        {
-               vector m1 = from.absmin, m2 = from.absmax;
-               v2_x = bound(m1_x, v2_x, m2_x);
-               v2_y = bound(m1_y, v2_y, m2_y);
-               v2_z = bound(m1_z, v2_z, m2_z);
+               vector m1 = to.absmin, m2 = to.absmax;
+               v2.x = bound(m1.x, v1.x, m2.x);
+               v2.y = bound(m1.y, v1.y, m2.y);
+               v2.z = bound(m1.z, v1.z, m2.z);
        }
-       return waypoint_gettravelcost(v1, v2);
+       return waypoint_gettravelcost(v1, v2, from, to);
 }
 
 // add a new link to the spawnfunc_waypoint, replacing the furthest link it already has