diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-09-22 20:48:08 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-09-22 20:48:48 +0300 |
commit | b4e651126059375044bd9ff45a1bbb225a1cfe44 (patch) | |
tree | 9758300532eb7d8266c069e6f1a201ef456f5baf /src | |
parent | a3e0ab99334d7c2d33a0bf206b711eff420a86c4 (diff) | |
download | manaplus-b4e651126059375044bd9ff45a1bbb225a1cfe44.tar.gz manaplus-b4e651126059375044bd9ff45a1bbb225a1cfe44.tar.bz2 manaplus-b4e651126059375044bd9ff45a1bbb225a1cfe44.tar.xz manaplus-b4e651126059375044bd9ff45a1bbb225a1cfe44.zip |
Remove getters for x,y player position in local player class.
Diffstat (limited to 'src')
-rw-r--r-- | src/localplayer.cpp | 170 |
1 files changed, 87 insertions, 83 deletions
diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 5aea98fbb..20d4094d6 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -219,7 +219,7 @@ LocalPlayer::~LocalPlayer() void LocalPlayer::logic() { if (mumbleManager) - mumbleManager->setPos(getTileX(), getTileY(), getDirection()); + mumbleManager->setPos(mX, mY, mDirection); // Actions are allowed once per second if (get_elapsed_time(mLastAction) >= 1000) @@ -236,14 +236,14 @@ void LocalPlayer::logic() dist = 20; if ((mNavigateX || mNavigateY) && - ((mCrossX + dist >= getTileX() && mCrossX <= getTileX() + dist - && mCrossY + dist >= getTileY() && mCrossY <= getTileY() + dist) + ((mCrossX + dist >= mX && mCrossX <= mX + dist + && mCrossY + dist >= mY && mCrossY <= mY + dist) || (!mCrossX && !mCrossY))) { for (Path::const_iterator i = mNavigatePath.begin(), i_end = mNavigatePath.end(); i != i_end; ++i) { - if ((*i).x == getTileX() && (*i).y == getTileY()) + if ((*i).x == mX && (*i).y == mY) { mNavigatePath.pop_front(); break; @@ -813,8 +813,8 @@ void LocalPlayer::nextTile(unsigned char dir A_UNUSED = 0) PartyMember *pm = Party::getParty(1)->getMember(getName()); if (pm) { - pm->setX(getTileX()); - pm->setY(getTileY()); + pm->setX(mX); + pm->setY(mY); } } @@ -925,8 +925,8 @@ bool LocalPlayer::pickUp(FloorItem *item) if (!Client::limitPackets(PACKET_PICKUP)) return false; - int dx = item->getTileX() - getTileX(); - int dy = item->getTileY() - getTileY(); + int dx = item->getTileX() - mX; + int dy = item->getTileY() - mY; int dist = 6; if (mPickUpType >= 4 && mPickUpType <= 6) @@ -1148,7 +1148,7 @@ void LocalPlayer::startWalking(unsigned char dir) else #endif { - Being::setDestination(getTileX(), getTileY()); + Being::setDestination(mX, mY); } return; } @@ -1324,8 +1324,8 @@ void LocalPlayer::attack(Being *target, bool keep, bool dontChangeEquipment) else #endif { - int dist_x = target->getTileX() - getTileX(); - int dist_y = target->getTileY() - getTileY(); + int dist_x = target->getTileX() - mX; + int dist_y = target->getTileY() - mY; // Must be standing or sitting to attack if (mAction != STAND && mAction != SIT) @@ -1516,8 +1516,8 @@ bool LocalPlayer::withinAttackRange(Being *target, bool fixDistance, else #endif { - dx = static_cast<int>(abs(target->getTileX() - getTileX())); - dy = static_cast<int>(abs(target->getTileY() - getTileY())); + dx = static_cast<int>(abs(target->getTileX() - mX)); + dy = static_cast<int>(abs(target->getTileY() - mY)); } return !(dx > range || dy > range); } @@ -1712,7 +1712,7 @@ void LocalPlayer::moveTo(int x, int y) void LocalPlayer::move(int dX, int dY) { mPickUpTarget = 0; - moveTo(getTileX() + dX, getTileY() + dY); + moveTo(mX + dX, mY + dY); } void LocalPlayer::moveToTarget(unsigned int dist) @@ -1811,7 +1811,7 @@ void LocalPlayer::moveToTarget(unsigned int dist) void LocalPlayer::moveToHome() { mPickUpTarget = 0; - if ((getTileX() != mCrossX || getTileY() != mCrossY) && mCrossX && mCrossY) + if ((mX != mCrossX || mY != mCrossY) && mCrossX && mCrossY) { moveTo(mCrossX, mCrossY); } @@ -1823,7 +1823,7 @@ void LocalPlayer::moveToHome() if (iter != mHomes.end()) { Vector pos = mHomes[(*iter).first]; - if (getTileX() == pos.x && getTileY() == pos.y) + if (mX == pos.x && mY == pos.y) { Net::getPlayerHandler()->setDestination( static_cast<int>(pos.x), @@ -1922,8 +1922,8 @@ void LocalPlayer::changeEquipmentBeforeAttack(Being* target) return; bool allowSword = false; - int dx = target->getTileX() - getTileX(); - int dy = target->getTileY() - getTileY(); + int dx = target->getTileX() - mX; + int dy = target->getTileY() - mY; Item *item = NULL; if (dx * dx + dy * dy > 80) @@ -2039,25 +2039,25 @@ void LocalPlayer::crazyMove1() if (!Client::limitPackets(PACKET_DIRECTION)) return; - if (getDirection() == Being::UP) + if (mDirection == Being::UP) { setWalkingDir(Being::UP); setDirection(Being::LEFT); Net::getPlayerHandler()->setDirection(Being::LEFT); } - else if (getDirection() == Being::LEFT) + else if (mDirection == Being::LEFT) { setWalkingDir(Being::LEFT); setDirection(Being::DOWN); Net::getPlayerHandler()->setDirection(Being::DOWN); } - else if (getDirection() == Being::DOWN) + else if (mDirection == Being::DOWN) { setWalkingDir(Being::DOWN); setDirection(Being::RIGHT); Net::getPlayerHandler()->setDirection(Being::RIGHT); } - else if (getDirection() == Being::RIGHT) + else if (mDirection == Being::RIGHT) { setWalkingDir(Being::RIGHT); setDirection(Being::UP); @@ -2073,25 +2073,25 @@ void LocalPlayer::crazyMove2() if (!Client::limitPackets(PACKET_DIRECTION)) return; - if (getDirection() == Being::UP) + if (mDirection == Being::UP) { setWalkingDir(Being::UP | Being::LEFT); setDirection(Being::RIGHT); Net::getPlayerHandler()->setDirection(Being::DOWN | Being::RIGHT); } - else if (getDirection() == Being::RIGHT) + else if (mDirection == Being::RIGHT) { setWalkingDir(Being::UP | Being::RIGHT); setDirection(Being::DOWN); Net::getPlayerHandler()->setDirection(Being::DOWN | Being::LEFT); } - else if (getDirection() == Being::DOWN) + else if (mDirection == Being::DOWN) { setWalkingDir(Being::DOWN | Being::RIGHT); setDirection(Being::LEFT); Net::getPlayerHandler()->setDirection(Being::UP | Being::LEFT); } - else if (getDirection() == Being::LEFT) + else if (mDirection == Being::LEFT) { setWalkingDir(Being::DOWN | Being::LEFT); setDirection(Being::UP); @@ -2272,19 +2272,19 @@ void LocalPlayer::crazyMove8() { 1, 0, -1, 0} //move down }; - if (getDirection() == Being::UP) + if (mDirection == Being::UP) idx = 0; - else if (getDirection() == Being::RIGHT) + else if (mDirection == Being::RIGHT) idx = 1; - else if (getDirection() == Being::DOWN) + else if (mDirection == Being::DOWN) idx = 2; - else if (getDirection() == Being::LEFT) + else if (mDirection == Being::LEFT) idx = 3; int mult = 1; if (mMap->getWalk(mX + movesX[idx][0], - getTileY() + movesY[idx][0], getWalkMask())) + mY + movesY[idx][0], getWalkMask())) { while (mMap->getWalk(mX + movesX[idx][0] * mult, mY + movesY[idx][0] * mult, @@ -2340,7 +2340,7 @@ void LocalPlayer::crazyMove9() switch (mCrazyMoveState) { case 0: - switch (getDirection()) + switch (mDirection) { case UP : dy = -1; break; case DOWN : dy = 1; break; @@ -2412,7 +2412,7 @@ void LocalPlayer::crazyMoveA() move(1, 0); break; case 'f': - switch (getDirection()) + switch (mDirection) { case UP : dy = -1; break; case DOWN : dy = 1; break; @@ -2423,7 +2423,7 @@ void LocalPlayer::crazyMoveA() move(dx, dy); break; case 'b': - switch (getDirection()) + switch (mDirection) { case UP : dy = 1; break; case DOWN : dy = -1; break; @@ -2487,7 +2487,7 @@ void LocalPlayer::crazyMoveA() if (Client::limitPackets(PACKET_DIRECTION)) { Uint8 dir = 0; - switch (getDirection()) + switch (mDirection) { case UP : dir = Being::LEFT; break; case DOWN : dir = Being::RIGHT; break; @@ -2503,7 +2503,7 @@ void LocalPlayer::crazyMoveA() if (Client::limitPackets(PACKET_DIRECTION)) { Uint8 dir = 0; - switch (getDirection()) + switch (mDirection) { case UP : dir = Being::RIGHT; break; case DOWN : dir = Being::LEFT; break; @@ -2519,7 +2519,7 @@ void LocalPlayer::crazyMoveA() if (Client::limitPackets(PACKET_DIRECTION)) { Uint8 dir = 0; - switch (getDirection()) + switch (mDirection) { case UP : dir = Being::DOWN; break; case DOWN : dir = Being::UP; break; @@ -2614,8 +2614,8 @@ bool LocalPlayer::isReachable(int x, int y, int maxCost) if (!mMap) return false; - if (x - 1 <= getTileX() && x + 1 >= getTileX() - && y - 1 <= getTileY() && y + 1 >= getTileY() ) + if (x - 1 <= mX && x + 1 >= mX + && y - 1 <= mY && y + 1 >= mY ) { return true; } @@ -2638,17 +2638,17 @@ bool LocalPlayer::isReachable(Being *being, int maxCost) if (being->isReachable() == Being::REACH_NO) return false; - if (being->getTileX() == getTileX() - && being->getTileY() == getTileY()) + if (being->getTileX() == mX + && being->getTileY() == mY) { being->setDistance(0); being->setIsReachable(Being::REACH_YES); return true; } - else if (being->getTileX() - 1 <= getTileX() - && being->getTileX() + 1 >= getTileX() - && being->getTileY() - 1 <= getTileY() - && being->getTileY() + 1 >= getTileY()) + else if (being->getTileX() - 1 <= mX + && being->getTileX() + 1 >= mX + && being->getTileY() - 1 <= mY + && being->getTileY() + 1 >= mY) { being->setDistance(1); being->setIsReachable(Being::REACH_YES); @@ -2681,8 +2681,8 @@ bool LocalPlayer::pickUpItems(int pickUpType) return false; bool status = false; - int x = getTileX(); - int y = getTileY(); + int x = mX; + int y = mY; // first pick up item on player position FloorItem *item = @@ -2703,7 +2703,7 @@ bool LocalPlayer::pickUpItems(int pickUpType) switch(pickUpType) { case 1: - switch (getDirection()) + switch (mDirection) { case UP : --y; break; case DOWN : ++y; break; @@ -2719,7 +2719,7 @@ bool LocalPlayer::pickUpItems(int pickUpType) } break; case 2: - switch (getDirection()) + switch (mDirection) { case UP : x1 = x - 1; y1 = y - 1; x2 = x + 1; y2 = y; break; case DOWN : x1 = x - 1; y1 = y; x2 = x + 1; y2 = y + 1; break; @@ -2996,8 +2996,8 @@ void LocalPlayer::setHome() static_cast<int>(pos.y)); } - if (iter != mHomes.end() && getTileX() == static_cast<int>(pos.x) - && getTileY() == static_cast<int>(pos.y)) + if (iter != mHomes.end() && mX == static_cast<int>(pos.x) + && mY == static_cast<int>(pos.y)) { mMap->updatePortalTile("", MapItem::EMPTY, static_cast<int>(pos.x), static_cast<int>(pos.y)); @@ -3014,17 +3014,17 @@ void LocalPlayer::setHome() static_cast<int>(pos.y), MapItem::EMPTY); } - pos.x = static_cast<float>(getTileX()); - pos.y = static_cast<float>(getTileY()); + pos.x = static_cast<float>(mX); + pos.y = static_cast<float>(mY); mHomes[key] = pos; mMap->updatePortalTile("home", MapItem::HOME, - getTileX(), getTileY()); - socialWindow->addPortal(getTileX(), getTileY()); + mX, mY); + socialWindow->addPortal(mX, mY); } - MapItem *mapItem = specialLayer->getTile(getTileX(), getTileY()); + MapItem *mapItem = specialLayer->getTile(mX, mY); if (mapItem) { - int idx = socialWindow->getPortalIndex(getTileX(), getTileY()); + int idx = socialWindow->getPortalIndex(mX, mY); mapItem->setName(keyboard.getKeyShortString( outfitWindow->keyName(idx))); } @@ -3032,11 +3032,11 @@ void LocalPlayer::setHome() } else { - MapItem *mapItem = specialLayer->getTile(getTileX(), getTileY()); + MapItem *mapItem = specialLayer->getTile(mX, mY); int type = 0; std::map<std::string, Vector>::iterator iter = mHomes.find(key); - if (iter != mHomes.end() && getTileX() == pos.x && getTileY() == pos.y) + if (iter != mHomes.end() && mX == pos.x && mY == pos.y) { mHomes.erase(key); saveHomes(); @@ -3057,26 +3057,24 @@ void LocalPlayer::setHome() { type = MapItem::EMPTY; } - mMap->updatePortalTile("", type, getTileX(), getTileY()); + mMap->updatePortalTile("", type, mX, mY); if (type != MapItem::EMPTY) { - socialWindow->addPortal(getTileX(), getTileY()); - mapItem = specialLayer->getTile(getTileX(), getTileY()); + socialWindow->addPortal(mX, mY); + mapItem = specialLayer->getTile(mX, mY); if (mapItem) { - int idx = socialWindow->getPortalIndex(getTileX(), getTileY()); + int idx = socialWindow->getPortalIndex(mX, mY); mapItem->setName(keyboard.getKeyShortString( outfitWindow->keyName(idx))); } } else { - specialLayer->setTile(getTileX(), getTileY(), MapItem::EMPTY); - socialWindow->removePortal(getTileX(), getTileY()); + specialLayer->setTile(mX, mY, MapItem::EMPTY); + socialWindow->removePortal(mX, mY); } - -// specialLayer->setTile(getTileX(), getTileY(), type); } } @@ -3234,8 +3232,8 @@ bool LocalPlayer::navigateTo(int x, int y) mShowNavigePath = true; mOldX = static_cast<int>(playerPos.x); mOldY = static_cast<int>(playerPos.y); - mOldTileX = getTileX(); - mOldTileY = getTileY(); + mOldTileX = mX; + mOldTileY = mY; mNavigateX = x; mNavigateY = y; mNavigateId = 0; @@ -3263,8 +3261,8 @@ void LocalPlayer::navigateTo(Being *being) mShowNavigePath = true; mOldX = static_cast<int>(playerPos.x); mOldY = static_cast<int>(playerPos.y); - mOldTileX = getTileX(); - mOldTileY = getTileY(); + mOldTileX = mX; + mOldTileY = mY; mNavigateX = being->getTileX(); mNavigateY = being->getTileY(); @@ -3307,7 +3305,7 @@ void LocalPlayer::updateCoords() const Vector &playerPos = getPosition(); - if (getTileX() != mOldTileX || getTileY() != mOldTileY) + if (mX != mOldTileX || mY != mOldTileY) { if (socialWindow) socialWindow->updatePortals(); @@ -3315,7 +3313,7 @@ void LocalPlayer::updateCoords() viewport->hideBeingPopup(); if (mMap) { - std::string str = mMap->getObjectData(getTileX(), getTileY(), + std::string str = mMap->getObjectData(mX, mY, MapItem::MUSIC); if (str.empty()) str = mMap->getMusicFile(); @@ -3331,7 +3329,7 @@ void LocalPlayer::updateCoords() if (mShowNavigePath) { - if (mMap && (getTileX() != mOldTileX || getTileY() != mOldTileY)) + if (mMap && (mX != mOldTileX || mY != mOldTileY)) { SpecialLayer *tmpLayer = mMap->getTempLayer(); if (!tmpLayer) @@ -3367,7 +3365,7 @@ void LocalPlayer::updateCoords() for (Path::const_iterator i = mNavigatePath.begin(), i_end = mNavigatePath.end(); i != i_end; ++i) { - if ((*i).x == getTileX() && (*i).y == getTileY()) + if ((*i).x == mX && (*i).y == mY) { mNavigatePath.pop_front(); break; @@ -3385,8 +3383,8 @@ void LocalPlayer::updateCoords() } mOldX = static_cast<int>(playerPos.x); mOldY = static_cast<int>(playerPos.y); - mOldTileX = getTileX(); - mOldTileY = getTileY(); + mOldTileX = mX; + mOldTileY = mY; } void LocalPlayer::targetMoved() @@ -3416,6 +3414,12 @@ int LocalPlayer::getPathLength(Being* being) if (being->mX == mX && being->mY == mY) return 0; + if (being->mX - 1 <= mX && being->mX + 1 >= mX + && being->mY - 1 <= mY && being->mY + 1 >= mY) + { + return 1; + } + Path debugPath = mMap->findPath( static_cast<int>(playerPos.x - 16) / 32, static_cast<int>(playerPos.y - 32) / 32, @@ -3635,15 +3639,15 @@ void LocalPlayer::followMoveTo(Being *being, int x1, int y1, int x2, int y2) case 1: if (x1 != x2 || y1 != y2) { - setDestination(getTileX() + x2 - x1, getTileY() + y2 - y1); - setNextDest(getTileX() + x2 - x1, getTileY() + y2 - y1); + setDestination(mX + x2 - x1, mY + y2 - y1); + setNextDest(mX + x2 - x1, mY + y2 - y1); } break; case 2: if (x1 != x2 || y1 != y2) { - setDestination(getTileX() + x1 - x2, getTileY() + y1 - y2); - setNextDest(getTileX() + x1 - x2, getTileY() + y1 - y2); + setDestination(mX + x1 - x2, mY + y1 - y2); + setNextDest(mX + x1 - x2, mY + y1 - y2); } break; case 3: @@ -3697,8 +3701,8 @@ void LocalPlayer::fixPos(int maxDist) if (!mCrossX && !mCrossY) return; - int dx = abs(getTileX() - mCrossX); - int dy = abs(getTileY() - mCrossY); + int dx = abs(mX - mCrossX); + int dy = abs(mY - mCrossY); int dest = (dx * dx) + (dy * dy); if (dest > maxDist && mActivityTime |