Mercurial > repos > IBBoard.WarFoundry.API
annotate API/Objects/Requirement/AbstractRequirement.cs @ 448:dbd779cdc0f9
Re #350: Add requirement to allow N of unit for specific other units
* Fix limit checking when "limited count" is not 1 (e.g. "need 2 for every 3")
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Fri, 23 Dec 2011 15:36:06 +0000 |
parents | 8f5125740316 |
children | dace3b7779ca |
rev | line source |
---|---|
358
dbe7ccb1e557
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
1 // This file (AbstractRequirement.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard |
dbe7ccb1e557
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
2 // |
dbe7ccb1e557
Re #345: Add failure message to 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. |
dbe7ccb1e557
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
4 using System; |
dbe7ccb1e557
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
5 |
381
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
6 |
358
dbe7ccb1e557
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
7 namespace IBBoard.WarFoundry.API.Objects.Requirement |
dbe7ccb1e557
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
8 { |
dbe7ccb1e557
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
9 public abstract class AbstractRequirement : IRequirement |
381
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
10 { |
427
3882b533d99d
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
419
diff
changeset
|
11 public abstract string RequirementID { get; } |
3882b533d99d
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
419
diff
changeset
|
12 |
381
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
13 public override bool Equals (object obj) |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
14 { |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
15 if (obj == null) |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
16 { |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
17 return false; |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
18 } |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
19 else if (obj.GetType().Equals(this.GetType())) |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
20 { |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
21 return TypeEquals(obj); |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
22 } |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
23 else |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
24 { |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
25 return false; |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
26 } |
358
dbe7ccb1e557
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
27 } |
381
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
28 |
419 | 29 public override abstract int GetHashCode(); |
30 | |
381
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
31 /// <summary> |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
32 /// Type-specific equality checking - must be implemented by each class |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
33 /// </summary> |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
34 /// <returns> |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
35 /// <code>true</code> if this object is equal to <code>obj</code>, else <code>false</code> |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
36 /// </returns> |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
37 /// <param name='obj'> |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
38 /// The object to compare to |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
39 /// </param> |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
40 protected abstract bool TypeEquals(object obj); |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
41 |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
42 protected virtual bool IsApplicable(WarFoundryObject toObjectAdded, Army toArmy) |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
43 { |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
44 return IsApplicable(toArmy) || IsApplicable(toObjectAdded); |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
45 } |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
46 |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
47 protected virtual bool IsApplicable(Army toArmy) |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
48 { |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
49 return true; |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
50 } |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
51 |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
52 protected virtual bool IsApplicable(WarFoundryObject toObject) |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
53 { |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
54 return true; |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
55 } |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
56 |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
57 |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
58 public string GetValidationMessage(Army army) |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
59 { |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
60 string message = ""; |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
61 |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
62 Validation result = ValidatesArmy(army); |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
63 if (!Validates.AsOkay(result)) |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
64 { |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
65 message = GetValidationFailedMessage(army); |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
66 } |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
67 |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
68 return message; |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
69 } |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
70 |
364
0dd8dbe8afe9
Fixes #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
358
diff
changeset
|
71 protected abstract string GetValidationFailedMessage(Army army); |
0dd8dbe8afe9
Fixes #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
358
diff
changeset
|
72 |
0dd8dbe8afe9
Fixes #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
358
diff
changeset
|
73 public string GetAllowsAddingMessage(UnitType toAdd, Army toArmy) |
0dd8dbe8afe9
Fixes #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
358
diff
changeset
|
74 { |
0dd8dbe8afe9
Fixes #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
358
diff
changeset
|
75 string message = ""; |
0dd8dbe8afe9
Fixes #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
358
diff
changeset
|
76 |
0dd8dbe8afe9
Fixes #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
358
diff
changeset
|
77 Validation result = AllowsAdding(toAdd, toArmy); |
0dd8dbe8afe9
Fixes #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
358
diff
changeset
|
78 if (!Validates.AsOkay(result)) |
0dd8dbe8afe9
Fixes #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
358
diff
changeset
|
79 { |
0dd8dbe8afe9
Fixes #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
358
diff
changeset
|
80 message = GetAllowsAddingFailedMessage(toAdd, toArmy); |
0dd8dbe8afe9
Fixes #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
358
diff
changeset
|
81 } |
0dd8dbe8afe9
Fixes #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
358
diff
changeset
|
82 |
0dd8dbe8afe9
Fixes #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
358
diff
changeset
|
83 return message; |
0dd8dbe8afe9
Fixes #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
358
diff
changeset
|
84 } |
0dd8dbe8afe9
Fixes #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
358
diff
changeset
|
85 |
381
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
86 protected abstract string GetAllowsAddingFailedMessage(UnitType toAdd, Army toArmy); |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
87 |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
88 public abstract Validation AllowsAdding(WarFoundryObject wfObject, Army toArmy); |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
89 |
30db6669f5cd
* Update to VS.Net 2010 compatibility
IBBoard <dev@ibboard.co.uk>
parents:
364
diff
changeset
|
90 public abstract Validation ValidatesArmy(Army army); |
358
dbe7ccb1e557
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
91 } |
dbe7ccb1e557
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
92 } |
dbe7ccb1e557
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
93 |