changeset 330:8ca5dd75d5b8

Re #27: Define unit requirements * Rename class to match behaviour (no longer just units) * Move to correct package
author IBBoard <dev@ibboard.co.uk>
date Sun, 27 Mar 2011 19:36:54 +0000
parents a5b34ca10d80
children e1d1b81b192a
files IBBoard.WarFoundry.API.csproj api/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs api/Objects/UnitRequiresAtLeastNUnitsRequirement.cs
diffstat 3 files changed, 52 insertions(+), 52 deletions(-) [+]
line diff
     1.1 --- a/IBBoard.WarFoundry.API.csproj	Sun Mar 27 19:15:31 2011 +0000
     1.2 +++ b/IBBoard.WarFoundry.API.csproj	Sun Mar 27 19:36:54 2011 +0000
     1.3 @@ -185,7 +185,7 @@
     1.4      <Compile Include="api\Savers\Xml\WarFoundryXmlArmySaver.cs" />
     1.5      <Compile Include="api\Savers\Xml\WarFoundryXmlGameSystemSaver.cs" />
     1.6      <Compile Include="api\Savers\Xml\WarFoundryXmlFileSaver.cs" />
     1.7 -    <Compile Include="api\Objects\UnitRequiresAtLeastNUnitsRequirement.cs" />
     1.8 +    <Compile Include="api\Objects\Requirement\RequiresAtLeastNUnitsRequirement.cs" />
     1.9    </ItemGroup>
    1.10    <ItemGroup>
    1.11      <Reference Include="System.Xml" />
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/api/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs	Sun Mar 27 19:36:54 2011 +0000
     2.3 @@ -0,0 +1,51 @@
     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
    2.12 +{
    2.13 +	/// <summary>
    2.14 +	/// A requirement where a WarFoundryObject requires at least N units of one or more unit types before it can be taken in an army.
    2.15 +	/// </summary>
    2.16 +	public class RequiresAtLeastNUnitsRequirement
    2.17 +	{
    2.18 +		private List<UnitType> requiredTypes;
    2.19 +
    2.20 +		public RequiresAtLeastNUnitsRequirement(params UnitType[] requiredUnitTypes)
    2.21 +		{
    2.22 +			requiredTypes = new List<UnitType>(requiredUnitTypes);
    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 +		/// <c>true</c> if the object can be added, else <c>false</c>
    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 bool AllowsAdding(WarFoundryObject wfObject, Army toArmy)
    2.38 +		{
    2.39 +			bool canAdd = true;
    2.40 +
    2.41 +			foreach (UnitType type in requiredTypes)
    2.42 +			{
    2.43 +				if (toArmy.GetUnitTypeCount(type) < 1)
    2.44 +				{
    2.45 +					canAdd = false;
    2.46 +					break;
    2.47 +				}
    2.48 +			}
    2.49 +
    2.50 +			return canAdd;
    2.51 +		}
    2.52 +	}
    2.53 +}
    2.54 +
     3.1 --- a/api/Objects/UnitRequiresAtLeastNUnitsRequirement.cs	Sun Mar 27 19:15:31 2011 +0000
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,51 +0,0 @@
     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
    3.12 -{
    3.13 -	/// <summary>
    3.14 -	/// A requirement where a Unit requires at least N units of one or more unit types before it can be taken.
    3.15 -	/// </summary>
    3.16 -	public class UnitRequiresAtLeastNUnitsRequirement
    3.17 -	{
    3.18 -		private List<UnitType> requiredTypes;
    3.19 -
    3.20 -		public UnitRequiresAtLeastNUnitsRequirement(params UnitType[] requiredUnitTypes)
    3.21 -		{
    3.22 -			requiredTypes = new List<UnitType>(requiredUnitTypes);
    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 bool AllowsAdding(WarFoundryObject wfObject, Army toArmy)
    3.38 -		{
    3.39 -			bool canAdd = true;
    3.40 -
    3.41 -			foreach (UnitType type in requiredTypes)
    3.42 -			{
    3.43 -				if (toArmy.GetUnitTypeCount(type) < 1)
    3.44 -				{
    3.45 -					canAdd = false;
    3.46 -					break;
    3.47 -				}
    3.48 -			}
    3.49 -
    3.50 -			return canAdd;
    3.51 -		}
    3.52 -	}
    3.53 -}
    3.54 -