summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2013-05-02 10:10:37 +0200
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2013-05-02 10:11:19 +0200
commit679d830d0ba6ecbcd698b1ff2625144d08314b9e (patch)
tree24e5c1ea5fa6f11165d726cd345726fd3dae8fdd /src/resources
parent35108f09f64835a8d02c5bfb2ec62426ab83bd59 (diff)
parenta6b11834f227b8edbfb39633380806480fd2a2c5 (diff)
downloadmana-client-679d830d0ba6ecbcd698b1ff2625144d08314b9e.tar.gz
mana-client-679d830d0ba6ecbcd698b1ff2625144d08314b9e.tar.bz2
mana-client-679d830d0ba6ecbcd698b1ff2625144d08314b9e.tar.xz
mana-client-679d830d0ba6ecbcd698b1ff2625144d08314b9e.zip
Merge branch 'master' into lpc2012
This merge reverts change 3b22c2cf170c877904dcef5a4af03ac360bd0581. Conflicts: src/gui/charcreatedialog.cpp src/net/manaserv/manaserv_protocol.h
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/attributes.cpp405
-rw-r--r--src/resources/attributes.h68
-rw-r--r--src/resources/chardb.cpp132
-rw-r--r--src/resources/chardb.h48
-rw-r--r--src/resources/specialdb.cpp3
-rw-r--r--src/resources/theme.cpp2
6 files changed, 656 insertions, 2 deletions
diff --git a/src/resources/attributes.cpp b/src/resources/attributes.cpp
new file mode 100644
index 00000000..c4c67fba
--- /dev/null
+++ b/src/resources/attributes.cpp
@@ -0,0 +1,405 @@
+/*
+ * The Mana Client
+ * Copyright (C) 2010-2013 The Mana Developers
+ *
+ * This file is part of The Mana 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/attributes.h"
+
+#include "log.h"
+#include "playerinfo.h"
+
+#include "gui/statuswindow.h"
+
+#include "resources/itemdb.h"
+
+#include "utils/gettext.h"
+#include "utils/stringutils.h"
+#include "utils/xml.h"
+
+#include <list>
+#include <map>
+
+#define DEFAULT_ATTRIBUTESDB_FILE "attributes.xml"
+#define DEFAULT_POINTS 30
+#define DEFAULT_MIN_PTS 1
+#define DEFAULT_MAX_PTS 9
+
+namespace Attributes {
+
+ typedef struct
+ {
+ unsigned int id;
+ std::string name;
+ std::string description;
+ /** Whether the attribute value can be modified by the player */
+ bool modifiable;
+ /**< Attribute scope. */
+ std::string scope;
+ /** The playerInfo core Id the attribute is linked with or -1 if not */
+ int playerInfoId;
+ } Attribute;
+
+ /** Map for attributes. */
+ typedef std::map<unsigned int, Attribute> AttributeMap;
+ static AttributeMap attributes;
+
+ /** tags = effects on attributes. */
+ typedef std::map< std::string, std::string > TagMap;
+ static TagMap tags;
+
+ /** List of modifiable attribute names used at character's creation. */
+ static std::vector<std::string> attributeLabels;
+
+ /** Characters creation points. */
+ static unsigned int creationPoints = DEFAULT_POINTS;
+ static unsigned int attributeMinimum = DEFAULT_MIN_PTS;
+ static unsigned int attributeMaximum = DEFAULT_MAX_PTS;
+
+ unsigned int getCreationPoints()
+ {
+ return creationPoints;
+ }
+
+ unsigned int getAttributeMinimum()
+ {
+ return attributeMinimum;
+ }
+
+ unsigned int getAttributeMaximum()
+ {
+ return attributeMaximum;
+ }
+
+ std::vector<std::string>& getLabels()
+ {
+ return attributeLabels;
+ }
+
+ /**
+ * Fills the list of base attribute labels.
+ */
+ static void fillLabels()
+ {
+ // Fill up the modifiable attribute label list.
+ attributeLabels.clear();
+ AttributeMap::const_iterator it, it_end;
+ for (it = attributes.begin(), it_end = attributes.end(); it != it_end;
+ it++)
+ {
+ if (it->second.modifiable &&
+ (it->second.scope == "character" || it->second.scope == "being"))
+ attributeLabels.push_back(it->second.name + ":");
+ }
+ }
+
+ /**
+ * Fills the list of base attribute labels.
+ */
+ static int getPlayerInfoIdFromAttrType(std::string attrType)
+ {
+ toLower(attrType);
+ if (attrType == "level")
+ return ::LEVEL;
+ else if (attrType == "hp")
+ return ::HP;
+ else if (attrType == "max-hp")
+ return ::MAX_HP;
+ else if (attrType == "mp")
+ return ::MP;
+ else if (attrType == "max-mp")
+ return ::MAX_MP;
+ else if (attrType == "exp")
+ return ::EXP;
+ else if (attrType == "exp-needed")
+ return ::EXP_NEEDED;
+ else if (attrType == "money")
+ return ::MONEY;
+ else if (attrType == "total-weight")
+ return ::TOTAL_WEIGHT;
+ else if (attrType == "max-weight")
+ return ::MAX_WEIGHT;
+ else if (attrType == "skill-points")
+ return ::SKILL_POINTS;
+ else if (attrType == "char-points")
+ return ::CHAR_POINTS;
+ else if (attrType == "corr-points")
+ return ::CORR_POINTS;
+ else if (attrType == "none")
+ return -2; // Used to hide the attribute display.
+
+ return -1; // Not linked to a playerinfo stat.
+ }
+
+ int getPlayerInfoIdFromAttrId(int attrId)
+ {
+ AttributeMap::const_iterator it = attributes.find(attrId);
+
+ if (it != attributes.end())
+ {
+ return it->second.playerInfoId;
+ }
+
+ return -1;
+ }
+
+ static void loadBuiltins()
+ {
+ {
+ Attribute a;
+ a.id = 16;
+ a.name = _("Strength");
+ a.description = "";
+ a.modifiable = true;
+ a.scope = "character";
+ a.playerInfoId = -1;
+
+ attributes[a.id] = a;
+ tags.insert(std::make_pair("str", _("Strength %+.1f")));
+ }
+
+ {
+ Attribute a;
+ a.id = 17;
+ a.name = _("Agility");
+ a.description = "";
+ a.modifiable = true;
+ a.scope = "character";
+ a.playerInfoId = -1;
+
+ attributes[a.id] = a;
+ tags.insert(std::make_pair("agi", _("Agility %+.1f")));
+ }
+
+ {
+ Attribute a;
+ a.id = 18;
+ a.name = _("Dexterity");
+ a.description = "";
+ a.modifiable = true;
+ a.scope = "character";
+ a.playerInfoId = -1;
+
+ attributes[a.id] = a;
+ tags.insert(std::make_pair("dex", _("Dexterity %+.1f")));
+ }
+
+ {
+ Attribute a;
+ a.id = 19;
+ a.name = _("Vitality");
+ a.description = "";
+ a.modifiable = true;
+ a.scope = "character";
+ a.playerInfoId = -1;
+
+ attributes[a.id] = a;
+ tags.insert(std::make_pair("vit", _("Vitality %+.1f")));
+ }
+
+ {
+ Attribute a;
+ a.id = 20;
+ a.name = _("Intelligence");
+ a.description = "";
+ a.modifiable = true;
+ a.scope = "character";
+ a.playerInfoId = -1;
+
+ attributes[a.id] = a;
+ tags.insert(std::make_pair("int", _("Intelligence %+.1f")));
+ }
+
+ {
+ Attribute a;
+ a.id = 21;
+ a.name = _("Willpower");
+ a.description = "";
+ a.modifiable = true;
+ a.scope = "character";
+ a.playerInfoId = -1;
+
+ attributes[a.id] = a;
+ tags.insert(std::make_pair("wil", _("Willpower %+.1f")));
+ }
+ }
+
+ void load()
+ {
+ logger->log("Initializing attributes database...");
+
+ XML::Document doc(DEFAULT_ATTRIBUTESDB_FILE);
+ xmlNodePtr rootNode = doc.rootNode();
+
+ if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "attributes"))
+ {
+ logger->log("Attributes: Error while loading "
+ DEFAULT_ATTRIBUTESDB_FILE ". Using Built-ins.");
+ loadBuiltins();
+ fillLabels();
+ return;
+ }
+
+ for_each_xml_child_node(node, rootNode)
+ {
+ if (xmlStrEqual(node->name, BAD_CAST "attribute"))
+ {
+ int id = XML::getProperty(node, "id", 0);
+
+ if (!id)
+ {
+ logger->log("Attributes: Invalid or missing stat ID in "
+ DEFAULT_ATTRIBUTESDB_FILE "!");
+ continue;
+ }
+ else if (attributes.find(id) != attributes.end())
+ {
+ logger->log("Attributes: Redefinition of stat ID %d", id);
+ }
+
+ std::string name = XML::getProperty(node, "name", "");
+
+ if (name.empty())
+ {
+ logger->log("Attributes: Invalid or missing stat name in "
+ DEFAULT_ATTRIBUTESDB_FILE "!");
+ continue;
+ }
+
+ // Create the attribute.
+ Attribute a;
+ a.id = id;
+ a.name = name;
+ a.description = XML::getProperty(node, "desc", "");
+ a.modifiable = XML::getBoolProperty(node, "modifiable", false);
+ a.scope = XML::getProperty(node, "scope", "none");
+ a.playerInfoId = getPlayerInfoIdFromAttrType(
+ XML::getProperty(node, "player-info", ""));
+
+ attributes[id] = a;
+
+ unsigned int count = 0;
+ for_each_xml_child_node(effectNode, node)
+ {
+ if (!xmlStrEqual(effectNode->name, BAD_CAST "modifier"))
+ continue;
+ ++count;
+ std::string tag = XML::getProperty(effectNode, "tag", "");
+ if (tag.empty())
+ {
+ if (name.empty())
+ {
+ logger->log("Attribute modifier in attribute %u:%s: "
+ "Empty name definition "
+ "on empty tag definition, skipping.",
+ a.id, a.name.c_str());
+ --count;
+ continue;
+ }
+ tag = name.substr(0, name.size() > 3 ? 3 : name.size());
+ tag = toLower(tag) + toString(count);
+ }
+
+ std::string effect = XML::getProperty(effectNode, "effect", "");
+ if (effect.empty())
+ {
+ if (name.empty())
+ {
+ logger->log("Attribute modifier in attribute %u:%s: "
+ "Empty name definition "
+ "on empty effect definition, skipping.",
+ a.id, a.name.c_str());
+ --count;
+ continue;
+ }
+ else
+ effect = name + " %+f";
+ }
+ tags.insert(std::make_pair(tag, effect));
+ }
+ logger->log("Found %d tags for attribute %d.", count, id);
+
+ }// End attribute
+ else if (xmlStrEqual(node->name, BAD_CAST "points"))
+ {
+ creationPoints = XML::getProperty(node, "start",DEFAULT_POINTS);
+ attributeMinimum = XML::getProperty(node, "minimum",
+ DEFAULT_MIN_PTS);
+ attributeMaximum = XML::getProperty(node, "maximum",
+ DEFAULT_MAX_PTS);
+ logger->log("Loaded points: start: %i, min: %i, max: %i.",
+ creationPoints, attributeMinimum, attributeMaximum);
+ }
+ else
+ {
+ continue;
+ }
+ }
+ logger->log("Found %d tags for %d attributes.", int(tags.size()),
+ int(attributes.size()));
+
+ fillLabels();
+
+ // Sanity checks on starting points
+ float modifiableAttributeCount = (float) attributeLabels.size();
+ float averageValue = ((float) creationPoints) / modifiableAttributeCount;
+ if (averageValue > attributeMaximum || averageValue < attributeMinimum
+ || creationPoints < 1)
+ {
+ logger->log("Attributes: Character's point values make "
+ "the character's creation impossible. "
+ "Switch back to defaults.");
+ creationPoints = DEFAULT_POINTS;
+ attributeMinimum = DEFAULT_MIN_PTS;
+ attributeMaximum = DEFAULT_MAX_PTS;
+ }
+ }
+
+ void unload()
+ {
+ attributes.clear();
+ }
+
+ void informItemDB()
+ {
+ std::list<ItemStat> dbStats;
+
+ TagMap::const_iterator it, it_end;
+ for (it = tags.begin(), it_end = tags.end(); it != it_end; ++it)
+ dbStats.push_back(ItemStat(it->first, it->second));
+
+ setStatsList(dbStats);
+ }
+
+ void informStatusWindow()
+ {
+ AttributeMap::const_iterator it, it_end;
+ for (it = attributes.begin(), it_end = attributes.end(); it != it_end;
+ it++)
+ {
+ if (it->second.playerInfoId == -1 &&
+ (it->second.scope == "character" || it->second.scope == "being"))
+ {
+ statusWindow->addAttribute(it->second.id,
+ it->second.name,
+ it->second.modifiable,
+ it->second.description);
+ }
+ }
+ }
+
+} // namespace Attributes
diff --git a/src/resources/attributes.h b/src/resources/attributes.h
new file mode 100644
index 00000000..7124ba94
--- /dev/null
+++ b/src/resources/attributes.h
@@ -0,0 +1,68 @@
+/*
+ * The Mana Client
+ * Copyright (C) 2010-2013 The Mana Developers
+ *
+ * This file is part of The Mana 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_ATTRIBUTES_H
+#define RESOURCES_ATTRIBUTES_H
+
+#include <string>
+#include <vector>
+
+namespace Attributes {
+
+ void load();
+
+ void unload();
+
+ void informItemDB();
+
+ void informStatusWindow();
+
+ /**
+ * Returns the list of base attribute labels.
+ */
+ std::vector<std::string>& getLabels();
+
+ /**
+ * Give back the corresponding playerinfo Id from the attribute id
+ * defined in the xml file.
+ */
+ int getPlayerInfoIdFromAttrId(int attrId);
+
+ /**
+ * Give the attribute points given to a character
+ * at its creation.
+ */
+ unsigned int getCreationPoints();
+
+ /**
+ * Give the minimum attribute point possible
+ * at character's creation.
+ */
+ unsigned int getAttributeMinimum();
+
+ /**
+ * Give the maximum attribute point possible
+ * at character's creation.
+ */
+ unsigned int getAttributeMaximum();
+
+} // namespace Attributes
+
+#endif // RESOURCES_ATTRIBUTES_H
diff --git a/src/resources/chardb.cpp b/src/resources/chardb.cpp
new file mode 100644
index 00000000..40ecd999
--- /dev/null
+++ b/src/resources/chardb.cpp
@@ -0,0 +1,132 @@
+/*
+ * Character creation settings
+ * Copyright (C) 2011-2013 The ManaPlus Developers
+ * Copyright (C) 2013 The Mana 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/chardb.h"
+
+#include "log.h"
+
+#include "utils/xml.h"
+
+namespace
+{
+ bool mLoaded = false;
+ unsigned mMinHairColor = 0;
+ unsigned mMaxHairColor = 0;
+ unsigned mMinHairStyle = 0;
+ unsigned mMaxHairStyle = 0;
+ unsigned mMinStat = 0;
+ unsigned mMaxStat = 0;
+ unsigned mSumStat = 0;
+ std::vector<int> mDefaultItems;
+}
+
+static void loadMinMax(xmlNodePtr node, unsigned *min, unsigned *max)
+{
+ *min = XML::getProperty(node, "min", 1);
+ *max = XML::getProperty(node, "max", 10);
+}
+
+void CharDB::load()
+{
+ if (mLoaded)
+ unload();
+
+ XML::Document doc("charcreation.xml");
+ xmlNodePtr root = doc.rootNode();
+
+ if (!root || !xmlStrEqual(root->name, BAD_CAST "chars"))
+ {
+ logger->log("CharDB: Failed to parse charcreation.xml.");
+ return;
+ }
+
+ for_each_xml_child_node(node, root)
+ {
+ if (xmlStrEqual(node->name, BAD_CAST "haircolor"))
+ {
+ loadMinMax(node, &mMinHairColor, &mMaxHairColor);
+ }
+ else if (xmlStrEqual(node->name, BAD_CAST "hairstyle"))
+ {
+ loadMinMax(node, &mMinHairStyle, &mMaxHairStyle);
+ }
+ else if (xmlStrEqual(node->name, BAD_CAST "stat"))
+ {
+ loadMinMax(node, &mMinStat, &mMaxStat);
+ mSumStat = XML::getProperty(node, "sum", 0);
+ }
+ else if (xmlStrEqual(node->name, BAD_CAST "item"))
+ {
+ const int id = XML::getProperty(node, "id", 0);
+ if (id > 0)
+ mDefaultItems.push_back(id);
+ }
+ }
+
+ mLoaded = true;
+}
+
+void CharDB::unload()
+{
+ logger->log("Unloading chars database...");
+
+ mLoaded = false;
+}
+
+unsigned CharDB::getMinHairColor()
+{
+ return mMinHairColor;
+}
+
+unsigned CharDB::getMaxHairColor()
+{
+ return mMaxHairColor;
+}
+
+unsigned CharDB::getMinHairStyle()
+{
+ return mMinHairStyle;
+}
+
+unsigned CharDB::getMaxHairStyle()
+{
+ return mMaxHairStyle;
+}
+
+unsigned CharDB::getMinStat()
+{
+ return mMinStat;
+}
+
+unsigned CharDB::getMaxStat()
+{
+ return mMaxStat;
+}
+
+unsigned CharDB::getSumStat()
+{
+ return mSumStat;
+}
+
+const std::vector<int> &CharDB::getDefaultItems()
+{
+ return mDefaultItems;
+}
diff --git a/src/resources/chardb.h b/src/resources/chardb.h
new file mode 100644
index 00000000..10530b26
--- /dev/null
+++ b/src/resources/chardb.h
@@ -0,0 +1,48 @@
+/*
+ * Character creation settings
+ * Copyright (C) 2011-2013 The ManaPlus Developers
+ * Copyright (C) 2013 The Mana 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_CHARDB_H
+#define RESOURCES_CHARDB_H
+
+#include <vector>
+
+/**
+ * Character creation settings.
+ */
+namespace CharDB
+{
+ void load();
+ void unload();
+
+ unsigned getMinHairColor();
+ unsigned getMaxHairColor();
+
+ unsigned getMinHairStyle();
+ unsigned getMaxHairStyle();
+
+ unsigned getMinStat();
+ unsigned getMaxStat();
+ unsigned getSumStat();
+
+ const std::vector<int> &getDefaultItems();
+}
+
+#endif // RESOURCES_CHARDB_H
diff --git a/src/resources/specialdb.cpp b/src/resources/specialdb.cpp
index 426a1143..c75f4b1b 100644
--- a/src/resources/specialdb.cpp
+++ b/src/resources/specialdb.cpp
@@ -61,7 +61,8 @@ void SpecialDB::load()
for_each_xml_child_node(set, root)
{
- if (xmlStrEqual(set->name, BAD_CAST "set"))
+ if (xmlStrEqual(set->name, BAD_CAST "set") ||
+ xmlStrEqual(set->name, BAD_CAST "special-set"))
{
setName = XML::getProperty(set, "name", "Actions");
diff --git a/src/resources/theme.cpp b/src/resources/theme.cpp
index 036cd4a3..8db05be9 100644
--- a/src/resources/theme.cpp
+++ b/src/resources/theme.cpp
@@ -542,7 +542,7 @@ void Theme::loadColors(std::string file)
if (file == "")
file = defaultThemePath;
- file += "/" COLORS_XML_FILE;
+ file += "/colors.xml";
XML::Document doc(file);
xmlNodePtr root = doc.rootNode();