changeset 331:e1d1b81b192a

Re #27: Define unit requirements * Implement code for min limits > 1
author IBBoard <dev@ibboard.co.uk>
date Sun, 27 Mar 2011 19:50:33 +0000
parents 8ca5dd75d5b8
children 2cb3bd9b11ea
files IBBoard.WarFoundry.API.csproj api/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs api/Objects/Requirement/UnitCountRequirementData.cs
diffstat 3 files changed, 47 insertions(+), 5 deletions(-) [+]
line diff
     1.1 --- a/IBBoard.WarFoundry.API.csproj	Sun Mar 27 19:36:54 2011 +0000
     1.2 +++ b/IBBoard.WarFoundry.API.csproj	Sun Mar 27 19:50:33 2011 +0000
     1.3 @@ -186,6 +186,7 @@
     1.4      <Compile Include="api\Savers\Xml\WarFoundryXmlGameSystemSaver.cs" />
     1.5      <Compile Include="api\Savers\Xml\WarFoundryXmlFileSaver.cs" />
     1.6      <Compile Include="api\Objects\Requirement\RequiresAtLeastNUnitsRequirement.cs" />
     1.7 +    <Compile Include="api\Objects\Requirement\UnitCountRequirementData.cs" />
     1.8    </ItemGroup>
     1.9    <ItemGroup>
    1.10      <Reference Include="System.Xml" />
     2.1 --- a/api/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs	Sun Mar 27 19:36:54 2011 +0000
     2.2 +++ b/api/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs	Sun Mar 27 19:50:33 2011 +0000
     2.3 @@ -5,18 +5,23 @@
     2.4  using System.Collections.Generic;
     2.5  using IBBoard.WarFoundry.API.Objects;
     2.6  
     2.7 -namespace IBBoard.WarFoundry.API.Objects
     2.8 +namespace IBBoard.WarFoundry.API.Objects.Requirement
     2.9  {
    2.10  	/// <summary>
    2.11  	/// 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.12  	/// </summary>
    2.13  	public class RequiresAtLeastNUnitsRequirement
    2.14  	{
    2.15 -		private List<UnitType> requiredTypes;
    2.16 +		private List<UnitCountRequirementData> requiredTypes;
    2.17  
    2.18  		public RequiresAtLeastNUnitsRequirement(params UnitType[] requiredUnitTypes)
    2.19  		{
    2.20 -			requiredTypes = new List<UnitType>(requiredUnitTypes);
    2.21 +			requiredTypes = new List<UnitCountRequirementData>();
    2.22 +
    2.23 +			foreach (UnitType unitType in requiredUnitTypes)
    2.24 +			{
    2.25 +				AddUnitTypeRequirement(unitType, 1);
    2.26 +			}
    2.27  		}
    2.28  
    2.29  		/// <summary>
    2.30 @@ -35,9 +40,9 @@
    2.31  		{
    2.32  			bool canAdd = true;
    2.33  
    2.34 -			foreach (UnitType type in requiredTypes)
    2.35 +			foreach (UnitCountRequirementData requirement in requiredTypes)
    2.36  			{
    2.37 -				if (toArmy.GetUnitTypeCount(type) < 1)
    2.38 +				if (toArmy.GetUnitTypeCount(requirement.UnitType) < requirement.Count)
    2.39  				{
    2.40  					canAdd = false;
    2.41  					break;
    2.42 @@ -45,6 +50,11 @@
    2.43  			}
    2.44  
    2.45  			return canAdd;
    2.46 +		}
    2.47 +
    2.48 +		public void AddUnitTypeRequirement(UnitType unitType, int minCount)
    2.49 +		{
    2.50 +			requiredTypes.Add(new UnitCountRequirementData(unitType, minCount));
    2.51  		}
    2.52  	}
    2.53  }
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/api/Objects/Requirement/UnitCountRequirementData.cs	Sun Mar 27 19:50:33 2011 +0000
     3.3 @@ -0,0 +1,31 @@
     3.4 +// This file (UnitCountRequirementData.cs) is a part of the IBBoard.WarFoundry.API.Tests 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 +
    3.10 +namespace IBBoard.WarFoundry.API.Objects.Requirement
    3.11 +{
    3.12 +	public class UnitCountRequirementData
    3.13 +	{
    3.14 +		private UnitType unitType;
    3.15 +		private int count;
    3.16 +
    3.17 +		public UnitCountRequirementData(UnitType unitType, int count)
    3.18 +		{
    3.19 +			this.unitType = unitType;
    3.20 +			this.count = count;
    3.21 +		}
    3.22 +
    3.23 +		public UnitType UnitType
    3.24 +		{
    3.25 +			get { return unitType; }
    3.26 +		}
    3.27 +
    3.28 +		public int Count
    3.29 +		{
    3.30 +			get { return count; }
    3.31 +		}
    3.32 +	}
    3.33 +}
    3.34 +