view API/Objects/Requirement/RequirementHandler.cs @ 355:47712a323cf2

Re #27: Unit requirements * Implement check for adding units to army
author IBBoard <dev@ibboard.co.uk>
date Mon, 25 Apr 2011 10:32:51 +0000
parents 65fccdd51aec
children 8781e53c59bb
line source
1 // This file (RequirementHandler.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard
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.
4 using System;
6 namespace IBBoard.WarFoundry.API.Objects.Requirement
7 {
8 /// <summary>
9 /// The requirement handler that tests the validity of armies.
10 /// </summary>
11 public class RequirementHandler
12 {
13 private RequirementHandler()
14 {
15 }
17 public static Validation ValidateArmy (Army army)
18 {
19 Validation result = Validation.Passed;
21 foreach (IRequirement requirement in army.GetRequirements())
22 {
23 if (!Validates.AsOkay(requirement.ValidatesArmy(army)))
24 {
25 result = Validation.Failed;
26 break;
27 }
28 }
30 return result;
31 }
33 public static Validation AllowsAdding(UnitType unitType, Army army)
34 {
35 Validation result = Validation.Passed;
37 foreach (IRequirement requirement in army.GetRequirements())
38 {
39 if (!Validates.AsOkay(requirement.AllowsAdding(unitType, army)))
40 {
41 result = Validation.Failed;
42 break;
43 }
44 }
46 return result;
47 }
48 }
49 }