summaryrefslogtreecommitdiff
path: root/src/being.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-03-17 22:07:11 +0200
committerAndrei Karas <akaras@inbox.ru>2011-03-17 22:07:11 +0200
commit9330b50231cb038295681874c3060aa97689f31d (patch)
tree60283ab807e32b722ccade2a1c38646aeaaf89d1 /src/being.cpp
parentabeb003b88cc49ba70cdadd2e3adec6eca1751ec (diff)
downloadManaVerse-9330b50231cb038295681874c3060aa97689f31d.tar.gz
ManaVerse-9330b50231cb038295681874c3060aa97689f31d.tar.bz2
ManaVerse-9330b50231cb038295681874c3060aa97689f31d.tar.xz
ManaVerse-9330b50231cb038295681874c3060aa97689f31d.zip
Move direction calucaltion to Being method.
Diffstat (limited to 'src/being.cpp')
-rw-r--r--src/being.cpp42
1 files changed, 31 insertions, 11 deletions
diff --git a/src/being.cpp b/src/being.cpp
index e66f3284b..49bcfee90 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -987,6 +987,34 @@ void Being::setDirection(Uint8 direction)
CompoundSprite::setDirection(dir);
}
+Uint8 Being::calcDirection() const
+{
+ int dir = 0;
+ if (mDest.x > mX)
+ dir |= RIGHT;
+ else if (mDest.x < mX)
+ dir |= LEFT;
+ if (mDest.y > mY)
+ dir |= DOWN;
+ else if (mDest.y < mY)
+ dir |= UP;
+ return dir;
+}
+
+Uint8 Being::calcDirection(int dstX, int dstY) const
+{
+ int dir = 0;
+ if (dstX > mX)
+ dir |= RIGHT;
+ else if (dstX < mX)
+ dir |= LEFT;
+ if (dstY > mY)
+ dir |= DOWN;
+ else if (dstY < mY)
+ dir |= UP;
+ return dir;
+}
+
/** TODO: Used by eAthena only */
void Being::nextTile()
{
@@ -999,17 +1027,9 @@ void Being::nextTile()
Position pos = mPath.front();
mPath.pop_front();
- int dir = 0;
- if (pos.x > mX)
- dir |= RIGHT;
- else if (pos.x < mX)
- dir |= LEFT;
- if (pos.y > mY)
- dir |= DOWN;
- else if (pos.y < mY)
- dir |= UP;
-
- setDirection(static_cast<Uint8>(dir));
+ Uint8 dir = calcDirection(pos.x, pos.y);
+ if (dir)
+ setDirection(static_cast<Uint8>(dir));
if (!mMap->getWalk(pos.x, pos.y, getWalkMask()))
{