summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-01-20 21:09:46 +0300
committerAndrei Karas <akaras@inbox.ru>2014-01-20 21:09:46 +0300
commit8f24400fc10658db9636e6cdd315504d75c71a5d (patch)
treef2f5a1094f6c48040b87238612d4042704846e40
parent1f2dd660dad937a3c1f2a2dfc07b756965e4ddae (diff)
downloadplus-8f24400fc10658db9636e6cdd315504d75c71a5d.tar.gz
plus-8f24400fc10658db9636e6cdd315504d75c71a5d.tar.bz2
plus-8f24400fc10658db9636e6cdd315504d75c71a5d.tar.xz
plus-8f24400fc10658db9636e6cdd315504d75c71a5d.zip
add attack action for pets.
New pets db attributes: attackOffsetX attackOffsetY attaclDirectionType
-rw-r--r--src/being/being.cpp41
-rw-r--r--src/being/being.h8
-rw-r--r--src/being/localplayer.h6
-rw-r--r--src/resources/beinginfo.cpp3
-rw-r--r--src/resources/beinginfo.h21
-rw-r--r--src/resources/db/petdb.cpp6
6 files changed, 83 insertions, 2 deletions
diff --git a/src/being/being.cpp b/src/being/being.cpp
index aa2b875af..dbe4d7350 100644
--- a/src/being/being.cpp
+++ b/src/being/being.cpp
@@ -134,6 +134,8 @@ Being::Being(const int id, const Type type, const uint16_t subtype,
mAttackSpeed(350),
mLevel(0),
mAttackRange(1),
+ mLastAttackX(0),
+ mLastAttackY(0),
mGender(GENDER_UNSPECIFIED),
mAction(STAND),
mSubType(0xFFFF),
@@ -760,6 +762,9 @@ void Being::handleAttack(Being *const victim, const int damage,
if (this != player_node)
setAction(Being::ATTACK, attackId);
+ mLastAttackX = victim->getTileX();
+ mLastAttackY = victim->getTileY();
+
if (mType == PLAYER && mEquippedWeapon)
fireMissile(victim, mEquippedWeapon->getMissileParticleFile());
else if (mInfo->getAttack(attackId))
@@ -1720,14 +1725,24 @@ void Being::petLogic()
return;
}
}
- if (mAction == STAND)
+ if (mOwner->getCurrentAction() != ATTACK)
+ {
+ if (mAction == ATTACK)
+ setAction(STAND, 0);
+ }
+ else
+ {
+ if (mAction == STAND || mAction == ATTACK)
+ setAction(ATTACK, 0);
+ }
+
+ if (mAction == STAND || mAction == ATTACK)
{
int directionType = 0;
switch (mOwner->getCurrentAction())
{
case STAND:
case MOVE:
- case ATTACK:
case HURT:
case SPAWN:
default:
@@ -1739,6 +1754,9 @@ void Being::petLogic()
case DEAD:
directionType = mInfo->getDeadDirectionType();
break;
+ case ATTACK:
+ directionType = mInfo->getAttackDirectionType();
+ break;
}
int newDir = 0;
@@ -1773,6 +1791,21 @@ void Being::petLogic()
else if (dstY < dstY0)
newDir |= UP;
break;
+
+ case 4:
+ {
+ const int dstX2 = mOwner->getLastAttackX();
+ const int dstY2 = mOwner->getLastAttackY();
+ if (dstX > dstX2)
+ newDir |= LEFT;
+ else if (dstX < dstX2)
+ newDir |= RIGHT;
+ if (dstY > dstY2)
+ newDir |= UP;
+ else if (dstY < dstY2)
+ newDir |= DOWN;
+ break;
+ }
}
if (newDir && newDir != getDirection())
setDirection(newDir);
@@ -3337,6 +3370,10 @@ void Being::fixPetSpawnPos(int &dstX, int &dstY) const
break;
case ATTACK:
+ offsetX1 = mInfo->getAttackOffsetX();
+ offsetY1 = mInfo->getAttackOffsetY();
+ break;
+
case SPAWN:
case HURT:
case STAND:
diff --git a/src/being/being.h b/src/being/being.h
index 7314fe1f1..d3dfe2cc1 100644
--- a/src/being/being.h
+++ b/src/being/being.h
@@ -930,6 +930,12 @@ class Being : public ActorSprite, public ConfigListener
int decUsage()
{ return --mUsageCounter; }
+ virtual int getLastAttackX() const
+ { return mLastAttackX; }
+
+ virtual int getLastAttackY() const
+ { return mLastAttackY; }
+
protected:
/**
* Updates name's location.
@@ -996,6 +1002,8 @@ class Being : public ActorSprite, public ConfigListener
int mLevel;
int mAttackRange;
+ int mLastAttackX;
+ int mLastAttackY;
Gender mGender;
Action mAction; /**< Action the being is performing */
uint16_t mSubType; /**< Subtype (graphical view, basically) */
diff --git a/src/being/localplayer.h b/src/being/localplayer.h
index 0e6ebe8a4..88a6f6754 100644
--- a/src/being/localplayer.h
+++ b/src/being/localplayer.h
@@ -503,6 +503,12 @@ class LocalPlayer final : public Being,
std::string getGameModifiersString();
+ int getLastAttackX() const override final
+ { return mTarget ? mTarget->getTileX() : mLastAttackX; }
+
+ int getLastAttackY() const override final
+ { return mTarget ? mTarget->getTileY() : mLastAttackY; }
+
protected:
void updateCoords() override final;
diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp
index 38c141d63..40ea7af1a 100644
--- a/src/resources/beinginfo.cpp
+++ b/src/resources/beinginfo.cpp
@@ -70,10 +70,13 @@ BeingInfo::BeingInfo() :
mMoveOffsetY(0),
mDeadOffsetX(0),
mDeadOffsetY(0),
+ mAttackOffsetX(0),
+ mAttackOffsetY(0),
mThinkTime(50),
mDirectionType(1),
mSitDirectionType(1),
mDeadDirectionType(1),
+ mAttackDirectionType(1),
mStaticMaxHP(false),
mTargetSelection(true)
{
diff --git a/src/resources/beinginfo.h b/src/resources/beinginfo.h
index d862f1020..31725d218 100644
--- a/src/resources/beinginfo.h
+++ b/src/resources/beinginfo.h
@@ -284,6 +284,18 @@ class BeingInfo final
int getDeadOffsetY() const A_WARN_UNUSED
{ return mDeadOffsetY; }
+ void setAttackOffsetX(const int n)
+ { mAttackOffsetX = n; }
+
+ int getAttackOffsetX() const A_WARN_UNUSED
+ { return mAttackOffsetX; }
+
+ void setAttackOffsetY(const int n)
+ { mAttackOffsetY = n; }
+
+ int getAttackOffsetY() const A_WARN_UNUSED
+ { return mAttackOffsetY; }
+
void setThinkTime(const int n)
{ mThinkTime = n; }
@@ -308,6 +320,12 @@ class BeingInfo final
int getDeadDirectionType() const A_WARN_UNUSED
{ return mDeadDirectionType; }
+ void setAttackDirectionType(const int n)
+ { mAttackDirectionType = n; }
+
+ int getAttackDirectionType() const A_WARN_UNUSED
+ { return mAttackDirectionType; }
+
void setColorsList(const std::string &name);
std::string getColor(const int idx) const A_WARN_UNUSED;
@@ -348,10 +366,13 @@ class BeingInfo final
int mMoveOffsetY;
int mDeadOffsetX;
int mDeadOffsetY;
+ int mAttackOffsetX;
+ int mAttackOffsetY;
int mThinkTime;
int mDirectionType;
int mSitDirectionType;
int mDeadDirectionType;
+ int mAttackDirectionType;
bool mStaticMaxHP;
bool mTargetSelection;
};
diff --git a/src/resources/db/petdb.cpp b/src/resources/db/petdb.cpp
index c9f3bdbeb..7af3c5d09 100644
--- a/src/resources/db/petdb.cpp
+++ b/src/resources/db/petdb.cpp
@@ -132,6 +132,10 @@ void PETDB::loadXmlFile(const std::string &fileName)
"deadOffsetX", 0));
currentInfo->setDeadOffsetY(XML::getProperty(petNode,
"deadOffsetY", 1));
+ currentInfo->setAttackOffsetX(XML::getProperty(petNode,
+ "attackOffsetX", currentInfo->getTargetOffsetX()));
+ currentInfo->setAttackOffsetY(XML::getProperty(petNode,
+ "attackOffsetY", currentInfo->getTargetOffsetY()));
currentInfo->setThinkTime(XML::getProperty(petNode,
"thinkTime", 500) / 10);
@@ -142,6 +146,8 @@ void PETDB::loadXmlFile(const std::string &fileName)
"sitDirectionType", 1));
currentInfo->setDeadDirectionType(XML::getProperty(petNode,
"deadDirectionType", 1));
+ currentInfo->setAttackDirectionType(XML::getProperty(petNode,
+ "attackDirectionType", 4));
SpriteDisplay display;
for_each_xml_child_node(spriteNode, petNode)