Created
November 21, 2014 02:46
-
-
Save leper/dbe9b85288909745e106 to your computer and use it in GitHub Desktop.
WIP for #2936
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/binaries/data/mods/public/simulation/templates/units/rome_infantry_swordsman_a.xml b/binaries/data/mods/public/simulation/templates/units/rome_infantry_swordsman_a.xml | |
index 743ada5..77c0c44 100644 | |
--- a/binaries/data/mods/public/simulation/templates/units/rome_infantry_swordsman_a.xml | |
+++ b/binaries/data/mods/public/simulation/templates/units/rome_infantry_swordsman_a.xml | |
@@ -7,7 +7,7 @@ | |
</Armour> | |
<Attack> | |
<Melee> | |
- <Hack>14</Hack> | |
+ <Hack method="add">14.0</Hack> | |
</Melee> | |
<Charge> | |
<Hack>28.0</Hack> | |
diff --git a/source/simulation2/system/ComponentManager.cpp b/source/simulation2/system/ComponentManager.cpp | |
index 4c7d35b..2b91b7f 100644 | |
--- a/source/simulation2/system/ComponentManager.cpp | |
+++ b/source/simulation2/system/ComponentManager.cpp | |
@@ -1085,6 +1085,9 @@ std::string CComponentManager::GenerateSchema() | |
std::string schema = | |
"<grammar xmlns='http://relaxng.org/ns/structure/1.0' xmlns:a='http://ns.wildfiregames.com/entity' datatypeLibrary='http://www.w3.org/2001/XMLSchema-datatypes'>" | |
"<define name='nonNegativeDecimal'>" | |
+ "<optional>" | |
+ "<attribute name='method'><data type='string'/></attribute>" | |
+ "</optional>" | |
"<data type='decimal'><param name='minInclusive'>0</param></data>" | |
"</define>" | |
"<define name='positiveDecimal'>" | |
diff --git a/source/simulation2/system/ParamNode.cpp b/source/simulation2/system/ParamNode.cpp | |
index f966004..203a39c 100644 | |
--- a/source/simulation2/system/ParamNode.cpp | |
+++ b/source/simulation2/system/ParamNode.cpp | |
@@ -78,11 +78,18 @@ void CParamNode::ApplyLayer(const XMBFile& xmb, const XMBElement& element, const | |
bool hasSetValue = false; | |
- // Look for special attributes | |
int at_disable = xmb.GetAttributeID("disable"); | |
int at_replace = xmb.GetAttributeID("replace"); | |
+ int at_method = xmb.GetAttributeID("method"); | |
int at_datatype = xmb.GetAttributeID("datatype"); | |
bool replacing = false; | |
+ enum method { | |
+ ADD, | |
+ SUB, | |
+ MUL, | |
+ DIV, | |
+ INVALID | |
+ } method = INVALID; | |
{ | |
XERO_ITER_ATTR(element, attr) | |
{ | |
@@ -96,6 +103,19 @@ void CParamNode::ApplyLayer(const XMBFile& xmb, const XMBElement& element, const | |
m_Childs.erase(name); | |
replacing = true; | |
} | |
+ else if (attr.Name == at_method) | |
+ { | |
+ if (std::wstring(attr.Value.begin(), attr.Value.end()) == L"add") | |
+ method = ADD; | |
+ else if (std::wstring(attr.Value.begin(), attr.Value.end()) == L"sub") | |
+ method = SUB; | |
+ else if (std::wstring(attr.Value.begin(), attr.Value.end()) == L"mul") | |
+ method = MUL; | |
+ else if (std::wstring(attr.Value.begin(), attr.Value.end()) == L"div") | |
+ method = DIV; | |
+ else | |
+ LOGERROR(L"Invalid method '%ls'", attr.Value.c_str()); | |
+ } | |
} | |
} | |
{ | |
@@ -142,6 +162,26 @@ void CParamNode::ApplyLayer(const XMBFile& xmb, const XMBElement& element, const | |
// Add this element as a child node | |
CParamNode& node = m_Childs[name]; | |
+ if (method != INVALID) | |
+ { | |
+ // TODO switch over supported types (int and fixed basically); log errors in other cases | |
+ fixed oldval = node.ToFixed(); | |
+ fixed mod = fixed::FromString(CStrW(value)); | |
+ switch (method) | |
+ { | |
+ case SUB: mod = -mod; | |
+ case ADD: | |
+ node.m_Value = (oldval + mod).ToString().FromUTF8(); | |
+ hasSetValue = true; | |
+ break; | |
+ case MUL: | |
+ // TODO | |
+ break; | |
+ case DIV: | |
+ // TODO | |
+ break; | |
+ } | |
+ } | |
if (!hasSetValue) | |
node.m_Value = value; | |
@@ -155,7 +195,8 @@ void CParamNode::ApplyLayer(const XMBFile& xmb, const XMBElement& element, const | |
XERO_ITER_ATTR(element, attr) | |
{ | |
// Skip special attributes | |
- if (attr.Name == at_replace) continue; | |
+ if (attr.Name == at_replace || attr.Name == at_method) | |
+ continue; | |
// Add any others | |
std::string attrName = xmb.GetAttributeString(attr.Name); | |
node.m_Childs["@" + attrName].m_Value = attr.Value.FromUTF8(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment