summaryrefslogtreecommitdiff
path: root/src/actorspritemanager.cpp
diff options
context:
space:
mode:
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,