From 9dd811b55587aeb76344b835006cb4a01601bb5d Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 23 Mar 2008 01:27:13 +0000 Subject: Merged revisions 3823,3825-3826,3829,3831-3839,3841-3842 via svnmerge from https://themanaworld.svn.sourceforge.net/svnroot/themanaworld/tmw/branches/0.0 ........ r3823 | crush_tmw | 2007-12-28 19:36:58 +0100 (Fri, 28 Dec 2007) | 1 line 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. ........ r3826 | crush_tmw | 2007-12-30 01:02:14 +0100 (Sun, 30 Dec 2007) | 1 line Added a key for targeting the nearest player character based on patches by Trinexx. Some mapping fixes at snake dungeon map. ........ r3839 | the_enemy | 2008-01-13 17:28:50 +0100 (Sun, 13 Jan 2008) | 1 line Fixed non-default location music loading ........ r3842 | crush_tmw | 2008-01-14 11:48:13 +0100 (Mon, 14 Jan 2008) | 1 line ixed an error in Davids last commit (couldn't compile that way). ........ --- src/resources/monsterdb.cpp | 26 ++++++++++------ src/resources/monsterinfo.cpp | 63 ++++++++++++++------------------------- src/resources/monsterinfo.h | 18 +++++++---- src/resources/resourcemanager.cpp | 21 +++++++++++++ src/resources/resourcemanager.h | 8 +++++ 5 files changed, 82 insertions(+), 54 deletions(-) (limited to 'src/resources') diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp index fd200e4e..e7e855fa 100644 --- a/src/resources/monsterdb.cpp +++ b/src/resources/monsterdb.cpp @@ -78,13 +78,11 @@ MonsterDB::load() for_each_xml_child_node(monsterNode, rootNode) { if (!xmlStrEqual(monsterNode->name, BAD_CAST "monster")) - { continue; - } MonsterInfo *currentInfo = new MonsterInfo(); - currentInfo->setName (XML::getProperty(monsterNode, "name", "unnamed")); + currentInfo->setName(XML::getProperty(monsterNode, "name", "unnamed")); std::string targetCursor; targetCursor = XML::getProperty(monsterNode, "targetCursor", "medium"); @@ -102,7 +100,8 @@ MonsterDB::load() } else { - logger->log("MonsterDB: Unknown target cursor type \"%s\" for %s - using medium sized one", + logger->log("MonsterDB: Unknown target cursor type \"%s\" for %s " + "- using medium sized one", targetCursor.c_str(), currentInfo->getName().c_str()); currentInfo->setTargetCursorSize(Being::TC_MEDIUM); } @@ -138,17 +137,26 @@ MonsterDB::load() } else { - logger->log("MonsterDB: Warning, sound effect %s for unknown event %s of monster %s", - filename, event.c_str(), currentInfo->getName().c_str()); + logger->log("MonsterDB: Warning, sound effect %s for " + "unknown event %s of monster %s", + filename, event.c_str(), + currentInfo->getName().c_str()); } } else if (xmlStrEqual(spriteNode->name, BAD_CAST "attack")) { - int id = XML::getProperty(spriteNode, "id", 0); - std::string particleEffect = XML::getProperty(spriteNode, "particle-effect", ""); - SpriteAction spriteAction = SpriteDef::makeSpriteAction(XML::getProperty(spriteNode, "action", "attack")); + const int id = XML::getProperty(spriteNode, "id", 0); + const std::string particleEffect = XML::getProperty( + spriteNode, "particle-effect", ""); + SpriteAction spriteAction = SpriteDef::makeSpriteAction( + XML::getProperty(spriteNode, "action", "attack")); currentInfo->addMonsterAttack(id, particleEffect, spriteAction); } + else 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 a7ad51a3..0af09c53 100644 --- a/src/resources/monsterinfo.cpp +++ b/src/resources/monsterinfo.cpp @@ -30,20 +30,17 @@ MonsterInfo::MonsterInfo(): mSprite("error.xml") { - } MonsterInfo::~MonsterInfo() { // kill vectors in mSoundEffects - for_each (mSounds.begin(), mSounds.end(), - make_dtor(mSounds)); + for_each(mSounds.begin(), mSounds.end(), make_dtor(mSounds)); mSounds.clear(); } - void -MonsterInfo::addSound(MonsterSoundEvent event, std::string filename) +MonsterInfo::addSound(MonsterSoundEvent event, const std::string &filename) { if (mSounds.find(event) == mSounds.end()) { @@ -53,59 +50,45 @@ MonsterInfo::addSound(MonsterSoundEvent event, std::string filename) mSounds[event]->push_back("sfx/" + filename); } - const std::string & MonsterInfo::getSound(MonsterSoundEvent event) const { - static std::string nothing(""); - std::map* >::const_iterator i; - i = mSounds.find(event); - if (i == mSounds.end()) - { - return nothing; - } - else - { - return i->second->at(rand()%i->second->size()); - } + static std::string empty(""); + std::map* >::const_iterator i = + mSounds.find(event); + return (i == mSounds.end()) ? empty : + i->second->at(rand() % i->second->size()); } const std::string & MonsterInfo::getAttackParticleEffect(int attackType) const { - static std::string nothing(""); - std::map::const_iterator i; - i = mMonsterAttacks.find(attackType); - if (i == mMonsterAttacks.end()) - { - return nothing; - } - else - { - return (*i).second->particleEffect; - } + static std::string empty(""); + std::map::const_iterator i = + mMonsterAttacks.find(attackType); + return (i == mMonsterAttacks.end()) ? empty : (*i).second->particleEffect; } SpriteAction MonsterInfo::getAttackAction(int attackType) const { - std::map::const_iterator i; - i = mMonsterAttacks.find(attackType); - if (i == mMonsterAttacks.end()) - { - return ACTION_ATTACK; - } - else - { - return (*i).second->action; - } + std::map::const_iterator i = + mMonsterAttacks.find(attackType); + return (i == mMonsterAttacks.end()) ? ACTION_ATTACK : (*i).second->action; } void -MonsterInfo::addMonsterAttack (int id, const std::string &particleEffect, SpriteAction action) +MonsterInfo::addMonsterAttack(int id, + const std::string &particleEffect, + SpriteAction action) { - MonsterAttack* a = new MonsterAttack; + MonsterAttack *a = new MonsterAttack; a->particleEffect = particleEffect; a->action = action; mMonsterAttacks[id] = a; } + +void MonsterInfo::addParticleEffect(const std::string &filename) +{ + mParticleEffects.push_back(filename); +} diff --git a/src/resources/monsterinfo.h b/src/resources/monsterinfo.h index 840f37be..f34a3ea9 100644 --- a/src/resources/monsterinfo.h +++ b/src/resources/monsterinfo.h @@ -27,6 +27,7 @@ #include #include #include +#include #include "../being.h" @@ -65,17 +66,20 @@ class MonsterInfo ~MonsterInfo(); void - setName(std::string name) { mName = name; } + setName(const std::string &name) { mName = name; } void - setSprite(std::string filename) { mSprite = filename; } + setSprite(const std::string &filename) { mSprite = filename; } void setTargetCursorSize(Being::TargetCursorSize targetCursorSize) { mTargetCursorSize = targetCursorSize; } void - addSound(MonsterSoundEvent event, std::string filename); + addSound(MonsterSoundEvent event, const std::string &filename); + + void + addParticleEffect(const std::string &filename); const std::string& getName() const { return mName; } @@ -89,7 +93,9 @@ class MonsterInfo const std::string& getSound(MonsterSoundEvent event) const; - void addMonsterAttack (int id, const std::string &particleEffect, SpriteAction action); + void addMonsterAttack(int id, + const std::string &particleEffect, + SpriteAction action); const std::string& getAttackParticleEffect(int attackType) const; @@ -97,7 +103,8 @@ class MonsterInfo SpriteAction getAttackAction(int attackType) const; - + const std::list& + getParticleEffects() const { return mParticleEffects; } private: std::string mName; @@ -105,6 +112,7 @@ class MonsterInfo Being::TargetCursorSize mTargetCursorSize; std::map* > mSounds; std::map mMonsterAttacks; + std::list mParticleEffects; }; #endif diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index fb9da9d7..59202ad8 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -200,6 +200,27 @@ ResourceManager::isDirectory(const std::string &path) return PHYSFS_isDirectory(path.c_str()); } +std::string +ResourceManager::getPath(const std::string &file) +{ + // get the real path to the file + const char* tmp = PHYSFS_getRealDir(file.c_str()); + std::string path; + + // if the file is not in the search path, then its NULL + if (tmp) + { + path = std::string(tmp) + "/" + file; + } + else + { + // if not found in search path return the default path + path = std::string(TMW_DATADIR) + std::string("data") + "/" + file; + } + + return path; +} + Resource *ResourceManager::get(std::string const &idPath, generator fun, void *data) { // Check if the id exists, and return the value if it does. diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h index abfd629a..da85e2f9 100644 --- a/src/resources/resourcemanager.h +++ b/src/resources/resourcemanager.h @@ -104,6 +104,14 @@ class ResourceManager */ bool isDirectory(const std::string &path); + + /** + * Returns the real path to a file + * + * @param file The file to get the real path to. + * @return The real path. + */ + std::string getPath(const std::string &file); /** * Creates a resource and adds it to the resource map. -- cgit v1.2.3-70-g09d2