Mercurial > repos > IBDev-IBBoard.WarFoundry.API
annotate api/Objects/GameSystem.cs @ 57:e0ce5578e7c2
Re #61 - Complete structure of WarFoundry API objects
* Add methods for adding and getting Notes and contained UnitTypes of a UnitType
* Add method to get requirements of a unit
* Separate out required abilities from optional abilities
* Remove UnitAbility and handle by passing a boolean to the AddAbility method
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 07 Apr 2009 14:43:04 +0000 |
parents | b271a2252758 |
children | 3ea0ab04352b |
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 { |
51 | 20 private bool warnOnError; |
21 private bool allowAllies; | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
22 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
|
23 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
|
24 private string defaultStats; |
0 | 25 |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
26 public GameSystem(string systemID, string systemName, IWarFoundryFactory creatingFactory) : base(systemID, systemName, creatingFactory) |
0 | 27 { |
6 | 28 stats = new Dictionary<string,SystemStats>(); |
0 | 29 } |
51 | 30 |
31 public bool AllowAllies | |
0 | 32 { |
51 | 33 get { return allowAllies; } |
34 set { allowAllies = value; } | |
35 } | |
0 | 36 |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
37 public void AddCategory(Category cat) |
0 | 38 { |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
39 RawCategories[cat.ID] = cat; |
0 | 40 } |
41 | |
42 public Category GetCategory(string id) | |
6 | 43 { |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
44 EnsureFullyLoaded(); |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
45 Category cat = null; |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
46 RawCategories.TryGetValue(id, out cat); |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
47 return cat; |
0 | 48 } |
49 | |
50 public Category[] Categories | |
51 { | |
52 get | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
53 { |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
54 EnsureFullyLoaded(); |
14
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
55 return DictionaryUtils.ToArray<string, Category>(RawCategories); |
0 | 56 } |
57 } | |
58 | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
59 protected Dictionary<string, Category> RawCategories |
0 | 60 { |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
61 get { return categories; } |
0 | 62 } |
63 | |
64 public bool WarnOnError | |
65 { | |
66 get | |
67 { | |
68 return warnOnError; | |
69 } | |
70 set { warnOnError = value; } | |
71 } | |
72 | |
6 | 73 public void AddSystemStats(SystemStats sysStats) |
74 { | |
75 stats[sysStats.ID] = sysStats; | |
76 } | |
77 | |
0 | 78 public SystemStats StandardSystemStats |
79 { | |
80 get | |
81 { | |
43
d0812d7de39d
Re #49 - Resolve namespace issues
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
82 EnsureFullyLoaded(); |
6 | 83 return stats[defaultStats]; |
0 | 84 } |
85 } | |
86 | |
87 public string StandardSystemStatsID | |
88 { | |
89 get | |
90 { | |
91 return defaultStats; | |
92 } | |
93 | |
94 set | |
95 { | |
96 if (value != null && value.Trim().Length > 0) | |
97 { | |
98 defaultStats = value; | |
99 } | |
100 } | |
101 } | |
102 | |
6 | 103 public SystemStats[] SystemStats |
0 | 104 { |
105 get | |
6 | 106 { |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
107 EnsureFullyLoaded(); |
6 | 108 SystemStats[] statsArray = new SystemStats[stats.Count]; |
109 stats.Values.CopyTo(statsArray, 0); | |
110 return statsArray; | |
0 | 111 } |
112 } | |
113 | |
6 | 114 public SystemStats GetSystemStatsForID(string id) |
115 { | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
116 EnsureFullyLoaded(); |
6 | 117 SystemStats statsForID; |
118 stats.TryGetValue(id, out statsForID); | |
119 return statsForID; | |
120 } | |
121 | |
0 | 122 public Race SystemDefaultRace |
123 { | |
124 get { return WarFoundryLoader.GetDefault().GetRace(this, Race.SYSTEM_DEFAULT_RACE_ID); } | |
125 } | |
126 | |
127 public bool Matches(GameSystem otherSystem) | |
128 { | |
129 if (otherSystem==null) | |
130 { | |
131 return false; | |
132 } | |
133 | |
134 return this.ID == otherSystem.ID; | |
135 } | |
136 | |
137 public override bool Equals(object obj) | |
138 { | |
139 if (obj == null) | |
140 { | |
141 return false; | |
142 } | |
143 | |
144 if (obj.GetType().Equals(this.GetType())) | |
145 { | |
146 GameSystem otherSystem = (GameSystem)obj; | |
147 | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
148 return this.ID == otherSystem.ID && this.Name == otherSystem.Name && ((this.RawCategories == null && otherSystem.RawCategories == null) || this.RawCategories.Equals(otherSystem.RawCategories)); |
0 | 149 } |
150 else | |
151 { | |
152 return false; | |
153 } | |
154 } | |
155 | |
156 public override int GetHashCode() | |
157 { | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
158 return ID.GetHashCode() + Name.GetHashCode() + (RawCategories!=null ? RawCategories.GetHashCode() : 0) + warnOnError.GetHashCode(); |
0 | 159 } |
160 | |
161 public bool UnitTypeMaxed(UnitType unitType, Army army) | |
162 { | |
38
548cfc776f54
Fixes #34 - Remove "Choices" and "Base/Increment" from Category
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
163 return unitType.MaxNumber!=WarFoundryCore.INFINITY && army.GetUnitTypeCount(unitType) >= unitType.MaxNumber; |
0 | 164 } |
165 | |
166 public bool UnitTypeMinned(UnitType unitType, Army army) | |
167 { | |
168 return army.GetUnitTypeCount(unitType) <= unitType.MinNumber; | |
169 } | |
170 | |
171 public List<EquipmentItem> GetSystemEquipmentList() | |
172 { | |
173 List<EquipmentItem> items = new List<EquipmentItem>(); | |
174 Race defaultRace = SystemDefaultRace; | |
175 | |
176 if (defaultRace!=null) | |
177 { | |
178 items = defaultRace.GetEquipmentList(); | |
179 } | |
180 | |
181 return items; | |
182 } | |
183 | |
184 public EquipmentItem GetSystemEquipmentItem(string id) | |
185 { | |
186 EquipmentItem item = null; | |
187 Race defaultRace = SystemDefaultRace; | |
188 | |
189 if (defaultRace!=null) | |
190 { | |
191 item = defaultRace.GetEquipmentItem(id); | |
192 } | |
193 | |
194 return item; | |
195 } | |
196 | |
197 public UnitType[] GetSystemUnitTypes(Category cat) | |
198 { | |
199 UnitType[] items = new UnitType[0]; | |
200 Race defaultRace = SystemDefaultRace; | |
201 | |
202 if (defaultRace!=null) | |
203 { | |
204 items = defaultRace.GetUnitTypes(cat); | |
205 } | |
206 | |
207 return items; | |
208 } | |
209 | |
210 public UnitType GetSystemUnitType(string id) | |
211 { | |
212 UnitType unit = null; | |
213 Race defaultRace = SystemDefaultRace; | |
214 | |
215 if (defaultRace!=null) | |
216 { | |
217 unit = defaultRace.GetUnitType(id); | |
218 } | |
219 | |
220 return unit; | |
221 } | |
222 | |
223 public List<Ability> GetSystemAbilityList() | |
224 { | |
225 List<Ability> items = new List<Ability>(); | |
226 Race defaultRace = SystemDefaultRace; | |
227 | |
228 if (defaultRace!=null) | |
229 { | |
230 items = defaultRace.GetAbilityList(); | |
231 } | |
232 | |
233 return items; | |
234 } | |
235 | |
236 public Ability GetSystemAbility(string id) | |
237 { | |
238 Ability ability = null; | |
239 Race defaultRace = SystemDefaultRace; | |
240 | |
241 if (defaultRace!=null) | |
242 { | |
243 ability = defaultRace.GetAbility(id); | |
244 } | |
245 | |
246 return ability; | |
247 } | |
248 } | |
249 } |