changeset 448:dbd779cdc0f9

Re #350: Add requirement to allow N of unit for specific other units * Fix limit checking when "limited count" is not 1 (e.g. "need 2 for every 3")
author IBBoard <dev@ibboard.co.uk>
date Fri, 23 Dec 2011 15:36:06 +0000
parents 4fbb7f205f7e
children ba6c762cdfc3
files API/Objects/Requirement/RequiresNUnitsForMUnitsRequirement.cs
diffstat 1 files changed, 3 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirement.cs	Tue Dec 20 21:03:33 2011 +0000
+++ b/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirement.cs	Fri Dec 23 15:36:06 2011 +0000
@@ -101,9 +101,9 @@
 
 		private bool IsValidByRequirement(UnitCountRequirementData limit, int allowedTypeCount, int limitedTypeCount)
 		{
-			double limitedTypeMultiplier = limitedTypeCount / (limit.Count * 1.0);
-			double allowedTypeMultiplier = allowedTypeCount / (limit.AllowsCount * 1.0);
-			return allowedTypeMultiplier <= limitedTypeMultiplier;
+			int wholeNumLimited = (limitedTypeCount / limit.Count);
+			double allowedRatio = (limit.AllowsCount / (limit.Count * 1.0));
+			return allowedRatio * wholeNumLimited >= allowedTypeCount;
 		}
 
 		public override Validation AllowsAdding(WarFoundryObject wfObject, Army toArmy)