annotate API/Objects/Requirement/AbstractUnitRequirement.cs @ 456:52baffdd2ab9

Re #379: Fix validation of requirements to check for unit * Default to not being applicable - make requirements say when they are * Fix UnitRequiresNUnitsForMUnitsRequirement to not be applicable when adding unrelated units (even if army itself fails the rule) * Fix type casting issues in equality check
author IBBoard <dev@ibboard.co.uk>
date Sat, 25 Feb 2012 16:35:31 +0000
parents afc6410e4efc
children 8e01c3174cc3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
455
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 // This file (AbstractRequirement.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
afc6410e4efc 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.
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 using System;
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using System.Collections.Generic;
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6
afc6410e4efc 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
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 {
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 public abstract class AbstractUnitRequirement<OBJECT_TYPE> : IRequirement where OBJECT_TYPE : IWarFoundryObject
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 {
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 private List<UnitCountRequirementData> requiredTypes;
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 private OBJECT_TYPE allowedObject;
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 public AbstractUnitRequirement(OBJECT_TYPE allowedObject, params UnitType[] requiredUnitTypes)
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 {
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 this.allowedObject = allowedObject;
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 requiredTypes = new List<UnitCountRequirementData>();
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 foreach (UnitType unitType in requiredUnitTypes)
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 {
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 AddUnitTypeRequirement(unitType);
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 }
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 }
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 public abstract string RequirementID { get; }
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 protected List<UnitCountRequirementData> RequiredTypes { get { return requiredTypes; } }
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 public abstract void AddUnitTypeRequirement(UnitType unitType);
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 public override bool Equals(object obj)
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 {
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 if (obj == null)
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 {
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 return false;
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 }
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 else if (obj.GetType().Equals(this.GetType()))
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38 {
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 return TypeEquals(obj);
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 }
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 else
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 {
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 return false;
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 }
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 }
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47 public override abstract int GetHashCode();
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 /// <summary>
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50 /// Type-specific equality checking - must be implemented by each class
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51 /// </summary>
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
52 /// <returns>
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53 /// <code>true</code> if this object is equal to <code>obj</code>, else <code>false</code>
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54 /// </returns>
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55 /// <param name='obj'>
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56 /// The object to compare to
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 /// </param>
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 protected abstract bool TypeEquals(object obj);
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
60 protected virtual bool IsApplicable(IWarFoundryObject toObjectAdded, Army toArmy)
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
61 {
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
62 return IsApplicable(toArmy) || IsApplicable(toObjectAdded);
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
63 }
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65 protected virtual bool IsApplicable(Army toArmy)
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66 {
456
52baffdd2ab9 Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents: 455
diff changeset
67 return false;
455
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
68 }
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
69
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
70 protected virtual bool IsApplicable(IWarFoundryObject toObject)
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
71 {
456
52baffdd2ab9 Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents: 455
diff changeset
72 return false;
455
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
73 }
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
74
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
75 public string GetValidationMessage(Army army)
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
76 {
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
77 string message = "";
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
78
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
79 Validation result = ValidatesArmy(army);
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
80 if (!Validates.AsOkay(result))
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
81 {
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
82 message = GetValidationFailedMessage(army);
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
83 }
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
84
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
85 return message;
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
86 }
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
87
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
88 protected virtual string ValidationFailedMessage { get { return "Army must contain: {0}."; } }
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
89
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
90 private string GetValidationFailedMessage(Army army)
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
91 {
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
92 return String.Format(ValidationFailedMessage, GetFailedRequirementsString(army));
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
93 }
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
94
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
95 protected abstract string GetFailedRequirementsString(Army army);
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
96
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
97 public string GetAllowsAddingMessage(IWarFoundryObject toAdd, Army toArmy)
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
98 {
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
99 string message = "";
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
100
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
101 Validation result = AllowsAdding(toAdd, toArmy);
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
102 if (!Validates.AsOkay(result))
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
103 {
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
104 message = GetAllowsAddingFailedMessage(toAdd, toArmy);
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
105 }
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
106
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
107 return message;
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
108 }
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
109
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
110 protected virtual string AllowsAddingFailedMessage { get { return ValidationFailedMessage; } }
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
111
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
112 protected string GetAllowsAddingFailedMessage(IWarFoundryObject toAdd, Army toArmy)
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
113 {
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
114 return String.Format(AllowsAddingFailedMessage, GetFailedAddingRequirementsString(toAdd, toArmy));
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
115 }
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
116
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
117 protected abstract string GetFailedAddingRequirementsString(IWarFoundryObject toAdd, Army toArmy);
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
118
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
119 public abstract Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy);
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
120
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
121 public abstract Validation ValidatesArmy(Army army);
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
122
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
123 protected UnitType GetUnitTypeFromObject(IWarFoundryObject toObject)
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
124 {
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
125 UnitType unitType = null;
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
126
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
127 if (toObject is UnitType)
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
128 {
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
129 unitType = (UnitType)toObject;
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
130 }
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
131 else if (toObject is Unit)
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
132 {
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
133 unitType = ((Unit)toObject).UnitType;
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
134 }
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
135
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
136 return unitType;
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
137 }
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
138
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
139 protected int GetUnitTypeCount(Army toArmy, UnitType unitType, IWarFoundryObject wfObject)
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
140 {
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
141 return toArmy.GetUnitTypeCount(unitType) + GetCountFromObject(wfObject, unitType);
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
142 }
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
143
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
144 protected int GetCountFromObject(IWarFoundryObject wfObject, UnitType limitedType)
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
145 {
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
146 return (limitedType.Equals(wfObject) || (wfObject is Unit && ((Unit)wfObject).UnitType.Equals(limitedType))) ? 1 : 0;
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
147 }
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
148
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
149 protected int GetObjectCount(Army toArmy, IWarFoundryObject wfObject)
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
150 {
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
151 return GetObjectCountFromArmy(toArmy) + GetObjectCountFromObject(wfObject);
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
152 }
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
153
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
154 protected abstract int GetObjectCountFromArmy(Army toArmy);
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
155
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
156 protected virtual int GetObjectCountFromObject(IWarFoundryObject wfObject)
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
157 {
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
158 return allowedObject.Equals(wfObject) ? 1 : 0;
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
159 }
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
160
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
161 public OBJECT_TYPE AllowedObject { get { return allowedObject; } }
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
162 }
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
163 }
afc6410e4efc Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
164