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 wrap: on
line diff
--- a/API/Objects/Army.cs	Sun Jan 22 19:17:06 2012 +0000
+++ b/API/Objects/Army.cs	Sat Jan 28 16:57:59 2012 +0000
@@ -12,6 +12,7 @@
 using ICSharpCode.SharpZipLib.Zip;
 using IBBoard.WarFoundry.API.Objects.Requirement;
 using IBBoard.Lang;
+using IBBoard.Collections;
 
 namespace IBBoard.WarFoundry.API.Objects
 {
@@ -272,6 +273,27 @@
 			return Race.GetRequirements();
 		}
 
+		public ICollection<IRequirement> GetAddingUnitRequirements(UnitType addingType)
+		{
+			Unit[] units = GetUnits();
+			SimpleSet<UnitType> unitTypes = new SimpleSet<UnitType>();
+			unitTypes.Add(addingType);
+
+			foreach (Unit unit in units)
+			{
+				unitTypes.Add(unit.UnitType);
+			}
+
+			SimpleSet<IRequirement> requirements = new SimpleSet<IRequirement>();
+
+			foreach (UnitType unitType in unitTypes)
+			{
+				requirements.AddRange(unitType.GetRequirements());
+			}
+
+			return requirements;
+		}
+
 		internal void OnArmyCompositionChanged()
 		{
 			if (ArmyCompositionChanged != null)
--- a/API/Objects/Requirement/RequirementHandler.cs	Sun Jan 22 19:17:06 2012 +0000
+++ b/API/Objects/Requirement/RequirementHandler.cs	Sat Jan 28 16:57:59 2012 +0000
@@ -50,7 +50,7 @@
 			Validation result = Validation.Passed;
 			failureMessages = new List<string>();
 			
-			foreach (IRequirement requirement in army.GetRequirements())
+			foreach (IRequirement requirement in army.GetAddingUnitRequirements(unitType))
 			{
 				if (!Validates.AsOkay(requirement.AllowsAdding(unitType, army)))
 				{