Mercurial > repos > IBDev-IBBoard.WarFoundry.API
comparison api/Objects/UnitRequiresAtLeastNUnitsRequirement.cs @ 329:a5b34ca10d80
Re #27: Define unit requirements
* Update method name for a more "natural language" approach of "if (req.AllowsAdding(...))"
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 27 Mar 2011 19:15:31 +0000 |
parents | f8471453c3cb |
children |
comparison
equal
deleted
inserted
replaced
328:f8471453c3cb | 329:a5b34ca10d80 |
---|---|
17 public UnitRequiresAtLeastNUnitsRequirement(params UnitType[] requiredUnitTypes) | 17 public UnitRequiresAtLeastNUnitsRequirement(params UnitType[] requiredUnitTypes) |
18 { | 18 { |
19 requiredTypes = new List<UnitType>(requiredUnitTypes); | 19 requiredTypes = new List<UnitType>(requiredUnitTypes); |
20 } | 20 } |
21 | 21 |
22 public bool CanAddToArmy(WarFoundryObject unit, Army army) | 22 /// <summary> |
23 /// Checks whether the supplied WarFoundryObject can be added to the supplied army. | |
24 /// </summary> | |
25 /// <returns> | |
26 /// <c>true</c> if the object can be added, else <c>false</c> | |
27 /// </returns> | |
28 /// <param name='wfObject'> | |
29 /// The object that we want to add. This may be involved in the check, or it may not affect the evaluation of the requirement | |
30 /// </param> | |
31 /// <param name='toArmy'> | |
32 /// The army to add the object to. | |
33 /// </param> | |
34 public bool AllowsAdding(WarFoundryObject wfObject, Army toArmy) | |
23 { | 35 { |
24 bool canAdd = true; | 36 bool canAdd = true; |
25 | 37 |
26 foreach (UnitType type in requiredTypes) | 38 foreach (UnitType type in requiredTypes) |
27 { | 39 { |
28 if (army.GetUnitTypeCount(type) < 1) | 40 if (toArmy.GetUnitTypeCount(type) < 1) |
29 { | 41 { |
30 canAdd = false; | 42 canAdd = false; |
31 break; | 43 break; |
32 } | 44 } |
33 } | 45 } |