Mercurial > repos > IBDev-IBBoard.WarFoundry.API
annotate API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirement.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 | dace3b7779ca |
children | afc6410e4efc |
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; |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
7 |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
8 namespace IBBoard.WarFoundry.API.Objects.Requirement |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
9 { |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
10 /// <summary> |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
11 /// 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
|
12 /// </summary> |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
13 public class UnitRequiresNoMoreThanNOfUnitTypeRequirement : RequiresNoMoreThanNOfUnitTypeRequirement |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
14 { |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
15 private UnitType requirementOnType; |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
16 |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
17 public UnitRequiresNoMoreThanNOfUnitTypeRequirement(UnitType requirementOn) : base() |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
18 { |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
19 requirementOnType = requirementOn; |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
20 } |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
21 |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
22 /// <summary> |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
23 /// Checks whether the supplied WarFoundryObject can be added to the supplied army. |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
24 /// </summary> |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
25 /// <returns> |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
26 /// A <code>Validation</code> enum to show the result of the validation |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
27 /// </returns> |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
28 /// <param name='wfObject'> |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
29 /// The object that we want to add. This may be involved in the check, or it may not affect the evaluation of the requirement |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
30 /// </param> |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
31 /// <param name='toArmy'> |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
32 /// The army to add the object to. |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
33 /// </param> |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
34 public override Validation AllowsAdding(WarFoundryObject wfObject, Army toArmy) |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
35 { |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
36 return IsApplicable(wfObject, toArmy) ? base.AllowsAdding(wfObject, toArmy) : Validation.NotApplicable; |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
37 } |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
38 |
419 | 39 protected override bool IsApplicable(WarFoundryObject toObject, Army toArmy) |
362
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
40 { |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
41 return IsApplicable(toArmy) || IsApplicable(toObject); |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
42 } |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
43 |
419 | 44 protected override bool IsApplicable(Army toArmy) |
362
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
45 { |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
46 return toArmy.GetUnitTypeCount(requirementOnType) > 0; |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
47 } |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
48 |
419 | 49 protected override bool IsApplicable(WarFoundryObject toObject) |
362
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
50 { |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
51 return requirementOnType.Equals(toObject) || (toObject is Unit && requirementOnType.Equals(((Unit)toObject).UnitType)); |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
52 } |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
53 } |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
54 } |
c19e61262400
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
343
diff
changeset
|
55 |