Mercurial > repos > IBBoard.WarFoundry.API
diff API/Objects/Requirement/RequiresNUnitsForMObjectsRequirement.cs @ 456:52baffdd2ab9
Re #379: Fix validation of requirements to check for unit
* Default to not being applicable - make requirements say when they are
* Fix UnitRequiresNUnitsForMUnitsRequirement to not be applicable when adding unrelated units (even if army itself fails the rule)
* Fix type casting issues in equality check
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 25 Feb 2012 16:35:31 +0000 |
parents | afc6410e4efc |
children | 8e01c3174cc3 |
line wrap: on
line diff
--- a/API/Objects/Requirement/RequiresNUnitsForMObjectsRequirement.cs Wed Feb 22 20:45:39 2012 +0000 +++ b/API/Objects/Requirement/RequiresNUnitsForMObjectsRequirement.cs Sat Feb 25 16:35:31 2012 +0000 @@ -93,7 +93,7 @@ { Validation canAdd = Validation.NotApplicable; UnitType addedUnitType = (wfObject is Unit) ? ((Unit)wfObject).UnitType : wfObject as UnitType; - bool typeFound = (wfObject == (IWarFoundryObject)AllowedObject); + bool typeFound = (wfObject == (IWarFoundryObject)AllowedObject || addedUnitType == (IWarFoundryObject)AllowedObject); int allowedTypeCount = GetAllowedObjectCount(toArmy, AllowedObject, wfObject); foreach (UnitCountRequirementData limit in RequiredTypes) @@ -141,25 +141,27 @@ public override Validation ValidatesArmy(Army army) { - Validation canAdd = Validation.NotApplicable; + Validation canAdd; int allowedTypeCount = GetObjectCountFromArmy(army, AllowedObject); - bool typeFound = (allowedTypeCount > 0); - foreach (UnitCountRequirementData limit in RequiredTypes) + if (allowedTypeCount > 0) { - int limitedTypeCount = GetUnitTypesCount(army, limit.UnitTypes); - typeFound |= (limitedTypeCount > 0); + canAdd = Validation.Passed; + + foreach (UnitCountRequirementData limit in RequiredTypes) + { + int limitedTypeCount = GetUnitTypesCount(army, limit.UnitTypes); - if (!IsValidByRequirement(limit, allowedTypeCount, limitedTypeCount)) - { - canAdd = Validation.Failed; - break; + if (!IsValidByRequirement(limit, allowedTypeCount, limitedTypeCount)) + { + canAdd = Validation.Failed; + break; + } } } - - if (typeFound && canAdd == Validation.NotApplicable) + else { - canAdd = Validation.Passed; + canAdd = Validation.NotApplicable; } return canAdd;