diff options
author | Philipp Sehmisch <tmw@crushnet.org> | 2007-12-30 00:02:14 +0000 |
---|---|---|
committer | Philipp Sehmisch <tmw@crushnet.org> | 2007-12-30 00:02:14 +0000 |
commit | 8d4dc1c28ee54f67c155b6759cf5776a917904ff (patch) | |
tree | ecf910e7214008c9a89f9d1bded37a8057abe1f2 /src/beingmanager.cpp | |
parent | 8e28cc3ac0f679cf35bc6a9ce1740ac7ae4aac47 (diff) | |
download | mana-8d4dc1c28ee54f67c155b6759cf5776a917904ff.tar.gz mana-8d4dc1c28ee54f67c155b6759cf5776a917904ff.tar.bz2 mana-8d4dc1c28ee54f67c155b6759cf5776a917904ff.tar.xz mana-8d4dc1c28ee54f67c155b6759cf5776a917904ff.zip |
Added a key for targeting the nearest player character based on patches by Trinexx. Some mapping fixes at snake dungeon map.
Diffstat (limited to 'src/beingmanager.cpp')
-rw-r--r-- | src/beingmanager.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index f35a305d..daceca5e 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -188,3 +188,30 @@ Being* BeingManager::findNearestLivingBeing(Uint16 x, Uint16 y, int maxdist, return (maxdist >= dist) ? closestBeing : NULL; } + +Being* BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxdist, + Being::Type type) +{ + Being *closestBeing = NULL; + int dist = 0; + int x = aroundBeing->mX; + int y = aroundBeing->mY; + + 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 != aroundBeing + ) + { + dist = d; + closestBeing = being; + } + } + + return (maxdist >= dist) ? closestBeing : NULL; +} |