# HG changeset patch # User IBBoard # Date 1256392910 0 # Node ID ca2cd24f687296e0c8196d14065444dd7db0c06b # Parent 948e90426a8d52d9d4b198db3af906b5810288a2 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 diff -r 948e90426a8d -r ca2cd24f6872 api/Objects/Unit.cs --- a/api/Objects/Unit.cs Fri Oct 23 19:55:54 2009 +0000 +++ b/api/Objects/Unit.cs Sat Oct 24 14:01:50 2009 +0000 @@ -22,6 +22,7 @@ private double points; private ArmyCategory cat; private Dictionary equipment = new Dictionary(); + private Dictionary> equipmentSlots = new Dictionary>(); private List containedUnits = new List(); public event DoubleValChangedDelegate PointsValueChanged; public event IntValChangedDelegate UnitSizeChanged; @@ -359,6 +360,17 @@ } equipment[equip] = newItem; + List selections = DictionaryUtils.GetValue(equipmentSlots, equip.SlotName); + + if (selections == null) + { + selections = new List(); + equipmentSlots[equip.SlotName] = selections; + } + + Console.WriteLine ("Sels: "+selections.Count); + + selections.Add(newItem); } public void SetEquipmentRatio(UnitEquipmentItem equip, double ratio) @@ -409,7 +421,17 @@ private void AddEquipmentRatio(UnitEquipmentItem equip, double ratio) { - equipment[equip] = new UnitEquipmentRatioSelection(this, equip, ratio); + UnitEquipmentRatioSelection newItem = new UnitEquipmentRatioSelection (this, equip, ratio); + equipment[equip] = newItem; + List selections = DictionaryUtils.GetValue(equipmentSlots, equip.SlotName); + + if (selections == null) + { + selections = new List(); + equipmentSlots[equip.SlotName] = selections; + } + + selections.Add(newItem); } private void RemoveEquipmentItem(UnitEquipmentItem equip) @@ -418,7 +440,10 @@ if (oldAmount != 0) { + AbstractUnitEquipmentItemSelection selection = DictionaryUtils.GetValue (equipment, equip); equipment.Remove(equip); + List slotSelections = DictionaryUtils.GetValue (equipmentSlots, equip.SlotName); + slotSelections.Remove(selection); OnUnitEquipmentAmountChanged(equip, oldAmount, 0); } } @@ -489,5 +514,33 @@ { return UnitType.GetStatValue(statName); } + + public int GetEquipmentAmountInSlot (string slotName) + { + int amount = 0; + + List selections = DictionaryUtils.GetValue(equipmentSlots, slotName); + + if (selections != null) + { + amount = GetSelectionTotal(selections); + } + + return amount; + } + + private int GetSelectionTotal (List selections) + { + int amount = 0; + + foreach (AbstractUnitEquipmentItemSelection selection in selections) + { + Console.WriteLine ("Sel: "+selection.NumberTaken); + amount+= selection.NumberTaken; + } + + return amount; + } + } }