From e466f9b3f9c2f75b5f4ba5c36d51d42110ab5ce5 Mon Sep 17 00:00:00 2001 From: E Spause Date: Fri, 19 Oct 2018 22:35:38 -0400 Subject: [PATCH] Fear pathing fixups, random path rewrite, and nektulos / general roambox fixups where best Z axis is below the ground --- zone/fearpath.cpp | 28 +++------------------------- zone/mob_ai.cpp | 8 +++++--- zone/pathfinder_interface.h | 2 +- zone/pathfinder_nav_mesh.cpp | 32 +++++++++++++++++++++++++++----- zone/pathfinder_nav_mesh.h | 4 ++-- zone/pathfinder_null.cpp | 2 +- zone/pathfinder_null.h | 4 ++-- zone/pathfinder_waypoint.cpp | 2 +- zone/pathfinder_waypoint.h | 4 ++-- 9 files changed, 44 insertions(+), 42 deletions(-) diff --git a/zone/fearpath.cpp b/zone/fearpath.cpp index c73ec448e..d86d0948e 100644 --- a/zone/fearpath.cpp +++ b/zone/fearpath.cpp @@ -157,41 +157,19 @@ void Mob::ProcessFlee() void Mob::CalculateNewFearpoint() { if (RuleB(Pathing, Fear) && zone->pathing) { - auto Node = zone->pathing->GetRandomLocation(); + auto Node = zone->pathing->GetRandomLocation(glm::vec3(GetX(), GetY(), GetZ())); if (Node.x != 0.0f || Node.y != 0.0f || Node.z != 0.0f) { - - ++Node.z; m_FearWalkTarget = Node; currently_fleeing = true; return; } + Stun(6000); + Log(Logs::Detail, Logs::Pathing, "No path found to selected node. Falling through to old fear point selection."); } - - int loop = 0; - float ranx, rany, ranz; - - currently_fleeing = true; - while (loop < 100) //Max 100 tries - { - int ran = 250 - (loop * 2); - loop++; - ranx = GetX() + zone->random.Int(0, ran - 1) - zone->random.Int(0, ran - 1); - rany = GetY() + zone->random.Int(0, ran - 1) - zone->random.Int(0, ran - 1); - ranz = FindGroundZ(ranx, rany); - if (ranz == BEST_Z_INVALID) - continue; - float fdist = ranz - GetZ(); - if (fdist >= -12 && fdist <= 12 && CheckCoordLosNoZLeaps(GetX(), GetY(), GetZ(), ranx, rany, ranz)) { - break; - } - } - - if (currently_fleeing) - m_FearWalkTarget = glm::vec3(ranx, rany, ranz); } diff --git a/zone/mob_ai.cpp b/zone/mob_ai.cpp index 8e2e3e029..bde1b5f11 100644 --- a/zone/mob_ai.cpp +++ b/zone/mob_ai.cpp @@ -802,6 +802,7 @@ void Client::AI_Process() if (AI_movement_timer->Check()) { // Check if we have reached the last fear point if(IsPositionEqualWithinCertainZ(glm::vec3(GetX(), GetY(), GetZ()), m_FearWalkTarget, 5.0f)) { + StopNavigation(); CalculateNewFearpoint(); } @@ -1080,11 +1081,12 @@ void Mob::AI_Process() { else { if (AI_movement_timer->Check()) { // Check if we have reached the last fear point - if (IsPositionEqualWithinCertainZ(glm::vec3(GetX(), GetY(), GetZ()), m_FearWalkTarget, 5.0f)) { + if (DistanceNoZ(glm::vec3(GetX(), GetY(), GetZ()), m_FearWalkTarget) <= 5.0f) { // Calculate a new point to run to + StopNavigation(); CalculateNewFearpoint(); } - NavigateTo( + RunTo( m_FearWalkTarget.x, m_FearWalkTarget.y, m_FearWalkTarget.z @@ -1661,7 +1663,7 @@ void NPC::AI_DoMovement() { destination.x = roambox_destination_x; destination.y = roambox_destination_y; destination.z = m_Position.z; - roambox_destination_z = GetFixedZ(destination) + this->GetZOffset(); + roambox_destination_z = zone->zonemap->FindClosestZ(glm::vec3(roambox_destination_x, roambox_destination_y, roambox_destination_z), nullptr) + this->GetZOffset(); Log(Logs::Detail, Logs::NPCRoamBox, diff --git a/zone/pathfinder_interface.h b/zone/pathfinder_interface.h index 2a874a50d..85a153813 100644 --- a/zone/pathfinder_interface.h +++ b/zone/pathfinder_interface.h @@ -30,7 +30,7 @@ public: virtual ~IPathfinder() { } virtual IPath FindRoute(const glm::vec3 &start, const glm::vec3 &end, bool &partial, bool &stuck) = 0; - virtual glm::vec3 GetRandomLocation() = 0; + virtual glm::vec3 GetRandomLocation(const glm::vec3 &start) = 0; virtual void DebugCommand(Client *c, const Seperator *sep) = 0; static IPathfinder *Load(const std::string &zone); diff --git a/zone/pathfinder_nav_mesh.cpp b/zone/pathfinder_nav_mesh.cpp index 615ba1c4e..cddf8d151 100644 --- a/zone/pathfinder_nav_mesh.cpp +++ b/zone/pathfinder_nav_mesh.cpp @@ -131,8 +131,11 @@ IPathfinder::IPath PathfinderNavmesh::FindRoute(const glm::vec3 &start, const gl return Route; } -glm::vec3 PathfinderNavmesh::GetRandomLocation() +glm::vec3 PathfinderNavmesh::GetRandomLocation(const glm::vec3 &start) { + if (start.x == 0.0f && start.y == 0.0) + return glm::vec3(0.f); + if (!m_impl->nav_mesh) { return glm::vec3(0.f); } @@ -143,14 +146,33 @@ glm::vec3 PathfinderNavmesh::GetRandomLocation() } dtQueryFilter filter; - filter.setIncludeFlags(65535U); + filter.setIncludeFlags(65535U ^ 2048); + filter.setAreaCost(0, 1.0f); //Normal + filter.setAreaCost(1, 3.0f); //Water + filter.setAreaCost(2, 5.0f); //Lava + filter.setAreaCost(4, 1.0f); //PvP + filter.setAreaCost(5, 2.0f); //Slime + filter.setAreaCost(6, 2.0f); //Ice + filter.setAreaCost(7, 4.0f); //V Water (Frigid Water) + filter.setAreaCost(8, 1.0f); //General Area + filter.setAreaCost(9, 0.1f); //Portal + filter.setAreaCost(10, 0.1f); //Prefer dtPolyRef randomRef; float point[3]; - if (dtStatusSucceed(m_impl->query->findRandomPoint(&filter, []() { - return (float)zone->random.Real(0.0, 1.0); - }, &randomRef, point))) + dtPolyRef start_ref; + glm::vec3 current_location(start.x, start.z, start.y); + glm::vec3 ext(5.0f, 100.0f, 5.0f); + + m_impl->query->findNearestPoly(¤t_location[0], &ext[0], &filter, &start_ref, 0); + + if (!start_ref) + { + return glm::vec3(0.f); + } + + if (dtStatusSucceed(m_impl->query->findRandomPointAroundCircle(start_ref, ¤t_location[0], 100.f, &filter, []() { return (float)zone->random.Real(0.0, 1.0); }, &randomRef, point))) { return glm::vec3(point[0], point[2], point[1]); } diff --git a/zone/pathfinder_nav_mesh.h b/zone/pathfinder_nav_mesh.h index e740e5ca7..40fca0b3b 100644 --- a/zone/pathfinder_nav_mesh.h +++ b/zone/pathfinder_nav_mesh.h @@ -10,7 +10,7 @@ public: virtual ~PathfinderNavmesh(); virtual IPath FindRoute(const glm::vec3 &start, const glm::vec3 &end, bool &partial, bool &stuck); - virtual glm::vec3 GetRandomLocation(); + virtual glm::vec3 GetRandomLocation(const glm::vec3 &start); virtual void DebugCommand(Client *c, const Seperator *sep); private: @@ -20,4 +20,4 @@ private: struct Implementation; std::unique_ptr m_impl; -}; \ No newline at end of file +}; diff --git a/zone/pathfinder_null.cpp b/zone/pathfinder_null.cpp index dce3d19f5..4a5cbbe63 100644 --- a/zone/pathfinder_null.cpp +++ b/zone/pathfinder_null.cpp @@ -10,7 +10,7 @@ IPathfinder::IPath PathfinderNull::FindRoute(const glm::vec3 &start, const glm:: return ret; } -glm::vec3 PathfinderNull::GetRandomLocation() +glm::vec3 PathfinderNull::GetRandomLocation(const glm::vec3 &start) { return glm::vec3(); } diff --git a/zone/pathfinder_null.h b/zone/pathfinder_null.h index 2c43e3085..242dcf755 100644 --- a/zone/pathfinder_null.h +++ b/zone/pathfinder_null.h @@ -9,6 +9,6 @@ public: virtual ~PathfinderNull() { } virtual IPath FindRoute(const glm::vec3 &start, const glm::vec3 &end, bool &partial, bool &stuck); - virtual glm::vec3 GetRandomLocation(); + virtual glm::vec3 GetRandomLocation(const glm::vec3 &start); virtual void DebugCommand(Client *c, const Seperator *sep) { } -}; \ No newline at end of file +}; diff --git a/zone/pathfinder_waypoint.cpp b/zone/pathfinder_waypoint.cpp index c3a85418e..9e9831e9c 100644 --- a/zone/pathfinder_waypoint.cpp +++ b/zone/pathfinder_waypoint.cpp @@ -184,7 +184,7 @@ IPathfinder::IPath PathfinderWaypoint::FindRoute(const glm::vec3 &start, const g return IPath(); } -glm::vec3 PathfinderWaypoint::GetRandomLocation() +glm::vec3 PathfinderWaypoint::GetRandomLocation(const glm::vec3 &start) { if (m_impl->Nodes.size() > 0) { auto idx = zone->random.Int(0, (int)m_impl->Nodes.size() - 1); diff --git a/zone/pathfinder_waypoint.h b/zone/pathfinder_waypoint.h index 3f6b99c9f..1570eca24 100644 --- a/zone/pathfinder_waypoint.h +++ b/zone/pathfinder_waypoint.h @@ -12,7 +12,7 @@ public: virtual ~PathfinderWaypoint(); virtual IPath FindRoute(const glm::vec3 &start, const glm::vec3 &end, bool &partial, bool &stuck); - virtual glm::vec3 GetRandomLocation(); + virtual glm::vec3 GetRandomLocation(const glm::vec3 &start); virtual void DebugCommand(Client *c, const Seperator *sep); private: @@ -28,4 +28,4 @@ private: struct Implementation; std::unique_ptr m_impl; -}; \ No newline at end of file +};