changeset 343:acd390dba551

Re #27: Unit requirements * First draft of "Unit requires no more than X" requirement
author IBBoard <dev@ibboard.co.uk>
date Wed, 06 Apr 2011 20:05:46 +0000
parents 407757e597f9
children 8585dfacac3b
files API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirement.cs IBBoard.WarFoundry.API.csproj
diffstat 3 files changed, 60 insertions(+), 2 deletions(-) [+]
line diff
     1.1 --- a/API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs	Mon Apr 04 19:45:38 2011 +0000
     1.2 +++ b/API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs	Wed Apr 06 20:05:46 2011 +0000
     1.3 @@ -36,7 +36,7 @@
     1.4  		/// <param name='toArmy'>
     1.5  		/// The army to add the object to.
     1.6  		/// </param>
     1.7 -		public Validation AllowsAdding(WarFoundryObject wfObject, Army toArmy)
     1.8 +		public virtual Validation AllowsAdding(WarFoundryObject wfObject, Army toArmy)
     1.9  		{
    1.10  			Validation canAdd = Validation.Passed;
    1.11  			
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirement.cs	Wed Apr 06 20:05:46 2011 +0000
     2.3 @@ -0,0 +1,58 @@
     2.4 +// This file (UnitRequiresAtLeastNUnitsRequirement.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 +using IBBoard.WarFoundry.API.Objects;
    2.10 +
    2.11 +namespace IBBoard.WarFoundry.API.Objects.Requirement
    2.12 +{
    2.13 +	/// <summary>
    2.14 +	/// A requirement where a UnitType can only be taken if there are no more than N units of one or more unit in an army.
    2.15 +	/// </summary>
    2.16 +	public class UnitRequiresNoMoreThanNOfUnitTypeRequirement : RequiresNoMoreThanNOfUnitTypeRequirement
    2.17 +	{
    2.18 +		private UnitType requirementOnType;
    2.19 +
    2.20 +		public UnitRequiresNoMoreThanNOfUnitTypeRequirement(UnitType requirementOn) : base()
    2.21 +		{
    2.22 +			requirementOnType = requirementOn;
    2.23 +		}
    2.24 +
    2.25 +		/// <summary>
    2.26 +		/// Checks whether the supplied WarFoundryObject can be added to the supplied army.
    2.27 +		/// </summary>
    2.28 +		/// <returns>
    2.29 +		/// A <code>Validation</code> enum to show the result of the validation
    2.30 +		/// </returns>
    2.31 +		/// <param name='wfObject'>
    2.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
    2.33 +		/// </param>
    2.34 +		/// <param name='toArmy'>
    2.35 +		/// The army to add the object to.
    2.36 +		/// </param>
    2.37 +		public override Validation AllowsAdding(WarFoundryObject wfObject, Army toArmy)
    2.38 +		{
    2.39 +			return IsApplicable(wfObject, toArmy) ? base.AllowsAdding(wfObject, toArmy) : Validation.NotApplicable;
    2.40 +		}
    2.41 +
    2.42 +
    2.43 +		private bool IsApplicable(WarFoundryObject toObject, Army toArmy)
    2.44 +		{
    2.45 +			return IsApplicable(toArmy) || IsApplicable(toObject);
    2.46 +		}
    2.47 +
    2.48 +
    2.49 +		private bool IsApplicable(Army toArmy)
    2.50 +		{
    2.51 +			return toArmy.GetUnitTypeCount(requirementOnType) > 0;
    2.52 +		}
    2.53 +
    2.54 +
    2.55 +		private bool IsApplicable(WarFoundryObject toObject)
    2.56 +		{
    2.57 +			return requirementOnType.Equals(toObject) || (toObject is Unit && requirementOnType.Equals(((Unit)toObject).UnitType));
    2.58 +		}
    2.59 +	}
    2.60 +}
    2.61 +
     3.1 --- a/IBBoard.WarFoundry.API.csproj	Mon Apr 04 19:45:38 2011 +0000
     3.2 +++ b/IBBoard.WarFoundry.API.csproj	Wed Apr 06 20:05:46 2011 +0000
     3.3 @@ -16,7 +16,6 @@
     3.4      <UpgradeBackupLocation>
     3.5      </UpgradeBackupLocation>
     3.6      <IsWebBootstrapper>false</IsWebBootstrapper>
     3.7 -    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
     3.8      <TargetFrameworkSubset>
     3.9      </TargetFrameworkSubset>
    3.10      <PublishUrl>publish\</PublishUrl>
    3.11 @@ -190,6 +189,7 @@
    3.12      <Compile Include="API\Objects\Requirement\RequiresNoMoreThanNOfUnitTypeRequirement.cs" />
    3.13      <Compile Include="API\Objects\Requirement\UnitRequiresAtLeastNUnitsRequirement.cs" />
    3.14      <Compile Include="API\Objects\Requirement\Validation.cs" />
    3.15 +    <Compile Include="API\Objects\Requirement\UnitRequiresNoMoreThanNOfUnitTypeRequirement.cs" />
    3.16    </ItemGroup>
    3.17    <ItemGroup>
    3.18      <Reference Include="System.Xml" />