comparison api/Objects/Unit.cs @ 65:aa2d05a9c635

Re #61 - Complete structure of WarFoundry API objects * Add parent links to Units (inverse of r97)
author IBBoard <dev@ibboard.co.uk>
date Thu, 09 Apr 2009 18:27:51 +0000
parents 2094bd0ba652
children aa66dd18cdae
comparison
equal deleted inserted replaced
64:2094bd0ba652 65:aa2d05a9c635
16 public class Unit : WarFoundryObject 16 public class Unit : WarFoundryObject
17 { 17 {
18 private UnitType type; 18 private UnitType type;
19 private int size; 19 private int size;
20 private Army army; 20 private Army army;
21 private Race race; 21 private Unit parentUnit;
22 private double points; 22 private double points;
23 private ArmyCategory cat; 23 private ArmyCategory cat;
24 private Dictionary<EquipmentItem, double> equipment = new Dictionary<EquipmentItem, double>(); 24 private Dictionary<EquipmentItem, double> equipment = new Dictionary<EquipmentItem, double>();
25 private List<Unit> containedUnits = new List<Unit>(); 25 private List<Unit> containedUnits = new List<Unit>();
26 public event DoubleValChangedDelegate PointsValueChanged; 26 public event DoubleValChangedDelegate PointsValueChanged;
156 } 156 }
157 } 157 }
158 158
159 public Race Race 159 public Race Race
160 { 160 {
161 get { return race; } 161 get { return UnitType.Race; }
162 set { race = value; }
163 } 162 }
164 163
165 public ArmyCategory Category 164 public ArmyCategory Category
166 { 165 {
167 get 166 get
209 { 208 {
210 if (!containedUnits.Contains(unit)) 209 if (!containedUnits.Contains(unit))
211 { 210 {
212 containedUnits.Add(unit); 211 containedUnits.Add(unit);
213 } 212 }
213
214 unit.ParentUnit = this;
214 } 215 }
215 else 216 else
216 { 217 {
217 throw new InvalidContainershipException(this, unit); 218 throw new InvalidContainershipException(this, unit);
218 } 219 }
219 } 220 }
220 221
221 public void RemoveContainedUnit(Unit unit) 222 public void RemoveContainedUnit(Unit unit)
222 { 223 {
223 containedUnits.Remove(unit); 224 containedUnits.Remove(unit);
225 }
226
227 public Unit ParentUnit
228 {
229 get { return parentUnit; }
230 set
231 {
232 if (!(parentUnit == value || (parentUnit != null && parentUnit.Equals(value))))
233 {
234 parentUnit = value;
235
236 if (value!=null)
237 {
238 value.AddContainedUnit(this);
239 }
240 }
241 }
224 } 242 }
225 243
226 public UnitEquipmentItem[] GetAllowedOptionalEquipment() 244 public UnitEquipmentItem[] GetAllowedOptionalEquipment()
227 { 245 {
228 List<UnitEquipmentItem> list = new List<UnitEquipmentItem>(); 246 List<UnitEquipmentItem> list = new List<UnitEquipmentItem>();