summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-10-18 20:00:38 +0300
committerAndrei Karas <akaras@inbox.ru>2015-10-18 20:08:15 +0300
commitcf6a135902b647b565e782e9cb9626b7ac8b361b (patch)
treea6cebb27ca4f89ea5e559958dac2a4af9afa87d2 /src
parenta3ad4ab670c7fa776375f569e9fe9d7fbe227245 (diff)
downloadmanaverse-cf6a135902b647b565e782e9cb9626b7ac8b361b.tar.gz
manaverse-cf6a135902b647b565e782e9cb9626b7ac8b361b.tar.bz2
manaverse-cf6a135902b647b565e782e9cb9626b7ac8b361b.tar.xz
manaverse-cf6a135902b647b565e782e9cb9626b7ac8b361b.zip
Add support for multiply sprites in each horse part.
Also fix horse sprites actions issue.
Diffstat (limited to 'src')
-rw-r--r--src/being/being.cpp97
-rw-r--r--src/being/being.h6
-rw-r--r--src/resources/db/horsedb.cpp49
-rw-r--r--src/resources/horseinfo.h12
-rw-r--r--src/resources/spritedisplay.h2
-rw-r--r--src/resources/spritereference.h4
6 files changed, 103 insertions, 67 deletions
diff --git a/src/being/being.cpp b/src/being/being.cpp
index 711fcf233..03e67f327 100644
--- a/src/being/being.cpp
+++ b/src/being/being.cpp
@@ -128,6 +128,9 @@ typedef std::map<int, int>::const_iterator IntMapCIter;
#define for_each_badges() \
for (int f = 0; f < BadgeIndex::BadgeIndexSize; f++)
+#define for_each_horses(name) \
+ FOR_EACH (std::vector<AnimatedSprite*>::const_iterator, it, name)
+
Being::Being(const BeingId id,
const ActorTypeT type,
const BeingTypeId subtype,
@@ -194,8 +197,6 @@ Being::Being(const BeingId id,
#ifdef EATHENA_SUPPORT
mChat(nullptr),
mHorseInfo(nullptr),
- mDownHorseSprite(nullptr),
- mUpHorseSprite(nullptr),
#endif
mX(0),
mY(0),
@@ -305,6 +306,7 @@ Being::~Being()
mBadgesCount = 0;
#ifdef EATHENA_SUPPORT
delete2(mChat);
+ removeHorse();
#endif
if (mOwner)
@@ -1440,10 +1442,10 @@ void Being::setAction(const BeingActionT &action, const int attackId)
sprite->play(currentAction);
}
#ifdef EATHENA_SUPPORT
- if (mDownHorseSprite)
- mDownHorseSprite->play(currentAction);
- if (mUpHorseSprite)
- mUpHorseSprite->play(currentAction);
+ for_each_horses(mDownHorseSprites)
+ (*it)->play(currentAction);
+ for_each_horses(mUpHorseSprites)
+ (*it)->play(currentAction);
#endif
mAction = action;
}
@@ -1513,10 +1515,10 @@ void Being::setDirection(const uint8_t direction)
}
#ifdef EATHENA_SUPPORT
- if (mDownHorseSprite)
- mDownHorseSprite->setSpriteDirection(dir);
- if (mUpHorseSprite)
- mUpHorseSprite->setSpriteDirection(dir);
+ for_each_horses(mDownHorseSprites)
+ (*it)->setSpriteDirection(dir);
+ for_each_horses(mUpHorseSprites)
+ (*it)->setSpriteDirection(dir);
#endif
recalcSpritesOrder();
}
@@ -1608,10 +1610,10 @@ void Being::logic()
if (mEmotionSprite)
mEmotionSprite->update(time);
#ifdef EATHENA_SUPPORT
- if (mDownHorseSprite)
- mDownHorseSprite->update(time);
- if (mUpHorseSprite)
- mUpHorseSprite->update(time);
+ for_each_horses(mDownHorseSprites)
+ (*it)->update(time);
+ for_each_horses(mUpHorseSprites)
+ (*it)->update(time);
#endif
if (mAnimationEffect)
@@ -2676,22 +2678,33 @@ void Being::draw(Graphics *const graphics,
const int px = getActorX() + offsetX;
const int py = getActorY() + offsetY;
#ifdef EATHENA_SUPPORT
- if (mDownHorseSprite)
+ if (mHorseInfo)
{
- mDownHorseSprite->draw(graphics,
- px + mHorseInfo->downOffsetX,
- py + mHorseInfo->downOffsetY);
+ for_each_horses(mDownHorseSprites)
+ {
+ (*it)->draw(graphics,
+ px + mHorseInfo->downOffsetX,
+ py + mHorseInfo->downOffsetY);
+ }
+
+ ActorSprite::draw1(graphics, px, py);
+ drawSpriteAt(graphics, px, py);
+
+ for_each_horses(mUpHorseSprites)
+ {
+ (*it)->draw(graphics,
+ px + mHorseInfo->upOffsetX,
+ py + mHorseInfo->upOffsetY);
+ }
}
-#endif
- ActorSprite::draw1(graphics, px, py);
- drawSpriteAt(graphics, px, py);
-#ifdef EATHENA_SUPPORT
- if (mUpHorseSprite)
+ else
{
- mUpHorseSprite->draw(graphics,
- px + mHorseInfo->upOffsetX,
- py + mHorseInfo->upOffsetY);
+ ActorSprite::draw1(graphics, px, py);
+ drawSpriteAt(graphics, px, py);
}
+#else
+ ActorSprite::draw1(graphics, px, py);
+ drawSpriteAt(graphics, px, py);
#endif
}
}
@@ -4032,31 +4045,45 @@ bool Being::isSellShopEnabled() const
}
#ifdef EATHENA_SUPPORT
+void Being::removeHorse()
+{
+ delete_all(mUpHorseSprites);
+ mUpHorseSprites.clear();
+ delete_all(mDownHorseSprites);
+ mDownHorseSprites.clear();
+}
+
void Being::setRiding(const bool b)
{
if (b == mRiding)
return;
mRiding = b;
setAction(mAction, 0);
+ removeHorse();
if (b)
{
mHorseInfo = HorseDB::get(1);
if (mHorseInfo)
{
- mDownHorseSprite = mHorseInfo->downSprite;
- mUpHorseSprite = mHorseInfo->upSprite;
- }
- else
- {
- mDownHorseSprite = nullptr;
- mUpHorseSprite = nullptr;
+ FOR_EACH (SpriteRefs, it, mHorseInfo->downSprites)
+ {
+ SpriteReference *const ref = *it;
+ mDownHorseSprites.push_back(AnimatedSprite::load(
+ ref->sprite,
+ ref->variant));
+ }
+ FOR_EACH (SpriteRefs, it, mHorseInfo->upSprites)
+ {
+ SpriteReference *const ref = *it;
+ mUpHorseSprites.push_back(AnimatedSprite::load(
+ ref->sprite,
+ ref->variant));
+ }
}
}
else
{
mHorseInfo = nullptr;
- mDownHorseSprite = nullptr;
- mUpHorseSprite = nullptr;
}
}
#endif
diff --git a/src/being/being.h b/src/being/being.h
index 09da505c5..8aad79698 100644
--- a/src/being/being.h
+++ b/src/being/being.h
@@ -895,6 +895,8 @@ class Being notfinal : public ActorSprite,
void setRiding(const bool b) override final;
+ void removeHorse();
+
void setSellBoard(const std::string &text);
std::string getSellBoard() const A_WARN_UNUSED
@@ -1087,8 +1089,8 @@ class Being notfinal : public ActorSprite,
ChatObject *mChat;
HorseInfo *mHorseInfo;
#endif
- AnimatedSprite *mDownHorseSprite;
- AnimatedSprite *mUpHorseSprite;
+ std::vector<AnimatedSprite*> mDownHorseSprites;
+ std::vector<AnimatedSprite*> mUpHorseSprites;
int mX; // position in tiles
int mY; // position in tiles
diff --git a/src/resources/db/horsedb.cpp b/src/resources/db/horsedb.cpp
index 41754bd77..df1e6345c 100644
--- a/src/resources/db/horsedb.cpp
+++ b/src/resources/db/horsedb.cpp
@@ -21,13 +21,14 @@
#include "resources/db/horsedb.h"
-#include "animatedsprite.h"
#include "configuration.h"
#include "logger.h"
#include "resources/beingcommon.h"
#include "resources/horseinfo.h"
+#include "utils/dtor.h"
+
#include "debug.h"
namespace
@@ -38,11 +39,15 @@ namespace
}
#define loadSprite(name) \
- currentInfo->name = AnimatedSprite::load( \
- paths.getStringValue("sprites").append(std::string( \
- reinterpret_cast<const char*>( \
- spriteNode->xmlChildrenNode->content))), \
- XML::getProperty(spriteNode, "variant", 0))
+ { \
+ SpriteReference *const currentSprite = new SpriteReference; \
+ currentSprite->sprite = paths.getStringValue("sprites").append( \
+ std::string(reinterpret_cast<const char*>( \
+ spriteNode->xmlChildrenNode->content))); \
+ currentSprite->variant = XML::getProperty( \
+ spriteNode, "variant", 0); \
+ currentInfo->name.push_back(currentSprite); \
+ }
static void loadDownSprites(XmlNodePtrConst parentNode,
HorseInfo *currentInfo);
@@ -55,10 +60,18 @@ void HorseDB::load()
if (mLoaded)
unload();
- mUnknown.downSprite = AnimatedSprite::load(
+ SpriteReference *currentSprite = new SpriteReference;
+ currentSprite->sprite = paths.getStringValue("sprites").append(
paths.getStringValue("spriteErrorFile"));
- mUnknown.upSprite = AnimatedSprite::load(
+ currentSprite->variant = 0;
+ mUnknown.downSprites.push_back(currentSprite);
+
+ currentSprite = new SpriteReference;
+ currentSprite->sprite = paths.getStringValue("sprites").append(
paths.getStringValue("spriteErrorFile"));
+ currentSprite->variant = 0;
+ mUnknown.upSprites.push_back(currentSprite);
+
mUnknown.upOffsetX = 0;
mUnknown.upOffsetY = 0;
mUnknown.downOffsetX = 0;
@@ -129,7 +142,7 @@ void HorseDB::loadXmlFile(const std::string &fileName)
continue;
if (xmlNameEqual(spriteNode, "sprite"))
- loadSprite(downSprite);
+ loadSprite(downSprites)
if (xmlNameEqual(spriteNode, "down"))
loadDownSprites(spriteNode, currentInfo);
@@ -149,10 +162,7 @@ static void loadDownSprites(XmlNodePtrConst parentNode,
continue;
if (xmlNameEqual(spriteNode, "sprite"))
- {
- loadSprite(downSprite);
- return;
- }
+ loadSprite(downSprites)
}
}
@@ -165,10 +175,7 @@ static void loadUpSprites(XmlNodePtrConst parentNode,
continue;
if (xmlNameEqual(spriteNode, "sprite"))
- {
- loadSprite(upSprite);
- return;
- }
+ loadSprite(upSprites)
}
}
@@ -176,14 +183,14 @@ void HorseDB::unload()
{
FOR_EACH (HorseInfos::const_iterator, i, mHorseInfos)
{
- delete i->second->upSprite;
- delete i->second->downSprite;
+ delete_all(i->second->upSprites);
+ delete_all(i->second->downSprites);
delete i->second;
}
mHorseInfos.clear();
- delete mUnknown.upSprite;
- delete mUnknown.downSprite;
+ delete_all(mUnknown.upSprites);
+ delete_all(mUnknown.downSprites);
mLoaded = false;
}
diff --git a/src/resources/horseinfo.h b/src/resources/horseinfo.h
index 860700124..8a96902d8 100644
--- a/src/resources/horseinfo.h
+++ b/src/resources/horseinfo.h
@@ -22,15 +22,15 @@
#ifndef RESOURCES_HORSEINFO_H
#define RESOURCES_HORSEINFO_H
-#include "localconsts.h"
+#include "resources/spritereference.h"
+
+#include <vector>
-class AnimatedSprite;
+#include "localconsts.h"
struct HorseInfo final
{
HorseInfo() :
- downSprite(nullptr),
- upSprite(nullptr),
downOffsetX(0),
downOffsetY(0),
upOffsetX(0),
@@ -39,8 +39,8 @@ struct HorseInfo final
A_DELETE_COPY(HorseInfo)
- AnimatedSprite *downSprite;
- AnimatedSprite *upSprite;
+ std::vector<SpriteReference*> downSprites;
+ std::vector<SpriteReference*> upSprites;
int downOffsetX;
int downOffsetY;
int upOffsetX;
diff --git a/src/resources/spritedisplay.h b/src/resources/spritedisplay.h
index 3885eb65b..edeee10c8 100644
--- a/src/resources/spritedisplay.h
+++ b/src/resources/spritedisplay.h
@@ -43,6 +43,4 @@ struct SpriteDisplay final
StringVect particles;
};
-typedef std::vector<SpriteReference*>::const_iterator SpriteRefs;
-
#endif // RESOURCES_SPRITEDISPLAY_H
diff --git a/src/resources/spritereference.h b/src/resources/spritereference.h
index b61f54a19..a68b0d792 100644
--- a/src/resources/spritereference.h
+++ b/src/resources/spritereference.h
@@ -23,7 +23,7 @@
#ifndef RESOURCES_SPRITEREFERENCE_H
#define RESOURCES_SPRITEREFERENCE_H
-#include <string>
+#include "utils/stringvector.h"
#include "localconsts.h"
@@ -48,4 +48,6 @@ struct SpriteReference final
int variant;
};
+typedef std::vector<SpriteReference*>::const_iterator SpriteRefs;
+
#endif // RESOURCES_SPRITEREFERENCE_H