diff options
Diffstat (limited to 'src/net/manaserv/beinghandler.cpp')
-rw-r--r-- | src/net/manaserv/beinghandler.cpp | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/src/net/manaserv/beinghandler.cpp b/src/net/manaserv/beinghandler.cpp index 220ecfba..f8cefecf 100644 --- a/src/net/manaserv/beinghandler.cpp +++ b/src/net/manaserv/beinghandler.cpp @@ -40,6 +40,8 @@ #include "utils/gettext.h" +#define POSITION_DIFF_TOLERANCE 48 + namespace ManaServ { BeingHandler::BeingHandler() @@ -186,20 +188,27 @@ void BeingHandler::handleBeingsMoveMessage(Net::MessageIn &msg) int id = msg.readInt16(); int flags = msg.readInt8(); Being *being = actorSpriteManager->findBeing(id); - int sx = 0; - int sy = 0; - int speed = 0; + int sx, sy, dx, dy, speed = 0; + + if ((!flags & (MOVING_POSITION | MOVING_DESTINATION))) + continue; if (flags & MOVING_POSITION) { sx = msg.readInt16(); sy = msg.readInt16(); - speed = msg.readInt8(); } - if (!being || !(flags & (MOVING_POSITION | MOVING_DESTINATION))) + + if (flags & MOVING_DESTINATION) { - continue; + dx = msg.readInt16(); + dy = msg.readInt16(); + speed = msg.readInt8(); } + + if (!being) + continue; + if (speed) { /* @@ -216,10 +225,18 @@ void BeingHandler::handleBeingsMoveMessage(Net::MessageIn &msg) if (being == player_node) continue; + // If the position differs too much from the actual one, we resync + // the being position if (flags & MOVING_POSITION) { - being->setDestination(sx, sy); + Vector serverPos(sx, sy); + if (serverPos.length() + - being->getPosition().length() > POSITION_DIFF_TOLERANCE) + being->setPosition(serverPos); } + + if (flags & MOVING_DESTINATION) + being->setDestination(dx, dy); } } |