Mercurial > repos > IBBoard.WarFoundry.API
annotate API/Objects/Requirement/UnitCountRequirementData.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 | 206a45fdfa9e |
children |
rev | line source |
---|---|
356 | 1 // This file (UnitCountRequirementData.cs) is a part of the IBBoard.WarFoundry.API.Tests 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; | |
5 using IBBoard.WarFoundry.API.Objects; | |
6 | |
7 namespace IBBoard.WarFoundry.API.Objects.Requirement | |
8 { | |
9 public class UnitCountRequirementData | |
10 { | |
444
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
11 private UnitType[] unitTypes; |
356 | 12 private int count; |
437
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
356
diff
changeset
|
13 private int allows; |
356 | 14 |
437
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
356
diff
changeset
|
15 public UnitCountRequirementData(UnitType unitType, int count) : this(unitType, count, WarFoundryCore.INFINITY) |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
356
diff
changeset
|
16 { |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
356
diff
changeset
|
17 //Do nothing special |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
356
diff
changeset
|
18 } |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
356
diff
changeset
|
19 |
444
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
20 public UnitCountRequirementData(UnitType unitType, int count, int allows) : this(new UnitType[]{unitType}, count, allows) |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
21 { |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
22 //Do nothing special |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
23 } |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
24 |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
25 public UnitCountRequirementData(UnitType[] unitTypes, int count) : this(unitTypes, count, WarFoundryCore.INFINITY) |
356 | 26 { |
444
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
27 //Do nothing special |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
28 } |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
29 |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
30 public UnitCountRequirementData(UnitType[] unitTypes, int count, int allows) |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
31 { |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
32 this.unitTypes = unitTypes ?? new UnitType[0]; |
356 | 33 this.count = count; |
437
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
356
diff
changeset
|
34 this.allows = allows; |
356 | 35 } |
36 | |
37 public UnitType UnitType | |
38 { | |
444
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
39 get { return unitTypes.Length > 0 ? unitTypes[0] : null; } |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
40 } |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
41 |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
42 public UnitType[] UnitTypes |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
43 { |
206a45fdfa9e
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
437
diff
changeset
|
44 get { return unitTypes; } |
356 | 45 } |
46 | |
47 public int Count | |
48 { | |
49 get { return count; } | |
50 } | |
51 | |
437
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
356
diff
changeset
|
52 public int AllowsCount |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
356
diff
changeset
|
53 { |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
356
diff
changeset
|
54 get { return allows; } |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
356
diff
changeset
|
55 } |
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
356
diff
changeset
|
56 |
356 | 57 public override bool Equals (object obj) |
58 { | |
59 if (obj == null) | |
60 { | |
61 return false; | |
62 } | |
63 else if (!(obj is UnitCountRequirementData)) | |
64 { | |
65 return false; | |
66 } | |
67 else | |
68 { | |
69 UnitCountRequirementData other = (UnitCountRequirementData)obj; | |
437
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
356
diff
changeset
|
70 return UnitType.Equals(other.UnitType) && Count == other.Count && AllowsCount == other.AllowsCount; |
356 | 71 } |
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
72 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
73 |
356 | 74 public override int GetHashCode() |
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
75 { |
437
0922851f6125
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
356
diff
changeset
|
76 return UnitType.GetHashCode() + Count + AllowsCount; |
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
77 } |
356 | 78 } |
79 } | |
80 |