summaryrefslogtreecommitdiff
path: root/src/units.cpp
diff options
context:
space:
mode:
authorPrzemysław Grzywacz <nexather@gmail.com>2013-05-04 21:57:58 +0200
committerPrzemysław Grzywacz <nexather@gmail.com>2013-05-04 21:57:58 +0200
commitbd1fdd87eed48ba3ffcc413936d6a6a60a429a97 (patch)
tree159fcd36797021939967c770febd59d9fbe1ee19 /src/units.cpp
parent0ef59afb6ee029a4e2247684f3f32f5bd064eb0b (diff)
downloadmana-bd1fdd87eed48ba3ffcc413936d6a6a60a429a97.tar.gz
mana-bd1fdd87eed48ba3ffcc413936d6a6a60a429a97.tar.bz2
mana-bd1fdd87eed48ba3ffcc413936d6a6a60a429a97.tar.xz
mana-bd1fdd87eed48ba3ffcc413936d6a6a60a429a97.zip
Client-side settings are now available from settings.xml
Diffstat (limited to 'src/units.cpp')
-rw-r--r--src/units.cpp107
1 files changed, 51 insertions, 56 deletions
diff --git a/src/units.cpp b/src/units.cpp
index 59181bde..1487eb21 100644
--- a/src/units.cpp
+++ b/src/units.cpp
@@ -50,7 +50,8 @@ enum UnitType {
struct UnitDescription units[UNIT_END];
-void Units::loadUnits()
+
+void Units::init()
{
{ // Setup default weight
struct UnitDescription ud;
@@ -90,72 +91,66 @@ void Units::loadUnits()
units[UNIT_CURRENCY] = ud;
}
+}
- XML::Document doc("units.xml");
- xmlNodePtr root = doc.rootNode();
+void Units::readUnitNode(xmlNodePtr node, const std::string &filename)
+{
+ struct UnitDescription ud;
+ int level = 1;
+ const std::string type = XML::getProperty(node, "type", "");
+ ud.conversion = XML::getProperty(node, "conversion", 1);
+ ud.mix = XML::getProperty(node, "mix", "no") == "yes";
- if (!root || !xmlStrEqual(root->name, BAD_CAST "units"))
- {
- logger->log("Error loading unit definition file: units.xml");
- return;
- }
+ struct UnitLevel bu;
+ bu.symbol = XML::getProperty(node, "base", "¤");
+ bu.count = 1;
+ bu.round = XML::getProperty(node, "round", 2);
+
+ ud.levels.push_back(bu);
- for_each_xml_child_node(node, root)
+ for_each_xml_child_node(uLevel, node)
{
- if (xmlStrEqual(node->name, BAD_CAST "unit"))
+ if (xmlStrEqual(uLevel->name, BAD_CAST "level"))
{
- struct UnitDescription ud;
- int level = 1;
- const std::string type = XML::getProperty(node, "type", "");
- ud.conversion = XML::getProperty(node, "conversion", 1);
- ud.mix = XML::getProperty(node, "mix", "no") == "yes";
-
- struct UnitLevel bu;
- bu.symbol = XML::getProperty(node, "base", "¤");
- bu.count = 1;
- bu.round = XML::getProperty(node, "round", 2);
+ struct UnitLevel ul;
+ ul.symbol = XML::getProperty(uLevel, "symbol",
+ strprintf("¤%d",level));
+ ul.count = XML::getProperty(uLevel, "count", -1);
+ ul.round = XML::getProperty(uLevel, "round", bu.round);
- ud.levels.push_back(bu);
-
- for_each_xml_child_node(uLevel, node)
+ if (ul.count > 0)
{
- if (xmlStrEqual(uLevel->name, BAD_CAST "level"))
- {
- struct UnitLevel ul;
- ul.symbol = XML::getProperty(uLevel, "symbol",
- strprintf("¤%d",level));
- ul.count = XML::getProperty(uLevel, "count", -1);
- ul.round = XML::getProperty(uLevel, "round", bu.round);
-
- if (ul.count > 0)
- {
- ud.levels.push_back(ul);
- level++;
- }
- else
- {
- logger->log("Error bad unit count: %d for %s in %s",
- ul.count, ul.symbol.c_str(), bu.symbol.c_str());
- }
- }
+ ud.levels.push_back(ul);
+ level++;
}
-
- // Add one more level for saftey
- struct UnitLevel ll;
- ll.symbol = "";
- ll.count = INT_MAX;
- ll.round = 0;
-
- ud.levels.push_back(ll);
-
- if (type == "weight")
- units[UNIT_WEIGHT] = ud;
- else if (type == "currency")
- units[UNIT_CURRENCY] = ud;
else
- logger->log("Error unknown unit type: %s", type.c_str());
+ {
+ logger->log("Error bad unit count: %d for %s in %s",
+ ul.count, ul.symbol.c_str(), bu.symbol.c_str());
+ }
}
}
+
+ // Add one more level for saftey
+ struct UnitLevel ll;
+ ll.symbol = "";
+ ll.count = INT_MAX;
+ ll.round = 0;
+
+ ud.levels.push_back(ll);
+
+ if (type == "weight")
+ units[UNIT_WEIGHT] = ud;
+ else if (type == "currency")
+ units[UNIT_CURRENCY] = ud;
+ else
+ logger->log("Error unknown unit type: %s in %s", type.c_str(), filename.c_str());
+
+}
+
+void Units::checkStatus()
+{
+
}
std::string formatUnit(int value, int type)