# HG changeset patch # User IBBoard # Date 1301255433 0 # Node ID e1d1b81b192a957ac02bad53d90b0b3c3a36797e # Parent 8ca5dd75d5b862a7a89cb13861296e3fd301bcdf Re #27: Define unit requirements * Implement code for min limits > 1 diff -r 8ca5dd75d5b8 -r e1d1b81b192a IBBoard.WarFoundry.API.csproj --- 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 @@ + diff -r 8ca5dd75d5b8 -r e1d1b81b192a api/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs --- 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 { /// /// A requirement where a WarFoundryObject requires at least N units of one or more unit types before it can be taken in an army. /// public class RequiresAtLeastNUnitsRequirement { - private List requiredTypes; + private List requiredTypes; public RequiresAtLeastNUnitsRequirement(params UnitType[] requiredUnitTypes) { - requiredTypes = new List(requiredUnitTypes); + requiredTypes = new List(); + + foreach (UnitType unitType in requiredUnitTypes) + { + AddUnitTypeRequirement(unitType, 1); + } } /// @@ -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)); } } } diff -r 8ca5dd75d5b8 -r e1d1b81b192a api/Objects/Requirement/UnitCountRequirementData.cs --- /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; } + } + } +} +