annotate api/Factories/Xml/WarFoundryXmlRaceFactory.cs @ 171:85dc413279a4

* Change imports to stop references to deprecated code no-open-ticket
author IBBoard <dev@ibboard.co.uk>
date Mon, 12 Oct 2009 18:41:17 +0000
parents 3045a168714a
children 996816199b72
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;
171
85dc413279a4 * Change imports to stop references to deprecated code
IBBoard <dev@ibboard.co.uk>
parents: 170
diff changeset
11 using IBBoard.CustomMath;
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 using ICSharpCode.SharpZipLib.Zip;
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 using IBBoard.WarFoundry.API.Objects;
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 namespace IBBoard.WarFoundry.API.Factories.Xml
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 {
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 /// <summary>
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 /// A sub-factory for loading WarFoundry Race XML files
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 /// </summary>
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 public class WarFoundryXmlRaceFactory : AbstractStagedLoadedSubFactory
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 {
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 private Dictionary<Race, XmlDocument> extraData = new Dictionary<Race, XmlDocument>();
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 public WarFoundryXmlRaceFactory(WarFoundryXmlFactory factory) : base (factory)
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 {
99
05a78408ae8f Re #58: Remove log notifier
IBBoard <dev@ibboard.co.uk>
parents: 92
diff changeset
26 //Do nothing special
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 }
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 private void StoreExtraData(Race wfObject, XmlElement elem)
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 {
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 extraData[wfObject] = elem.OwnerDocument;
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 }
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 private XmlDocument GetExtraData(Race obj)
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 {
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 XmlDocument extra = null;
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 extraData.TryGetValue(obj, out extra);
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38 return extra;
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 }
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 public Race CreateRaceFromElement(ZipFile file, XmlElement elem)
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 {
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 string id = elem.GetAttribute("id");
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 string subid = elem.GetAttribute("subid");
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 string systemID = elem.GetAttribute("system");
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 string name = elem.GetAttribute("name");
55
9080366031c0 Re #9 - Refactor for small methods
IBBoard <dev@ibboard.co.uk>
parents: 53
diff changeset
47 Race race = new Race(id, subid, name, WarFoundryLoader.GetDefault().GetGameSystem(systemID), mainFactory);
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48 StoreExtraData(race, elem);
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 return race;
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
52 public void CompleteLoading(Race race)
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53 {
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54 if (!WarFoundryXmlFactoryUtils.CanCompleteLoading(race))
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55 {
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56 return;
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 }
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 race.SetAsLoading();
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
60 XmlDocument extraData = GetExtraData(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 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
63 {
68
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
64 CreateCategoryFromElement(node, race);
52
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
85
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
67 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
68 {
68
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
69 CreateEquipmentItemFromElement(node, race);
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
70 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
71
85
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
72 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
73 {
68
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
74 CreateAbilityFromElement(node, race);
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
75 }
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
76
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
77 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
78 {
70
780f3926abad Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 69
diff changeset
79 GetUnitTypeForElement(node, race);
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
80 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
81
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
82 race.SetAsFullyLoaded();
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
83 }
68
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
84
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
85 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
86 {
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
87 Category cat = CreateCategoryFromElement(elem);
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
88 parentRace.AddCategory(cat);
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
89 return cat;
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
90 }
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
91
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
92 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
93 {
71
0303ac938fc5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 70
diff changeset
94 return GetUnitTypeForElement(WarFoundryXmlFactoryUtils.SelectSingleElement(doc, "/race:race/race:units/race:unit[@id='"+id+"']"), parentRace);
68
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
95 }
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
96
70
780f3926abad Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 69
diff changeset
97 private UnitType GetUnitTypeForElement(XmlElement elem, Race parentRace)
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
98 {
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
99 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
100 UnitType type = parentRace.GetUnitType(id);
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
101
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
102 if (type==null)
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 type = CreateUnitTypeFromElement(elem, id, parentRace);
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
105 }
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
106
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
107 return type;
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
108 }
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
109
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
110 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
111 {
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
112 string name = elem.GetAttribute("typeName");
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
113 UnitType type = new UnitType(id, name, parentRace);
170
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
114 LoadCoreValuesForUnitType(elem, type);
167
9ba56a8e5096 Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
115 LoadEquipmentSlotsForUnitType(elem, type);
68
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
116 LoadEquipmentForUnitType(elem, type);
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
117 LoadAbilitiesForUnitType(elem, type);
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
118 LoadContainedUnitsForUnitType(elem, type);
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
119 LoadRequirementsForUnitType(elem, type);
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
120 LoadExtraDataForUnitType(elem, type);
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
121 LoadNotesForUnitType(elem, type);
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
122 parentRace.AddUnitType(type);
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
123 return type;
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
124 }
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
125
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
126 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
127 {
eb9a6d91a6db Fixes #190: Mutex groups aren't honoured when adding equipment
IBBoard <dev@ibboard.co.uk>
parents: 156
diff changeset
128 try
eb9a6d91a6db Fixes #190: Mutex groups aren't honoured when adding equipment
IBBoard <dev@ibboard.co.uk>
parents: 156
diff changeset
129 {
eb9a6d91a6db Fixes #190: Mutex groups aren't honoured when adding equipment
IBBoard <dev@ibboard.co.uk>
parents: 156
diff changeset
130 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
131 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
132 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
133 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
134 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
135 type.CostPerTrooper = XmlTools.GetDoubleValueFromAttribute(elem, "points");
eb9a6d91a6db Fixes #190: Mutex groups aren't honoured when adding equipment
IBBoard <dev@ibboard.co.uk>
parents: 156
diff changeset
136 type.BaseUnitCost = XmlTools.GetDoubleValueFromAttribute(elem, "unitPoints");
eb9a6d91a6db Fixes #190: Mutex groups aren't honoured when adding equipment
IBBoard <dev@ibboard.co.uk>
parents: 156
diff changeset
137 }
eb9a6d91a6db Fixes #190: Mutex groups aren't honoured when adding equipment
IBBoard <dev@ibboard.co.uk>
parents: 156
diff changeset
138 catch (FormatException ex)
eb9a6d91a6db Fixes #190: Mutex groups aren't honoured when adding equipment
IBBoard <dev@ibboard.co.uk>
parents: 156
diff changeset
139 {
eb9a6d91a6db Fixes #190: Mutex groups aren't honoured when adding equipment
IBBoard <dev@ibboard.co.uk>
parents: 156
diff changeset
140 throw new InvalidDataException(ex.Message, ex);
156
62ff1ac132d2 Fixes #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 154
diff changeset
141 }
62ff1ac132d2 Fixes #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 154
diff changeset
142
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
143 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
144 Category cat = type.Race.GetCategory(mainCatID);
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
145
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
146 if (cat == null)
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
147 {
156
62ff1ac132d2 Fixes #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 154
diff changeset
148 throw new InvalidDataException(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
149 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
150
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
151 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
152 XmlElement statsElement = WarFoundryXmlFactoryUtils.SelectSingleElement(elem, "race:stats");
81
032b174fc17a Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
153 Stats unitStats = ParseUnitStats(statsElement, type.GameSystem);
170
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
154 type.SetUnitStats(unitStats);
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
155 }
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
156
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
157 private void LoadEquipmentSlotsForUnitType(XmlElement elem, UnitType type)
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
158 {
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
159 foreach (XmlElement equip in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:equipmentSlots/race:equipmentSlot"))
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
160 {
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
161 string slotName = equip.GetAttribute("name");
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
162 int slotLimit = XmlTools.GetIntValueFromAttribute(equip, "limit");
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
163 type.AddEquipmentSlot(slotName, slotLimit);
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
164 }
68
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
165 }
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
166
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
167 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
168 {
85
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
169 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
170 {
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
171 string id = equip.GetAttribute("id");
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
172 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
173
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
174 if (equipItem!=null)
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
175 {
154
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
176 string mutexGroupString = equip.GetAttribute("exclusivityGroups");
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
177 string[] mutexGroups;
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
178
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
179 if (mutexGroupString == "")
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
180 {
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
181 mutexGroupString = equip.GetAttribute("exclusivityGroup");
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
182 }
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
183
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
184 if (mutexGroupString != "")
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
185 {
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
186 string[] groups = mutexGroupString.Split(',');
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
187 int groupCount = groups.Length;
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
188
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
189 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
190 {
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
191 groups[i] = groups[i].Trim();
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
192 }
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
193
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
194 mutexGroups = groups;
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
195 }
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
196 else
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
197 {
4a02c07278e7 Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents: 152
diff changeset
198 mutexGroups = new string[0];
152
0c0e14f03785 Re #180: Add multiple mutex groups
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
199 }
0c0e14f03785 Re #180: Add multiple mutex groups
IBBoard <dev@ibboard.co.uk>
parents: 138
diff changeset
200
170
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
201 UnitEquipmentItem unitEquipItem = new UnitEquipmentItem(equipItem, type, mutexGroups);
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
202
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
203 string equipSlot = equip.GetAttribute("equipmentSlot");
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
204
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
205 if (equipSlot != "")
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
206 {
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
207 if (type.HasEquipmentSlot(equipSlot))
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
208 {
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
209 unitEquipItem.SlotName = equipSlot;
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
210 }
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
211 else
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
212 {
3045a168714a * Line ending clean-up
IBBoard <dev@ibboard.co.uk>
parents: 167
diff changeset
213 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
214 }
167
9ba56a8e5096 Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
215 }
9ba56a8e5096 Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
216
90
bd2aaa9a61df Re #50: Complete loading of core XML file
IBBoard <dev@ibboard.co.uk>
parents: 88
diff changeset
217 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
218
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
219
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
220 try
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
221 {
88
110a7b0bcab5 Re #50: Complete core loading from XML
IBBoard <dev@ibboard.co.uk>
parents: 87
diff changeset
222 unitEquipItem.IsRequired = bool.Parse(equip.GetAttribute("required"));
86
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
223 }
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
224 catch(FormatException e)
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
225 {
87
9fba3b4ccdcd Re #50: Complete core XML loading
IBBoard <dev@ibboard.co.uk>
parents: 86
diff changeset
226 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
227 }
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
228
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
229 try
91
571d8ddc7d9a Fixes #111: "Replace Weapon" button doesn't always enable
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
230 {
88
110a7b0bcab5 Re #50: Complete core loading from XML
IBBoard <dev@ibboard.co.uk>
parents: 87
diff changeset
231 unitEquipItem.MinNumber = int.Parse(equip.GetAttribute("minNum"));
86
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
232 }
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
233 catch (FormatException e)
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
234 {
87
9fba3b4ccdcd Re #50: Complete core XML loading
IBBoard <dev@ibboard.co.uk>
parents: 86
diff changeset
235 throw new InvalidFileException("Attribute 'minNum' of unit equipment item " + id + " for " + type.Name + " was not a valid integer", e);
86
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
236 }
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
237
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
238 try
91
571d8ddc7d9a Fixes #111: "Replace Weapon" button doesn't always enable
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
239 {
88
110a7b0bcab5 Re #50: Complete core loading from XML
IBBoard <dev@ibboard.co.uk>
parents: 87
diff changeset
240 unitEquipItem.MaxNumber = int.Parse(equip.GetAttribute("maxNum"));
86
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
241 }
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
242 catch (FormatException e)
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
243 {
87
9fba3b4ccdcd Re #50: Complete core XML loading
IBBoard <dev@ibboard.co.uk>
parents: 86
diff changeset
244 throw new InvalidFileException("Attribute 'maxNum' of unit equipment item " + id + " for " + type.Name + " was not a valid integer", e);
86
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
245 }
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
246
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
247 try
91
571d8ddc7d9a Fixes #111: "Replace Weapon" button doesn't always enable
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
248 {
88
110a7b0bcab5 Re #50: Complete core loading from XML
IBBoard <dev@ibboard.co.uk>
parents: 87
diff changeset
249 unitEquipItem.MinPercentage = double.Parse(equip.GetAttribute("minPercentage"));
86
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
250 }
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
251 catch (FormatException e)
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
252 {
87
9fba3b4ccdcd Re #50: Complete core XML loading
IBBoard <dev@ibboard.co.uk>
parents: 86
diff changeset
253 throw new InvalidFileException("Attribute 'minPercentage' 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
254 }
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
255
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
256 try
91
571d8ddc7d9a Fixes #111: "Replace Weapon" button doesn't always enable
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
257 {
88
110a7b0bcab5 Re #50: Complete core loading from XML
IBBoard <dev@ibboard.co.uk>
parents: 87
diff changeset
258 unitEquipItem.MaxPercentage = double.Parse(equip.GetAttribute("maxPercentage"));
86
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
259 }
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
260 catch (FormatException e)
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
261 {
87
9fba3b4ccdcd Re #50: Complete core XML loading
IBBoard <dev@ibboard.co.uk>
parents: 86
diff changeset
262 throw new InvalidFileException("Attribute 'maxPercentage' 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
263 }
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
264
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
265 try
91
571d8ddc7d9a Fixes #111: "Replace Weapon" button doesn't always enable
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
266 {
88
110a7b0bcab5 Re #50: Complete core loading from XML
IBBoard <dev@ibboard.co.uk>
parents: 87
diff changeset
267 unitEquipItem.CostMultiplier = double.Parse(equip.GetAttribute("costMultiplier"));
86
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
268 }
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
269 catch (FormatException e)
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
270 {
87
9fba3b4ccdcd Re #50: Complete core XML loading
IBBoard <dev@ibboard.co.uk>
parents: 86
diff changeset
271 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
272 }
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
273
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
274 try
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
275 {
88
110a7b0bcab5 Re #50: Complete core loading from XML
IBBoard <dev@ibboard.co.uk>
parents: 87
diff changeset
276 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
277 }
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
278 catch (ArgumentException e)
129636305ad7 Re #50: Complete core loading of XML files
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
279 {
87
9fba3b4ccdcd Re #50: Complete core XML loading
IBBoard <dev@ibboard.co.uk>
parents: 86
diff changeset
280 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
281 }
85
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
282 }
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
283 else
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
284 {
128
45a9452579a2 Fixes #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
285 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
286 }
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
287 }
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
288
68
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
289 }
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
290
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
291 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
292 {
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
293 foreach (XmlElement ability in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:unitAbilities/race:unitAbility"))
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
294 {
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
295 string id = ability.GetAttribute("abilityID");
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
296 bool required = XmlTools.GetBoolValueFromAttribute(ability, "required");
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
297 type.AddAbility(type.Race.GetAbility(id), required);
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
298 }
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
299 }
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
300
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
301 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
302 {
69
91cf8efbea0b Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
303 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
304 {
91cf8efbea0b Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
305 string id = containedUnitType.GetAttribute("containedID");
91cf8efbea0b Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
306 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
307
91cf8efbea0b Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
308 if (containedType!=null)
91cf8efbea0b Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
309 {
91cf8efbea0b Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
310 type.AddContainedUnitType(containedType);
91cf8efbea0b Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
311 }
91cf8efbea0b Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
312 else
91cf8efbea0b Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
313 {
128
45a9452579a2 Fixes #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
314 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
315 }
91cf8efbea0b Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
316 }
68
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
317 }
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
318
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
319 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
320 {
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
321 //TODO: Load requirements
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
322 }
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
323
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
324 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
325 {
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
326 }
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
327
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
328 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
329 {
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
330 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
331
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
332 if (node!=null)
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
333 {
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
334 type.Notes = node.InnerText;
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
335 }
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
336 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
337
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
338 private Stats ParseUnitStats(XmlElement elem, GameSystem system)
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
339 {
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
340 String statsID = elem.GetAttribute("statSet");
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
341 SystemStats statsSet;
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
342
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
343 if (statsID == "")
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
344 {
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
345 statsSet = system.StandardSystemStats;
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
346 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
347 else
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
348 {
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
349 statsSet = system.GetSystemStatsForID(statsID);
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
350 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
351
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
352 Stats stats = new Stats(statsSet);
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
353
53
1b35eed503ef Closes #13 - Migrate to XPath
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
354 foreach (XmlElement stat in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:stat"))
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
355 {
67
e6200220ece3 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 55
diff changeset
356 String statName = stat.GetAttribute("name");
e6200220ece3 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 55
diff changeset
357 stats.SetStatValue(statName, stat.InnerText);
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
358 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
359
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
360 return stats;
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
361 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
362
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
363 private EquipmentItem CreateEquipmentItemFromElement(XmlElement elem, Race race)
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
364 {
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
365 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
366 EquipmentItem item = race.GetEquipmentItem(id);
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
367
85
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
368 if (item == null)
68
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 item = CreateEquipmentItemFromElement(elem, id, race);
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
371 }
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
372
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
373 return item;
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
374 }
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
375
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
376 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
377 {
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
378 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
379 EquipmentItem item = new EquipmentItem(id, name, race);
55
9080366031c0 Re #9 - Refactor for small methods
IBBoard <dev@ibboard.co.uk>
parents: 53
diff changeset
380 double cost = 0;
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
381 ArmourType armourType;
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
382
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
383 try
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
384 {
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
385 cost = XmlTools.GetDoubleValueFromAttribute(elem, "cost");
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
386 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
387 catch(FormatException ex)
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
388 {
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
389 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
390 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
391
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
392 try
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
393 {
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
394 armourType = (ArmourType)Enum.Parse(typeof(ArmourType), elem.GetAttribute("armourType"));
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
395 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
396 catch(ArgumentException ex)
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
397 {
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
398 throw new InvalidFileException("Attribute 'armourType' of equipment "+id+" was not a valid value from the enumeration", ex);
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
399 }
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
400
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
401 //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
402 item.Cost = cost;
9080366031c0 Re #9 - Refactor for small methods
IBBoard <dev@ibboard.co.uk>
parents: 53
diff changeset
403 item.ItemArmourType = armourType;
85
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
404 race.AddEquipmentItem(item);
55
9080366031c0 Re #9 - Refactor for small methods
IBBoard <dev@ibboard.co.uk>
parents: 53
diff changeset
405 return item;
52
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
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
408 private Ability CreateAbilityFromElement(XmlElement elem, Race race)
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
409 {
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
410 string id = elem.GetAttribute("id");
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
411 string name = elem.GetAttribute("name");
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
412 Ability ability = new Ability(id, name);
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
413 XmlNode node = elem.SelectSingleNode("description", WarFoundryXmlFactoryUtils.GetNamespaceManager());
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
414 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
415 race.AddAbility(ability);
52
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
416 return ability;
64ef178c18aa Re #10 - Refactor for readability
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
417 }
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 }