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 diff
     1.1 --- a/API/Objects/Requirement/RequiresNUnitsForMObjectsRequirement.cs	Sat Mar 24 20:33:11 2012 +0000
     1.2 +++ b/API/Objects/Requirement/RequiresNUnitsForMObjectsRequirement.cs	Sat Mar 31 15:23:49 2012 +0100
     1.3 @@ -58,8 +58,9 @@
     1.4  
     1.5  		private bool IsValidByRequirement(UnitCountRequirementData limit, int allowedTypeCount, int limitedTypeCount)
     1.6  		{
     1.7 -			double allowedRatio = (limit.AllowsCount / (limit.Count * 1.0));
     1.8 -			return allowedRatio * limitedTypeCount >= allowedTypeCount;
     1.9 +			double normalisedLimited = limitedTypeCount / (limit.Count * 1.0);
    1.10 +			double normalisedAllowed = allowedTypeCount / (limit.AllowsCount * 1.0);
    1.11 +			return normalisedLimited >= 1 && normalisedAllowed <= normalisedLimited;
    1.12  		}
    1.13  
    1.14  		public override Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy)