comparison API/Objects/Requirement/RequiresNUnitsForMObjectsRequirement.cs @ 467:750eed630c41

Fixes #395: Requirements can incorrectly allow based on common divisor * Round the "limited/required" normalised count down to get correct values
author IBBoard <dev@ibboard.co.uk>
date Sat, 31 Mar 2012 20:18:42 +0100
parents bdfa314789cc
children f48c49b53738
comparison
equal deleted inserted replaced
466:bdfa314789cc 467:750eed630c41
56 return IsValidByRequirement(limit, allowedTypeCount, limitedTypeCount); 56 return IsValidByRequirement(limit, allowedTypeCount, limitedTypeCount);
57 } 57 }
58 58
59 private bool IsValidByRequirement(UnitCountRequirementData limit, int allowedTypeCount, int limitedTypeCount) 59 private bool IsValidByRequirement(UnitCountRequirementData limit, int allowedTypeCount, int limitedTypeCount)
60 { 60 {
61 double normalisedLimited = limitedTypeCount / (limit.Count * 1.0); 61 //Round down limited units to get only whole amounts
62 double normalisedLimited = Math.Floor(limitedTypeCount / (limit.Count * 1.0));
62 double normalisedAllowed = allowedTypeCount / (limit.AllowsCount * 1.0); 63 double normalisedAllowed = allowedTypeCount / (limit.AllowsCount * 1.0);
63 return normalisedLimited >= 1 && normalisedAllowed <= normalisedLimited; 64 return normalisedLimited >= 1 && normalisedAllowed <= normalisedLimited;
64 } 65 }
65 66
66 public override Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy) 67 public override Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy)