diff options
-rw-r--r-- | src/monster.cpp | 32 | ||||
-rw-r--r-- | src/resources/monsterdb.cpp | 4 | ||||
-rw-r--r-- | src/resources/monsterinfo.cpp | 3 | ||||
-rw-r--r-- | src/resources/monsterinfo.h | 9 |
4 files changed, 34 insertions, 14 deletions
diff --git a/src/monster.cpp b/src/monster.cpp index a62c1f4c..c472a21b 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -35,12 +35,26 @@ Monster::Monster(Uint16 id, Uint16 job, Map *map): Being(id, job, map) { const MonsterInfo& info = getInfo(); - std::string filename = info.getSprite(); - if (filename.empty()) - filename = "error.xml"; - mSprites[BASE_SPRITE] = - AnimatedSprite::load("graphics/sprites/" + filename); + // Setup Monster sprites + int c = BASE_SPRITE; + const std::list<std::string> &sprites = info.getSprites(); + for (std::list<std::string>::const_iterator i = sprites.begin(); + i != sprites.end(); + i++) + { + if (c == VECTOREND_SPRITE) break; + + std::string file = "graphics/sprites/" + *i; + mSprites[c] = AnimatedSprite::load(file); + c++; + } + + // Ensure that something is shown + if (c == BASE_SPRITE) + { + mSprites[c] = AnimatedSprite::load("graphics/sprites/error.xml"); + } const std::list<std::string> &particleEffects = info.getParticleEffects(); for (std::list<std::string>::const_iterator i = particleEffects.begin(); @@ -111,7 +125,13 @@ Monster::setAction(Action action, int attackType) if (currentAction != ACTION_INVALID) { - mSprites[BASE_SPRITE]->play(currentAction); + for (int i = 0; i < VECTOREND_SPRITE; i++) + { + if (mSprites[i]) + { + mSprites[i]->play(currentAction); + } + } mAction = action; } } diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp index 1d198a96..e0c47db8 100644 --- a/src/resources/monsterdb.cpp +++ b/src/resources/monsterdb.cpp @@ -44,7 +44,7 @@ MonsterDB::load() if (mLoaded) return; - mUnknown.setSprite("error.xml"); + mUnknown.addSprite("error.xml"); mUnknown.setName("unnamed"); logger->log("Initializing monster database..."); @@ -94,7 +94,7 @@ MonsterDB::load() { if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite")) { - currentInfo->setSprite((const char*) spriteNode->xmlChildrenNode->content); + currentInfo->addSprite((const char*) spriteNode->xmlChildrenNode->content); } else if (xmlStrEqual(spriteNode->name, BAD_CAST "sound")) { diff --git a/src/resources/monsterinfo.cpp b/src/resources/monsterinfo.cpp index bac9c35f..1e982213 100644 --- a/src/resources/monsterinfo.cpp +++ b/src/resources/monsterinfo.cpp @@ -23,8 +23,7 @@ #include "../utils/dtor.h" -MonsterInfo::MonsterInfo(): - mSprite("error.xml") +MonsterInfo::MonsterInfo() { } diff --git a/src/resources/monsterinfo.h b/src/resources/monsterinfo.h index f13c2f7c..88f6fb2b 100644 --- a/src/resources/monsterinfo.h +++ b/src/resources/monsterinfo.h @@ -67,7 +67,8 @@ class MonsterInfo setName(const std::string &name) { mName = name; } void - setSprite(const std::string &filename) { mSprite = filename; } + addSprite(const std::string &filename) + { mSprites.push_back(filename); } void setTargetCursorSize(Being::TargetCursorSize targetCursorSize) @@ -82,8 +83,8 @@ class MonsterInfo const std::string& getName() const { return mName; } - const std::string& - getSprite() const { return mSprite; } + const std::list<std::string>& + getSprites() const { return mSprites; } Being::TargetCursorSize getTargetCursorSize() const { return mTargetCursorSize; } @@ -106,7 +107,7 @@ class MonsterInfo private: std::string mName; - std::string mSprite; + std::list<std::string> mSprites; Being::TargetCursorSize mTargetCursorSize; std::map<MonsterSoundEvent, std::vector<std::string>* > mSounds; std::map<int, MonsterAttack*> mMonsterAttacks; |