diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-03-21 16:52:59 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-03-21 16:52:59 +0300 |
commit | ac4e40a1408ad4d6fbcfce9d2bc6a0bc187ea5a4 (patch) | |
tree | 13314fbbb4945414b8be5d1d0236e1c41f88e8c8 | |
parent | 68857593b01b73d33fa1a12011cf9cb402db8a73 (diff) | |
download | mv-ac4e40a1408ad4d6fbcfce9d2bc6a0bc187ea5a4.tar.gz mv-ac4e40a1408ad4d6fbcfce9d2bc6a0bc187ea5a4.tar.bz2 mv-ac4e40a1408ad4d6fbcfce9d2bc6a0bc187ea5a4.tar.xz mv-ac4e40a1408ad4d6fbcfce9d2bc6a0bc187ea5a4.zip |
Split StatusEffect into StatusEffect and StatusEffectDB.
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/being/actorsprite.cpp | 12 | ||||
-rw-r--r-- | src/client.cpp | 6 | ||||
-rw-r--r-- | src/gui/popups/beingpopup.cpp | 4 | ||||
-rw-r--r-- | src/resources/db/statuseffectdb.cpp | 192 | ||||
-rw-r--r-- | src/resources/db/statuseffectdb.h | 62 | ||||
-rw-r--r-- | src/statuseffect.cpp | 156 | ||||
-rw-r--r-- | src/statuseffect.h | 30 |
9 files changed, 271 insertions, 195 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 114a793ad..b7cad1890 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -737,6 +737,8 @@ SET(SRCS resources/skilltype.h resources/db/sounddb.cpp resources/db/sounddb.h + resources/db/statuseffectdb.cpp + resources/db/statuseffectdb.h resources/db/weaponsdb.cpp resources/db/weaponsdb.h resources/soundeffect.cpp diff --git a/src/Makefile.am b/src/Makefile.am index bb54a285c..bb16842c9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1188,6 +1188,8 @@ manaplus_SOURCES += main.cpp \ resources/db/skillunitdb.h \ resources/db/sounddb.cpp \ resources/db/sounddb.h \ + resources/db/statuseffectdb.cpp \ + resources/db/statuseffectdb.h \ resources/db/weaponsdb.cpp \ resources/db/weaponsdb.h \ resources/iteminfo.h \ diff --git a/src/being/actorsprite.cpp b/src/being/actorsprite.cpp index f444bdd71..4424d4e07 100644 --- a/src/being/actorsprite.cpp +++ b/src/being/actorsprite.cpp @@ -40,6 +40,8 @@ #include "resources/sprite/imagesprite.h" #include "resources/sprite/spritereference.h" +#include "resources/db/statuseffectdb.h" + #include "utils/checkutils.h" #include "utils/delete2.h" #include "utils/timer.h" @@ -116,7 +118,7 @@ void ActorSprite::logic() FOR_EACH (std::set<int>::const_iterator, it, mStatusEffects) { const StatusEffect *const effect - = StatusEffect::getStatusEffect(*it, Enable_true); + = StatusEffectDB::getStatusEffect(*it, Enable_true); if (effect && effect->particleEffectIsPersistent()) updateStatusEffect(*it, Enable_true); } @@ -193,7 +195,7 @@ void ActorSprite::setStatusEffectBlock(const int offset, for (unsigned i = 0; i < STATUS_EFFECTS; i++) { const bool val = (newEffects & (1 << i)) > 0; - const int index = StatusEffect::blockEffectIndexToEffectIndex( + const int index = StatusEffectDB::blockEffectIndexToEffectIndex( offset + i); // block-id (offset + i) to id (index) if (index != -1) @@ -252,15 +254,15 @@ void ActorSprite::setStatusEffectOpiton0(const uint32_t option) void ActorSprite::updateStunMode(const int oldMode, const int newMode) { - handleStatusEffect(StatusEffect::getStatusEffect( + handleStatusEffect(StatusEffectDB::getStatusEffect( oldMode, Enable_false), -1); - handleStatusEffect(StatusEffect::getStatusEffect( + handleStatusEffect(StatusEffectDB::getStatusEffect( newMode, Enable_true), -1); } void ActorSprite::updateStatusEffect(const int index, const Enable newStatus) { - StatusEffect *const effect = StatusEffect::getStatusEffect( + StatusEffect *const effect = StatusEffectDB::getStatusEffect( index, newStatus); if (!effect) return; diff --git a/src/client.cpp b/src/client.cpp index 387eaea63..696389c69 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -32,7 +32,6 @@ #include "settings.h" #include "soundmanager.h" #include "spellmanager.h" -#include "statuseffect.h" #include "units.h" #include "being/localplayer.h" @@ -123,6 +122,7 @@ #include "resources/db/palettedb.h" #include "resources/db/petdb.h" #include "resources/db/skillunitdb.h" +#include "resources/db/statuseffectdb.h" #include "resources/db/weaponsdb.h" #include "utils/cpu.h" @@ -596,7 +596,7 @@ void Client::gameClear() WeaponsDB::unload(); PaletteDB::unload(); PETDB::unload(); - StatusEffect::unload(); + StatusEffectDB::unload(); ModDB::unload(); if (loginHandler) @@ -1300,7 +1300,7 @@ int Client::gameExec() HorseDB::load(); EmoteDB::load(); // ModDB::load(); - StatusEffect::load(); + StatusEffectDB::load(); Units::loadUnits(); EquipmentWindow::prepareSlotNames(); diff --git a/src/gui/popups/beingpopup.cpp b/src/gui/popups/beingpopup.cpp index aad81d3cd..b5434eae0 100644 --- a/src/gui/popups/beingpopup.cpp +++ b/src/gui/popups/beingpopup.cpp @@ -37,6 +37,8 @@ #include "resources/chatobject.h" +#include "resources/db/statuseffectdb.h" + #include "utils/gettext.h" #include "utils/stringutils.h" @@ -344,7 +346,7 @@ void BeingPopup::show(const int x, const int y, Being *const b) FOR_EACH (std::set<int>::const_iterator, it, effects) { const StatusEffect *const effect = - StatusEffect::getStatusEffect( + StatusEffectDB::getStatusEffect( *it, Enable_true); if (!effect) diff --git a/src/resources/db/statuseffectdb.cpp b/src/resources/db/statuseffectdb.cpp new file mode 100644 index 000000000..60ea6ea17 --- /dev/null +++ b/src/resources/db/statuseffectdb.cpp @@ -0,0 +1,192 @@ +/* + * The ManaPlus Client + * Copyright (C) 2008-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2016 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "resources/db/statuseffectdb.h" + +#include "configuration.h" +#include "soundmanager.h" +#include "statuseffect.h" + +#include "const/resources/spriteaction.h" + +#include "gui/widgets/tabs/chat/chattab.h" + +#include "particle/particle.h" + +#include "listeners/debugmessagelistener.h" + +#include "resources/beingcommon.h" + +#include "resources/sprite/animatedsprite.h" + +#include "debug.h" + +namespace +{ + typedef std::map<int, StatusEffect *> status_effect_map[2]; + bool mLoaded = false; + status_effect_map statusEffects; + std::map<int, int> blockEffectIndexMap; +} // namespace + +int StatusEffectDB::blockEffectIndexToEffectIndex(const int blockIndex) +{ + if (blockEffectIndexMap.find(blockIndex) == blockEffectIndexMap.end()) + return -1; + return blockEffectIndexMap[blockIndex]; +} + +StatusEffect *StatusEffectDB::getStatusEffect(const int index, + const Enable enabling) +{ + std::map<int, StatusEffect *> &effects + = statusEffects[enabling == Enable_true]; + const std::map<int, StatusEffect *>::iterator it = effects.find(index); + if (it != effects.end()) + return (*it).second; + if (config.getBoolValue("unimplimentedLog")) + { + const std::string str = strprintf("Missing status effect: %d", index); + logger->log(str); + DebugMessageListener::distributeEvent(str); + } + return nullptr; +} + +void StatusEffectDB::load() +{ + if (mLoaded) + unload(); + + loadXmlFile(paths.getStringValue("statusEffectsFile")); + loadXmlFile(paths.getStringValue("statusEffectsPatchFile")); + loadXmlDir("statusEffectsPatchDir", loadXmlFile); + + mLoaded = true; +} + +void StatusEffectDB::loadXmlFile(const std::string &fileName) +{ + XML::Document doc(fileName, UseResman_true, SkipError_false); + const XmlNodePtrConst rootNode = doc.rootNode(); + + if (!rootNode || !xmlNameEqual(rootNode, "status-effects")) + { + logger->log("Error loading status effects file: " + fileName); + return; + } + + for_each_xml_child_node(node, rootNode) + { + if (xmlNameEqual(node, "include")) + { + const std::string incName = XML::getProperty(node, "name", ""); + if (!incName.empty()) + loadXmlFile(incName); + continue; + } + + status_effect_map *the_map = nullptr; + + const int index = atoi(XML::getProperty(node, "id", "-1").c_str()); + + if (xmlNameEqual(node, "status-effect")) + { + the_map = &statusEffects; + const int block_index = atoi(XML::getProperty( + node, "block-id", "-1").c_str()); + + if (index >= 0 && block_index >= 0) + blockEffectIndexMap[block_index] = index; + } + + if (the_map) + { + StatusEffect *startEffect = (*the_map)[1][index]; + StatusEffect *endEffect = (*the_map)[0][index]; + const std::string name = XML::getProperty(node, "name", ""); + if (!startEffect) + startEffect = new StatusEffect; + if (!endEffect) + endEffect = new StatusEffect; + + startEffect->mName = name; + startEffect->mIsPoison = + (name == paths.getStringValue("poisonEffectName")); + startEffect->mIsCart = + (name == paths.getStringValue("cartEffectName")); + startEffect->mIsRiding = + (name == paths.getStringValue("ridingEffectName")); + startEffect->mIsTrickDead = + (name == paths.getStringValue("trickDeadEffectName")); + startEffect->mIsPostDelay = + (name == paths.getStringValue("postDelayName")); + startEffect->mMessage = XML::getProperty( + node, "start-message", ""); + startEffect->mSFXEffect = XML::getProperty( + node, "start-audio", ""); + startEffect->mParticleEffect = XML::getProperty( + node, "start-particle", ""); + + startEffect->mIcon = XML::getProperty(node, "icon", ""); + startEffect->mAction = XML::getProperty(node, "action", ""); + startEffect->mPersistentParticleEffect = (XML::getProperty( + node, "persistent-particle-effect", "no")) != "no"; + + endEffect->mName = startEffect->mName; + endEffect->mIsPoison = startEffect->mIsPoison; + endEffect->mIsCart = startEffect->mIsCart; + endEffect->mIsRiding = startEffect->mIsRiding; + endEffect->mIsTrickDead = startEffect->mIsTrickDead; + endEffect->mIsPostDelay = startEffect->mIsPostDelay; + endEffect->mMessage = XML::getProperty(node, "end-message", ""); + endEffect->mSFXEffect = XML::getProperty(node, "end-audio", ""); + endEffect->mParticleEffect = XML::getProperty( + node, "end-particle", ""); + + (*the_map)[1][index] = startEffect; + (*the_map)[0][index] = endEffect; + } + } +} + +static void unloadMap(std::map<int, StatusEffect *> &map) +{ + for (std::map<int, StatusEffect *>::iterator it = map.begin(); + it != map.end(); ++it) + { + delete (*it).second; + } + + map.clear(); +} + +void StatusEffectDB::unload() +{ + if (!mLoaded) + return; + + unloadMap(statusEffects[0]); + unloadMap(statusEffects[1]); + + mLoaded = false; +} diff --git a/src/resources/db/statuseffectdb.h b/src/resources/db/statuseffectdb.h new file mode 100644 index 000000000..d239c1903 --- /dev/null +++ b/src/resources/db/statuseffectdb.h @@ -0,0 +1,62 @@ +/* + * The ManaPlus Client + * Copyright (C) 2008-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2016 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef RESOURCES_DB_STATUSEFFECTDB_H +#define RESOURCES_DB_STATUSEFFECTDB_H + +#include "enums/simpletypes/enable.h" + +#include <string> + +#include "localconsts.h" + +class StatusEffect; + +namespace StatusEffectDB +{ + /** + * Retrieves a status effect. + * + * \param index Index of the status effect. + * \param enabling Whether to retrieve the activating effect (true) or + * the deactivating effect (false). + */ + StatusEffect *getStatusEffect(const int index, + const Enable enabling) A_WARN_UNUSED; + + /** + * Maps a block effect index to its corresponding effect index. Block + * effect indices are used for opt2/opt3/status.option blocks; their + * mapping to regular effect indices is handled in the config file. + * + * Returns -1 on failure. + */ + int blockEffectIndexToEffectIndex(const int blocKIndex) A_WARN_UNUSED; + + void load(); + + void loadXmlFile(const std::string &fileName); + + void unload(); +} // namespace StatusEffectDB + +#endif // RESOURCES_DB_STATUSEFFECTDB_H diff --git a/src/statuseffect.cpp b/src/statuseffect.cpp index 591b70815..26e6d97b7 100644 --- a/src/statuseffect.cpp +++ b/src/statuseffect.cpp @@ -39,10 +39,6 @@ #include "debug.h" -static void unloadMap(std::map<int, StatusEffect *> &map); - -bool StatusEffect::mLoaded = false; - StatusEffect::StatusEffect() : mMessage(), mSFXEffect(), @@ -103,155 +99,3 @@ std::string StatusEffect::getAction() const else return mAction; } - - -// -- initialisation and static parts -- - - -typedef std::map<int, StatusEffect *> status_effect_map[2]; - -static status_effect_map statusEffects; -static std::map<int, int> blockEffectIndexMap; - -int StatusEffect::blockEffectIndexToEffectIndex(const int blockIndex) -{ - if (blockEffectIndexMap.find(blockIndex) == blockEffectIndexMap.end()) - return -1; - return blockEffectIndexMap[blockIndex]; -} - -StatusEffect *StatusEffect::getStatusEffect(const int index, - const Enable enabling) -{ - std::map<int, StatusEffect *> &effects - = statusEffects[enabling == Enable_true]; - const std::map<int, StatusEffect *>::iterator it = effects.find(index); - if (it != effects.end()) - return (*it).second; - if (config.getBoolValue("unimplimentedLog")) - { - const std::string str = strprintf("Missing status effect: %d", index); - logger->log(str); - DebugMessageListener::distributeEvent(str); - } - return nullptr; -} - -void StatusEffect::load() -{ - if (mLoaded) - unload(); - - loadXmlFile(paths.getStringValue("statusEffectsFile")); - loadXmlFile(paths.getStringValue("statusEffectsPatchFile")); - loadXmlDir("statusEffectsPatchDir", loadXmlFile); - - mLoaded = true; -} - -void StatusEffect::loadXmlFile(const std::string &fileName) -{ - XML::Document doc(fileName, UseResman_true, SkipError_false); - const XmlNodePtrConst rootNode = doc.rootNode(); - - if (!rootNode || !xmlNameEqual(rootNode, "status-effects")) - { - logger->log("Error loading status effects file: " + fileName); - return; - } - - for_each_xml_child_node(node, rootNode) - { - if (xmlNameEqual(node, "include")) - { - const std::string incName = XML::getProperty(node, "name", ""); - if (!incName.empty()) - loadXmlFile(incName); - continue; - } - - status_effect_map *the_map = nullptr; - - const int index = atoi(XML::getProperty(node, "id", "-1").c_str()); - - if (xmlNameEqual(node, "status-effect")) - { - the_map = &statusEffects; - const int block_index = atoi(XML::getProperty( - node, "block-id", "-1").c_str()); - - if (index >= 0 && block_index >= 0) - blockEffectIndexMap[block_index] = index; - } - - if (the_map) - { - StatusEffect *startEffect = (*the_map)[1][index]; - StatusEffect *endEffect = (*the_map)[0][index]; - const std::string name = XML::getProperty(node, "name", ""); - if (!startEffect) - startEffect = new StatusEffect; - if (!endEffect) - endEffect = new StatusEffect; - - startEffect->mName = name; - startEffect->mIsPoison = - (name == paths.getStringValue("poisonEffectName")); - startEffect->mIsCart = - (name == paths.getStringValue("cartEffectName")); - startEffect->mIsRiding = - (name == paths.getStringValue("ridingEffectName")); - startEffect->mIsTrickDead = - (name == paths.getStringValue("trickDeadEffectName")); - startEffect->mIsPostDelay = - (name == paths.getStringValue("postDelayName")); - startEffect->mMessage = XML::getProperty( - node, "start-message", ""); - startEffect->mSFXEffect = XML::getProperty( - node, "start-audio", ""); - startEffect->mParticleEffect = XML::getProperty( - node, "start-particle", ""); - - startEffect->mIcon = XML::getProperty(node, "icon", ""); - startEffect->mAction = XML::getProperty(node, "action", ""); - startEffect->mPersistentParticleEffect = (XML::getProperty( - node, "persistent-particle-effect", "no")) != "no"; - - endEffect->mName = startEffect->mName; - endEffect->mIsPoison = startEffect->mIsPoison; - endEffect->mIsCart = startEffect->mIsCart; - endEffect->mIsRiding = startEffect->mIsRiding; - endEffect->mIsTrickDead = startEffect->mIsTrickDead; - endEffect->mIsPostDelay = startEffect->mIsPostDelay; - endEffect->mMessage = XML::getProperty(node, "end-message", ""); - endEffect->mSFXEffect = XML::getProperty(node, "end-audio", ""); - endEffect->mParticleEffect = XML::getProperty( - node, "end-particle", ""); - - (*the_map)[1][index] = startEffect; - (*the_map)[0][index] = endEffect; - } - } -} - -static void unloadMap(std::map<int, StatusEffect *> &map) -{ - for (std::map<int, StatusEffect *>::iterator it = map.begin(); - it != map.end(); ++it) - { - delete (*it).second; - } - - map.clear(); -} - -void StatusEffect::unload() -{ - if (!mLoaded) - return; - - unloadMap(statusEffects[0]); - unloadMap(statusEffects[1]); - - mLoaded = false; -} diff --git a/src/statuseffect.h b/src/statuseffect.h index 698a33bd0..b1a2d1d3e 100644 --- a/src/statuseffect.h +++ b/src/statuseffect.h @@ -94,36 +94,6 @@ class StatusEffect final bool isPostDelay() const A_WARN_UNUSED { return mIsPostDelay; } - /** - * Retrieves a status effect. - * - * \param index Index of the status effect. - * \param enabling Whether to retrieve the activating effect (true) or - * the deactivating effect (false). - */ - static StatusEffect *getStatusEffect(const int index, - const Enable enabling) - A_WARN_UNUSED; - - /** - * Maps a block effect index to its corresponding effect index. Block - * effect indices are used for opt2/opt3/status.option blocks; their - * mapping to regular effect indices is handled in the config file. - * - * Returns -1 on failure. - */ - static int blockEffectIndexToEffectIndex(const int blocKIndex) - A_WARN_UNUSED; - - static void load(); - - static void loadXmlFile(const std::string &fileName); - - static void unload(); - - private: - static bool mLoaded; - std::string mMessage; std::string mSFXEffect; std::string mParticleEffect; |