From 7fff21acd4aa7a7f34f8c7e9a14962c08cb0e9c5 Mon Sep 17 00:00:00 2001 From: Sally Cochenour Date: Tue, 3 Mar 2020 16:58:09 -0500 Subject: [PATCH] Instead of vertical cap, quadruple z axis distance Far more natural results! --- src/k_waypoint.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/k_waypoint.c b/src/k_waypoint.c index 1913af0a6..8d822c3d6 100644 --- a/src/k_waypoint.c +++ b/src/k_waypoint.c @@ -223,26 +223,22 @@ waypoint_t *K_GetClosestWaypointToMobj(mobj_t *const mobj) checkwaypoint = &waypointheap[i]; // TODO: Keep the old version of this function, - // make this 128 check & sight checks a separate function. - checkdist = abs((mobj->z >> FRACBITS) - (checkwaypoint->mobj->z >> FRACBITS)); + // make the vertical axis faking & sight checks a separate function. + checkdist = P_AproxDistance( + (mobj->x >> FRACBITS) - (checkwaypoint->mobj->x >> FRACBITS), + (mobj->y >> FRACBITS) - (checkwaypoint->mobj->y >> FRACBITS)); + checkdist = P_AproxDistance(checkdist, ((mobj->z >> FRACBITS) - (checkwaypoint->mobj->z >> FRACBITS)) << 2); - if (checkdist <= 128) + if (checkdist < closestdist) { - checkdist = P_AproxDistance( - (mobj->x >> FRACBITS) - (checkwaypoint->mobj->x >> FRACBITS), - (mobj->y >> FRACBITS) - (checkwaypoint->mobj->y >> FRACBITS)); - - if (checkdist < closestdist) + if (!P_CheckSight(mobj, checkwaypoint->mobj)) { - if (!P_CheckSight(mobj, checkwaypoint->mobj)) - { - // Save sight checks for the end, so we only do it if we have to - continue; - } - - closestwaypoint = checkwaypoint; - closestdist = checkdist; + // Save sight checks for the end, so we only do it if we have to + continue; } + + closestwaypoint = checkwaypoint; + closestdist = checkdist; } } }