Mercurial > repos > snowblizz-super-API-ideas
annotate api/Objects/Unit.cs @ 178:ca2cd24f6872
Re #198: Add slots with counts to units
* Add storing of selections by slot on add and removing on remove
* Add method to get total number of items in a slot
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 24 Oct 2009 14:01:50 +0000 |
parents | 91f7b8da0b53 |
children | 55dc7c97fcfe |
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; |
161
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
10 using IBBoard.WarFoundry.API.Util; |
82 | 11 |
12 namespace IBBoard.WarFoundry.API.Objects | |
13 { | |
14 /// <summary> | |
15 /// Summary description for UnitInstance. | |
16 /// </summary> | |
143
7f13ffcb8765
Re #164: Show unit cost in army tree
IBBoard <dev@ibboard.co.uk>
parents:
134
diff
changeset
|
17 public class Unit : WarFoundryObject, ICostedWarFoundryObject |
82 | 18 { |
19 private UnitType type; | |
20 private int size; | |
21 private Unit parentUnit; | |
22 private double points; | |
23 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
|
24 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
|
25 private Dictionary<string, List<AbstractUnitEquipmentItemSelection>> equipmentSlots = new Dictionary<string, List<AbstractUnitEquipmentItemSelection>>(); |
82 | 26 private List<Unit> containedUnits = new List<Unit>(); |
27 public event DoubleValChangedDelegate PointsValueChanged; | |
28 public event IntValChangedDelegate UnitSizeChanged; | |
85
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
29 public event DoubleValChangedDelegate UnitEquipmentAmountChanged; |
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
30 |
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
31 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
|
32 |
123
52e8c3cdde10
Re #127: Unit creation always assigns default equipment
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
33 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
|
34 { |
52e8c3cdde10
Re #127: Unit creation always assigns default equipment
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
35 SetInitialEquipment(); |
52e8c3cdde10
Re #127: Unit creation always assigns default equipment
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
36 } |
52e8c3cdde10
Re #127: Unit creation always assigns default equipment
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
37 |
52e8c3cdde10
Re #127: Unit creation always assigns default equipment
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
38 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
|
39 { |
83
89cc29b4c012
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
40 Category = parentArmyCat; |
82 | 41 type = unitType; |
42 Size = startSize; | |
43 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
|
44 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
|
45 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
|
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 |
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 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
|
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 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
|
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 |
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 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
|
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 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
|
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 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
|
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 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
|
60 } |
82 | 61 } |
62 | |
63 protected override string DefaultName() | |
64 { | |
65 if (type != null) | |
66 { | |
67 if (size == 1) | |
68 { | |
69 return type.Name; | |
70 } | |
71 else | |
72 { | |
73 return String.Format(Translation.GetTranslation("defaultUnitName"), size, type.Name); | |
74 } | |
75 } | |
76 else | |
77 { | |
78 return "Unknown Unit"; | |
79 } | |
80 } | |
81 | |
82 private void SetInitialEquipment() | |
83 { | |
84 foreach (UnitEquipmentItem unitEquip in UnitType.GetEquipmentItems()) | |
85 { | |
86 if (unitEquip.IsRequired) | |
87 { | |
88 if (CanEquipWithItem(unitEquip)) | |
89 { | |
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
|
90 if (unitEquip.IsRatioLimit) |
151
1d13820b3d96
Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents:
149
diff
changeset
|
91 { |
149
c01366bd1627
Fixes #181: Unit points costs don't always include equipment
IBBoard <dev@ibboard.co.uk>
parents:
143
diff
changeset
|
92 SetEquipmentRatio(unitEquip, unitEquip.MinPercentage); |
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
|
93 } |
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
|
94 else |
151
1d13820b3d96
Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents:
149
diff
changeset
|
95 { |
149
c01366bd1627
Fixes #181: Unit points costs don't always include equipment
IBBoard <dev@ibboard.co.uk>
parents:
143
diff
changeset
|
96 SetEquipmentAmount(unitEquip, unitEquip.MinNumber); |
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 } |
82 | 98 } |
99 } | |
100 } | |
101 } | |
102 | |
103 private void CalcCost() | |
104 { | |
105 double oldpoints = points; | |
106 points = type.CostPerTrooper * AdditionalTroopers + type.BaseUnitCost; | |
107 | |
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
|
108 foreach (AbstractUnitEquipmentItemSelection equipSelection in equipment.Values) |
82 | 109 { |
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
|
110 points += equipSelection.TotalCost; |
82 | 111 } |
112 | |
113 if (oldpoints!=points) | |
114 { | |
115 OnPointsValueChanged(oldpoints, points); | |
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 | |
143
7f13ffcb8765
Re #164: Show unit cost in army tree
IBBoard <dev@ibboard.co.uk>
parents:
134
diff
changeset
|
162 [Obsolete("Use Points instead")] |
82 | 163 public double PointsValue |
164 { | |
143
7f13ffcb8765
Re #164: Show unit cost in army tree
IBBoard <dev@ibboard.co.uk>
parents:
134
diff
changeset
|
165 get { return Points; } |
7f13ffcb8765
Re #164: Show unit cost in army tree
IBBoard <dev@ibboard.co.uk>
parents:
134
diff
changeset
|
166 } |
7f13ffcb8765
Re #164: Show unit cost in army tree
IBBoard <dev@ibboard.co.uk>
parents:
134
diff
changeset
|
167 |
7f13ffcb8765
Re #164: Show unit cost in army tree
IBBoard <dev@ibboard.co.uk>
parents:
134
diff
changeset
|
168 public double Points |
7f13ffcb8765
Re #164: Show unit cost in army tree
IBBoard <dev@ibboard.co.uk>
parents:
134
diff
changeset
|
169 { |
82 | 170 get |
171 { | |
172 if (points == 0) | |
173 { | |
174 CalcCost(); | |
175 } | |
176 | |
177 return points; | |
178 } | |
61
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 |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
181 public Unit[] ContainedUnits |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
182 { |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
183 get { return containedUnits.ToArray(); } |
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 |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
186 public void AddContainedUnit(Unit unit) |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
187 { |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
188 if (UnitType.CanContainUnit(unit)) |
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 if (!containedUnits.Contains(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 containedUnits.Add(unit); |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
193 } |
65
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
194 |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
195 unit.ParentUnit = this; |
61
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 else |
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 throw new InvalidContainershipException(this, unit); |
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 } |
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 public void RemoveContainedUnit(Unit 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 containedUnits.Remove(unit); |
65
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 |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
208 public Unit ParentUnit |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
209 { |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
210 get { return parentUnit; } |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
211 set |
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 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
|
214 { |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
215 parentUnit = value; |
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 (value!=null) |
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 value.AddContainedUnit(this); |
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 } |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
222 } |
82 | 223 } |
224 | |
161
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
225 [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
|
226 public UnitEquipmentItem[] GetAllowedAdditionalEquipment() |
164 | 227 { |
161
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
228 return UnitEquipmentUtil.GetAllowedEquipmentItems(this); |
82 | 229 } |
230 | |
231 public UnitEquipmentItem[] GetEquipment() | |
232 { | |
233 return DictionaryUtils.ToKeyArray(equipment); | |
234 } | |
235 | |
236 public EquipmentItem[] GetRequiredEquipment() | |
237 { | |
238 List<EquipmentItem> list = new List<EquipmentItem>(); | |
239 | |
240 foreach(UnitEquipmentItem item in GetEquipment()) | |
241 { | |
242 if (item.IsRequired) | |
243 { | |
244 list.Add(item.EquipmentItem); | |
245 } | |
246 } | |
247 | |
248 return list.ToArray(); | |
249 } | |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
250 |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
251 public double GetEquipmentAmount(UnitEquipmentItem item) |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
252 { |
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
|
253 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
|
254 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
|
255 |
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 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
|
257 { |
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 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
|
259 } |
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 return amount; |
82 | 262 } |
263 | |
264 public double GetEquipmentAmount(string equipID) | |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
265 { |
82 | 266 return GetEquipmentAmount(UnitType.GetEquipmentItem(equipID)); |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
267 } |
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
|
268 |
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
|
269 public bool GetEquipmentAmountIsRatio(UnitEquipmentItem item) |
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
|
270 { |
134
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
271 return IsEquipmentAmountRatio(GetEquipmentSelection(item)); |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
272 } |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
273 |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
274 private AbstractUnitEquipmentItemSelection GetEquipmentSelection(UnitEquipmentItem item) |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
275 { |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
276 return DictionaryUtils.GetValue(equipment, item); |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
277 } |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
278 |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
279 private bool IsEquipmentAmountRatio(AbstractUnitEquipmentItemSelection selection) |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
280 { |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
281 return (selection is UnitEquipmentRatioSelection); |
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
|
282 } |
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
|
283 |
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
|
284 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
|
285 { |
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
|
286 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
|
287 } |
134
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
288 |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
289 public string GetEquipmentAmountString(string equipID) |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
290 { |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
291 return GetEquipmentAmountString(UnitType.GetEquipmentItem(equipID)); |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
292 } |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
293 |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
294 public string GetEquipmentAmountString(UnitEquipmentItem item) |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
295 { |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
296 String amountString = ""; |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
297 AbstractUnitEquipmentItemSelection selection = GetEquipmentSelection(item); |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
298 |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
299 if (IsEquipmentAmountRatio(selection)) |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
300 { |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
301 amountString = UnitEquipmentRatioSelection.GetEquipmentAmountString(GetEquipmentAmount(item)); |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
302 } |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
303 else |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
304 { |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
305 amountString = UnitEquipmentNumericSelection.GetEquipmentAmountString(GetEquipmentAmount(item)); |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
306 } |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
307 |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
308 return amountString; |
57f7b80757ea
Re #68: Export army to another format
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
309 } |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
310 |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
311 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
|
312 { |
82 | 313 if (amount <1 && amount != WarFoundryCore.INFINITY) |
314 { | |
315 amount = 0; | |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
316 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
317 |
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
|
318 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
|
319 { |
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
|
320 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
|
321 } |
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 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
|
323 { |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
324 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
|
325 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
|
326 |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
327 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
|
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 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
|
330 { |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
331 AddEquipmentAmount(equip, amount); |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
332 } |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
333 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
|
334 { |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
335 //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
|
336 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
|
337 } |
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
|
338 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
|
339 { |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
340 equipment.Remove(equip); |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
341 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
|
342 } |
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 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
|
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 } |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
347 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
348 |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
349 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
|
350 { |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
351 AbstractUnitEquipmentItemSelection newItem = null; |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
352 |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
353 if (equip.IsRatioLimit) |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
354 { |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
355 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
|
356 } |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
357 else |
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 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
|
360 } |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
361 |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
362 equipment[equip] = newItem; |
178
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
363 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
|
364 |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
365 if (selections == null) |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
366 { |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
367 selections = new List<AbstractUnitEquipmentItemSelection>(); |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
368 equipmentSlots[equip.SlotName] = selections; |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
369 } |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
370 |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
371 Console.WriteLine ("Sels: "+selections.Count); |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
372 |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
373 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
|
374 } |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
375 |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
376 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
|
377 { |
80
aa66dd18cdae
Closes #81 - Resolve Unit Equipment problems in WinForms GUI
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
378 if (!equip.IsRatioLimit) |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
379 { |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
380 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
|
381 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
382 |
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
|
383 if (ratio > 100) |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
384 { |
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
|
385 ratio = 100; |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
386 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
387 else if (ratio < 0) |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
388 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
389 ratio = 0; |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
390 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
391 |
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
|
392 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
|
393 { |
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
|
394 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
|
395 } |
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
|
396 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
|
397 { |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
398 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
|
399 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
|
400 |
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
|
401 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
|
402 { |
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
|
403 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
|
404 { |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
405 AddEquipmentRatio(equip, ratio); |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
406 } |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
407 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
|
408 { |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
409 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
|
410 } |
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
|
411 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
|
412 { |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
413 equipment.Remove(equip); |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
414 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
|
415 } |
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
|
416 |
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 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
|
418 } |
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
|
419 } |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
420 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
421 |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
422 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
|
423 { |
178
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
424 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
|
425 equipment[equip] = newItem; |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
426 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
|
427 |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
428 if (selections == null) |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
429 { |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
430 selections = new List<AbstractUnitEquipmentItemSelection>(); |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
431 equipmentSlots[equip.SlotName] = selections; |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
432 } |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
433 |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
434 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
|
435 } |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
436 |
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
|
437 private void RemoveEquipmentItem(UnitEquipmentItem equip) |
82 | 438 { |
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
|
439 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
|
440 |
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
|
441 if (oldAmount != 0) |
82 | 442 { |
178
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
443 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
|
444 equipment.Remove(equip); |
178
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
445 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
|
446 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
|
447 OnUnitEquipmentAmountChanged(equip, oldAmount, 0); |
82 | 448 } |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
449 } |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
450 |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
451 public bool CanEquipWithItem(UnitEquipmentItem item) |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
452 { |
154
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
453 string[] mutexes = item.MutexGroups; |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
454 bool canEquip = false; |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
455 |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
456 if (mutexes.Length == 0) |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
457 { |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
458 canEquip = true; |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
459 } |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
460 else |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
461 { |
162
624422e91a1c
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
161
diff
changeset
|
462 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
|
463 } |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
464 |
152
0c0e14f03785
Re #180: Add multiple mutex groups
IBBoard <dev@ibboard.co.uk>
parents:
151
diff
changeset
|
465 return canEquip; |
154
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
466 } |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
467 |
161
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
468 [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
|
469 public List<UnitEquipmentItem> GetBlockingEquipmentItems(UnitEquipmentItem item) |
164 | 470 { |
161
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
471 return UnitEquipmentUtil.GetBlockingEquipmentItems(this, item); |
82 | 472 } |
473 | |
474 public bool CanEquipWithItem(string equipID) | |
475 { | |
476 return CanEquipWithItem(UnitType.GetEquipmentItem(equipID)); | |
477 } | |
478 | |
479 private void OnPointsValueChanged(double oldValue, double newValue) | |
480 { | |
481 if (PointsValueChanged!=null) | |
482 { | |
483 PointsValueChanged(this, oldValue, newValue); | |
484 } | |
485 } | |
486 | |
487 private void OnUnitSizeChanged(int oldValue, int newValue) | |
488 { | |
489 if (UnitSizeChanged!=null) | |
490 { | |
491 UnitSizeChanged(this, oldValue, newValue); | |
492 } | |
493 } | |
494 | |
495 private void OnUnitEquipmentAmountChanged(UnitEquipmentItem equip, double oldValue, double newValue) | |
496 { | |
497 if (UnitEquipmentAmountChanged!=null) | |
498 { | |
499 UnitEquipmentAmountChanged(equip, oldValue, newValue); | |
500 } | |
501 } | |
502 | |
503 public Stat[] UnitStatsArray | |
504 { | |
505 get { return UnitType.UnitStatsArray; } | |
81
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
506 } |
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 public Stat[] UnitStatsArrayWithName |
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
509 { |
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
510 get { return UnitType.UnitStatsArrayWithName; } |
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
511 } |
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
512 |
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
513 public string GetStatValue(string statName) |
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
514 { |
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
515 return UnitType.GetStatValue(statName); |
82 | 516 } |
178
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
517 |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
518 public int GetEquipmentAmountInSlot (string slotName) |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
519 { |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
520 int amount = 0; |
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 List<AbstractUnitEquipmentItemSelection> selections = DictionaryUtils.GetValue(equipmentSlots, slotName); |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
523 |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
524 if (selections != null) |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
525 { |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
526 amount = GetSelectionTotal(selections); |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
527 } |
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 return amount; |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
530 } |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
531 |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
532 private int GetSelectionTotal (List<AbstractUnitEquipmentItemSelection> selections) |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
533 { |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
534 int amount = 0; |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
535 |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
536 foreach (AbstractUnitEquipmentItemSelection selection in selections) |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
537 { |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
538 Console.WriteLine ("Sel: "+selection.NumberTaken); |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
539 amount+= selection.NumberTaken; |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
540 } |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
541 |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
542 return amount; |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
543 } |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
544 |
82 | 545 } |
546 } |