Mercurial > repos > IBDev-IBBoard.WarFoundry.API
comparison API/Objects/Requirement/RaceRequiresNoMoreThanNUnitsRequirement.cs @ 460:025319b6fa7a
Re #379: Fix validation of requirements to check for unit
* Create max count requirement object
* Re-add code for min/max counts as requirements
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 04 Mar 2012 21:13:52 +0000 |
parents | |
children | f48c49b53738 |
comparison
equal
deleted
inserted
replaced
459:7a00aeba3d2f | 460:025319b6fa7a |
---|---|
1 // This file (RaceRequiresNoMoreThanNUnitsRequirement.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2012 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.Collections; | |
6 | |
7 namespace IBBoard.WarFoundry.API.Objects.Requirement | |
8 { | |
9 public class RaceRequiresNoMoreThanNUnitsRequirement : RequiresNoMoreThanNOfUnitTypeRequirement<Race> | |
10 { | |
11 private static readonly string REQUIREMENT_ID_RACE = "RaceRequiresNoMoreThanNUnits"; | |
12 | |
13 public RaceRequiresNoMoreThanNUnitsRequirement(Race requirementOn, params UnitType[] requiredUnitTypes) : base(requirementOn, requiredUnitTypes) | |
14 { | |
15 //Do nothing special | |
16 } | |
17 | |
18 protected override int GetObjectCountFromArmy(Army toArmy, Race obj) | |
19 { | |
20 return toArmy.Race == AllowedObject ? 1 : 0; | |
21 } | |
22 | |
23 protected override bool IsApplicable(Army toArmy) | |
24 { | |
25 bool isApplicable = false; | |
26 SimpleSet<UnitType> checkedTypes = new SimpleSet<UnitType>(); | |
27 | |
28 foreach (UnitCountRequirementData limit in ConstraintTypes) | |
29 { | |
30 foreach (UnitType unitType in limit.UnitTypes) | |
31 { | |
32 if (!checkedTypes.Contains(unitType)) | |
33 { | |
34 if (toArmy.GetUnitTypeCount(unitType) > 0) | |
35 { | |
36 isApplicable = true; | |
37 break; | |
38 } | |
39 | |
40 checkedTypes.Add(unitType); | |
41 } | |
42 } | |
43 } | |
44 | |
45 return isApplicable; | |
46 } | |
47 | |
48 public override string RequirementID | |
49 { | |
50 get | |
51 { | |
52 return REQUIREMENT_ID_RACE; | |
53 } | |
54 } | |
55 } | |
56 } | |
57 |