Mercurial > repos > IBBoard.WarFoundry.API
annotate api/Objects/Category.cs @ 331:e1d1b81b192a
Re #27: Define unit requirements
* Implement code for min limits > 1
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 27 Mar 2011 19:50:33 +0000 |
parents | 92d10b06ab0f |
children |
rev | line source |
---|---|
104
2f3cafb69799
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
1 // This file (Category.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard. |
15 | 2 // |
104
2f3cafb69799
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
82
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. |
15 | 4 |
82 | 5 using System; |
6 using System.Xml; | |
7 using IBBoard.Logging; | |
8 | |
9 namespace IBBoard.WarFoundry.API.Objects | |
10 { | |
11 /// <summary> | |
12 /// A Category is a definition at the <see cref=" GameSystem"/> or <see cref=" Race"/> level of a group that <see cref=" UnitType"/>s belong to. Each category has a name and a min/max limit on points or percentage of a total army cost that units in the category can total. | |
13 /// </summary> | |
14 public class Category : WarFoundryObject | |
15 { | |
16 private int minPts = 0; | |
17 private int maxPts = WarFoundryCore.INFINITY; | |
18 private int minPc = 0; | |
19 private int maxPc = 100; | |
20 | |
21 | |
22 public Category(string id, string name) : base(id, name) | |
23 { | |
12
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
24 } |
82 | 25 |
26 protected override string DefaultName() | |
27 { | |
28 return ""; | |
46
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
29 } |
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
30 |
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
31 /// <value> |
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
32 /// Gets or sets the minimum number of points that the units of this category can cost. Note: This should be set AFTER MaximumPoints, otherwise an unintended default value may be set for the minimum |
82 | 33 /// </value> |
34 public int MinimumPoints | |
35 { | |
36 get { return minPts; } | |
37 set | |
38 { | |
39 minPts = (value >= 0 ? value : 0); | |
40 CheckMinimumPoints(); | |
41 } | |
42 } | |
46
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
43 |
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
44 /// <value> |
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
45 /// Gets or sets the maximum number of points that the units of this category can cost. Note: This should be set BEFORE MinimumPoints, otherwise an unintended default value may be set for the minimum |
82 | 46 /// </value> |
47 public int MaximumPoints | |
48 { | |
49 get { return maxPts; } | |
50 set | |
51 { | |
52 maxPts = (value >= 0 ? value : WarFoundryCore.INFINITY); | |
53 CheckMinimumPoints(); | |
54 } | |
46
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
55 } |
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
56 |
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
57 /// <summary> |
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
58 /// Makes sure that the minimum points value isn't more than the maximum points value, hence the warning on the properties |
82 | 59 /// </summary> |
60 private void CheckMinimumPoints() | |
61 { | |
38
548cfc776f54
Fixes #34 - Remove "Choices" and "Base/Increment" from Category
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
62 if (MinimumPoints > MaximumPoints && MaximumPoints!=WarFoundryCore.INFINITY) |
12
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
63 { |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
64 MinimumPoints = MaximumPoints; |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
65 LogNotifier.WarnFormat(GetType(), "Category {0} ({1}) had a minimum points limit greater than its maximum points limit.", Name, ID); |
82 | 66 } |
0 | 67 } |
68 | |
46
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
69 /// <value> |
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
70 /// Gets or sets the minimum percentage of the total army points value that the units of this category can cost. Note: This should be set AFTER MaximumPercentage, otherwise an unintended default value may be set for the minimum |
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
71 /// </value> |
82 | 72 public int MinimumPercentage |
73 { | |
74 get { return minPc; } | |
75 set | |
76 { | |
77 minPc = (value >= 0 ? value : 0); | |
78 CheckMinimumPercentage(); | |
79 } | |
46
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
80 } |
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
81 |
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
82 /// <value> |
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
83 /// Gets or sets the maximum percentage of the total army points value that the units of this category can cost. Note: This should be set BEFORE MinimumPercentage, otherwise an unintended default value may be set for the minimum |
82 | 84 /// </value> |
85 public int MaximumPercentage | |
86 { | |
87 get { return maxPc; } | |
88 set | |
89 { | |
90 if (value < 0) | |
91 { | |
92 maxPc = 0; | |
93 } | |
94 else if (value > 100) | |
95 { | |
96 maxPc = 100; | |
97 } | |
98 else | |
99 { | |
100 maxPc = value; | |
101 } | |
102 | |
103 CheckMinimumPercentage(); | |
104 } | |
46
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
105 } |
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
106 |
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
107 /// <summary> |
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
108 /// Makes sure that the minimum percentage value isn't more than the maximum points value, hence the warning on the properties |
82 | 109 /// </summary> |
110 private void CheckMinimumPercentage() | |
111 { | |
12
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
112 if (MinimumPercentage > MaximumPercentage) |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
113 { |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
114 MinimumPercentage = MaximumPercentage; |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
115 LogNotifier.WarnFormat(GetType(), "Category {0} ({1}) had a minimum percentage limit greater than its maximum percentage limit.", Name, ID); |
82 | 116 } |
117 } | |
118 } | |
119 } |