summaryrefslogtreecommitdiff
path: root/src/beingmanager.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2006-09-29 23:59:08 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2006-09-29 23:59:08 +0000
commite8f94fe7ca5e7e7838eaa84f1792b4b42b4bada3 (patch)
treee8dc775e12f6b4eb0a6d56448f05286c774bbb8a /src/beingmanager.cpp
parent0e8c09433f3a193b5a94a1ad572d8237113cdfbf (diff)
downloadmana-e8f94fe7ca5e7e7838eaa84f1792b4b42b4bada3.tar.gz
mana-e8f94fe7ca5e7e7838eaa84f1792b4b42b4bada3.tar.bz2
mana-e8f94fe7ca5e7e7838eaa84f1792b4b42b4bada3.tar.xz
mana-e8f94fe7ca5e7e7838eaa84f1792b4b42b4bada3.zip
Merged trunk changes from revision 2618 to 2716 into the 0.1.0 branch.
Diffstat (limited to 'src/beingmanager.cpp')
-rw-r--r--src/beingmanager.cpp29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp
index d2db055a..30b68ee2 100644
--- a/src/beingmanager.cpp
+++ b/src/beingmanager.cpp
@@ -113,9 +113,9 @@ Being* BeingManager::findBeing(Uint16 x, Uint16 y, Being::Type type)
return (i == mBeings.end()) ? NULL : *i;
}
-Beings* BeingManager::getAll()
+Beings& BeingManager::getAll()
{
- return &mBeings;
+ return mBeings;
}
void BeingManager::logic()
@@ -153,3 +153,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;
+}