mirror of
https://github.com/EQEmu/Server.git
synced 2026-02-16 12:52: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);
|
||||
|
||||
PathfindingRoute ret;
|
||||
|
||||
ret.m_status = PathComplete;
|
||||
ret.m_dest = dest_loc;
|
||||
ret.m_current_node = 0;
|
||||
ret.m_active = true;
|
||||
@ -208,7 +208,7 @@ PathfindingRoute PathfindingManager::FindRoute(const glm::vec3 &src_loc, const g
|
||||
|
||||
dtPolyRef start_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(&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;
|
||||
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) {
|
||||
glm::vec3 epos = dest_location;
|
||||
if (path[npoly - 1] != end_ref)
|
||||
m_nav_query->closestPointOnPoly(path[npoly - 1], &dest_location[0], &epos[0], 0);
|
||||
|
||||
float straight_path[256 * 3];
|
||||
unsigned char straight_path_flags[256];
|
||||
float straight_path[512 * 3];
|
||||
unsigned char straight_path_flags[512];
|
||||
int n_straight_polys;
|
||||
dtPolyRef straight_path_polys[256];
|
||||
m_nav_query->findStraightPath(¤t_location[0], &epos[0], path, npoly,
|
||||
dtPolyRef straight_path_polys[512];
|
||||
status = m_nav_query->findStraightPath(¤t_location[0], &epos[0], path, npoly,
|
||||
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) {
|
||||
ret.m_nodes.reserve(n_straight_polys);
|
||||
@ -309,6 +323,10 @@ PathfindingRoute::~PathfindingRoute()
|
||||
|
||||
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);
|
||||
if (dist <= max_dest_drift) {
|
||||
return true;
|
||||
|
||||
@ -43,6 +43,13 @@ struct PathfindingNode
|
||||
unsigned short flag;
|
||||
};
|
||||
|
||||
enum PathfindingRouteStatus
|
||||
{
|
||||
PathComplete,
|
||||
PathPartial,
|
||||
PathBroken
|
||||
};
|
||||
|
||||
class PathfindingRoute
|
||||
{
|
||||
public:
|
||||
@ -56,11 +63,13 @@ public:
|
||||
unsigned short GetPreviousNodeFlag();
|
||||
const std::vector<PathfindingNode>& GetNodes() const { return m_nodes; }
|
||||
std::vector<PathfindingNode>& GetNodesEdit() { return m_nodes; }
|
||||
PathfindingRouteStatus GetStatus() { return m_status; }
|
||||
private:
|
||||
glm::vec3 m_dest;
|
||||
std::vector<PathfindingNode> m_nodes;
|
||||
int m_current_node;
|
||||
bool m_active;
|
||||
PathfindingRouteStatus m_status;
|
||||
|
||||
friend class PathfindingManager;
|
||||
};
|
||||
|
||||
@ -4101,10 +4101,9 @@ void command_path(Client *c, const Seperator *sep)
|
||||
bool first = true;
|
||||
auto route = zone->pathing.FindRoute(src, dest);
|
||||
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 (dist > 10000.0f) {
|
||||
c->Message(0, "Path from (%.2f, %.2f, %.2f) to (%.2f, %.2f, %.2f) found with %i nodes, broken path, would need warp.",
|
||||
|
||||
if (route.GetStatus() == PathComplete) {
|
||||
c->Message(0, "Path from (%.2f, %.2f, %.2f) to (%.2f, %.2f, %.2f) found with %i nodes, complete path.",
|
||||
src.x,
|
||||
src.y,
|
||||
src.z,
|
||||
@ -4112,9 +4111,7 @@ void command_path(Client *c, const Seperator *sep)
|
||||
dest.y,
|
||||
dest.z,
|
||||
(int)nodes.size());
|
||||
return;
|
||||
}
|
||||
else if (dist > 100.0f) {
|
||||
} else if (route.GetStatus() == PathPartial) {
|
||||
c->Message(0, "Path from (%.2f, %.2f, %.2f) to (%.2f, %.2f, %.2f) found with %i nodes, partial path.",
|
||||
src.x,
|
||||
src.y,
|
||||
@ -4123,17 +4120,17 @@ void command_path(Client *c, const Seperator *sep)
|
||||
dest.y,
|
||||
dest.z,
|
||||
(int)nodes.size());
|
||||
return;
|
||||
}
|
||||
|
||||
c->Message(0, "Path from (%.2f, %.2f, %.2f) to (%.2f, %.2f, %.2f) found with %i nodes, complete path.",
|
||||
src.x,
|
||||
src.y,
|
||||
src.z,
|
||||
dest.x,
|
||||
dest.y,
|
||||
dest.z,
|
||||
(int)nodes.size());
|
||||
else {
|
||||
c->Message(0, "Path from (%.2f, %.2f, %.2f) to (%.2f, %.2f, %.2f) found with %i nodes, broken path.",
|
||||
src.x,
|
||||
src.y,
|
||||
src.z,
|
||||
dest.x,
|
||||
dest.y,
|
||||
dest.z,
|
||||
(int)nodes.size());
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
auto &nodes = m_pathing_route.GetNodesEdit();
|
||||
auto &last_node = nodes[nodes.size() - 1];
|
||||
//Code to complete partial paths.
|
||||
//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 {
|
||||
if (m_pathing_route.GetStatus() == PathBroken) {
|
||||
auto &nodes = m_pathing_route.GetNodesEdit();
|
||||
auto &last_node = nodes[nodes.size() - 1];
|
||||
auto flag_temp = last_node.flag;
|
||||
last_node.flag = NavigationPolyFlagPortal;
|
||||
|
||||
PathfindingNode end;
|
||||
end.position.x = ToX;
|
||||
end.position.y = ToY;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user