# HG changeset patch # User IBBoard # Date 1334519552 -3600 # Node ID 0a20688977934d875584b29767182f26bcb9fff6 # Parent 426b8c5e283c87b6ba29afb83baf3fd5a11869e8 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 diff -r 426b8c5e283c -r 0a2068897793 API/Commands/CreateAndAddUnitCommand.cs --- a/API/Commands/CreateAndAddUnitCommand.cs Sat Apr 14 20:44:22 2012 +0100 +++ b/API/Commands/CreateAndAddUnitCommand.cs Sun Apr 15 20:52:32 2012 +0100 @@ -14,11 +14,13 @@ private UnitType addedUnitType; private ArmyCategory armyCat; private Unit addedUnit; + private Unit parentUnit; - public CreateAndAddUnitCommand(UnitType toAdd, ArmyCategory armyCatTo) + public CreateAndAddUnitCommand(UnitType toAdd, ArmyCategory armyCatTo, Unit parentUnit = null) { addedUnitType = toAdd; armyCat = armyCatTo; + this.parentUnit = parentUnit; } public override bool CanExecute() @@ -45,6 +47,7 @@ public override bool Execute() { addedUnit = new Unit(addedUnitType, armyCat); + addedUnit.ParentUnit = parentUnit; this.Redo(); return true; } diff -r 426b8c5e283c -r 0a2068897793 API/Objects/Army.cs --- a/API/Objects/Army.cs Sat Apr 14 20:44:22 2012 +0100 +++ b/API/Objects/Army.cs Sun Apr 15 20:52:32 2012 +0100 @@ -170,7 +170,7 @@ public Unit[] GetUnits(Category cat) { - return GetUnits(this.GetCategory(cat)); + return GetUnits(GetCategory(cat)); } public Unit[] GetUnits(ArmyCategory cat) @@ -178,6 +178,16 @@ return cat.GetUnits(); } + public Unit[] GetMainUnits(Category cat) + { + return GetMainUnits(GetCategory(cat)); + } + + public Unit[] GetMainUnits(ArmyCategory cat) + { + return cat.GetMainUnits(); + } + public Unit[] GetUnits() { List fullList = new List(); diff -r 426b8c5e283c -r 0a2068897793 API/Objects/ArmyCategory.cs --- a/API/Objects/ArmyCategory.cs Sat Apr 14 20:44:22 2012 +0100 +++ b/API/Objects/ArmyCategory.cs Sun Apr 15 20:52:32 2012 +0100 @@ -98,6 +98,21 @@ return units.ToArray(); } + public Unit[] GetMainUnits() + { + List mainUnits = new List(); + + foreach (Unit unit in units) + { + if (unit.ParentUnit == null) + { + mainUnits.Add(unit); + } + } + + return mainUnits.ToArray(); + } + private double TotalPoints { get { return pointsTotal; }