diff --git a/src/k_waypoint.cpp b/src/k_waypoint.cpp index a7e7e1617..8bcbd7024 100644 --- a/src/k_waypoint.cpp +++ b/src/k_waypoint.cpp @@ -409,7 +409,49 @@ waypoint_t *K_GetBestWaypointForMobj(mobj_t *const mobj, waypoint_t *const hint) checkdist = P_AproxDistance( (mobj->x / FRACUNIT) - (checkwaypoint->mobj->x / FRACUNIT), (mobj->y / FRACUNIT) - (checkwaypoint->mobj->y / FRACUNIT)); - checkdist = P_AproxDistance(checkdist, ((mobj->z / FRACUNIT) - (checkwaypoint->mobj->z / FRACUNIT)) * 4); + + UINT8 zMultiplier = 4; // Heavily weight z distance, for the sake of overlapping paths + + if (hint != NULL) + { + boolean connectedToHint = (checkwaypoint == hint); + + if (connectedToHint == false && hint->numnextwaypoints > 0) + { + for (size_t i = 0U; i < hint->numnextwaypoints; i++) + { + if (hint->nextwaypoints[i] == checkwaypoint) + { + connectedToHint = true; + break; + } + } + } + + if (connectedToHint == false && hint->numprevwaypoints > 0) + { + for (size_t i = 0U; i < hint->numprevwaypoints; i++) + { + if (hint->prevwaypoints[i] == checkwaypoint) + { + connectedToHint = true; + break; + } + } + } + + // Do not consider z height for next/prev waypoints of current waypoint. + // This helps the current waypoint not be behind you when you're taking a jump. + if (connectedToHint == true) + { + zMultiplier = 0; + } + } + + if (zMultiplier > 0) + { + checkdist = P_AproxDistance(checkdist, ((mobj->z / FRACUNIT) - (checkwaypoint->mobj->z / FRACUNIT)) * zMultiplier); + } fixed_t rad = (checkwaypoint->mobj->radius / FRACUNIT);