Mercurial > repos > IBBoard.WarFoundry.API
annotate api/Objects/Category.cs @ 392:db6713d5b35f default-army-size
RRe #97: Default army size issues
author | snowblizz |
---|---|
date | Wed, 01 Dec 2010 20:00:58 +0000 |
parents | 2f3cafb69799 |
children | 92d10b06ab0f |
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 |
12
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
26 [Obsolete("Use the two argument constructor and the appropriate 'set' methods")] |
0 | 27 public Category(string id, string name, int minPoints, int maxPoints, int minPercent, int maxPercent, int minChoices, int maxChoices, int baseValue, int incrementValue, int incrementAmount) : base(id, name) |
28 { | |
12
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
29 MinimumPoints = minPoints; |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
30 MaximumPoints = maxPoints; |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
31 MinimumPercentage = minPercent; |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
32 MaximumPercentage = maxPercent; |
82 | 33 } |
34 | |
35 protected override string DefaultName() | |
36 { | |
37 return ""; | |
46
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
38 } |
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
39 |
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
40 /// <value> |
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
41 /// 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 | 42 /// </value> |
43 public int MinimumPoints | |
44 { | |
45 get { return minPts; } | |
46 set | |
47 { | |
48 minPts = (value >= 0 ? value : 0); | |
49 CheckMinimumPoints(); | |
50 } | |
51 } | |
46
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
52 |
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
53 /// <value> |
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
54 /// 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 | 55 /// </value> |
56 public int MaximumPoints | |
57 { | |
58 get { return maxPts; } | |
59 set | |
60 { | |
61 maxPts = (value >= 0 ? value : WarFoundryCore.INFINITY); | |
62 CheckMinimumPoints(); | |
63 } | |
46
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
64 } |
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
65 |
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
66 /// <summary> |
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
67 /// Makes sure that the minimum points value isn't more than the maximum points value, hence the warning on the properties |
82 | 68 /// </summary> |
69 private void CheckMinimumPoints() | |
70 { | |
38
548cfc776f54
Fixes #34 - Remove "Choices" and "Base/Increment" from Category
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
71 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
|
72 { |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
73 MinimumPoints = MaximumPoints; |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
74 LogNotifier.WarnFormat(GetType(), "Category {0} ({1}) had a minimum points limit greater than its maximum points limit.", Name, ID); |
82 | 75 } |
0 | 76 } |
77 | |
46
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
78 /// <value> |
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
79 /// 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
|
80 /// </value> |
82 | 81 public int MinimumPercentage |
82 { | |
83 get { return minPc; } | |
84 set | |
85 { | |
86 minPc = (value >= 0 ? value : 0); | |
87 CheckMinimumPercentage(); | |
88 } | |
46
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
89 } |
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
90 |
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
91 /// <value> |
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
92 /// 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 | 93 /// </value> |
94 public int MaximumPercentage | |
95 { | |
96 get { return maxPc; } | |
97 set | |
98 { | |
99 if (value < 0) | |
100 { | |
101 maxPc = 0; | |
102 } | |
103 else if (value > 100) | |
104 { | |
105 maxPc = 100; | |
106 } | |
107 else | |
108 { | |
109 maxPc = value; | |
110 } | |
111 | |
112 CheckMinimumPercentage(); | |
113 } | |
46
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
114 } |
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
115 |
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
116 /// <summary> |
a5855fcd75ab
Re #11 - Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
117 /// Makes sure that the minimum percentage value isn't more than the maximum points value, hence the warning on the properties |
82 | 118 /// </summary> |
119 private void CheckMinimumPercentage() | |
120 { | |
12
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
121 if (MinimumPercentage > MaximumPercentage) |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
122 { |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
123 MinimumPercentage = MaximumPercentage; |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
124 LogNotifier.WarnFormat(GetType(), "Category {0} ({1}) had a minimum percentage limit greater than its maximum percentage limit.", Name, ID); |
82 | 125 } |
126 } | |
127 } | |
128 } |