Ticket #2936: relative_templates.diff
File relative_templates.diff, 17.7 KB (added by , 9 years ago) |
---|
-
source/simulation2/components/CCmpFootprint.cpp
59 59 "<choice>" 60 60 "<element name='Square' a:help='Set the footprint to a square of the given size'>" 61 61 "<attribute name='width' a:help='Size of the footprint along the left/right direction (in metres)'>" 62 "<ref name='positiveDecimal'/>" 62 "<data type='decimal'>" 63 "<param name='minExclusive'>0.0</param>" 64 "</data>" 63 65 "</attribute>" 64 66 "<attribute name='depth' a:help='Size of the footprint along the front/back direction (in metres)'>" 65 "<ref name='positiveDecimal'/>" 67 "<data type='decimal'>" 68 "<param name='minExclusive'>0.0</param>" 69 "</data>" 66 70 "</attribute>" 67 71 "</element>" 68 72 "<element name='Circle' a:help='Set the footprint to a circle of the given size'>" 69 73 "<attribute name='radius' a:help='Radius of the footprint (in metres)'>" 70 "<ref name='positiveDecimal'/>" 74 "<data type='decimal'>" 75 "<param name='minExclusive'>0.0</param>" 76 "</data>" 71 77 "</attribute>" 72 78 "</element>" 73 79 "</choice>" -
source/simulation2/components/CCmpObstruction.cpp
112 112 "<choice>" 113 113 "<element name='Static'>" 114 114 "<attribute name='width'>" 115 "<ref name='positiveDecimal'/>" 115 "<data type='decimal'>" 116 "<param name='minExclusive'>0.0</param>" 117 "</data>" 116 118 "</attribute>" 117 119 "<attribute name='depth'>" 118 "<ref name='positiveDecimal'/>" 120 "<data type='decimal'>" 121 "<param name='minExclusive'>0.0</param>" 122 "</data>" 119 123 "</attribute>" 120 124 "</element>" 121 125 "<element name='Unit'>" 122 126 "<attribute name='radius'>" 123 "<ref name='positiveDecimal'/>" 127 "<data type='decimal'>" 128 "<param name='minExclusive'>0.0</param>" 129 "</data>" 124 130 "</attribute>" 125 131 "</element>" 126 132 "<element name='Obstructions'>" … … 138 144 "</attribute>" 139 145 "</optional>" 140 146 "<attribute name='width'>" 141 "<ref name='positiveDecimal'/>" 147 "<data type='decimal'>" 148 "<param name='minExclusive'>0.0</param>" 149 "</data>" 142 150 "</attribute>" 143 151 "<attribute name='depth'>" 144 "<ref name='positiveDecimal'/>" 152 "<data type='decimal'>" 153 "<param name='minExclusive'>0.0</param>" 154 "</data>" 145 155 "</attribute>" 146 156 "</element>" 147 157 "</zeroOrMore>" -
source/simulation2/components/CCmpVisualActor.cpp
146 146 "</element>" 147 147 "<element name='Box' a:help='Sets the selection shape to a box of specified dimensions'>" 148 148 "<attribute name='width'>" 149 "<ref name='positiveDecimal' />" 149 "<data type='decimal'>" 150 "<param name='minExclusive'>0.0</param>" 151 "</data>" 150 152 "</attribute>" 151 153 "<attribute name='height'>" 152 "<ref name='positiveDecimal' />" 154 "<data type='decimal'>" 155 "<param name='minExclusive'>0.0</param>" 156 "</data>" 153 157 "</attribute>" 154 158 "<attribute name='depth'>" 155 "<ref name='positiveDecimal' />" 159 "<data type='decimal'>" 160 "<param name='minExclusive'>0.0</param>" 161 "</data>" 156 162 "</attribute>" 157 163 "</element>" 158 164 "<element name='Cylinder' a:help='Sets the selection shape to a cylinder of specified dimensions'>" 159 165 "<attribute name='radius'>" 160 "<ref name='positiveDecimal' />" 166 "<data type='decimal'>" 167 "<param name='minExclusive'>0.0</param>" 168 "</data>" 161 169 "</attribute>" 162 170 "<attribute name='height'>" 163 "<ref name='positiveDecimal' />" 171 "<data type='decimal'>" 172 "<param name='minExclusive'>0.0</param>" 173 "</data>" 164 174 "</attribute>" 165 175 "</element>" 166 176 "</choice>" -
source/simulation2/docs/SimulationDocs.h
297 297 - <code><text/></code> 298 298 - <code><data type='boolean'/></code> 299 299 - <code><data type='decimal'/></code> 300 - <code><data type='integer'/></code> 300 301 - <code><data type='nonNegativeInteger'/></code> 301 302 - <code><data type='positiveInteger'/></code> 303 - <code><ref name='decimal'/></code> 302 304 - <code><ref name='nonNegativeDecimal'/></code> 303 305 - <code><ref name='positiveDecimal'/></code> 304 306 305 (The last two are slightly different since they're not standard data types.)306 307 308 The <code><data></code> elements are native elements, while the <code><ref></code> elements are elements added for our engine. These non-native elements allow the definition of an operation that depends on the parent template. Possible operations are "add", "sub" mul" and "div", and can be applied as the example below. 309 310 Say the parent template is 311 @code 312 <Entity> 313 <Example> 314 <Name>Semi-Humanoids</Name> 315 <Height>9000</Height> 316 <Eyes/> 317 </Example> 318 <!-- ... other components ... --> 319 </Entity> 320 @endcode 321 and the child template appears like 322 @code 323 <Entity> 324 <Example> 325 <Name>Barney</Name> 326 <Height op="add">5</Height> 327 <Eyes/> 328 </Example> 329 <!-- ... other components ... --> 330 </Entity> 331 @endcode 332 then Barney would have a height of 9005. 333 307 334 Elements can be wrapped in <code><optional></code>. 308 335 Groups of elements can be wrapped in <code><choice></code> to allow only one of them. 309 336 The content of an <code><element></code> can be further nested elements, but note that -
source/simulation2/system/ComponentManager.cpp
1092 1092 1093 1093 std::string CComponentManager::GenerateSchema() 1094 1094 { 1095 std::string numericOperation = 1096 "<optional>" 1097 "<attribute name='op'>" 1098 "<choice>" 1099 "<value>add</value>" 1100 "<value>sub</value>" 1101 "<value>mul</value>" 1102 "<value>div</value>" 1103 "</choice>" 1104 "</attribute>" 1105 "</optional>"; 1095 1106 std::string schema = 1096 1107 "<grammar xmlns='http://relaxng.org/ns/structure/1.0' xmlns:a='http://ns.wildfiregames.com/entity' datatypeLibrary='http://www.w3.org/2001/XMLSchema-datatypes'>" 1108 "<define name='decimal'>" 1109 "<data type='decimal'/>" 1110 + numericOperation + 1111 "</define>" 1097 1112 "<define name='nonNegativeDecimal'>" 1098 1113 "<data type='decimal'><param name='minInclusive'>0</param></data>" 1114 + numericOperation + 1099 1115 "</define>" 1100 1116 "<define name='positiveDecimal'>" 1101 1117 "<data type='decimal'><param name='minExclusive'>0</param></data>" 1118 + numericOperation + 1102 1119 "</define>" 1103 1120 "<define name='anything'>" 1104 1121 "<zeroOrMore>" -
source/simulation2/system/ParamNode.cpp
76 76 // Look for special attributes 77 77 int at_disable = xmb.GetAttributeID("disable"); 78 78 int at_replace = xmb.GetAttributeID("replace"); 79 int at_op = xmb.GetAttributeID("op"); 79 80 int at_datatype = xmb.GetAttributeID("datatype"); 81 enum op { 82 INVALID, 83 ADD, 84 SUB, 85 MUL, 86 DIV 87 } op = INVALID; 80 88 bool replacing = false; 81 89 { 82 90 XERO_ITER_ATTR(element, attr) … … 91 99 m_Childs.erase(name); 92 100 replacing = true; 93 101 } 102 else if (attr.Name == at_op) 103 { 104 if (std::wstring(attr.Value.begin(), attr.Value.end()) == L"add") 105 op = ADD; 106 else if (std::wstring(attr.Value.begin(), attr.Value.end()) == L"sub") 107 op = SUB; 108 else if (std::wstring(attr.Value.begin(), attr.Value.end()) == L"mul") 109 op = MUL; 110 else if (std::wstring(attr.Value.begin(), attr.Value.end()) == L"div") 111 op = DIV; 112 else 113 LOGWARNING("Invalid op '%ls'", attr.Value); 114 } 94 115 } 95 116 } 96 117 { … … 137 158 138 159 // Add this element as a child node 139 160 CParamNode& node = m_Childs[name]; 161 if (op != INVALID) 162 { 163 // TODO Support parsing of data types other than fixed; log warnings in other cases 164 fixed oldval = node.ToFixed(); 165 fixed mod = fixed::FromString(CStrW(value)); 166 switch (op) 167 { 168 case SUB: mod = -mod; 169 case ADD: 170 node.m_Value = (oldval + mod).ToString().FromUTF8(); 171 break; 172 case MUL: 173 node.m_Value = (oldval.Multiply(mod)).ToString().FromUTF8(); 174 break; 175 case DIV: 176 if (mod.IsZero()) 177 { 178 // Even though it's undefined, just return the original value 179 LOGWARNING("Attempted divide-by-zero in '%hs'%ls'.", name, sourceIdentifier ? (" in '" + utf8_from_wstring(sourceIdentifier) + "'") : ""); 180 break; 181 } 182 node.m_Value = (oldval / mod).ToString().FromUTF8(); 183 break; 184 } 185 hasSetValue = true; 186 } 140 187 if (!hasSetValue) 141 188 node.m_Value = value; 142 189 … … 150 197 XERO_ITER_ATTR(element, attr) 151 198 { 152 199 // Skip special attributes 153 if (attr.Name == at_replace) continue; 200 if (attr.Name == at_replace || attr.Name == at_op) 201 continue; 154 202 // Add any others 155 203 std::string attrName = xmb.GetAttributeString(attr.Name); 156 204 node.m_Childs["@" + attrName].m_Value = attr.Value.FromUTF8(); -
source/tools/templatesanalyzer/CreateRMTest.py
1 ''' 2 * CreateRMTest.py 3 * 4 * Copyright (C) 2015 Wildfire Games. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to deal 8 * in the Software without restriction, including without limitation the rights 9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 * copies of the Software, and to permit persons to whom the Software is 11 * furnished to do so, subject to the following conditions: 12 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 * THE SOFTWARE. 23 ''' 24 1 25 import xml.etree.ElementTree as ET 2 26 import os 3 27 -
source/tools/templatesanalyzer/unitTables.py
1 ''' 2 * unitTables.py 3 * 4 * Copyright (C) 2015 Wildfire Games. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to deal 8 * in the Software without restriction, including without limitation the rights 9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 * copies of the Software, and to permit persons to whom the Software is 11 * furnished to do so, subject to the following conditions: 12 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 * THE SOFTWARE. 23 ''' 24 1 25 import xml.etree.ElementTree as ET 2 26 import os 3 27 import glob … … 51 75 def htout(file, value): 52 76 file.write("<p>" + value + "</p>\n" ) 53 77 78 def NumericStatProcess(unit, newValue, templateValue): 79 if (newValue not in unit): 80 unit[newValue] = 0; # This is kind of a sanity hack. 81 if (templateValue.attrib == {}): 82 unit[newValue] = templateValue.text 83 elif (templateValue.attrib == "add"): 84 newValue += templateValue.text 85 elif (templateValue.attrib == "sub"): 86 newValue -= templateValue.text 87 elif (templateValue.attrib == "mul"): 88 newValue *= templateValue.text 89 elif (templateValue.attrib == "div"): 90 newValue /= templateValue.text 91 54 92 def CalcUnit(UnitName, existingUnit = None): 55 93 unit = { 'HP' : "0", "BuildTime" : "0", "Cost" : { 'food' : "0", "wood" : "0", "stone" : "0", "metal" : "0", "population" : "0"}, 56 94 'Attack' : { "Melee" : { "Hack" : 0, "Pierce" : 0, "Crush" : 0 }, "Ranged" : { "Hack" : 0, "Pierce" : 0, "Crush" : 0 } }, … … 69 107 unit["Parent"] = Template.getroot().get("parent") + ".xml" 70 108 71 109 if (Template.find("./Identity/Civ") != None): 72 unit['Civ'] = Template.find("./Identity/Civ").text110 NumericStatProcess(unit, 'Civ', Template.find("./Identity/Civ")) 73 111 74 112 if (Template.find("./Health/Max") != None): 75 unit['HP'] = Template.find("./Health/Max").text113 NumericStatProcess(unit, 'HP', Template.find("./Health/Max")) 76 114 77 115 if (Template.find("./Cost/BuildTime") != None): 78 unit['BuildTime'] = Template.find("./Cost/BuildTime").text116 NumericStatProcess(unit, 'BuildTime', Template.find("./Cost/BuildTime")) 79 117 80 118 if (Template.find("./Cost/Resources") != None): 81 119 for type in list(Template.find("./Cost/Resources")): 82 unit['Cost'][type.tag] = type.text120 NumericStatProcess(unit['Cost'], type.tag, type) 83 121 84 122 if (Template.find("./Attack/Melee") != None): 85 123 if (Template.find("./Attack/Melee/RepeatTime") != None): 86 unit['RepeatRate']["Melee"] = Template.find("./Attack/Melee/RepeatTime").text124 NumericStatProcess(unit['RepeatRate'], "Melee", Template.find("./Attack/Melee/RepeatTime")) 87 125 if (Template.find("./Attack/Melee/PrepareTime") != None): 88 unit['PrepRate']["Melee"] = Template.find("./Attack/Melee/PrepareTime").text126 NumericStatProcess(unit['PrepRate'], "Melee", Template.find("./Attack/Melee/PrepareTime")) 89 127 for atttype in AttackTypes: 90 128 if (Template.find("./Attack/Melee/"+atttype) != None): 91 unit['Attack']['Melee'][atttype] = Template.find("./Attack/Melee/"+atttype).text129 NumericStatProcess(unit['Attack']['Melee'], atttype, Template.find("./Attack/Melee/"+atttype)) 92 130 if (Template.find("./Attack/Melee/Bonuses") != None): 93 131 for Bonus in Template.find("./Attack/Melee/Bonuses"): 94 132 Against = [] … … 112 150 if (Template.find("./Attack/Ranged") != None): 113 151 unit['Ranged'] = "true" 114 152 if (Template.find("./Attack/Ranged/MaxRange") != None): 115 unit['Range'] = Template.find("./Attack/Ranged/MaxRange").text153 NumericStatProcess(unit, 'Range', Template.find("./Attack/Ranged/MaxRange")) 116 154 if (Template.find("./Attack/Ranged/RepeatTime") != None): 117 unit['RepeatRate']["Ranged"] = Template.find("./Attack/Ranged/RepeatTime").text155 NumericStatProcess(unit['RepeatRate'], "Ranged", Template.find("./Attack/Ranged/RepeatTime")) 118 156 if (Template.find("./Attack/Ranged/PrepareTime") != None): 119 unit['PrepRate']["Ranged"] = Template.find("./Attack/Ranged/PrepareTime").text157 NumericStatProcess(unit['PrepRate'], "Ranged", Template.find("./Attack/Ranged/PrepareTime")) 120 158 for atttype in AttackTypes: 121 159 if (Template.find("./Attack/Ranged/"+atttype) != None): 122 unit['Attack']['Ranged'][atttype] = Template.find("./Attack/Ranged/"+atttype).text160 NumericStatProcess(unit['Attack']['Ranged'], atttype, Template.find("./Attack/Ranged/"+atttype)) 123 161 if (Template.find("./Attack/Ranged/Bonuses") != None): 124 162 for Bonus in Template.find("./Attack/Ranged/Bonuses"): 125 163 Against = [] … … 142 180 if (Template.find("./Armour") != None): 143 181 for atttype in AttackTypes: 144 182 if (Template.find("./Armour/"+atttype) != None): 145 unit['Armour'][atttype] = Template.find("./Armour/"+atttype).text183 NumericStatProcess(unit['Armour'], atttype, Template.find("./Armour/"+atttype)) 146 184 147 185 if (Template.find("./UnitMotion") != None): 148 186 if (Template.find("./UnitMotion/WalkSpeed") != None): 149 unit['WalkSpeed'] = Template.find("./UnitMotion/WalkSpeed").text187 NumericStatProcess(unit, 'WalkSpeed', Template.find("./UnitMotion/WalkSpeed")) 150 188 151 189 if (Template.find("./Identity/VisibleClasses") != None): 152 190 newClasses = Template.find("./Identity/VisibleClasses").text.split(" ") … … 174 212 175 213 rstr += "<td style=\"text-align:right;\">" + Name + "</td>\n" 176 214 177 rstr += "<td>" + UnitDict["HP"]+ "</td>\n"215 rstr += "<td>" + str(UnitDict["HP"]) + "</td>\n" 178 216 179 rstr += "<td>" + UnitDict["BuildTime"]+ "</td>\n"217 rstr += "<td>" + str(UnitDict["BuildTime"]) + "</td>\n" 180 218 181 rstr += "<td>" + UnitDict["WalkSpeed"]+ "</td>\n"219 rstr += "<td>" + str(UnitDict["WalkSpeed"]) + "</td>\n" 182 220 183 221 rstr += "<td>" + UnitDict["Cost"]["food"] + "F / " + UnitDict["Cost"]["wood"] + "W / " + UnitDict["Cost"]["stone"] + "S / " + UnitDict["Cost"]["metal"] + "M</td>\n" 184 222 … … 696 734 CivUnitComparisons(CivData[Civ],CivData[oCiv]) 697 735 f.write("</table>") 698 736 699 f.write("</body>\n</html>") 700 No newline at end of file 737 f.write("</body>\n</html>")