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 diff
     1.1 --- a/API/Objects/Requirement/AbstractUnitRequirement.cs	Wed May 23 20:37:23 2012 +0100
     1.2 +++ b/API/Objects/Requirement/AbstractUnitRequirement.cs	Wed May 23 20:56:27 2012 +0100
     1.3 @@ -73,17 +73,17 @@
     1.4  			return hash;
     1.5  		}
     1.6  
     1.7 -		protected virtual bool IsApplicable(IWarFoundryObject toObjectAdded, Army toArmy)
     1.8 +		protected virtual bool IsApplicable(IWarFoundryObject toObjectAdded, Army toArmy, AddingContext context)
     1.9  		{
    1.10 -			return IsApplicable(toArmy) || IsApplicable(toObjectAdded);
    1.11 +			return IsApplicable(toArmy, context) || IsApplicable(toObjectAdded, context);
    1.12  		}
    1.13  
    1.14 -		protected virtual bool IsApplicable(Army toArmy)
    1.15 +		protected virtual bool IsApplicable(Army toArmy, AddingContext context)
    1.16  		{
    1.17  			return false;
    1.18  		}
    1.19  
    1.20 -		protected virtual bool IsApplicable(IWarFoundryObject toObject)
    1.21 +		protected virtual bool IsApplicable(IWarFoundryObject toObject, AddingContext context)
    1.22  		{
    1.23  			return false;
    1.24  		}
    1.25 @@ -132,7 +132,42 @@
    1.26  
    1.27  		protected abstract string GetFailedAddingRequirementsString(IWarFoundryObject toAdd, Army toArmy);
    1.28  
    1.29 -		public abstract  Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy);
    1.30 +		/// <summary>
    1.31 +		/// Checks whether the supplied WarFoundryObject can be added to the supplied army.
    1.32 +		/// </summary>
    1.33 +		/// <returns>
    1.34 +		/// A <code>Validation</code> enum to show the result of the validation
    1.35 +		/// </returns>
    1.36 +		/// <param name='wfObject'>
    1.37 +		/// The object that we want to add. This may be involved in the check, or it may not affect the evaluation of the requirement
    1.38 +		/// </param>
    1.39 +		/// <param name='toArmy'>
    1.40 +		/// The army to add the object to.
    1.41 +		/// </param>
    1.42 +		public Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy)
    1.43 +		{
    1.44 +			return AllowsAdding(wfObject, toArmy, null);
    1.45 +		}
    1.46 +
    1.47 +		/// <summary>
    1.48 +		/// Checks whether the supplied WarFoundryObject can be added to the supplied army.
    1.49 +		/// </summary>
    1.50 +		/// <returns>
    1.51 +		/// A <code>Validation</code> enum to show the result of the validation
    1.52 +		/// </returns>
    1.53 +		/// <param name='wfObject'>
    1.54 +		/// The object that we want to add. This may be involved in the check, or it may not affect the evaluation of the requirement
    1.55 +		/// </param>
    1.56 +		/// <param name='toArmy'>
    1.57 +		/// The army to add the object to.
    1.58 +		/// </param>
    1.59 +		/// <param name='context'>The context for the action (may be null)</param>
    1.60 +		public Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy, AddingContext context)
    1.61 +		{
    1.62 +			return IsApplicable(wfObject, toArmy, context) ? CheckAllowsAdding(wfObject, toArmy, context) : Validation.NotApplicable;
    1.63 +		}
    1.64 +
    1.65 +		protected abstract Validation CheckAllowsAdding(IWarFoundryObject wfObject, Army toArmy, AddingContext context);
    1.66  
    1.67  		public abstract  Validation ValidatesArmy(Army army);
    1.68  
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/API/Objects/Requirement/AddingContext.cs	Wed May 23 20:56:27 2012 +0100
     2.3 @@ -0,0 +1,17 @@
     2.4 +// This file (AbstractRequirement.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard
     2.5 +// 
     2.6 +// 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.
     2.7 +using System;
     2.8 +using System.Collections.Generic;
     2.9 +
    2.10 +namespace IBBoard.WarFoundry.API.Objects.Requirement
    2.11 +{
    2.12 +	/// <summary>
    2.13 +	/// Marker interface (for now) of useful context information for the AllowsAdding method call.
    2.14 +	/// </summary>
    2.15 +	public interface AddingContext
    2.16 +	{
    2.17 +
    2.18 +	}
    2.19 +}
    2.20 +
     3.1 --- a/API/Objects/Requirement/RaceRequiresAtLeastNUnitsRequirement.cs	Wed May 23 20:37:23 2012 +0100
     3.2 +++ b/API/Objects/Requirement/RaceRequiresAtLeastNUnitsRequirement.cs	Wed May 23 20:56:27 2012 +0100
     3.3 @@ -20,7 +20,7 @@
     3.4  			return toArmy.Race == AllowedObject ? 1 : 0;
     3.5  		}
     3.6  
     3.7 -		protected override bool IsApplicable(Army toArmy)
     3.8 +		protected override bool IsApplicable(Army toArmy, AddingContext context)
     3.9  		{
    3.10  			bool isApplicable = false;
    3.11  			SimpleSet<UnitType> checkedTypes = new SimpleSet<UnitType>();
     4.1 --- a/API/Objects/Requirement/RaceRequiresNoMoreThanNUnitsRequirement.cs	Wed May 23 20:37:23 2012 +0100
     4.2 +++ b/API/Objects/Requirement/RaceRequiresNoMoreThanNUnitsRequirement.cs	Wed May 23 20:56:27 2012 +0100
     4.3 @@ -20,7 +20,7 @@
     4.4  			return toArmy.Race == AllowedObject ? 1 : 0;
     4.5  		}
     4.6  
     4.7 -		protected override bool IsApplicable(Army toArmy)
     4.8 +		protected override bool IsApplicable(Army toArmy, AddingContext context)
     4.9  		{
    4.10  			bool isApplicable = false;
    4.11  			SimpleSet<UnitType> checkedTypes = new SimpleSet<UnitType>();
     5.1 --- a/API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs	Wed May 23 20:37:23 2012 +0100
     5.2 +++ b/API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs	Wed May 23 20:56:27 2012 +0100
     5.3 @@ -30,29 +30,12 @@
     5.4  			}
     5.5  		}
     5.6  
     5.7 -		/// <summary>
     5.8 -		/// Checks whether the supplied WarFoundryObject can be added to the supplied army.
     5.9 -		/// </summary>
    5.10 -		/// <returns>
    5.11 -		/// A <code>Validation</code> enum to show the result of the validation
    5.12 -		/// </returns>
    5.13 -		/// <param name='wfObject'>
    5.14 -		/// The object that we want to add. This may be involved in the check, or it may not affect the evaluation of the requirement
    5.15 -		/// </param>
    5.16 -		/// <param name='toArmy'>
    5.17 -		/// The army to add the object to.
    5.18 -		/// </param>
    5.19 -		public override Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy)
    5.20 -		{
    5.21 -			return IsApplicable(wfObject, toArmy) ? CheckAllowsAdding(wfObject, toArmy) : Validation.NotApplicable;
    5.22 -		}
    5.23 -
    5.24 -		protected override bool IsApplicable(Army toArmy)
    5.25 +		protected override bool IsApplicable(Army toArmy, AddingContext context)
    5.26  		{
    5.27  			return false;
    5.28  		}
    5.29  
    5.30 -		protected override bool IsApplicable(IWarFoundryObject toObject)
    5.31 +		protected override bool IsApplicable(IWarFoundryObject toObject, AddingContext context)
    5.32  		{
    5.33  			bool isApplicable = false;
    5.34  			UnitType unitType = GetUnitTypeFromObject(toObject);
    5.35 @@ -79,7 +62,7 @@
    5.36  			return isApplicable;
    5.37  		}
    5.38  
    5.39 -		private Validation CheckAllowsAdding(IWarFoundryObject wfObject, Army toArmy)
    5.40 +		protected override Validation CheckAllowsAdding(IWarFoundryObject wfObject, Army toArmy, AddingContext context)
    5.41  		{
    5.42  			Validation isValid = Validation.Passed;
    5.43  			
     6.1 --- a/API/Objects/Requirement/RequiresNUnitsForMObjectsRequirement.cs	Wed May 23 20:37:23 2012 +0100
     6.2 +++ b/API/Objects/Requirement/RequiresNUnitsForMObjectsRequirement.cs	Wed May 23 20:56:27 2012 +0100
     6.3 @@ -64,7 +64,7 @@
     6.4  			return normalisedLimited >= 1 && normalisedAllowed <= normalisedLimited;
     6.5  		}
     6.6  
     6.7 -		public override Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy)
     6.8 +		protected override Validation CheckAllowsAdding(IWarFoundryObject wfObject, Army toArmy, AddingContext context)
     6.9  		{
    6.10  			Validation canAdd = Validation.NotApplicable;
    6.11  			UnitType addedUnitType = (wfObject is Unit) ? ((Unit)wfObject).UnitType : wfObject as UnitType;
     7.1 --- a/API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs	Wed May 23 20:37:23 2012 +0100
     7.2 +++ b/API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs	Wed May 23 20:56:27 2012 +0100
     7.3 @@ -28,29 +28,12 @@
     7.4  			}
     7.5  		}
     7.6  
     7.7 -		/// <summary>
     7.8 -		/// Checks whether the supplied WarFoundryObject can be added to the supplied army.
     7.9 -		/// </summary>
    7.10 -		/// <returns>
    7.11 -		/// A <code>Validation</code> enum to show the result of the validation
    7.12 -		/// </returns>
    7.13 -		/// <param name='wfObject'>
    7.14 -		/// The object that we want to add. This may be involved in the check, or it may not affect the evaluation of the requirement
    7.15 -		/// </param>
    7.16 -		/// <param name='toArmy'>
    7.17 -		/// The army to add the object to.
    7.18 -		/// </param>
    7.19 -		public override Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy)
    7.20 -		{
    7.21 -			return IsApplicable(wfObject, toArmy) ? CheckAllowsAdding(wfObject, toArmy) : Validation.NotApplicable;
    7.22 -		}
    7.23 -
    7.24 -		protected override bool IsApplicable(Army toArmy)
    7.25 +		protected override bool IsApplicable(Army toArmy, AddingContext context)
    7.26  		{
    7.27  			return false;
    7.28  		}
    7.29  
    7.30 -		protected override bool IsApplicable(IWarFoundryObject toObject)
    7.31 +		protected override bool IsApplicable(IWarFoundryObject toObject, AddingContext context)
    7.32  		{
    7.33  			bool isApplicable = false;
    7.34  			UnitType unitType = GetUnitTypeFromObject(toObject);
    7.35 @@ -77,7 +60,7 @@
    7.36  			return isApplicable;
    7.37  		}
    7.38  
    7.39 -		private Validation CheckAllowsAdding(IWarFoundryObject wfObject, Army toArmy)
    7.40 +		protected override Validation CheckAllowsAdding(IWarFoundryObject wfObject, Army toArmy, AddingContext context)
    7.41  		{
    7.42  			Validation canAdd = Validation.Passed;
    7.43  			
     8.1 --- a/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirement.cs	Wed May 23 20:37:23 2012 +0100
     8.2 +++ b/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirement.cs	Wed May 23 20:56:27 2012 +0100
     8.3 @@ -16,17 +16,12 @@
     8.4  		{
     8.5  		}
     8.6  
     8.7 -		public override Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy)
     8.8 +		protected override bool IsApplicable(IWarFoundryObject toObject, Army toArmy, AddingContext context)
     8.9  		{
    8.10 -			return IsApplicable(wfObject, toArmy) ? base.AllowsAdding(wfObject, toArmy) : Validation.NotApplicable;
    8.11 +			return IsApplicable(toObject, context) || IsApplicableForRequiredType(toObject, toArmy);
    8.12  		}
    8.13  
    8.14 -		protected override bool IsApplicable(IWarFoundryObject toObject, Army toArmy)
    8.15 -		{
    8.16 -			return IsApplicable(toObject) || IsApplicableForRequiredType(toObject, toArmy);
    8.17 -		}
    8.18 -
    8.19 -		protected override bool IsApplicable(IWarFoundryObject toObject)
    8.20 +		protected override bool IsApplicable(IWarFoundryObject toObject, AddingContext context)
    8.21  		{
    8.22  			return AllowedObject.Equals(toObject) || (toObject is Unit && AllowedObject.Equals(((Unit)toObject).UnitType));
    8.23  		}
     9.1 --- a/API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirement.cs	Wed May 23 20:37:23 2012 +0100
     9.2 +++ b/API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirement.cs	Wed May 23 20:56:27 2012 +0100
     9.3 @@ -20,29 +20,12 @@
     9.4  			//Do nothing
     9.5  		}
     9.6  
     9.7 -		/// <summary>
     9.8 -		/// Checks whether the supplied WarFoundryObject can be added to the supplied army.
     9.9 -		/// </summary>
    9.10 -		/// <returns>
    9.11 -		/// A <code>Validation</code> enum to show the result of the validation
    9.12 -		/// </returns>
    9.13 -		/// <param name='wfObject'>
    9.14 -		/// The object that we want to add. This may be involved in the check, or it may not affect the evaluation of the requirement
    9.15 -		/// </param>
    9.16 -		/// <param name='toArmy'>
    9.17 -		/// The army to add the object to.
    9.18 -		/// </param>
    9.19 -		public override Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy)
    9.20 +		protected override bool IsApplicable(IWarFoundryObject toObject, Army toArmy, AddingContext context)
    9.21  		{
    9.22 -			return IsApplicable(wfObject, toArmy) ? base.AllowsAdding(wfObject, toArmy) : Validation.NotApplicable;
    9.23 +			return IsApplicable(toObject, context) || IsApplicableForRequiredType(toObject, toArmy);
    9.24  		}
    9.25  
    9.26 -		protected override bool IsApplicable(IWarFoundryObject toObject, Army toArmy)
    9.27 -		{
    9.28 -			return IsApplicable(toObject) || IsApplicableForRequiredType(toObject, toArmy);
    9.29 -		}
    9.30 -
    9.31 -		protected override bool IsApplicable(IWarFoundryObject toObject)
    9.32 +		protected override bool IsApplicable(IWarFoundryObject toObject, AddingContext context)
    9.33  		{
    9.34  			return AllowedObject.Equals(toObject) || (toObject is Unit && AllowedObject.Equals(((Unit)toObject).UnitType));
    9.35  		}
    10.1 --- a/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirement.cs	Wed May 23 20:37:23 2012 +0100
    10.2 +++ b/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirement.cs	Wed May 23 20:56:27 2012 +0100
    10.3 @@ -17,12 +17,12 @@
    10.4  			//Do nothing special
    10.5  		}
    10.6  
    10.7 -		protected override bool IsApplicable(IWarFoundryObject toObject, Army toArmy)
    10.8 +		protected override bool IsApplicable(IWarFoundryObject toObject, Army toArmy, AddingContext context)
    10.9  		{
   10.10 -			return base.IsApplicable(toObject, toArmy) || IsApplicableForRequiredType(toObject, toArmy);
   10.11 +			return base.IsApplicable(toObject, toArmy, context) || IsApplicableForRequiredType(toObject, toArmy);
   10.12  		}
   10.13  
   10.14 -		protected override bool IsApplicable(IWarFoundryObject toObject)
   10.15 +		protected override bool IsApplicable(IWarFoundryObject toObject, AddingContext context)
   10.16  		{
   10.17  			return AllowedObject.Equals(toObject) || (toObject is Unit && AllowedObject.Equals(((Unit)toObject).UnitType));
   10.18  		}
    11.1 --- a/IBBoard.WarFoundry.API.csproj	Wed May 23 20:37:23 2012 +0100
    11.2 +++ b/IBBoard.WarFoundry.API.csproj	Wed May 23 20:56:27 2012 +0100
    11.3 @@ -196,6 +196,7 @@
    11.4      <Compile Include="API\Objects\Requirement\AbstractUnitRequirement.cs" />
    11.5      <Compile Include="API\Objects\Requirement\RaceRequiresAtLeastNUnitsRequirement.cs" />
    11.6      <Compile Include="API\Objects\Requirement\RaceRequiresNoMoreThanNUnitsRequirement.cs" />
    11.7 +    <Compile Include="API\Objects\Requirement\AddingContext.cs" />
    11.8    </ItemGroup>
    11.9    <ItemGroup>
   11.10      <Reference Include="System.Xml" />