diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/actorspritemanager.cpp | 15 | ||||
-rw-r--r-- | src/actorspritemanager.h | 2 | ||||
-rw-r--r-- | src/game.cpp | 26 | ||||
-rw-r--r-- | src/localplayer.cpp | 4 | ||||
-rw-r--r-- | src/vector.h | 5 |
5 files changed, 24 insertions, 28 deletions
diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp index 2928aa45..683f346d 100644 --- a/src/actorspritemanager.cpp +++ b/src/actorspritemanager.cpp @@ -218,18 +218,23 @@ FloorItem *ActorSpriteManager::findItem(int id) const return NULL; } -FloorItem *ActorSpriteManager::findItem(int x, int y) const +FloorItem *ActorSpriteManager::findItem(int x, int y, int maxDist) const { + FloorItem *item = 0; + int smallestDist = 0; for_actors { - if ((*it)->getTileX() == x && (*it)->getTileY() == y && - (*it)->getType() == ActorSprite::FLOOR_ITEM) + int dist = std::max(std::abs((*it)->getTileX() - x), + std::abs((*it)->getTileY() - y)); + if (((*it)->getType() == ActorSprite::FLOOR_ITEM) && + ((!item && dist <= maxDist) || dist < smallestDist)) { - return static_cast<FloorItem*>(*it); + item = static_cast<FloorItem*>(*it); + smallestDist = dist; } } - return NULL; + return item; } Being *ActorSpriteManager::findBeingByName(const std::string &name, diff --git a/src/actorspritemanager.h b/src/actorspritemanager.h index 64703396..ee41ae6d 100644 --- a/src/actorspritemanager.h +++ b/src/actorspritemanager.h @@ -96,7 +96,7 @@ class ActorSpriteManager /** * Returns a FloorItem at specific coordinates. */ - FloorItem *findItem(int x, int y) const; + FloorItem *findItem(int x, int y, int maxDist = 0) const; /** * Returns a being nearest to specific coordinates. diff --git a/src/game.cpp b/src/game.cpp index 1c24d5d1..7eb2cef1 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -377,29 +377,11 @@ static void handleItemPickUp() int y = local_player->getTileY(); // Let's look for items around until you find one. - bool found = false; - for (int xX = x - 1; xX < x + 2; ++xX) - { - for (int yY = y - 1; yY < y + 2; ++yY) - { - FloorItem *item = actorSpriteManager->findItem(xX, yY); - if (item) - { - found = true; - local_player->pickUp(item); - - // We found it, so set the player - // direction accordingly, - local_player->lookAt( - local_player->getMap()->getTileCenter(xX, yY)); + FloorItem *item = actorSpriteManager->findItem(x, y, 1); + if (!item) + return; - // Get out of the loops - break; - } - } - if (found) - break; - } + local_player->pickUp(item); } /** diff --git a/src/localplayer.cpp b/src/localplayer.cpp index a0350ce8..612fdd82 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -605,6 +605,10 @@ void LocalPlayer::pickUp(FloorItem *item) if (dx * dx + dy * dy < 4) { Net::getPlayerHandler()->pickUp(item); + // We found it, so set the player direction to it + // if the player does not move + if (getDestination() == getPosition()) + lookAt(item->getPosition()); mPickUpTarget = NULL; } else diff --git a/src/vector.h b/src/vector.h index 3360c20b..c0457bd7 100644 --- a/src/vector.h +++ b/src/vector.h @@ -182,6 +182,11 @@ class Vector float x, y, z; }; +inline bool operator == (const Vector &a, const Vector &b) +{ + return a.x == b.x && a.y == b.y && a.z == b.z; +} + /** * Appends a string representation of a vector to the output stream. */ |