Mercurial > repos > IBDev-IBBoard.WarFoundry.API
annotate api/Objects/Unit.cs @ 98:4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
* Check the type of the existing unit and replace if necessary
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 09 Aug 2009 13:12:38 +0000 |
parents | 95746083d037 |
children | f7b9423c2a5a |
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 | |
82 | 5 using System; |
6 using System.Collections.Generic; | |
7 using System.Text; | |
0 | 8 using System.Xml; |
82 | 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; | |
20 private Unit parentUnit; | |
21 private double points; | |
22 private ArmyCategory cat; | |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
23 private Dictionary<UnitEquipmentItem, AbstractUnitEquipmentItemSelection> equipment = new Dictionary<UnitEquipmentItem, AbstractUnitEquipmentItemSelection>(); |
82 | 24 private List<Unit> containedUnits = new List<Unit>(); |
25 public event DoubleValChangedDelegate PointsValueChanged; | |
26 public event IntValChangedDelegate UnitSizeChanged; | |
85
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
27 public event DoubleValChangedDelegate UnitEquipmentAmountChanged; |
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
28 |
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
29 public Unit(UnitType unitType, ArmyCategory parentArmyCat) : this(unitType, unitType.MinSize, parentArmyCat) { } |
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
30 |
83
89cc29b4c012
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
31 public Unit(UnitType unitType, int startSize, ArmyCategory parentArmyCat) |
85
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
32 { |
83
89cc29b4c012
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
33 Category = parentArmyCat; |
82 | 34 type = unitType; |
35 Size = startSize; | |
36 SetInitialEquipment(); | |
37 CalcCost(); | |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
38 UnitEquipmentAmountChanged+= new DoubleValChangedDelegate(UnitEquipmentAmountChangedHandler); |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
39 UnitSizeChanged+= new IntValChangedDelegate(UnitSizeChangedHandler); |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
40 } |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
41 |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
42 private void UnitEquipmentAmountChangedHandler(WarFoundryObject obj, double oldVal, double newVal) |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
43 { |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
44 CalcCost(); |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
45 } |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
46 |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
47 private void UnitSizeChangedHandler(WarFoundryObject obj, int oldVal, int newVal) |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
48 { |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
49 CalcCost(); |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
50 |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
51 if (HasDefaultName()) |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
52 { |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
53 OnNameChanged("", Name); |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
54 } |
82 | 55 } |
56 | |
57 protected override string DefaultName() | |
58 { | |
59 if (type != null) | |
60 { | |
61 if (size == 1) | |
62 { | |
63 return type.Name; | |
64 } | |
65 else | |
66 { | |
67 return String.Format(Translation.GetTranslation("defaultUnitName"), size, type.Name); | |
68 } | |
69 } | |
70 else | |
71 { | |
72 return "Unknown Unit"; | |
73 } | |
74 } | |
75 | |
76 private void SetInitialEquipment() | |
77 { | |
78 foreach (UnitEquipmentItem unitEquip in UnitType.GetEquipmentItems()) | |
79 { | |
80 if (unitEquip.IsRequired) | |
81 { | |
82 if (CanEquipWithItem(unitEquip)) | |
83 { | |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
84 if (unitEquip.IsRatioLimit) |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
85 { |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
86 equipment[unitEquip] = new UnitEquipmentRatioSelection(this, unitEquip); |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
87 } |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
88 else |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
89 { |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
90 equipment[unitEquip] = new UnitEquipmentNumericSelection(this, unitEquip); |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
91 } |
82 | 92 } |
93 } | |
94 } | |
95 } | |
96 | |
97 private void CalcCost() | |
98 { | |
99 String oldName = HasDefaultName() ? Name : null; | |
100 double oldpoints = points; | |
101 points = type.CostPerTrooper * AdditionalTroopers + type.BaseUnitCost; | |
102 | |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
103 foreach (AbstractUnitEquipmentItemSelection equipSelection in equipment.Values) |
82 | 104 { |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
105 points += equipSelection.TotalCost; |
82 | 106 } |
107 | |
108 if (oldpoints!=points) | |
109 { | |
110 OnPointsValueChanged(oldpoints, points); | |
111 } | |
112 | |
113 if (oldName!=null) | |
114 { | |
115 OnNameChanged(oldName, Name); | |
116 } | |
0 | 117 } |
118 | |
119 public int AdditionalTroopers | |
120 { | |
121 get { return Math.Max(Size - type.BaseSize, 0); } | |
82 | 122 } |
123 | |
124 public int Size | |
125 { | |
126 get { return size; } | |
127 set | |
128 { | |
129 if (value!=size) | |
130 { | |
131 int oldValue = size; | |
132 size = (value>0 ? value : 1); | |
133 OnUnitSizeChanged(oldValue, size); | |
134 } | |
135 } | |
136 } | |
137 | |
138 public UnitType UnitType | |
0 | 139 { |
82 | 140 get { return type; } |
141 } | |
142 | |
143 public Army Army | |
144 { | |
83
89cc29b4c012
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
145 get { return (Category == null ? null : Category.ParentArmy); } |
82 | 146 } |
147 | |
148 public Race Race | |
149 { | |
150 get { return UnitType.Race; } | |
151 } | |
152 | |
153 public ArmyCategory Category | |
85
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
154 { |
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
155 get |
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
156 { |
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
157 return cat; |
82 | 158 } |
159 set { cat = value; } | |
160 } | |
161 | |
162 public double PointsValue | |
163 { | |
164 get | |
165 { | |
166 if (points == 0) | |
167 { | |
168 CalcCost(); | |
169 } | |
170 | |
171 return points; | |
172 } | |
61
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
173 } |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
174 |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
175 public Unit[] ContainedUnits |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
176 { |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
177 get { return containedUnits.ToArray(); } |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
178 } |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
179 |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
180 public void AddContainedUnit(Unit unit) |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
181 { |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
182 if (UnitType.CanContainUnit(unit)) |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
183 { |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
184 if (!containedUnits.Contains(unit)) |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
185 { |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
186 containedUnits.Add(unit); |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
187 } |
65
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
188 |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
189 unit.ParentUnit = this; |
61
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
190 } |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
191 else |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
192 { |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
193 throw new InvalidContainershipException(this, unit); |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
194 } |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
195 } |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
196 |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
197 public void RemoveContainedUnit(Unit unit) |
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 containedUnits.Remove(unit); |
65
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
200 } |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
201 |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
202 public Unit ParentUnit |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
203 { |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
204 get { return parentUnit; } |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
205 set |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
206 { |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
207 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
|
208 { |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
209 parentUnit = value; |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
210 |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
211 if (value!=null) |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
212 { |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
213 value.AddContainedUnit(this); |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
214 } |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
215 } |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
216 } |
82 | 217 } |
218 | |
219 public UnitEquipmentItem[] GetAllowedOptionalEquipment() | |
220 { | |
221 List<UnitEquipmentItem> list = new List<UnitEquipmentItem>(); | |
222 | |
223 foreach (UnitEquipmentItem item in UnitType.GetEquipmentItems()) | |
224 { | |
225 if (!item.IsRequired) | |
226 { | |
227 list.Add(item); | |
228 } | |
229 } | |
230 | |
231 return list.ToArray(); | |
232 } | |
233 | |
234 public UnitEquipmentItem[] GetEquipment() | |
235 { | |
236 return DictionaryUtils.ToKeyArray(equipment); | |
237 } | |
238 | |
239 public EquipmentItem[] GetRequiredEquipment() | |
240 { | |
241 List<EquipmentItem> list = new List<EquipmentItem>(); | |
242 | |
243 foreach(UnitEquipmentItem item in GetEquipment()) | |
244 { | |
245 if (item.IsRequired) | |
246 { | |
247 list.Add(item.EquipmentItem); | |
248 } | |
249 } | |
250 | |
251 return list.ToArray(); | |
252 } | |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
253 |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
254 public double GetEquipmentAmount(UnitEquipmentItem item) |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
255 { |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
256 double amount = 0; |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
257 AbstractUnitEquipmentItemSelection selection = DictionaryUtils.GetValue(equipment, item); |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
258 |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
259 if (selection != null) |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
260 { |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
261 amount = selection.AmountTaken; |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
262 } |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
263 |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
264 return amount; |
82 | 265 } |
266 | |
267 public double GetEquipmentAmount(string equipID) | |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
268 { |
82 | 269 return GetEquipmentAmount(UnitType.GetEquipmentItem(equipID)); |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
270 } |
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 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
|
273 { |
82 | 274 if (amount <1 && amount != WarFoundryCore.INFINITY) |
275 { | |
276 amount = 0; | |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
277 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
278 |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
279 if (amount == 0) |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
280 { |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
281 RemoveEquipmentItem(equip); |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
282 } |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
283 else |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
284 { |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
285 AbstractUnitEquipmentItemSelection currSelection = DictionaryUtils.GetValue(equipment, equip); |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
286 double oldAmount = (currSelection == null ? 0 : currSelection.AmountTaken); |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
287 |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
288 if (amount != oldAmount) |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
289 { |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
290 if (oldAmount == 0) |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
291 { |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
292 AddEquipmentAmount(equip, amount); |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
293 } |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
294 else if (currSelection is UnitEquipmentNumericSelection) |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
295 { |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
296 //A UnitEquipmentItem shouldn't change its IsRatio value, so assume we already have the right sub-type |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
297 currSelection.AmountTaken = amount; |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
298 } |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
299 else |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
300 { |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
301 equipment.Remove(equip); |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
302 AddEquipmentAmount(equip, amount); |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
303 } |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
304 |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
305 OnUnitEquipmentAmountChanged(equip, oldAmount, amount); |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
306 } |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
307 } |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
308 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
309 |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
310 private void AddEquipmentAmount(UnitEquipmentItem equip, int amount) |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
311 { |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
312 AbstractUnitEquipmentItemSelection newItem = null; |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
313 |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
314 if (equip.IsRatioLimit) |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
315 { |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
316 newItem = new UnitEquipmentNumericForRatioSelection(this, equip, amount); |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
317 } |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
318 else |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
319 { |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
320 newItem = new UnitEquipmentNumericSelection(this, equip, amount); |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
321 } |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
322 |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
323 equipment[equip] = newItem; |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
324 } |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
325 |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
326 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
|
327 { |
80
aa66dd18cdae
Closes #81 - Resolve Unit Equipment problems in WinForms GUI
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
328 if (!equip.IsRatioLimit) |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
329 { |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
330 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
|
331 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
332 |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
333 if (ratio > 1) |
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 ratio = 1; |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
336 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
337 else if (ratio < 0) |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
338 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
339 ratio = 0; |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
340 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
341 |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
342 if (ratio == 0) |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
343 { |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
344 RemoveEquipmentItem(equip); |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
345 } |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
346 else |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
347 { |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
348 AbstractUnitEquipmentItemSelection currSelection = DictionaryUtils.GetValue(equipment, equip); |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
349 double oldRatio = (currSelection == null ? 0 : currSelection.AmountTaken); |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
350 |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
351 if (ratio != oldRatio) |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
352 { |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
353 if (oldRatio == 0) |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
354 { |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
355 AddEquipmentRatio(equip, ratio); |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
356 } |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
357 else if (currSelection is UnitEquipmentRatioSelection) |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
358 { |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
359 currSelection.AmountTaken = ratio; |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
360 } |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
361 else |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
362 { |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
363 equipment.Remove(equip); |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
364 AddEquipmentRatio(equip, ratio); |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
365 } |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
366 |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
367 OnUnitEquipmentAmountChanged(equip, oldRatio, ratio); |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
368 } |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
369 } |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
370 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
371 |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
372 private void AddEquipmentRatio(UnitEquipmentItem equip, double ratio) |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
373 { |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
374 equipment[equip] = new UnitEquipmentRatioSelection(this, equip, ratio); |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
375 } |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
376 |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
377 private void RemoveEquipmentItem(UnitEquipmentItem equip) |
82 | 378 { |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
379 double oldAmount = GetEquipmentAmount(equip); |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
380 |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
381 if (oldAmount != 0) |
82 | 382 { |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
383 equipment.Remove(equip); |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
384 OnUnitEquipmentAmountChanged(equip, oldAmount, 0); |
82 | 385 } |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
386 } |
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 public bool CanEquipWithItem(UnitEquipmentItem item) |
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 string mutex = item.MutexGroup; |
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 if (mutex == "") |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
393 { |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
394 return true; |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
395 } |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
396 |
80
aa66dd18cdae
Closes #81 - Resolve Unit Equipment problems in WinForms GUI
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
397 foreach (UnitEquipmentItem unitItem in GetEquipment()) |
64
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 if (unitItem.MutexGroup == mutex) |
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 false; |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
402 } |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
403 } |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
404 |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
405 return true; |
82 | 406 } |
407 | |
408 public bool CanEquipWithItem(string equipID) | |
409 { | |
410 return CanEquipWithItem(UnitType.GetEquipmentItem(equipID)); | |
411 } | |
412 | |
413 private void OnPointsValueChanged(double oldValue, double newValue) | |
414 { | |
415 if (PointsValueChanged!=null) | |
416 { | |
417 PointsValueChanged(this, oldValue, newValue); | |
418 } | |
419 } | |
420 | |
421 private void OnUnitSizeChanged(int oldValue, int newValue) | |
422 { | |
423 if (UnitSizeChanged!=null) | |
424 { | |
425 UnitSizeChanged(this, oldValue, newValue); | |
426 } | |
427 } | |
428 | |
429 private void OnUnitEquipmentAmountChanged(UnitEquipmentItem equip, double oldValue, double newValue) | |
430 { | |
431 if (UnitEquipmentAmountChanged!=null) | |
432 { | |
433 UnitEquipmentAmountChanged(equip, oldValue, newValue); | |
434 } | |
435 } | |
436 | |
437 public Stat[] UnitStatsArray | |
438 { | |
439 get { return UnitType.UnitStatsArray; } | |
81
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
440 } |
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
441 |
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
442 public Stat[] UnitStatsArrayWithName |
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
443 { |
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
444 get { return UnitType.UnitStatsArrayWithName; } |
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
445 } |
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
446 |
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
447 public string GetStatValue(string statName) |
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
448 { |
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
449 return UnitType.GetStatValue(statName); |
82 | 450 } |
451 } | |
452 } |