From fafa33e1906ce167d52f1447e0d5028ba9a498f7 Mon Sep 17 00:00:00 2001 From: Chris Miles Date: Wed, 15 Feb 2023 10:52:03 -0600 Subject: [PATCH] [Groundspawns] Fix issue where groundspawns appear floating high off the ground (#2930) --- zone/object.cpp | 22 ++++++++++++++++++++++ zone/object.h | 1 + 2 files changed, 23 insertions(+) diff --git a/zone/object.cpp b/zone/object.cpp index ef3bf5c5b..c223ec248 100644 --- a/zone/object.cpp +++ b/zone/object.cpp @@ -71,6 +71,8 @@ Object::Object(uint32 id, uint32 type, uint32 icon, const Object_Struct& object, m_data.size = object.size; m_data.tilt_x = object.tilt_x; m_data.tilt_y = object.tilt_y; + + FixZ(); } //creating a re-ocurring ground spawn. @@ -100,6 +102,8 @@ Object::Object(const EQ::ItemInstance* inst, char* name,float max_x,float min_x, strcpy(m_data.object_name, name); RandomSpawn(false); + FixZ(); + // Hardcoded portion for unknown members m_data.unknown024 = 0x7f001194; m_data.unknown076 = 0x0000d5fe; @@ -167,6 +171,8 @@ Object::Object(Client* client, const EQ::ItemInstance* inst) strcpy(m_data.object_name, DEFAULT_OBJECT_NAME); } } + + FixZ(); } Object::Object(const EQ::ItemInstance *inst, float x, float y, float z, float heading, uint32 decay_time) @@ -223,6 +229,8 @@ Object::Object(const EQ::ItemInstance *inst, float x, float y, float z, float he strcpy(m_data.object_name, DEFAULT_OBJECT_NAME); } } + + FixZ(); } Object::Object(const char *model, float x, float y, float z, float heading, uint8 type, uint32 decay_time) @@ -247,6 +255,8 @@ Object::Object(const char *model, float x, float y, float z, float heading, uint m_data.z = z; m_data.zone_id = zone->GetZoneID(); + FixZ(); + if (decay_time) decay_timer.Start(); @@ -1172,3 +1182,15 @@ void Object::SetEntityVariable(std::string variable_name, std::string variable_v o_EntityVariables[variable_name] = variable_value; } + +void Object::FixZ() +{ + float best_z = BEST_Z_INVALID; + if (zone->zonemap != nullptr) { + auto dest = glm::vec3(m_data.x, m_data.y, m_data.z + 5); + best_z = zone->zonemap->FindBestZ(dest, nullptr); + if (best_z != BEST_Z_INVALID) { + m_data.z = best_z; + } + } +} diff --git a/zone/object.h b/zone/object.h index 13232dc24..c62095129 100644 --- a/zone/object.h +++ b/zone/object.h @@ -204,6 +204,7 @@ protected: Timer respawn_timer; Timer decay_timer; + void FixZ(); }; #endif