comparison API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs @ 479:f48c49b53738

Re #410: "N units per M models in parent" requirement * Add a "context" object that will hold the parent unit (or possibly other stuff) * Update all method signatures and calls
author IBBoard <dev@ibboard.co.uk>
date Wed, 23 May 2012 20:56:27 +0100
parents 159dc9be36c2
children e0641e0eb86c
comparison
equal deleted inserted replaced
478:e4e2a85604b6 479:f48c49b53738
26 { 26 {
27 return REQUIREMENT_ID; 27 return REQUIREMENT_ID;
28 } 28 }
29 } 29 }
30 30
31 /// <summary> 31 protected override bool IsApplicable(Army toArmy, AddingContext context)
32 /// Checks whether the supplied WarFoundryObject can be added to the supplied army.
33 /// </summary>
34 /// <returns>
35 /// A <code>Validation</code> enum to show the result of the validation
36 /// </returns>
37 /// <param name='wfObject'>
38 /// The object that we want to add. This may be involved in the check, or it may not affect the evaluation of the requirement
39 /// </param>
40 /// <param name='toArmy'>
41 /// The army to add the object to.
42 /// </param>
43 public override Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy)
44 {
45 return IsApplicable(wfObject, toArmy) ? CheckAllowsAdding(wfObject, toArmy) : Validation.NotApplicable;
46 }
47
48 protected override bool IsApplicable(Army toArmy)
49 { 32 {
50 return false; 33 return false;
51 } 34 }
52 35
53 protected override bool IsApplicable(IWarFoundryObject toObject) 36 protected override bool IsApplicable(IWarFoundryObject toObject, AddingContext context)
54 { 37 {
55 bool isApplicable = false; 38 bool isApplicable = false;
56 UnitType unitType = GetUnitTypeFromObject(toObject); 39 UnitType unitType = GetUnitTypeFromObject(toObject);
57 40
58 if (unitType != null) 41 if (unitType != null)
75 } 58 }
76 } 59 }
77 return isApplicable; 60 return isApplicable;
78 } 61 }
79 62
80 private Validation CheckAllowsAdding(IWarFoundryObject wfObject, Army toArmy) 63 protected override Validation CheckAllowsAdding(IWarFoundryObject wfObject, Army toArmy, AddingContext context)
81 { 64 {
82 Validation canAdd = Validation.Passed; 65 Validation canAdd = Validation.Passed;
83 66
84 foreach (UnitCountRequirementData limit in ConstraintTypes) 67 foreach (UnitCountRequirementData limit in ConstraintTypes)
85 { 68 {