From 86f1cedf9126a93357f4b3705bb255f240d90217 Mon Sep 17 00:00:00 2001 From: Akkadius Date: Sat, 18 Aug 2018 23:18:55 -0500 Subject: [PATCH] Add LOS checks into roambox logic to prevent scaling mountains and going over buildings, cpu cycle saves and logging added. Things are looking really good now --- zone/mob_ai.cpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/zone/mob_ai.cpp b/zone/mob_ai.cpp index 1ed005033..9a62ef15c 100644 --- a/zone/mob_ai.cpp +++ b/zone/mob_ai.cpp @@ -1685,19 +1685,46 @@ void NPC::AI_DoMovement() { * if the roam box was sloppily configured */ if (!this->GetWasSpawnedInWater()) { - if (zone->zonemap != nullptr && zone->watermap != nullptr) { + if (zone->HasMap() && zone->HasWaterMap()) { auto position = glm::vec3( roambox_destination_x, roambox_destination_y, - this->FindGroundZ(roambox_destination_x, roambox_destination_y, 5) + (m_Position.z - 15) ); if (zone->watermap->InLiquid(position)) { + Log(Logs::Detail, + Logs::NPCRoamBox, "%s | My destination is in water and I don't belong there!", + this->GetCleanName()); + return; } } } + /** + * We check for line of sight because we dont' want NPC's scaling on top of buildings and over ridiculous + * mountains, this also peels back the frequency of pathing as well because we don't want to spam LOS checks + * so if we fail a LOS check to our randomly chosen destination, we roll another timer cycle and wait again + * + * This is also far nicer on CPU since roamboxes are heavy by nature + */ + if (!CheckLosFN( + roambox_destination_x, + roambox_destination_y, + m_Position.z + GetZOffset(), + this->GetSize())) { + + time_until_can_move = Timer::GetCurrentTime() + RandomTimer(roambox_min_delay, roambox_delay); + + Log(Logs::Detail, + Logs::NPCRoamBox, + "%s | Can't see where I want to go... I'll try something else...", + this->GetCleanName()); + + return; + } + Log(Logs::Detail, Logs::NPCRoamBox, "Calculate | NPC: %s distance %.3f | min_x %.3f | max_x %.3f | final_x %.3f | min_y %.3f | max_y %.3f | final_y %.3f",