Mercurial > repos > IBDev-IBBoard.WarFoundry.API
comparison api/Objects/UnitEquipmentItem.cs @ 152:0c0e14f03785
Re #180: Add multiple mutex groups
* Add multiple mutex groups to UnitEquipmentItem
* Add new attribute to Race schema
* Make everywhere handle multiple groups instead of assuming one
* Make factory load new attribute then fall back to old (deprecated) attribute
* Add method to Unit to get the blocking items (useful for future UI work to say "replace X and Y with Z")
* Add IsMutuallyExclusive method to UnitEquipmentItem to determine whether mutex groups overlap
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 26 Sep 2009 19:51:11 +0000 |
parents | c11c0da01bbc |
children | 4a02c07278e7 |
comparison
equal
deleted
inserted
replaced
151:1d13820b3d96 | 152:0c0e14f03785 |
---|---|
1 // This file (UnitEquipmentItem.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard. | 1 // This file (UnitEquipmentItem.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard. |
2 // | 2 // |
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. | 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. |
4 | 4 |
5 using System; | 5 using System; |
6 using System.Xml; | |
7 using IBBoard.Lang; | 6 using IBBoard.Lang; |
8 | 7 |
9 namespace IBBoard.WarFoundry.API.Objects | 8 namespace IBBoard.WarFoundry.API.Objects |
10 { | 9 { |
11 /// <summary> | 10 /// <summary> |
20 private int maxNum; | 19 private int maxNum; |
21 private double minPercentage; | 20 private double minPercentage; |
22 private double maxPercentage; | 21 private double maxPercentage; |
23 private double costMultiplier; | 22 private double costMultiplier; |
24 private RoundType roundType; | 23 private RoundType roundType; |
25 private string mutexGroup; | 24 private string[] mutexGroups; |
26 private UnitType unitType; | 25 private UnitType unitType; |
27 | 26 |
28 public UnitEquipmentItem(EquipmentItem equipmentItem, UnitType equipmentFor) : this(equipmentItem, equipmentFor, "") | 27 public UnitEquipmentItem(EquipmentItem equipmentItem, UnitType equipmentFor) : this(equipmentItem, equipmentFor, new string[0]) |
29 { | 28 { |
30 //Do nothing extra | 29 //Do nothing extra |
31 } | 30 } |
32 | 31 |
33 public UnitEquipmentItem(EquipmentItem equipmentItem, UnitType equipmentFor, string mutexGroup) | 32 public UnitEquipmentItem(EquipmentItem equipmentItem, UnitType equipmentFor, params string[] mutexGroups) |
34 { | 33 { |
35 item = equipmentItem; | 34 item = equipmentItem; |
36 unitType = equipmentFor; | 35 unitType = equipmentFor; |
37 this.mutexGroup = mutexGroup; | 36 this.mutexGroups = mutexGroups; |
38 unitType.AddEquipmentItem(this); | 37 unitType.AddEquipmentItem(this); |
39 } | 38 } |
40 | 39 |
41 public override string Name | 40 public override string Name |
42 { | 41 { |
103 { | 102 { |
104 get { return roundUp; } | 103 get { return roundUp; } |
105 set { roundUp = value; } | 104 set { roundUp = value; } |
106 } | 105 } |
107 | 106 |
107 [Obsolete("Use MutexGroups instead for greater flexibility")] | |
108 public string MutexGroup | 108 public string MutexGroup |
109 { | 109 { |
110 get { return mutexGroup; } | 110 get { return (mutexGroups.Length == 0 ? "" : mutexGroups[0]); } |
111 } | |
112 | |
113 public String[] MutexGroups | |
114 { | |
115 get { return (string[]) mutexGroups.Clone(); } | |
111 } | 116 } |
112 | 117 |
113 public UnitType EquipmentForUnit | 118 public UnitType EquipmentForUnit |
114 { | 119 { |
115 get { return unitType; } | 120 get { return unitType; } |
182 return EquipmentItem.Name+ " ("+EquipmentItem.Cost+"pts each)"; | 187 return EquipmentItem.Name+ " ("+EquipmentItem.Cost+"pts each)"; |
183 } | 188 } |
184 | 189 |
185 public bool HasAlternatives() | 190 public bool HasAlternatives() |
186 { | 191 { |
187 if (MutexGroup=="") | 192 if (MutexGroups.Length == 0) |
188 { | 193 { |
189 return false; | 194 return false; |
190 } | 195 } |
191 else if (EquipmentForUnit == null) | 196 else if (EquipmentForUnit == null) |
192 { | 197 { |
193 return false; | 198 return false; |
194 } | 199 } |
195 else | 200 else |
196 { | 201 { |
197 //If the number of items in the MutEx group is greater than one then it must be this item plus another | 202 //If the number of items in the MutEx group is greater than one then it must be this item plus another |
198 return EquipmentForUnit.GetEquipmentItemsByExclusionGroup(MutexGroup).Length > 1; | 203 return EquipmentForUnit.GetEquipmentItemsByExclusionGroups(MutexGroups).Length > 1; |
199 } | 204 } |
200 } | 205 } |
201 | 206 |
202 public ArmourType ItemArmourType | 207 public ArmourType ItemArmourType |
203 { | 208 { |
220 } | 225 } |
221 | 226 |
222 public bool CanBeUsedWithArmourType(ArmourType otherItemType) | 227 public bool CanBeUsedWithArmourType(ArmourType otherItemType) |
223 { | 228 { |
224 return EquipmentItem.CanBeUsedWithArmourType(otherItemType); | 229 return EquipmentItem.CanBeUsedWithArmourType(otherItemType); |
230 } | |
231 | |
232 /// <summary> | |
233 /// Checks the "mutex" (mutual exclusion) groups of the other item against its own and determines whether the two items are mutually exclusive (share at least one mutex group) | |
234 /// </summary> | |
235 /// <param name="item">the item to check against</param> | |
236 /// <returns><code>true</code> if the two items share at least one mutex group, else <code>false</code></returns> | |
237 public bool IsMutuallyExclusive(UnitEquipmentItem item) | |
238 { | |
239 bool areMutex = false; | |
240 | |
241 foreach (string mutex in MutexGroups) | |
242 { | |
243 foreach (string otherMutex in item.MutexGroups) | |
244 { | |
245 if (mutex.Equals(otherMutex)) | |
246 { | |
247 areMutex = true; | |
248 goto postLoop; | |
249 } | |
250 } | |
251 } | |
252 postLoop: | |
253 | |
254 return areMutex; | |
225 } | 255 } |
226 } | 256 } |
227 } | 257 } |