changeset 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 d100ca4bd0c1
files api/Objects/Unit.cs
diffstat 1 files changed, 22 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/api/Objects/Unit.cs	Thu Apr 09 15:36:22 2009 +0000
+++ b/api/Objects/Unit.cs	Thu Apr 09 18:27:51 2009 +0000
@@ -17,8 +17,8 @@
 	{
 		private UnitType type;
 		private int size;
-		private Army army;
-		private Race race;
+		private Army army;
+		private Unit parentUnit;
 		private double points;
 		private ArmyCategory cat;
 		private Dictionary<EquipmentItem, double> equipment = new Dictionary<EquipmentItem, double>();
@@ -158,8 +158,7 @@
 
 		public Race Race
 		{
-			get { return race; }
-			set { race = value; }
+			get { return UnitType.Race; }
 		}
 
 		public ArmyCategory Category
@@ -211,6 +210,8 @@
 				{
 					containedUnits.Add(unit);
 				}
+				
+				unit.ParentUnit = this;
 			}
 			else
 			{
@@ -221,6 +222,23 @@
 		public void RemoveContainedUnit(Unit unit)
 		{
 			containedUnits.Remove(unit);
+		}
+		
+		public Unit ParentUnit
+		{
+			get { return parentUnit; }
+			set
+			{
+				if (!(parentUnit == value || (parentUnit != null && parentUnit.Equals(value))))
+				{
+					parentUnit = value;
+					
+					if (value!=null)
+					{
+						value.AddContainedUnit(this);
+					}
+				}
+			}
 		}
 
 		public UnitEquipmentItem[] GetAllowedOptionalEquipment()