Mercurial > repos > IBBoard.WarFoundry.API
changeset 479:f48c49b53738
Re #410: "N units per M models in parent" requirement
* Add a "context" object that will hold the parent unit (or possibly other stuff)
* Update all method signatures and calls
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 23 May 2012 20:56:27 +0100 |
parents | e4e2a85604b6 |
children | e0641e0eb86c |
files | API/Objects/Requirement/AbstractUnitRequirement.cs API/Objects/Requirement/AddingContext.cs API/Objects/Requirement/RaceRequiresAtLeastNUnitsRequirement.cs API/Objects/Requirement/RaceRequiresNoMoreThanNUnitsRequirement.cs API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs API/Objects/Requirement/RequiresNUnitsForMObjectsRequirement.cs API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirement.cs API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirement.cs API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirement.cs IBBoard.WarFoundry.API.csproj |
diffstat | 11 files changed, 76 insertions(+), 79 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Objects/Requirement/AbstractUnitRequirement.cs Wed May 23 20:37:23 2012 +0100 +++ b/API/Objects/Requirement/AbstractUnitRequirement.cs Wed May 23 20:56:27 2012 +0100 @@ -73,17 +73,17 @@ return hash; } - protected virtual bool IsApplicable(IWarFoundryObject toObjectAdded, Army toArmy) + protected virtual bool IsApplicable(IWarFoundryObject toObjectAdded, Army toArmy, AddingContext context) { - return IsApplicable(toArmy) || IsApplicable(toObjectAdded); + return IsApplicable(toArmy, context) || IsApplicable(toObjectAdded, context); } - protected virtual bool IsApplicable(Army toArmy) + protected virtual bool IsApplicable(Army toArmy, AddingContext context) { return false; } - protected virtual bool IsApplicable(IWarFoundryObject toObject) + protected virtual bool IsApplicable(IWarFoundryObject toObject, AddingContext context) { return false; } @@ -132,7 +132,42 @@ protected abstract string GetFailedAddingRequirementsString(IWarFoundryObject toAdd, Army toArmy); - public abstract Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy); + /// <summary> + /// Checks whether the supplied WarFoundryObject can be added to the supplied army. + /// </summary> + /// <returns> + /// A <code>Validation</code> enum to show the result of the validation + /// </returns> + /// <param name='wfObject'> + /// The object that we want to add. This may be involved in the check, or it may not affect the evaluation of the requirement + /// </param> + /// <param name='toArmy'> + /// The army to add the object to. + /// </param> + public Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy) + { + return AllowsAdding(wfObject, toArmy, null); + } + + /// <summary> + /// Checks whether the supplied WarFoundryObject can be added to the supplied army. + /// </summary> + /// <returns> + /// A <code>Validation</code> enum to show the result of the validation + /// </returns> + /// <param name='wfObject'> + /// The object that we want to add. This may be involved in the check, or it may not affect the evaluation of the requirement + /// </param> + /// <param name='toArmy'> + /// The army to add the object to. + /// </param> + /// <param name='context'>The context for the action (may be null)</param> + public Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy, AddingContext context) + { + return IsApplicable(wfObject, toArmy, context) ? CheckAllowsAdding(wfObject, toArmy, context) : Validation.NotApplicable; + } + + protected abstract Validation CheckAllowsAdding(IWarFoundryObject wfObject, Army toArmy, AddingContext context); public abstract Validation ValidatesArmy(Army army);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/API/Objects/Requirement/AddingContext.cs Wed May 23 20:56:27 2012 +0100 @@ -0,0 +1,17 @@ +// This file (AbstractRequirement.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard +// +// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. +using System; +using System.Collections.Generic; + +namespace IBBoard.WarFoundry.API.Objects.Requirement +{ + /// <summary> + /// Marker interface (for now) of useful context information for the AllowsAdding method call. + /// </summary> + public interface AddingContext + { + + } +} +
--- a/API/Objects/Requirement/RaceRequiresAtLeastNUnitsRequirement.cs Wed May 23 20:37:23 2012 +0100 +++ b/API/Objects/Requirement/RaceRequiresAtLeastNUnitsRequirement.cs Wed May 23 20:56:27 2012 +0100 @@ -20,7 +20,7 @@ return toArmy.Race == AllowedObject ? 1 : 0; } - protected override bool IsApplicable(Army toArmy) + protected override bool IsApplicable(Army toArmy, AddingContext context) { bool isApplicable = false; SimpleSet<UnitType> checkedTypes = new SimpleSet<UnitType>();
--- a/API/Objects/Requirement/RaceRequiresNoMoreThanNUnitsRequirement.cs Wed May 23 20:37:23 2012 +0100 +++ b/API/Objects/Requirement/RaceRequiresNoMoreThanNUnitsRequirement.cs Wed May 23 20:56:27 2012 +0100 @@ -20,7 +20,7 @@ return toArmy.Race == AllowedObject ? 1 : 0; } - protected override bool IsApplicable(Army toArmy) + protected override bool IsApplicable(Army toArmy, AddingContext context) { bool isApplicable = false; SimpleSet<UnitType> checkedTypes = new SimpleSet<UnitType>();
--- a/API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs Wed May 23 20:37:23 2012 +0100 +++ b/API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs Wed May 23 20:56:27 2012 +0100 @@ -30,29 +30,12 @@ } } - /// <summary> - /// Checks whether the supplied WarFoundryObject can be added to the supplied army. - /// </summary> - /// <returns> - /// A <code>Validation</code> enum to show the result of the validation - /// </returns> - /// <param name='wfObject'> - /// The object that we want to add. This may be involved in the check, or it may not affect the evaluation of the requirement - /// </param> - /// <param name='toArmy'> - /// The army to add the object to. - /// </param> - public override Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy) - { - return IsApplicable(wfObject, toArmy) ? CheckAllowsAdding(wfObject, toArmy) : Validation.NotApplicable; - } - - protected override bool IsApplicable(Army toArmy) + protected override bool IsApplicable(Army toArmy, AddingContext context) { return false; } - protected override bool IsApplicable(IWarFoundryObject toObject) + protected override bool IsApplicable(IWarFoundryObject toObject, AddingContext context) { bool isApplicable = false; UnitType unitType = GetUnitTypeFromObject(toObject); @@ -79,7 +62,7 @@ return isApplicable; } - private Validation CheckAllowsAdding(IWarFoundryObject wfObject, Army toArmy) + protected override Validation CheckAllowsAdding(IWarFoundryObject wfObject, Army toArmy, AddingContext context) { Validation isValid = Validation.Passed;
--- a/API/Objects/Requirement/RequiresNUnitsForMObjectsRequirement.cs Wed May 23 20:37:23 2012 +0100 +++ b/API/Objects/Requirement/RequiresNUnitsForMObjectsRequirement.cs Wed May 23 20:56:27 2012 +0100 @@ -64,7 +64,7 @@ return normalisedLimited >= 1 && normalisedAllowed <= normalisedLimited; } - public override Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy) + protected override Validation CheckAllowsAdding(IWarFoundryObject wfObject, Army toArmy, AddingContext context) { Validation canAdd = Validation.NotApplicable; UnitType addedUnitType = (wfObject is Unit) ? ((Unit)wfObject).UnitType : wfObject as UnitType;
--- a/API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs Wed May 23 20:37:23 2012 +0100 +++ b/API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs Wed May 23 20:56:27 2012 +0100 @@ -28,29 +28,12 @@ } } - /// <summary> - /// Checks whether the supplied WarFoundryObject can be added to the supplied army. - /// </summary> - /// <returns> - /// A <code>Validation</code> enum to show the result of the validation - /// </returns> - /// <param name='wfObject'> - /// The object that we want to add. This may be involved in the check, or it may not affect the evaluation of the requirement - /// </param> - /// <param name='toArmy'> - /// The army to add the object to. - /// </param> - public override Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy) - { - return IsApplicable(wfObject, toArmy) ? CheckAllowsAdding(wfObject, toArmy) : Validation.NotApplicable; - } - - protected override bool IsApplicable(Army toArmy) + protected override bool IsApplicable(Army toArmy, AddingContext context) { return false; } - protected override bool IsApplicable(IWarFoundryObject toObject) + protected override bool IsApplicable(IWarFoundryObject toObject, AddingContext context) { bool isApplicable = false; UnitType unitType = GetUnitTypeFromObject(toObject); @@ -77,7 +60,7 @@ return isApplicable; } - private Validation CheckAllowsAdding(IWarFoundryObject wfObject, Army toArmy) + protected override Validation CheckAllowsAdding(IWarFoundryObject wfObject, Army toArmy, AddingContext context) { Validation canAdd = Validation.Passed;
--- a/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirement.cs Wed May 23 20:37:23 2012 +0100 +++ b/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirement.cs Wed May 23 20:56:27 2012 +0100 @@ -16,17 +16,12 @@ { } - public override Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy) + protected override bool IsApplicable(IWarFoundryObject toObject, Army toArmy, AddingContext context) { - return IsApplicable(wfObject, toArmy) ? base.AllowsAdding(wfObject, toArmy) : Validation.NotApplicable; + return IsApplicable(toObject, context) || IsApplicableForRequiredType(toObject, toArmy); } - protected override bool IsApplicable(IWarFoundryObject toObject, Army toArmy) - { - return IsApplicable(toObject) || IsApplicableForRequiredType(toObject, toArmy); - } - - protected override bool IsApplicable(IWarFoundryObject toObject) + protected override bool IsApplicable(IWarFoundryObject toObject, AddingContext context) { return AllowedObject.Equals(toObject) || (toObject is Unit && AllowedObject.Equals(((Unit)toObject).UnitType)); }
--- a/API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirement.cs Wed May 23 20:37:23 2012 +0100 +++ b/API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirement.cs Wed May 23 20:56:27 2012 +0100 @@ -20,29 +20,12 @@ //Do nothing } - /// <summary> - /// Checks whether the supplied WarFoundryObject can be added to the supplied army. - /// </summary> - /// <returns> - /// A <code>Validation</code> enum to show the result of the validation - /// </returns> - /// <param name='wfObject'> - /// The object that we want to add. This may be involved in the check, or it may not affect the evaluation of the requirement - /// </param> - /// <param name='toArmy'> - /// The army to add the object to. - /// </param> - public override Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy) + protected override bool IsApplicable(IWarFoundryObject toObject, Army toArmy, AddingContext context) { - return IsApplicable(wfObject, toArmy) ? base.AllowsAdding(wfObject, toArmy) : Validation.NotApplicable; + return IsApplicable(toObject, context) || IsApplicableForRequiredType(toObject, toArmy); } - protected override bool IsApplicable(IWarFoundryObject toObject, Army toArmy) - { - return IsApplicable(toObject) || IsApplicableForRequiredType(toObject, toArmy); - } - - protected override bool IsApplicable(IWarFoundryObject toObject) + protected override bool IsApplicable(IWarFoundryObject toObject, AddingContext context) { return AllowedObject.Equals(toObject) || (toObject is Unit && AllowedObject.Equals(((Unit)toObject).UnitType)); }
--- a/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirement.cs Wed May 23 20:37:23 2012 +0100 +++ b/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirement.cs Wed May 23 20:56:27 2012 +0100 @@ -17,12 +17,12 @@ //Do nothing special } - protected override bool IsApplicable(IWarFoundryObject toObject, Army toArmy) + protected override bool IsApplicable(IWarFoundryObject toObject, Army toArmy, AddingContext context) { - return base.IsApplicable(toObject, toArmy) || IsApplicableForRequiredType(toObject, toArmy); + return base.IsApplicable(toObject, toArmy, context) || IsApplicableForRequiredType(toObject, toArmy); } - protected override bool IsApplicable(IWarFoundryObject toObject) + protected override bool IsApplicable(IWarFoundryObject toObject, AddingContext context) { return AllowedObject.Equals(toObject) || (toObject is Unit && AllowedObject.Equals(((Unit)toObject).UnitType)); }
--- a/IBBoard.WarFoundry.API.csproj Wed May 23 20:37:23 2012 +0100 +++ b/IBBoard.WarFoundry.API.csproj Wed May 23 20:56:27 2012 +0100 @@ -196,6 +196,7 @@ <Compile Include="API\Objects\Requirement\AbstractUnitRequirement.cs" /> <Compile Include="API\Objects\Requirement\RaceRequiresAtLeastNUnitsRequirement.cs" /> <Compile Include="API\Objects\Requirement\RaceRequiresNoMoreThanNUnitsRequirement.cs" /> + <Compile Include="API\Objects\Requirement\AddingContext.cs" /> </ItemGroup> <ItemGroup> <Reference Include="System.Xml" />