diff API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirement.cs @ 455:afc6410e4efc

Re #379: Fix validation of requirements to check for unit * Move to "Unit" requirements, since we assume things depend on units * Rename some classes to more meaningful names from unit-based change * Rename "requires N for M" requirement as we can make it more flexible
author IBBoard <dev@ibboard.co.uk>
date Wed, 22 Feb 2012 20:45:39 +0000
parents def5d333c5e8
children 680db2462e34
line wrap: on
line diff
--- a/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirement.cs	Tue Jan 31 20:58:09 2012 +0000
+++ b/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirement.cs	Wed Feb 22 20:45:39 2012 +0000
@@ -10,28 +10,25 @@
 	/// <summary>
 	/// A requirement where a UnitType requires at least N units of one or more unit types before any number of that object can be taken in an army.
 	/// </summary>
-	public class UnitRequiresAtLeastNUnitsRequirement : RequiresAtLeastNUnitsRequirement
+	public class UnitRequiresAtLeastNUnitsRequirement : RequiresAtLeastNUnitsRequirement<UnitType>
 	{
-		private UnitType requirementOnType;
-
-		public UnitRequiresAtLeastNUnitsRequirement(UnitType requirementOn) : base()
+		public UnitRequiresAtLeastNUnitsRequirement(UnitType requirementOn) : base(requirementOn)
 		{
-			requirementOnType = requirementOn;
 		}
 
-		protected override bool IsApplicable(WarFoundryObject toObjectAdded)
+		protected override bool IsApplicable(IWarFoundryObject toObjectAdded)
 		{
 			return base.IsApplicable(toObjectAdded) || IsRequirementOnType(toObjectAdded);
 		}
 
-		private bool IsRequirementOnType(WarFoundryObject toObjectAdded)
+		private bool IsRequirementOnType(IWarFoundryObject toObjectAdded)
 		{
-			return requirementOnType.Equals(toObjectAdded) || (toObjectAdded is Unit && requirementOnType.Equals(((Unit)toObjectAdded).UnitType));
+			return AllowedObject.Equals(toObjectAdded) || (toObjectAdded is Unit && AllowedObject.Equals(((Unit)toObjectAdded).UnitType));
 		}
 
 		protected override bool IsApplicable(Army toArmy)
 		{
-			return toArmy.GetUnitTypeCount(requirementOnType) > 0;
+			return toArmy.GetUnitTypeCount(AllowedObject) > 0;
 		}
 
 		public override Validation ValidatesArmy(Army toArmy)