Mercurial > repos > snowblizz-super-API-ideas
annotate api/Objects/Unit.cs @ 65:aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
* Add parent links to Units (inverse of r97)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Thu, 09 Apr 2009 18:27:51 +0000 |
parents | 2094bd0ba652 |
children | aa66dd18cdae |
rev | line source |
---|---|
15 | 1 // This file (Unit.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard. |
2 // | |
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. | |
4 | |
0 | 5 using System; |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
6 using System.Collections.Generic; |
0 | 7 using System.Text; |
8 using System.Xml; | |
9 using IBBoard.Lang; | |
10 | |
11 namespace IBBoard.WarFoundry.API.Objects | |
12 { | |
13 /// <summary> | |
14 /// Summary description for UnitInstance. | |
15 /// </summary> | |
16 public class Unit : WarFoundryObject | |
17 { | |
18 private UnitType type; | |
19 private int size; | |
65
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
20 private Army army; |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
21 private Unit parentUnit; |
0 | 22 private double points; |
23 private ArmyCategory cat; | |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
24 private Dictionary<EquipmentItem, double> equipment = new Dictionary<EquipmentItem, double>(); |
61
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
25 private List<Unit> containedUnits = new List<Unit>(); |
0 | 26 public event DoubleValChangedDelegate PointsValueChanged; |
27 public event IntValChangedDelegate UnitSizeChanged; | |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
28 public event DoubleValChangedDelegate UnitEquipmentAmountChanged; |
0 | 29 |
30 public Unit(UnitType unitType, Army parentArmy) : this(unitType, unitType.MinSize, parentArmy){} | |
31 | |
32 public Unit(UnitType unitType, int startSize, Army parentArmy) | |
33 { | |
34 Army = parentArmy; | |
35 type = unitType; | |
36 Size = startSize; | |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
37 SetInitialEquipment(); |
0 | 38 CalcCost(); |
39 } | |
40 | |
41 protected override string DefaultName() | |
42 { | |
43 if (type != null) | |
44 { | |
45 if (size == 1) | |
46 { | |
47 return type.Name; | |
48 } | |
49 else | |
50 { | |
51 return String.Format(Translation.GetTranslation("defaultUnitName"), size, type.Name); | |
52 } | |
53 } | |
54 else | |
55 { | |
56 return "Unknown Unit"; | |
57 } | |
58 } | |
59 | |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
60 private void SetInitialEquipment() |
0 | 61 { |
62 foreach (UnitEquipmentItem unitEquip in UnitType.GetEquipmentItems()) | |
63 { | |
64 if (unitEquip.IsRequired) | |
65 { | |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
66 if (CanEquipWithItem(unitEquip)) |
0 | 67 { |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
68 equipment[unitEquip.EquipmentItem] = unitEquip.MinNumber; |
0 | 69 } |
70 } | |
71 } | |
72 } | |
73 | |
74 private void CalcCost() | |
75 { | |
76 String oldName = HasDefaultName() ? Name : null; | |
77 double oldpoints = points; | |
78 points = type.CostPerTrooper * AdditionalTroopers + type.BaseUnitCost; | |
79 | |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
80 foreach (EquipmentItem equipItem in equipment.Keys) |
0 | 81 { |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
82 double count = equipment[equipItem]; |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
83 UnitEquipmentItem unitEquipItem = UnitType.GetEquipmentItem(equipItem); |
0 | 84 |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
85 if (unitEquipItem.IsRatioLimit) |
0 | 86 { |
87 if (unitEquipItem.RoundNumberUp) | |
88 { | |
89 points+= Math.Ceiling(size * count) * equipItem.Cost; | |
90 } | |
91 else | |
92 { | |
93 points+= Math.Floor(size * count) * equipItem.Cost; | |
94 } | |
95 } | |
96 else | |
97 { | |
38
548cfc776f54
Fixes #34 - Remove "Choices" and "Base/Increment" from Category
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
98 if (count == WarFoundryCore.INFINITY) |
0 | 99 { |
100 points+= size * equipItem.Cost; | |
101 } | |
102 else | |
103 { | |
104 points+= count * equipItem.Cost; | |
105 } | |
106 } | |
107 } | |
108 | |
109 if (oldpoints!=points) | |
110 { | |
111 OnPointsValueChanged(oldpoints, points); | |
112 } | |
113 | |
114 if (oldName!=null) | |
115 { | |
116 OnNameChanged(oldName, Name); | |
117 } | |
118 } | |
119 | |
120 public int AdditionalTroopers | |
121 { | |
122 get { return Math.Max(Size - type.BaseSize, 0); } | |
123 } | |
124 | |
125 public int Size | |
126 { | |
127 get { return size; } | |
128 set | |
129 { | |
130 if (value!=size) | |
131 { | |
132 int oldValue = size; | |
133 size = (value>0 ? value : 1); | |
134 CalcCost(); | |
135 OnUnitSizeChanged(oldValue, size); | |
136 } | |
137 } | |
138 } | |
139 | |
140 public UnitType UnitType | |
141 { | |
142 get { return type; } | |
143 } | |
144 | |
145 public Army Army | |
146 { | |
147 get { return army; } | |
148 set | |
149 { | |
150 army = value; | |
151 | |
152 if (army == null) | |
153 { | |
154 Category = null; | |
155 } | |
156 } | |
157 } | |
158 | |
159 public Race Race | |
160 { | |
65
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
161 get { return UnitType.Race; } |
0 | 162 } |
163 | |
164 public ArmyCategory Category | |
165 { | |
166 get | |
167 { | |
168 if (cat==null) | |
169 { | |
170 if (Army!=null) | |
171 { | |
172 return Army.GetCategory(UnitType.MainCategory); | |
173 } | |
174 else | |
175 { | |
176 return null; | |
177 } | |
178 } | |
179 else | |
180 { | |
181 return cat; | |
182 } | |
183 } | |
184 set { cat = value; } | |
185 } | |
186 | |
187 public double PointsValue | |
188 { | |
189 get | |
190 { | |
191 if (points == 0) | |
192 { | |
193 CalcCost(); | |
194 } | |
195 | |
196 return points; | |
197 } | |
61
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
198 } |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
199 |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
200 public Unit[] ContainedUnits |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
201 { |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
202 get { return containedUnits.ToArray(); } |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
203 } |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
204 |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
205 public void AddContainedUnit(Unit unit) |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
206 { |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
207 if (UnitType.CanContainUnit(unit)) |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
208 { |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
209 if (!containedUnits.Contains(unit)) |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
210 { |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
211 containedUnits.Add(unit); |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
212 } |
65
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
213 |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
214 unit.ParentUnit = this; |
61
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
215 } |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
216 else |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
217 { |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
218 throw new InvalidContainershipException(this, unit); |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
219 } |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
220 } |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
221 |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
222 public void RemoveContainedUnit(Unit unit) |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
223 { |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
224 containedUnits.Remove(unit); |
65
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
225 } |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
226 |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
227 public Unit ParentUnit |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
228 { |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
229 get { return parentUnit; } |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
230 set |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
231 { |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
232 if (!(parentUnit == value || (parentUnit != null && parentUnit.Equals(value)))) |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
233 { |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
234 parentUnit = value; |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
235 |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
236 if (value!=null) |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
237 { |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
238 value.AddContainedUnit(this); |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
239 } |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
240 } |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
241 } |
0 | 242 } |
243 | |
244 public UnitEquipmentItem[] GetAllowedOptionalEquipment() | |
245 { | |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
246 List<UnitEquipmentItem> list = new List<UnitEquipmentItem>(); |
0 | 247 |
248 foreach (UnitEquipmentItem item in UnitType.GetEquipmentItems()) | |
249 { | |
250 if (!item.IsRequired) | |
251 { | |
252 list.Add(item); | |
253 } | |
254 } | |
255 | |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
256 return list.ToArray(); |
0 | 257 } |
258 | |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
259 public EquipmentItem[] GetEquipment() |
0 | 260 { |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
261 return DictionaryUtils.ToKeyArray(equipment); |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
262 } |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
263 |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
264 private UnitEquipmentItem[] GetUnitEquipmentItemsForEquipment() |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
265 { |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
266 EquipmentItem[] items = GetEquipment(); |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
267 int arrLength = items.Length; |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
268 UnitEquipmentItem[] unitItems = new UnitEquipmentItem[arrLength]; |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
269 |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
270 for (int i = 0; i < arrLength; i++) |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
271 { |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
272 UnitType.GetEquipmentItem(items[i]); |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
273 } |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
274 |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
275 return unitItems; |
0 | 276 } |
277 | |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
278 public EquipmentItem[] GetRequiredEquipment() |
0 | 279 { |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
280 List<EquipmentItem> list = new List<EquipmentItem>(); |
0 | 281 |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
282 foreach(UnitEquipmentItem item in GetUnitEquipmentItemsForEquipment()) |
0 | 283 { |
284 if (item.IsRequired) | |
285 { | |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
286 list.Add(item.EquipmentItem); |
0 | 287 } |
288 } | |
289 | |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
290 return list.ToArray(); |
0 | 291 } |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
292 |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
293 public double GetEquipmentAmount(UnitEquipmentItem item) |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
294 { |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
295 return GetEquipmentAmount(item.EquipmentItem); |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
296 } |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
297 |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
298 public double GetEquipmentAmount(EquipmentItem item) |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
299 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
300 if (equipment.ContainsKey(item)) |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
301 { |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
302 return equipment[item]; |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
303 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
304 else |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
305 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
306 return 0; |
0 | 307 } |
308 } | |
309 | |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
310 public double GetEquipmentAmount(string equipID) |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
311 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
312 return GetEquipmentAmount(UnitType.GetEquipmentItem(equipID)); |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
313 } |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
314 |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
315 public void SetEquipmentAmount(UnitEquipmentItem equip, int amount) |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
316 { |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
317 SetEquipmentAmount(equip.EquipmentItem, amount); |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
318 } |
0 | 319 |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
320 public void SetEquipmentAmount(EquipmentItem equip, int amount) |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
321 { |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
322 if (UnitType.IsRatioLimitedEquipmentItem(equip)) |
0 | 323 { |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
324 throw new InvalidOperationException("Equipment with ID "+equip.ID+" for unit of type "+UnitType.ID+" has a ratio limit, not an absolute limit"); |
0 | 325 } |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
326 |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
327 if (amount <1 && amount != WarFoundryCore.INFINITY) |
0 | 328 { |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
329 amount = 0; |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
330 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
331 |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
332 SetEquipmentAmount(equip, amount); |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
333 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
334 |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
335 public void SetEquipmentRatio(UnitEquipmentItem equip, double ratio) |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
336 { |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
337 SetEquipmentRatio(equip.EquipmentItem, ratio); |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
338 } |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
339 |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
340 public void SetEquipmentRatio(EquipmentItem equip, double ratio) |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
341 { |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
342 if (UnitType.IsAbsoluteLimitedEquipmentItem(equip)) |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
343 { |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
344 throw new InvalidOperationException("Equipment with ID "+equip.ID+" for unit of type "+UnitType.ID+" has an absolute limit, not a ratio limit"); |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
345 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
346 |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
347 if (ratio > 1) |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
348 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
349 ratio = 1; |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
350 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
351 else if (ratio < 0) |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
352 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
353 ratio = 0; |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
354 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
355 |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
356 SetEquipmentAmount(equip, ratio); |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
357 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
358 |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
359 private void SetEquipmentAmount(EquipmentItem equip, double amount) |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
360 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
361 double oldAmount = 0; |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
362 |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
363 if (equipment.ContainsKey(equip)) |
0 | 364 { |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
365 oldAmount = equipment[equip]; |
0 | 366 } |
367 | |
368 if (amount!=oldAmount) | |
369 { | |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
370 if (amount != 0) |
0 | 371 { |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
372 equipment[equip] = amount; |
0 | 373 } |
374 else | |
375 { | |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
376 equipment.Remove(equip); |
0 | 377 } |
378 | |
379 OnUnitEquipmentAmountChanged(equip, oldAmount, amount); | |
380 CalcCost(); | |
381 } | |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
382 } |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
383 |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
384 public bool CanEquipWithItem(UnitEquipmentItem item) |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
385 { |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
386 string mutex = item.MutexGroup; |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
387 |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
388 if (mutex == "") |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
389 { |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
390 return true; |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
391 } |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
392 |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
393 foreach (UnitEquipmentItem unitItem in GetUnitEquipmentItemsForEquipment()) |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
394 { |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
395 if (unitItem.MutexGroup == mutex) |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
396 { |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
397 return false; |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
398 } |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
399 } |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
400 |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
401 return true; |
0 | 402 } |
403 | |
404 public bool CanEquipWithItem(string equipID) | |
405 { | |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
406 return CanEquipWithItem(UnitType.GetEquipmentItem(equipID)); |
0 | 407 } |
408 | |
409 private void OnPointsValueChanged(double oldValue, double newValue) | |
410 { | |
411 if (PointsValueChanged!=null) | |
412 { | |
413 PointsValueChanged(this, oldValue, newValue); | |
414 } | |
415 } | |
416 | |
417 private void OnUnitSizeChanged(int oldValue, int newValue) | |
418 { | |
419 if (UnitSizeChanged!=null) | |
420 { | |
421 UnitSizeChanged(this, oldValue, newValue); | |
422 } | |
423 } | |
424 | |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
425 private void OnUnitEquipmentAmountChanged(EquipmentItem equip, double oldValue, double newValue) |
0 | 426 { |
427 if (UnitEquipmentAmountChanged!=null) | |
428 { | |
429 UnitEquipmentAmountChanged(equip, oldValue, newValue); | |
430 } | |
431 } | |
432 | |
433 public Stats UnitStats | |
434 { | |
435 get { return UnitType.UnitStats; } | |
436 } | |
437 } | |
438 } |