Ticket #2936: relative_templates_r16964.patch
File relative_templates_r16964.patch, 15.5 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/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" and "mul", 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>mul</value>" 1101 "</choice>" 1102 "</attribute>" 1103 "</optional>"; 1095 1104 std::string schema = 1096 1105 "<grammar xmlns='http://relaxng.org/ns/structure/1.0' xmlns:a='http://ns.wildfiregames.com/entity' datatypeLibrary='http://www.w3.org/2001/XMLSchema-datatypes'>" 1106 "<define name='decimal'>" 1107 "<data type='decimal'/>" 1108 + numericOperation + 1109 "</define>" 1097 1110 "<define name='nonNegativeDecimal'>" 1098 1111 "<data type='decimal'><param name='minInclusive'>0</param></data>" 1112 + numericOperation + 1099 1113 "</define>" 1100 1114 "<define name='positiveDecimal'>" 1101 1115 "<data type='decimal'><param name='minExclusive'>0</param></data>" 1116 + numericOperation + 1102 1117 "</define>" 1103 1118 "<define name='anything'>" 1104 1119 "<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 MUL 85 } op = INVALID; 80 86 bool replacing = false; 81 87 { 82 88 XERO_ITER_ATTR(element, attr) … … 91 97 m_Childs.erase(name); 92 98 replacing = true; 93 99 } 100 else if (attr.Name == at_op) 101 { 102 if (std::wstring(attr.Value.begin(), attr.Value.end()) == L"add") 103 op = ADD; 104 else if (std::wstring(attr.Value.begin(), attr.Value.end()) == L"mul") 105 op = MUL; 106 else 107 LOGWARNING("Invalid op '%ls'", attr.Value); 108 } 94 109 } 95 110 } 96 111 { … … 137 152 138 153 // Add this element as a child node 139 154 CParamNode& node = m_Childs[name]; 155 if (op != INVALID) 156 { 157 // TODO Support parsing of data types other than fixed; log warnings in other cases 158 fixed oldval = node.ToFixed(); 159 fixed mod = fixed::FromString(CStrW(value)); 160 switch (op) 161 { 162 case ADD: 163 node.m_Value = (oldval + mod).ToString().FromUTF8(); 164 break; 165 case MUL: 166 node.m_Value = (oldval.Multiply(mod)).ToString().FromUTF8(); 167 break; 168 } 169 hasSetValue = true; 170 } 140 171 if (!hasSetValue) 141 172 node.m_Value = value; 142 173 … … 150 181 XERO_ITER_ATTR(element, attr) 151 182 { 152 183 // Skip special attributes 153 if (attr.Name == at_replace) continue; 184 if (attr.Name == at_replace || attr.Name == at_op) 185 continue; 154 186 // Add any others 155 187 std::string attrName = xmb.GetAttributeString(attr.Name); 156 188 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 == "mul"): 86 newValue *= templateValue.text 87 54 88 def CalcUnit(UnitName, existingUnit = None): 55 89 unit = { 'HP' : "0", "BuildTime" : "0", "Cost" : { 'food' : "0", "wood" : "0", "stone" : "0", "metal" : "0", "population" : "0"}, 56 90 'Attack' : { "Melee" : { "Hack" : 0, "Pierce" : 0, "Crush" : 0 }, "Ranged" : { "Hack" : 0, "Pierce" : 0, "Crush" : 0 } }, … … 69 103 unit["Parent"] = Template.getroot().get("parent") + ".xml" 70 104 71 105 if (Template.find("./Identity/Civ") != None): 72 unit['Civ'] = Template.find("./Identity/Civ").text106 NumericStatProcess(unit, 'Civ', Template.find("./Identity/Civ")) 73 107 74 108 if (Template.find("./Health/Max") != None): 75 unit['HP'] = Template.find("./Health/Max").text109 NumericStatProcess(unit, 'HP', Template.find("./Health/Max")) 76 110 77 111 if (Template.find("./Cost/BuildTime") != None): 78 unit['BuildTime'] = Template.find("./Cost/BuildTime").text112 NumericStatProcess(unit, 'BuildTime', Template.find("./Cost/BuildTime")) 79 113 80 114 if (Template.find("./Cost/Resources") != None): 81 115 for type in list(Template.find("./Cost/Resources")): 82 unit['Cost'][type.tag] = type.text116 NumericStatProcess(unit['Cost'], type.tag, type) 83 117 84 118 if (Template.find("./Attack/Melee") != None): 85 119 if (Template.find("./Attack/Melee/RepeatTime") != None): 86 unit['RepeatRate']["Melee"] = Template.find("./Attack/Melee/RepeatTime").text120 NumericStatProcess(unit['RepeatRate'], "Melee", Template.find("./Attack/Melee/RepeatTime")) 87 121 if (Template.find("./Attack/Melee/PrepareTime") != None): 88 unit['PrepRate']["Melee"] = Template.find("./Attack/Melee/PrepareTime").text122 NumericStatProcess(unit['PrepRate'], "Melee", Template.find("./Attack/Melee/PrepareTime")) 89 123 for atttype in AttackTypes: 90 124 if (Template.find("./Attack/Melee/"+atttype) != None): 91 unit['Attack']['Melee'][atttype] = Template.find("./Attack/Melee/"+atttype).text125 NumericStatProcess(unit['Attack']['Melee'], atttype, Template.find("./Attack/Melee/"+atttype)) 92 126 if (Template.find("./Attack/Melee/Bonuses") != None): 93 127 for Bonus in Template.find("./Attack/Melee/Bonuses"): 94 128 Against = [] … … 112 146 if (Template.find("./Attack/Ranged") != None): 113 147 unit['Ranged'] = "true" 114 148 if (Template.find("./Attack/Ranged/MaxRange") != None): 115 unit['Range'] = Template.find("./Attack/Ranged/MaxRange").text149 NumericStatProcess(unit, 'Range', Template.find("./Attack/Ranged/MaxRange")) 116 150 if (Template.find("./Attack/Ranged/RepeatTime") != None): 117 unit['RepeatRate']["Ranged"] = Template.find("./Attack/Ranged/RepeatTime").text151 NumericStatProcess(unit['RepeatRate'], "Ranged", Template.find("./Attack/Ranged/RepeatTime")) 118 152 if (Template.find("./Attack/Ranged/PrepareTime") != None): 119 unit['PrepRate']["Ranged"] = Template.find("./Attack/Ranged/PrepareTime").text153 NumericStatProcess(unit['PrepRate'], "Ranged", Template.find("./Attack/Ranged/PrepareTime")) 120 154 for atttype in AttackTypes: 121 155 if (Template.find("./Attack/Ranged/"+atttype) != None): 122 unit['Attack']['Ranged'][atttype] = Template.find("./Attack/Ranged/"+atttype).text156 NumericStatProcess(unit['Attack']['Ranged'], atttype, Template.find("./Attack/Ranged/"+atttype)) 123 157 if (Template.find("./Attack/Ranged/Bonuses") != None): 124 158 for Bonus in Template.find("./Attack/Ranged/Bonuses"): 125 159 Against = [] … … 142 176 if (Template.find("./Armour") != None): 143 177 for atttype in AttackTypes: 144 178 if (Template.find("./Armour/"+atttype) != None): 145 unit['Armour'][atttype] = Template.find("./Armour/"+atttype).text179 NumericStatProcess(unit['Armour'], atttype, Template.find("./Armour/"+atttype)) 146 180 147 181 if (Template.find("./UnitMotion") != None): 148 182 if (Template.find("./UnitMotion/WalkSpeed") != None): 149 unit['WalkSpeed'] = Template.find("./UnitMotion/WalkSpeed").text183 NumericStatProcess(unit, 'WalkSpeed', Template.find("./UnitMotion/WalkSpeed")) 150 184 151 185 if (Template.find("./Identity/VisibleClasses") != None): 152 186 newClasses = Template.find("./Identity/VisibleClasses").text.split(" ") … … 174 208 175 209 rstr += "<td style=\"text-align:right;\">" + Name + "</td>\n" 176 210 177 rstr += "<td>" + UnitDict["HP"]+ "</td>\n"211 rstr += "<td>" + str(UnitDict["HP"]) + "</td>\n" 178 212 179 rstr += "<td>" + UnitDict["BuildTime"]+ "</td>\n"213 rstr += "<td>" + str(UnitDict["BuildTime"]) + "</td>\n" 180 214 181 rstr += "<td>" + UnitDict["WalkSpeed"]+ "</td>\n"215 rstr += "<td>" + str(UnitDict["WalkSpeed"]) + "</td>\n" 182 216 183 217 rstr += "<td>" + UnitDict["Cost"]["food"] + "F / " + UnitDict["Cost"]["wood"] + "W / " + UnitDict["Cost"]["stone"] + "S / " + UnitDict["Cost"]["metal"] + "M</td>\n" 184 218 … … 696 730 CivUnitComparisons(CivData[Civ],CivData[oCiv]) 697 731 f.write("</table>") 698 732 699 f.write("</body>\n</html>") 700 No newline at end of file 733 f.write("</body>\n</html>")