diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-03-17 00:02:23 +0100 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-03-17 00:02:23 +0100 |
commit | 452dc7f163749de0b5d698af2f022ca22c1aabb0 (patch) | |
tree | 5a84201f77bb71bc2ee2e1a4adb37220756d32b1 /src/map.cpp | |
parent | 6846acdcf0159423c188b56fc4a5f4c19f123eb7 (diff) | |
download | mana-452dc7f163749de0b5d698af2f022ca22c1aabb0.tar.gz mana-452dc7f163749de0b5d698af2f022ca22c1aabb0.tar.bz2 mana-452dc7f163749de0b5d698af2f022ca22c1aabb0.tar.xz mana-452dc7f163749de0b5d698af2f022ca22c1aabb0.zip |
Now the client centers the pixel positions when using tA.
I made it so that the behaviour can be changed with only
a boolean setting in the playerhandler.
Diffstat (limited to 'src/map.cpp')
-rw-r--r-- | src/map.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/map.cpp b/src/map.cpp index 87c902f6..69793299 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -710,6 +710,40 @@ Position Map::checkNodeOffsets(int radius, unsigned char walkMask, return Position(tx * 32 + fx, ty * 32 + fy); } +Path Map::findTilePath(int startPixelX, int startPixelY, int endPixelX, + int endPixelY, unsigned char walkMask, int maxCost) +{ + Path myPath = findPath(startPixelX / mTileWidth, startPixelY / mTileHeight, + endPixelX / mTileWidth, endPixelY / mTileHeight, + walkMask, maxCost); + + // Don't compute empty coordinates. + if (myPath.empty()) + return myPath; + + // Convert the map path to pixels over tiles + // And add interpolation between the starting and ending offsets + Path::iterator it = myPath.begin(); + while (it != myPath.end()) + { + // A position that is valid on the start and end tile is not + // necessarily valid on all the tiles in between, so check the offsets. + *it = Position(it->x * mTileWidth + mTileWidth / 2, + it->y * mTileHeight + mTileHeight / 2); + it++; + } + + // Remove the last path node, as it's more clever to go to the destination. + // It also permit to avoid zigzag at the end of the path, + // especially with mouse. + Position destination((endPixelX / mTileWidth) * mTileWidth + mTileWidth / 2, + (endPixelY / mTileHeight) * mTileHeight + mTileHeight / 2); + myPath.pop_back(); + myPath.push_back(destination); + + return myPath; +} + Path Map::findPixelPath(int startPixelX, int startPixelY, int endPixelX, int endPixelY, int radius, unsigned char walkMask, int maxCost) |