Mercurial > repos > IBDev-IBBoard.WarFoundry.API
annotate api/Objects/GameSystem.cs @ 43:d0812d7de39d
Re #49 - Resolve namespace issues
* Fix up some XPath queries
* Remove one unnecessary namespace
* Check local name of elements, not name (which is qualified)
* Add method to get double value from an attribute including handling INF
* Remove min/max for equipment item as it is now moved to the UnitType's reference to the equipment item
*
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 22 Mar 2009 17:05:01 +0000 |
parents | 548cfc776f54 |
children | b271a2252758 |
rev | line source |
---|---|
15 | 1 // This file (GameSystem.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard. |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
2 // |
15 | 3 // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
4 |
0 | 5 using System; |
6 using System.Collections.Generic; | |
7 using System.Xml; | |
8 using System.IO; | |
9 using IBBoard.Logging; | |
10 using IBBoard.WarFoundry.API.Factories; | |
11 using ICSharpCode.SharpZipLib.Zip; | |
12 | |
13 namespace IBBoard.WarFoundry.API.Objects | |
14 { | |
15 /// <summary> | |
16 /// Summary description for GameSystem. | |
17 /// </summary> | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
18 public class GameSystem : WarFoundryStagedLoadingObject |
0 | 19 { |
20 private bool warnOnError; | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
21 private Dictionary<string, Category> categories = new Dictionary<string,Category>(); |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
22 private Dictionary<string, SystemStats> stats = new Dictionary<string,SystemStats>(); |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
23 private string defaultStats; |
0 | 24 |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
25 public GameSystem(string systemID, string systemName, IWarFoundryFactory creatingFactory) : base(systemID, systemName, creatingFactory) |
0 | 26 { |
6 | 27 stats = new Dictionary<string,SystemStats>(); |
0 | 28 } |
29 | |
30 /*public void CompleteLoading(Category[] cats, Dictionary<string, SystemStats> sysStats, string defaultStatsID) | |
31 { | |
32 categories = cats; | |
33 stats = new SystemStatsSet(sysStats); | |
34 defaultStats = defaultStatsID; | |
35 base.CompleteLoading(); | |
36 }*/ | |
37 | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
38 public void AddCategory(Category cat) |
0 | 39 { |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
40 RawCategories[cat.ID] = cat; |
0 | 41 } |
42 | |
43 public Category GetCategory(string id) | |
6 | 44 { |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
45 EnsureFullyLoaded(); |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
46 Category cat = null; |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
47 RawCategories.TryGetValue(id, out cat); |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
48 return cat; |
0 | 49 } |
50 | |
51 public Category[] Categories | |
52 { | |
53 get | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
54 { |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
55 EnsureFullyLoaded(); |
14
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
56 return DictionaryUtils.ToArray<string, Category>(RawCategories); |
0 | 57 } |
58 } | |
59 | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
60 protected Dictionary<string, Category> RawCategories |
0 | 61 { |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
62 get { return categories; } |
0 | 63 } |
64 | |
65 public bool WarnOnError | |
66 { | |
67 get | |
68 { | |
69 return warnOnError; | |
70 } | |
71 set { warnOnError = value; } | |
72 } | |
73 | |
6 | 74 public void AddSystemStats(SystemStats sysStats) |
75 { | |
76 stats[sysStats.ID] = sysStats; | |
77 } | |
78 | |
0 | 79 public SystemStats StandardSystemStats |
80 { | |
81 get | |
82 { | |
43
d0812d7de39d
Re #49 - Resolve namespace issues
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
83 EnsureFullyLoaded(); |
6 | 84 return stats[defaultStats]; |
0 | 85 } |
86 } | |
87 | |
88 public string StandardSystemStatsID | |
89 { | |
90 get | |
91 { | |
92 return defaultStats; | |
93 } | |
94 | |
95 set | |
96 { | |
97 if (value != null && value.Trim().Length > 0) | |
98 { | |
99 defaultStats = value; | |
100 } | |
101 } | |
102 } | |
103 | |
6 | 104 public SystemStats[] SystemStats |
0 | 105 { |
106 get | |
6 | 107 { |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
108 EnsureFullyLoaded(); |
6 | 109 SystemStats[] statsArray = new SystemStats[stats.Count]; |
110 stats.Values.CopyTo(statsArray, 0); | |
111 return statsArray; | |
0 | 112 } |
113 } | |
114 | |
6 | 115 public SystemStats GetSystemStatsForID(string id) |
116 { | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
117 EnsureFullyLoaded(); |
6 | 118 SystemStats statsForID; |
119 stats.TryGetValue(id, out statsForID); | |
120 return statsForID; | |
121 } | |
122 | |
0 | 123 public Race SystemDefaultRace |
124 { | |
125 get { return WarFoundryLoader.GetDefault().GetRace(this, Race.SYSTEM_DEFAULT_RACE_ID); } | |
126 } | |
127 | |
128 public bool Matches(GameSystem otherSystem) | |
129 { | |
130 if (otherSystem==null) | |
131 { | |
132 return false; | |
133 } | |
134 | |
135 return this.ID == otherSystem.ID; | |
136 } | |
137 | |
138 public override bool Equals(object obj) | |
139 { | |
140 if (obj == null) | |
141 { | |
142 return false; | |
143 } | |
144 | |
145 if (obj.GetType().Equals(this.GetType())) | |
146 { | |
147 GameSystem otherSystem = (GameSystem)obj; | |
148 | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
149 return this.ID == otherSystem.ID && this.Name == otherSystem.Name && ((this.RawCategories == null && otherSystem.RawCategories == null) || this.RawCategories.Equals(otherSystem.RawCategories)); |
0 | 150 } |
151 else | |
152 { | |
153 return false; | |
154 } | |
155 } | |
156 | |
157 public override int GetHashCode() | |
158 { | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
159 return ID.GetHashCode() + Name.GetHashCode() + (RawCategories!=null ? RawCategories.GetHashCode() : 0) + warnOnError.GetHashCode(); |
0 | 160 } |
161 | |
162 public bool UnitTypeMaxed(UnitType unitType, Army army) | |
163 { | |
38
548cfc776f54
Fixes #34 - Remove "Choices" and "Base/Increment" from Category
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
164 return unitType.MaxNumber!=WarFoundryCore.INFINITY && army.GetUnitTypeCount(unitType) >= unitType.MaxNumber; |
0 | 165 } |
166 | |
167 public bool UnitTypeMinned(UnitType unitType, Army army) | |
168 { | |
169 return army.GetUnitTypeCount(unitType) <= unitType.MinNumber; | |
170 } | |
171 | |
172 public List<EquipmentItem> GetSystemEquipmentList() | |
173 { | |
174 List<EquipmentItem> items = new List<EquipmentItem>(); | |
175 Race defaultRace = SystemDefaultRace; | |
176 | |
177 if (defaultRace!=null) | |
178 { | |
179 items = defaultRace.GetEquipmentList(); | |
180 } | |
181 | |
182 return items; | |
183 } | |
184 | |
185 public EquipmentItem GetSystemEquipmentItem(string id) | |
186 { | |
187 EquipmentItem item = null; | |
188 Race defaultRace = SystemDefaultRace; | |
189 | |
190 if (defaultRace!=null) | |
191 { | |
192 item = defaultRace.GetEquipmentItem(id); | |
193 } | |
194 | |
195 return item; | |
196 } | |
197 | |
198 public UnitType[] GetSystemUnitTypes(Category cat) | |
199 { | |
200 UnitType[] items = new UnitType[0]; | |
201 Race defaultRace = SystemDefaultRace; | |
202 | |
203 if (defaultRace!=null) | |
204 { | |
205 items = defaultRace.GetUnitTypes(cat); | |
206 } | |
207 | |
208 return items; | |
209 } | |
210 | |
211 public UnitType GetSystemUnitType(string id) | |
212 { | |
213 UnitType unit = null; | |
214 Race defaultRace = SystemDefaultRace; | |
215 | |
216 if (defaultRace!=null) | |
217 { | |
218 unit = defaultRace.GetUnitType(id); | |
219 } | |
220 | |
221 return unit; | |
222 } | |
223 | |
224 public List<Ability> GetSystemAbilityList() | |
225 { | |
226 List<Ability> items = new List<Ability>(); | |
227 Race defaultRace = SystemDefaultRace; | |
228 | |
229 if (defaultRace!=null) | |
230 { | |
231 items = defaultRace.GetAbilityList(); | |
232 } | |
233 | |
234 return items; | |
235 } | |
236 | |
237 public Ability GetSystemAbility(string id) | |
238 { | |
239 Ability ability = null; | |
240 Race defaultRace = SystemDefaultRace; | |
241 | |
242 if (defaultRace!=null) | |
243 { | |
244 ability = defaultRace.GetAbility(id); | |
245 } | |
246 | |
247 return ability; | |
248 } | |
249 } | |
250 } |