comparison api/Objects/UnitType.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 5145b7c61ae0
children 4a02c07278e7
comparison
equal deleted inserted replaced
151:1d13820b3d96 152:0c0e14f03785
231 { 231 {
232 if (!equipment.ContainsKey(item.ID)) 232 if (!equipment.ContainsKey(item.ID))
233 { 233 {
234 equipment.Add(item.ID, item); 234 equipment.Add(item.ID, item);
235 equipmentKeyOrder.Add(item.ID); 235 equipmentKeyOrder.Add(item.ID);
236 AddToMutexGroup(item); 236 AddToMutexGroups(item);
237 } 237 }
238 } 238 }
239 239
240 private void AddToMutexGroup(UnitEquipmentItem item) 240 private void AddToMutexGroups(UnitEquipmentItem item)
241 { 241 {
242 string mutexGroup = item.MutexGroup; 242 string[] mutexGroups = item.MutexGroups;
243 243
244 if (mutexGroup!="" && mutexGroup!=null) 244 foreach (string mutexGroup in mutexGroups)
245 { 245 {
246 List<UnitEquipmentItem> items = DictionaryUtils.GetValue(equipmentExclusionGroups, mutexGroup); 246 List<UnitEquipmentItem> items = DictionaryUtils.GetValue(equipmentExclusionGroups, mutexGroup);
247 247
248 if (items == null) 248 if (items == null)
249 { 249 {
294 return DictionaryUtils.ToArray<string, UnitEquipmentItem>(equipment); 294 return DictionaryUtils.ToArray<string, UnitEquipmentItem>(equipment);
295 } 295 }
296 296
297 public UnitEquipmentItem[] GetEquipmentItemsByExclusionGroup(string group) 297 public UnitEquipmentItem[] GetEquipmentItemsByExclusionGroup(string group)
298 { 298 {
299 List<UnitEquipmentItem> list = DictionaryUtils.GetValue(equipmentExclusionGroups, group); 299 return GetEquipmentItemsByExclusionGroups(new string[] { group });
300 300 }
301 if (list == null) 301
302 { 302 public UnitEquipmentItem[] GetEquipmentItemsByExclusionGroups(string[] groups)
303 return new UnitEquipmentItem[0]; 303 {
304 } 304 List<UnitEquipmentItem> list = new List<UnitEquipmentItem>();
305 else 305
306 { 306 foreach (string group in groups)
307 return list.ToArray(); 307 {
308 } 308 List<UnitEquipmentItem> groupList = DictionaryUtils.GetValue(equipmentExclusionGroups, group);
309
310 if (groupList != null)
311 {
312 list.AddRange(groupList);
313 }
314 }
315
316 return list.ToArray();
309 } 317 }
310 318
311 public bool IsRatioLimitedEquipmentItem(EquipmentItem item) 319 public bool IsRatioLimitedEquipmentItem(EquipmentItem item)
312 { 320 {
313 UnitEquipmentItem equip = GetEquipmentItem(item); 321 UnitEquipmentItem equip = GetEquipmentItem(item);