| 1 |
/* |
| 2 |
* An effects manager |
| 3 |
* Copyright (C) 2008 Fate <fate.tmw@googlemail.com> |
| 4 |
* Copyright (C) 2008 Chuck Miller <shadowmil@gmail.com> |
| 5 |
* |
| 6 |
* This file is part of The Mana World. |
| 7 |
* |
| 8 |
* This program is free software; you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU General Public License as published by |
| 10 |
* the Free Software Foundation; either version 2 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* This program is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU General Public License |
| 19 |
* along with this program; if not, write to the Free Software |
| 20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 |
*/ |
| 22 |
|
| 23 |
#include "being.h" |
| 24 |
#include "effectmanager.h" |
| 25 |
#include "log.h" |
| 26 |
#include "particle.h" |
| 27 |
#include "sound.h" |
| 28 |
|
| 29 |
#include "utils/xml.h" |
| 30 |
|
| 31 |
EffectManager::EffectManager() |
| 32 |
{ |
| 33 |
XML::Document doc("effects.xml"); |
| 34 |
xmlNodePtr root = doc.rootNode(); |
| 35 |
|
| 36 |
if (!root || !xmlStrEqual(root->name, BAD_CAST "being-effects")) |
| 37 |
{ |
| 38 |
logger->log("Error loading being effects file: effects.xml"); |
| 39 |
return; |
| 40 |
} |
| 41 |
else |
| 42 |
{ |
| 43 |
logger->log("Effects are now loading"); |
| 44 |
} |
| 45 |
|
| 46 |
for_each_xml_child_node(node, root) |
| 47 |
{ |
| 48 |
if (xmlStrEqual(node->name, BAD_CAST "effect")) |
| 49 |
{ |
| 50 |
EffectDescription ed; |
| 51 |
ed.id = XML::getProperty(node, "id", -1); |
| 52 |
ed.GFX = XML::getProperty(node, "particle", ""); |
| 53 |
ed.SFX = XML::getProperty(node, "audio", ""); |
| 54 |
mEffects.push_back(ed); |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
EffectManager::~EffectManager() |
| 60 |
{ |
| 61 |
} |
| 62 |
|
| 63 |
bool EffectManager::trigger(int id, Being* being) |
| 64 |
{ |
| 65 |
bool rValue = false; |
| 66 |
for (std::list<EffectDescription>::iterator i = mEffects.begin(); i != mEffects.end(); ++i) |
| 67 |
{ |
| 68 |
if ((*i).id == id) |
| 69 |
{ |
| 70 |
rValue = true; |
| 71 |
if (!(*i).GFX.empty()) |
| 72 |
{ |
| 73 |
Particle *selfFX; |
| 74 |
selfFX = particleEngine->addEffect((*i).GFX, 0, 0); |
| 75 |
being->controlParticle(selfFX); |
| 76 |
} |
| 77 |
if (!(*i).SFX.empty()) |
| 78 |
sound.playSfx((*i).SFX); |
| 79 |
break; |
| 80 |
} |
| 81 |
} |
| 82 |
return rValue; |
| 83 |
} |
| 84 |
|
| 85 |
bool EffectManager::trigger(int id, int x, int y) |
| 86 |
{ |
| 87 |
bool rValue = false; |
| 88 |
for (std::list<EffectDescription>::iterator i = mEffects.begin(); i != mEffects.end(); ++i) |
| 89 |
{ |
| 90 |
if ((*i).id == id) |
| 91 |
{ |
| 92 |
rValue = true; |
| 93 |
if (!(*i).GFX.empty()) |
| 94 |
particleEngine->addEffect((*i).GFX, x, y); |
| 95 |
if (!(*i).SFX.empty()) |
| 96 |
sound.playSfx((*i).SFX); |
| 97 |
break; |
| 98 |
} |
| 99 |
} |
| 100 |
return rValue; |
| 101 |
} |