summaryrefslogtreecommitdiff
path: root/src/beingmanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/beingmanager.cpp')
-rw-r--r--src/beingmanager.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp
index 25edeb24..027e08d3 100644
--- a/src/beingmanager.cpp
+++ b/src/beingmanager.cpp
@@ -159,3 +159,28 @@ void BeingManager::clear()
mBeings.push_back(player_node);
}
}
+
+Being* BeingManager::findNearestLivingBeing(Uint16 x, Uint16 y, int maxdist,
+ Being::Type type)
+{
+ Being *closestBeing = NULL;
+ int dist = 0;
+
+ for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++)
+ {
+ Being *being = (*i);
+ int d = abs(being->mX - x) + abs(being->mY - y);
+
+ if ((being->getType() == type || type == Being::UNKNOWN)
+ && (d < dist || closestBeing == NULL) // it is closer
+ && being->mAction != Being::DEAD // no dead beings
+ && being->mAction != Being::MONSTER_DEAD
+ )
+ {
+ dist = d;
+ closestBeing = being;
+ }
+ }
+
+ return (maxdist >= dist) ? closestBeing : NULL;
+}