Mercurial > repos > IBBoard.WarFoundry.API
comparison API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs @ 337:3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 03 Apr 2011 18:50:32 +0000 |
parents | |
children | 5f94b8a40876 |
comparison
equal
deleted
inserted
replaced
336:3631c1493c7f | 337:3c4a6403a88c |
---|---|
1 // This file (RequiresNoMoreThanNOfUnitTypeRequirement.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard | |
2 // | |
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; | |
5 using IBBoard.WarFoundry.API.Objects; | |
6 using System.Collections.Generic; | |
7 | |
8 namespace IBBoard.WarFoundry.API.Objects.Requirement | |
9 { | |
10 /// <summary> | |
11 /// A requirement where a WarFoundryObject cannot be taken in an army if more than N of a UnitType will be in the army. | |
12 /// </summary> | |
13 public class RequiresNoMoreThanNOfUnitTypeRequirement | |
14 { | |
15 private List<UnitCountRequirementData> limitedTypes; | |
16 | |
17 public RequiresNoMoreThanNOfUnitTypeRequirement(params UnitType[] limitedUnitTypes) | |
18 { | |
19 limitedTypes = new List<UnitCountRequirementData>(); | |
20 | |
21 foreach (UnitType unitType in limitedUnitTypes) | |
22 { | |
23 AddUnitTypeRequirement(unitType, 0); | |
24 } | |
25 } | |
26 | |
27 /// <summary> | |
28 /// Checks whether the supplied WarFoundryObject can be added to the supplied army. | |
29 /// </summary> | |
30 /// <returns> | |
31 /// <c>true</c> if the object can be added, else <c>false</c> | |
32 /// </returns> | |
33 /// <param name='wfObject'> | |
34 /// The object that we want to add. This may be involved in the check, or it may not affect the evaluation of the requirement | |
35 /// </param> | |
36 /// <param name='toArmy'> | |
37 /// The army to add the object to. | |
38 /// </param> | |
39 public bool AllowsAdding(WarFoundryObject wfObject, Army toArmy) | |
40 { | |
41 bool canAdd = true; | |
42 | |
43 foreach (UnitCountRequirementData limit in limitedTypes) | |
44 { | |
45 if (toArmy.GetUnitTypeCount(limit.UnitType) > limit.Count) | |
46 { | |
47 canAdd = false; | |
48 break; | |
49 } | |
50 } | |
51 | |
52 return canAdd; | |
53 } | |
54 | |
55 /// <summary> | |
56 /// Adds a requirement for there to be at least minCount of a given UnitType | |
57 /// </summary> | |
58 /// <param name='unitType'> | |
59 /// The unit type to require. | |
60 /// </param> | |
61 /// <param name='minCount'> | |
62 /// The minimum number of that type that must exist. | |
63 /// </param> | |
64 public void AddUnitTypeRequirement(UnitType unitType, int minCount) | |
65 { | |
66 limitedTypes.Add(new UnitCountRequirementData(unitType, minCount)); | |
67 } | |
68 } | |
69 } | |
70 |