summaryrefslogtreecommitdiff
path: root/src/actorspritemanager.cpp
diff options
context:
space:
mode:
authorErik Schilling <ablu.erikschilling@googlemail.com>2012-01-19 18:15:54 +0100
committerErik Schilling <ablu.erikschilling@googlemail.com>2012-01-22 12:05:11 +0100
commit8a4b82e3ed75e426d44b69640f009e1e731c75c4 (patch)
tree4393fcd7681942561dc0ac988d4762682979328f /src/actorspritemanager.cpp
parentc4bdf324d7d464bc7fabbf88e1a6e66701c6e7cb (diff)
downloadmana-8a4b82e3ed75e426d44b69640f009e1e731c75c4.tar.gz
mana-8a4b82e3ed75e426d44b69640f009e1e731c75c4.tar.bz2
mana-8a4b82e3ed75e426d44b69640f009e1e731c75c4.tar.xz
mana-8a4b82e3ed75e426d44b69640f009e1e731c75c4.zip
Prevented looking at item when picking up while moving
+ Fixes from Bjorns review. Reviewed-by: Bjorn.
Diffstat (limited to 'src/actorspritemanager.cpp')
-rw-r--r--src/actorspritemanager.cpp15
1 files changed, 10 insertions, 5 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,