summaryrefslogtreecommitdiff
path: root/src/being/being.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-12-24 14:16:52 +0300
committerAndrei Karas <akaras@inbox.ru>2013-12-24 14:16:52 +0300
commitf812b1f3f1b508504170de4e2d3574775e89c4d1 (patch)
tree508c602170976ffad7b66953ce324712b96575e4 /src/being/being.cpp
parent82ea830316b90bc4e55f2b34eb3c09df897df44d (diff)
downloadplus-f812b1f3f1b508504170de4e2d3574775e89c4d1.tar.gz
plus-f812b1f3f1b508504170de4e2d3574775e89c4d1.tar.bz2
plus-f812b1f3f1b508504170de4e2d3574775e89c4d1.tar.xz
plus-f812b1f3f1b508504170de4e2d3574775e89c4d1.zip
add basic follow logic for pets with hard coded parameters.
Diffstat (limited to 'src/being/being.cpp')
-rw-r--r--src/being/being.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/being/being.cpp b/src/being/being.cpp
index ba2108402..0b7010789 100644
--- a/src/being/being.cpp
+++ b/src/being/being.cpp
@@ -1592,6 +1592,9 @@ void Being::logic()
actorManager->destroy(this);
}
+ if (mPet)
+ mPet->petLogic();
+
const SoundInfo *const sound = mNextSound.sound;
if (sound)
{
@@ -1608,6 +1611,46 @@ void Being::logic()
BLOCK_END("Being::logic")
}
+void Being::petLogic()
+{
+ if (!mOwner || !mMap || !mInfo)
+ return;
+ int dstX = mOwner->getTileX();
+ int dstY = mOwner->getTileY();
+ const int followDist = 3;
+ const int dist = 1;
+ const int divX = abs(dstX - mX);
+ const int divY = abs(dstY - mY);
+ if (divX > followDist || divY > followDist)
+ {
+ if (divX > followDist)
+ {
+ if (dstX > mX + dist)
+ dstX -= dist;
+ else if (dstX + dist <= mX)
+ dstX += dist;
+ }
+ else
+ {
+ dstX = mX;
+ }
+
+ if (divY > followDist)
+ {
+ if (dstY > mY + dist)
+ dstY -= dist;
+ else if (dstX + dist <= mX)
+ dstY += dist;
+ }
+ else
+ {
+ dstY = mY;
+ }
+
+ setPath(mMap->findPath(mX, mY, dstX, dstY, getWalkMask()));
+ }
+}
+
void Being::drawEmotion(Graphics *const graphics, const int offsetX,
const int offsetY) const
{