summaryrefslogtreecommitdiff
path: root/src/resources/db/statdb.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-06-30 15:08:36 +0300
committerAndrei Karas <akaras@inbox.ru>2016-06-30 15:08:36 +0300
commit98db053ae7fa09a8b209dca95e4e65d00320cc0b (patch)
treeb57a5aaa669a20f0e43f4be698ef3204ed56c0fb /src/resources/db/statdb.cpp
parent3589bb9fa0800650accc124ea6820d5834c27e43 (diff)
downloadmv-98db053ae7fa09a8b209dca95e4e65d00320cc0b.tar.gz
mv-98db053ae7fa09a8b209dca95e4e65d00320cc0b.tar.bz2
mv-98db053ae7fa09a8b209dca95e4e65d00320cc0b.tar.xz
mv-98db053ae7fa09a8b209dca95e4e65d00320cc0b.zip
Move extended stats from status window into stats.xml too.s20160630
Also add reports about failed stats loading.
Diffstat (limited to 'src/resources/db/statdb.cpp')
-rw-r--r--src/resources/db/statdb.cpp53
1 files changed, 49 insertions, 4 deletions
diff --git a/src/resources/db/statdb.cpp b/src/resources/db/statdb.cpp
index e079d323a..ae48485bd 100644
--- a/src/resources/db/statdb.cpp
+++ b/src/resources/db/statdb.cpp
@@ -37,9 +37,10 @@ namespace
{
bool mLoaded = false;
static std::vector<BasicStat> mBasicStats;
+ static std::vector<BasicStat> mExtendedStats;
} // namespace
-void StatDb::addBasicStats()
+void StatDb::addDefaultStats()
{
mBasicStats.push_back(BasicStat(Attributes::STR,
"str",
@@ -67,11 +68,16 @@ void StatDb::addBasicStats()
_("Luck")));
}
-const std::vector<BasicStat> &StatDb::getExtraStats()
+const std::vector<BasicStat> &StatDb::getBasicStats()
{
return mBasicStats;
}
+const std::vector<BasicStat> &StatDb::getExtendedStats()
+{
+ return mExtendedStats;
+}
+
void StatDb::load()
{
if (mLoaded)
@@ -92,11 +98,15 @@ static void loadBasicStats(const XmlNodePtr rootNode)
{
if (xmlNameEqual(node, "stat"))
{
+ const std::string name = XML::getProperty(node, "name", "");
const int id = XML::getProperty(node, "id", 0);
if (id <= 0 || id >= maxAttr)
+ {
+ reportAlways("Wrong id for basic stat with name %s",
+ name.c_str());
continue;
+ }
const std::string tag = XML::getProperty(node, "tag", "");
- const std::string name = XML::getProperty(node, "name", "");
mBasicStats.push_back(BasicStat(static_cast<AttributesT>(id),
tag,
name));
@@ -104,6 +114,28 @@ static void loadBasicStats(const XmlNodePtr rootNode)
}
}
+static void loadExtendedStats(const XmlNodePtr rootNode)
+{
+ const int maxAttr = static_cast<int>(Attributes::MAX_ATTRIBUTE);
+ for_each_xml_child_node(node, rootNode)
+ {
+ if (xmlNameEqual(node, "stat"))
+ {
+ const std::string name = XML::getProperty(node, "name", "");
+ const int id = XML::getProperty(node, "id", 0);
+ if (id <= 0 || id >= maxAttr)
+ {
+ reportAlways("Wrong id for extended stat with name %s",
+ name.c_str());
+ continue;
+ }
+ mExtendedStats.push_back(BasicStat(static_cast<AttributesT>(id),
+ std::string(),
+ name));
+ }
+ }
+}
+
void StatDb::loadXmlFile(const std::string &fileName,
const SkipError skipError)
{
@@ -117,7 +149,7 @@ void StatDb::loadXmlFile(const std::string &fileName,
logger->log("StatDb: Error while loading %s!",
fileName.c_str());
if (skipError == SkipError_false)
- addBasicStats();
+ addDefaultStats();
return;
}
@@ -134,6 +166,19 @@ void StatDb::loadXmlFile(const std::string &fileName,
{
loadBasicStats(node);
}
+ else if (xmlNameEqual(node, "extended"))
+ {
+ loadExtendedStats(node);
+ }
+ }
+ if (skipError == SkipError_false)
+ {
+ if (mBasicStats.empty() &&
+ mExtendedStats.empty())
+ {
+ reportAlways("StatDb: no stats found");
+ addDefaultStats();
+ }
}
}