changeset 466:bdfa314789cc

Re #395: Requirements can incorrectly allow based on common divisor * Rebuild validation check to use normalised values
author IBBoard <dev@ibboard.co.uk>
date Sat, 31 Mar 2012 15:23:49 +0100
parents 7b9ff7b1df24
children 750eed630c41
files API/Objects/Requirement/RequiresNUnitsForMObjectsRequirement.cs
diffstat 1 files changed, 3 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/API/Objects/Requirement/RequiresNUnitsForMObjectsRequirement.cs	Sat Mar 24 20:33:11 2012 +0000
+++ b/API/Objects/Requirement/RequiresNUnitsForMObjectsRequirement.cs	Sat Mar 31 15:23:49 2012 +0100
@@ -58,8 +58,9 @@
 
 		private bool IsValidByRequirement(UnitCountRequirementData limit, int allowedTypeCount, int limitedTypeCount)
 		{
-			double allowedRatio = (limit.AllowsCount / (limit.Count * 1.0));
-			return allowedRatio * limitedTypeCount >= allowedTypeCount;
+			double normalisedLimited = limitedTypeCount / (limit.Count * 1.0);
+			double normalisedAllowed = allowedTypeCount / (limit.AllowsCount * 1.0);
+			return normalisedLimited >= 1 && normalisedAllowed <= normalisedLimited;
 		}
 
 		public override Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy)