changeset 451:676f5ce04176

Re #379: Fix validation of requirements to check for unit * Add method to Army to differentiate "all requirements" from "requirements relevant to adding a unit"
author IBBoard <dev@ibboard.co.uk>
date Sat, 28 Jan 2012 16:57:59 +0000
parents 8811737baebf
children b671085871b7
files API/Objects/Army.cs API/Objects/Requirement/RequirementHandler.cs
diffstat 2 files changed, 23 insertions(+), 1 deletions(-) [+]
line diff
     1.1 --- a/API/Objects/Army.cs	Sun Jan 22 19:17:06 2012 +0000
     1.2 +++ b/API/Objects/Army.cs	Sat Jan 28 16:57:59 2012 +0000
     1.3 @@ -12,6 +12,7 @@
     1.4  using ICSharpCode.SharpZipLib.Zip;
     1.5  using IBBoard.WarFoundry.API.Objects.Requirement;
     1.6  using IBBoard.Lang;
     1.7 +using IBBoard.Collections;
     1.8  
     1.9  namespace IBBoard.WarFoundry.API.Objects
    1.10  {
    1.11 @@ -272,6 +273,27 @@
    1.12  			return Race.GetRequirements();
    1.13  		}
    1.14  
    1.15 +		public ICollection<IRequirement> GetAddingUnitRequirements(UnitType addingType)
    1.16 +		{
    1.17 +			Unit[] units = GetUnits();
    1.18 +			SimpleSet<UnitType> unitTypes = new SimpleSet<UnitType>();
    1.19 +			unitTypes.Add(addingType);
    1.20 +
    1.21 +			foreach (Unit unit in units)
    1.22 +			{
    1.23 +				unitTypes.Add(unit.UnitType);
    1.24 +			}
    1.25 +
    1.26 +			SimpleSet<IRequirement> requirements = new SimpleSet<IRequirement>();
    1.27 +
    1.28 +			foreach (UnitType unitType in unitTypes)
    1.29 +			{
    1.30 +				requirements.AddRange(unitType.GetRequirements());
    1.31 +			}
    1.32 +
    1.33 +			return requirements;
    1.34 +		}
    1.35 +
    1.36  		internal void OnArmyCompositionChanged()
    1.37  		{
    1.38  			if (ArmyCompositionChanged != null)
     2.1 --- a/API/Objects/Requirement/RequirementHandler.cs	Sun Jan 22 19:17:06 2012 +0000
     2.2 +++ b/API/Objects/Requirement/RequirementHandler.cs	Sat Jan 28 16:57:59 2012 +0000
     2.3 @@ -50,7 +50,7 @@
     2.4  			Validation result = Validation.Passed;
     2.5  			failureMessages = new List<string>();
     2.6  			
     2.7 -			foreach (IRequirement requirement in army.GetRequirements())
     2.8 +			foreach (IRequirement requirement in army.GetAddingUnitRequirements(unitType))
     2.9  			{
    2.10  				if (!Validates.AsOkay(requirement.AllowsAdding(unitType, army)))
    2.11  				{