comparison API/Objects/Requirement/RequirementHandler.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 676f5ce04176
children 4f01fdc3bb41
comparison
equal deleted inserted replaced
486:6e5b39caeb4e 487:248df19652f9
1 // This file (RequirementHandler.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard 1 // This file (RequirementHandler.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard
2 // 2 //
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. 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.
4 using System; 4 using System;
5 using System.Collections.Generic; 5 using System.Collections.Generic;
6 using IBBoard.WarFoundry.API.Objects.Requirement.Context;
6 7
7 namespace IBBoard.WarFoundry.API.Objects.Requirement 8 namespace IBBoard.WarFoundry.API.Objects.Requirement
8 { 9 {
9 /// <summary> 10 /// <summary>
10 /// The requirement handler that tests the validity of armies. 11 /// The requirement handler that tests the validity of armies.
39 return result; 40 return result;
40 } 41 }
41 42
42 public static Validation AllowsAdding(UnitType unitType, Army army) 43 public static Validation AllowsAdding(UnitType unitType, Army army)
43 { 44 {
44 ICollection<string> ignored; 45 return AllowsAdding(unitType, army, new NullAddingContext());
45 return AllowsAdding(unitType, army, out ignored);
46 } 46 }
47 47
48 public static Validation AllowsAdding(UnitType unitType, Army army, AddingContext context)
49 {
50 ICollection<string> ignored;
51 return AllowsAdding(unitType, army, context, out ignored);
52 }
53
48 public static Validation AllowsAdding(UnitType unitType, Army army, out ICollection<string> failureMessages) 54 public static Validation AllowsAdding(UnitType unitType, Army army, out ICollection<string> failureMessages)
55 {
56 return AllowsAdding(unitType, army, new NullAddingContext(), out failureMessages);
57 }
58
59 public static Validation AllowsAdding(UnitType unitType, Army army, AddingContext context, out ICollection<string> failureMessages)
49 { 60 {
50 Validation result = Validation.Passed; 61 Validation result = Validation.Passed;
51 failureMessages = new List<string>(); 62 failureMessages = new List<string>();
52 63
53 foreach (IRequirement requirement in army.GetAddingUnitRequirements(unitType)) 64 foreach (IRequirement requirement in army.GetAddingUnitRequirements(unitType))
54 { 65 {
55 if (!Validates.AsOkay(requirement.AllowsAdding(unitType, army))) 66 if (!Validates.AsOkay(requirement.AllowsAdding(unitType, army)))
56 { 67 {
57 result = Validation.Failed; 68 result = Validation.Failed;
58 failureMessages.Add(requirement.GetAllowsAddingMessage(unitType, army)); 69 failureMessages.Add(requirement.GetAllowsAddingMessage(unitType, army, context));
59 } 70 }
60 } 71 }
61 72
62 return result; 73 return result;
63 } 74 }