annotate API/Objects/Requirement/UnitCountRequirementData.cs @ 437:0922851f6125

Re #350: Add requirement to allow N of unit for specific other units * Extend unit count requirement data to handle fixed numbers of units allowed per unit required * Add initial stub of requirement using some copy-and-paste, but starting to avoid ticket:379
author IBBoard <dev@ibboard.co.uk>
date Tue, 29 Nov 2011 20:55:21 +0000
parents 51cccccf3669
children 206a45fdfa9e
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 {
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
11 private UnitType unitType;
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
0922851f6125 Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents: 356
diff changeset
20 public UnitCountRequirementData(UnitType unitType, int count, int allows)
356
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
21 {
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
22 this.unitType = unitType;
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
23 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
24 this.allows = allows;
356
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
25 }
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
26
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
27 public UnitType UnitType
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
28 {
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
29 get { return unitType; }
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
30 }
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
31
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
32 public int Count
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
33 {
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
34 get { return count; }
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
437
0922851f6125 Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents: 356
diff changeset
37 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
38 {
0922851f6125 Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents: 356
diff changeset
39 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
40 }
0922851f6125 Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents: 356
diff changeset
41
356
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
42 public override bool Equals (object obj)
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
43 {
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
44 if (obj == null)
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 return false;
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
47 }
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
48 else if (!(obj is UnitCountRequirementData))
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
49 {
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
50 return false;
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
51 }
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
52 else
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
53 {
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
54 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
55 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
56 }
337
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58
356
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
59 public override int GetHashCode()
337
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
60 {
437
0922851f6125 Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents: 356
diff changeset
61 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
62 }
356
51cccccf3669 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
63 }
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