Mercurial > repos > IBBoard.WarFoundry.API
comparison API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs @ 458:680db2462e34
Re #379:
* Move GetObjectCountFromArmy(Army, OBJECT_TYPE) to top level and implement
* Fix army validation for appropriate "NA" returns
* Make basic "Requires..." requirements abstract so that we always need to make specific versions (e.g. UnitRequires... that knows how to check amount of units)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 26 Feb 2012 20:16:33 +0000 |
parents | 8e01c3174cc3 |
children | 159dc9be36c2 |
comparison
equal
deleted
inserted
replaced
457:8e01c3174cc3 | 458:680db2462e34 |
---|---|
11 /// <summary> | 11 /// <summary> |
12 /// A requirement where a WarFoundryObject requires at least N units of any of the specified unit types before any number of that object can be taken in an army. | 12 /// A requirement where a WarFoundryObject requires at least N units of any of the specified unit types before any number of that object can be taken in an army. |
13 /// | 13 /// |
14 /// The definition for how this requirement is built from a data file is defined in the <see cref="UnitRequiresAtLeastNUnitsRequirementFactory"/> class. | 14 /// The definition for how this requirement is built from a data file is defined in the <see cref="UnitRequiresAtLeastNUnitsRequirementFactory"/> class. |
15 /// </summary> | 15 /// </summary> |
16 public class RequiresAtLeastNUnitsRequirement<OBJECT_TYPE> : AbstractUnitRequirement<OBJECT_TYPE> where OBJECT_TYPE : IWarFoundryObject | 16 public abstract class RequiresAtLeastNUnitsRequirement<OBJECT_TYPE> : AbstractUnitRequirement<OBJECT_TYPE> where OBJECT_TYPE : IWarFoundryObject |
17 { | 17 { |
18 public static readonly string REQUIREMENT_ID = "RequiresAtLeastNUnits"; | 18 public static readonly string REQUIREMENT_ID = "RequiresAtLeastNUnits"; |
19 | 19 |
20 public RequiresAtLeastNUnitsRequirement(OBJECT_TYPE requirementOn, params UnitType[] requiredUnitTypes) : base(requirementOn, requiredUnitTypes) | 20 public RequiresAtLeastNUnitsRequirement(OBJECT_TYPE requirementOn, params UnitType[] requiredUnitTypes) : base(requirementOn, requiredUnitTypes) |
21 { | 21 { |
154 /// <param name='toValidate'> | 154 /// <param name='toValidate'> |
155 /// The army to validate | 155 /// The army to validate |
156 /// </param> | 156 /// </param> |
157 public override Validation ValidatesArmy(Army toValidate) | 157 public override Validation ValidatesArmy(Army toValidate) |
158 { | 158 { |
159 Validation isValid = Validation.Passed; | 159 Validation isValid = Validation.NotApplicable; |
160 | 160 int allowedTypeCount = GetObjectCountFromArmy(toValidate, AllowedObject); |
161 foreach (UnitCountRequirementData requirement in ConstraintTypes) | 161 |
162 { | 162 if (allowedTypeCount > 0) |
163 if (toValidate.GetUnitTypeCount(requirement.UnitType) < requirement.Count) | 163 { |
164 { | 164 isValid = Validation.Passed; |
165 isValid = Validation.Failed; | 165 |
166 break; | 166 foreach (UnitCountRequirementData requirement in ConstraintTypes) |
167 } | 167 { |
168 if (toValidate.GetUnitTypeCount(requirement.UnitType) < requirement.Count) | |
169 { | |
170 isValid = Validation.Failed; | |
171 break; | |
172 } | |
173 } | |
174 } | |
175 else | |
176 { | |
177 isValid = Validation.NotApplicable; | |
168 } | 178 } |
169 | 179 |
170 return isValid; | 180 return isValid; |
171 } | 181 } |
172 | 182 |