comparison API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirement.cs @ 455:afc6410e4efc

Re #379: Fix validation of requirements to check for unit * Move to "Unit" requirements, since we assume things depend on units * Rename some classes to more meaningful names from unit-based change * Rename "requires N for M" requirement as we can make it more flexible
author IBBoard <dev@ibboard.co.uk>
date Wed, 22 Feb 2012 20:45:39 +0000
parents def5d333c5e8
children 8e01c3174cc3
comparison
equal deleted inserted replaced
454:def5d333c5e8 455:afc6410e4efc
8 namespace IBBoard.WarFoundry.API.Objects.Requirement 8 namespace IBBoard.WarFoundry.API.Objects.Requirement
9 { 9 {
10 /// <summary> 10 /// <summary>
11 /// A requirement where a UnitType can only be taken if there are no more than N units of one or more unit in an army. 11 /// A requirement where a UnitType can only be taken if there are no more than N units of one or more unit in an army.
12 /// </summary> 12 /// </summary>
13 public class UnitRequiresNoMoreThanNOfUnitTypeRequirement : RequiresNoMoreThanNOfUnitTypeRequirement 13 public class UnitRequiresNoMoreThanNOfUnitTypeRequirement : RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>
14 { 14 {
15 private UnitType requirementOnType; 15 private UnitType requirementOnType;
16 16
17 public UnitRequiresNoMoreThanNOfUnitTypeRequirement(UnitType requirementOn) : base() 17 public UnitRequiresNoMoreThanNOfUnitTypeRequirement(UnitType requirementOn) : base()
18 { 18 {
29 /// The object that we want to add. This may be involved in the check, or it may not affect the evaluation of the requirement 29 /// The object that we want to add. This may be involved in the check, or it may not affect the evaluation of the requirement
30 /// </param> 30 /// </param>
31 /// <param name='toArmy'> 31 /// <param name='toArmy'>
32 /// The army to add the object to. 32 /// The army to add the object to.
33 /// </param> 33 /// </param>
34 public override Validation AllowsAdding(WarFoundryObject wfObject, Army toArmy) 34 public override Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy)
35 { 35 {
36 return IsApplicable(wfObject, toArmy) ? base.AllowsAdding(wfObject, toArmy) : Validation.NotApplicable; 36 return IsApplicable(wfObject, toArmy) ? base.AllowsAdding(wfObject, toArmy) : Validation.NotApplicable;
37 } 37 }
38 38
39 protected override bool IsApplicable(WarFoundryObject toObject, Army toArmy) 39 protected override bool IsApplicable(IWarFoundryObject toObject, Army toArmy)
40 { 40 {
41 return IsApplicable(toArmy) || IsApplicable(toObject); 41 return IsApplicable(toArmy) || IsApplicable(toObject);
42 } 42 }
43 43
44 protected override bool IsApplicable(Army toArmy) 44 protected override bool IsApplicable(Army toArmy)
45 { 45 {
46 return toArmy.GetUnitTypeCount(requirementOnType) > 0; 46 return toArmy.GetUnitTypeCount(requirementOnType) > 0;
47 } 47 }
48 48
49 protected override bool IsApplicable(WarFoundryObject toObject) 49 protected override bool IsApplicable(IWarFoundryObject toObject)
50 { 50 {
51 return requirementOnType.Equals(toObject) || (toObject is Unit && requirementOnType.Equals(((Unit)toObject).UnitType)); 51 return requirementOnType.Equals(toObject) || (toObject is Unit && requirementOnType.Equals(((Unit)toObject).UnitType));
52 } 52 }
53 } 53 }
54 } 54 }