annotate API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs @ 358:dbe7ccb1e557

Re #345: Add failure message to requirements * Add abstract requirement class to handle some of the message commonality
author IBBoard <dev@ibboard.co.uk>
date Sun, 01 May 2011 13:56:20 +0000
parents 50d0d3b39a0b
children 2a9c046be55a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
357
50d0d3b39a0b Re #140: Add equality methods
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
337
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
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.
357
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
4 using System;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
5 using System.Collections.Generic;
337
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using IBBoard.WarFoundry.API.Objects;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 namespace IBBoard.WarFoundry.API.Objects.Requirement
357
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
9 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
10 /// <summary>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
11 /// A requirement where a WarFoundryObject requires at least N units of one or more unit types before any number of that object can be taken in an army.
337
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 /// </summary>
358
dbe7ccb1e557 Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents: 357
diff changeset
13 public class RequiresAtLeastNUnitsRequirement : AbstractRequirement
357
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
14 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
15 private List<UnitCountRequirementData> requiredTypes;
337
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 public RequiresAtLeastNUnitsRequirement(params UnitType[] requiredUnitTypes)
357
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
18 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
19 requiredTypes = new List<UnitCountRequirementData>();
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
20
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
21 foreach (UnitType unitType in requiredUnitTypes)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
22 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
23 AddUnitTypeRequirement(unitType);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
24 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
25 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
26
358
dbe7ccb1e557 Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents: 357
diff changeset
27 protected override bool TypeEquals (object obj)
357
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
28 {
358
dbe7ccb1e557 Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents: 357
diff changeset
29 RequiresAtLeastNUnitsRequirement otherReq = (RequiresAtLeastNUnitsRequirement)obj;
dbe7ccb1e557 Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents: 357
diff changeset
30 if (!Collections.Collections.AreEqual(requiredTypes, otherReq.requiredTypes))
357
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
31 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
32 return false;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
33 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
34 else
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
35 {
358
dbe7ccb1e557 Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents: 357
diff changeset
36 return true;
357
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
37 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
38 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
39
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
40 /// <summary>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
41 /// Checks whether the supplied WarFoundryObject can be added to the supplied army.
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
42 /// </summary>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
43 /// <returns>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
44 /// A <code>Validation</code> enum to show the result of the validation
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
45 /// </returns>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
46 /// <param name='wfObject'>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
47 /// The object that we want to add. This may be involved in the check, or it may not affect the evaluation of the requirement
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
48 /// </param>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
49 /// <param name='toArmy'>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
50 /// The army to add the object to.
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
51 /// </param>
358
dbe7ccb1e557 Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents: 357
diff changeset
52 public override Validation AllowsAdding(WarFoundryObject wfObject, Army toArmy)
357
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
53 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
54 return IsApplicable(wfObject, toArmy) ? CheckAllowsAdding(wfObject, toArmy) : Validation.NotApplicable;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
55 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
56
358
dbe7ccb1e557 Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents: 357
diff changeset
57 protected override bool IsApplicable(Army toArmy)
357
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
58 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
59 return false;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
60 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
61
358
dbe7ccb1e557 Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents: 357
diff changeset
62 protected override bool IsApplicable(WarFoundryObject toObject)
357
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
63 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
64 bool isApplicable = false;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
65 UnitType unitType = GetUnitTypeFromObject(toObject);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
66
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
67 if (unitType != null)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
68 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
69 isApplicable = IsApplicable(unitType);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
70 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
71
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
72 return isApplicable;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
73 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
74
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
75 protected UnitType GetUnitTypeFromObject (WarFoundryObject toObject)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
76 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
77 UnitType unitType = null;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
78
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
79 if (toObject is UnitType)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
80 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
81 unitType = (UnitType)toObject;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
82 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
83 else if (toObject is Unit)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
84 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
85 unitType = ((Unit)toObject).UnitType;
337
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
86 }
357
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
87
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
88 return unitType;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
89 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
90
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
91 private bool IsApplicable (UnitType unitType)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
92 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
93 bool isApplicable = false;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
94 foreach (UnitCountRequirementData requirement in requiredTypes)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
95 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
96 if (requirement.UnitType.Equals(unitType))
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
97 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
98 isApplicable = true;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
99 break;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
100 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
101 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
102 return isApplicable;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
103 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
104
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
105 private Validation CheckAllowsAdding(WarFoundryObject wfObject, Army toArmy)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
106 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
107 Validation isValid = Validation.Passed;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
108
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
109 foreach (UnitCountRequirementData requirement in requiredTypes)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
110 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
111 if (GetUnitTypeCount(toArmy, requirement.UnitType, wfObject) < requirement.Count)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
112 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
113 isValid = Validation.Failed;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
114 break;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
115 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
116 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
117
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
118 return isValid;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
119 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
120
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
121 private int GetUnitTypeCount(Army toArmy, UnitType unitType, WarFoundryObject wfObject)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
122 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
123 return toArmy.GetUnitTypeCount(unitType) + GetCountFromObject(wfObject, unitType);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
124 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
125
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
126 private int GetCountFromObject(WarFoundryObject wfObject, UnitType limitedType)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
127 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
128 return (limitedType.Equals(wfObject) || (wfObject is Unit && ((Unit)wfObject).UnitType.Equals(limitedType))) ? 1 : 0;
337
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
129 }
357
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
130
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
131 /// <summary>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
132 /// Adds a requirement for there to be at least minCount of a given UnitType
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
133 /// </summary>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
134 /// <param name='unitType'>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
135 /// The unit type to require.
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
136 /// </param>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
137 /// <param name='minCount'>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
138 /// The minimum number of that type that must exist.
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
139 /// </param>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
140 public void AddUnitTypeRequirement(UnitType unitType, int minCount)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
141 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
142 requiredTypes.Add(new UnitCountRequirementData(unitType, minCount));
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
143 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
144
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
145 /// <summary>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
146 /// Adds a requirement for there to be one or more of a given UnitType
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
147 /// </summary>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
148 /// <param name='unitType'>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
149 /// The unit type to require.
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
150 /// </param>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
151 public void AddUnitTypeRequirement (UnitType unitType)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
152 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
153 AddUnitTypeRequirement(unitType, 1);
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
154 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
155
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
156 /// <summary>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
157 /// Checks whether the supplied army is currently valid according to this requirement.
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
158 /// </summary>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
159 /// <returns>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
160 /// A <code>Validation</code> enum to show the result of the validation
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
161 /// </returns>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
162 /// <param name='toValidate'>
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
163 /// The army to validate
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
164 /// </param>
358
dbe7ccb1e557 Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents: 357
diff changeset
165 public override Validation ValidatesArmy(Army toValidate)
357
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
166 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
167 Validation isValid = Validation.Passed;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
168
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
169 foreach (UnitCountRequirementData requirement in requiredTypes)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
170 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
171 if (toValidate.GetUnitTypeCount(requirement.UnitType) < requirement.Count)
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
172 {
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
173 isValid = Validation.Failed;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
174 break;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
175 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
176 }
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
177
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
178 return isValid;
50d0d3b39a0b Re #140: Add equality methods
IBBoard <dev@ibboard.co.uk>
parents: 350
diff changeset
179 }
358
dbe7ccb1e557 Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents: 357
diff changeset
180
dbe7ccb1e557 Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents: 357
diff changeset
181 protected override string GetValidationFailedMessage (Army army)
dbe7ccb1e557 Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents: 357
diff changeset
182 {
dbe7ccb1e557 Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents: 357
diff changeset
183 string message = "";
dbe7ccb1e557 Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents: 357
diff changeset
184 return message;
dbe7ccb1e557 Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents: 357
diff changeset
185 }
337
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
186 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
187 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
188