comparison api/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs @ 332:2cb3bd9b11ea

Re #27: Define unit requirements * Add new method for validating an existing army * Refactor existing code into new method
author IBBoard <dev@ibboard.co.uk>
date Mon, 28 Mar 2011 19:41:43 +0000
parents e1d1b81b192a
children 17d8d357467e
comparison
equal deleted inserted replaced
331:e1d1b81b192a 332:2cb3bd9b11ea
36 /// <param name='toArmy'> 36 /// <param name='toArmy'>
37 /// The army to add the object to. 37 /// The army to add the object to.
38 /// </param> 38 /// </param>
39 public bool AllowsAdding(WarFoundryObject wfObject, Army toArmy) 39 public bool AllowsAdding(WarFoundryObject wfObject, Army toArmy)
40 { 40 {
41 return this.ValidatesArmy(toArmy);
42 }
43
44 public void AddUnitTypeRequirement(UnitType unitType, int minCount)
45 {
46 requiredTypes.Add(new UnitCountRequirementData(unitType, minCount));
47 }
48
49 /// <summary>
50 /// Checks whether the supplied army is currently valid according to this requirement.
51 /// </summary>
52 /// <returns>
53 /// <c>true</c> if the army is valid, else <c>false</c>
54 /// </returns>
55 /// <param name='toValidate'>
56 /// The army to validate
57 /// </param>
58 public bool ValidatesArmy(Army toValidate)
59 {
41 bool canAdd = true; 60 bool canAdd = true;
42 61
43 foreach (UnitCountRequirementData requirement in requiredTypes) 62 foreach (UnitCountRequirementData requirement in requiredTypes)
44 { 63 {
45 if (toArmy.GetUnitTypeCount(requirement.UnitType) < requirement.Count) 64 if (toValidate.GetUnitTypeCount(requirement.UnitType) < requirement.Count)
46 { 65 {
47 canAdd = false; 66 canAdd = false;
48 break; 67 break;
49 } 68 }
50 } 69 }
51 70
52 return canAdd; 71 return canAdd;
53 } 72 }
54
55 public void AddUnitTypeRequirement(UnitType unitType, int minCount)
56 {
57 requiredTypes.Add(new UnitCountRequirementData(unitType, minCount));
58 }
59 } 73 }
60 } 74 }
61 75