00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "being.h"
00024 #include "effectmanager.h"
00025 #include "log.h"
00026 #include "particle.h"
00027 #include "sound.h"
00028
00029 #include "utils/xml.h"
00030
00031 EffectManager::EffectManager()
00032 {
00033 XML::Document doc("effects.xml");
00034 xmlNodePtr root = doc.rootNode();
00035
00036 if (!root || !xmlStrEqual(root->name, BAD_CAST "being-effects"))
00037 {
00038 logger->log("Error loading being effects file: effects.xml");
00039 return;
00040 }
00041 else
00042 {
00043 logger->log("Effects are now loading");
00044 }
00045
00046 for_each_xml_child_node(node, root)
00047 {
00048 if (xmlStrEqual(node->name, BAD_CAST "effect"))
00049 {
00050 EffectDescription ed;
00051 ed.id = XML::getProperty(node, "id", -1);
00052 ed.GFX = XML::getProperty(node, "particle", "");
00053 ed.SFX = XML::getProperty(node, "audio", "");
00054 mEffects.push_back(ed);
00055 }
00056 }
00057 }
00058
00059 EffectManager::~EffectManager()
00060 {
00061 }
00062
00063 bool EffectManager::trigger(int id, Being* being)
00064 {
00065 bool rValue = false;
00066 for (std::list<EffectDescription>::iterator i = mEffects.begin(); i != mEffects.end(); ++i)
00067 {
00068 if ((*i).id == id)
00069 {
00070 rValue = true;
00071 if (!(*i).GFX.empty())
00072 {
00073 Particle *selfFX;
00074 selfFX = particleEngine->addEffect((*i).GFX, 0, 0);
00075 being->controlParticle(selfFX);
00076 }
00077 if (!(*i).SFX.empty())
00078 sound.playSfx((*i).SFX);
00079 break;
00080 }
00081 }
00082 return rValue;
00083 }
00084
00085 bool EffectManager::trigger(int id, int x, int y)
00086 {
00087 bool rValue = false;
00088 for (std::list<EffectDescription>::iterator i = mEffects.begin(); i != mEffects.end(); ++i)
00089 {
00090 if ((*i).id == id)
00091 {
00092 rValue = true;
00093 if (!(*i).GFX.empty())
00094 particleEngine->addEffect((*i).GFX, x, y);
00095 if (!(*i).SFX.empty())
00096 sound.playSfx((*i).SFX);
00097 break;
00098 }
00099 }
00100 return rValue;
00101 }