Mercurial > repos > IBBoard.WarFoundry.API
comparison api/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs @ 331:e1d1b81b192a
Re #27: Define unit requirements
* Implement code for min limits > 1
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 27 Mar 2011 19:50:33 +0000 |
parents | 8ca5dd75d5b8 |
children | 2cb3bd9b11ea |
comparison
equal
deleted
inserted
replaced
330:8ca5dd75d5b8 | 331:e1d1b81b192a |
---|---|
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. | 3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. |
4 using System; | 4 using System; |
5 using System.Collections.Generic; | 5 using System.Collections.Generic; |
6 using IBBoard.WarFoundry.API.Objects; | 6 using IBBoard.WarFoundry.API.Objects; |
7 | 7 |
8 namespace IBBoard.WarFoundry.API.Objects | 8 namespace IBBoard.WarFoundry.API.Objects.Requirement |
9 { | 9 { |
10 /// <summary> | 10 /// <summary> |
11 /// A requirement where a WarFoundryObject requires at least N units of one or more unit types before it can be taken in an army. | 11 /// A requirement where a WarFoundryObject requires at least N units of one or more unit types before it can be taken in an army. |
12 /// </summary> | 12 /// </summary> |
13 public class RequiresAtLeastNUnitsRequirement | 13 public class RequiresAtLeastNUnitsRequirement |
14 { | 14 { |
15 private List<UnitType> requiredTypes; | 15 private List<UnitCountRequirementData> requiredTypes; |
16 | 16 |
17 public RequiresAtLeastNUnitsRequirement(params UnitType[] requiredUnitTypes) | 17 public RequiresAtLeastNUnitsRequirement(params UnitType[] requiredUnitTypes) |
18 { | 18 { |
19 requiredTypes = new List<UnitType>(requiredUnitTypes); | 19 requiredTypes = new List<UnitCountRequirementData>(); |
20 | |
21 foreach (UnitType unitType in requiredUnitTypes) | |
22 { | |
23 AddUnitTypeRequirement(unitType, 1); | |
24 } | |
20 } | 25 } |
21 | 26 |
22 /// <summary> | 27 /// <summary> |
23 /// Checks whether the supplied WarFoundryObject can be added to the supplied army. | 28 /// Checks whether the supplied WarFoundryObject can be added to the supplied army. |
24 /// </summary> | 29 /// </summary> |
33 /// </param> | 38 /// </param> |
34 public bool AllowsAdding(WarFoundryObject wfObject, Army toArmy) | 39 public bool AllowsAdding(WarFoundryObject wfObject, Army toArmy) |
35 { | 40 { |
36 bool canAdd = true; | 41 bool canAdd = true; |
37 | 42 |
38 foreach (UnitType type in requiredTypes) | 43 foreach (UnitCountRequirementData requirement in requiredTypes) |
39 { | 44 { |
40 if (toArmy.GetUnitTypeCount(type) < 1) | 45 if (toArmy.GetUnitTypeCount(requirement.UnitType) < requirement.Count) |
41 { | 46 { |
42 canAdd = false; | 47 canAdd = false; |
43 break; | 48 break; |
44 } | 49 } |
45 } | 50 } |
46 | 51 |
47 return canAdd; | 52 return canAdd; |
48 } | 53 } |
54 | |
55 public void AddUnitTypeRequirement(UnitType unitType, int minCount) | |
56 { | |
57 requiredTypes.Add(new UnitCountRequirementData(unitType, minCount)); | |
58 } | |
49 } | 59 } |
50 } | 60 } |
51 | 61 |