diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-03-29 01:26:56 +0200 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-03-29 01:26:56 +0200 |
commit | 15c69030f987bd7d67fdbaf2158b2c3ae430143f (patch) | |
tree | a8ec211017aad38cd9784c1c837cada34eab3dfe /src/net/tmwa | |
parent | ce94f62be91c98310281b33dbc7f4b79fd4e8052 (diff) | |
download | mana-15c69030f987bd7d67fdbaf2158b2c3ae430143f.tar.gz mana-15c69030f987bd7d67fdbaf2158b2c3ae430143f.tar.bz2 mana-15c69030f987bd7d67fdbaf2158b2c3ae430143f.tar.xz mana-15c69030f987bd7d67fdbaf2158b2c3ae430143f.zip |
Added the Map::getTileCenter() convenience function.
and made use of it through the tA code.
I also remove the obsolete TODO in the flooritem class.
Diffstat (limited to 'src/net/tmwa')
-rw-r--r-- | src/net/tmwa/beinghandler.cpp | 41 | ||||
-rw-r--r-- | src/net/tmwa/playerhandler.cpp | 9 |
2 files changed, 19 insertions, 31 deletions
diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp index d61559f8..960f08ed 100644 --- a/src/net/tmwa/beinghandler.cpp +++ b/src/net/tmwa/beinghandler.cpp @@ -101,18 +101,15 @@ Being *createBeing(int id, short job) return being; } -static void handleMoveMessage(Uint16 srcX, Uint16 srcY, - Uint16 dstX, Uint16 dstY, - Being *dstBeing, int tileWidth, int tileHeight) +static void handleMoveMessage(Map *map, Being *dstBeing, + Uint16 srcX, Uint16 srcY, + Uint16 dstX, Uint16 dstY) { // Avoid dealing with flawed destination - if (srcX && srcY && dstX && dstY) + if (map && dstBeing && srcX && srcY && dstX && dstY) { - Vector pos(srcX * tileWidth + tileWidth / 2, - srcY * tileHeight + tileHeight / 2); - - Vector dest(dstX * tileWidth + tileWidth / 2, - dstY * tileHeight + tileHeight / 2); + Vector pos = map->getTileCenter(srcX, srcY); + Vector dest = map->getTileCenter(dstX, dstY); // Don't set the position as the movement algorithm // can guess it and it would break the animation played, @@ -125,14 +122,13 @@ static void handleMoveMessage(Uint16 srcX, Uint16 srcY, } } -static void handlePosMessage(Uint16 x, Uint16 y, Being *dstBeing, - int tileWidth, int tileHeight, Uint8 dir = 0) +static void handlePosMessage(Map *map, Being *dstBeing, Uint16 x, Uint16 y, + Uint8 dir = 0) { // Avoid dealing with flawed destination - if (x && y) + if (map && dstBeing && x && y) { - Vector pos(x * tileWidth + tileWidth / 2, - y * tileHeight + tileHeight / 2); + Vector pos = map->getTileCenter(x, y); Vector beingPos = dstBeing->getPosition(); // Don't set the position as the movement algorithm // can guess it and it would break the animation played, @@ -171,8 +167,6 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) // Prepare useful translation variables Map *map = Game::instance()->getCurrentMap(); - int tileWidth = map->getTileWidth(); - int tileHeight = map->getTileHeight(); switch (msg.getId()) { @@ -264,15 +258,14 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) { Uint16 srcX, srcY, dstX, dstY; msg.readCoordinatePair(srcX, srcY, dstX, dstY); - handleMoveMessage(srcX, srcY, dstX, dstY, dstBeing, - tileWidth, tileHeight); + handleMoveMessage(map, dstBeing, srcX, srcY, dstX, dstY); } else { Uint8 dir; Uint16 x, y; msg.readCoordinates(x, y, dir); - handlePosMessage(x, y, dstBeing, tileWidth, tileHeight, dir); + handlePosMessage(map, dstBeing, x, y, dir); } msg.readInt8(); // unknown @@ -312,8 +305,7 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) Uint16 srcX, srcY, dstX, dstY; msg.readCoordinatePair(srcX, srcY, dstX, dstY); msg.readInt32(); // Server tick - handleMoveMessage(srcX, srcY, dstX, dstY, dstBeing, - tileWidth, tileHeight); + handleMoveMessage(map, dstBeing, srcX, srcY, dstX, dstY); } break; @@ -624,15 +616,14 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) { Uint16 srcX, srcY, dstX, dstY; msg.readCoordinatePair(srcX, srcY, dstX, dstY); - handleMoveMessage(srcX, srcY, dstX, dstY, dstBeing, - tileWidth, tileHeight); + handleMoveMessage(map, dstBeing, srcX, srcY, dstX, dstY); } else { Uint8 dir; Uint16 x, y; msg.readCoordinates(x, y, dir); - handlePosMessage(x, y, dstBeing, tileWidth, tileHeight, dir); + handlePosMessage(map, dstBeing, x, y, dir); } gmstatus = msg.readInt16(); @@ -687,7 +678,7 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) Uint16 x, y; x = msg.readInt16(); y = msg.readInt16(); - handlePosMessage(x, y, dstBeing, tileWidth, tileHeight); + handlePosMessage(map, dstBeing, x, y); } } break; diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp index 9d97dc73..f7a211d1 100644 --- a/src/net/tmwa/playerhandler.cpp +++ b/src/net/tmwa/playerhandler.cpp @@ -202,21 +202,18 @@ void PlayerHandler::handleMessage(Net::MessageIn &msg) /* Scroll if necessary */ Map *map = game->getCurrentMap(); - int tileWidth = map->getTileWidth(); - int tileHeight = map->getTileHeight(); int tileX = player_node->getTileX(); int tileY = player_node->getTileY(); if (!sameMap || (abs(x - tileX) > MAP_TELEPORT_SCROLL_DISTANCE) || (abs(y - tileY) > MAP_TELEPORT_SCROLL_DISTANCE)) { - scrollOffsetX = (x - tileX) * tileWidth; - scrollOffsetY = (y - tileY) * tileHeight; + scrollOffsetX = (x - tileX) * map->getTileWidth(); + scrollOffsetY = (y - tileY) * map->getTileHeight(); } player_node->setAction(Being::STAND); - Vector pos(x * tileWidth + tileWidth / 2, - y * tileHeight + tileHeight / 2); + Vector pos = map->getTileCenter(x, y); player_node->setPosition(pos); // Stop movement player_node->setDestination(pos.x, pos.y); |