Fixes and improvements in find path
This commit is contained in:
parent
2bd86d0695
commit
6966221e39
|
@ -178,6 +178,12 @@ void LocalPlayer::cancelWalk(Otc::Direction direction)
|
||||||
|
|
||||||
bool LocalPlayer::autoWalk(const Position& destination)
|
bool LocalPlayer::autoWalk(const Position& destination)
|
||||||
{
|
{
|
||||||
|
bool tryKnownPath = false;
|
||||||
|
if(destination != m_autoWalkDestination) {
|
||||||
|
m_knownCompletePath = false;
|
||||||
|
tryKnownPath = true;
|
||||||
|
}
|
||||||
|
|
||||||
std::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> result;
|
std::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> result;
|
||||||
std::vector<Otc::Direction> limitedPath;
|
std::vector<Otc::Direction> limitedPath;
|
||||||
|
|
||||||
|
@ -185,15 +191,20 @@ bool LocalPlayer::autoWalk(const Position& destination)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// try to find a path that we know
|
// try to find a path that we know
|
||||||
result = g_map.findPath(m_position, destination, 1000, 0);
|
if(tryKnownPath || m_knownCompletePath) {
|
||||||
if(std::get<1>(result) == Otc::PathFindResultOk) {
|
result = g_map.findPath(m_position, destination, 50000, 0);
|
||||||
limitedPath = std::get<0>(result);
|
if(std::get<1>(result) == Otc::PathFindResultOk) {
|
||||||
// limit to 127 steps
|
limitedPath = std::get<0>(result);
|
||||||
if(limitedPath.size() > 127)
|
// limit to 127 steps
|
||||||
limitedPath.resize(127);
|
if(limitedPath.size() > 127)
|
||||||
} else {
|
limitedPath.resize(127);
|
||||||
// no known path found, try to discover one
|
m_knownCompletePath = true;
|
||||||
result = g_map.findPath(m_position, destination, 1000, Otc::PathFindAllowNotSeenTiles);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// no known path found, try to discover one
|
||||||
|
if(limitedPath.empty()) {
|
||||||
|
result = g_map.findPath(m_position, destination, 50000, Otc::PathFindAllowNotSeenTiles);
|
||||||
if(std::get<1>(result) != Otc::PathFindResultOk) {
|
if(std::get<1>(result) != Otc::PathFindResultOk) {
|
||||||
callLuaField("onAutoWalkFail", std::get<1>(result));
|
callLuaField("onAutoWalkFail", std::get<1>(result));
|
||||||
return false;
|
return false;
|
||||||
|
@ -228,6 +239,7 @@ void LocalPlayer::stopAutoWalk()
|
||||||
{
|
{
|
||||||
m_autoWalkDestination = Position();
|
m_autoWalkDestination = Position();
|
||||||
m_lastAutoWalkPosition = Position();
|
m_lastAutoWalkPosition = Position();
|
||||||
|
m_knownCompletePath = false;
|
||||||
|
|
||||||
if(m_autoWalkContinueEvent)
|
if(m_autoWalkContinueEvent)
|
||||||
m_autoWalkContinueEvent->cancel();
|
m_autoWalkContinueEvent->cancel();
|
||||||
|
|
|
@ -130,6 +130,7 @@ private:
|
||||||
stdext::boolean<true> m_lastPrewalkDone;
|
stdext::boolean<true> m_lastPrewalkDone;
|
||||||
stdext::boolean<false> m_autoWalking;
|
stdext::boolean<false> m_autoWalking;
|
||||||
stdext::boolean<false> m_waitingWalkPong;
|
stdext::boolean<false> m_waitingWalkPong;
|
||||||
|
stdext::boolean<false> m_knownCompletePath;
|
||||||
|
|
||||||
stdext::boolean<false> m_premium;
|
stdext::boolean<false> m_premium;
|
||||||
stdext::boolean<false> m_known;
|
stdext::boolean<false> m_known;
|
||||||
|
|
|
@ -522,7 +522,7 @@ int Map::getLastAwareFloor()
|
||||||
return Otc::SEA_FLOOR;
|
return Otc::SEA_FLOOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> Map::findPath(const Position& startPos, const Position& goalPos, int maxSteps, int flags)
|
std::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> Map::findPath(const Position& startPos, const Position& goalPos, int maxComplexity, int flags)
|
||||||
{
|
{
|
||||||
// pathfinding using A* search algorithm
|
// pathfinding using A* search algorithm
|
||||||
// as described in http://en.wikipedia.org/wiki/A*_search_algorithm
|
// as described in http://en.wikipedia.org/wiki/A*_search_algorithm
|
||||||
|
@ -545,8 +545,6 @@ 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::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> ret;
|
||||||
std::vector<Otc::Direction>& dirs = std::get<0>(ret);
|
std::vector<Otc::Direction>& dirs = std::get<0>(ret);
|
||||||
Otc::PathFindResult& result = std::get<1>(ret);
|
Otc::PathFindResult& result = std::get<1>(ret);
|
||||||
|
@ -563,11 +561,6 @@ std::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> Map::findPath(const
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(startPos.distance(goalPos) > maxSteps) {
|
|
||||||
result = Otc::PathFindResultTooFar;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unordered_map<Position, Node*, PositionHasher> nodes;
|
std::unordered_map<Position, Node*, PositionHasher> nodes;
|
||||||
std::priority_queue<Node*, std::vector<Node*>, LessNode> searchList;
|
std::priority_queue<Node*, std::vector<Node*>, LessNode> searchList;
|
||||||
|
|
||||||
|
@ -576,13 +569,7 @@ std::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> Map::findPath(const
|
||||||
nodes[startPos] = currentNode;
|
nodes[startPos] = currentNode;
|
||||||
Node *foundNode = nullptr;
|
Node *foundNode = nullptr;
|
||||||
while(currentNode) {
|
while(currentNode) {
|
||||||
// too far
|
if((int)nodes.size() > maxComplexity) {
|
||||||
if(currentNode->steps >= maxSteps) {
|
|
||||||
result = Otc::PathFindResultTooFar;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(nodes.size() > MAX_COMPLEXITY) {
|
|
||||||
result = Otc::PathFindResultTooFar;
|
result = Otc::PathFindResultTooFar;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -209,7 +209,7 @@ public:
|
||||||
std::vector<AnimatedTextPtr> getAnimatedTexts() { return m_animatedTexts; }
|
std::vector<AnimatedTextPtr> getAnimatedTexts() { return m_animatedTexts; }
|
||||||
std::vector<StaticTextPtr> getStaticTexts() { return m_staticTexts; }
|
std::vector<StaticTextPtr> getStaticTexts() { return m_staticTexts; }
|
||||||
|
|
||||||
std::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> findPath(const Position& start, const Position& goal, int maxSteps, int flags = 0);
|
std::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> findPath(const Position& start, const Position& goal, int maxComplexity, int flags = 0);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void removeUnawareThings();
|
void removeUnawareThings();
|
||||||
|
|
|
@ -42,7 +42,7 @@ enum MinimapTileFlags {
|
||||||
#pragma pack(push,1) // disable memory alignment
|
#pragma pack(push,1) // disable memory alignment
|
||||||
struct MinimapTile
|
struct MinimapTile
|
||||||
{
|
{
|
||||||
MinimapTile() : flags(0), color(0), speed(100) { }
|
MinimapTile() : flags(0), color(0), speed(10) { }
|
||||||
uint8 flags;
|
uint8 flags;
|
||||||
uint8 color;
|
uint8 color;
|
||||||
uint8 speed;
|
uint8 speed;
|
||||||
|
|
Loading…
Reference in New Issue