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
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
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
26 protected override string DefaultName()
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
27 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
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
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
33 /// </value>
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
34 public int MinimumPoints
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
35 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
36 get { return minPts; }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
37 set
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
38 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
39 minPts = (value >= 0 ? value : 0);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
40 CheckMinimumPoints();
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
41 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
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
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
46 /// </value>
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
47 public int MaximumPoints
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
48 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
49 get { return maxPts; }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
50 set
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
51 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
52 maxPts = (value >= 0 ? value : WarFoundryCore.INFINITY);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
53 CheckMinimumPoints();
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
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
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
59 /// </summary>
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
60 private void CheckMinimumPoints()
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
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
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
66 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
67 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
72 public int MinimumPercentage
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
73 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
74 get { return minPc; }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
75 set
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
76 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
77 minPc = (value >= 0 ? value : 0);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
78 CheckMinimumPercentage();
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
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
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
84 /// </value>
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
85 public int MaximumPercentage
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
86 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
87 get { return maxPc; }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
88 set
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
89 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
90 if (value < 0)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
91 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
92 maxPc = 0;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
93 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
94 else if (value > 100)
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 maxPc = 100;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
97 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
98 else
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
99 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
100 maxPc = value;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
101 }
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 CheckMinimumPercentage();
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
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
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
109 /// </summary>
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
110 private void CheckMinimumPercentage()
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
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
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
116 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
117 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
118 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
119 }