summaryrefslogtreecommitdiff
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
parentabeb003b88cc49ba70cdadd2e3adec6eca1751ec (diff)
downloadplus-9330b50231cb038295681874c3060aa97689f31d.tar.gz
plus-9330b50231cb038295681874c3060aa97689f31d.tar.bz2
plus-9330b50231cb038295681874c3060aa97689f31d.tar.xz
plus-9330b50231cb038295681874c3060aa97689f31d.zip
Move direction calucaltion to Being method.
-rw-r--r--src/being.cpp42
-rw-r--r--src/being.h4
-rw-r--r--src/net/tmwa/beinghandler.cpp10
3 files changed, 36 insertions, 20 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()))
{
diff --git a/src/being.h b/src/being.h
index 1dc2fd8f8..7d4883ba6 100644
--- a/src/being.h
+++ b/src/being.h
@@ -652,6 +652,10 @@ class Being : public ActorSprite, public ConfigListener
int getHP()
{ return mHP; }
+ Uint8 calcDirection(int dstX, int dstY) const;
+
+ Uint8 calcDirection() const;
+
protected:
/**
* Sets the new path for this being.
diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp
index fb3ac44be..74a620ce3 100644
--- a/src/net/tmwa/beinghandler.cpp
+++ b/src/net/tmwa/beinghandler.cpp
@@ -951,15 +951,7 @@ void BeingHandler::handleMessage(Net::MessageIn &msg)
if (srcX != dstX || srcY != dstY)
{
- int dir = 0;
- if (dstX > srcX)
- dir |= Being::RIGHT;
- else if (dstX < srcX)
- dir |= Being::LEFT;
- if (dstY > srcY)
- dir |= Being::DOWN;
- else if (dstY < srcY)
- dir |= Being::UP;
+ int dir = dstBeing->calcDirection(dstX, dstY);
if (dir && dstBeing->getDirection() != dir)
{