changeset 334:f56254f50ce5

Re #27: Define unit requirements * Make use of default value in "Requires at least N" * Add initial implementation of "No more than N"
author IBBoard <dev@ibboard.co.uk>
date Wed, 30 Mar 2011 19:09:28 +0000
parents 17d8d357467e
children 36be56d9b9c4
files IBBoard.WarFoundry.API.csproj api/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs api/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs
diffstat 3 files changed, 72 insertions(+), 1 deletions(-) [+]
line diff
     1.1 --- a/IBBoard.WarFoundry.API.csproj	Tue Mar 29 19:53:13 2011 +0000
     1.2 +++ b/IBBoard.WarFoundry.API.csproj	Wed Mar 30 19:09:28 2011 +0000
     1.3 @@ -187,6 +187,7 @@
     1.4      <Compile Include="api\Savers\Xml\WarFoundryXmlFileSaver.cs" />
     1.5      <Compile Include="api\Objects\Requirement\RequiresAtLeastNUnitsRequirement.cs" />
     1.6      <Compile Include="api\Objects\Requirement\UnitCountRequirementData.cs" />
     1.7 +    <Compile Include="api\Objects\Requirement\RequiresNoMoreThanNOfUnitTypeRequirement.cs" />
     1.8    </ItemGroup>
     1.9    <ItemGroup>
    1.10      <Reference Include="System.Xml" />
     2.1 --- a/api/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs	Tue Mar 29 19:53:13 2011 +0000
     2.2 +++ b/api/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs	Wed Mar 30 19:09:28 2011 +0000
     2.3 @@ -20,7 +20,7 @@
     2.4  
     2.5  			foreach (UnitType unitType in requiredUnitTypes)
     2.6  			{
     2.7 -				AddUnitTypeRequirement(unitType, 1);
     2.8 +				AddUnitTypeRequirement(unitType);
     2.9  			}
    2.10  		}
    2.11  
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/api/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs	Wed Mar 30 19:09:28 2011 +0000
     3.3 @@ -0,0 +1,70 @@
     3.4 +// This file (RequiresNoMoreThanNOfUnitTypeRequirement.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 IBBoard.WarFoundry.API.Objects;
     3.9 +using System.Collections.Generic;
    3.10 +
    3.11 +namespace IBBoard.WarFoundry.API.Objects.Requirement
    3.12 +{
    3.13 +	/// <summary>
    3.14 +	/// A requirement where a WarFoundryObject cannot be taken in an army if more than N of a UnitType will be in the army.
    3.15 +	/// </summary>
    3.16 +	public class RequiresNoMoreThanNOfUnitTypeRequirement
    3.17 +	{
    3.18 +		private List<UnitCountRequirementData> limitedTypes;
    3.19 +
    3.20 +		public RequiresNoMoreThanNOfUnitTypeRequirement(params UnitType[] limitedUnitTypes)
    3.21 +		{
    3.22 +			limitedTypes = new List<UnitCountRequirementData>();
    3.23 +
    3.24 +			foreach (UnitType unitType in limitedUnitTypes)
    3.25 +			{
    3.26 +				AddUnitTypeRequirement(unitType, 0);
    3.27 +			}
    3.28 +		}
    3.29 +
    3.30 +		/// <summary>
    3.31 +		/// Checks whether the supplied WarFoundryObject can be added to the supplied army.
    3.32 +		/// </summary>
    3.33 +		/// <returns>
    3.34 +		/// <c>true</c> if the object can be added, else <c>false</c>
    3.35 +		/// </returns>
    3.36 +		/// <param name='wfObject'>
    3.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
    3.38 +		/// </param>
    3.39 +		/// <param name='toArmy'>
    3.40 +		/// The army to add the object to.
    3.41 +		/// </param>
    3.42 +		public bool AllowsAdding(WarFoundryObject wfObject, Army toArmy)
    3.43 +		{
    3.44 +			bool canAdd = true;
    3.45 +
    3.46 +			foreach (UnitCountRequirementData limit in limitedTypes)
    3.47 +			{
    3.48 +				if (toArmy.GetUnitTypeCount(limit.UnitType) > limit.Count)
    3.49 +				{
    3.50 +					canAdd = false;
    3.51 +					break;
    3.52 +				}
    3.53 +			}
    3.54 +
    3.55 +			return canAdd;
    3.56 +		}
    3.57 +
    3.58 +		/// <summary>
    3.59 +		/// Adds a requirement for there to be at least minCount of a given UnitType
    3.60 +		/// </summary>
    3.61 +		/// <param name='unitType'>
    3.62 +		/// The unit type to require.
    3.63 +		/// </param>
    3.64 +		/// <param name='minCount'>
    3.65 +		/// The minimum number of that type that must exist.
    3.66 +		/// </param>
    3.67 +		public void AddUnitTypeRequirement(UnitType unitType, int minCount)
    3.68 +		{
    3.69 +			limitedTypes.Add(new UnitCountRequirementData(unitType, minCount));
    3.70 +		}
    3.71 +	}
    3.72 +}
    3.73 +