From 9330b50231cb038295681874c3060aa97689f31d Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 17 Mar 2011 22:07:11 +0200 Subject: Move direction calucaltion to Being method. --- src/being.cpp | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) (limited to 'src/being.cpp') 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(dir)); + Uint8 dir = calcDirection(pos.x, pos.y); + if (dir) + setDirection(static_cast(dir)); if (!mMap->getWalk(pos.x, pos.y, getWalkMask())) { -- cgit v1.2.3-60-g2f50