Mercurial > repos > IBDev-IBBoard.WarFoundry.API
annotate API/Objects/Requirement/RaceRequiresAtLeastNUnitsRequirement.cs @ 479:f48c49b53738
Re #410: "N units per M models in parent" requirement
* Add a "context" object that will hold the parent unit (or possibly other stuff)
* Update all method signatures and calls
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 23 May 2012 20:56:27 +0100 |
parents | 7a00aeba3d2f |
children | e0641e0eb86c |
rev | line source |
---|---|
459
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
1 // This file (RaceRequiresAtLeastNUnitsRequirement.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2012 IBBoard |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
2 // |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
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. |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
4 using System; |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
5 using IBBoard.Collections; |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
6 |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
7 namespace IBBoard.WarFoundry.API.Objects.Requirement |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
8 { |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
9 public class RaceRequiresAtLeastNUnitsRequirement : RequiresAtLeastNUnitsRequirement<Race> |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
10 { |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
11 private static readonly string REQUIREMENT_ID_RACE = "RaceRequiresAtLeastNUnits"; |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
12 |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
13 public RaceRequiresAtLeastNUnitsRequirement(Race requirementOn, params UnitType[] requiredUnitTypes) : base(requirementOn, requiredUnitTypes) |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
14 { |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
15 //Do nothing special |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
16 } |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
17 |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
18 protected override int GetObjectCountFromArmy(Army toArmy, Race obj) |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
19 { |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
20 return toArmy.Race == AllowedObject ? 1 : 0; |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
21 } |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
22 |
479
f48c49b53738
Re #410: "N units per M models in parent" requirement
IBBoard <dev@ibboard.co.uk>
parents:
459
diff
changeset
|
23 protected override bool IsApplicable(Army toArmy, AddingContext context) |
459
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
24 { |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
25 bool isApplicable = false; |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
26 SimpleSet<UnitType> checkedTypes = new SimpleSet<UnitType>(); |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
27 |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
28 foreach (UnitCountRequirementData limit in ConstraintTypes) |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
29 { |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
30 foreach (UnitType unitType in limit.UnitTypes) |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
31 { |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
32 if (!checkedTypes.Contains(unitType)) |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
33 { |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
34 if (toArmy.GetUnitTypeCount(unitType) > 0) |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
35 { |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
36 isApplicable = true; |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
37 break; |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
38 } |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
39 |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
40 checkedTypes.Add(unitType); |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
41 } |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
42 } |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
43 } |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
44 |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
45 return isApplicable; |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
46 } |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
47 |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
48 public override string RequirementID |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
49 { |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
50 get |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
51 { |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
52 return REQUIREMENT_ID_RACE; |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
53 } |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
54 } |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
55 } |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
56 } |
7a00aeba3d2f
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
57 |