view API/Objects/Requirement/AbstractRequirement.cs @ 381:30db6669f5cd

* Update to VS.Net 2010 compatibility * Fix whitespace no-open-ticket
author IBBoard <dev@ibboard.co.uk>
date Sun, 07 Aug 2011 19:15:33 +0000
parents 0dd8dbe8afe9
children 71fceea2725b
line source
1 // This file (AbstractRequirement.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;
7 namespace IBBoard.WarFoundry.API.Objects.Requirement
8 {
9 public abstract class AbstractRequirement : IRequirement
10 {
11 public override bool Equals (object obj)
12 {
13 if (obj == null)
14 {
15 return false;
16 }
17 else if (obj.GetType().Equals(this.GetType()))
18 {
19 return TypeEquals(obj);
20 }
21 else
22 {
23 return false;
24 }
25 }
27 /// <summary>
28 /// Type-specific equality checking - must be implemented by each class
29 /// </summary>
30 /// <returns>
31 /// <code>true</code> if this object is equal to <code>obj</code>, else <code>false</code>
32 /// </returns>
33 /// <param name='obj'>
34 /// The object to compare to
35 /// </param>
36 protected abstract bool TypeEquals(object obj);
38 protected virtual bool IsApplicable(WarFoundryObject toObjectAdded, Army toArmy)
39 {
40 return IsApplicable(toArmy) || IsApplicable(toObjectAdded);
41 }
43 protected virtual bool IsApplicable(Army toArmy)
44 {
45 return true;
46 }
48 protected virtual bool IsApplicable(WarFoundryObject toObject)
49 {
50 return true;
51 }
54 public string GetValidationMessage(Army army)
55 {
56 string message = "";
58 Validation result = ValidatesArmy(army);
59 if (!Validates.AsOkay(result))
60 {
61 message = GetValidationFailedMessage(army);
62 }
64 return message;
65 }
67 protected abstract string GetValidationFailedMessage(Army army);
69 public string GetAllowsAddingMessage(UnitType toAdd, Army toArmy)
70 {
71 string message = "";
73 Validation result = AllowsAdding(toAdd, toArmy);
74 if (!Validates.AsOkay(result))
75 {
76 message = GetAllowsAddingFailedMessage(toAdd, toArmy);
77 }
79 return message;
80 }
82 protected abstract string GetAllowsAddingFailedMessage(UnitType toAdd, Army toArmy);
84 public abstract Validation AllowsAdding(WarFoundryObject wfObject, Army toArmy);
86 public abstract Validation ValidatesArmy(Army army);
87 }
88 }