annotate api/Factories/Xml/WarFoundryXmlRaceFactory.cs @ 252:a54da5a8b5bb

Re #268: Restructure stats for re-use * Add "Member Type" class * Add member type setting and getting to Race * Load member types from XML files * Make unit type pull stat line from stats or first member type, or fall back to a blank stat line * Change Stats object to initialise blank values * Change schema * Make stats optional * Add member type list to race * Add optional member type references to units
author IBBoard <dev@ibboard.co.uk>
date Sun, 25 Apr 2010 15:07:08 +0000
parents 91ee6259677f
children 435eb28b4549
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 // This file (WarFoundryXmlRaceFactory.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using System;
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using System.Collections.Generic;
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using System.IO;
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 using System.Xml;
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 using IBBoard.Xml;
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 using ICSharpCode.SharpZipLib.Zip;
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 using IBBoard.WarFoundry.API.Objects;
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 namespace IBBoard.WarFoundry.API.Factories.Xml
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 {
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 /// <summary>
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 /// A sub-factory for loading WarFoundry Race XML files
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 /// </summary>
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 public class WarFoundryXmlRaceFactory : AbstractStagedLoadedSubFactory
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 {
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 private Dictionary<Race, XmlDocument> extraData = new Dictionary<Race, XmlDocument>();
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 public WarFoundryXmlRaceFactory(WarFoundryXmlFactory factory) : base (factory)
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 {
99
05a78408ae8f Re #58: Remove log notifier
IBBoard <dev@ibboard.co.uk>
parents: 92
diff changeset
27 //Do nothing special
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 private void StoreExtraData(Race wfObject, XmlElement elem)
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 {
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 extraData[wfObject] = elem.OwnerDocument;
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 private XmlDocument GetExtraData(Race obj)
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 {
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 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
38 extraData.TryGetValue(obj, out extra);
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 return extra;
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 public Race CreateRaceFromElement(ZipFile file, XmlElement elem)
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 {
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 string id = elem.GetAttribute("id");
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 string subid = elem.GetAttribute("subid");
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 string systemID = elem.GetAttribute("system");
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47 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
48 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
49
d1c90159547a Fixes #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents: 224
diff changeset
50 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
51 {
232
f5009a00a50d Re #236: Handle null game system in race
IBBoard <dev@ibboard.co.uk>
parents: 231
diff changeset
52 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
53 }
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 Race race = new Race(id, subid, name, gameSystem, mainFactory);
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56 StoreExtraData(race, elem);
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 return race;
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
60 public void CompleteLoading(Race race)
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
61 {
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
62 if (!WarFoundryXmlFactoryUtils.CanCompleteLoading(race))
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
63 {
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64 return;
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
67 race.SetAsLoading();
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
68 XmlDocument extraData = GetExtraData(race);
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
69
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
70 foreach (XmlElement node in WarFoundryXmlFactoryUtils.SelectNodes(extraData, "/race:race/race:categories/cat:cat"))
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
71 {
68
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
72 CreateCategoryFromElement(node, race);
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
73 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
74
85
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
75 foreach (XmlElement node in WarFoundryXmlFactoryUtils.SelectNodes(extraData, "/race:race/race:equipment/race:equipmentItem"))
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
76 {
68
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
77 CreateEquipmentItemFromElement(node, race);
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
78 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
79
85
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
80 foreach (XmlElement node in WarFoundryXmlFactoryUtils.SelectNodes(extraData, "/race:race/race:abilities/race:ability"))
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
81 {
68
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
82 CreateAbilityFromElement(node, race);
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
83 }
252
a54da5a8b5bb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 242
diff changeset
84
a54da5a8b5bb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 242
diff changeset
85 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
86 {
a54da5a8b5bb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 242
diff changeset
87 CreateMemberTypeFromElement(node, race);
a54da5a8b5bb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 242
diff changeset
88 }
68
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
89
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
90 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
91 {
70
780f3926abad Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 69
diff changeset
92 GetUnitTypeForElement(node, race);
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
93 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
94
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
95 race.SetAsFullyLoaded();
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
96 }
68
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
97
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
98 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
99 {
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
100 Category cat = CreateCategoryFromElement(elem);
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
101 parentRace.AddCategory(cat);
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
102 return cat;
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
103 }
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 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
106 {
217
89e26d51afc2 Fixes #226: "NullReferenceException" for a unitID
IBBoard <dev@ibboard.co.uk>
parents: 207
diff changeset
107 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
108
89e26d51afc2 Fixes #226: "NullReferenceException" for a unitID
IBBoard <dev@ibboard.co.uk>
parents: 207
diff changeset
109 if (unitWithId == null)
89e26d51afc2 Fixes #226: "NullReferenceException" for a unitID
IBBoard <dev@ibboard.co.uk>
parents: 207
diff changeset
110 {
89e26d51afc2 Fixes #226: "NullReferenceException" for a unitID
IBBoard <dev@ibboard.co.uk>
parents: 207
diff changeset
111 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
112 }
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 return GetUnitTypeForElement(unitWithId, parentRace);
68
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
115 }
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
116
70
780f3926abad Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 69
diff changeset
117 private UnitType GetUnitTypeForElement(XmlElement elem, Race parentRace)
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
118 {
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
119 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
120 UnitType type = parentRace.GetUnitType(id);
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
121
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
122 if (type==null)
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
123 {
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
124 type = CreateUnitTypeFromElement(elem, id, parentRace);
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
125 }
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 return type;
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
128 }
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 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
131 {
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
132 string name = elem.GetAttribute("typeName");
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
133 UnitType type = new UnitType(id, name, parentRace);
170
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
134 LoadCoreValuesForUnitType(elem, type);
167
9ba56a8e5096 Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
135 LoadEquipmentSlotsForUnitType(elem, type);
68
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
136 LoadEquipmentForUnitType(elem, type);
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
137 LoadAbilitiesForUnitType(elem, type);
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
138 LoadContainedUnitsForUnitType(elem, type);
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
139 LoadRequirementsForUnitType(elem, type);
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
140 LoadExtraDataForUnitType(elem, type);
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
141 LoadNotesForUnitType(elem, type);
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
142 parentRace.AddUnitType(type);
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
143 return type;
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
144 }
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 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
147 {
eb9a6d91a6db Fixes #190: Mutex groups aren't honoured when adding equipment
IBBoard <dev@ibboard.co.uk>
parents: 156
diff changeset
148 try
eb9a6d91a6db Fixes #190: Mutex groups aren't honoured when adding equipment
IBBoard <dev@ibboard.co.uk>
parents: 156
diff changeset
149 {
eb9a6d91a6db Fixes #190: Mutex groups aren't honoured when adding equipment
IBBoard <dev@ibboard.co.uk>
parents: 156
diff changeset
150 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
151 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
152 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
153 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
154 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
155 type.CostPerTrooper = XmlTools.GetDoubleValueFromAttribute(elem, "points");
224
f097888efcfe Fixes #233: "unitPoints" attribute is badly named
IBBoard <dev@ibboard.co.uk>
parents: 222
diff changeset
156 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
157 }
eb9a6d91a6db Fixes #190: Mutex groups aren't honoured when adding equipment
IBBoard <dev@ibboard.co.uk>
parents: 156
diff changeset
158 catch (FormatException ex)
eb9a6d91a6db Fixes #190: Mutex groups aren't honoured when adding equipment
IBBoard <dev@ibboard.co.uk>
parents: 156
diff changeset
159 {
217
89e26d51afc2 Fixes #226: "NullReferenceException" for a unitID
IBBoard <dev@ibboard.co.uk>
parents: 207
diff changeset
160 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
161 }
62ff1ac132d2 Fixes #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 154
diff changeset
162
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
163 string mainCatID = elem.GetAttribute("cat");
68
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
164 Category cat = type.Race.GetCategory(mainCatID);
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
165
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
166 if (cat == null)
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
167 {
217
89e26d51afc2 Fixes #226: "NullReferenceException" for a unitID
IBBoard <dev@ibboard.co.uk>
parents: 207
diff changeset
168 throw new InvalidFileException(String.Format("Category with ID '{1}' did not exist for UnitType '{0}'", type.Name, mainCatID));
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
169 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
170
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
171 type.MainCategory = cat;
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
172 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
173
a54da5a8b5bb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 242
diff changeset
174 if (statsElement!=null)
a54da5a8b5bb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 242
diff changeset
175 {
a54da5a8b5bb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 242
diff changeset
176 Stats unitStats = ParseUnitStats(statsElement, type.GameSystem);
a54da5a8b5bb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 242
diff changeset
177 type.SetUnitStats(unitStats);
a54da5a8b5bb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 242
diff changeset
178 }
a54da5a8b5bb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 242
diff changeset
179
a54da5a8b5bb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 242
diff changeset
180 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
181
a54da5a8b5bb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 242
diff changeset
182 foreach (XmlElement unitMemberRef in unitMemberReferences)
a54da5a8b5bb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 242
diff changeset
183 {
a54da5a8b5bb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 242
diff changeset
184 string typeID = unitMemberRef.GetAttribute("typeID");
a54da5a8b5bb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 242
diff changeset
185 UnitMemberType unitMemberType = type.Race.GetUnitMemberType(typeID);
a54da5a8b5bb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 242
diff changeset
186 type.AddUnitMemberType(unitMemberType);
a54da5a8b5bb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 242
diff changeset
187 }
170
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
188 }
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
189
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
190 private void LoadEquipmentSlotsForUnitType(XmlElement elem, UnitType type)
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
191 {
176
22429737cd77 Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 175
diff changeset
192 foreach (XmlElement equipSlot in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:equipmentSlots/race:equipmentSlot"))
170
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
193 {
176
22429737cd77 Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 175
diff changeset
194 LoadEquipmentSlotForUnitType (type, equipSlot);
22429737cd77 Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 175
diff changeset
195 }
22429737cd77 Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 175
diff changeset
196 }
22429737cd77 Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 175
diff changeset
197
22429737cd77 Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 175
diff changeset
198 private static void LoadEquipmentSlotForUnitType (UnitType type, XmlElement equipSlot)
22429737cd77 Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 175
diff changeset
199 {
22429737cd77 Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 175
diff changeset
200 string slotName = equipSlot.GetAttribute ("name");
183
36adabb1c3ea Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 176
diff changeset
201 AbstractLimit limit = GetMaxLimit (equipSlot);
176
22429737cd77 Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 175
diff changeset
202
22429737cd77 Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 175
diff changeset
203 if (limit!=null)
22429737cd77 Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 175
diff changeset
204 {
22429737cd77 Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 175
diff changeset
205 type.AddEquipmentSlot (slotName, limit);
170
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
206 }
68
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
207 }
183
36adabb1c3ea Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 176
diff changeset
208
36adabb1c3ea Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 176
diff changeset
209 private static AbstractLimit GetMaxLimit (XmlElement equipSlot)
36adabb1c3ea Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 176
diff changeset
210 {
36adabb1c3ea Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 176
diff changeset
211 XmlElement limitElem = WarFoundryXmlFactoryUtils.SelectSingleElement(equipSlot, "race:maxLimit/*[1]");
36adabb1c3ea Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 176
diff changeset
212 return GetLimitFromElement(limitElem);
36adabb1c3ea Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 176
diff changeset
213 }
176
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 private static AbstractLimit GetLimitFromElement(XmlElement limitElem)
22429737cd77 Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 175
diff changeset
216 {
198
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
217 AbstractLimit limit = null;
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
218
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
219 if (limitElem != null)
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
220 {
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
221 switch (limitElem.LocalName)
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
222 {
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
223 case "percentageLimit":
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
224 double limitPercent = XmlTools.GetDoubleValueFromAttribute(limitElem, "limit");
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
225 bool roundUp = limitElem.GetAttribute("round").Equals("up");
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
226 limit = new SimpleRoundedPercentageLimit(limitPercent, roundUp);
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
227 break;
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
228 case "sizeConstrainedLimit":
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
229 limit = new NumericSizeConstrainedLimit(XmlTools.GetIntValueFromAttribute(limitElem, "limit"));
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
230 break;
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
231 case "absoluteLimit":
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
232 limit = new AbsoluteNumericLimit(XmlTools.GetIntValueFromAttribute(limitElem, "limit"));
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
233 break;
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
234 case "unitSizeLimit":
207
897c53d5a8aa Re #208
IBBoard <dev@ibboard.co.uk>
parents: 198
diff changeset
235 limit = new SimpleRoundedPercentageLimit(100);
198
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
236 break;
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
237 default:
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
238 //TODO: Warn of missing handler for when we've extended the limit list
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
239 break;
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
240 }
176
22429737cd77 Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 175
diff changeset
241 }
22429737cd77 Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 175
diff changeset
242
22429737cd77 Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 175
diff changeset
243 return limit;
22429737cd77 Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 175
diff changeset
244 }
22429737cd77 Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 175
diff changeset
245
68
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
246
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
247 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
248 {
85
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
249 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
250 {
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
251 string id = equip.GetAttribute("id");
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
252 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
253
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
254 if (equipItem!=null)
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
255 {
154
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
256 string mutexGroupString = equip.GetAttribute("exclusivityGroups");
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
257 string[] mutexGroups;
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 if (mutexGroupString == "")
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 mutexGroupString = equip.GetAttribute("exclusivityGroup");
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 if (mutexGroupString != "")
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 string[] groups = mutexGroupString.Split(',');
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
267 int groupCount = groups.Length;
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
268
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
269 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
270 {
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
271 groups[i] = groups[i].Trim();
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
272 }
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
273
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
274 mutexGroups = groups;
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
275 }
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
276 else
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
277 {
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
278 mutexGroups = new string[0];
152
0c0e14f03785 Re #180: Add multiple mutex groups
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
279 }
0c0e14f03785 Re #180: Add multiple mutex groups
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
280
170
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
281 UnitEquipmentItem unitEquipItem = new UnitEquipmentItem(equipItem, type, mutexGroups);
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
282
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
283 string equipSlot = equip.GetAttribute("equipmentSlot");
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
284
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
285 if (equipSlot != "")
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
286 {
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
287 if (type.HasEquipmentSlot(equipSlot))
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
288 {
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
289 unitEquipItem.SlotName = equipSlot;
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
290 }
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
291 else
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
292 {
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
293 throw new InvalidFileException("Attribute 'equipmentSlot' of unit equipment item " + id + " for " + type.Name + " was not a valid slot name");
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
294 }
198
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
295 }
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
296
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
297 AbstractLimit limit = GetMaxLimit(equip);
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
298
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
299 if (limit != null)
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
300 {
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
301 unitEquipItem.MaxLimit = limit;
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
302 }
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
303
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
304 limit = GetMinLimit(equip);
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
305
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
306 if (limit != null)
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
307 {
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
308 unitEquipItem.MinLimit = limit;
167
9ba56a8e5096 Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
309 }
183
36adabb1c3ea Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 176
diff changeset
310
90
bd2aaa9a61df Re #50: Complete loading of core XML file
IBBoard <dev@ibboard.co.uk>
parents: 88
diff changeset
311 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
312
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
313 try
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
314 {
219
f609bcf7035b Fixes #222: decimal comma/point not handled correctly (again?) in costMultiplier
IBBoard <dev@ibboard.co.uk>
parents: 217
diff changeset
315 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
316 }
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
317 catch(FormatException e)
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
318 {
87
9fba3b4ccdcd Re #50: Complete core XML loading
IBBoard <dev@ibboard.co.uk>
parents: 86
diff changeset
319 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
320 }
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
321
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
322 try
91
571d8ddc7d9a Fixes #111: "Replace Weapon" button doesn't always enable
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
323 {
219
f609bcf7035b Fixes #222: decimal comma/point not handled correctly (again?) in costMultiplier
IBBoard <dev@ibboard.co.uk>
parents: 217
diff changeset
324 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
325 }
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
326 catch (FormatException e)
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
327 {
87
9fba3b4ccdcd Re #50: Complete core XML loading
IBBoard <dev@ibboard.co.uk>
parents: 86
diff changeset
328 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
329 }
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
330
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
331 try
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
332 {
88
110a7b0bcab5 Re #50: Complete core loading from XML
IBBoard <dev@ibboard.co.uk>
parents: 87
diff changeset
333 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
334 }
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
335 catch (ArgumentException e)
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
336 {
87
9fba3b4ccdcd Re #50: Complete core XML loading
IBBoard <dev@ibboard.co.uk>
parents: 86
diff changeset
337 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
338 }
85
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
339 }
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
340 else
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
341 {
128
45a9452579a2 Fixes #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
342 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
343 }
195
11bad32cfa06 * Implement new equipment limit loading
IBBoard <dev@ibboard.co.uk>
parents: 192
diff changeset
344 }
198
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
345 }
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
346
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
347 private static AbstractLimit GetMinLimit(XmlElement elem)
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
348 {
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
349 XmlElement limitElem = WarFoundryXmlFactoryUtils.SelectSingleElement(elem, "race:minLimit/*[1]");
c4cf4c7db7d5 * Line ending fix
IBBoard <dev@ibboard.co.uk>
parents: 195
diff changeset
350 return GetLimitFromElement(limitElem);
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 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
354 {
222
2f9ad5385707 Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents: 221
diff changeset
355 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
356 {
222
2f9ad5385707 Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents: 221
diff changeset
357 string id = abilityElem.GetAttribute("abilityID");
221
78f7456f6419 Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents: 219
diff changeset
358 Ability ability = type.Race.GetAbility(id);
78f7456f6419 Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents: 219
diff changeset
359
78f7456f6419 Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents: 219
diff changeset
360 if (ability == null)
78f7456f6419 Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents: 219
diff changeset
361 {
78f7456f6419 Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents: 219
diff changeset
362 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
363 }
222
2f9ad5385707 Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents: 221
diff changeset
364
2f9ad5385707 Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents: 221
diff changeset
365 bool required = XmlTools.GetBoolValueFromAttribute(abilityElem, "required");
221
78f7456f6419 Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents: 219
diff changeset
366 type.AddAbility(ability, required);
68
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
367 }
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
368 }
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
369
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
370 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
371 {
69
91cf8efbea0b Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
372 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
373 {
91cf8efbea0b Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
374 string id = containedUnitType.GetAttribute("containedID");
91cf8efbea0b Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
375 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
376
91cf8efbea0b Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
377 if (containedType!=null)
91cf8efbea0b Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
378 {
91cf8efbea0b Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
379 type.AddContainedUnitType(containedType);
91cf8efbea0b Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
380 }
91cf8efbea0b Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
381 else
91cf8efbea0b Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
382 {
128
45a9452579a2 Fixes #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
383 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
384 }
91cf8efbea0b Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
385 }
68
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
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
388 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
389 {
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
390 //TODO: Load requirements
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
391 }
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 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
394 {
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
395 }
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
396
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
397 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
398 {
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
399 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
400
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
401 if (node!=null)
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
402 {
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
403 type.Notes = node.InnerText;
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
404 }
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
405 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
406
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
407 private Stats ParseUnitStats(XmlElement elem, GameSystem system)
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
408 {
252
a54da5a8b5bb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 242
diff changeset
409 if (elem == null)
a54da5a8b5bb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 242
diff changeset
410 {
a54da5a8b5bb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 242
diff changeset
411 return null;
a54da5a8b5bb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 242
diff changeset
412 }
a54da5a8b5bb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 242
diff changeset
413
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
414 String statsID = elem.GetAttribute("statSet");
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
415 SystemStats statsSet;
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
416
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
417 if (statsID == "")
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
418 {
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
419 statsSet = system.StandardSystemStats;
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
420 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
421 else
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
422 {
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
423 statsSet = system.GetSystemStatsForID(statsID);
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
424 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
425
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
426 Stats stats = new Stats(statsSet);
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
427
53
1b35eed503ef Closes #13 - Migrate to XPath
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
428 foreach (XmlElement stat in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:stat"))
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
429 {
67
e6200220ece3 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 55
diff changeset
430 String statName = stat.GetAttribute("name");
e6200220ece3 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 55
diff changeset
431 stats.SetStatValue(statName, stat.InnerText);
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
432 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
433
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
434 return stats;
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
435 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
436
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
437 private EquipmentItem CreateEquipmentItemFromElement(XmlElement elem, Race race)
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
438 {
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
439 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
440 EquipmentItem item = race.GetEquipmentItem(id);
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
441
85
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
442 if (item == null)
68
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
443 {
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
444 item = CreateEquipmentItemFromElement(elem, id, race);
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
445 }
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
446
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
447 return item;
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
448 }
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
449
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
450 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
451 {
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
452 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
453 EquipmentItem item = new EquipmentItem(id, name, race);
55
9080366031c0 Re #9 - Refactor for small methods
IBBoard <dev@ibboard.co.uk>
parents: 53
diff changeset
454 double cost = 0;
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
455 ArmourType armourType;
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
456
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
457 try
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
458 {
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
459 cost = XmlTools.GetDoubleValueFromAttribute(elem, "cost");
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
460 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
461 catch(FormatException ex)
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
462 {
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
463 throw new InvalidFileException("Attribute 'cost' of equipment item "+id+" was not a valid number", ex);
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
464 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
465
242
91ee6259677f * Make "armourType" parse error more informative
IBBoard <dev@ibboard.co.uk>
parents: 232
diff changeset
466 string armourTypeAttrib = elem.GetAttribute("armourType");
91ee6259677f * Make "armourType" parse error more informative
IBBoard <dev@ibboard.co.uk>
parents: 232
diff changeset
467
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
468 try
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
469 {
242
91ee6259677f * Make "armourType" parse error more informative
IBBoard <dev@ibboard.co.uk>
parents: 232
diff changeset
470 armourType = (ArmourType)Enum.Parse(typeof(ArmourType), armourTypeAttrib);
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
471 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
472 catch(ArgumentException ex)
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
473 {
242
91ee6259677f * Make "armourType" parse error more informative
IBBoard <dev@ibboard.co.uk>
parents: 232
diff changeset
474 throw new InvalidFileException("Attribute value '"+armourTypeAttrib+"' for 'armourType' of equipment "+id+" was not one of the allowed values", ex);
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
475 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
476
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
477 //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
478 item.Cost = cost;
9080366031c0 Re #9 - Refactor for small methods
IBBoard <dev@ibboard.co.uk>
parents: 53
diff changeset
479 item.ItemArmourType = armourType;
85
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
480 race.AddEquipmentItem(item);
55
9080366031c0 Re #9 - Refactor for small methods
IBBoard <dev@ibboard.co.uk>
parents: 53
diff changeset
481 return item;
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
482 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
483
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
484 private Ability CreateAbilityFromElement(XmlElement elem, Race race)
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
485 {
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
486 string id = elem.GetAttribute("id");
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
487 string name = elem.GetAttribute("name");
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
488 Ability ability = new Ability(id, name);
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
489 XmlNode node = elem.SelectSingleNode("description", WarFoundryXmlFactoryUtils.GetNamespaceManager());
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
490 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
491 race.AddAbility(ability);
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
492 return ability;
252
a54da5a8b5bb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 242
diff changeset
493 }
a54da5a8b5bb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 242
diff changeset
494
a54da5a8b5bb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 242
diff changeset
495 private void CreateMemberTypeFromElement(XmlElement elem, Race race)
a54da5a8b5bb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 242
diff changeset
496 {
a54da5a8b5bb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 242
diff changeset
497 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
498 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
499 race.AddUnitMemberType(unitMemberType);
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
500 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
501 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
502 }