Mercurial > repos > IBDev-IBBoard.WarFoundry.API
annotate API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirement.cs @ 454:def5d333c5e8
Re #379: Fix validation of requirements to check for unit
* Remove custom messages for overrides to reduce verbosity
* Add missing multiplication signs for readability
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 31 Jan 2012 20:58:09 +0000 |
parents | b671085871b7 |
children | afc6410e4efc |
rev | line source |
---|---|
360
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
1 // This file (UnitRequiresAtLeastNUnitsRequirement.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
2 // |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
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. |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
4 using System; |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
5 using System.Collections.Generic; |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
6 using IBBoard.WarFoundry.API.Objects; |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
7 |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
8 namespace IBBoard.WarFoundry.API.Objects.Requirement |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
9 { |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
10 /// <summary> |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
11 /// A requirement where a UnitType requires at least N units of one or more unit types before any number of that object can be taken in an army. |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
12 /// </summary> |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
13 public class UnitRequiresAtLeastNUnitsRequirement : RequiresAtLeastNUnitsRequirement |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
14 { |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
15 private UnitType requirementOnType; |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
16 |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
17 public UnitRequiresAtLeastNUnitsRequirement(UnitType requirementOn) : base() |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
18 { |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
19 requirementOnType = requirementOn; |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
20 } |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
21 |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
22 protected override bool IsApplicable(WarFoundryObject toObjectAdded) |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
23 { |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
24 return base.IsApplicable(toObjectAdded) || IsRequirementOnType(toObjectAdded); |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
25 } |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
26 |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
27 private bool IsRequirementOnType(WarFoundryObject toObjectAdded) |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
28 { |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
29 return requirementOnType.Equals(toObjectAdded) || (toObjectAdded is Unit && requirementOnType.Equals(((Unit)toObjectAdded).UnitType)); |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
30 } |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
31 |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
32 protected override bool IsApplicable(Army toArmy) |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
33 { |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
34 return toArmy.GetUnitTypeCount(requirementOnType) > 0; |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
35 } |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
36 |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
37 public override Validation ValidatesArmy(Army toArmy) |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
38 { |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
39 return IsApplicable(toArmy) ? base.ValidatesArmy(toArmy) : Validation.NotApplicable; |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
40 } |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
41 } |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
42 } |
777725613edb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
350
diff
changeset
|
43 |