Mercurial > repos > IBDev-IBBoard.WarFoundry.API
diff api/Objects/Unit.cs @ 61:3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
* Add containership support to Unit class
* Add method to UnitType to check if a UnitType is of an allowed type
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Thu, 09 Apr 2009 14:17:53 +0000 |
parents | 3a90f70dac73 |
children | 2094bd0ba652 |
line wrap: on
line diff
--- a/api/Objects/Unit.cs Thu Apr 09 13:58:23 2009 +0000 +++ b/api/Objects/Unit.cs Thu Apr 09 14:17:53 2009 +0000 @@ -21,7 +21,8 @@ private Race race; private double points; private ArmyCategory cat; - private Dictionary<UnitEquipmentItem, double> equipment = new Dictionary<UnitEquipmentItem, double>(); + private Dictionary<UnitEquipmentItem, double> equipment = new Dictionary<UnitEquipmentItem, double>(); + private List<Unit> containedUnits = new List<Unit>(); public event DoubleValChangedDelegate PointsValueChanged; public event IntValChangedDelegate UnitSizeChanged; public event DoubleValChangedDelegate UnitEquipmentAmountChanged; @@ -195,6 +196,31 @@ return points; } + } + + public Unit[] ContainedUnits + { + get { return containedUnits.ToArray(); } + } + + public void AddContainedUnit(Unit unit) + { + if (UnitType.CanContainUnit(unit)) + { + if (!containedUnits.Contains(unit)) + { + containedUnits.Add(unit); + } + } + else + { + throw new InvalidContainershipException(this, unit); + } + } + + public void RemoveContainedUnit(Unit unit) + { + containedUnits.Remove(unit); } public UnitEquipmentItem[] GetAllowedOptionalEquipment()