diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2008-10-09 19:42:13 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2008-10-09 19:42:13 +0000 |
commit | 3fe1772b1e00344365e3cf8204225be19925b9e5 (patch) | |
tree | 0f66dddac8e14787096c01368611efa53f453134 /src/beingmanager.cpp | |
parent | 8cc0423b0c0aaa5dd9e91f673a691e5e634988c1 (diff) | |
download | mana-3fe1772b1e00344365e3cf8204225be19925b9e5.tar.gz mana-3fe1772b1e00344365e3cf8204225be19925b9e5.tar.bz2 mana-3fe1772b1e00344365e3cf8204225be19925b9e5.tar.xz mana-3fe1772b1e00344365e3cf8204225be19925b9e5.zip |
Merged the movement branch into trunk
I consider this the only way forward. In my tests this code isn't actually
doing worse than what was there before. Of course some cases are a bit broken,
and I'm open to any kind of feedback so that we can fix those issues.
Diffstat (limited to 'src/beingmanager.cpp')
-rw-r--r-- | src/beingmanager.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index a58c97e7..abb23f5e 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -39,8 +39,9 @@ class FindBeingFunctor bool operator() (Being *being) { Uint16 other_y = y + ((being->getType() == Being::NPC) ? 1 : 0); - return (being->mX / 32 == x && - (being->mY / 32 == y || being->mY / 32 == other_y) && + const Vector &pos = being->getPosition(); + return ((int) pos.x / 32 == x && + ((int) pos.y / 32 == y || (int) pos.y / 32 == other_y) && being->mAction != Being::DEAD && (type == Being::UNKNOWN || being->getType() == type)); } @@ -165,7 +166,8 @@ Being* BeingManager::findNearestLivingBeing(Uint16 x, Uint16 y, int maxdist, for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++) { Being *being = (*i); - int d = abs(being->mX - x) + abs(being->mY - y); + const Vector &pos = being->getPosition(); + int d = abs((int) pos.x - x) + abs((int) pos.y - y); if ((being->getType() == type || type == Being::UNKNOWN) && (d < dist || closestBeing == NULL) // it is closer @@ -185,13 +187,14 @@ Being* BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxdist, { Being *closestBeing = NULL; int dist = 0; - int x = aroundBeing->mX; - int y = aroundBeing->mY; + const Vector &aroundBeingPos = aroundBeing->getPosition(); for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++) { Being *being = (*i); - int d = abs(being->mX - x) + abs(being->mY - y); + const Vector &pos = being->getPosition(); + int d = abs((int) pos.x - aroundBeingPos.x) + + abs((int) pos.y - aroundBeingPos.y); if ((being->getType() == type || type == Being::UNKNOWN) && (d < dist || closestBeing == NULL) // it is closer |