0
|
1 using System;
|
|
2 using System.Collections;
|
|
3 using System.Collections.Generic;
|
|
4 using System.Xml;
|
|
5 using IBBoard.Logging;
|
|
6 using IBBoard.WarFoundry.API.Requirements;
|
|
7
|
|
8 namespace IBBoard.WarFoundry.API.Objects
|
|
9 {
|
|
10 /// <summary>
|
|
11 /// Summary description for Unit.
|
|
12 /// </summary>
|
|
13 public class UnitType : WarFoundryObject
|
|
14 {
|
|
15 protected Category mainCat;
|
|
16 protected string mainCatID;
|
|
17 protected Category[] categories;
|
|
18 protected string[] categoryIDs;
|
|
19 protected Race race;
|
|
20 protected int min, max, baseSize = 0;
|
|
21 protected int minSize, maxSize;
|
|
22 protected double baseUnitCost;
|
|
23 protected double costPerTrooper;
|
|
24 protected Stats stats;
|
|
25 protected UnitRequirement[] requirements;
|
|
26 protected Hashtable equipment = new Hashtable();
|
|
27 protected Hashtable equipmentExclusionGroups = new Hashtable();
|
|
28 protected ArrayList equipmentKeyOrder = new ArrayList();
|
|
29
|
|
30 public UnitType(string id, string typeName, string mainCategoryID, string[] allCategoryIDs, int minNum, int maxNum, int minimumSize, int maximumSize, double unitCost, double trooperCost, Stats unitStats, UnitRequirement[] unitRequirements, Race parentRace) : base(id, typeName)
|
|
31 {
|
|
32 mainCatID = mainCategoryID;
|
|
33 categoryIDs = allCategoryIDs;
|
|
34 race = parentRace;
|
|
35
|
|
36 if (minNum > maxNum && maxNum!=-1)
|
|
37 {
|
|
38 min = maxNum;
|
|
39 LogNotifier.WarnFormat(GetType(), "Unit type {0} ({1}) had a minimum number greater than their maximum number.", typeName, id);
|
|
40 }
|
|
41 else
|
|
42 {
|
|
43 min = (minNum >= 0 ? minNum : 0);
|
|
44 }
|
|
45
|
|
46 max = maxNum;
|
|
47
|
|
48 if (minimumSize > maximumSize && maximumSize!=-1)
|
|
49 {
|
|
50 minSize = maximumSize;
|
|
51 LogNotifier.WarnFormat(GetType(), "Unit type {0} ({1}) had a minimum size greater than their maximum size.", typeName, id);
|
|
52 }
|
|
53 else
|
|
54 {
|
|
55 minSize = (minimumSize >= 0 ? minimumSize : 0);
|
|
56 }
|
|
57
|
|
58 maxSize = maximumSize;
|
|
59 baseUnitCost = unitCost;
|
|
60 costPerTrooper = trooperCost;
|
|
61 requirements = unitRequirements;
|
|
62 stats = unitStats;
|
|
63 }
|
|
64
|
|
65 public Race Race
|
|
66 {
|
|
67 get { return race; }
|
|
68 }
|
|
69
|
|
70 public virtual Category MainCategory
|
|
71 {
|
|
72 get
|
|
73 {
|
|
74 if (mainCat == null)
|
|
75 {
|
|
76 mainCat = Race.GetCategory(mainCatID);
|
|
77 }
|
|
78
|
|
79 return mainCat;
|
|
80 }
|
|
81 }
|
|
82
|
|
83 public virtual Category[] Categories
|
|
84 {
|
|
85 get
|
|
86 {
|
|
87 if (categories == null)
|
|
88 {
|
|
89 categories = new Category[categoryIDs.Length];
|
|
90
|
|
91 for (int i = 0; i<categoryIDs.Length; i++)
|
|
92 {
|
|
93 categories[i] = Race.GetCategory(categoryIDs[i]);
|
|
94 }
|
|
95 }
|
|
96
|
|
97 return categories;
|
|
98 }
|
|
99 }
|
|
100
|
|
101 public int MinSize
|
|
102 {
|
|
103 get { return minSize; }
|
|
104 }
|
|
105
|
|
106 public int MaxSize
|
|
107 {
|
|
108 get { return maxSize; }
|
|
109 }
|
|
110
|
|
111 public int BaseSize
|
|
112 {
|
|
113 get { return baseSize; }
|
|
114 }
|
|
115
|
|
116 public int MinNumber
|
|
117 {
|
|
118 get { return min; }
|
|
119 }
|
|
120
|
|
121 public int MaxNumber
|
|
122 {
|
|
123 get { return max; }
|
|
124 }
|
|
125
|
|
126 public double BaseUnitCost
|
|
127 {
|
|
128 get { return baseUnitCost; }
|
|
129 }
|
|
130
|
|
131 public double CostPerTrooper
|
|
132 {
|
|
133 get { return costPerTrooper; }
|
|
134 }
|
|
135
|
|
136 protected override string DefaultName()
|
|
137 {
|
|
138 throw new InvalidOperationException("Unit type with id "+id+" did not have a name specified");
|
|
139 }
|
|
140
|
|
141 public Stats UnitStats
|
|
142 {
|
|
143 get
|
|
144 {
|
|
145 return stats;
|
|
146 }
|
|
147 }
|
|
148
|
|
149 public UnitEquipmentItem GetEquipmentItem(string id)
|
|
150 {
|
|
151 return (UnitEquipmentItem)equipment[id];
|
|
152 }
|
|
153
|
|
154 public UnitEquipmentItem[] GetEquipmentItems()
|
|
155 {
|
|
156 UnitEquipmentItem[] items = new UnitEquipmentItem[equipment.Count];
|
|
157 int i = 0;
|
|
158
|
|
159 foreach (string itemID in equipmentKeyOrder)
|
|
160 {
|
|
161 items[i++] = (UnitEquipmentItem)equipment[itemID];
|
|
162 }
|
|
163
|
|
164 return items;
|
|
165 }
|
|
166
|
|
167 public List<FailedUnitRequirement> CanAddToArmy(Army army)
|
|
168 {
|
|
169 List<FailedUnitRequirement> failures = new List<FailedUnitRequirement>();
|
|
170
|
|
171 if (requirements!=null && requirements.Length > 0)
|
|
172 {
|
|
173 foreach (UnitRequirement requirement in requirements)
|
|
174 {
|
|
175 FailedUnitRequirement failure = (FailedUnitRequirement)requirement.CanAddToWarFoundryObject(army);
|
|
176
|
|
177 if (failure!=null)
|
|
178 {
|
|
179 failures.Add(failure);
|
|
180 }
|
|
181 }
|
|
182 }
|
|
183
|
|
184 return failures;
|
|
185 }
|
|
186
|
|
187 public List<FailedUnitRequirement> CanRemoveFromArmy(Army army)
|
|
188 {
|
|
189 List<FailedUnitRequirement> failures = new List<FailedUnitRequirement>();
|
|
190
|
|
191 if (requirements!=null && requirements.Length > 0)
|
|
192 {
|
|
193 foreach (UnitRequirement requirement in requirements)
|
|
194 {
|
|
195 FailedUnitRequirement failure = (FailedUnitRequirement)requirement.CanRemoveFromWarFoundryObject(army);
|
|
196
|
|
197 if (failure!=null)
|
|
198 {
|
|
199 failures.Add(failure);
|
|
200 }
|
|
201 }
|
|
202 }
|
|
203
|
|
204 return failures;
|
|
205 }
|
|
206
|
|
207 public UnitEquipmentItem[] GetEquipmentItemsByExclusionGroup(string group)
|
|
208 {
|
|
209 ArrayList list = (ArrayList)equipmentExclusionGroups[group];
|
|
210
|
|
211 if (list == null)
|
|
212 {
|
|
213 return new UnitEquipmentItem[0];
|
|
214 }
|
|
215 else
|
|
216 {
|
|
217 return (UnitEquipmentItem[])list.ToArray(typeof(UnitEquipmentItem));
|
|
218 }
|
|
219 }
|
|
220 }
|
|
221 }
|