changeset 332:2cb3bd9b11ea

Re #27: Define unit requirements * Add new method for validating an existing army * Refactor existing code into new method
author IBBoard <dev@ibboard.co.uk>
date Mon, 28 Mar 2011 19:41:43 +0000
parents e1d1b81b192a
children 17d8d357467e
files api/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs
diffstat 1 files changed, 20 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/api/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs	Sun Mar 27 19:50:33 2011 +0000
+++ b/api/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs	Mon Mar 28 19:41:43 2011 +0000
@@ -38,11 +38,30 @@
 		/// </param>
 		public bool AllowsAdding(WarFoundryObject wfObject, Army toArmy)
 		{
+			return this.ValidatesArmy(toArmy);
+		}
+
+		public void AddUnitTypeRequirement(UnitType unitType, int minCount)
+		{
+			requiredTypes.Add(new UnitCountRequirementData(unitType, minCount));
+		}
+
+		/// <summary>
+		/// Checks whether the supplied army is currently valid according to this requirement.
+		/// </summary>
+		/// <returns>
+		/// <c>true</c> if the army is valid, else <c>false</c>
+		/// </returns>
+		/// <param name='toValidate'>
+		/// The army to validate
+		/// </param>
+		public bool ValidatesArmy(Army toValidate)
+		{
 			bool canAdd = true;
 
 			foreach (UnitCountRequirementData requirement in requiredTypes)
 			{
-				if (toArmy.GetUnitTypeCount(requirement.UnitType) < requirement.Count)
+				if (toValidate.GetUnitTypeCount(requirement.UnitType) < requirement.Count)
 				{
 					canAdd = false;
 					break;
@@ -51,11 +70,6 @@
 
 			return canAdd;
 		}
-
-		public void AddUnitTypeRequirement(UnitType unitType, int minCount)
-		{
-			requiredTypes.Add(new UnitCountRequirementData(unitType, minCount));
-		}
 	}
 }