Mercurial > repos > IBDev-IBBoard.WarFoundry.API
annotate api/Factories/Xml/WarFoundryXmlRaceFactory.cs @ 274:4ef761279ea2
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
* Fix ability description loading by adding namespace alias
* Make use of utility method to help
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 19 Jun 2010 19:07:52 +0000 |
parents | 166d01079acf |
children | cd657faa0c05 8981fc45fe17 |
rev | line source |
---|---|
52 | 1 // This file (WarFoundryXmlRaceFactory.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard |
2 // | |
104
2f3cafb69799
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
99
diff
changeset
|
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. |
52 | 4 |
5 using System; | |
6 using System.Collections.Generic; | |
7 using System.IO; | |
8 using System.Xml; | |
9 using IBBoard.Xml; | |
10 using IBBoard.IO; | |
176
22429737cd77
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
175
diff
changeset
|
11 using IBBoard.Limits; |
171
85dc413279a4
* Change imports to stop references to deprecated code
IBBoard <dev@ibboard.co.uk>
parents:
170
diff
changeset
|
12 using IBBoard.CustomMath; |
52 | 13 using ICSharpCode.SharpZipLib.Zip; |
14 using IBBoard.WarFoundry.API.Objects; | |
15 | |
16 namespace IBBoard.WarFoundry.API.Factories.Xml | |
17 { | |
18 /// <summary> | |
19 /// A sub-factory for loading WarFoundry Race XML files | |
20 /// </summary> | |
21 public class WarFoundryXmlRaceFactory : AbstractStagedLoadedSubFactory | |
22 { | |
23 private Dictionary<Race, XmlDocument> extraData = new Dictionary<Race, XmlDocument>(); | |
265
6fe0cb1bf74f
Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
263
diff
changeset
|
24 private WarFoundryXmlLimitParser limitParser = new WarFoundryXmlLimitParser(); |
52 | 25 |
26 public WarFoundryXmlRaceFactory(WarFoundryXmlFactory factory) : base (factory) | |
27 { | |
99 | 28 //Do nothing special |
52 | 29 } |
30 | |
31 private void StoreExtraData(Race wfObject, XmlElement elem) | |
32 { | |
33 extraData[wfObject] = elem.OwnerDocument; | |
34 } | |
35 | |
36 private XmlDocument GetExtraData(Race obj) | |
37 { | |
38 XmlDocument extra = null; | |
231
d1c90159547a
Fixes #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
224
diff
changeset
|
39 extraData.TryGetValue(obj, out extra); |
52 | 40 return extra; |
41 } | |
42 | |
43 public Race CreateRaceFromElement(ZipFile file, XmlElement elem) | |
44 { | |
45 string id = elem.GetAttribute("id"); | |
46 string subid = elem.GetAttribute("subid"); | |
47 string systemID = elem.GetAttribute("system"); | |
48 string name = elem.GetAttribute("name"); | |
231
d1c90159547a
Fixes #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
224
diff
changeset
|
49 GameSystem gameSystem = WarFoundryLoader.GetDefault ().GetGameSystem (systemID); |
d1c90159547a
Fixes #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
224
diff
changeset
|
50 |
d1c90159547a
Fixes #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
224
diff
changeset
|
51 if (gameSystem == null) |
d1c90159547a
Fixes #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
224
diff
changeset
|
52 { |
232
f5009a00a50d
Re #236: Handle null game system in race
IBBoard <dev@ibboard.co.uk>
parents:
231
diff
changeset
|
53 throw new InvalidFileException("Referenced game system, '"+systemID+"', did not exist"); |
231
d1c90159547a
Fixes #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
224
diff
changeset
|
54 } |
d1c90159547a
Fixes #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
224
diff
changeset
|
55 |
d1c90159547a
Fixes #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
224
diff
changeset
|
56 Race race = new Race(id, subid, name, gameSystem, mainFactory); |
52 | 57 StoreExtraData(race, elem); |
58 return race; | |
59 } | |
60 | |
61 public void CompleteLoading(Race race) | |
62 { | |
63 if (!WarFoundryXmlFactoryUtils.CanCompleteLoading(race)) | |
64 { | |
65 return; | |
66 } | |
67 | |
68 race.SetAsLoading(); | |
69 XmlDocument extraData = GetExtraData(race); | |
70 | |
71 foreach (XmlElement node in WarFoundryXmlFactoryUtils.SelectNodes(extraData, "/race:race/race:categories/cat:cat")) | |
72 { | |
68
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
73 CreateCategoryFromElement(node, race); |
52 | 74 } |
75 | |
85
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
76 foreach (XmlElement node in WarFoundryXmlFactoryUtils.SelectNodes(extraData, "/race:race/race:equipment/race:equipmentItem")) |
52 | 77 { |
68
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
78 CreateEquipmentItemFromElement(node, race); |
52 | 79 } |
80 | |
85
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
81 foreach (XmlElement node in WarFoundryXmlFactoryUtils.SelectNodes(extraData, "/race:race/race:abilities/race:ability")) |
52 | 82 { |
68
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
83 CreateAbilityFromElement(node, race); |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
84 } |
252
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
242
diff
changeset
|
85 |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
242
diff
changeset
|
86 foreach (XmlElement node in WarFoundryXmlFactoryUtils.SelectNodes(extraData, "/race:race/race:memberTypes/race:memberType")) |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
242
diff
changeset
|
87 { |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
242
diff
changeset
|
88 CreateMemberTypeFromElement(node, race); |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
242
diff
changeset
|
89 } |
68
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
90 |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
91 foreach (XmlElement node in WarFoundryXmlFactoryUtils.SelectNodes(extraData, "/race:race/race:units/race:unit")) |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
92 { |
70
780f3926abad
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
69
diff
changeset
|
93 GetUnitTypeForElement(node, race); |
52 | 94 } |
95 | |
96 race.SetAsFullyLoaded(); | |
97 } | |
68
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
98 |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
99 private Category CreateCategoryFromElement(XmlElement elem, Race parentRace) |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
100 { |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
101 Category cat = CreateCategoryFromElement(elem); |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
102 parentRace.AddCategory(cat); |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
103 return cat; |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
104 } |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
105 |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
106 private UnitType GetUnitTypeFromDocument(XmlDocument doc, string id, Race parentRace) |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
107 { |
217
89e26d51afc2
Fixes #226: "NullReferenceException" for a unitID
IBBoard <dev@ibboard.co.uk>
parents:
207
diff
changeset
|
108 XmlElement unitWithId = WarFoundryXmlFactoryUtils.SelectSingleElement (doc, "/race:race/race:units/race:unit[@id='" + id + "']"); |
89e26d51afc2
Fixes #226: "NullReferenceException" for a unitID
IBBoard <dev@ibboard.co.uk>
parents:
207
diff
changeset
|
109 |
89e26d51afc2
Fixes #226: "NullReferenceException" for a unitID
IBBoard <dev@ibboard.co.uk>
parents:
207
diff
changeset
|
110 if (unitWithId == null) |
89e26d51afc2
Fixes #226: "NullReferenceException" for a unitID
IBBoard <dev@ibboard.co.uk>
parents:
207
diff
changeset
|
111 { |
89e26d51afc2
Fixes #226: "NullReferenceException" for a unitID
IBBoard <dev@ibboard.co.uk>
parents:
207
diff
changeset
|
112 throw new InvalidFileException("Could not find unit with ID "+id); |
89e26d51afc2
Fixes #226: "NullReferenceException" for a unitID
IBBoard <dev@ibboard.co.uk>
parents:
207
diff
changeset
|
113 } |
89e26d51afc2
Fixes #226: "NullReferenceException" for a unitID
IBBoard <dev@ibboard.co.uk>
parents:
207
diff
changeset
|
114 |
89e26d51afc2
Fixes #226: "NullReferenceException" for a unitID
IBBoard <dev@ibboard.co.uk>
parents:
207
diff
changeset
|
115 return GetUnitTypeForElement(unitWithId, parentRace); |
68
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
116 } |
52 | 117 |
70
780f3926abad
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
69
diff
changeset
|
118 private UnitType GetUnitTypeForElement(XmlElement elem, Race parentRace) |
52 | 119 { |
120 string id = elem.GetAttribute("id"); | |
68
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
121 UnitType type = parentRace.GetUnitType(id); |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
122 |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
123 if (type==null) |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
124 { |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
125 type = CreateUnitTypeFromElement(elem, id, parentRace); |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
126 } |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
127 |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
128 return type; |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
129 } |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
130 |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
131 private UnitType CreateUnitTypeFromElement(XmlElement elem, string id, Race parentRace) |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
132 { |
52 | 133 string name = elem.GetAttribute("typeName"); |
134 UnitType type = new UnitType(id, name, parentRace); | |
170 | 135 LoadCoreValuesForUnitType(elem, type); |
167
9ba56a8e5096
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
136 LoadEquipmentSlotsForUnitType(elem, type); |
68
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
137 LoadEquipmentForUnitType(elem, type); |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
138 LoadAbilitiesForUnitType(elem, type); |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
139 LoadContainedUnitsForUnitType(elem, type); |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
140 LoadRequirementsForUnitType(elem, type); |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
141 LoadExtraDataForUnitType(elem, type); |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
142 LoadNotesForUnitType(elem, type); |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
143 parentRace.AddUnitType(type); |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
144 return type; |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
145 } |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
146 |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
147 private void LoadCoreValuesForUnitType(XmlElement elem, UnitType type) |
158
eb9a6d91a6db
Fixes #190: Mutex groups aren't honoured when adding equipment
IBBoard <dev@ibboard.co.uk>
parents:
156
diff
changeset
|
148 { |
eb9a6d91a6db
Fixes #190: Mutex groups aren't honoured when adding equipment
IBBoard <dev@ibboard.co.uk>
parents:
156
diff
changeset
|
149 try |
eb9a6d91a6db
Fixes #190: Mutex groups aren't honoured when adding equipment
IBBoard <dev@ibboard.co.uk>
parents:
156
diff
changeset
|
150 { |
eb9a6d91a6db
Fixes #190: Mutex groups aren't honoured when adding equipment
IBBoard <dev@ibboard.co.uk>
parents:
156
diff
changeset
|
151 type.MaxNumber = XmlTools.GetIntValueFromAttribute(elem, "maxNum"); |
eb9a6d91a6db
Fixes #190: Mutex groups aren't honoured when adding equipment
IBBoard <dev@ibboard.co.uk>
parents:
156
diff
changeset
|
152 type.MinNumber = XmlTools.GetIntValueFromAttribute(elem, "minNum"); |
eb9a6d91a6db
Fixes #190: Mutex groups aren't honoured when adding equipment
IBBoard <dev@ibboard.co.uk>
parents:
156
diff
changeset
|
153 type.MaxSize = XmlTools.GetIntValueFromAttribute(elem, "maxSize"); |
eb9a6d91a6db
Fixes #190: Mutex groups aren't honoured when adding equipment
IBBoard <dev@ibboard.co.uk>
parents:
156
diff
changeset
|
154 type.MinSize = XmlTools.GetIntValueFromAttribute(elem, "minSize"); |
eb9a6d91a6db
Fixes #190: Mutex groups aren't honoured when adding equipment
IBBoard <dev@ibboard.co.uk>
parents:
156
diff
changeset
|
155 type.BaseSize = XmlTools.GetIntValueFromAttribute(elem, "baseSize"); |
eb9a6d91a6db
Fixes #190: Mutex groups aren't honoured when adding equipment
IBBoard <dev@ibboard.co.uk>
parents:
156
diff
changeset
|
156 type.CostPerTrooper = XmlTools.GetDoubleValueFromAttribute(elem, "points"); |
224
f097888efcfe
Fixes #233: "unitPoints" attribute is badly named
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
157 type.BaseUnitCost = XmlTools.GetDoubleValueFromAttribute(elem, "basePoints"); |
158
eb9a6d91a6db
Fixes #190: Mutex groups aren't honoured when adding equipment
IBBoard <dev@ibboard.co.uk>
parents:
156
diff
changeset
|
158 } |
eb9a6d91a6db
Fixes #190: Mutex groups aren't honoured when adding equipment
IBBoard <dev@ibboard.co.uk>
parents:
156
diff
changeset
|
159 catch (FormatException ex) |
eb9a6d91a6db
Fixes #190: Mutex groups aren't honoured when adding equipment
IBBoard <dev@ibboard.co.uk>
parents:
156
diff
changeset
|
160 { |
217
89e26d51afc2
Fixes #226: "NullReferenceException" for a unitID
IBBoard <dev@ibboard.co.uk>
parents:
207
diff
changeset
|
161 throw new InvalidFileException(ex.Message, ex); |
156
62ff1ac132d2
Fixes #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
154
diff
changeset
|
162 } |
62ff1ac132d2
Fixes #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
154
diff
changeset
|
163 |
257
435eb28b4549
Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
252
diff
changeset
|
164 Race race = type.Race; |
52 | 165 string mainCatID = elem.GetAttribute("cat"); |
257
435eb28b4549
Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
252
diff
changeset
|
166 Category cat = race.GetCategory(mainCatID); |
52 | 167 |
168 if (cat == null) | |
169 { | |
217
89e26d51afc2
Fixes #226: "NullReferenceException" for a unitID
IBBoard <dev@ibboard.co.uk>
parents:
207
diff
changeset
|
170 throw new InvalidFileException(String.Format("Category with ID '{1}' did not exist for UnitType '{0}'", type.Name, mainCatID)); |
52 | 171 } |
172 | |
173 type.MainCategory = cat; | |
257
435eb28b4549
Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
252
diff
changeset
|
174 |
435eb28b4549
Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
252
diff
changeset
|
175 XmlNodeList unitCategories = WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:unitCategories/race:unitCategory"); |
435eb28b4549
Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
252
diff
changeset
|
176 |
435eb28b4549
Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
252
diff
changeset
|
177 foreach (XmlElement unitCategory in unitCategories) |
435eb28b4549
Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
252
diff
changeset
|
178 { |
435eb28b4549
Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
252
diff
changeset
|
179 string catID = unitCategory.GetAttribute("catID"); |
435eb28b4549
Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
252
diff
changeset
|
180 Category unitCat = race.GetCategory(catID); |
435eb28b4549
Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
252
diff
changeset
|
181 |
435eb28b4549
Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
252
diff
changeset
|
182 if (unitCat == null) |
435eb28b4549
Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
252
diff
changeset
|
183 { |
435eb28b4549
Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
252
diff
changeset
|
184 throw new InvalidFileException(String.Format("Category with ID '{1}' did not exist for UnitType '{0}'", type.Name, catID)); |
435eb28b4549
Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
252
diff
changeset
|
185 } |
435eb28b4549
Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
252
diff
changeset
|
186 |
435eb28b4549
Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
252
diff
changeset
|
187 type.AddCategory(unitCat); |
435eb28b4549
Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
252
diff
changeset
|
188 } |
435eb28b4549
Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
252
diff
changeset
|
189 |
133
a6d1cc17ec33
* Fix XPath query so that units get the right stats instead of just the first stats
IBBoard <dev@ibboard.co.uk>
parents:
128
diff
changeset
|
190 XmlElement statsElement = WarFoundryXmlFactoryUtils.SelectSingleElement(elem, "race:stats"); |
252
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
242
diff
changeset
|
191 |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
242
diff
changeset
|
192 if (statsElement!=null) |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
242
diff
changeset
|
193 { |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
242
diff
changeset
|
194 Stats unitStats = ParseUnitStats(statsElement, type.GameSystem); |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
242
diff
changeset
|
195 type.SetUnitStats(unitStats); |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
242
diff
changeset
|
196 } |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
242
diff
changeset
|
197 |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
242
diff
changeset
|
198 XmlNodeList unitMemberReferences = WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:unitMembers/race:unitMember"); |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
242
diff
changeset
|
199 |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
242
diff
changeset
|
200 foreach (XmlElement unitMemberRef in unitMemberReferences) |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
242
diff
changeset
|
201 { |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
242
diff
changeset
|
202 string typeID = unitMemberRef.GetAttribute("typeID"); |
257
435eb28b4549
Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
252
diff
changeset
|
203 UnitMemberType unitMemberType = race.GetUnitMemberType(typeID); |
252
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
242
diff
changeset
|
204 type.AddUnitMemberType(unitMemberType); |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
242
diff
changeset
|
205 } |
170 | 206 } |
207 | |
208 private void LoadEquipmentSlotsForUnitType(XmlElement elem, UnitType type) | |
209 { | |
176
22429737cd77
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
175
diff
changeset
|
210 foreach (XmlElement equipSlot in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:equipmentSlots/race:equipmentSlot")) |
170 | 211 { |
176
22429737cd77
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
175
diff
changeset
|
212 LoadEquipmentSlotForUnitType (type, equipSlot); |
22429737cd77
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
175
diff
changeset
|
213 } |
22429737cd77
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
175
diff
changeset
|
214 } |
22429737cd77
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
175
diff
changeset
|
215 |
265
6fe0cb1bf74f
Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
263
diff
changeset
|
216 private void LoadEquipmentSlotForUnitType(UnitType type, XmlElement equipSlot) |
176
22429737cd77
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
175
diff
changeset
|
217 { |
265
6fe0cb1bf74f
Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
263
diff
changeset
|
218 string slotName = equipSlot.GetAttribute("name"); |
6fe0cb1bf74f
Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
263
diff
changeset
|
219 ILimit limit = GetMaxLimit(equipSlot); |
176
22429737cd77
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
175
diff
changeset
|
220 |
265
6fe0cb1bf74f
Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
263
diff
changeset
|
221 if (limit != null) |
176
22429737cd77
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
175
diff
changeset
|
222 { |
265
6fe0cb1bf74f
Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
263
diff
changeset
|
223 type.AddEquipmentSlot(slotName, limit); |
170 | 224 } |
68
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
225 } |
176
22429737cd77
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
175
diff
changeset
|
226 |
265
6fe0cb1bf74f
Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
263
diff
changeset
|
227 private ILimit GetMinLimit(XmlElement elem) |
176
22429737cd77
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
175
diff
changeset
|
228 { |
265
6fe0cb1bf74f
Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
263
diff
changeset
|
229 return limitParser.GetMinLimit(elem); |
176
22429737cd77
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
175
diff
changeset
|
230 } |
22429737cd77
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
175
diff
changeset
|
231 |
265
6fe0cb1bf74f
Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
263
diff
changeset
|
232 private ILimit GetMaxLimit(XmlElement elem) |
6fe0cb1bf74f
Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
263
diff
changeset
|
233 { |
6fe0cb1bf74f
Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
263
diff
changeset
|
234 return limitParser.GetMaxLimit(elem); |
6fe0cb1bf74f
Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
263
diff
changeset
|
235 } |
68
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
236 |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
237 private void LoadEquipmentForUnitType(XmlElement elem, UnitType type) |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
238 { |
85
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
239 foreach (XmlElement equip in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:unitEquipment/race:unitEquipmentItem")) |
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
240 { |
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
241 string id = equip.GetAttribute("id"); |
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
242 EquipmentItem equipItem = type.Race.GetEquipmentItem(id); |
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
243 |
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
244 if (equipItem!=null) |
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
245 { |
154
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
246 string mutexGroupString = equip.GetAttribute("exclusivityGroups"); |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
247 string[] mutexGroups; |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
248 |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
249 if (mutexGroupString == "") |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
250 { |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
251 mutexGroupString = equip.GetAttribute("exclusivityGroup"); |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
252 } |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
253 |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
254 if (mutexGroupString != "") |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
255 { |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
256 string[] groups = mutexGroupString.Split(','); |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
257 int groupCount = groups.Length; |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
258 |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
259 for (int i = 0; i < groupCount; i++) |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
260 { |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
261 groups[i] = groups[i].Trim(); |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
262 } |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
263 |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
264 mutexGroups = groups; |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
265 } |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
266 else |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
267 { |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
268 mutexGroups = new string[0]; |
152
0c0e14f03785
Re #180: Add multiple mutex groups
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
269 } |
0c0e14f03785
Re #180: Add multiple mutex groups
IBBoard <dev@ibboard.co.uk>
parents:
138
diff
changeset
|
270 |
170 | 271 UnitEquipmentItem unitEquipItem = new UnitEquipmentItem(equipItem, type, mutexGroups); |
272 | |
273 string equipSlot = equip.GetAttribute("equipmentSlot"); | |
274 | |
275 if (equipSlot != "") | |
276 { | |
277 if (type.HasEquipmentSlot(equipSlot)) | |
278 { | |
279 unitEquipItem.SlotName = equipSlot; | |
280 } | |
281 else | |
282 { | |
283 throw new InvalidFileException("Attribute 'equipmentSlot' of unit equipment item " + id + " for " + type.Name + " was not a valid slot name"); | |
284 } | |
198 | 285 } |
286 | |
265
6fe0cb1bf74f
Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
263
diff
changeset
|
287 ILimit limit = GetMaxLimit(equip); |
198 | 288 |
289 if (limit != null) | |
290 { | |
291 unitEquipItem.MaxLimit = limit; | |
292 } | |
293 | |
294 limit = GetMinLimit(equip); | |
295 | |
296 if (limit != null) | |
297 { | |
298 unitEquipItem.MinLimit = limit; | |
167
9ba56a8e5096
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
299 } |
183
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
176
diff
changeset
|
300 |
90
bd2aaa9a61df
Re #50: Complete loading of core XML file
IBBoard <dev@ibboard.co.uk>
parents:
88
diff
changeset
|
301 unitEquipItem.RoundNumberUp = equip.GetAttribute("roundDirection").Equals("up"); |
86
129636305ad7
Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents:
85
diff
changeset
|
302 |
129636305ad7
Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents:
85
diff
changeset
|
303 try |
129636305ad7
Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents:
85
diff
changeset
|
304 { |
219
f609bcf7035b
Fixes #222: decimal comma/point not handled correctly (again?) in costMultiplier
IBBoard <dev@ibboard.co.uk>
parents:
217
diff
changeset
|
305 unitEquipItem.IsRequired = XmlTools.GetBoolValueFromAttribute(equip, "required"); |
86
129636305ad7
Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents:
85
diff
changeset
|
306 } |
129636305ad7
Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents:
85
diff
changeset
|
307 catch(FormatException e) |
129636305ad7
Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents:
85
diff
changeset
|
308 { |
87
9fba3b4ccdcd
Re #50: Complete core XML loading
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
309 throw new InvalidFileException("Attribute 'required' of unit equipment item " + id + " for " + type.Name + " was not a valid boolean", e); |
86
129636305ad7
Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents:
85
diff
changeset
|
310 } |
129636305ad7
Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents:
85
diff
changeset
|
311 |
129636305ad7
Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents:
85
diff
changeset
|
312 try |
91
571d8ddc7d9a
Fixes #111: "Replace Weapon" button doesn't always enable
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
313 { |
219
f609bcf7035b
Fixes #222: decimal comma/point not handled correctly (again?) in costMultiplier
IBBoard <dev@ibboard.co.uk>
parents:
217
diff
changeset
|
314 unitEquipItem.CostMultiplier = XmlTools.GetDoubleValueFromAttribute(equip, "costMultiplier"); |
86
129636305ad7
Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents:
85
diff
changeset
|
315 } |
129636305ad7
Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents:
85
diff
changeset
|
316 catch (FormatException e) |
129636305ad7
Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents:
85
diff
changeset
|
317 { |
87
9fba3b4ccdcd
Re #50: Complete core XML loading
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
318 throw new InvalidFileException("Attribute 'costMultiplier' of unit equipment item " + id + " for " + type.Name + " was not a valid decimal number", e); |
86
129636305ad7
Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents:
85
diff
changeset
|
319 } |
129636305ad7
Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents:
85
diff
changeset
|
320 |
129636305ad7
Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents:
85
diff
changeset
|
321 try |
129636305ad7
Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents:
85
diff
changeset
|
322 { |
88
110a7b0bcab5
Re #50: Complete core loading from XML
IBBoard <dev@ibboard.co.uk>
parents:
87
diff
changeset
|
323 unitEquipItem.CostRoundType = (RoundType) Enum.Parse(typeof(RoundType), equip.GetAttribute("costRounding")); |
86
129636305ad7
Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents:
85
diff
changeset
|
324 } |
129636305ad7
Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents:
85
diff
changeset
|
325 catch (ArgumentException e) |
129636305ad7
Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents:
85
diff
changeset
|
326 { |
87
9fba3b4ccdcd
Re #50: Complete core XML loading
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
327 throw new InvalidFileException("Attribute 'costRounding' of unit equipment item " + id + " for " + type.Name + " was not a valid rounding type", e); |
86
129636305ad7
Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents:
85
diff
changeset
|
328 } |
85
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
329 } |
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
330 else |
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
331 { |
128
45a9452579a2
Fixes #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
332 throw new InvalidFileException("Equipment item with ID '" + id + "' was required by " + type.Name + " but was not found"); |
85
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
333 } |
195
11bad32cfa06
* Implement new equipment limit loading
IBBoard <dev@ibboard.co.uk>
parents:
192
diff
changeset
|
334 } |
198 | 335 } |
68
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
336 |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
337 private void LoadAbilitiesForUnitType(XmlElement elem, UnitType type) |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
338 { |
222
2f9ad5385707
Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents:
221
diff
changeset
|
339 foreach (XmlElement abilityElem in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:unitAbilities/race:unitAbility")) |
68
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
340 { |
222
2f9ad5385707
Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents:
221
diff
changeset
|
341 string id = abilityElem.GetAttribute("abilityID"); |
221
78f7456f6419
Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents:
219
diff
changeset
|
342 Ability ability = type.Race.GetAbility(id); |
78f7456f6419
Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents:
219
diff
changeset
|
343 |
78f7456f6419
Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents:
219
diff
changeset
|
344 if (ability == null) |
78f7456f6419
Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents:
219
diff
changeset
|
345 { |
78f7456f6419
Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents:
219
diff
changeset
|
346 throw new InvalidFileException("Ability for "+type.Name+ " with ID "+id+ " did not exist in race definition"); |
78f7456f6419
Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents:
219
diff
changeset
|
347 } |
222
2f9ad5385707
Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents:
221
diff
changeset
|
348 |
2f9ad5385707
Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents:
221
diff
changeset
|
349 bool required = XmlTools.GetBoolValueFromAttribute(abilityElem, "required"); |
221
78f7456f6419
Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents:
219
diff
changeset
|
350 type.AddAbility(ability, required); |
68
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
351 } |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
352 } |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
353 |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
354 private void LoadContainedUnitsForUnitType(XmlElement elem, UnitType type) |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
355 { |
69
91cf8efbea0b
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
356 foreach (XmlElement containedUnitType in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:contains/race:containedUnit")) |
91cf8efbea0b
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
357 { |
91cf8efbea0b
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
358 string id = containedUnitType.GetAttribute("containedID"); |
91cf8efbea0b
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
359 UnitType containedType = GetUnitTypeFromDocument(elem.OwnerDocument, id, type.Race); |
91cf8efbea0b
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
360 |
91cf8efbea0b
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
361 if (containedType!=null) |
91cf8efbea0b
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
362 { |
91cf8efbea0b
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
363 type.AddContainedUnitType(containedType); |
91cf8efbea0b
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
364 } |
91cf8efbea0b
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
365 else |
91cf8efbea0b
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
366 { |
128
45a9452579a2
Fixes #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
367 throw new InvalidFileException("Unit type " + type.Name + " tried to contain undefined unit with ID "+id); |
69
91cf8efbea0b
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
368 } |
91cf8efbea0b
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
369 } |
68
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
370 } |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
371 |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
372 private void LoadRequirementsForUnitType(XmlElement elem, UnitType type) |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
373 { |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
374 //TODO: Load requirements |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
375 } |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
376 |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
377 private void LoadExtraDataForUnitType(XmlElement elem, UnitType type) |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
378 { |
272
166d01079acf
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
265
diff
changeset
|
379 foreach (XmlElement extraData in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:extraData/race:data")) |
166d01079acf
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
265
diff
changeset
|
380 { |
166d01079acf
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
265
diff
changeset
|
381 string id = extraData.GetAttribute("id"); |
166d01079acf
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
265
diff
changeset
|
382 string data = extraData.InnerXml; |
166d01079acf
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
265
diff
changeset
|
383 type.AddExtraData(id, data); |
166d01079acf
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
265
diff
changeset
|
384 } |
68
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
385 } |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
386 |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
387 private void LoadNotesForUnitType(XmlElement elem, UnitType type) |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
388 { |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
389 XmlNode node = WarFoundryXmlFactoryUtils.SelectSingleNode(elem, "race:notes"); |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
390 |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
391 if (node!=null) |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
392 { |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
393 type.Notes = node.InnerText; |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
394 } |
52 | 395 } |
396 | |
397 private Stats ParseUnitStats(XmlElement elem, GameSystem system) | |
398 { | |
252
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
242
diff
changeset
|
399 if (elem == null) |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
242
diff
changeset
|
400 { |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
242
diff
changeset
|
401 return null; |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
242
diff
changeset
|
402 } |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
242
diff
changeset
|
403 |
52 | 404 String statsID = elem.GetAttribute("statSet"); |
405 SystemStats statsSet; | |
406 | |
407 if (statsID == "") | |
408 { | |
409 statsSet = system.StandardSystemStats; | |
410 } | |
411 else | |
412 { | |
413 statsSet = system.GetSystemStatsForID(statsID); | |
414 } | |
415 | |
416 Stats stats = new Stats(statsSet); | |
417 | |
53 | 418 foreach (XmlElement stat in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:stat")) |
52 | 419 { |
67
e6200220ece3
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
55
diff
changeset
|
420 String statName = stat.GetAttribute("name"); |
e6200220ece3
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
55
diff
changeset
|
421 stats.SetStatValue(statName, stat.InnerText); |
52 | 422 } |
423 | |
424 return stats; | |
425 } | |
426 | |
427 private EquipmentItem CreateEquipmentItemFromElement(XmlElement elem, Race race) | |
428 { | |
429 string id = elem.GetAttribute("id"); | |
68
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
430 EquipmentItem item = race.GetEquipmentItem(id); |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
431 |
85
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
432 if (item == null) |
68
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
433 { |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
434 item = CreateEquipmentItemFromElement(elem, id, race); |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
435 } |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
436 |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
437 return item; |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
438 } |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
439 |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
440 private EquipmentItem CreateEquipmentItemFromElement(XmlElement elem, string id, Race race) |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
441 { |
52 | 442 string name = elem.GetAttribute("name"); |
68
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
443 EquipmentItem item = new EquipmentItem(id, name, race); |
55
9080366031c0
Re #9 - Refactor for small methods
IBBoard <dev@ibboard.co.uk>
parents:
53
diff
changeset
|
444 double cost = 0; |
52 | 445 |
446 try | |
447 { | |
448 cost = XmlTools.GetDoubleValueFromAttribute(elem, "cost"); | |
449 } | |
450 catch(FormatException ex) | |
451 { | |
452 throw new InvalidFileException("Attribute 'cost' of equipment item "+id+" was not a valid number", ex); | |
453 } | |
263
7933d852181e
Re #289: Double-check extensibility where sets of values are allowed
IBBoard <dev@ibboard.co.uk>
parents:
257
diff
changeset
|
454 |
52 | 455 //TODO: Parse equipment stats if there are any |
55
9080366031c0
Re #9 - Refactor for small methods
IBBoard <dev@ibboard.co.uk>
parents:
53
diff
changeset
|
456 item.Cost = cost; |
85
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
457 race.AddEquipmentItem(item); |
55
9080366031c0
Re #9 - Refactor for small methods
IBBoard <dev@ibboard.co.uk>
parents:
53
diff
changeset
|
458 return item; |
52 | 459 } |
460 | |
461 private Ability CreateAbilityFromElement(XmlElement elem, Race race) | |
462 { | |
463 string id = elem.GetAttribute("id"); | |
464 string name = elem.GetAttribute("name"); | |
465 Ability ability = new Ability(id, name); | |
274
4ef761279ea2
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
272
diff
changeset
|
466 XmlNode node = WarFoundryXmlFactoryUtils.SelectSingleNode(elem, "race:description"); |
52 | 467 ability.Description = (node == null) ? "" : node.InnerText; |
85
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
468 race.AddAbility(ability); |
52 | 469 return ability; |
252
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
242
diff
changeset
|
470 } |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
242
diff
changeset
|
471 |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
242
diff
changeset
|
472 private void CreateMemberTypeFromElement(XmlElement elem, Race race) |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
242
diff
changeset
|
473 { |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
242
diff
changeset
|
474 Stats stats = ParseUnitStats(WarFoundryXmlFactoryUtils.SelectSingleElement(elem, "race:stats"), race.GameSystem); |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
242
diff
changeset
|
475 UnitMemberType unitMemberType = new UnitMemberType(elem.GetAttribute("id"), elem.GetAttribute("name"), stats); |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
242
diff
changeset
|
476 race.AddUnitMemberType(unitMemberType); |
52 | 477 } |
478 } | |
479 } |