Bug fixes with fear points and teleport jumps

This commit is contained in:
KimLS 2017-08-06 20:48:39 -07:00
parent 3afee1f841
commit 575ba28b62
4 changed files with 67 additions and 25 deletions

View File

@ -133,20 +133,7 @@ void Mob::CalculateNewFearpoint()
if (Node.x != 0.0f || Node.y != 0.0f || Node.z != 0.0f) {
++Node.z;
glm::vec3 CurrentPosition(GetX(), GetY(), GetZ());
auto Route = zone->pathing->FindRoute(CurrentPosition, Node);
if (!Route.empty())
{
auto first = (*Route.begin());
m_FearWalkTarget = glm::vec3(first.pos.x, first.pos.y, first.pos.z);
currently_fleeing = true;
Log(Logs::Detail, Logs::None, "Feared to node %i (%8.3f, %8.3f, %8.3f)", Node, first.pos.x, first.pos.y, first.pos.z);
return;
}
m_FearWalkTarget = Node;
}

View File

@ -6,6 +6,7 @@
#include "pathfinder_nav_mesh.h"
#include "zone.h"
#include "water_map.h"
#include "client.h"
#include "../common/compression.h"
@ -106,12 +107,7 @@ IPathfinder::IPath PathfinderNavmesh::FindRoute(const glm::vec3 &start, const gl
node.z = straight_path[i * 3 + 1];
node.y = straight_path[i * 3 + 2];
if (zone->HasMap()) {
auto best_z = zone->zonemap->FindBestZ(node, nullptr);
if (best_z != BEST_Z_INVALID) {
node.z = best_z;
}
}
Route.push_back(node);
unsigned short flag = 0;
if (dtStatusSucceed(m_impl->nav_mesh->getPolyFlags(straight_path_polys[i], &flag))) {
@ -119,8 +115,6 @@ IPathfinder::IPath PathfinderNavmesh::FindRoute(const glm::vec3 &start, const gl
Route.push_back(true);
}
}
Route.push_back(node);
}
return Route;
@ -134,6 +128,28 @@ IPathfinder::IPath PathfinderNavmesh::FindRoute(const glm::vec3 &start, const gl
glm::vec3 PathfinderNavmesh::GetRandomLocation()
{
if (!m_impl->nav_mesh) {
return glm::vec3();
}
if (!m_impl->query) {
m_impl->query = dtAllocNavMeshQuery();
m_impl->query->init(m_impl->nav_mesh, 32768);
}
dtQueryFilter filter;
filter.setIncludeFlags(65535U);
dtPolyRef randomRef;
float point[3];
if (dtStatusSucceed(m_impl->query->findRandomPoint(&filter, []() {
return (float)zone->random.Real(0.0, 1.0);
}, &randomRef, point)))
{
return glm::vec3(point[0], point[2], point[1]);
}
return glm::vec3();
}

View File

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

View File

@ -2,9 +2,25 @@
#include "client.h"
#include "zone.h"
#include "water_map.h"
extern Zone *zone;
void AdjustRoute(std::list<IPathfinder::IPathNode> &nodes, int flymode) {
if (!zone->HasMap() || !zone->HasWaterMap()) {
return;
}
for (auto &node : nodes) {
if (flymode == 0 || !zone->watermap->InLiquid(node.pos)) {
auto best_z = zone->zonemap->FindBestZ(node.pos, nullptr);
if (best_z != BEST_Z_INVALID) {
node.pos.z = best_z;
}
}
}
}
glm::vec3 Mob::UpdatePath(float ToX, float ToY, float ToZ, float Speed, bool &WaypointChanged, bool &NodeReached)
{
glm::vec3 To(ToX, ToY, ToZ);
@ -23,6 +39,8 @@ glm::vec3 Mob::UpdatePath(float ToX, float ToY, float ToZ, float Speed, bool &Wa
if (Route.empty()) {
Route = zone->pathing->FindRoute(From, To);
AdjustRoute(Route, flymode);
PathingDestination = To;
WaypointChanged = true;
NodeReached = false;
@ -39,10 +57,18 @@ glm::vec3 Mob::UpdatePath(float ToX, float ToY, float ToZ, float Speed, bool &Wa
if (!SameDestination) {
//We had a route but our target position moved too much
Route = zone->pathing->FindRoute(From, To);
AdjustRoute(Route, flymode);
PathingDestination = To;
WaypointChanged = true;
NodeReached = false;
return (*Route.begin()).pos;
if (Route.empty()) {
return From;
}
else {
return (*Route.begin()).pos;
}
}
}
@ -93,14 +119,20 @@ glm::vec3 Mob::UpdatePath(float ToX, float ToY, float ToZ, float Speed, bool &Wa
if (Route.empty()) {
Route = zone->pathing->FindRoute(From, To);
AdjustRoute(Route, flymode);
PathingDestination = To;
WaypointChanged = true;
return (*Route.begin()).pos;
if (Route.empty()) {
return From;
}
else {
return (*Route.begin()).pos;
}
}
else {
auto node = *Route.begin();
if (node.teleport) {
//If is identity node then is teleport node.
Route.pop_front();
if (Route.empty()) {