annotate API/Objects/Requirement/RequirementHandler.cs @ 454:def5d333c5e8

Re #379: Fix validation of requirements to check for unit * Remove custom messages for overrides to reduce verbosity * Add missing multiplication signs for readability
author IBBoard <dev@ibboard.co.uk>
date Tue, 31 Jan 2012 20:58:09 +0000
parents 676f5ce04176
children 248df19652f9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
353
65fccdd51aec Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 // This file (RequirementHandler.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard
65fccdd51aec Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
65fccdd51aec Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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.
65fccdd51aec Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 using System;
361
8781e53c59bb Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents: 355
diff changeset
5 using System.Collections.Generic;
353
65fccdd51aec Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6
65fccdd51aec Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 namespace IBBoard.WarFoundry.API.Objects.Requirement
65fccdd51aec Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 {
65fccdd51aec Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 /// <summary>
65fccdd51aec Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 /// The requirement handler that tests the validity of armies.
65fccdd51aec Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 /// </summary>
65fccdd51aec Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 public class RequirementHandler
65fccdd51aec Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 {
65fccdd51aec Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 private RequirementHandler()
65fccdd51aec Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 {
65fccdd51aec Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 }
363
506af4cbe3f5 Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents: 361
diff changeset
17
506af4cbe3f5 Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents: 361
diff changeset
18
506af4cbe3f5 Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents: 361
diff changeset
19 public static Validation ValidateArmy(Army army)
361
8781e53c59bb Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents: 355
diff changeset
20 {
8781e53c59bb Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents: 355
diff changeset
21 ICollection<string> ignored;
8781e53c59bb Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents: 355
diff changeset
22 return ValidateArmy(army, out ignored);
8781e53c59bb Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents: 355
diff changeset
23 }
8781e53c59bb Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents: 355
diff changeset
24
363
506af4cbe3f5 Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents: 361
diff changeset
25 public static Validation ValidateArmy(Army army, out ICollection<string> failureMessages)
506af4cbe3f5 Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents: 361
diff changeset
26 {
361
8781e53c59bb Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents: 355
diff changeset
27 Validation result = Validation.Passed;
363
506af4cbe3f5 Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents: 361
diff changeset
28 failureMessages = new List<string>();
506af4cbe3f5 Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents: 361
diff changeset
29
506af4cbe3f5 Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents: 361
diff changeset
30 foreach (IRequirement requirement in army.GetRequirements())
506af4cbe3f5 Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents: 361
diff changeset
31 {
506af4cbe3f5 Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents: 361
diff changeset
32 if (!Validates.AsOkay(requirement.ValidatesArmy(army)))
506af4cbe3f5 Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents: 361
diff changeset
33 {
361
8781e53c59bb Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents: 355
diff changeset
34 result = Validation.Failed;
363
506af4cbe3f5 Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents: 361
diff changeset
35 failureMessages.Add(requirement.GetValidationMessage(army));
506af4cbe3f5 Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents: 361
diff changeset
36 }
506af4cbe3f5 Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents: 361
diff changeset
37 }
506af4cbe3f5 Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents: 361
diff changeset
38
506af4cbe3f5 Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents: 361
diff changeset
39 return result;
506af4cbe3f5 Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents: 361
diff changeset
40 }
355
47712a323cf2 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 353
diff changeset
41
47712a323cf2 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 353
diff changeset
42 public static Validation AllowsAdding(UnitType unitType, Army army)
47712a323cf2 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 353
diff changeset
43 {
363
506af4cbe3f5 Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents: 361
diff changeset
44 ICollection<string> ignored;
506af4cbe3f5 Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents: 361
diff changeset
45 return AllowsAdding(unitType, army, out ignored);
506af4cbe3f5 Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents: 361
diff changeset
46 }
506af4cbe3f5 Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents: 361
diff changeset
47
506af4cbe3f5 Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents: 361
diff changeset
48 public static Validation AllowsAdding(UnitType unitType, Army army, out ICollection<string> failureMessages)
506af4cbe3f5 Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents: 361
diff changeset
49 {
355
47712a323cf2 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 353
diff changeset
50 Validation result = Validation.Passed;
363
506af4cbe3f5 Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents: 361
diff changeset
51 failureMessages = new List<string>();
506af4cbe3f5 Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents: 361
diff changeset
52
451
676f5ce04176 Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents: 363
diff changeset
53 foreach (IRequirement requirement in army.GetAddingUnitRequirements(unitType))
355
47712a323cf2 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 353
diff changeset
54 {
47712a323cf2 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 353
diff changeset
55 if (!Validates.AsOkay(requirement.AllowsAdding(unitType, army)))
47712a323cf2 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 353
diff changeset
56 {
47712a323cf2 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 353
diff changeset
57 result = Validation.Failed;
363
506af4cbe3f5 Fixes #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents: 361
diff changeset
58 failureMessages.Add(requirement.GetAllowsAddingMessage(unitType, army));
355
47712a323cf2 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 353
diff changeset
59 }
47712a323cf2 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 353
diff changeset
60 }
47712a323cf2 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 353
diff changeset
61
47712a323cf2 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 353
diff changeset
62 return result;
47712a323cf2 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 353
diff changeset
63 }
353
65fccdd51aec Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64 }
65fccdd51aec Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65 }
65fccdd51aec Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66