Fear pathing fixups, random path rewrite, and nektulos / general roambox fixups where best Z axis is below the ground

This commit is contained in:
E Spause 2018-10-19 22:35:38 -04:00
parent 904bc3e004
commit e466f9b3f9
9 changed files with 44 additions and 42 deletions

View File

@ -157,41 +157,19 @@ void Mob::ProcessFlee()
void Mob::CalculateNewFearpoint() { void Mob::CalculateNewFearpoint() {
if (RuleB(Pathing, Fear) && zone->pathing) { 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) { if (Node.x != 0.0f || Node.y != 0.0f || Node.z != 0.0f) {
++Node.z;
m_FearWalkTarget = Node; m_FearWalkTarget = Node;
currently_fleeing = true; currently_fleeing = true;
return; return;
} }
Stun(6000);
Log(Logs::Detail, Log(Logs::Detail,
Logs::Pathing, Logs::Pathing,
"No path found to selected node. Falling through to old fear point selection."); "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);
} }

View File

@ -802,6 +802,7 @@ void Client::AI_Process()
if (AI_movement_timer->Check()) { if (AI_movement_timer->Check()) {
// Check if we have reached the last fear point // Check if we have reached the last fear point
if(IsPositionEqualWithinCertainZ(glm::vec3(GetX(), GetY(), GetZ()), m_FearWalkTarget, 5.0f)) { if(IsPositionEqualWithinCertainZ(glm::vec3(GetX(), GetY(), GetZ()), m_FearWalkTarget, 5.0f)) {
StopNavigation();
CalculateNewFearpoint(); CalculateNewFearpoint();
} }
@ -1080,11 +1081,12 @@ void Mob::AI_Process() {
else { else {
if (AI_movement_timer->Check()) { if (AI_movement_timer->Check()) {
// Check if we have reached the last fear point // 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 // Calculate a new point to run to
StopNavigation();
CalculateNewFearpoint(); CalculateNewFearpoint();
} }
NavigateTo( RunTo(
m_FearWalkTarget.x, m_FearWalkTarget.x,
m_FearWalkTarget.y, m_FearWalkTarget.y,
m_FearWalkTarget.z m_FearWalkTarget.z
@ -1661,7 +1663,7 @@ void NPC::AI_DoMovement() {
destination.x = roambox_destination_x; destination.x = roambox_destination_x;
destination.y = roambox_destination_y; destination.y = roambox_destination_y;
destination.z = m_Position.z; 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, Log(Logs::Detail,
Logs::NPCRoamBox, Logs::NPCRoamBox,

View File

@ -30,7 +30,7 @@ public:
virtual ~IPathfinder() { } virtual ~IPathfinder() { }
virtual IPath FindRoute(const glm::vec3 &start, const glm::vec3 &end, bool &partial, bool &stuck) = 0; 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; virtual void DebugCommand(Client *c, const Seperator *sep) = 0;
static IPathfinder *Load(const std::string &zone); static IPathfinder *Load(const std::string &zone);

View File

@ -131,8 +131,11 @@ IPathfinder::IPath PathfinderNavmesh::FindRoute(const glm::vec3 &start, const gl
return Route; 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) { if (!m_impl->nav_mesh) {
return glm::vec3(0.f); return glm::vec3(0.f);
} }
@ -143,14 +146,33 @@ glm::vec3 PathfinderNavmesh::GetRandomLocation()
} }
dtQueryFilter filter; 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; dtPolyRef randomRef;
float point[3]; float point[3];
if (dtStatusSucceed(m_impl->query->findRandomPoint(&filter, []() { dtPolyRef start_ref;
return (float)zone->random.Real(0.0, 1.0); glm::vec3 current_location(start.x, start.z, start.y);
}, &randomRef, point))) glm::vec3 ext(5.0f, 100.0f, 5.0f);
m_impl->query->findNearestPoly(&current_location[0], &ext[0], &filter, &start_ref, 0);
if (!start_ref)
{
return glm::vec3(0.f);
}
if (dtStatusSucceed(m_impl->query->findRandomPointAroundCircle(start_ref, &current_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]); return glm::vec3(point[0], point[2], point[1]);
} }

View File

@ -10,7 +10,7 @@ public:
virtual ~PathfinderNavmesh(); virtual ~PathfinderNavmesh();
virtual IPath FindRoute(const glm::vec3 &start, const glm::vec3 &end, bool &partial, bool &stuck); 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); virtual void DebugCommand(Client *c, const Seperator *sep);
private: private:
@ -20,4 +20,4 @@ private:
struct Implementation; struct Implementation;
std::unique_ptr<Implementation> m_impl; std::unique_ptr<Implementation> m_impl;
}; };

View File

@ -10,7 +10,7 @@ IPathfinder::IPath PathfinderNull::FindRoute(const glm::vec3 &start, const glm::
return ret; return ret;
} }
glm::vec3 PathfinderNull::GetRandomLocation() glm::vec3 PathfinderNull::GetRandomLocation(const glm::vec3 &start)
{ {
return glm::vec3(); return glm::vec3();
} }

View File

@ -9,6 +9,6 @@ public:
virtual ~PathfinderNull() { } virtual ~PathfinderNull() { }
virtual IPath FindRoute(const glm::vec3 &start, const glm::vec3 &end, bool &partial, bool &stuck); 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) { } virtual void DebugCommand(Client *c, const Seperator *sep) { }
}; };

View File

@ -184,7 +184,7 @@ IPathfinder::IPath PathfinderWaypoint::FindRoute(const glm::vec3 &start, const g
return IPath(); return IPath();
} }
glm::vec3 PathfinderWaypoint::GetRandomLocation() glm::vec3 PathfinderWaypoint::GetRandomLocation(const glm::vec3 &start)
{ {
if (m_impl->Nodes.size() > 0) { if (m_impl->Nodes.size() > 0) {
auto idx = zone->random.Int(0, (int)m_impl->Nodes.size() - 1); auto idx = zone->random.Int(0, (int)m_impl->Nodes.size() - 1);

View File

@ -12,7 +12,7 @@ public:
virtual ~PathfinderWaypoint(); virtual ~PathfinderWaypoint();
virtual IPath FindRoute(const glm::vec3 &start, const glm::vec3 &end, bool &partial, bool &stuck); 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); virtual void DebugCommand(Client *c, const Seperator *sep);
private: private:
@ -28,4 +28,4 @@ private:
struct Implementation; struct Implementation;
std::unique_ptr<Implementation> m_impl; std::unique_ptr<Implementation> m_impl;
}; };