# HG changeset patch # User IBBoard # Date 1334603663 -3600 # Node ID e6c93ceba1197a81acce1f8dccecb3cbadd95f98 # Parent 0a20688977934d875584b29767182f26bcb9fff6 Re #359: Add "only contained" attribute to unit types * Make sure we add and remove from the parent unit appropriately * Make sure that setting the unit's parent to null removes it from the parent diff -r 0a2068897793 -r e6c93ceba119 API/Commands/CreateAndAddUnitCommand.cs --- a/API/Commands/CreateAndAddUnitCommand.cs Sun Apr 15 20:52:32 2012 +0100 +++ b/API/Commands/CreateAndAddUnitCommand.cs Mon Apr 16 20:14:23 2012 +0100 @@ -47,19 +47,20 @@ public override bool Execute() { addedUnit = new Unit(addedUnitType, armyCat); - addedUnit.ParentUnit = parentUnit; - this.Redo(); + Redo(); return true; } public override void Redo() { + addedUnit.ParentUnit = parentUnit; armyCat.AddUnit(addedUnit); } public override void Undo() { armyCat.RemoveUnit(addedUnit); + addedUnit.ParentUnit = null; } public override string Name diff -r 0a2068897793 -r e6c93ceba119 API/Objects/Unit.cs --- a/API/Objects/Unit.cs Sun Apr 15 20:52:32 2012 +0100 +++ b/API/Objects/Unit.cs Mon Apr 16 20:14:23 2012 +0100 @@ -223,8 +223,13 @@ { if (!(parentUnit == value || (parentUnit != null && parentUnit.Equals(value)))) { + if (parentUnit != null) + { + parentUnit.RemoveContainedUnit(this); + } + parentUnit = value; - + if (value != null) { value.AddContainedUnit(this);