From 9ac306fe672f66ad954d13bbf00d73eae74c8376 Mon Sep 17 00:00:00 2001 From: Fryguy Date: Sun, 13 Oct 2024 16:53:09 -0400 Subject: [PATCH] [Bug] FindBestZ selecting false zone floor as bestz - Results in roambox failures (#4504) Added underworld checks per the EQMac project --- zone/map.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/zone/map.cpp b/zone/map.cpp index 3ed0e585b..410392e8a 100644 --- a/zone/map.cpp +++ b/zone/map.cpp @@ -31,12 +31,14 @@ Map::~Map() { } float Map::FindBestZ(glm::vec3 &start, glm::vec3 *result) const { - if (!imp) + if (!imp) { return BEST_Z_INVALID; + } glm::vec3 tmp; - if(!result) + if (!result) { result = &tmp; + } start.z += RuleI(Map, FindBestZHeightAdjust); glm::vec3 from(start.x, start.y, start.z); @@ -45,16 +47,22 @@ float Map::FindBestZ(glm::vec3 &start, glm::vec3 *result) const { bool hit = false; hit = imp->rm->raycast((const RmReal*)&from, (const RmReal*)&to, (RmReal*)result, nullptr, &hit_distance); - if(hit) { + if (hit && zone->newzone_data.underworld != 0.0f && result->z < zone->newzone_data.underworld) { + hit = false; + } + + if (hit) { return result->z; } // Find nearest Z above us - to.z = -BEST_Z_INVALID; hit = imp->rm->raycast((const RmReal*)&from, (const RmReal*)&to, (RmReal*)result, nullptr, &hit_distance); - if (hit) - { + if (zone->newzone_data.max_z != 0.0f && result->z > zone->newzone_data.max_z) { + hit = false; + } + + if (hit) { return result->z; }