diff options
author | Bertram <bertram@cegetel.net> | 2010-02-23 22:32:18 +0100 |
---|---|---|
committer | Bertram <bertram@cegetel.net> | 2010-02-23 22:32:18 +0100 |
commit | 3adb0710b9b0262b7d7a03aa687e78c232f04d06 (patch) | |
tree | 79577ee68ace01c3614cba57d12522bc0d2f07da /src/localplayer.cpp | |
parent | 55bd286b4bea4445894a576d64f788d53863b499 (diff) | |
download | mana-3adb0710b9b0262b7d7a03aa687e78c232f04d06.tar.gz mana-3adb0710b9b0262b7d7a03aa687e78c232f04d06.tar.bz2 mana-3adb0710b9b0262b7d7a03aa687e78c232f04d06.tar.xz mana-3adb0710b9b0262b7d7a03aa687e78c232f04d06.zip |
Sanitized ManaServ movement protocol, by mainly moving code from LocalPlayer to Being.
This fixes some movement glitches under ManaServ and make the code much cleaner
even if it's not perfect enough yet.
First of all, many checks have been gathered in the Being::setDestination() calls.
Also, now all path nodes including destination are checked against surrounding
tiles to correct the path when necessary.
The LocalPlayer::nextTile() still needs to be reviewed and some checks are missing
but it's almost done :)
Diffstat (limited to 'src/localplayer.cpp')
-rw-r--r-- | src/localplayer.cpp | 60 |
1 files changed, 7 insertions, 53 deletions
diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 6f63d799..d7f64113 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -462,63 +462,17 @@ void LocalPlayer::setTarget(Being *target) void LocalPlayer::setDestination(int x, int y) { - if (Net::getNetworkType() == ServerInfo::MANASERV) - { - // Pre-computing character's destination in tiles - const int tx = x / 32; - const int ty = y / 32; - - // Check the walkability of the destination - // If the destination is a wall, don't go there! - if (!mMap->getWalk(tx, ty)) - return; - - // Pre-computing character's position useful variables. - Vector playerPosition = getPosition(); - const int posX = (int)(playerPosition.x / 32); - const int posY = (int)(playerPosition.y / 32); - const int offsetY = (int)playerPosition.y % 32; - - // check if we're finding a path to the seeked destination - // If the path is empty... and isn't on the same tile, - // then, it's an unvalid one. - if (posX != tx || posY != ty) - { - Path evaluatedPath = mMap->findPath(posX, posY, tx, ty, - getWalkMask()); - if (evaluatedPath.empty()) - return; - } - - // Pre-computing character's destination offsets. - int fx = x % 32; - int fy = y % 32; - - // Fix coordinates so that the player does not seem to dig into walls. - if (fx > 16 && !mMap->getWalk(tx + 1, ty, getWalkMask())) - fx = 16; - else if (fx < 16 && !mMap->getWalk(tx - 1, ty, getWalkMask())) - fx = 16; - else if (fy > 16 && !mMap->getWalk(tx, ty + 1, getWalkMask())) - fy = 16; - else if (fy < 16 && !mMap->getWalk(tx, ty - 1, getWalkMask())) - fy = 16; - - // Test also the current character's position, to avoid the corner case - // where a player can approach an obstacle by walking from slightly - // under, diagonally. First part to the walk on water bug. - if (offsetY < 16 && !mMap->getWalk(posX, posY - 1, getWalkMask())) - fy = 16; - - x = tx * 32 + fx; - y = ty * 32 + fy; - } - // Only send a new message to the server when destination changes if (x != mDest.x || y != mDest.y) { Being::setDestination(x, y); - Net::getPlayerHandler()->setDestination(x, y, mDirection); + + // Manaserv: + // If the destination given to being class is accepted, + // we inform the Server. + if ((x == mDest.x && y == mDest.y) + || Net::getNetworkType() == ServerInfo::EATHENA) + Net::getPlayerHandler()->setDestination(x, y, mDirection); } mPickUpTarget = NULL; |