392
|
1 // This file (GameSystem.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard.
|
|
2 //
|
|
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.
|
|
4
|
|
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>
|
|
18 public class GameSystem : WarFoundryStagedLoadingObject
|
|
19 {
|
|
20
|
|
21 private bool warnOnError;
|
|
22 private bool allowAllies;
|
|
23 private Dictionary<string, Category> categories = new Dictionary<string,Category>();
|
|
24 private Dictionary<string, SystemStats> stats = new Dictionary<string,SystemStats>();
|
|
25 private string defaultStats;
|
|
26 private int defaultArmySize;
|
|
27
|
|
28 public GameSystem(string systemID, string systemName, IWarFoundryFactory creatingFactory)
|
|
29 : base(systemID, systemName, creatingFactory)
|
|
30 {
|
|
31 stats = new Dictionary<string,SystemStats>();
|
|
32 }
|
|
33
|
|
34 public int SystemArmyDefaultSize
|
|
35 {
|
|
36 get { return defaultArmySize; }
|
|
37 set
|
|
38 {
|
|
39 if (value == 0)
|
|
40 {
|
|
41 defaultArmySize = 1;
|
|
42 throw new ArgumentException("No default system army size");
|
|
43
|
|
44 }
|
|
45
|
|
46 defaultArmySize = value;
|
|
47 }
|
|
48 }
|
|
49
|
|
50 public bool AllowAllies
|
|
51 {
|
|
52 get { return allowAllies; }
|
|
53 set { allowAllies = value; }
|
|
54 }
|
|
55
|
|
56 public void AddCategory(Category cat)
|
|
57 {
|
|
58 RawCategories[cat.ID] = cat;
|
|
59 }
|
|
60
|
|
61 public Category GetCategory(string id)
|
|
62 {
|
|
63 EnsureFullyLoaded();
|
|
64 Category cat = null;
|
|
65 RawCategories.TryGetValue(id, out cat);
|
|
66 return cat;
|
|
67 }
|
|
68
|
|
69 public Category[] Categories
|
|
70 {
|
|
71 get
|
|
72 {
|
|
73 EnsureFullyLoaded();
|
|
74 return DictionaryUtils.ToArray<string, Category>(RawCategories);
|
|
75 }
|
|
76 }
|
|
77
|
|
78 protected Dictionary<string, Category> RawCategories
|
|
79 {
|
|
80 get { return categories; }
|
|
81 }
|
|
82
|
|
83 public bool WarnOnError
|
|
84 {
|
|
85 get
|
|
86 {
|
|
87 return warnOnError;
|
|
88 }
|
|
89 set { warnOnError = value; }
|
|
90 }
|
|
91
|
|
92 public void AddSystemStats(SystemStats sysStats)
|
|
93 {
|
|
94 stats[sysStats.ID] = sysStats;
|
|
95 }
|
|
96
|
|
97 public SystemStats StandardSystemStats
|
|
98 {
|
|
99 get
|
|
100 {
|
|
101 EnsureFullyLoaded();
|
|
102 return stats[defaultStats];
|
|
103 }
|
|
104 }
|
|
105
|
|
106 public string StandardSystemStatsID
|
|
107 {
|
|
108 get
|
|
109 {
|
|
110 EnsureFullyLoaded();
|
|
111 return defaultStats;
|
|
112 }
|
|
113
|
|
114 set
|
|
115 {
|
|
116 if (value != null && value.Trim().Length > 0)
|
|
117 {
|
|
118 defaultStats = value;
|
|
119 }
|
|
120 }
|
|
121 }
|
|
122
|
|
123 public SystemStats[] SystemStats
|
|
124 {
|
|
125 get
|
|
126 {
|
|
127 EnsureFullyLoaded();
|
|
128 SystemStats[] statsArray = new SystemStats[stats.Count];
|
|
129 stats.Values.CopyTo(statsArray, 0);
|
|
130 return statsArray;
|
|
131 }
|
|
132 }
|
|
133
|
|
134 public SystemStats GetSystemStatsForID(string id)
|
|
135 {
|
|
136 EnsureFullyLoaded();
|
|
137 SystemStats statsForID;
|
|
138 stats.TryGetValue(id, out statsForID);
|
|
139 return statsForID;
|
|
140 }
|
|
141
|
|
142 public Race SystemDefaultRace
|
|
143 {
|
|
144 get { return WarFoundryLoader.GetDefault().GetRace(this, Race.SYSTEM_DEFAULT_RACE_ID); }
|
|
145 }
|
|
146
|
|
147 public bool Matches(GameSystem otherSystem)
|
|
148 {
|
|
149 if (otherSystem==null)
|
|
150 {
|
|
151 return false;
|
|
152 }
|
|
153
|
|
154 return this.ID == otherSystem.ID;
|
|
155 }
|
|
156
|
|
157 public override bool Equals(object obj)
|
|
158 {
|
|
159 if (obj == null)
|
|
160 {
|
|
161 return false;
|
|
162 }
|
|
163
|
|
164 if (obj.GetType().Equals(this.GetType()))
|
|
165 {
|
|
166 GameSystem otherSystem = (GameSystem)obj;
|
|
167
|
|
168 return this.ID == otherSystem.ID && this.Name == otherSystem.Name && ((this.RawCategories == null && otherSystem.RawCategories == null) || this.RawCategories.Equals(otherSystem.RawCategories));
|
|
169 }
|
|
170 else
|
|
171 {
|
|
172 return false;
|
|
173 }
|
|
174 }
|
|
175
|
|
176 public override int GetHashCode()
|
|
177 {
|
|
178 return ID.GetHashCode() + Name.GetHashCode() + (RawCategories!=null ? RawCategories.GetHashCode() : 0) + warnOnError.GetHashCode();
|
|
179 }
|
|
180
|
|
181 public bool UnitTypeMaxed(UnitType unitType, Army army)
|
|
182 {
|
|
183 return unitType.MaxNumber!=WarFoundryCore.INFINITY && army.GetUnitTypeCount(unitType) >= unitType.MaxNumber;
|
|
184 }
|
|
185
|
|
186 public bool UnitTypeMinned(UnitType unitType, Army army)
|
|
187 {
|
|
188 return army.GetUnitTypeCount(unitType) <= unitType.MinNumber;
|
|
189 }
|
|
190
|
|
191 public List<EquipmentItem> GetSystemEquipmentList()
|
|
192 {
|
|
193 List<EquipmentItem> items = new List<EquipmentItem>();
|
|
194 Race defaultRace = SystemDefaultRace;
|
|
195
|
|
196 if (defaultRace!=null)
|
|
197 {
|
|
198 items = defaultRace.GetEquipmentList();
|
|
199 }
|
|
200
|
|
201 return items;
|
|
202 }
|
|
203
|
|
204 public EquipmentItem GetSystemEquipmentItem(string id)
|
|
205 {
|
|
206 EquipmentItem item = null;
|
|
207 Race defaultRace = SystemDefaultRace;
|
|
208
|
|
209 if (defaultRace!=null)
|
|
210 {
|
|
211 item = defaultRace.GetEquipmentItem(id);
|
|
212 }
|
|
213
|
|
214 return item;
|
|
215 }
|
|
216
|
|
217 public UnitType[] GetSystemUnitTypes(Category cat)
|
|
218 {
|
|
219 UnitType[] items = new UnitType[0];
|
|
220 Race defaultRace = SystemDefaultRace;
|
|
221
|
|
222 if (defaultRace!=null)
|
|
223 {
|
|
224 items = defaultRace.GetUnitTypes(cat);
|
|
225 }
|
|
226
|
|
227 return items;
|
|
228 }
|
|
229
|
|
230 public UnitType GetSystemUnitType(string id)
|
|
231 {
|
|
232 UnitType unit = null;
|
|
233 Race defaultRace = SystemDefaultRace;
|
|
234
|
|
235 if (defaultRace!=null)
|
|
236 {
|
|
237 unit = defaultRace.GetUnitType(id);
|
|
238 }
|
|
239
|
|
240 return unit;
|
|
241 }
|
|
242
|
|
243 public List<Ability> GetSystemAbilityList()
|
|
244 {
|
|
245 List<Ability> items = new List<Ability>();
|
|
246 Race defaultRace = SystemDefaultRace;
|
|
247
|
|
248 if (defaultRace!=null)
|
|
249 {
|
|
250 items = defaultRace.GetAbilityList();
|
|
251 }
|
|
252
|
|
253 return items;
|
|
254 }
|
|
255
|
|
256 public Ability GetSystemAbility(string id)
|
|
257 {
|
|
258 Ability ability = null;
|
|
259 Race defaultRace = SystemDefaultRace;
|
|
260
|
|
261 if (defaultRace!=null)
|
|
262 {
|
|
263 ability = defaultRace.GetAbility(id);
|
|
264 }
|
|
265
|
|
266 return ability;
|
|
267 }
|
|
268 }
|
|
269 }
|