mirror of
https://github.com/edubart/otclient.git
synced 2025-12-02 16:06:51 +01:00
Limit path finding max complexity
This commit is contained in:
@@ -540,6 +540,8 @@ std::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> Map::findPath(const
|
||||
}
|
||||
};
|
||||
|
||||
const uint MAX_COMPLEXITY = 100000;
|
||||
|
||||
std::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> ret;
|
||||
std::vector<Otc::Direction>& dirs = std::get<0>(ret);
|
||||
Otc::PathFindResult& result = std::get<1>(ret);
|
||||
@@ -575,6 +577,11 @@ std::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> Map::findPath(const
|
||||
break;
|
||||
}
|
||||
|
||||
if(nodes.size() > MAX_COMPLEXITY) {
|
||||
result = Otc::PathFindResultTooFar;
|
||||
break;
|
||||
}
|
||||
|
||||
// path found
|
||||
if(currentNode->pos == goalPos && (!foundNode || currentNode->cost < foundNode->cost))
|
||||
foundNode = currentNode;
|
||||
|
||||
Reference in New Issue
Block a user