Mercurial > repos > IBBoard.WarFoundry.API
annotate api/Objects/Unit.cs @ 279:51b3027a7dae
Re #295: Index out of bounds when changing unit size and clicking in equipment list
* Trigger 'fake' equipment amount changed events when the unit size changes for all ratio equipment - ratio won't have changed, but absolute number will
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 14 Jul 2010 20:01:14 +0000 |
parents | 6fe0cb1bf74f |
children | 5c4b3d91795f |
rev | line source |
---|---|
104
2f3cafb69799
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
101
diff
changeset
|
1 // This file (Unit.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 2007, 2008, IBBoard. |
15 | 2 // |
104
2f3cafb69799
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
101
diff
changeset
|
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. |
15 | 4 |
82 | 5 using System; |
6 using System.Collections.Generic; | |
7 using System.Text; | |
0 | 8 using System.Xml; |
164 | 9 using IBBoard.Lang; |
183
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
180
diff
changeset
|
10 using IBBoard.Limits; |
161
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
11 using IBBoard.WarFoundry.API.Util; |
82 | 12 |
13 namespace IBBoard.WarFoundry.API.Objects | |
14 { | |
15 /// <summary> | |
16 /// Summary description for UnitInstance. | |
17 /// </summary> | |
143
7f13ffcb8765
Re #164: Show unit cost in army tree
IBBoard <dev@ibboard.co.uk>
parents:
134
diff
changeset
|
18 public class Unit : WarFoundryObject, ICostedWarFoundryObject |
82 | 19 { |
20 private UnitType type; | |
21 private int size; | |
22 private Unit parentUnit; | |
23 private double points; | |
24 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
|
25 private Dictionary<UnitEquipmentItem, AbstractUnitEquipmentItemSelection> equipment = new Dictionary<UnitEquipmentItem, AbstractUnitEquipmentItemSelection>(); |
178
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
26 private Dictionary<string, List<AbstractUnitEquipmentItemSelection>> equipmentSlots = new Dictionary<string, List<AbstractUnitEquipmentItemSelection>>(); |
82 | 27 private List<Unit> containedUnits = new List<Unit>(); |
28 public event DoubleValChangedDelegate PointsValueChanged; | |
29 public event IntValChangedDelegate UnitSizeChanged; | |
85
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
30 public event DoubleValChangedDelegate UnitEquipmentAmountChanged; |
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
31 |
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
32 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
|
33 |
123
52e8c3cdde10
Re #127: Unit creation always assigns default equipment
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
34 public Unit(UnitType unitType, int startSize, ArmyCategory parentArmyCat) : this("", "", startSize, unitType, parentArmyCat) |
52e8c3cdde10
Re #127: Unit creation always assigns default equipment
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
35 { |
279
51b3027a7dae
Re #295: Index out of bounds when changing unit size and clicking in equipment list
IBBoard <dev@ibboard.co.uk>
parents:
265
diff
changeset
|
36 SetInitialEquipment(); |
51b3027a7dae
Re #295: Index out of bounds when changing unit size and clicking in equipment list
IBBoard <dev@ibboard.co.uk>
parents:
265
diff
changeset
|
37 UnitSizeChanged += new IntValChangedDelegate(RefreshUnitEquipmentAmounts); |
51b3027a7dae
Re #295: Index out of bounds when changing unit size and clicking in equipment list
IBBoard <dev@ibboard.co.uk>
parents:
265
diff
changeset
|
38 } |
123
52e8c3cdde10
Re #127: Unit creation always assigns default equipment
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
39 |
52e8c3cdde10
Re #127: Unit creation always assigns default equipment
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
40 public Unit(string id, string name, int startSize, UnitType unitType, ArmyCategory parentArmyCat) : base(id, name) |
85
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
41 { |
83
89cc29b4c012
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
42 Category = parentArmyCat; |
82 | 43 type = unitType; |
44 Size = startSize; | |
45 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
|
46 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
|
47 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
|
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 |
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 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
|
51 { |
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 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
|
53 } |
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 |
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
|
55 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
|
56 { |
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
|
57 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
|
58 |
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
|
59 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
|
60 { |
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
|
61 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
|
62 } |
82 | 63 } |
64 | |
65 protected override string DefaultName() | |
66 { | |
67 if (type != null) | |
68 { | |
69 if (size == 1) | |
70 { | |
71 return type.Name; | |
72 } | |
73 else | |
74 { | |
75 return String.Format(Translation.GetTranslation("defaultUnitName"), size, type.Name); | |
76 } | |
77 } | |
78 else | |
79 { | |
80 return "Unknown Unit"; | |
81 } | |
82 } | |
83 | |
84 private void SetInitialEquipment() | |
85 { | |
86 foreach (UnitEquipmentItem unitEquip in UnitType.GetEquipmentItems()) | |
87 { | |
88 if (unitEquip.IsRequired) | |
89 { | |
90 if (CanEquipWithItem(unitEquip)) | |
91 { | |
265
6fe0cb1bf74f
Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
254
diff
changeset
|
92 ILimit minLimit = unitEquip.MinLimit; |
183
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
180
diff
changeset
|
93 |
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
180
diff
changeset
|
94 if (minLimit is IPercentageLimit) |
151
1d13820b3d96
Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents:
149
diff
changeset
|
95 { |
204
3ef067225dc3
Fixes #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
201
diff
changeset
|
96 SetEquipmentRatio(unitEquip, UnitEquipmentUtil.GetMinEquipmentPercentage(this, unitEquip)); |
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
|
97 } |
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
|
98 else |
151
1d13820b3d96
Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents:
149
diff
changeset
|
99 { |
204
3ef067225dc3
Fixes #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
201
diff
changeset
|
100 SetEquipmentAmount(unitEquip, UnitEquipmentUtil.GetMinEquipmentCount(this, unitEquip)); |
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
|
101 } |
82 | 102 } |
103 } | |
104 } | |
105 } | |
106 | |
107 private void CalcCost() | |
108 { | |
109 double oldpoints = points; | |
110 points = type.CostPerTrooper * AdditionalTroopers + type.BaseUnitCost; | |
111 | |
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
|
112 foreach (AbstractUnitEquipmentItemSelection equipSelection in equipment.Values) |
82 | 113 { |
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
|
114 points += equipSelection.TotalCost; |
82 | 115 } |
116 | |
117 if (oldpoints!=points) | |
118 { | |
119 OnPointsValueChanged(oldpoints, points); | |
120 } | |
0 | 121 } |
122 | |
123 public int AdditionalTroopers | |
124 { | |
125 get { return Math.Max(Size - type.BaseSize, 0); } | |
82 | 126 } |
127 | |
128 public int Size | |
129 { | |
130 get { return size; } | |
131 set | |
132 { | |
133 if (value!=size) | |
134 { | |
135 int oldValue = size; | |
136 size = (value>0 ? value : 1); | |
137 OnUnitSizeChanged(oldValue, size); | |
138 } | |
139 } | |
140 } | |
141 | |
142 public UnitType UnitType | |
0 | 143 { |
82 | 144 get { return type; } |
145 } | |
146 | |
147 public Army Army | |
148 { | |
83
89cc29b4c012
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
149 get { return (Category == null ? null : Category.ParentArmy); } |
82 | 150 } |
151 | |
152 public Race Race | |
153 { | |
154 get { return UnitType.Race; } | |
155 } | |
156 | |
157 public ArmyCategory Category | |
85
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
158 { |
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
159 get |
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
160 { |
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
161 return cat; |
82 | 162 } |
163 set { cat = value; } | |
164 } | |
165 | |
143
7f13ffcb8765
Re #164: Show unit cost in army tree
IBBoard <dev@ibboard.co.uk>
parents:
134
diff
changeset
|
166 [Obsolete("Use Points instead")] |
82 | 167 public double PointsValue |
168 { | |
143
7f13ffcb8765
Re #164: Show unit cost in army tree
IBBoard <dev@ibboard.co.uk>
parents:
134
diff
changeset
|
169 get { return Points; } |
7f13ffcb8765
Re #164: Show unit cost in army tree
IBBoard <dev@ibboard.co.uk>
parents:
134
diff
changeset
|
170 } |
7f13ffcb8765
Re #164: Show unit cost in army tree
IBBoard <dev@ibboard.co.uk>
parents:
134
diff
changeset
|
171 |
7f13ffcb8765
Re #164: Show unit cost in army tree
IBBoard <dev@ibboard.co.uk>
parents:
134
diff
changeset
|
172 public double Points |
7f13ffcb8765
Re #164: Show unit cost in army tree
IBBoard <dev@ibboard.co.uk>
parents:
134
diff
changeset
|
173 { |
82 | 174 get |
175 { | |
176 if (points == 0) | |
177 { | |
178 CalcCost(); | |
179 } | |
180 | |
181 return points; | |
182 } | |
61
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 |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
185 public Unit[] ContainedUnits |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
186 { |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
187 get { return containedUnits.ToArray(); } |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
188 } |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
189 |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
190 public void AddContainedUnit(Unit unit) |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
191 { |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
192 if (UnitType.CanContainUnit(unit)) |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
193 { |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
194 if (!containedUnits.Contains(unit)) |
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 containedUnits.Add(unit); |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
197 } |
65
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
198 |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
199 unit.ParentUnit = this; |
61
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
200 } |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
201 else |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
202 { |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
203 throw new InvalidContainershipException(this, unit); |
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 } |
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 public void RemoveContainedUnit(Unit 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 containedUnits.Remove(unit); |
65
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 |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
212 public Unit ParentUnit |
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 get { return parentUnit; } |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
215 set |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
216 { |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
217 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
|
218 { |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
219 parentUnit = value; |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
220 |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
221 if (value!=null) |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
222 { |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
223 value.AddContainedUnit(this); |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
224 } |
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 } |
82 | 227 } |
228 | |
161
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
229 [Obsolete("Use UnitEquipmentUtil.GetAllowedEquipmentItems(Unit) instead")] |
158
eb9a6d91a6db
Fixes #190: Mutex groups aren't honoured when adding equipment
IBBoard <dev@ibboard.co.uk>
parents:
154
diff
changeset
|
230 public UnitEquipmentItem[] GetAllowedAdditionalEquipment() |
164 | 231 { |
161
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
232 return UnitEquipmentUtil.GetAllowedEquipmentItems(this); |
82 | 233 } |
234 | |
235 public UnitEquipmentItem[] GetEquipment() | |
236 { | |
237 return DictionaryUtils.ToKeyArray(equipment); | |
238 } | |
239 | |
240 public EquipmentItem[] GetRequiredEquipment() | |
241 { | |
242 List<EquipmentItem> list = new List<EquipmentItem>(); | |
243 | |
244 foreach(UnitEquipmentItem item in GetEquipment()) | |
245 { | |
246 if (item.IsRequired) | |
247 { | |
248 list.Add(item.EquipmentItem); | |
249 } | |
250 } | |
251 | |
213 | 252 return list.ToArray(); |
253 } | |
254 | |
255 internal AbstractUnitEquipmentItemSelection GetEquipmentSelection(UnitEquipmentItem item) | |
256 { | |
257 return DictionaryUtils.GetValue(equipment, item); | |
82 | 258 } |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
259 |
212
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
208
diff
changeset
|
260 [Obsolete("Use UnitEquipmentUtil method instead")] |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
261 public double GetEquipmentAmount(UnitEquipmentItem item) |
213 | 262 { |
212
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
208
diff
changeset
|
263 return UnitEquipmentUtil.GetEquipmentAmount(this, item); |
213 | 264 } |
265 | |
212
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
208
diff
changeset
|
266 [Obsolete("Use UnitEquipmentUtil method instead")] |
82 | 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)); |
213 | 270 } |
271 | |
212
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
208
diff
changeset
|
272 [Obsolete("Use UnitEquipmentUtil method instead")] |
101
f7b9423c2a5a
Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
98
diff
changeset
|
273 public bool GetEquipmentAmountIsRatio(UnitEquipmentItem item) |
213 | 274 { |
212
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
208
diff
changeset
|
275 return UnitEquipmentUtil.GetEquipmentAmountIsRatio(this, item); |
213 | 276 } |
277 | |
212
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
208
diff
changeset
|
278 [Obsolete("Use UnitEquipmentUtil method instead")] |
101
f7b9423c2a5a
Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
98
diff
changeset
|
279 public bool GetEquipmentAmountIsRatio(string itemID) |
f7b9423c2a5a
Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
98
diff
changeset
|
280 { |
f7b9423c2a5a
Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
98
diff
changeset
|
281 return GetEquipmentAmountIsRatio(UnitType.GetEquipmentItem(itemID)); |
f7b9423c2a5a
Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
98
diff
changeset
|
282 } |
134
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
283 |
212
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
208
diff
changeset
|
284 [Obsolete("Implementation is down to the UI")] |
134
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
285 public string GetEquipmentAmountString(string equipID) |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
286 { |
212
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
208
diff
changeset
|
287 return ""; |
213 | 288 } |
289 | |
212
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
208
diff
changeset
|
290 [Obsolete("Implementation is down to the UI")] |
134
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
291 public string GetEquipmentAmountString(UnitEquipmentItem item) |
213 | 292 { |
212
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
208
diff
changeset
|
293 return ""; |
134
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
294 } |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
295 |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
296 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
|
297 { |
82 | 298 if (amount <1 && amount != WarFoundryCore.INFINITY) |
299 { | |
300 amount = 0; | |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
301 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
302 |
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 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
|
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 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
|
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 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
|
308 { |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
309 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
|
310 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
|
311 |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
312 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
|
313 { |
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
|
314 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
|
315 { |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
316 AddEquipmentAmount(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 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
|
319 { |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
320 //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
|
321 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
|
322 } |
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
|
323 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
|
324 { |
206
0ca96143aa03
Re #211: Swapping from percentage to numeric selection doesn't remove old selection
IBBoard <dev@ibboard.co.uk>
parents:
205
diff
changeset
|
325 RemoveEquipmentItem(equip); |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
326 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
|
327 } |
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
|
328 |
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
|
329 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
|
330 } |
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
|
331 } |
54
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 |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
334 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
|
335 { |
183
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
180
diff
changeset
|
336 AbstractUnitEquipmentItemSelection newItem = new UnitEquipmentNumericSelection(this, equip, amount); |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
337 equipment[equip] = newItem; |
178
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
338 List<AbstractUnitEquipmentItemSelection> selections = DictionaryUtils.GetValue(equipmentSlots, equip.SlotName); |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
339 |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
340 if (selections == null) |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
341 { |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
342 selections = new List<AbstractUnitEquipmentItemSelection>(); |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
343 equipmentSlots[equip.SlotName] = selections; |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
344 } |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
345 |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
346 selections.Add(newItem); |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
347 } |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
348 |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
349 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
|
350 { |
80
aa66dd18cdae
Closes #81 - Resolve Unit Equipment problems in WinForms GUI
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
351 if (!equip.IsRatioLimit) |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
352 { |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
353 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
|
354 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
355 |
101
f7b9423c2a5a
Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
98
diff
changeset
|
356 if (ratio > 100) |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
357 { |
101
f7b9423c2a5a
Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
98
diff
changeset
|
358 ratio = 100; |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
359 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
360 else if (ratio < 0) |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
361 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
362 ratio = 0; |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
363 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
364 |
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 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
|
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 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
|
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 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
|
370 { |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
371 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
|
372 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
|
373 |
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
|
374 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
|
375 { |
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
|
376 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
|
377 { |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
378 AddEquipmentRatio(equip, ratio); |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
379 } |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
380 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
|
381 { |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
382 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
|
383 } |
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 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
|
385 { |
206
0ca96143aa03
Re #211: Swapping from percentage to numeric selection doesn't remove old selection
IBBoard <dev@ibboard.co.uk>
parents:
205
diff
changeset
|
386 RemoveEquipmentItem(equip); |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
387 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
|
388 } |
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
|
389 |
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
|
390 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
|
391 } |
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
|
392 } |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
393 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
394 |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
395 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
|
396 { |
178
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
397 UnitEquipmentRatioSelection newItem = new UnitEquipmentRatioSelection (this, equip, ratio); |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
398 equipment[equip] = newItem; |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
399 List<AbstractUnitEquipmentItemSelection> selections = DictionaryUtils.GetValue(equipmentSlots, equip.SlotName); |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
400 |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
401 if (selections == null) |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
402 { |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
403 selections = new List<AbstractUnitEquipmentItemSelection>(); |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
404 equipmentSlots[equip.SlotName] = selections; |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
405 } |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
406 |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
407 selections.Add(newItem); |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
408 } |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
409 |
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
|
410 private void RemoveEquipmentItem(UnitEquipmentItem equip) |
216 | 411 { |
214
1b718b67f7f6
Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents:
213
diff
changeset
|
412 double oldAmount = UnitEquipmentUtil.GetEquipmentAmount(this, equip); |
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
|
413 |
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
|
414 if (oldAmount != 0) |
82 | 415 { |
178
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
416 AbstractUnitEquipmentItemSelection selection = DictionaryUtils.GetValue (equipment, equip); |
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
|
417 equipment.Remove(equip); |
178
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
418 List<AbstractUnitEquipmentItemSelection> slotSelections = DictionaryUtils.GetValue (equipmentSlots, equip.SlotName); |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
419 slotSelections.Remove(selection); |
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
|
420 OnUnitEquipmentAmountChanged(equip, oldAmount, 0); |
82 | 421 } |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
422 } |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
423 |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
424 public bool CanEquipWithItem(UnitEquipmentItem item) |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
425 { |
154
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
426 string[] mutexes = item.MutexGroups; |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
427 bool canEquip = false; |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
428 |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
429 if (mutexes.Length == 0) |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
430 { |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
431 canEquip = true; |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
432 } |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
433 else |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
434 { |
162
624422e91a1c
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
161
diff
changeset
|
435 canEquip = UnitEquipmentUtil.GetBlockingEquipmentItems(this, item).Count == 0; |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
436 } |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
437 |
152
0c0e14f03785
Re #180: Add multiple mutex groups
IBBoard <dev@ibboard.co.uk>
parents:
151
diff
changeset
|
438 return canEquip; |
154
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
439 } |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
440 |
161
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
441 [Obsolete("Use UnitEquipmentUtil.GetBlockingEquipmentItems(Unit, UnitEquipmentItem) instead")] |
154
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
442 public List<UnitEquipmentItem> GetBlockingEquipmentItems(UnitEquipmentItem item) |
164 | 443 { |
161
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
444 return UnitEquipmentUtil.GetBlockingEquipmentItems(this, item); |
82 | 445 } |
446 | |
447 public bool CanEquipWithItem(string equipID) | |
448 { | |
449 return CanEquipWithItem(UnitType.GetEquipmentItem(equipID)); | |
450 } | |
451 | |
452 private void OnPointsValueChanged(double oldValue, double newValue) | |
453 { | |
454 if (PointsValueChanged!=null) | |
455 { | |
456 PointsValueChanged(this, oldValue, newValue); | |
457 } | |
458 } | |
459 | |
460 private void OnUnitSizeChanged(int oldValue, int newValue) | |
461 { | |
462 if (UnitSizeChanged!=null) | |
463 { | |
464 UnitSizeChanged(this, oldValue, newValue); | |
465 } | |
466 } | |
467 | |
468 private void OnUnitEquipmentAmountChanged(UnitEquipmentItem equip, double oldValue, double newValue) | |
469 { | |
470 if (UnitEquipmentAmountChanged!=null) | |
471 { | |
472 UnitEquipmentAmountChanged(equip, oldValue, newValue); | |
473 } | |
474 } | |
475 | |
254
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
476 [Obsolete("Use UnitStatsArrays instead")] |
82 | 477 public Stat[] UnitStatsArray |
478 { | |
479 get { return UnitType.UnitStatsArray; } | |
81
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
480 } |
254
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
481 |
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
482 public Stat[][] UnitStatsArrays |
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
483 { |
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
484 get { return UnitType.UnitStatsArrays; } |
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
485 } |
81
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
486 |
254
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
487 [Obsolete("Use UnitStatsArraysWithName instead")] |
81
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
488 public Stat[] UnitStatsArrayWithName |
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
489 { |
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
490 get { return UnitType.UnitStatsArrayWithName; } |
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
491 } |
254
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
492 |
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
493 public Stat[][] UnitStatsArraysWithName |
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
494 { |
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
495 get { return UnitType.UnitStatsArraysWithName; } |
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
496 } |
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
497 |
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
498 public string[] UnitStatsArrayIDs |
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
499 { |
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
500 get |
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
501 { |
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
502 return UnitType.UnitStatsArrayIDs; |
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
503 } |
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
504 } |
81
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
505 |
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
506 public string GetStatValue(string statName) |
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
507 { |
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
508 return UnitType.GetStatValue(statName); |
82 | 509 } |
178
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
510 |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
511 public int GetEquipmentAmountInSlot (string slotName) |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
512 { |
213 | 513 int amount = 0; |
514 | |
212
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
208
diff
changeset
|
515 List<AbstractUnitEquipmentItemSelection> selections = GetEquipmentSlotSelections(slotName); |
178
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
516 |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
517 if (selections != null) |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
518 { |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
519 amount = GetSelectionTotal(selections); |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
520 } |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
521 |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
522 return amount; |
213 | 523 } |
524 | |
525 internal List<AbstractUnitEquipmentItemSelection> GetEquipmentSlotSelections(string slotName) | |
526 { | |
527 return DictionaryUtils.GetValue(equipmentSlots, slotName); | |
178
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
528 } |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
529 |
197
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
530 /// <summary> |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
531 /// Gets the total amount of items taken for the item's slot, excluding the provided item |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
532 /// </summary> |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
533 /// <param name="item">the item to exclude from the count</param> |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
534 /// <returns>the total number of items</returns> |
201
4d7ff70bb109
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
197
diff
changeset
|
535 public int GetEquipmentAmountInSlotExcludingItem(UnitEquipmentItem item) |
197
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
536 { |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
537 int amount = 0; |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
538 |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
539 List<AbstractUnitEquipmentItemSelection> selections = DictionaryUtils.GetValue(equipmentSlots, item.SlotName); |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
540 |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
541 if (selections != null) |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
542 { |
205
c0edb72a10ba
Fixes #210: Editing equipment in slot loses amount
IBBoard <dev@ibboard.co.uk>
parents:
204
diff
changeset
|
543 selections = new List<AbstractUnitEquipmentItemSelection>(selections); |
197
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
544 RemoveSelectionFromList(item, selections); |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
545 amount = GetSelectionTotal(selections); |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
546 } |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
547 |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
548 return amount; |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
549 } |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
550 |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
551 private void RemoveSelectionFromList(UnitEquipmentItem item, List<AbstractUnitEquipmentItemSelection> selections) |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
552 { |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
553 AbstractUnitEquipmentItemSelection selection = GetEquipmentSelection(item); |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
554 |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
555 if (selection != null) |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
556 { |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
557 selections.Remove(selection); |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
558 } |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
559 } |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
560 |
178
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
561 private int GetSelectionTotal (List<AbstractUnitEquipmentItemSelection> selections) |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
562 { |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
563 int amount = 0; |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
564 |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
565 foreach (AbstractUnitEquipmentItemSelection selection in selections) |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
566 { |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
567 amount+= selection.NumberTaken; |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
568 } |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
569 |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
570 return amount; |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
571 } |
208
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
206
diff
changeset
|
572 |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
206
diff
changeset
|
573 /// <summary> |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
206
diff
changeset
|
574 /// Default stub implementation of getting the unit's abilities - defaults to just the unit type's required abilities until we get a way to modify them |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
206
diff
changeset
|
575 /// </summary> |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
206
diff
changeset
|
576 public ICollection<Ability> Abilities |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
206
diff
changeset
|
577 { |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
206
diff
changeset
|
578 get |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
206
diff
changeset
|
579 { |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
206
diff
changeset
|
580 return UnitType.GetRequiredAbilities(); |
279
51b3027a7dae
Re #295: Index out of bounds when changing unit size and clicking in equipment list
IBBoard <dev@ibboard.co.uk>
parents:
265
diff
changeset
|
581 } |
51b3027a7dae
Re #295: Index out of bounds when changing unit size and clicking in equipment list
IBBoard <dev@ibboard.co.uk>
parents:
265
diff
changeset
|
582 } |
51b3027a7dae
Re #295: Index out of bounds when changing unit size and clicking in equipment list
IBBoard <dev@ibboard.co.uk>
parents:
265
diff
changeset
|
583 |
51b3027a7dae
Re #295: Index out of bounds when changing unit size and clicking in equipment list
IBBoard <dev@ibboard.co.uk>
parents:
265
diff
changeset
|
584 private void RefreshUnitEquipmentAmounts(WarFoundryObject obj, int oldValue, int newValue) |
51b3027a7dae
Re #295: Index out of bounds when changing unit size and clicking in equipment list
IBBoard <dev@ibboard.co.uk>
parents:
265
diff
changeset
|
585 { |
51b3027a7dae
Re #295: Index out of bounds when changing unit size and clicking in equipment list
IBBoard <dev@ibboard.co.uk>
parents:
265
diff
changeset
|
586 foreach (UnitEquipmentItem item in equipment.Keys) |
51b3027a7dae
Re #295: Index out of bounds when changing unit size and clicking in equipment list
IBBoard <dev@ibboard.co.uk>
parents:
265
diff
changeset
|
587 { |
51b3027a7dae
Re #295: Index out of bounds when changing unit size and clicking in equipment list
IBBoard <dev@ibboard.co.uk>
parents:
265
diff
changeset
|
588 AbstractUnitEquipmentItemSelection selection = equipment[item]; |
51b3027a7dae
Re #295: Index out of bounds when changing unit size and clicking in equipment list
IBBoard <dev@ibboard.co.uk>
parents:
265
diff
changeset
|
589 |
51b3027a7dae
Re #295: Index out of bounds when changing unit size and clicking in equipment list
IBBoard <dev@ibboard.co.uk>
parents:
265
diff
changeset
|
590 if (selection is UnitEquipmentRatioSelection) |
51b3027a7dae
Re #295: Index out of bounds when changing unit size and clicking in equipment list
IBBoard <dev@ibboard.co.uk>
parents:
265
diff
changeset
|
591 { |
51b3027a7dae
Re #295: Index out of bounds when changing unit size and clicking in equipment list
IBBoard <dev@ibboard.co.uk>
parents:
265
diff
changeset
|
592 OnUnitEquipmentAmountChanged(item, selection.AmountTaken, selection.AmountTaken); |
51b3027a7dae
Re #295: Index out of bounds when changing unit size and clicking in equipment list
IBBoard <dev@ibboard.co.uk>
parents:
265
diff
changeset
|
593 } |
51b3027a7dae
Re #295: Index out of bounds when changing unit size and clicking in equipment list
IBBoard <dev@ibboard.co.uk>
parents:
265
diff
changeset
|
594 } |
51b3027a7dae
Re #295: Index out of bounds when changing unit size and clicking in equipment list
IBBoard <dev@ibboard.co.uk>
parents:
265
diff
changeset
|
595 } |
82 | 596 } |
597 } |