From 8a28e8500d9b8202545fc6fda5e65b98d0872436 Mon Sep 17 00:00:00 2001 From: Akkadius Date: Mon, 3 Sep 2018 03:06:23 -0500 Subject: [PATCH] Make fear and fleeing respect navmesh for both clients and NPCs --- zone/fearpath.cpp | 29 +++++++++++++++-------------- zone/mob_ai.cpp | 8 ++++++-- zone/zone.cpp | 6 +++--- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/zone/fearpath.cpp b/zone/fearpath.cpp index 168dd2ce6..c73ec448e 100644 --- a/zone/fearpath.cpp +++ b/zone/fearpath.cpp @@ -155,42 +155,43 @@ void Mob::ProcessFlee() } } -void Mob::CalculateNewFearpoint() -{ - if(RuleB(Pathing, Fear) && zone->pathing) - { +void Mob::CalculateNewFearpoint() { + if (RuleB(Pathing, Fear) && zone->pathing) { auto Node = zone->pathing->GetRandomLocation(); if (Node.x != 0.0f || Node.y != 0.0f || Node.z != 0.0f) { ++Node.z; - m_FearWalkTarget = Node; + m_FearWalkTarget = Node; + currently_fleeing = true; + return; } - Log(Logs::Detail, Logs::None, "No path found to selected node. Falling through to old fear point selection."); + Log(Logs::Detail, + Logs::Pathing, + "No path found to selected node. Falling through to old fear point selection."); } - int loop = 0; + int loop = 0; float ranx, rany, ranz; currently_fleeing = true; while (loop < 100) //Max 100 tries { - int ran = 250 - (loop*2); + 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); + 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)) - { + if (fdist >= -12 && fdist <= 12 && CheckCoordLosNoZLeaps(GetX(), GetY(), GetZ(), ranx, rany, ranz)) { break; } } if (currently_fleeing) - m_FearWalkTarget = glm::vec3(ranx, rany, ranz); + m_FearWalkTarget = glm::vec3(ranx, rany, ranz); } diff --git a/zone/mob_ai.cpp b/zone/mob_ai.cpp index 9fe43e1ea..2ba5cea7f 100644 --- a/zone/mob_ai.cpp +++ b/zone/mob_ai.cpp @@ -1142,8 +1142,12 @@ void Mob::AI_Process() { bool WaypointChanged, NodeReached; glm::vec3 Goal = UpdatePath( - m_FearWalkTarget.x, m_FearWalkTarget.y, m_FearWalkTarget.z, - GetFearSpeed(), WaypointChanged, NodeReached + m_FearWalkTarget.x, + m_FearWalkTarget.y, + m_FearWalkTarget.z, + GetFearSpeed(), + WaypointChanged, + NodeReached ); if (WaypointChanged) diff --git a/zone/zone.cpp b/zone/zone.cpp index d43527c4f..3b9e5e513 100644 --- a/zone/zone.cpp +++ b/zone/zone.cpp @@ -904,10 +904,10 @@ bool Zone::Init(bool iStaticZone) { RuleManager::Instance()->LoadRules(&database, r_name.c_str()); } } - - zone->zonemap = Map::LoadMapFile(zone->map_name); + + zone->zonemap = Map::LoadMapFile(zone->map_name); zone->watermap = WaterMap::LoadWaterMapfile(zone->map_name); - zone->pathing = IPathfinder::Load(zone->map_name); + zone->pathing = IPathfinder::Load(zone->map_name); Log(Logs::General, Logs::Status, "Loading spawn conditions..."); if(!spawn_conditions.LoadSpawnConditions(short_name, instanceid)) {