Mercurial > repos > IBBoard.WarFoundry.API
comparison API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs @ 487:248df19652f9
Re #410: Create "N units per M models in parent unit" requirement
* Add null adding context
* Add initial skeleton of "N units per M models in parent unit" requirement
* Update use of context
* Standardise some of "is applicable" testing
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Fri, 27 Jul 2012 20:31:12 +0100 |
parents | e0641e0eb86c |
children |
comparison
equal
deleted
inserted
replaced
486:6e5b39caeb4e | 487:248df19652f9 |
---|---|
65 { | 65 { |
66 Validation canAdd = Validation.Passed; | 66 Validation canAdd = Validation.Passed; |
67 | 67 |
68 foreach (UnitCountRequirementData limit in ConstraintTypes) | 68 foreach (UnitCountRequirementData limit in ConstraintTypes) |
69 { | 69 { |
70 if (GetUnitTypeCount(toArmy, limit.UnitType, wfObject) > limit.Count) | 70 if (GetUnitTypeCount(toArmy, limit.UnitType, wfObject, context) > limit.Count) |
71 { | 71 { |
72 canAdd = Validation.Failed; | 72 canAdd = Validation.Failed; |
73 break; | 73 break; |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 return canAdd; | 77 return canAdd; |
78 } | 78 } |
79 | 79 |
80 private int GetUnitTypeCount(Army toArmy, UnitType unitType, WarFoundryObject wfObject) | 80 private int GetUnitTypeCount(Army toArmy, UnitType unitType, IWarFoundryObject wfObject, AddingContext context) |
81 { | 81 { |
82 return toArmy.GetUnitTypeCount(unitType) + GetCountFromObject(wfObject, unitType); | 82 return toArmy.GetUnitTypeCount(unitType) + GetCountFromObject(wfObject, unitType) + GetCountFromContext(context); |
83 } | 83 } |
84 | 84 |
85 private int GetCountFromObject(WarFoundryObject wfObject, UnitType limitedType) | 85 private int GetCountFromObject(IWarFoundryObject wfObject, UnitType limitedType, AddingContext context) |
86 { | 86 { |
87 return (limitedType.Equals(wfObject) || (wfObject is Unit && ((Unit)wfObject).UnitType.Equals(limitedType))) ? 1 : 0; | 87 return (limitedType.Equals(wfObject) || (wfObject is Unit && ((Unit)wfObject).UnitType.Equals(limitedType))) ? 1 : 0; |
88 } | |
89 | |
90 protected virtual int GetCountFromContext(AddingContext context) | |
91 { | |
92 return 0; | |
88 } | 93 } |
89 | 94 |
90 /// <summary> | 95 /// <summary> |
91 /// Adds a requirement for there to be no more than maxCount of a given UnitType | 96 /// Adds a requirement for there to be no more than maxCount of a given UnitType |
92 /// </summary> | 97 /// </summary> |
175 } | 180 } |
176 | 181 |
177 return failures; | 182 return failures; |
178 } | 183 } |
179 | 184 |
180 protected override string GetFailedAddingRequirementsString(IWarFoundryObject toAdd, Army toArmy) | 185 protected override string GetFailedAddingRequirementsString(IWarFoundryObject toAdd, Army toArmy, AddingContext context) |
181 { | 186 { |
182 return String.Join("; ", GetFailedAddingRequirements(toAdd, toArmy).ToArray()); | 187 return String.Join("; ", GetFailedAddingRequirements(toAdd, toArmy).ToArray()); |
183 } | 188 } |
184 | 189 |
185 private List<string> GetFailedAddingRequirements(IWarFoundryObject toAdd, Army army) | 190 private List<string> GetFailedAddingRequirements(IWarFoundryObject toAdd, Army army) |