diff options
author | Chuck Miller <shadowmil@gmail.com> | 2009-07-27 19:32:32 -0400 |
---|---|---|
committer | Chuck Miller <shadowmil@gmail.com> | 2009-07-27 19:33:40 -0400 |
commit | 5a27795be5450add2cf3da3c03b2fe8771325e3e (patch) | |
tree | daedd1beba82a87966317b81c92f9662caae2dda | |
parent | 99648c2c8693de68ebe0449e139413864e5dd6f1 (diff) | |
download | mana-client-5a27795be5450add2cf3da3c03b2fe8771325e3e.tar.gz mana-client-5a27795be5450add2cf3da3c03b2fe8771325e3e.tar.bz2 mana-client-5a27795be5450add2cf3da3c03b2fe8771325e3e.tar.xz mana-client-5a27795be5450add2cf3da3c03b2fe8771325e3e.zip |
Makes mX and mY in the being class private
-rw-r--r-- | src/being.h | 17 | ||||
-rw-r--r-- | src/beingmanager.cpp | 13 | ||||
-rw-r--r-- | src/game.cpp | 10 | ||||
-rw-r--r-- | src/gui/viewport.cpp | 10 | ||||
-rw-r--r-- | src/localplayer.cpp | 31 | ||||
-rw-r--r-- | src/map.cpp | 2 | ||||
-rw-r--r-- | src/net/ea/beinghandler.cpp | 23 | ||||
-rw-r--r-- | src/net/ea/maphandler.cpp | 9 | ||||
-rw-r--r-- | src/net/ea/playerhandler.cpp | 11 |
9 files changed, 58 insertions, 68 deletions
diff --git a/src/being.h b/src/being.h index 9213a2dc..e16e464d 100644 --- a/src/being.h +++ b/src/being.h @@ -149,7 +149,6 @@ class Being : public Sprite, public ConfigListener enum { DOWN = 1, LEFT = 2, UP = 4, RIGHT = 8 }; #ifdef EATHENA_SUPPORT - Uint16 mX, mY; /**< Tile coordinates */ int mFrame; int mWalkTime; #endif @@ -210,6 +209,21 @@ class Being : public Sprite, public ConfigListener #endif /** + * Returns the tile x or y coord + */ + int getTileX() const + { return mX; } + + int getTileY() const + { return mY; } + + /** + * Sets the tile x or y coord + */ + void setTileCoords(int x, int y) + { mX = x; mY = y; } + + /** * Puts a "speech balloon" above this being for the specified amount * of time. * @@ -603,6 +617,7 @@ class Being : public Sprite, public ConfigListener Vector mPos; Vector mDest; int mPx, mPy; /**< Position in pixels */ + int mX, mY; /**< Position on tile */ /** Target cursor being used */ SimpleAnimation* mUsedTargetCursor; diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index 284f1343..0b8f71b5 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -40,14 +40,9 @@ class FindBeingFunctor bool operator() (Being *being) { Uint16 other_y = y + ((being->getType() == Being::NPC) ? 1 : 0); -#ifdef TMWSERV_SUPPORT const Vector &pos = being->getPosition(); return ((int) pos.x / 32 == x && ((int) pos.y / 32 == y || (int) pos.y / 32 == other_y) && -#else - return (being->mX == x && - (being->mY == y || being->mY == other_y) && -#endif being->mAction != Being::DEAD && (type == Being::UNKNOWN || being->getType() == type)); } @@ -242,7 +237,7 @@ Being *BeingManager::findNearestLivingBeing(int x, int y, int maxdist, const Vector &pos = being->getPosition(); int d = abs(((int) pos.x) - x) + abs(((int) pos.y) - y); #else - int d = abs(being->mX - x) + abs(being->mY - y); + int d = abs(being->getTileX() - x) + abs(being->getTileY() - y); #endif if ((being->getType() == type || type == Being::UNKNOWN) @@ -268,8 +263,8 @@ Being *BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxdist, int y = apos.y; maxdist = maxdist * 32; #else - int x = aroundBeing->mX; - int y = aroundBeing->mY; + int x = aroundBeing->getTileX(); + int y = aroundBeing->getTileY(); #endif for (Beings::const_iterator i = mBeings.begin(), i_end = mBeings.end(); @@ -280,7 +275,7 @@ Being *BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxdist, const Vector &pos = being->getPosition(); int d = abs(((int) pos.x) - x) + abs(((int) pos.y) - y); #else - int d = abs(being->mX - x) + abs(being->mY - y); + int d = abs(being->getTileX() - x) + abs(being->getTileY() - y); #endif if ((being->getType() == type || type == Being::UNKNOWN) diff --git a/src/game.cpp b/src/game.cpp index e35e707c..abb74b2a 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -759,14 +759,9 @@ void Game::handleInput() { case KeyboardConfig::KEY_PICKUP: { -#ifdef TMWSERV_SUPPORT const Vector &pos = player_node->getPosition(); Uint16 x = (int) pos.x / 32; Uint16 y = (int) pos.y / 32; -#else - Uint16 x = player_node->mX; - Uint16 y = player_node->mY; -#endif FloorItem *item = floorItemManager->findByCoordinates(x, y); @@ -938,14 +933,9 @@ void Game::handleInput() return; } -#ifdef TMWSERV_SUPPORT const Vector &pos = player_node->getPosition(); const Uint16 x = (int) pos.x / 32; const Uint16 y = (int) pos.y / 32; -#else - const Uint16 x = player_node->mX; - const Uint16 y = player_node->mY; -#endif unsigned char direction = 0; // Translate pressed keys to movement and direction diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 68b5fed3..9a631581 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -116,22 +116,12 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) } // Calculate viewpoint -#ifdef TMWSERV_SUPPORT int midTileX = (graphics->getWidth() + mScrollCenterOffsetX) / 2; int midTileY = (graphics->getHeight() + mScrollCenterOffsetX) / 2; const Vector &playerPos = player_node->getPosition(); const int player_x = (int) playerPos.x - midTileX; const int player_y = (int) playerPos.y - midTileY; -#else - int midTileX = (graphics->getWidth() + mScrollCenterOffsetX) / 32 / 2; - int midTileY = (graphics->getHeight() + mScrollCenterOffsetY) / 32 / 2; - - int player_x = (player_node->mX - midTileX) * 32 + - player_node->getXOffset(); - int player_y = (player_node->mY - midTileY) * 32 + - player_node->getYOffset(); -#endif if (mScrollLaziness < 1) mScrollLaziness = 1; // Avoids division by zero diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 34ab5246..4e9257ca 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -197,8 +197,8 @@ void LocalPlayer::logic() const int rangeY = abs(mTarget->getPosition().y - getPosition().y); #else // Find whether target is in range - const int rangeX = abs(mTarget->mX - mX); - const int rangeY = abs(mTarget->mY - mY); + const int rangeX = abs(mTarget->getTileX() - getTileX()); + const int rangeY = abs(mTarget->getTileY() - getTileY()); #endif const int attackRange = getAttackRange(); const int inRange = rangeX > attackRange || rangeY > attackRange @@ -331,13 +331,8 @@ void LocalPlayer::setInvItem(int index, int id, int amount) void LocalPlayer::pickUp(FloorItem *item) { -#ifdef TMWSERV_SUPPORT int dx = item->getX() - (int) getPosition().x / 32; int dy = item->getY() - (int) getPosition().y / 32; -#else - int dx = item->getX() - mX; - int dy = item->getY() - mY; -#endif if (dx * dx + dy * dy < 4) { @@ -374,7 +369,7 @@ void LocalPlayer::walk(unsigned char dir) #ifdef TMWSERV_SUPPORT Being::setDestination(pos.x, pos.y); #else - Being::setDestination(mX, mY); + Being::setDestination(getTileX(), getTileY()); #endif return; } @@ -409,9 +404,9 @@ void LocalPlayer::walk(unsigned char dir) ((int) pos.y + dy) / 32, getWalkMask())) dy = 16 - (int) pos.y % 32; #else - if (dx && !mMap->getWalk(mX + dx, mY, getWalkMask())) + if (dx && !mMap->getWalk(getTileX() + dx, getTileY(), getWalkMask())) dx = 0; - if (dy && !mMap->getWalk(mX, mY + dy, getWalkMask())) + if (dy && !mMap->getWalk(getTileX(), getTileY() + dy, getWalkMask())) dy = 0; #endif @@ -441,13 +436,13 @@ void LocalPlayer::walk(unsigned char dir) setDestination((int) pos.x + (dx * dScaler), (int) pos.y + (dy * dScaler)); } #else - if (dx && dy && !mMap->getWalk(mX + dx, mY + dy, getWalkMask())) + if (dx && dy && !mMap->getWalk(getTileX() + dx, getTileY() + dy, getWalkMask())) dx = 0; // Walk to where the player can actually go - if ((dx || dy) && mMap->getWalk(mX + dx, mY + dy, getWalkMask())) + if ((dx || dy) && mMap->getWalk(getTileX() + dx, getTileY() + dy, getWalkMask())) { - setDestination(mX + dx, mY + dy); + setDestination(getTileX() + dx, getTileY() + dy); } #endif else if (dir) @@ -682,8 +677,8 @@ void LocalPlayer::attack(Being *target, bool keep) int dist_x = plaPos.x - tarPos.x; int dist_y = plaPos.y - tarPos.y; #else - int dist_x = target->mX - mX; - int dist_y = target->mY - mY; + int dist_x = target->getTileX() - getTileX(); + int dist_y = target->getTileY() - getTileY(); // Must be standing to attack if (mAction != STAND) @@ -984,8 +979,8 @@ bool LocalPlayer::withinAttackRange(Being *target) return !(dx > range || dy > range); #else - int dist_x = abs(target->mX - mX); - int dist_y = abs(target->mY - mY); + int dist_x = abs(target->getTileX() - getTileY()); + int dist_y = abs(target->getTileY() - getTileX()); if (dist_x > getAttackRange() || dist_y > getAttackRange()) { @@ -1007,7 +1002,7 @@ void LocalPlayer::setGotoTarget(Being *target) #else setTarget(target); mGoingToTarget = true; - setDestination(target->mX, target->mY); + setDestination(target->getTileX(), target->getTileY()); #endif } diff --git a/src/map.cpp b/src/map.cpp index 38c49112..81bf7313 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -449,7 +449,7 @@ bool Map::occupied(int x, int y) const const Being *being = *i; // job 45 is a portal, they don't collide - if (being->mX == x && being->mY == y && being->mJob != 45) + if (being->getTileX() == x && being->getTileY() == y && being->mJob != 45) return true; } diff --git a/src/net/ea/beinghandler.cpp b/src/net/ea/beinghandler.cpp index f149f15f..1d780a60 100644 --- a/src/net/ea/beinghandler.cpp +++ b/src/net/ea/beinghandler.cpp @@ -194,14 +194,15 @@ void BeingHandler::handleMessage(MessageIn &msg) Uint16 srcX, srcY, dstX, dstY; msg.readCoordinatePair(srcX, srcY, dstX, dstY); dstBeing->setAction(Being::STAND); - dstBeing->mX = srcX; - dstBeing->mY = srcY; + dstBeing->setTileCoords(srcX, srcY); dstBeing->setDestination(dstX, dstY); } else { Uint8 dir; - msg.readCoordinates(dstBeing->mX, dstBeing->mY, dir); + Uint16 x, y; + msg.readCoordinates(x, y, dir); + dstBeing->setTileCoords(x, y); dstBeing->setDirection(dir); } @@ -234,8 +235,7 @@ void BeingHandler::handleMessage(MessageIn &msg) if (dstBeing) { dstBeing->setAction(Being::STAND); - dstBeing->mX = srcX; - dstBeing->mY = srcY; + dstBeing->setTileCoords(srcX, srcY); dstBeing->setDestination(dstX, dstY); } @@ -515,14 +515,15 @@ void BeingHandler::handleMessage(MessageIn &msg) { Uint16 srcX, srcY, dstX, dstY; msg.readCoordinatePair(srcX, srcY, dstX, dstY); - dstBeing->mX = srcX; - dstBeing->mY = srcY; + dstBeing->setTileCoords(srcX, srcY); dstBeing->setDestination(dstX, dstY); } else { Uint8 dir; - msg.readCoordinates(dstBeing->mX, dstBeing->mY, dir); + Uint16 x, y; + msg.readCoordinates(x, y, dir); + dstBeing->setTileCoords(x, y); dstBeing->setDirection(dir); } @@ -577,8 +578,10 @@ void BeingHandler::handleMessage(MessageIn &msg) if (mSync || id != player_node->getId()) { dstBeing = beingManager->findBeing(id); if (dstBeing) { - dstBeing->mX = msg.readInt16(); - dstBeing->mY = msg.readInt16(); + Uint16 x, y; + x = msg.readInt16(); + y = msg.readInt16(); + dstBeing->setTileCoords(x, y); if (dstBeing->mAction == Being::WALK) { dstBeing->mFrame = 0; dstBeing->setAction(Being::STAND); diff --git a/src/net/ea/maphandler.cpp b/src/net/ea/maphandler.cpp index a466e022..3036612e 100644 --- a/src/net/ea/maphandler.cpp +++ b/src/net/ea/maphandler.cpp @@ -61,14 +61,17 @@ void MapHandler::handleMessage(MessageIn &msg) switch (msg.getId()) { case SMSG_MAP_LOGIN_SUCCESS: + { + Uint16 x, y; msg.readInt32(); // server tick - msg.readCoordinates(player_node->mX, player_node->mY, direction); + msg.readCoordinates(x, y, direction); msg.skip(2); // unknown logger->log("Protocol: Player start position: (%d, %d), Direction: %d", - player_node->mX, player_node->mY, direction); + x, y, direction); state = STATE_GAME; + player_node->setTileCoords(x, y); game = new Game; - break; + } break; case SMSG_SERVER_PING: // We ignore this for now diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp index 3bc11b83..edd58562 100644 --- a/src/net/ea/playerhandler.cpp +++ b/src/net/ea/playerhandler.cpp @@ -200,17 +200,16 @@ void PlayerHandler::handleMessage(MessageIn &msg) /* Scroll if neccessary */ if (!nearby - || (abs(x - player_node->mX) > MAP_TELEPORT_SCROLL_DISTANCE) - || (abs(y - player_node->mY) > MAP_TELEPORT_SCROLL_DISTANCE)) + || (abs(x - player_node->getTileX()) > MAP_TELEPORT_SCROLL_DISTANCE) + || (abs(y - player_node->getTileY()) > MAP_TELEPORT_SCROLL_DISTANCE)) { - scrollOffsetX = (x - player_node->mX) * 32; - scrollOffsetY = (y - player_node->mY) * 32; + scrollOffsetX = (x - player_node->getTileX()) * 32; + scrollOffsetY = (y - player_node->getTileY()) * 32; } player_node->setAction(Being::STAND); player_node->mFrame = 0; - player_node->mX = x; - player_node->mY = y; + player_node->setTileCoords(x, y); logger->log("Adjust scrolling by %d:%d", (int) scrollOffsetX, (int) scrollOffsetY); |