changeset 471:0a2068897793

Re #359: Add "only contained" attribute to unit types * Add "main units" methods to get only top-level units * Add nesting to unit creation command
author IBBoard <dev@ibboard.co.uk>
date Sun, 15 Apr 2012 20:52:32 +0100
parents 426b8c5e283c
children e6c93ceba119
files API/Commands/CreateAndAddUnitCommand.cs API/Objects/Army.cs API/Objects/ArmyCategory.cs
diffstat 3 files changed, 30 insertions(+), 2 deletions(-) [+]
line diff
     1.1 --- a/API/Commands/CreateAndAddUnitCommand.cs	Sat Apr 14 20:44:22 2012 +0100
     1.2 +++ b/API/Commands/CreateAndAddUnitCommand.cs	Sun Apr 15 20:52:32 2012 +0100
     1.3 @@ -14,11 +14,13 @@
     1.4  		private UnitType addedUnitType;
     1.5  		private ArmyCategory armyCat;
     1.6  		private Unit addedUnit;
     1.7 +		private Unit parentUnit;
     1.8  
     1.9 -		public CreateAndAddUnitCommand(UnitType toAdd, ArmyCategory armyCatTo)
    1.10 +		public CreateAndAddUnitCommand(UnitType toAdd, ArmyCategory armyCatTo, Unit parentUnit = null)
    1.11  		{
    1.12  			addedUnitType = toAdd;
    1.13  			armyCat = armyCatTo;
    1.14 +			this.parentUnit = parentUnit;
    1.15  		}
    1.16  
    1.17  		public override bool CanExecute()
    1.18 @@ -45,6 +47,7 @@
    1.19  		public override bool Execute()
    1.20  		{
    1.21  			addedUnit = new Unit(addedUnitType, armyCat);
    1.22 +			addedUnit.ParentUnit = parentUnit;
    1.23  			this.Redo();
    1.24  			return true;
    1.25  		}
     2.1 --- a/API/Objects/Army.cs	Sat Apr 14 20:44:22 2012 +0100
     2.2 +++ b/API/Objects/Army.cs	Sun Apr 15 20:52:32 2012 +0100
     2.3 @@ -170,7 +170,7 @@
     2.4  
     2.5  		public Unit[] GetUnits(Category cat)
     2.6  		{
     2.7 -			return GetUnits(this.GetCategory(cat));
     2.8 +			return GetUnits(GetCategory(cat));
     2.9  		}
    2.10  
    2.11  		public Unit[] GetUnits(ArmyCategory cat)
    2.12 @@ -178,6 +178,16 @@
    2.13  			return cat.GetUnits();
    2.14  		}
    2.15  
    2.16 +		public Unit[] GetMainUnits(Category cat)
    2.17 +		{
    2.18 +			return GetMainUnits(GetCategory(cat));
    2.19 +		}
    2.20 +
    2.21 +		public Unit[] GetMainUnits(ArmyCategory cat)
    2.22 +		{
    2.23 +			return cat.GetMainUnits();
    2.24 +		}
    2.25 +
    2.26  		public Unit[] GetUnits()
    2.27  		{
    2.28  			List<Unit> fullList = new List<Unit>();
     3.1 --- a/API/Objects/ArmyCategory.cs	Sat Apr 14 20:44:22 2012 +0100
     3.2 +++ b/API/Objects/ArmyCategory.cs	Sun Apr 15 20:52:32 2012 +0100
     3.3 @@ -98,6 +98,21 @@
     3.4  			return units.ToArray();
     3.5  		}
     3.6  
     3.7 +		public Unit[] GetMainUnits()
     3.8 +		{
     3.9 +			List<Unit> mainUnits = new List<Unit>();
    3.10 +
    3.11 +			foreach (Unit unit in units)
    3.12 +			{
    3.13 +				if (unit.ParentUnit == null)
    3.14 +				{
    3.15 +					mainUnits.Add(unit);
    3.16 +				}
    3.17 +			}
    3.18 +
    3.19 +			return mainUnits.ToArray();
    3.20 +		}
    3.21 +
    3.22  		private double TotalPoints
    3.23  		{
    3.24  			get { return pointsTotal; }