diff api/Objects/Unit.cs @ 83:89cc29b4c012

Re #90: Stop new units showing up twice * Hand all of unit adding/removing down to category * Refactor out OnFailedRequirement method in Army * Make Army listen to and propogate FailedRequirement events from Units * Add OnUnitAdded/Removed method to ArmyCategory that takes list of failures * Remove direct reference to Army from Unit and go via ArmyCategory instead
author IBBoard <dev@ibboard.co.uk>
date Sat, 27 Jun 2009 19:39:04 +0000
parents 3ea0ab04352b
children 46ad6f478203
line wrap: on
line diff
--- a/api/Objects/Unit.cs	Sat Jun 27 18:59:49 2009 +0000
+++ b/api/Objects/Unit.cs	Sat Jun 27 19:39:04 2009 +0000
@@ -17,7 +17,6 @@
 	{
 		private UnitType type;
 		private int size;
-		private Army army;
 		private Unit parentUnit;
 		private double points;
 		private ArmyCategory cat;
@@ -25,13 +24,13 @@
 		private List<Unit> containedUnits = new List<Unit>();
 		public event DoubleValChangedDelegate PointsValueChanged;
 		public event IntValChangedDelegate UnitSizeChanged;
-		public event DoubleValChangedDelegate UnitEquipmentAmountChanged;
-
-		public Unit(UnitType unitType, Army parentArmy) : this(unitType, unitType.MinSize, parentArmy){}
-
-		public Unit(UnitType unitType, int startSize, Army parentArmy)
-		{
-			Army = parentArmy;
+		public event DoubleValChangedDelegate UnitEquipmentAmountChanged;
+
+		public Unit(UnitType unitType, ArmyCategory parentArmyCat) : this(unitType, unitType.MinSize, parentArmyCat) { }
+
+		public Unit(UnitType unitType, int startSize, ArmyCategory parentArmyCat)
+		{
+			Category = parentArmyCat;
 			type = unitType;
 			Size = startSize;
 			SetInitialEquipment();
@@ -143,16 +142,7 @@
 
 		public Army Army
 		{
-			get { return army; }
-			set 
-			{
-				army = value;
-
-				if (army == null)
-				{
-					Category = null;
-				}
-			}
+			get { return (Category == null ? null : Category.ParentArmy); }
 		}
 
 		public Race Race
@@ -161,24 +151,10 @@
 		}
 
 		public ArmyCategory Category
-		{
-			get 
-			{ 
-				if (cat==null)
-				{
-					if (Army!=null)
-					{
-						return Army.GetCategory(UnitType.MainCategory);
-					}
-					else
-					{
-						return null;
-					}
-				}
-				else
-				{
-					return cat; 
-				}
+		{
+			get
+			{
+				return cat;
 			}
 			set { cat = value; }
 		}