Mercurial > repos > IBDev-IBBoard.WarFoundry.API
annotate API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirement.cs @ 499:2fc99446f9c9 default tip
Add initial structure for categories of equipment
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 16 Oct 2016 20:26:44 +0100 |
parents | 248df19652f9 |
children |
rev | line source |
---|---|
362
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
1 // This file (UnitRequiresAtLeastNUnitsRequirement.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
2 // |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
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. |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
4 using System; |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
5 using System.Collections.Generic; |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
6 using IBBoard.WarFoundry.API.Objects; |
480
e0641e0eb86c
Re #410: "N units per M models in parent" requirement
IBBoard <dev@ibboard.co.uk>
parents:
479
diff
changeset
|
7 using IBBoard.WarFoundry.API.Objects.Requirement.Context; |
362
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
8 |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
9 namespace IBBoard.WarFoundry.API.Objects.Requirement |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
10 { |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
11 /// <summary> |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
12 /// A requirement where a UnitType can only be taken if there are no more than N units of one or more unit in an army. |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
13 /// </summary> |
455
afc6410e4efc
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
454
diff
changeset
|
14 public class UnitRequiresNoMoreThanNOfUnitTypeRequirement : RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> |
362
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
15 { |
457
8e01c3174cc3
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
455
diff
changeset
|
16 public UnitRequiresNoMoreThanNOfUnitTypeRequirement(UnitType allowedObject, params UnitType[] unitTypes) : base(allowedObject, unitTypes) |
362
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
17 { |
457
8e01c3174cc3
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
455
diff
changeset
|
18 //Do nothing special |
362
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
19 } |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
20 |
479
f48c49b53738
Re #410: "N units per M models in parent" requirement
IBBoard <dev@ibboard.co.uk>
parents:
461
diff
changeset
|
21 protected override bool IsApplicable(IWarFoundryObject toObject, AddingContext context) |
362
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
22 { |
457
8e01c3174cc3
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
455
diff
changeset
|
23 return AllowedObject.Equals(toObject) || (toObject is Unit && AllowedObject.Equals(((Unit)toObject).UnitType)); |
8e01c3174cc3
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
455
diff
changeset
|
24 } |
8e01c3174cc3
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
455
diff
changeset
|
25 |
487
248df19652f9
Re #410: Create "N units per M models in parent unit" requirement
IBBoard <dev@ibboard.co.uk>
parents:
480
diff
changeset
|
26 protected override bool IsApplicableToBoth(IWarFoundryObject toObject, Army toArmy, AddingContext context) |
457
8e01c3174cc3
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
455
diff
changeset
|
27 { |
8e01c3174cc3
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
455
diff
changeset
|
28 bool isApplicable = false; |
8e01c3174cc3
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
455
diff
changeset
|
29 UnitType addedType = toObject as UnitType; |
8e01c3174cc3
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
455
diff
changeset
|
30 |
8e01c3174cc3
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
455
diff
changeset
|
31 if (addedType == null) |
8e01c3174cc3
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
455
diff
changeset
|
32 { |
8e01c3174cc3
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
455
diff
changeset
|
33 addedType = (toObject is Unit) ? ((Unit)toObject).UnitType : null; |
8e01c3174cc3
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
455
diff
changeset
|
34 } |
8e01c3174cc3
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
455
diff
changeset
|
35 |
8e01c3174cc3
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
455
diff
changeset
|
36 if (addedType != null && toArmy.GetUnitTypeCount(AllowedObject) > 0) |
8e01c3174cc3
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
455
diff
changeset
|
37 { |
8e01c3174cc3
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
455
diff
changeset
|
38 foreach (UnitCountRequirementData limit in ConstraintTypes) |
8e01c3174cc3
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
455
diff
changeset
|
39 { |
8e01c3174cc3
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
455
diff
changeset
|
40 if (Arrays.Contains(limit.UnitTypes, addedType)) |
8e01c3174cc3
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
455
diff
changeset
|
41 { |
8e01c3174cc3
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
455
diff
changeset
|
42 isApplicable = true; |
8e01c3174cc3
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
455
diff
changeset
|
43 break; |
8e01c3174cc3
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
455
diff
changeset
|
44 } |
8e01c3174cc3
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
455
diff
changeset
|
45 } |
8e01c3174cc3
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
455
diff
changeset
|
46 } |
8e01c3174cc3
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
455
diff
changeset
|
47 |
8e01c3174cc3
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
455
diff
changeset
|
48 return isApplicable; |
362
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
49 } |
458 | 50 |
51 protected override int GetObjectCountFromArmy(Army toArmy, UnitType obj) | |
52 { | |
53 return toArmy.GetUnitTypeCount(obj); | |
54 } | |
362
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
55 } |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
56 } |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
57 |