Mercurial > repos > IBDev-IBBoard.WarFoundry.API
annotate api/Objects/GameSystem.cs @ 15:306558904c2a
Re #1 - LGPL license all code
* Add LGPL header to all files
* Add COPYING.LGPL and COPYING.GPL with content of license
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 25 Jan 2009 14:50:36 +0000 |
parents | 0770e5cbba7c |
children | 548cfc776f54 |
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 { | |
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 { | |
163 return unitType.MaxNumber!=-1 && army.GetUnitTypeCount(unitType) >= unitType.MaxNumber; | |
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 } |