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 tryKnownPath = false;
|
||||
if(destination != m_autoWalkDestination) {
|
||||
m_knownCompletePath = false;
|
||||
tryKnownPath = true;
|
||||
}
|
||||
|
||||
std::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> result;
|
||||
std::vector<Otc::Direction> 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(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);
|
||||
} else {
|
||||
m_knownCompletePath = true;
|
||||
}
|
||||
}
|
||||
|
||||
// no known path found, try to discover one
|
||||
result = g_map.findPath(m_position, destination, 1000, Otc::PathFindAllowNotSeenTiles);
|
||||
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();
|
||||
|
|
|
@ -130,6 +130,7 @@ private:
|
|||
stdext::boolean<true> m_lastPrewalkDone;
|
||||
stdext::boolean<false> m_autoWalking;
|
||||
stdext::boolean<false> m_waitingWalkPong;
|
||||
stdext::boolean<false> m_knownCompletePath;
|
||||
|
||||
stdext::boolean<false> m_premium;
|
||||
stdext::boolean<false> m_known;
|
||||
|
|
|
@ -522,7 +522,7 @@ int Map::getLastAwareFloor()
|
|||
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
|
||||
// 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::vector<Otc::Direction>& dirs = std::get<0>(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;
|
||||
}
|
||||
|
||||
if(startPos.distance(goalPos) > maxSteps) {
|
||||
result = Otc::PathFindResultTooFar;
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::unordered_map<Position, Node*, PositionHasher> nodes;
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -209,7 +209,7 @@ public:
|
|||
std::vector<AnimatedTextPtr> getAnimatedTexts() { return m_animatedTexts; }
|
||||
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:
|
||||
void removeUnawareThings();
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue