diff --git a/src/client/localplayer.cpp b/src/client/localplayer.cpp index cb9688f8..15342cab 100644 --- a/src/client/localplayer.cpp +++ b/src/client/localplayer.cpp @@ -178,6 +178,12 @@ void LocalPlayer::cancelWalk(Otc::Direction direction) bool LocalPlayer::autoWalk(const Position& destination) { + bool tryKnownPath = false; + if(destination != m_autoWalkDestination) { + m_knownCompletePath = false; + tryKnownPath = true; + } + std::tuple, Otc::PathFindResult> result; std::vector limitedPath; @@ -185,15 +191,20 @@ bool LocalPlayer::autoWalk(const Position& destination) return true; // try to find a path that we know - result = g_map.findPath(m_position, destination, 1000, 0); - if(std::get<1>(result) == Otc::PathFindResultOk) { - limitedPath = std::get<0>(result); - // limit to 127 steps - if(limitedPath.size() > 127) - limitedPath.resize(127); - } else { - // no known path found, try to discover one - result = g_map.findPath(m_position, destination, 1000, Otc::PathFindAllowNotSeenTiles); + if(tryKnownPath || m_knownCompletePath) { + result = g_map.findPath(m_position, destination, 50000, 0); + if(std::get<1>(result) == Otc::PathFindResultOk) { + limitedPath = std::get<0>(result); + // limit to 127 steps + if(limitedPath.size() > 127) + limitedPath.resize(127); + m_knownCompletePath = true; + } + } + + // 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) { callLuaField("onAutoWalkFail", std::get<1>(result)); return false; @@ -228,6 +239,7 @@ void LocalPlayer::stopAutoWalk() { m_autoWalkDestination = Position(); m_lastAutoWalkPosition = Position(); + m_knownCompletePath = false; if(m_autoWalkContinueEvent) m_autoWalkContinueEvent->cancel(); diff --git a/src/client/localplayer.h b/src/client/localplayer.h index bd1c6919..10837252 100644 --- a/src/client/localplayer.h +++ b/src/client/localplayer.h @@ -130,6 +130,7 @@ private: stdext::boolean m_lastPrewalkDone; stdext::boolean m_autoWalking; stdext::boolean m_waitingWalkPong; + stdext::boolean m_knownCompletePath; stdext::boolean m_premium; stdext::boolean m_known; diff --git a/src/client/map.cpp b/src/client/map.cpp index 772f394f..533b6677 100644 --- a/src/client/map.cpp +++ b/src/client/map.cpp @@ -522,7 +522,7 @@ int Map::getLastAwareFloor() return Otc::SEA_FLOOR; } -std::tuple, Otc::PathFindResult> Map::findPath(const Position& startPos, const Position& goalPos, int maxSteps, int flags) +std::tuple, Otc::PathFindResult> Map::findPath(const Position& startPos, const Position& goalPos, int maxComplexity, int flags) { // pathfinding using A* search algorithm // as described in http://en.wikipedia.org/wiki/A*_search_algorithm @@ -545,8 +545,6 @@ std::tuple, Otc::PathFindResult> Map::findPath(const } }; - const uint MAX_COMPLEXITY = 100000; - std::tuple, Otc::PathFindResult> ret; std::vector& dirs = std::get<0>(ret); Otc::PathFindResult& result = std::get<1>(ret); @@ -563,11 +561,6 @@ std::tuple, Otc::PathFindResult> Map::findPath(const return ret; } - if(startPos.distance(goalPos) > maxSteps) { - result = Otc::PathFindResultTooFar; - return ret; - } - std::unordered_map nodes; std::priority_queue, LessNode> searchList; @@ -576,13 +569,7 @@ std::tuple, Otc::PathFindResult> Map::findPath(const nodes[startPos] = currentNode; Node *foundNode = nullptr; while(currentNode) { - // too far - if(currentNode->steps >= maxSteps) { - result = Otc::PathFindResultTooFar; - break; - } - - if(nodes.size() > MAX_COMPLEXITY) { + if((int)nodes.size() > maxComplexity) { result = Otc::PathFindResultTooFar; break; } diff --git a/src/client/map.h b/src/client/map.h index 82dc3c52..1930a392 100644 --- a/src/client/map.h +++ b/src/client/map.h @@ -209,7 +209,7 @@ public: std::vector getAnimatedTexts() { return m_animatedTexts; } std::vector getStaticTexts() { return m_staticTexts; } - std::tuple, Otc::PathFindResult> findPath(const Position& start, const Position& goal, int maxSteps, int flags = 0); + std::tuple, Otc::PathFindResult> findPath(const Position& start, const Position& goal, int maxComplexity, int flags = 0); private: void removeUnawareThings(); diff --git a/src/client/minimap.h b/src/client/minimap.h index 5f8aeb2e..a11210e0 100644 --- a/src/client/minimap.h +++ b/src/client/minimap.h @@ -42,7 +42,7 @@ enum MinimapTileFlags { #pragma pack(push,1) // disable memory alignment struct MinimapTile { - MinimapTile() : flags(0), color(0), speed(100) { } + MinimapTile() : flags(0), color(0), speed(10) { } uint8 flags; uint8 color; uint8 speed;