Mercurial > repos > snowblizz-super-API-ideas
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 wrap: on
line diff
--- a/IBBoard.WarFoundry.API.csproj Sun Mar 27 19:36:54 2011 +0000 +++ b/IBBoard.WarFoundry.API.csproj Sun Mar 27 19:50:33 2011 +0000 @@ -186,6 +186,7 @@ <Compile Include="api\Savers\Xml\WarFoundryXmlGameSystemSaver.cs" /> <Compile Include="api\Savers\Xml\WarFoundryXmlFileSaver.cs" /> <Compile Include="api\Objects\Requirement\RequiresAtLeastNUnitsRequirement.cs" /> + <Compile Include="api\Objects\Requirement\UnitCountRequirementData.cs" /> </ItemGroup> <ItemGroup> <Reference Include="System.Xml" />
--- a/api/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs Sun Mar 27 19:36:54 2011 +0000 +++ b/api/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs Sun Mar 27 19:50:33 2011 +0000 @@ -5,18 +5,23 @@ using System.Collections.Generic; using IBBoard.WarFoundry.API.Objects; -namespace IBBoard.WarFoundry.API.Objects +namespace IBBoard.WarFoundry.API.Objects.Requirement { /// <summary> /// A requirement where a WarFoundryObject requires at least N units of one or more unit types before it can be taken in an army. /// </summary> public class RequiresAtLeastNUnitsRequirement { - private List<UnitType> requiredTypes; + private List<UnitCountRequirementData> requiredTypes; public RequiresAtLeastNUnitsRequirement(params UnitType[] requiredUnitTypes) { - requiredTypes = new List<UnitType>(requiredUnitTypes); + requiredTypes = new List<UnitCountRequirementData>(); + + foreach (UnitType unitType in requiredUnitTypes) + { + AddUnitTypeRequirement(unitType, 1); + } } /// <summary> @@ -35,9 +40,9 @@ { bool canAdd = true; - foreach (UnitType type in requiredTypes) + foreach (UnitCountRequirementData requirement in requiredTypes) { - if (toArmy.GetUnitTypeCount(type) < 1) + if (toArmy.GetUnitTypeCount(requirement.UnitType) < requirement.Count) { canAdd = false; break; @@ -45,6 +50,11 @@ } return canAdd; + } + + public void AddUnitTypeRequirement(UnitType unitType, int minCount) + { + requiredTypes.Add(new UnitCountRequirementData(unitType, minCount)); } } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/api/Objects/Requirement/UnitCountRequirementData.cs Sun Mar 27 19:50:33 2011 +0000 @@ -0,0 +1,31 @@ +// This file (UnitCountRequirementData.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 IBBoard +// +// 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. +using System; +using IBBoard.WarFoundry.API.Objects; + +namespace IBBoard.WarFoundry.API.Objects.Requirement +{ + public class UnitCountRequirementData + { + private UnitType unitType; + private int count; + + public UnitCountRequirementData(UnitType unitType, int count) + { + this.unitType = unitType; + this.count = count; + } + + public UnitType UnitType + { + get { return unitType; } + } + + public int Count + { + get { return count; } + } + } +} +