annotate api/Objects/UnitType.cs @ 34:b28be912adab

Re #32 - Migrate to schema * Remove use of Categories (now just has a single category) * Fix infinite loop of trying to load files by adding a "is loading" flag * Fix invalid setting of MinSize to MaxNumber when we're testing if MinSize > MaxSize
author IBBoard <dev@ibboard.co.uk>
date Sun, 15 Mar 2009 16:07:52 +0000
parents 306558904c2a
children 548cfc776f54
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15
306558904c2a Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
1 // This file (UnitType.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard.
306558904c2a Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
2 //
306558904c2a Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
3 // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.
306558904c2a Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
4
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using System;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using System.Collections;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using System.Collections.Generic;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 using System.Xml;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 using IBBoard.Logging;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 using IBBoard.WarFoundry.API.Requirements;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 namespace IBBoard.WarFoundry.API.Objects
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 /// Summary description for Unit.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 public class UnitType : WarFoundryObject
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 {
34
b28be912adab Re #32 - Migrate to schema
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
19 protected Category mainCat;
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 protected Race race;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 protected int min, max, baseSize = 0;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 protected int minSize, maxSize;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 protected double baseUnitCost;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 protected double costPerTrooper;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 protected Stats stats;
12
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
26 protected List<UnitRequirement> requirements = new List<UnitRequirement>();
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 protected Hashtable equipment = new Hashtable();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 protected Hashtable equipmentExclusionGroups = new Hashtable();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 protected ArrayList equipmentKeyOrder = new ArrayList();
12
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
30
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
31
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
32 public UnitType(string id, string typeName, Race parentRace) : base(id, typeName)
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
33 {
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
34 race = parentRace;
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
35 }
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
36
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
37 [Obsolete("Use three parameter constructor and setters")]
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38 public UnitType(string id, string typeName, string mainCategoryID, string[] allCategoryIDs, int minNum, int maxNum, int minimumSize, int maximumSize, double unitCost, double trooperCost, Stats unitStats, UnitRequirement[] unitRequirements, Race parentRace) : base(id, typeName)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 race = parentRace;
34
b28be912adab Re #32 - Migrate to schema
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
41 mainCat = race.GetCategory(mainCategoryID);
12
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
42 MinNumber = minNum;
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
43 MaxNumber = maxNum;
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
44 MinSize = minimumSize;
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
45 MaxSize = maximumSize;
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
46 BaseUnitCost = unitCost;
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
47 CostPerTrooper = trooperCost;
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
48 UnitStats = unitStats;
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
49
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
50 foreach (UnitRequirement requirement in requirements)
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
51 {
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
52 AddRequirement(requirement);
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56 public Race Race
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 get { return race; }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
60
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
61 public virtual Category MainCategory
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
62 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
63 get
12
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
64 {
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65 return mainCat;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66 }
12
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
67 set
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
68 {
34
b28be912adab Re #32 - Migrate to schema
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
69 mainCat = value;
12
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
70 }
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
71 }
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
72
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
73 public int MinSize
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
74 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
75 get { return minSize; }
12
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
76 set
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
77 {
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
78 minSize = (value >= 0 ? value : 0);
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
79 CheckMinimumSize();
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
80 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
81 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
82
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
83 public int MaxSize
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
84 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
85 get { return maxSize; }
12
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
86 set
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
87 {
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
88 maxSize = (value >= -1 ? value : -1);
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
89 CheckMinimumSize();
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
90 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
91 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
92
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
93 public int BaseSize
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
94 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
95 get { return baseSize; }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
96 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
97
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
98 public int MinNumber
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
99 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
100 get { return min; }
12
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
101 set
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
102 {
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
103 min = (value >= 0 ? value : 0);
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
104 CheckMinimumNumber();
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
105 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
106 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
107
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
108 public int MaxNumber
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
109 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
110 get { return max; }
12
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
111 set
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
112 {
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
113 max = (value >= -1 ? value : -1);
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
114 CheckMinimumNumber();
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
115 }
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
116 }
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
117
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
118 private void CheckMinimumNumber()
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
119 {
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
120 if (MinNumber > MaxNumber && MaxNumber!=-1)
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
121 {
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
122 MinNumber = MaxNumber;
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
123 LogNotifier.WarnFormat(GetType(), "Unit type {0} ({1}) had a minimum number greater than their maximum number.", Name, ID);
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
124 }
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
125 }
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
126
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
127 private void CheckMinimumSize()
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
128 {
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
129 if (MinSize > MaxSize && MaxSize!=-1)
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
130 {
34
b28be912adab Re #32 - Migrate to schema
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
131 MinSize = MaxSize;
12
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
132 LogNotifier.WarnFormat(GetType(), "Unit type {0} ({1}) had a minimum size greater than their maximum size.", Name, ID);
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
133 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
134 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
135
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
136 public double BaseUnitCost
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
137 {
12
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
138 get { return baseUnitCost; }
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
139 set { baseUnitCost = (value >= 0 ? value : 0); }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
140 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
141
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
142 public double CostPerTrooper
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
143 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
144 get { return costPerTrooper; }
12
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
145 set { costPerTrooper = (value >= 0 ? value : 0); }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
146 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
147
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
148 protected override string DefaultName()
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
149 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
150 throw new InvalidOperationException("Unit type with id "+id+" did not have a name specified");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
151 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
152
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
153 public Stats UnitStats
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
154 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
155 get
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
156 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
157 return stats;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
158 }
12
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
159 set
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
160 {
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
161 if (value!=null)
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
162 {
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
163 stats = value;
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
164 }
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
165 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
166 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
167
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
168 public UnitEquipmentItem GetEquipmentItem(string id)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
169 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
170 return (UnitEquipmentItem)equipment[id];
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
171 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
172
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
173 public UnitEquipmentItem[] GetEquipmentItems()
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
174 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
175 UnitEquipmentItem[] items = new UnitEquipmentItem[equipment.Count];
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
176 int i = 0;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
177
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
178 foreach (string itemID in equipmentKeyOrder)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
179 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
180 items[i++] = (UnitEquipmentItem)equipment[itemID];
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
181 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
182
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
183 return items;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
184 }
12
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
185
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
186 public void AddRequirement(UnitRequirement requirement)
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
187 {
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
188 requirements.Add(requirement);
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
189 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
190
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
191 public List<FailedUnitRequirement> CanAddToArmy(Army army)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
192 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
193 List<FailedUnitRequirement> failures = new List<FailedUnitRequirement>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
194
12
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
195 if (requirements!=null && requirements.Count > 0)
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
196 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
197 foreach (UnitRequirement requirement in requirements)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
198 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
199 FailedUnitRequirement failure = (FailedUnitRequirement)requirement.CanAddToWarFoundryObject(army);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
200
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
201 if (failure!=null)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
202 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
203 failures.Add(failure);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
204 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
205 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
206 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
207
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
208 return failures;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
209 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
210
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
211 public List<FailedUnitRequirement> CanRemoveFromArmy(Army army)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
212 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
213 List<FailedUnitRequirement> failures = new List<FailedUnitRequirement>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
214
12
ac232763858b Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
215 if (requirements!=null && requirements.Count > 0)
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
216 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
217 foreach (UnitRequirement requirement in requirements)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
218 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
219 FailedUnitRequirement failure = (FailedUnitRequirement)requirement.CanRemoveFromWarFoundryObject(army);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
220
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
221 if (failure!=null)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
222 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
223 failures.Add(failure);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
224 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
225 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
226 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
227
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
228 return failures;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
229 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
230
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
231 public UnitEquipmentItem[] GetEquipmentItemsByExclusionGroup(string group)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
232 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
233 ArrayList list = (ArrayList)equipmentExclusionGroups[group];
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
234
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
235 if (list == null)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
236 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
237 return new UnitEquipmentItem[0];
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
238 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
239 else
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
240 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
241 return (UnitEquipmentItem[])list.ToArray(typeof(UnitEquipmentItem));
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
242 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
243 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
244 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
245 }