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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
356
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
1 // This file (UnitCountRequirementData.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 IBBoard
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
2 //
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
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.
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
4 using System;
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
5 using IBBoard.WarFoundry.API.Objects;
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
6
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
7 namespace IBBoard.WarFoundry.API.Objects.Requirement
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
8 {
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
9 public class UnitCountRequirementData
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
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
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
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
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
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
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
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
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
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
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
35 }
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
36
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
37 public UnitType UnitType
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
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
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
45 }
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
46
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
47 public int Count
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
48 {
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
49 get { return count; }
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
50 }
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
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
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
57 public override bool Equals (object obj)
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
58 {
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
59 if (obj == null)
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
60 {
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
61 return false;
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
62 }
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
63 else if (!(obj is UnitCountRequirementData))
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
64 {
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
65 return false;
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
66 }
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
67 else
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
68 {
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
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
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
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
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
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
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
78 }
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
79 }
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
80