Mercurial > repos > IBBoard.WarFoundry.API
changeset 461:f0594621e4a0
Re #379: Fix validation of requirements to check for unit
* Move "Is applicable" checks up to abstract "no more than N of unit type" class
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 05 Mar 2012 19:52:54 +0000 |
parents | 025319b6fa7a |
children | 159dc9be36c2 |
files | API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirement.cs |
diffstat | 2 files changed, 38 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs Sun Mar 04 21:13:52 2012 +0000 +++ b/API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs Mon Mar 05 19:52:54 2012 +0000 @@ -42,6 +42,43 @@ /// </param> public override Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy) { + return IsApplicable(wfObject, toArmy) ? CheckAllowsAdding(wfObject, toArmy) : Validation.NotApplicable; + } + + protected override bool IsApplicable(Army toArmy) + { + return false; + } + + protected override bool IsApplicable(IWarFoundryObject toObject) + { + bool isApplicable = false; + UnitType unitType = GetUnitTypeFromObject(toObject); + + if (unitType != null) + { + isApplicable = IsApplicable(unitType); + } + + return isApplicable; + } + + private bool IsApplicable(UnitType unitType) + { + bool isApplicable = false; + foreach (UnitCountRequirementData requirement in ConstraintTypes) + { + if (requirement.UnitType.Equals(unitType)) + { + isApplicable = true; + break; + } + } + return isApplicable; + } + + private Validation CheckAllowsAdding(IWarFoundryObject wfObject, Army toArmy) + { Validation canAdd = Validation.Passed; foreach (UnitCountRequirementData limit in ConstraintTypes)
--- a/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirement.cs Sun Mar 04 21:13:52 2012 +0000 +++ b/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirement.cs Mon Mar 05 19:52:54 2012 +0000 @@ -17,26 +17,9 @@ //Do nothing special } - /// <summary> - /// Checks whether the supplied WarFoundryObject can be added to the supplied army. - /// </summary> - /// <returns> - /// A <code>Validation</code> enum to show the result of the validation - /// </returns> - /// <param name='wfObject'> - /// The object that we want to add. This may be involved in the check, or it may not affect the evaluation of the requirement - /// </param> - /// <param name='toArmy'> - /// The army to add the object to. - /// </param> - public override Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy) - { - return IsApplicable(wfObject, toArmy) ? base.AllowsAdding(wfObject, toArmy) : Validation.NotApplicable; - } - protected override bool IsApplicable(IWarFoundryObject toObject, Army toArmy) { - return IsApplicable(toObject) || IsApplicableForRequiredType(toObject, toArmy); + return base.IsApplicable(toObject, toArmy) || IsApplicableForRequiredType(toObject, toArmy); } protected override bool IsApplicable(IWarFoundryObject toObject)