summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/beingmanager.cpp12
-rw-r--r--src/beingmanager.h6
2 files changed, 11 insertions, 7 deletions
diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp
index 26672de0..656b297e 100644
--- a/src/beingmanager.cpp
+++ b/src/beingmanager.cpp
@@ -213,8 +213,8 @@ void BeingManager::clear()
}
Being *BeingManager::findNearestLivingBeing(int x, int y,
- int maxTileDist,
- Being::Type type) const
+ int maxTileDist, Being::Type type,
+ Being *excluded) const
{
Being *closestBeing = 0;
int dist = 0;
@@ -231,8 +231,9 @@ Being *BeingManager::findNearestLivingBeing(int x, int y,
int d = abs(((int) pos.x) - x) + abs(((int) pos.y) - y);
if ((being->getType() == type || type == Being::UNKNOWN)
- && (d < dist || !closestBeing) // it is closer
- && being->isAlive()) // no dead beings
+ && (d < dist || !closestBeing) // it is closer
+ && being->isAlive() // no dead beings
+ && being != excluded)
{
dist = d;
closestBeing = being;
@@ -246,7 +247,8 @@ Being *BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxDist,
Being::Type type) const
{
const Vector &pos = aroundBeing->getPosition();
- return findNearestLivingBeing((int)pos.x, (int)pos.y, maxDist, type);
+ return findNearestLivingBeing((int)pos.x, (int)pos.y, maxDist, type,
+ aroundBeing);
}
bool BeingManager::hasBeing(Being *being) const
diff --git a/src/beingmanager.h b/src/beingmanager.h
index d81db668..7fd63afe 100644
--- a/src/beingmanager.h
+++ b/src/beingmanager.h
@@ -75,9 +75,11 @@ class BeingManager
* @param maxTileDist Maximal distance in tiles. If minimal distance is
* larger, no being is returned.
* @param type The type of being to look for.
+ * @param excluded The being to exclude from the search.
*/
Being *findNearestLivingBeing(int x, int y, int maxTileDist,
- Being::Type type = Being::UNKNOWN) const;
+ Being::Type type = Being::UNKNOWN,
+ Being *excluded = 0) const;
/**
* Returns a being nearest to another being.
@@ -88,7 +90,7 @@ class BeingManager
* @param type The type of being to look for.
*/
Being *findNearestLivingBeing(Being *aroundBeing, int maxTileDist,
- Being::Type type = Being::UNKNOWN) const;
+ Being::Type type = Being::UNKNOWN) const;
/**
* Finds a being by name and (optionally) by type.