Mercurial > repos > IBDev-IBBoard.WarFoundry.API
annotate API/Objects/Requirement/RequiresNUnitsForMUnitsRequirement.cs @ 446:ca1e8f7c8b73
Re: #350: Add requirement to allow N of unit for specific other units
* Update army validation to support required amounts other than 1
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 20 Dec 2011 20:26:54 +0000 |
parents | 2d1bdd679f82 |
children | 4fbb7f205f7e |
rev | line source |
---|---|
437
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
1 // This file(RequiresNUnitsForMUnitsRequirement.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
2 // |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
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. |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
4 using System; |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
5 using System.Collections.Generic; |
438
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
6 using System.Text; |
437
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
7 |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
8 namespace IBBoard.WarFoundry.API.Objects.Requirement |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
9 { |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
10 public class RequiresNUnitsForMUnitsRequirement : AbstractRequirement |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
11 { |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
12 public static readonly string REQUIREMENT_ID = "RequiresNUnitsForMUnits"; |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
13 private List<UnitCountRequirementData> requiredTypes; |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
14 private UnitType allowedType; |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
15 |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
16 public RequiresNUnitsForMUnitsRequirement(UnitType allowedType, params UnitType[] requiredUnitTypes) |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
17 { |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
18 this.allowedType = allowedType; |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
19 FailureStringPrefix = "Army must contain: "; |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
20 requiredTypes = new List<UnitCountRequirementData>(); |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
21 |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
22 foreach (UnitType unitType in requiredUnitTypes) |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
23 { |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
24 AddUnitTypeRequirement(unitType); |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
25 } |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
26 } |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
27 |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
28 public override int GetHashCode() |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
29 { |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
30 int hash = 0; |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
31 |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
32 foreach (UnitCountRequirementData req in requiredTypes) |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
33 { |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
34 hash += req.UnitType.GetHashCode(); |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
35 } |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
36 |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
37 return hash; |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
38 } |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
39 |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
40 protected override bool TypeEquals(object obj) |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
41 { |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
42 RequiresNUnitsForMUnitsRequirement otherReq = (RequiresNUnitsForMUnitsRequirement)obj; |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
43 if (!Collections.Collections.AreEqual(requiredTypes, otherReq.requiredTypes)) |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
44 { |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
45 return false; |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
46 } |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
47 else |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
48 { |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
49 return true; |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
50 } |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
51 } |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
52 |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
53 protected string FailureStringPrefix { get; set; } |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
54 |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
55 protected override string GetAllowsAddingFailedMessage(UnitType toAdd, Army toArmy) |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
56 { |
438
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
57 StringBuilder sb = new StringBuilder(); |
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
58 sb.Append(FailureStringPrefix); |
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
59 sb.Append(String.Join("; ", GetFailedAddingRequirements(toAdd, toArmy).ToArray())); |
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
60 sb.Append("."); |
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
61 return sb.ToString(); |
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
62 } |
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
63 |
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
64 private List<string> GetFailedAddingRequirements(UnitType unitType, Army toArmy) |
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
65 { |
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
66 List<string> failures = new List<string>(); |
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
67 int allowedTypeCount = GetUnitTypeCount(toArmy, allowedType, unitType); |
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
68 |
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
69 foreach (UnitCountRequirementData limit in requiredTypes) |
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
70 { |
444
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
71 int limitedTypeCount = GetUnitTypesCount(toArmy, limit.UnitTypes, unitType); |
438
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
72 |
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
73 if (!IsValidByRequirement(unitType, toArmy, limit, allowedTypeCount)) |
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
74 { |
444
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
75 string unitTypeList = GetUnitTypeList(limit); |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
76 failures.Add(String.Format("{0} {1} for every {2} {3} (would have {4} for {5})", limit.Count, unitTypeList, limit.AllowsCount, allowedType.Name, limitedTypeCount, allowedTypeCount)); |
438
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
77 } |
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
78 } |
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
79 |
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
80 return failures; |
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
81 } |
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
82 |
444
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
83 private string GetUnitTypeList(UnitCountRequirementData limit) |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
84 { |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
85 List<String> namesList = new List<String>(); |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
86 |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
87 foreach (UnitType unitType in limit.UnitTypes) |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
88 { |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
89 namesList.Add(unitType.Name); |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
90 } |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
91 |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
92 string[] names = namesList.ToArray(); |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
93 return String.Join(" or ", names); |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
94 } |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
95 |
438
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
96 private bool IsValidByRequirement(WarFoundryObject wfObject, Army toArmy, UnitCountRequirementData limit, int allowedTypeCount) |
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
97 { |
444
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
98 int limitedTypeCount = GetUnitTypesCount(toArmy, limit.UnitTypes, wfObject); |
438
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
99 return IsValidByRequirement(limit, allowedTypeCount, limitedTypeCount); |
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
100 } |
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
101 |
439
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
102 private bool IsValidByRequirement(UnitCountRequirementData limit, int allowedTypeCount, int limitedTypeCount) |
438
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
103 { |
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
104 double limitedTypeMultiplier = limitedTypeCount / (limit.Count * 1.0); |
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
105 double allowedTypeMultiplier = allowedTypeCount / (limit.AllowsCount * 1.0); |
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
106 return allowedTypeMultiplier <= limitedTypeMultiplier; |
437
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
107 } |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
108 |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
109 public override Validation AllowsAdding(WarFoundryObject wfObject, Army toArmy) |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
110 { |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
111 Validation canAdd = Validation.NotApplicable; |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
112 UnitType addedUnitType = (wfObject is Unit) ? ((Unit)wfObject).UnitType : wfObject as UnitType; |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
113 bool typeFound = (addedUnitType == allowedType); |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
114 int allowedTypeCount = GetUnitTypeCount(toArmy, allowedType, wfObject); |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
115 |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
116 foreach (UnitCountRequirementData limit in requiredTypes) |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
117 { |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
118 typeFound |= (addedUnitType == limit.UnitType); |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
119 |
438
410f3d85c9c5
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
120 if (!IsValidByRequirement(wfObject, toArmy, limit, allowedTypeCount)) |
437
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
121 { |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
122 canAdd = Validation.Failed; |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
123 break; |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
124 } |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
125 } |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
126 |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
127 if (typeFound && canAdd == Validation.NotApplicable) |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
128 { |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
129 canAdd = Validation.Passed; |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
130 } |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
131 |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
132 return canAdd; |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
133 } |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
134 |
444
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
135 private int GetUnitTypesCount(Army toArmy, UnitType[] unitTypes, WarFoundryObject wfObject) |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
136 { |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
137 int count = 0; |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
138 |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
139 foreach (UnitType unitType in unitTypes) |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
140 { |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
141 count += GetUnitTypeCount(toArmy, unitType, wfObject); |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
142 } |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
143 |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
144 return count; |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
145 } |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
146 |
437
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
147 private int GetUnitTypeCount(Army toArmy, UnitType unitType, WarFoundryObject wfObject) |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
148 { |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
149 return toArmy.GetUnitTypeCount(unitType) + GetCountFromObject(wfObject, unitType); |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
150 } |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
151 |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
152 private int GetCountFromObject(WarFoundryObject wfObject, UnitType limitedType) |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
153 { |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
154 return (limitedType.Equals(wfObject) || (wfObject is Unit && ((Unit)wfObject).UnitType.Equals(limitedType))) ? 1 : 0; |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
155 } |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
156 |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
157 public override Validation ValidatesArmy(Army army) |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
158 { |
439
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
159 Validation canAdd = Validation.NotApplicable; |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
160 int allowedTypeCount = army.GetUnitTypeCount(allowedType); |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
161 bool typeFound = (allowedTypeCount > 0); |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
162 |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
163 foreach (UnitCountRequirementData limit in requiredTypes) |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
164 { |
446
ca1e8f7c8b73
Re: #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
445
diff
changeset
|
165 int limitedTypeCount = GetUnitTypesCount(army, limit.UnitTypes); |
439
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
166 typeFound |= (limitedTypeCount > 0); |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
167 |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
168 if (!IsValidByRequirement(limit, allowedTypeCount, limitedTypeCount)) |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
169 { |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
170 canAdd = Validation.Failed; |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
171 break; |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
172 } |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
173 } |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
174 |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
175 if (typeFound && canAdd == Validation.NotApplicable) |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
176 { |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
177 canAdd = Validation.Passed; |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
178 } |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
179 |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
180 return canAdd; |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
181 } |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
182 |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
183 protected override string GetValidationFailedMessage(Army army) |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
184 { |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
185 StringBuilder sb = new StringBuilder(); |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
186 sb.Append(FailureStringPrefix); |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
187 sb.Append(String.Join("; ", GetFailedValidationRequirements(army).ToArray())); |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
188 sb.Append("."); |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
189 return sb.ToString(); |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
190 } |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
191 |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
192 private List<string> GetFailedValidationRequirements(Army army) |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
193 { |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
194 List<string> failures = new List<string>(); |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
195 int allowedTypeCount = army.GetUnitTypeCount(allowedType); |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
196 |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
197 foreach (UnitCountRequirementData limit in requiredTypes) |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
198 { |
446
ca1e8f7c8b73
Re: #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
445
diff
changeset
|
199 int limitedTypeCount = GetUnitTypesCount(army, limit.UnitTypes); |
439
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
200 |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
201 if (!IsValidByRequirement(limit, allowedTypeCount, limitedTypeCount)) |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
202 { |
446
ca1e8f7c8b73
Re: #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
445
diff
changeset
|
203 string unitTypeList = GetUnitTypeList(limit); |
ca1e8f7c8b73
Re: #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
445
diff
changeset
|
204 failures.Add(String.Format("{0} {1} for every {2} {3} (have {4} for {5})", limit.Count, unitTypeList, limit.AllowsCount, allowedType.Name, limitedTypeCount, allowedTypeCount)); |
439
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
205 } |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
206 } |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
207 |
5252dfb9cdfb
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
438
diff
changeset
|
208 return failures; |
437
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
209 } |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
210 |
446
ca1e8f7c8b73
Re: #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
445
diff
changeset
|
211 private int GetUnitTypesCount(Army army, UnitType[] unitTypes) |
ca1e8f7c8b73
Re: #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
445
diff
changeset
|
212 { |
ca1e8f7c8b73
Re: #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
445
diff
changeset
|
213 return GetUnitTypesCount(army, unitTypes, null); |
ca1e8f7c8b73
Re: #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
445
diff
changeset
|
214 } |
ca1e8f7c8b73
Re: #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
445
diff
changeset
|
215 |
437
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
216 public override string RequirementID |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
217 { |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
218 get |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
219 { |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
220 return REQUIREMENT_ID; |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
221 } |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
222 } |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
223 |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
224 /// <summary> |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
225 /// Adds a requirement for there to be at least minCount of a given UnitType, allowing allowedCount of this UnitType |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
226 /// </summary> |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
227 /// <param name='unitType'> |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
228 /// The unit type to require. |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
229 /// </param> |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
230 /// <param name='minCount'> |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
231 /// The minimum number of that type that must exist. |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
232 /// </param> |
441
d2331ee59d74
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
440
diff
changeset
|
233 /// <param name='allowedCount'> |
d2331ee59d74
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
440
diff
changeset
|
234 /// The number of units allowed for every minCount units of the supplied unit type. |
d2331ee59d74
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
440
diff
changeset
|
235 /// </param> |
437
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
236 public void AddUnitTypeRequirement(UnitType unitType, int minCount, int allowedCount) |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
237 { |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
238 requiredTypes.Add(new UnitCountRequirementData(unitType, minCount, allowedCount)); |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
239 } |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
240 |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
241 /// <summary> |
441
d2331ee59d74
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
440
diff
changeset
|
242 /// Adds a requirement for there to be at least one of a given UnitType, allowing allowedCount of this UnitType |
d2331ee59d74
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
440
diff
changeset
|
243 /// </summary> |
d2331ee59d74
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
440
diff
changeset
|
244 /// <param name='unitType'> |
d2331ee59d74
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
440
diff
changeset
|
245 /// The unit type to require. |
d2331ee59d74
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
440
diff
changeset
|
246 /// </param> |
d2331ee59d74
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
440
diff
changeset
|
247 /// <param name='allowedCount'> |
d2331ee59d74
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
440
diff
changeset
|
248 /// The number of units allowed for each unit of the supplied unit type. |
d2331ee59d74
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
440
diff
changeset
|
249 /// </param> |
d2331ee59d74
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
440
diff
changeset
|
250 public void AddUnitTypeRequirement(UnitType unitType, int allowedCount) |
d2331ee59d74
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
440
diff
changeset
|
251 { |
445
2d1bdd679f82
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
444
diff
changeset
|
252 AddUnitTypeRequirement(allowedCount, unitType); |
441
d2331ee59d74
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
440
diff
changeset
|
253 } |
d2331ee59d74
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
440
diff
changeset
|
254 |
d2331ee59d74
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
440
diff
changeset
|
255 /// <summary> |
445
2d1bdd679f82
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
444
diff
changeset
|
256 /// Adds a requirement for there to be one or more of the given UnitTypes, allowing one of this UnitType. If multiple unit types |
444
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
257 /// are supplied here then the number is additive (so 1 x unitType1 and 1 x unitType2 allows two of this UnitType). |
437
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
258 /// </summary> |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
259 /// <param name='unitType'> |
444
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
260 /// The unit type or types to require. |
437
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
261 /// </param> |
444
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
262 public void AddUnitTypeRequirement(params UnitType[] unitTypes) |
437
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
263 { |
444
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
264 AddUnitTypeRequirement(1, unitTypes); |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
265 } |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
266 |
445
2d1bdd679f82
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
444
diff
changeset
|
267 /// <summary> |
2d1bdd679f82
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
444
diff
changeset
|
268 /// Adds a requirement for there to be one or more of the given UnitTypes, allowing allowsAmount of this UnitType. If multiple unit types |
2d1bdd679f82
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
444
diff
changeset
|
269 /// are supplied here then the number is additive (so 1 x unitType1 and 1 x unitType2 allows two of this UnitType). |
2d1bdd679f82
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
444
diff
changeset
|
270 /// </summary> |
2d1bdd679f82
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
444
diff
changeset
|
271 /// <param name="allowsAmount"> |
2d1bdd679f82
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
444
diff
changeset
|
272 /// The number of units to be allowed for each 1 of unitType |
2d1bdd679f82
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
444
diff
changeset
|
273 /// </param> |
2d1bdd679f82
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
444
diff
changeset
|
274 /// <param name='unitType'> |
2d1bdd679f82
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
444
diff
changeset
|
275 /// The unit type or types to require. |
2d1bdd679f82
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
444
diff
changeset
|
276 /// </param> |
2d1bdd679f82
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
444
diff
changeset
|
277 public void AddUnitTypeRequirement(int allowsAmount, params UnitType[] unitTypes) |
444
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
441
diff
changeset
|
278 { |
445
2d1bdd679f82
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
444
diff
changeset
|
279 requiredTypes.Add(new UnitCountRequirementData(unitTypes, 1, allowsAmount)); |
437
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
280 } |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
281 } |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
282 } |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
283 |