mirror of
https://github.com/EQEmu/Server.git
synced 2026-03-23 19:02:25 +00:00
Changed how i calc partial and broken paths
This commit is contained in:
parent
66c952eff0
commit
76f3bb1ce6
@ -188,7 +188,7 @@ PathfindingRoute PathfindingManager::FindRoute(const glm::vec3 &src_loc, const g
|
|||||||
glm::vec3 dest_location(dest_loc.x, dest_loc.z, dest_loc.y);
|
glm::vec3 dest_location(dest_loc.x, dest_loc.z, dest_loc.y);
|
||||||
|
|
||||||
PathfindingRoute ret;
|
PathfindingRoute ret;
|
||||||
|
ret.m_status = PathComplete;
|
||||||
ret.m_dest = dest_loc;
|
ret.m_dest = dest_loc;
|
||||||
ret.m_current_node = 0;
|
ret.m_current_node = 0;
|
||||||
ret.m_active = true;
|
ret.m_active = true;
|
||||||
@ -208,7 +208,7 @@ PathfindingRoute PathfindingManager::FindRoute(const glm::vec3 &src_loc, const g
|
|||||||
|
|
||||||
dtPolyRef start_ref;
|
dtPolyRef start_ref;
|
||||||
dtPolyRef end_ref;
|
dtPolyRef end_ref;
|
||||||
glm::vec3 ext(10.0f, 10.0f, 10.0f);
|
glm::vec3 ext(15.0f, 15.0f, 15.0f);
|
||||||
|
|
||||||
m_nav_query->findNearestPoly(¤t_location[0], &ext[0], &m_filter, &start_ref, 0);
|
m_nav_query->findNearestPoly(¤t_location[0], &ext[0], &m_filter, &start_ref, 0);
|
||||||
m_nav_query->findNearestPoly(&dest_location[0], &ext[0], &m_filter, &end_ref, 0);
|
m_nav_query->findNearestPoly(&dest_location[0], &ext[0], &m_filter, &end_ref, 0);
|
||||||
@ -223,20 +223,34 @@ PathfindingRoute PathfindingManager::FindRoute(const glm::vec3 &src_loc, const g
|
|||||||
|
|
||||||
int npoly = 0;
|
int npoly = 0;
|
||||||
dtPolyRef path[256] = { 0 };
|
dtPolyRef path[256] = { 0 };
|
||||||
m_nav_query->findPath(start_ref, end_ref, ¤t_location[0], &dest_location[0], &m_filter, path, &npoly, 256);
|
auto status = m_nav_query->findPath(start_ref, end_ref, ¤t_location[0], &dest_location[0], &m_filter, path, &npoly, 256);
|
||||||
|
|
||||||
|
if (status & DT_OUT_OF_NODES || status & DT_BUFFER_TOO_SMALL) {
|
||||||
|
ret.m_status = PathPartial;
|
||||||
|
}
|
||||||
|
else if (status & DT_PARTIAL_RESULT) {
|
||||||
|
ret.m_status = PathBroken;
|
||||||
|
}
|
||||||
|
|
||||||
if (npoly) {
|
if (npoly) {
|
||||||
glm::vec3 epos = dest_location;
|
glm::vec3 epos = dest_location;
|
||||||
if (path[npoly - 1] != end_ref)
|
if (path[npoly - 1] != end_ref)
|
||||||
m_nav_query->closestPointOnPoly(path[npoly - 1], &dest_location[0], &epos[0], 0);
|
m_nav_query->closestPointOnPoly(path[npoly - 1], &dest_location[0], &epos[0], 0);
|
||||||
|
|
||||||
float straight_path[256 * 3];
|
float straight_path[512 * 3];
|
||||||
unsigned char straight_path_flags[256];
|
unsigned char straight_path_flags[512];
|
||||||
int n_straight_polys;
|
int n_straight_polys;
|
||||||
dtPolyRef straight_path_polys[256];
|
dtPolyRef straight_path_polys[512];
|
||||||
m_nav_query->findStraightPath(¤t_location[0], &epos[0], path, npoly,
|
status = m_nav_query->findStraightPath(¤t_location[0], &epos[0], path, npoly,
|
||||||
straight_path, straight_path_flags,
|
straight_path, straight_path_flags,
|
||||||
straight_path_polys, &n_straight_polys, 256, DT_STRAIGHTPATH_ALL_CROSSINGS);
|
straight_path_polys, &n_straight_polys, 512, DT_STRAIGHTPATH_ALL_CROSSINGS);
|
||||||
|
|
||||||
|
if (ret.m_status == PathComplete && status & DT_OUT_OF_NODES || status & DT_BUFFER_TOO_SMALL) {
|
||||||
|
ret.m_status = PathPartial;
|
||||||
|
}
|
||||||
|
else if (ret.m_status == PathComplete && status & DT_PARTIAL_RESULT) {
|
||||||
|
ret.m_status = PathBroken;
|
||||||
|
}
|
||||||
|
|
||||||
if (n_straight_polys) {
|
if (n_straight_polys) {
|
||||||
ret.m_nodes.reserve(n_straight_polys);
|
ret.m_nodes.reserve(n_straight_polys);
|
||||||
@ -309,6 +323,10 @@ PathfindingRoute::~PathfindingRoute()
|
|||||||
|
|
||||||
bool PathfindingRoute::DestinationValid(const glm::vec3 &dest)
|
bool PathfindingRoute::DestinationValid(const glm::vec3 &dest)
|
||||||
{
|
{
|
||||||
|
if (m_status == PathPartial && m_current_node + 1 == m_nodes.size()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
auto dist = vec_dist(dest, m_dest);
|
auto dist = vec_dist(dest, m_dest);
|
||||||
if (dist <= max_dest_drift) {
|
if (dist <= max_dest_drift) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -43,6 +43,13 @@ struct PathfindingNode
|
|||||||
unsigned short flag;
|
unsigned short flag;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum PathfindingRouteStatus
|
||||||
|
{
|
||||||
|
PathComplete,
|
||||||
|
PathPartial,
|
||||||
|
PathBroken
|
||||||
|
};
|
||||||
|
|
||||||
class PathfindingRoute
|
class PathfindingRoute
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -56,11 +63,13 @@ public:
|
|||||||
unsigned short GetPreviousNodeFlag();
|
unsigned short GetPreviousNodeFlag();
|
||||||
const std::vector<PathfindingNode>& GetNodes() const { return m_nodes; }
|
const std::vector<PathfindingNode>& GetNodes() const { return m_nodes; }
|
||||||
std::vector<PathfindingNode>& GetNodesEdit() { return m_nodes; }
|
std::vector<PathfindingNode>& GetNodesEdit() { return m_nodes; }
|
||||||
|
PathfindingRouteStatus GetStatus() { return m_status; }
|
||||||
private:
|
private:
|
||||||
glm::vec3 m_dest;
|
glm::vec3 m_dest;
|
||||||
std::vector<PathfindingNode> m_nodes;
|
std::vector<PathfindingNode> m_nodes;
|
||||||
int m_current_node;
|
int m_current_node;
|
||||||
bool m_active;
|
bool m_active;
|
||||||
|
PathfindingRouteStatus m_status;
|
||||||
|
|
||||||
friend class PathfindingManager;
|
friend class PathfindingManager;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -4101,10 +4101,9 @@ void command_path(Client *c, const Seperator *sep)
|
|||||||
bool first = true;
|
bool first = true;
|
||||||
auto route = zone->pathing.FindRoute(src, dest);
|
auto route = zone->pathing.FindRoute(src, dest);
|
||||||
auto &nodes = route.GetNodes();
|
auto &nodes = route.GetNodes();
|
||||||
auto &last_node = nodes[nodes.size() - 1];
|
|
||||||
auto dist = DistanceSquared(glm::vec4(last_node.position, 1.0f), glm::vec4(dest.x, dest.y, dest.z, 0.0f));
|
if (route.GetStatus() == PathComplete) {
|
||||||
if (dist > 10000.0f) {
|
c->Message(0, "Path from (%.2f, %.2f, %.2f) to (%.2f, %.2f, %.2f) found with %i nodes, complete path.",
|
||||||
c->Message(0, "Path from (%.2f, %.2f, %.2f) to (%.2f, %.2f, %.2f) found with %i nodes, broken path, would need warp.",
|
|
||||||
src.x,
|
src.x,
|
||||||
src.y,
|
src.y,
|
||||||
src.z,
|
src.z,
|
||||||
@ -4112,9 +4111,7 @@ void command_path(Client *c, const Seperator *sep)
|
|||||||
dest.y,
|
dest.y,
|
||||||
dest.z,
|
dest.z,
|
||||||
(int)nodes.size());
|
(int)nodes.size());
|
||||||
return;
|
} else if (route.GetStatus() == PathPartial) {
|
||||||
}
|
|
||||||
else if (dist > 100.0f) {
|
|
||||||
c->Message(0, "Path from (%.2f, %.2f, %.2f) to (%.2f, %.2f, %.2f) found with %i nodes, partial path.",
|
c->Message(0, "Path from (%.2f, %.2f, %.2f) to (%.2f, %.2f, %.2f) found with %i nodes, partial path.",
|
||||||
src.x,
|
src.x,
|
||||||
src.y,
|
src.y,
|
||||||
@ -4123,17 +4120,17 @@ void command_path(Client *c, const Seperator *sep)
|
|||||||
dest.y,
|
dest.y,
|
||||||
dest.z,
|
dest.z,
|
||||||
(int)nodes.size());
|
(int)nodes.size());
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
c->Message(0, "Path from (%.2f, %.2f, %.2f) to (%.2f, %.2f, %.2f) found with %i nodes, complete path.",
|
c->Message(0, "Path from (%.2f, %.2f, %.2f) to (%.2f, %.2f, %.2f) found with %i nodes, broken path.",
|
||||||
src.x,
|
src.x,
|
||||||
src.y,
|
src.y,
|
||||||
src.z,
|
src.z,
|
||||||
dest.x,
|
dest.x,
|
||||||
dest.y,
|
dest.y,
|
||||||
dest.z,
|
dest.z,
|
||||||
(int)nodes.size());
|
(int)nodes.size());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void command_pvp(Client *c, const Seperator *sep)
|
void command_pvp(Client *c, const Seperator *sep)
|
||||||
|
|||||||
@ -38,35 +38,12 @@ glm::vec3 Mob::UpdatePath(float ToX, float ToY, float ToZ, float Speed, bool &Wa
|
|||||||
|
|
||||||
m_pathing_route = zone->pathing.FindRoute(from, to);
|
m_pathing_route = zone->pathing.FindRoute(from, to);
|
||||||
|
|
||||||
auto &nodes = m_pathing_route.GetNodesEdit();
|
if (m_pathing_route.GetStatus() == PathBroken) {
|
||||||
auto &last_node = nodes[nodes.size() - 1];
|
auto &nodes = m_pathing_route.GetNodesEdit();
|
||||||
//Code to complete partial paths.
|
auto &last_node = nodes[nodes.size() - 1];
|
||||||
//If the path is too long then just warp to end.
|
|
||||||
if (nodes.size() < 256) {
|
|
||||||
auto dist = DistanceSquared(glm::vec4(last_node.position, 1.0f), glm::vec4(ToX, ToY, ToZ, 0.0f));
|
|
||||||
if (dist > 10000.0f) {
|
|
||||||
auto flag_temp = last_node.flag;
|
|
||||||
last_node.flag = NavigationPolyFlagPortal;
|
|
||||||
|
|
||||||
PathfindingNode end;
|
|
||||||
end.position.x = ToX;
|
|
||||||
end.position.y = ToY;
|
|
||||||
end.position.z = ToZ;
|
|
||||||
end.flag = flag_temp;
|
|
||||||
nodes.push_back(end);
|
|
||||||
}
|
|
||||||
else if (dist > 100.0f) {
|
|
||||||
PathfindingNode end;
|
|
||||||
end.position.x = ToX;
|
|
||||||
end.position.y = ToY;
|
|
||||||
end.position.z = ToZ;
|
|
||||||
end.flag = NavigationPolyFlagNormal;
|
|
||||||
nodes.push_back(end);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
auto flag_temp = last_node.flag;
|
auto flag_temp = last_node.flag;
|
||||||
last_node.flag = NavigationPolyFlagPortal;
|
last_node.flag = NavigationPolyFlagPortal;
|
||||||
|
|
||||||
PathfindingNode end;
|
PathfindingNode end;
|
||||||
end.position.x = ToX;
|
end.position.x = ToX;
|
||||||
end.position.y = ToY;
|
end.position.y = ToY;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user