From f812b1f3f1b508504170de4e2d3574775e89c4d1 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 24 Dec 2013 14:16:52 +0300 Subject: add basic follow logic for pets with hard coded parameters. --- src/being/being.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ src/being/being.h | 2 ++ 2 files changed, 45 insertions(+) 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 { diff --git a/src/being/being.h b/src/being/being.h index 08ac81e9e..e20db69f4 100644 --- a/src/being/being.h +++ b/src/being/being.h @@ -412,6 +412,8 @@ class Being : public ActorSprite, public ConfigListener */ virtual void logic() override; + void petLogic(); + /** * Draws the speech text above the being. */ -- cgit v1.2.3-70-g09d2