Mercurial > repos > IBDev-IBBoard.WarFoundry.API
annotate API/Factories/Xml/WarFoundryXmlRaceFactory.cs @ 481:81f32062c9fa
Re #419: Remove assumptions of a file-based install
* Convert schemas to resources and load them from there
* Remove use of "data" folder relative to exe location from default "Hacks" (GTK/WinForms GUIs can re-add it locally)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 25 Jun 2012 21:04:02 +0100 |
parents | 2ba1f24eb427 |
children |
rev | line source |
---|---|
469
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
1 // This file (WarFoundryXmlRaceFactory.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
2 // |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
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. |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
4 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
5 using System; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
6 using System.Collections.Generic; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
7 using System.IO; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
8 using System.Xml; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
9 using IBBoard.Xml; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
10 using IBBoard.IO; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
11 using IBBoard.Limits; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
12 using IBBoard.CustomMath; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
13 using ICSharpCode.SharpZipLib.Zip; |
370
077e9be48438
Re #346: Add requirement schema support
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
14 using IBBoard.WarFoundry.API.Objects; |
371
bfdb95906075
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
370
diff
changeset
|
15 using IBBoard.WarFoundry.API.Objects.Requirement; |
469
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
16 using IBBoard.WarFoundry.API.Factories.Requirement; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
17 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
18 namespace IBBoard.WarFoundry.API.Factories.Xml |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
19 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
20 /// <summary> |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
21 /// A sub-factory for loading WarFoundry Race XML files |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
22 /// </summary> |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
23 public class WarFoundryXmlRaceFactory : IRaceFactory<XmlDocument, XmlElement> |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
24 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
25 private Dictionary<Race, XmlDocument> extraData = new Dictionary<Race, XmlDocument>(); |
376
e50682387d63
Re #353: Handle unloaded units being referenced outside factory
IBBoard <dev@ibboard.co.uk>
parents:
374
diff
changeset
|
26 private WarFoundryXmlLimitParser limitParser = new WarFoundryXmlLimitParser(); |
469
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
27 private WarFoundryXmlFactory mainFactory; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
28 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
29 public WarFoundryXmlRaceFactory(WarFoundryXmlFactory factory) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
30 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
31 this.mainFactory = factory; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
32 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
33 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
34 private void StoreExtraData(Race wfObject, XmlElement elem) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
35 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
36 extraData[wfObject] = elem.OwnerDocument; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
37 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
38 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
39 private XmlDocument GetExtraData(Race obj) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
40 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
41 XmlDocument extra = null; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
42 extraData.TryGetValue(obj, out extra); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
43 return extra; |
377
c3b0b28bad48
Re #353: Handle unloaded units being referenced outside factory
IBBoard <dev@ibboard.co.uk>
parents:
376
diff
changeset
|
44 } |
c3b0b28bad48
Re #353: Handle unloaded units being referenced outside factory
IBBoard <dev@ibboard.co.uk>
parents:
376
diff
changeset
|
45 |
c3b0b28bad48
Re #353: Handle unloaded units being referenced outside factory
IBBoard <dev@ibboard.co.uk>
parents:
376
diff
changeset
|
46 public Race CreateRace(XmlElement elem) |
c3b0b28bad48
Re #353: Handle unloaded units being referenced outside factory
IBBoard <dev@ibboard.co.uk>
parents:
376
diff
changeset
|
47 { |
469
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
48 string id = elem.GetAttribute("id"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
49 string subid = elem.GetAttribute("subid"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
50 string systemID = elem.GetAttribute("system"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
51 string name = elem.GetAttribute("name"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
52 string armyDefaultName = elem.GetAttribute("defaultArmyName"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
53 GameSystem gameSystem = WarFoundryLoader.GetDefault ().GetGameSystem (systemID); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
54 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
55 if (gameSystem == null) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
56 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
57 throw new InvalidFileException("Referenced game system, '"+systemID+"', did not exist"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
58 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
59 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
60 Race race = new Race(id, subid, name, gameSystem, mainFactory); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
61 race.ArmyDefaultName = armyDefaultName; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
62 StoreExtraData(race, elem); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
63 return race; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
64 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
65 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
66 public void CompleteLoading(Race race) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
67 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
68 if (!WarFoundryXmlFactoryUtils.CanCompleteLoading(race)) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
69 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
70 return; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
71 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
72 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
73 race.SetAsLoading(); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
74 XmlDocument extraData = GetExtraData(race); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
75 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
76 foreach (XmlElement node in WarFoundryXmlFactoryUtils.SelectNodes(extraData, "/race:race/race:categories/cat:cat")) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
77 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
78 CreateCategoryFromElement(node, race); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
79 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
80 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
81 foreach (XmlElement node in WarFoundryXmlFactoryUtils.SelectNodes(extraData, "/race:race/race:equipment/race:equipmentItem")) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
82 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
83 CreateEquipmentItemFromElement(node, race); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
84 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
85 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
86 foreach (XmlElement node in WarFoundryXmlFactoryUtils.SelectNodes(extraData, "/race:race/race:abilities/race:ability")) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
87 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
88 CreateAbilityFromElement(node, race); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
89 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
90 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
91 foreach (XmlElement node in WarFoundryXmlFactoryUtils.SelectNodes(extraData, "/race:race/race:memberTypes/race:memberType")) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
92 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
93 CreateMemberTypeFromElement(node, race); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
94 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
95 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
96 foreach (XmlElement node in WarFoundryXmlFactoryUtils.SelectNodes(extraData, "/race:race/race:units/race:unit")) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
97 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
98 GetUnitTypeForElement(node, race); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
99 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
100 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
101 race.SetAsFullyLoaded(); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
102 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
103 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
104 private Category CreateCategoryFromElement(XmlElement elem, Race parentRace) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
105 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
106 Category cat = CategoryLoader.CreateFromElement(elem); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
107 parentRace.AddCategory(cat); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
108 return cat; |
377
c3b0b28bad48
Re #353: Handle unloaded units being referenced outside factory
IBBoard <dev@ibboard.co.uk>
parents:
376
diff
changeset
|
109 } |
c3b0b28bad48
Re #353: Handle unloaded units being referenced outside factory
IBBoard <dev@ibboard.co.uk>
parents:
376
diff
changeset
|
110 |
c3b0b28bad48
Re #353: Handle unloaded units being referenced outside factory
IBBoard <dev@ibboard.co.uk>
parents:
376
diff
changeset
|
111 |
c3b0b28bad48
Re #353: Handle unloaded units being referenced outside factory
IBBoard <dev@ibboard.co.uk>
parents:
376
diff
changeset
|
112 public UnitType GetUnitType(string id, Race parentRace) |
c3b0b28bad48
Re #353: Handle unloaded units being referenced outside factory
IBBoard <dev@ibboard.co.uk>
parents:
376
diff
changeset
|
113 { |
c3b0b28bad48
Re #353: Handle unloaded units being referenced outside factory
IBBoard <dev@ibboard.co.uk>
parents:
376
diff
changeset
|
114 return GetUnitType(id, parentRace, GetExtraData(parentRace)); |
c3b0b28bad48
Re #353: Handle unloaded units being referenced outside factory
IBBoard <dev@ibboard.co.uk>
parents:
376
diff
changeset
|
115 } |
c3b0b28bad48
Re #353: Handle unloaded units being referenced outside factory
IBBoard <dev@ibboard.co.uk>
parents:
376
diff
changeset
|
116 |
c3b0b28bad48
Re #353: Handle unloaded units being referenced outside factory
IBBoard <dev@ibboard.co.uk>
parents:
376
diff
changeset
|
117 public UnitType GetUnitType(string id, Race parentRace, XmlDocument doc) |
c3b0b28bad48
Re #353: Handle unloaded units being referenced outside factory
IBBoard <dev@ibboard.co.uk>
parents:
376
diff
changeset
|
118 { |
c3b0b28bad48
Re #353: Handle unloaded units being referenced outside factory
IBBoard <dev@ibboard.co.uk>
parents:
376
diff
changeset
|
119 UnitType type = parentRace.GetUnitType(id); |
c3b0b28bad48
Re #353: Handle unloaded units being referenced outside factory
IBBoard <dev@ibboard.co.uk>
parents:
376
diff
changeset
|
120 |
c3b0b28bad48
Re #353: Handle unloaded units being referenced outside factory
IBBoard <dev@ibboard.co.uk>
parents:
376
diff
changeset
|
121 if (type==null) |
c3b0b28bad48
Re #353: Handle unloaded units being referenced outside factory
IBBoard <dev@ibboard.co.uk>
parents:
376
diff
changeset
|
122 { |
c3b0b28bad48
Re #353: Handle unloaded units being referenced outside factory
IBBoard <dev@ibboard.co.uk>
parents:
376
diff
changeset
|
123 type = GetUnitTypeFromDocument(doc, id, parentRace); |
c3b0b28bad48
Re #353: Handle unloaded units being referenced outside factory
IBBoard <dev@ibboard.co.uk>
parents:
376
diff
changeset
|
124 } |
c3b0b28bad48
Re #353: Handle unloaded units being referenced outside factory
IBBoard <dev@ibboard.co.uk>
parents:
376
diff
changeset
|
125 |
c3b0b28bad48
Re #353: Handle unloaded units being referenced outside factory
IBBoard <dev@ibboard.co.uk>
parents:
376
diff
changeset
|
126 return type; |
469
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
127 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
128 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
129 private UnitType GetUnitTypeFromDocument(XmlDocument doc, string id, Race parentRace) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
130 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
131 XmlElement unitWithId = WarFoundryXmlFactoryUtils.SelectSingleElement (doc, "/race:race/race:units/race:unit[@id='" + id + "']"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
132 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
133 if (unitWithId == null) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
134 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
135 throw new InvalidFileException("Could not find unit with ID "+id); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
136 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
137 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
138 return GetUnitTypeForElement(unitWithId, parentRace); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
139 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
140 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
141 private UnitType GetUnitTypeForElement(XmlElement elem, Race parentRace) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
142 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
143 string id = elem.GetAttribute("id"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
144 UnitType type = parentRace.GetUnitType(id); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
145 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
146 if (type==null) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
147 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
148 type = CreateUnitTypeFromElement(elem, id, parentRace); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
149 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
150 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
151 return type; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
152 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
153 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
154 private UnitType CreateUnitTypeFromElement(XmlElement elem, string id, Race parentRace) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
155 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
156 string name = elem.GetAttribute("typeName"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
157 UnitType type = new UnitType(id, name, parentRace); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
158 LoadCoreValuesForUnitType(elem, type); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
159 parentRace.AddUnitType(type); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
160 LoadEquipmentSlotsForUnitType(elem, type); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
161 LoadEquipmentForUnitType(elem, type); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
162 LoadAbilitiesForUnitType(elem, type); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
163 LoadContainedUnitsForUnitType(elem, type); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
164 LoadRequirementsForUnitType(elem, type); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
165 LoadExtraDataForUnitType(elem, type); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
166 LoadNotesForUnitType(elem, type); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
167 return type; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
168 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
169 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
170 private void LoadCoreValuesForUnitType(XmlElement elem, UnitType type) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
171 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
172 try |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
173 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
174 type.MaxNumber = XmlTools.GetIntValueFromAttribute(elem, "maxNum"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
175 type.MinNumber = XmlTools.GetIntValueFromAttribute(elem, "minNum"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
176 type.MaxSize = XmlTools.GetIntValueFromAttribute(elem, "maxSize"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
177 type.MinSize = XmlTools.GetIntValueFromAttribute(elem, "minSize"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
178 type.BaseSize = XmlTools.GetIntValueFromAttribute(elem, "baseSize"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
179 type.CostPerTrooper = XmlTools.GetDoubleValueFromAttribute(elem, "points"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
180 type.BaseUnitCost = XmlTools.GetDoubleValueFromAttribute(elem, "basePoints"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
181 type.IsContainedOnly = XmlTools.GetBoolValueFromAttribute(elem, "containedOnly"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
182 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
183 catch (FormatException ex) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
184 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
185 throw new InvalidFileException(ex.Message, ex); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
186 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
187 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
188 Race race = type.Race; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
189 string mainCatID = elem.GetAttribute("cat"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
190 Category cat = race.GetCategory(mainCatID); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
191 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
192 if (cat == null) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
193 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
194 throw new InvalidFileException(String.Format("Category with ID '{1}' did not exist for UnitType '{0}'", type.Name, mainCatID)); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
195 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
196 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
197 type.MainCategory = cat; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
198 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
199 XmlNodeList unitCategories = WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:unitCategories/race:unitCategory"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
200 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
201 foreach (XmlElement unitCategory in unitCategories) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
202 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
203 string catID = unitCategory.GetAttribute("catID"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
204 Category unitCat = race.GetCategory(catID); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
205 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
206 if (unitCat == null) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
207 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
208 throw new InvalidFileException(String.Format("Category with ID '{1}' did not exist for UnitType '{0}'", type.Name, catID)); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
209 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
210 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
211 type.AddCategory(unitCat); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
212 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
213 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
214 XmlElement statsElement = WarFoundryXmlFactoryUtils.SelectSingleElement(elem, "race:stats"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
215 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
216 if (statsElement!=null) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
217 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
218 Stats unitStats = ParseUnitStats(statsElement, type.GameSystem); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
219 type.SetUnitStats(unitStats); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
220 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
221 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
222 XmlNodeList unitMemberReferences = WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:unitMembers/race:unitMember"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
223 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
224 foreach (XmlElement unitMemberRef in unitMemberReferences) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
225 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
226 string typeID = unitMemberRef.GetAttribute("typeID"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
227 UnitMemberType unitMemberType = race.GetUnitMemberType(typeID); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
228 type.AddUnitMemberType(unitMemberType); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
229 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
230 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
231 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
232 private void LoadEquipmentSlotsForUnitType(XmlElement elem, UnitType type) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
233 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
234 foreach (XmlElement equipSlot in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:equipmentSlots/race:equipmentSlot")) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
235 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
236 LoadEquipmentSlotForUnitType (type, equipSlot); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
237 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
238 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
239 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
240 private void LoadEquipmentSlotForUnitType(UnitType type, XmlElement equipSlot) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
241 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
242 string slotName = equipSlot.GetAttribute("name"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
243 ILimit limit = GetMaxLimit(equipSlot); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
244 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
245 if (limit != null) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
246 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
247 type.AddEquipmentSlot(slotName, limit); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
248 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
249 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
250 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
251 private ILimit GetMinLimit(XmlElement elem) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
252 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
253 return limitParser.GetMinLimit(elem); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
254 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
255 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
256 private ILimit GetMaxLimit(XmlElement elem) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
257 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
258 return limitParser.GetMaxLimit(elem); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
259 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
260 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
261 private void LoadEquipmentForUnitType(XmlElement elem, UnitType type) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
262 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
263 foreach (XmlElement equip in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:unitEquipment/race:unitEquipmentItem")) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
264 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
265 string id = equip.GetAttribute("id"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
266 EquipmentItem equipItem = type.Race.GetEquipmentItem(id); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
267 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
268 if (equipItem!=null) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
269 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
270 string mutexGroupString = equip.GetAttribute("exclusivityGroups"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
271 string[] mutexGroups; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
272 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
273 if (mutexGroupString == "") |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
274 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
275 mutexGroupString = equip.GetAttribute("exclusivityGroup"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
276 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
277 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
278 if (mutexGroupString != "") |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
279 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
280 string[] groups = mutexGroupString.Split(','); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
281 int groupCount = groups.Length; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
282 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
283 for (int i = 0; i < groupCount; i++) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
284 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
285 groups[i] = groups[i].Trim(); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
286 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
287 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
288 mutexGroups = groups; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
289 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
290 else |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
291 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
292 mutexGroups = new string[0]; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
293 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
294 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
295 UnitEquipmentItem unitEquipItem = new UnitEquipmentItem(equipItem, type, mutexGroups); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
296 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
297 string equipSlot = equip.GetAttribute("equipmentSlot"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
298 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
299 if (equipSlot != "") |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
300 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
301 if (type.HasEquipmentSlot(equipSlot)) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
302 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
303 unitEquipItem.SlotName = equipSlot; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
304 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
305 else |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
306 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
307 throw new InvalidFileException("Attribute 'equipmentSlot' of unit equipment item " + id + " for " + type.Name + " was not a valid slot name"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
308 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
309 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
310 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
311 ILimit limit = GetMaxLimit(equip); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
312 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
313 if (limit != null) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
314 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
315 unitEquipItem.MaxLimit = limit; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
316 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
317 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
318 limit = GetMinLimit(equip); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
319 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
320 if (limit != null) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
321 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
322 unitEquipItem.MinLimit = limit; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
323 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
324 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
325 unitEquipItem.RoundNumberUp = equip.GetAttribute("roundDirection").Equals("up"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
326 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
327 try |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
328 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
329 unitEquipItem.IsRequired = XmlTools.GetBoolValueFromAttribute(equip, "required"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
330 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
331 catch(FormatException e) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
332 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
333 throw new InvalidFileException("Attribute 'required' of unit equipment item " + id + " for " + type.Name + " was not a valid boolean", e); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
334 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
335 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
336 try |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
337 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
338 unitEquipItem.CostMultiplier = XmlTools.GetDoubleValueFromAttribute(equip, "costMultiplier"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
339 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
340 catch (FormatException e) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
341 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
342 throw new InvalidFileException("Attribute 'costMultiplier' of unit equipment item " + id + " for " + type.Name + " was not a valid decimal number", e); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
343 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
344 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
345 try |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
346 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
347 unitEquipItem.CostRoundType = (RoundType) Enum.Parse(typeof(RoundType), equip.GetAttribute("costRounding")); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
348 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
349 catch (ArgumentException e) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
350 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
351 throw new InvalidFileException("Attribute 'costRounding' of unit equipment item " + id + " for " + type.Name + " was not a valid rounding type", e); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
352 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
353 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
354 else |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
355 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
356 throw new InvalidFileException("Equipment item with ID '" + id + "' was required by " + type.Name + " but was not found"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
357 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
358 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
359 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
360 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
361 private void LoadAbilitiesForUnitType(XmlElement elem, UnitType type) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
362 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
363 foreach (XmlElement abilityElem in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:unitAbilities/race:unitAbility")) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
364 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
365 string id = abilityElem.GetAttribute("abilityID"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
366 Ability ability = type.Race.GetAbility(id); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
367 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
368 if (ability == null) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
369 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
370 throw new InvalidFileException("Ability for "+type.Name+ " with ID "+id+ " did not exist in race definition"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
371 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
372 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
373 bool required = XmlTools.GetBoolValueFromAttribute(abilityElem, "required"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
374 type.AddAbility(ability, required); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
375 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
376 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
377 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
378 private void LoadContainedUnitsForUnitType(XmlElement elem, UnitType type) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
379 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
380 foreach (XmlElement containedUnitType in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:contains/race:containedUnit")) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
381 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
382 string id = containedUnitType.GetAttribute("containedID"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
383 UnitType containedType = GetUnitTypeFromDocument(elem.OwnerDocument, id, type.Race); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
384 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
385 if (containedType!=null) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
386 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
387 type.AddContainedUnitType(containedType); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
388 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
389 else |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
390 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
391 throw new InvalidFileException("Unit type " + type.Name + " tried to contain undefined unit with ID "+id); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
392 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
393 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
394 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
395 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
396 private void LoadRequirementsForUnitType(XmlElement elem, UnitType type) |
371
bfdb95906075
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
370
diff
changeset
|
397 { |
370
077e9be48438
Re #346: Add requirement schema support
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
398 foreach (XmlElement extraData in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:requirements/race:requirement")) |
077e9be48438
Re #346: Add requirement schema support
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
399 { |
077e9be48438
Re #346: Add requirement schema support
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
400 string name = extraData.GetAttribute("requirementName"); |
380
7036bf04e955
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
379
diff
changeset
|
401 IRequirementFactory reqFactory = WarFoundryLoader.GetRequirementFactory(name); |
371
bfdb95906075
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
370
diff
changeset
|
402 |
bfdb95906075
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
370
diff
changeset
|
403 if (reqFactory != null) { |
370
077e9be48438
Re #346: Add requirement schema support
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
404 string data = WarFoundryXmlFactoryUtils.SelectSingleElement(extraData, "race:data").InnerText; |
379
04f4c2fea356
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
378
diff
changeset
|
405 IRequirement req = reqFactory.CreateRequirement(type, data, this); |
370
077e9be48438
Re #346: Add requirement schema support
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
406 type.AddRequirement(req); |
077e9be48438
Re #346: Add requirement schema support
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
407 } |
469
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
408 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
409 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
410 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
411 private void LoadExtraDataForUnitType(XmlElement elem, UnitType type) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
412 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
413 foreach (XmlElement extraData in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:extraData/race:data")) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
414 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
415 string id = extraData.GetAttribute("id"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
416 string data = extraData.InnerXml; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
417 type.AddExtraData(id, data); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
418 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
419 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
420 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
421 private void LoadNotesForUnitType(XmlElement elem, UnitType type) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
422 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
423 XmlNode node = WarFoundryXmlFactoryUtils.SelectSingleNode(elem, "race:notes"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
424 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
425 if (node!=null) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
426 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
427 type.Notes = node.InnerText; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
428 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
429 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
430 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
431 private Stats ParseUnitStats(XmlElement elem, GameSystem system) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
432 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
433 if (elem == null) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
434 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
435 return null; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
436 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
437 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
438 String statsID = elem.GetAttribute("statSet"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
439 SystemStats statsSet; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
440 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
441 if (statsID == "") |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
442 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
443 statsSet = system.StandardSystemStats; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
444 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
445 else |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
446 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
447 statsSet = system.GetSystemStatsForID(statsID); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
448 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
449 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
450 Stats stats = new Stats(statsSet); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
451 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
452 foreach (XmlElement stat in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:stat")) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
453 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
454 String statName = stat.GetAttribute("name"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
455 stats.SetStatValue(statName, stat.InnerText); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
456 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
457 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
458 return stats; |
371
bfdb95906075
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
370
diff
changeset
|
459 } |
469
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
460 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
461 private EquipmentItem CreateEquipmentItemFromElement(XmlElement elem, Race race) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
462 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
463 string id = elem.GetAttribute("id"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
464 EquipmentItem item = race.GetEquipmentItem(id); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
465 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
466 if (item == null) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
467 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
468 item = CreateEquipmentItemFromElement(elem, id, race); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
469 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
470 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
471 return item; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
472 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
473 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
474 private EquipmentItem CreateEquipmentItemFromElement(XmlElement elem, string id, Race race) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
475 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
476 string name = elem.GetAttribute("name"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
477 EquipmentItem item = new EquipmentItem(id, name, race); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
478 double cost = 0; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
479 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
480 try |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
481 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
482 cost = XmlTools.GetDoubleValueFromAttribute(elem, "cost"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
483 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
484 catch(FormatException ex) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
485 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
486 throw new InvalidFileException("Attribute 'cost' of equipment item "+id+" was not a valid number", ex); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
487 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
488 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
489 //TODO: Parse equipment stats if there are any |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
490 item.Cost = cost; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
491 race.AddEquipmentItem(item); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
492 return item; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
493 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
494 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
495 private Ability CreateAbilityFromElement(XmlElement elem, Race race) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
496 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
497 string id = elem.GetAttribute("id"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
498 string name = elem.GetAttribute("name"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
499 Ability ability = new Ability(id, name); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
500 XmlNode node = WarFoundryXmlFactoryUtils.SelectSingleNode(elem, "race:description"); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
501 ability.Description = (node == null) ? "" : node.InnerText; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
502 race.AddAbility(ability); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
503 return ability; |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
504 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
505 |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
506 private void CreateMemberTypeFromElement(XmlElement elem, Race race) |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
507 { |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
508 Stats stats = ParseUnitStats(WarFoundryXmlFactoryUtils.SelectSingleElement(elem, "race:stats"), race.GameSystem); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
509 UnitMemberType unitMemberType = new UnitMemberType(elem.GetAttribute("id"), elem.GetAttribute("name"), stats); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
510 race.AddUnitMemberType(unitMemberType); |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
511 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
512 } |
2ba1f24eb427
Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents:
450
diff
changeset
|
513 } |