diff options
-rw-r--r-- | src/net/manaserv/beinghandler.cpp | 34 | ||||
-rw-r--r-- | src/net/manaserv/manaserv_protocol.h | 2 |
2 files changed, 26 insertions, 10 deletions
diff --git a/src/net/manaserv/beinghandler.cpp b/src/net/manaserv/beinghandler.cpp index 6e9b3645..414f914d 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() @@ -217,20 +219,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) { /* @@ -241,18 +250,25 @@ void BeingHandler::handleBeingsMoveMessage(Net::MessageIn &msg) * with the Being::logic() function calls * @see MILLISECONDS_IN_A_TICK */ - being->setWalkSpeed( - giveSpeedInPixelsPerTicks((float) speed / 10)); + being->setWalkSpeed(giveSpeedInPixelsPerTicks((float) speed / 10)); } // Ignore messages from the server for the local player 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); } } diff --git a/src/net/manaserv/manaserv_protocol.h b/src/net/manaserv/manaserv_protocol.h index 5726ab92..b5023a42 100644 --- a/src/net/manaserv/manaserv_protocol.h +++ b/src/net/manaserv/manaserv_protocol.h @@ -118,7 +118,7 @@ enum { PGMSG_DIRECTION_CHANGE = 0x0272, // B Direction GPMSG_BEING_DIR_CHANGE = 0x0273, // W being id, B direction GPMSG_BEING_HEALTH_CHANGE = 0x0274, // W being id, W hp, W max hp - GPMSG_BEINGS_MOVE = 0x0280, // { W being id, B flags [, W*2 position, B speed] }* + GPMSG_BEINGS_MOVE = 0x0280, // { W being id, B flags [, [W*2 position,] W*2 destination, B speed] }* GPMSG_ITEMS = 0x0281, // { W item id, W*2 position }* PGMSG_ATTACK = 0x0290, // W being id GPMSG_BEING_ATTACK = 0x0291, // W being id, B direction, B attacktype |