Limit path finding max complexity

This commit is contained in:
Eduardo Bart
2013-01-20 14:30:53 -02:00
parent 8c6d5a0f5c
commit 18a37393c5
2 changed files with 8 additions and 5 deletions

View File

@@ -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;