view api/Objects/GameSystem.cs @ 104:2f3cafb69799

Re #121: Migrate to AGPL license * Update all API files to AGPL license * Include AGPL license and remove GPL/LGPL documents * Fix copyright dates where they're known
author IBBoard <dev@ibboard.co.uk>
date Sat, 15 Aug 2009 10:36:50 +0000
parents 3ea0ab04352b
children d576034ad1dd
line source
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.
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;
13 namespace IBBoard.WarFoundry.API.Objects
14 {
15 /// <summary>
16 /// Summary description for GameSystem.
17 /// </summary>
18 public class GameSystem : WarFoundryStagedLoadingObject
19 {
20 private bool warnOnError;
21 private bool allowAllies;
22 private Dictionary<string, Category> categories = new Dictionary<string,Category>();
23 private Dictionary<string, SystemStats> stats = new Dictionary<string,SystemStats>();
24 private string defaultStats;
26 public GameSystem(string systemID, string systemName, IWarFoundryFactory creatingFactory) : base(systemID, systemName, creatingFactory)
27 {
28 stats = new Dictionary<string,SystemStats>();
29 }
31 public bool AllowAllies
32 {
33 get { return allowAllies; }
34 set { allowAllies = value; }
35 }
37 public void AddCategory(Category cat)
38 {
39 RawCategories[cat.ID] = cat;
40 }
42 public Category GetCategory(string id)
43 {
44 EnsureFullyLoaded();
45 Category cat = null;
46 RawCategories.TryGetValue(id, out cat);
47 return cat;
48 }
50 public Category[] Categories
51 {
52 get
53 {
54 EnsureFullyLoaded();
55 return DictionaryUtils.ToArray<string, Category>(RawCategories);
56 }
57 }
59 protected Dictionary<string, Category> RawCategories
60 {
61 get { return categories; }
62 }
64 public bool WarnOnError
65 {
66 get
67 {
68 return warnOnError;
69 }
70 set { warnOnError = value; }
71 }
73 public void AddSystemStats(SystemStats sysStats)
74 {
75 stats[sysStats.ID] = sysStats;
76 }
78 public SystemStats StandardSystemStats
79 {
80 get
81 {
82 EnsureFullyLoaded();
83 return stats[defaultStats];
84 }
85 }
87 public string StandardSystemStatsID
88 {
89 get
90 {
91 return defaultStats;
92 }
94 set
95 {
96 if (value != null && value.Trim().Length > 0)
97 {
98 defaultStats = value;
99 }
100 }
101 }
103 public SystemStats[] SystemStats
104 {
105 get
106 {
107 EnsureFullyLoaded();
108 SystemStats[] statsArray = new SystemStats[stats.Count];
109 stats.Values.CopyTo(statsArray, 0);
110 return statsArray;
111 }
112 }
114 public SystemStats GetSystemStatsForID(string id)
115 {
116 EnsureFullyLoaded();
117 SystemStats statsForID;
118 stats.TryGetValue(id, out statsForID);
119 return statsForID;
120 }
122 public Race SystemDefaultRace
123 {
124 get { return WarFoundryLoader.GetDefault().GetRace(this, Race.SYSTEM_DEFAULT_RACE_ID); }
125 }
127 public bool Matches(GameSystem otherSystem)
128 {
129 if (otherSystem==null)
130 {
131 return false;
132 }
134 return this.ID == otherSystem.ID;
135 }
137 public override bool Equals(object obj)
138 {
139 if (obj == null)
140 {
141 return false;
142 }
144 if (obj.GetType().Equals(this.GetType()))
145 {
146 GameSystem otherSystem = (GameSystem)obj;
148 return this.ID == otherSystem.ID && this.Name == otherSystem.Name && ((this.RawCategories == null && otherSystem.RawCategories == null) || this.RawCategories.Equals(otherSystem.RawCategories));
149 }
150 else
151 {
152 return false;
153 }
154 }
156 public override int GetHashCode()
157 {
158 return ID.GetHashCode() + Name.GetHashCode() + (RawCategories!=null ? RawCategories.GetHashCode() : 0) + warnOnError.GetHashCode();
159 }
161 public bool UnitTypeMaxed(UnitType unitType, Army army)
162 {
163 return unitType.MaxNumber!=WarFoundryCore.INFINITY && army.GetUnitTypeCount(unitType) >= unitType.MaxNumber;
164 }
166 public bool UnitTypeMinned(UnitType unitType, Army army)
167 {
168 return army.GetUnitTypeCount(unitType) <= unitType.MinNumber;
169 }
171 public List<EquipmentItem> GetSystemEquipmentList()
172 {
173 List<EquipmentItem> items = new List<EquipmentItem>();
174 Race defaultRace = SystemDefaultRace;
176 if (defaultRace!=null)
177 {
178 items = defaultRace.GetEquipmentList();
179 }
181 return items;
182 }
184 public EquipmentItem GetSystemEquipmentItem(string id)
185 {
186 EquipmentItem item = null;
187 Race defaultRace = SystemDefaultRace;
189 if (defaultRace!=null)
190 {
191 item = defaultRace.GetEquipmentItem(id);
192 }
194 return item;
195 }
197 public UnitType[] GetSystemUnitTypes(Category cat)
198 {
199 UnitType[] items = new UnitType[0];
200 Race defaultRace = SystemDefaultRace;
202 if (defaultRace!=null)
203 {
204 items = defaultRace.GetUnitTypes(cat);
205 }
207 return items;
208 }
210 public UnitType GetSystemUnitType(string id)
211 {
212 UnitType unit = null;
213 Race defaultRace = SystemDefaultRace;
215 if (defaultRace!=null)
216 {
217 unit = defaultRace.GetUnitType(id);
218 }
220 return unit;
221 }
223 public List<Ability> GetSystemAbilityList()
224 {
225 List<Ability> items = new List<Ability>();
226 Race defaultRace = SystemDefaultRace;
228 if (defaultRace!=null)
229 {
230 items = defaultRace.GetAbilityList();
231 }
233 return items;
234 }
236 public Ability GetSystemAbility(string id)
237 {
238 Ability ability = null;
239 Race defaultRace = SystemDefaultRace;
241 if (defaultRace!=null)
242 {
243 ability = defaultRace.GetAbility(id);
244 }
246 return ability;
247 }
248 }
249 }