summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-12-25 02:06:09 +0300
committerAndrei Karas <akaras@inbox.ru>2013-12-25 02:10:11 +0300
commit219424dc0e194a722bc93ba51b973fda8715869f (patch)
treebe1586057d67bb329edad911a386d4945cba4882 /src
parent2d4c4cb494842daa6b3865bc2729782098e367d8 (diff)
downloadplus-219424dc0e194a722bc93ba51b973fda8715869f.tar.gz
plus-219424dc0e194a722bc93ba51b973fda8715869f.tar.bz2
plus-219424dc0e194a722bc93ba51b973fda8715869f.tar.xz
plus-219424dc0e194a722bc93ba51b973fda8715869f.zip
add pet spawn offset in tiles from owner position.
New pet db attributes: offsetX, offsetY Offset counted from player direction.
Diffstat (limited to 'src')
-rw-r--r--src/being/being.cpp39
-rw-r--r--src/being/being.h2
-rw-r--r--src/resources/db/petdb.cpp5
3 files changed, 44 insertions, 2 deletions
diff --git a/src/being/being.cpp b/src/being/being.cpp
index 90912e8a7..b7d6019ec 100644
--- a/src/being/being.cpp
+++ b/src/being/being.cpp
@@ -1644,6 +1644,7 @@ void Being::petLogic()
if (divX >= warpDist || divY >= warpDist)
{
setAction(Being::STAND, 0);
+ fixPetSpawnPos(dstX, dstY);
setTileCoords(dstX, dstY);
Net::getPetHandler()->spawn(mOwner, dstX, dstY);
}
@@ -3134,11 +3135,14 @@ void Being::addPet(const int id)
id, ActorSprite::PET, 0);
if (being)
{
- being->setTileCoords(mX, mY);
being->setOwner(this);
mPetId = id;
mPet = being;
- Net::getPetHandler()->spawn(this, mX, mY);
+ int dstX = mX;
+ int dstY = mY;
+ being->fixPetSpawnPos(dstX, dstY);
+ being->setTileCoords(dstX, dstY);
+ Net::getPetHandler()->spawn(this, dstX, dstY);
}
}
@@ -3175,6 +3179,37 @@ void Being::updatePets()
}
}
+void Being::fixPetSpawnPos(int &dstX, int &dstY) const
+{
+ if (!mInfo || !mOwner)
+ return;
+
+ const int offsetX1 = mInfo->getTargetOffsetX();
+ const int offsetY1 = mInfo->getTargetOffsetY();
+ int offsetX = offsetX1;
+ int offsetY = offsetY1;
+ switch (mOwner->getDirection())
+ {
+ case LEFT:
+ offsetX = offsetY1;
+ offsetY = -offsetX1;
+ break;
+ case RIGHT:
+ offsetX = offsetY1;
+ offsetY = offsetX1;
+ break;
+ case UP:
+ offsetY = -offsetY;
+ break;
+ default:
+ case DOWN:
+ break;
+ }
+ logger->log("fix offset: %d,%d", offsetX, offsetY);
+ dstX += offsetX;
+ dstY += offsetY;
+}
+
void Being::playSfx(const SoundInfo &sound, Being *const being,
const bool main, const int x, const int y) const
{
diff --git a/src/being/being.h b/src/being/being.h
index 6722e5d4c..e8bc7da37 100644
--- a/src/being/being.h
+++ b/src/being/being.h
@@ -881,6 +881,8 @@ class Being : public ActorSprite, public ConfigListener
void updatePets();
+ void fixPetSpawnPos(int &dstX, int &dstY) const;
+
Being *getPet()
{ return mPet; }
diff --git a/src/resources/db/petdb.cpp b/src/resources/db/petdb.cpp
index 397af6220..eeb8af9a0 100644
--- a/src/resources/db/petdb.cpp
+++ b/src/resources/db/petdb.cpp
@@ -92,6 +92,11 @@ void PETDB::load()
currentInfo->setWalkSpeed(XML::getProperty(petNode,
"walkSpeed", 0));
+ currentInfo->setTargetOffsetX(XML::getProperty(petNode,
+ "offsetX", 0));
+ currentInfo->setTargetOffsetY(XML::getProperty(petNode,
+ "offsetY", 1));
+
SpriteDisplay display;
for_each_xml_child_node(spriteNode, petNode)