Mercurial > repos > IBBoard.WarFoundry.API
changeset 345:008537acf244
Re #27: Unit requirements
* Make basic "Requires at least" requirement take into account the unit type being added
* Make unit version of "requires at least" requirement pass execution up to the matching parent method
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 09 Apr 2011 11:00:09 +0000 |
parents | 8585dfacac3b |
children | b0ba1d25f51e |
files | API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirement.cs |
diffstat | 2 files changed, 23 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs Sat Apr 09 10:47:58 2011 +0000 +++ b/API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs Sat Apr 09 11:00:09 2011 +0000 @@ -38,7 +38,28 @@ /// </param> public virtual Validation AllowsAdding(WarFoundryObject wfObject, Army toArmy) { - return this.ValidatesArmy(toArmy); + Validation isValid = Validation.Passed; + + foreach (UnitCountRequirementData requirement in requiredTypes) + { + if (GetUnitTypeCount(toArmy, requirement.UnitType, wfObject) < requirement.Count) + { + isValid = Validation.Failed; + break; + } + } + + return isValid; + } + + private int GetUnitTypeCount(Army toArmy, UnitType unitType, WarFoundryObject wfObject) + { + return toArmy.GetUnitTypeCount(unitType) + GetCountFromObject(wfObject, unitType); + } + + private int GetCountFromObject(WarFoundryObject wfObject, UnitType limitedType) + { + return (limitedType.Equals(wfObject) || (wfObject is Unit && ((Unit)wfObject).UnitType.Equals(limitedType))) ? 1 : 0; } /// <summary>
--- a/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirement.cs Sat Apr 09 10:47:58 2011 +0000 +++ b/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirement.cs Sat Apr 09 11:00:09 2011 +0000 @@ -33,7 +33,7 @@ /// </param> public override Validation AllowsAdding(WarFoundryObject wfObject, Army toArmy) { - return IsApplicable(wfObject, toArmy) ? base.ValidatesArmy(toArmy) : Validation.NotApplicable; + return IsApplicable(wfObject, toArmy) ? base.AllowsAdding(wfObject, toArmy) : Validation.NotApplicable; }