changeset 335:36be56d9b9c4

Re #27: Define unit requirements * Copy and paste first requirement that does "requirement for unit type"
author IBBoard <dev@ibboard.co.uk>
date Sat, 02 Apr 2011 20:06:50 +0000
parents f56254f50ce5
children 3631c1493c7f
files IBBoard.WarFoundry.API.csproj api/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs api/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirement.cs
diffstat 3 files changed, 47 insertions(+), 1 deletions(-) [+]
line diff
     1.1 --- a/IBBoard.WarFoundry.API.csproj	Wed Mar 30 19:09:28 2011 +0000
     1.2 +++ b/IBBoard.WarFoundry.API.csproj	Sat Apr 02 20:06:50 2011 +0000
     1.3 @@ -188,6 +188,7 @@
     1.4      <Compile Include="api\Objects\Requirement\RequiresAtLeastNUnitsRequirement.cs" />
     1.5      <Compile Include="api\Objects\Requirement\UnitCountRequirementData.cs" />
     1.6      <Compile Include="api\Objects\Requirement\RequiresNoMoreThanNOfUnitTypeRequirement.cs" />
     1.7 +    <Compile Include="api\Objects\Requirement\UnitRequiresAtLeastNUnitsRequirement.cs" />
     1.8    </ItemGroup>
     1.9    <ItemGroup>
    1.10      <Reference Include="System.Xml" />
     2.1 --- a/api/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs	Wed Mar 30 19:09:28 2011 +0000
     2.2 +++ b/api/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs	Sat Apr 02 20:06:50 2011 +0000
     2.3 @@ -36,7 +36,7 @@
     2.4  		/// <param name='toArmy'>
     2.5  		/// The army to add the object to.
     2.6  		/// </param>
     2.7 -		public bool AllowsAdding(WarFoundryObject wfObject, Army toArmy)
     2.8 +		public virtual bool AllowsAdding(WarFoundryObject wfObject, Army toArmy)
     2.9  		{
    2.10  			return this.ValidatesArmy(toArmy);
    2.11  		}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/api/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirement.cs	Sat Apr 02 20:06:50 2011 +0000
     3.3 @@ -0,0 +1,45 @@
     3.4 +// This file (UnitRequiresAtLeastNUnitsRequirement.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard
     3.5 +// 
     3.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.
     3.7 +using System;
     3.8 +using System.Collections.Generic;
     3.9 +using IBBoard.WarFoundry.API.Objects;
    3.10 +
    3.11 +namespace IBBoard.WarFoundry.API.Objects.Requirement
    3.12 +{
    3.13 +	/// <summary>
    3.14 +	/// A requirement where a UnitType requires at least N units of one or more unit types before any number of that object can be taken in an army.
    3.15 +	/// </summary>
    3.16 +	public class UnitRequiresAtLeastNUnitsRequirement : RequiresAtLeastNUnitsRequirement
    3.17 +	{
    3.18 +		private UnitType requirementOnType;
    3.19 +
    3.20 +		public UnitRequiresAtLeastNUnitsRequirement(UnitType requirementOn) : base()
    3.21 +		{
    3.22 +			requirementOnType = requirementOn;
    3.23 +		}
    3.24 +
    3.25 +		/// <summary>
    3.26 +		/// Checks whether the supplied WarFoundryObject can be added to the supplied army.
    3.27 +		/// </summary>
    3.28 +		/// <returns>
    3.29 +		/// <c>true</c> if the object can be added, else <c>false</c>
    3.30 +		/// </returns>
    3.31 +		/// <param name='wfObject'>
    3.32 +		/// The object that we want to add. This may be involved in the check, or it may not affect the evaluation of the requirement
    3.33 +		/// </param>
    3.34 +		/// <param name='toArmy'>
    3.35 +		/// The army to add the object to.
    3.36 +		/// </param>
    3.37 +		public override bool AllowsAdding(WarFoundryObject wfObject, Army toArmy)
    3.38 +		{
    3.39 +			return IsApplicable(wfObject, toArmy) ? base.ValidatesArmy(toArmy) : true;
    3.40 +		}
    3.41 +
    3.42 +		public bool IsApplicable (WarFoundryObject wfObject, Army toArmy)
    3.43 +		{
    3.44 +			return toArmy.GetUnitTypeCount(requirementOnType) > 0 || requirementOnType.Equals(wfObject) || (wfObject is Unit && requirementOnType.Equals(((Unit)wfObject).UnitType));
    3.45 +		}
    3.46 +	}
    3.47 +}
    3.48 +