annotate api/Objects/Category.cs @ 263:7933d852181e

Re #289: Double-check extensibility where sets of values are allowed * Remove ArmourType and all usage as it needs rebuilding from scratch to be extensible and isn't widely used yet
author IBBoard <dev@ibboard.co.uk>
date Sat, 05 Jun 2010 12:43:28 +0000
parents 2f3cafb69799
children 92d10b06ab0f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
306558904c2a Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
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
306558904c2a Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
4
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
5 using System;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
6 using System.Xml;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
7 using IBBoard.Logging;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
8
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
9 namespace IBBoard.WarFoundry.API.Objects
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
10 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
11 /// <summary>
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
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.
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
13 /// </summary>
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
14 public class Category : WarFoundryObject
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
15 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
16 private int minPts = 0;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
17 private int maxPts = WarFoundryCore.INFINITY;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
18 private int minPc = 0;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
19 private int maxPc = 100;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
20
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
21
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
22 public Category(string id, string name) : base(id, name)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
23 {
12
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
24 }
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
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
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
33 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
34
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
35 protected override string DefaultName()
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
36 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
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
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
42 /// </value>
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
43 public int MinimumPoints
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
44 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
45 get { return minPts; }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
46 set
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
47 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
48 minPts = (value >= 0 ? value : 0);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
49 CheckMinimumPoints();
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
50 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
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
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
55 /// </value>
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
56 public int MaximumPoints
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
57 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
58 get { return maxPts; }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
59 set
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
60 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
61 maxPts = (value >= 0 ? value : WarFoundryCore.INFINITY);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
62 CheckMinimumPoints();
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
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
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
68 /// </summary>
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
69 private void CheckMinimumPoints()
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
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
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
75 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
76 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
81 public int MinimumPercentage
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
82 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
83 get { return minPc; }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
84 set
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
85 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
86 minPc = (value >= 0 ? value : 0);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
87 CheckMinimumPercentage();
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
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
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
93 /// </value>
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
94 public int MaximumPercentage
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
95 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
96 get { return maxPc; }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
97 set
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
98 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
99 if (value < 0)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
100 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
101 maxPc = 0;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
102 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
103 else if (value > 100)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
104 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
105 maxPc = 100;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
106 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
107 else
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
108 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
109 maxPc = value;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
110 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
111
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
112 CheckMinimumPercentage();
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
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
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
118 /// </summary>
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
119 private void CheckMinimumPercentage()
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
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
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
125 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
126 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
127 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
128 }