summaryrefslogtreecommitdiff
path: root/src/resources/db
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-03-21 16:52:59 +0300
committerAndrei Karas <akaras@inbox.ru>2016-03-21 16:52:59 +0300
commitac4e40a1408ad4d6fbcfce9d2bc6a0bc187ea5a4 (patch)
tree13314fbbb4945414b8be5d1d0236e1c41f88e8c8 /src/resources/db
parent68857593b01b73d33fa1a12011cf9cb402db8a73 (diff)
downloadmanaverse-ac4e40a1408ad4d6fbcfce9d2bc6a0bc187ea5a4.tar.gz
manaverse-ac4e40a1408ad4d6fbcfce9d2bc6a0bc187ea5a4.tar.bz2
manaverse-ac4e40a1408ad4d6fbcfce9d2bc6a0bc187ea5a4.tar.xz
manaverse-ac4e40a1408ad4d6fbcfce9d2bc6a0bc187ea5a4.zip
Split StatusEffect into StatusEffect and StatusEffectDB.
Diffstat (limited to 'src/resources/db')
-rw-r--r--src/resources/db/statuseffectdb.cpp192
-rw-r--r--src/resources/db/statuseffectdb.h62
2 files changed, 254 insertions, 0 deletions
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