00001 /* 00002 * The Mana World 00003 * Copyright (C) 2004 The Mana World Development Team 00004 * 00005 * This file is part of The Mana World. 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 */ 00021 00022 #include "resources/monsterinfo.h" 00023 00024 #include "utils/dtor.h" 00025 00026 MonsterInfo::MonsterInfo() 00027 { 00028 } 00029 00030 MonsterInfo::~MonsterInfo() 00031 { 00032 // kill vectors in mSoundEffects 00033 delete_all(mSounds); 00034 delete_all(mMonsterAttacks); 00035 mSounds.clear(); 00036 } 00037 00038 void MonsterInfo::addSound(MonsterSoundEvent event, const std::string &filename) 00039 { 00040 if (mSounds.find(event) == mSounds.end()) 00041 { 00042 mSounds[event] = new std::vector<std::string>; 00043 } 00044 00045 mSounds[event]->push_back("sfx/" + filename); 00046 } 00047 00048 const std::string &MonsterInfo::getSound(MonsterSoundEvent event) const 00049 { 00050 static std::string empty(""); 00051 std::map<MonsterSoundEvent, std::vector<std::string>* >::const_iterator i = 00052 mSounds.find(event); 00053 return (i == mSounds.end()) ? empty : 00054 i->second->at(rand() % i->second->size()); 00055 } 00056 00057 const std::string &MonsterInfo::getAttackParticleEffect(int attackType) const 00058 { 00059 static std::string empty(""); 00060 std::map<int, MonsterAttack*>::const_iterator i = 00061 mMonsterAttacks.find(attackType); 00062 return (i == mMonsterAttacks.end()) ? empty : (*i).second->particleEffect; 00063 } 00064 00065 SpriteAction MonsterInfo::getAttackAction(int attackType) const 00066 { 00067 std::map<int, MonsterAttack*>::const_iterator i = 00068 mMonsterAttacks.find(attackType); 00069 return (i == mMonsterAttacks.end()) ? ACTION_ATTACK : (*i).second->action; 00070 } 00071 00072 void MonsterInfo::addMonsterAttack(int id, 00073 const std::string &particleEffect, 00074 SpriteAction action) 00075 { 00076 MonsterAttack *a = new MonsterAttack; 00077 a->particleEffect = particleEffect; 00078 a->action = action; 00079 mMonsterAttacks[id] = a; 00080 } 00081 00082 void MonsterInfo::addParticleEffect(const std::string &filename) 00083 { 00084 mParticleEffects.push_back(filename); 00085 }