diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2006-09-02 12:50:40 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2006-09-02 12:50:40 +0000 |
commit | 3213f41daeed034c8aa9b8be9e86796737a38a78 (patch) | |
tree | 5441dd101209774d6e7c6612281b3ef12bd941a5 /src/beingmanager.cpp | |
parent | f5fc009543a0a189bcde5acf91ff315dd9cd05e9 (diff) | |
download | mana-3213f41daeed034c8aa9b8be9e86796737a38a78.tar.gz mana-3213f41daeed034c8aa9b8be9e86796737a38a78.tar.bz2 mana-3213f41daeed034c8aa9b8be9e86796737a38a78.tar.xz mana-3213f41daeed034c8aa9b8be9e86796737a38a78.zip |
Applied patch by Bernard Lidicky, adding targetting nearest monster with either
keyboard or mouse. Also made clicking beings in general a bit easier (patch
applied by Bjørn Lindeijer).
Diffstat (limited to 'src/beingmanager.cpp')
-rw-r--r-- | src/beingmanager.cpp | 25 |
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; +} |