From df2d513ba368f24cbec3ece3ff0084093a568e86 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Fri, 28 Dec 2007 18:36:58 +0000 Subject: Added the possibility to assign particle effects to monsters in the monster database. Added flame particle effect to fire goblin as a proof of concept. --- src/being.cpp | 3 ++- src/monster.cpp | 14 +++++++++++++- src/resources/monsterdb.cpp | 6 ++++++ src/resources/monsterinfo.cpp | 5 +++++ src/resources/monsterinfo.h | 8 ++++++++ 5 files changed, 34 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/being.cpp b/src/being.cpp index b068270b..ad60dc2f 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -83,7 +83,6 @@ Being::~Being() { std::for_each(mSprites.begin(), mSprites.end(), make_dtor(mSprites)); clearPath(); - setMap(NULL); for ( std::list::iterator i = mChildParticleEffects.begin(); i != mChildParticleEffects.end(); @@ -92,6 +91,8 @@ Being::~Being() (*i)->kill(); } + setMap(NULL); + instances--; if (instances == 0) diff --git a/src/monster.cpp b/src/monster.cpp index 779b4f56..e2a07e86 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -26,6 +26,7 @@ #include "animatedsprite.h" #include "game.h" #include "sound.h" +#include "particle.h" #include "resources/monsterdb.h" @@ -35,7 +36,9 @@ Monster::Monster(Uint32 id, Uint16 job, Map *map): Being(id, job, map) { - std::string filename = MonsterDB::get(job - 1002).getSprite(); + const MonsterInfo& info = MonsterDB::get(job - 1002); + + std::string filename = info.getSprite(); if (filename != "") { mSprites[BASE_SPRITE] = AnimatedSprite::load( @@ -45,6 +48,15 @@ Monster::Monster(Uint32 id, Uint16 job, Map *map): { mSprites[BASE_SPRITE] = AnimatedSprite::load("graphics/sprites/error.xml"); } + + const std::list &particleEffects = info.getParticleEffects(); + for ( std::list::const_iterator i = particleEffects.begin(); + i != particleEffects.end(); + i++ + ) + { + controlParticle(particleEngine->addEffect((*i), 0, 0)); + } } void diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp index 84e3a219..e007eda0 100644 --- a/src/resources/monsterdb.cpp +++ b/src/resources/monsterdb.cpp @@ -142,6 +142,12 @@ MonsterDB::load() filename, event.c_str(), currentInfo->getName().c_str()); } } + + if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx")) + { + currentInfo->addParticleEffect( + (const char*) spriteNode->xmlChildrenNode->content); + } } mMonsterInfos[XML::getProperty(monsterNode, "id", 0)] = currentInfo; } diff --git a/src/resources/monsterinfo.cpp b/src/resources/monsterinfo.cpp index c4c9ce10..8238dc3e 100644 --- a/src/resources/monsterinfo.cpp +++ b/src/resources/monsterinfo.cpp @@ -70,3 +70,8 @@ MonsterInfo::getSound(MonsterSoundEvent event) const return i->second->at(rand()%i->second->size()); } } + +void MonsterInfo::addParticleEffect(std::string filename) +{ + mParticleEffects.push_back(filename); +} diff --git a/src/resources/monsterinfo.h b/src/resources/monsterinfo.h index 7d49db1a..d9d17510 100644 --- a/src/resources/monsterinfo.h +++ b/src/resources/monsterinfo.h @@ -27,6 +27,7 @@ #include #include #include +#include #include "../being.h" @@ -71,6 +72,9 @@ class MonsterInfo void addSound(MonsterSoundEvent event, std::string filename); + void + addParticleEffect(std::string filename); + const std::string& getName() const { return mName; } @@ -83,11 +87,15 @@ class MonsterInfo std::string getSound(MonsterSoundEvent event) const; + const std::list& + getParticleEffects() const { return mParticleEffects; } + private: std::string mName; std::string mSprite; Being::TargetCursorSize mTargetCursorSize; std::map* > mSounds; + std::list mParticleEffects; }; #endif -- cgit v1.2.3-70-g09d2