comparison api/Objects/GameSystem.cs @ 0:520818033bb6

Initial commit of WarFoundry code
author IBBoard <dev@ibboard.co.uk>
date Fri, 19 Dec 2008 15:57:51 +0000
parents
children 150a5669cd7b
comparison
equal deleted inserted replaced
-1:000000000000 0:520818033bb6
1 using System;
2 using System.Collections.Generic;
3 using System.Xml;
4 using System.IO;
5 using IBBoard.Logging;
6 using IBBoard.WarFoundry.API.Factories;
7 using ICSharpCode.SharpZipLib.Zip;
8
9 namespace IBBoard.WarFoundry.API.Objects
10 {
11 /// <summary>
12 /// Summary description for GameSystem.
13 /// </summary>
14 public class GameSystem : WarFoundryObject // WarFoundryStagedLoadSourceObject
15 {
16 private bool warnOnError;
17 private Category[] categories;
18 private SystemStatsSet stats;
19 private string defaultStats;
20 private FileInfo sourceFile;
21
22 public GameSystem(string systemID, string systemName) : base(systemID, systemName)
23 {
24 }
25
26 /*public void CompleteLoading(Category[] cats, Dictionary<string, SystemStats> sysStats, string defaultStatsID)
27 {
28 categories = cats;
29 stats = new SystemStatsSet(sysStats);
30 defaultStats = defaultStatsID;
31 base.CompleteLoading();
32 }*/
33
34 public FileInfo SourceFile
35 {
36 get { return sourceFile; }
37 set { sourceFile = value; }
38 }
39
40 public int GetCategoryCount()
41 {
42 return categories.Length;
43 }
44
45 public Category GetCategory(int index)
46 {
47 return categories[index];
48 }
49
50 public Category GetCategory(string id)
51 {
52 for (int i = 0; i<categories.Length; i++)
53 {
54 if (categories[i].ID == id)
55 {
56 return categories[i];
57 }
58 }
59
60 return null;
61 }
62
63 public Category[] Categories
64 {
65 get
66 {
67 return SystemCategories;
68 }
69 set
70 {
71 SystemCategories = value;
72 }
73 }
74
75 protected virtual Category[] SystemCategories
76 {
77 get
78 {
79 return RawSystemCategories;
80 }
81 set
82 {
83 RawSystemCategories = value;
84 }
85 }
86
87 protected Category[] RawSystemCategories
88 {
89 get
90 {
91 return categories;
92 }
93 set
94 {
95 if (value!=null)
96 {
97 categories = value;
98 }
99 }
100 }
101
102 public bool WarnOnError
103 {
104 get
105 {
106 return warnOnError;
107 }
108 set { warnOnError = value; }
109 }
110
111 public SystemStats StandardSystemStats
112 {
113 get
114 {
115 return SystemStats[defaultStats];
116 }
117 }
118
119 public string StandardSystemStatsID
120 {
121 get
122 {
123 return defaultStats;
124 }
125
126 set
127 {
128 if (value != null && value.Trim().Length > 0)
129 {
130 defaultStats = value;
131 }
132 }
133 }
134
135 public SystemStatsSet SystemStats
136 {
137 get
138 {
139 return stats;
140 }
141 set
142 {
143 stats = value;
144 }
145 }
146
147 public Race SystemDefaultRace
148 {
149 get { return WarFoundryLoader.GetDefault().GetRace(this, Race.SYSTEM_DEFAULT_RACE_ID); }
150 }
151
152 public bool Matches(GameSystem otherSystem)
153 {
154 if (otherSystem==null)
155 {
156 return false;
157 }
158
159 return this.ID == otherSystem.ID;
160 }
161
162 public override bool Equals(object obj)
163 {
164 if (obj == null)
165 {
166 return false;
167 }
168
169 if (obj.GetType().Equals(this.GetType()))
170 {
171 GameSystem otherSystem = (GameSystem)obj;
172
173 return this.ID == otherSystem.ID && this.Name == otherSystem.Name && ((this.RawSystemCategories == null && otherSystem.RawSystemCategories == null) || this.RawSystemCategories.Equals(otherSystem.RawSystemCategories));
174 }
175 else
176 {
177 return false;
178 }
179 }
180
181 public override int GetHashCode()
182 {
183 return ID.GetHashCode() + Name.GetHashCode() + (RawSystemCategories!=null ? RawSystemCategories.GetHashCode() : 0) + warnOnError.GetHashCode();
184 }
185
186 public bool UnitTypeMaxed(UnitType unitType, Army army)
187 {
188 return unitType.MaxNumber!=-1 && army.GetUnitTypeCount(unitType) >= unitType.MaxNumber;
189 }
190
191 public bool UnitTypeMinned(UnitType unitType, Army army)
192 {
193 return army.GetUnitTypeCount(unitType) <= unitType.MinNumber;
194 }
195
196 public List<EquipmentItem> GetSystemEquipmentList()
197 {
198 List<EquipmentItem> items = new List<EquipmentItem>();
199 Race defaultRace = SystemDefaultRace;
200
201 if (defaultRace!=null)
202 {
203 items = defaultRace.GetEquipmentList();
204 }
205
206 return items;
207 }
208
209 public EquipmentItem GetSystemEquipmentItem(string id)
210 {
211 EquipmentItem item = null;
212 Race defaultRace = SystemDefaultRace;
213
214 if (defaultRace!=null)
215 {
216 item = defaultRace.GetEquipmentItem(id);
217 }
218
219 return item;
220 }
221
222 public UnitType[] GetSystemUnitTypes(Category cat)
223 {
224 UnitType[] items = new UnitType[0];
225 Race defaultRace = SystemDefaultRace;
226
227 if (defaultRace!=null)
228 {
229 items = defaultRace.GetUnitTypes(cat);
230 }
231
232 return items;
233 }
234
235 public UnitType GetSystemUnitType(string id)
236 {
237 UnitType unit = null;
238 Race defaultRace = SystemDefaultRace;
239
240 if (defaultRace!=null)
241 {
242 unit = defaultRace.GetUnitType(id);
243 }
244
245 return unit;
246 }
247
248 public List<Ability> GetSystemAbilityList()
249 {
250 List<Ability> items = new List<Ability>();
251 Race defaultRace = SystemDefaultRace;
252
253 if (defaultRace!=null)
254 {
255 items = defaultRace.GetAbilityList();
256 }
257
258 return items;
259 }
260
261 public Ability GetSystemAbility(string id)
262 {
263 Ability ability = null;
264 Race defaultRace = SystemDefaultRace;
265
266 if (defaultRace!=null)
267 {
268 ability = defaultRace.GetAbility(id);
269 }
270
271 return ability;
272 }
273 }
274 }