annotate api/Objects/Army.cs @ 181:8c6f55d289b0

Fixes #200: Stats names should be case-insensitive * ToLower() all stat names/IDs so that they are case-insensitive
author IBBoard <dev@ibboard.co.uk>
date Sat, 24 Oct 2009 15:18:00 +0000
parents 7f13ffcb8765
children 35dc06030355
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: 89
diff changeset
1 // This file (Army.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: 8
diff changeset
2 //
104
2f3cafb69799 Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents: 89
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: 8
diff changeset
4
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
5 using System;
58
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
6 using System.IO;
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
7 using System.Collections.Generic;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
8 using System.Text;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
9 using System.Xml;
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 using IBBoard.WarFoundry.API;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 using IBBoard.WarFoundry.API.Factories;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 using IBBoard.WarFoundry.API.Requirements;
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
13 using ICSharpCode.SharpZipLib.Zip;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
14
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
15 namespace IBBoard.WarFoundry.API.Objects
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
16 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
17 /// <summary>
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
18 /// Summary description for Army.
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
19 /// </summary>
143
7f13ffcb8765 Re #164: Show unit cost in army tree
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
20 public class Army : WarFoundryObject, ICostedWarFoundryObject
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
21 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
22 //private GameSystem system;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
23 private Race armyRace;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
24 private int maxPoints;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
25 private double pointsTotal;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
26 private Dictionary<Category, ArmyCategory> categories;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
27
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
28 public event ObjectAddDelegate UnitAdded;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
29 public event ObjectRemoveDelegate UnitRemoved;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
30 public event FailedUnitRequirementDelegate FailedRequirement;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
31 public event DoubleValChangedDelegate PointsValueChanged;
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 private DoubleValChangedDelegate PointsValueChangedMethod;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33
59
3fa4658c50c6 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
34 public Army(Race race, string armyName, int maxArmyPoints) : this(race, armyName, maxArmyPoints, null)
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 }
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
37
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
38 public Army(Race race, string armyName, int maxArmyPoints, ZipFile file) : base(armyName)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
39 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
40 armyRace = race;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
41 Name = armyName;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
42 maxPoints = maxArmyPoints;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
43 PointsValueChangedMethod = new DoubleValChangedDelegate(PointsValueChangedHandler);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
44 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
45
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
46 public ArmyCategory GetCategory(Category cat)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
47 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
48 ArmyCategory armyCat = null;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
49 ArmyCategories.TryGetValue(cat, out armyCat);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
50 return armyCat;
58
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
51 }
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
52
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
53 private Dictionary<Category, ArmyCategory> ArmyCategories
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
54 {
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
55 get
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
56 {
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
57 if (categories==null)
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
58 {
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
59 categories = new Dictionary<Category, ArmyCategory>();
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
60 Category[] raceCats = Race.Categories;
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
61 ArmyCategory cat;
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
62 int raceCatCount = raceCats.Length;
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
63
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
64 for (int i = 0; i < raceCatCount; i++)
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
65 {
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
66 Category raceCat = raceCats[i];
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
67 cat = new ArmyCategory(this, raceCat);
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
68 categories[raceCat] = cat;
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
69 cat.PointsValueChanged+= PointsValueChangedMethod;
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
70 cat.UnitAdded+=new ObjectAddDelegate(Army_UnitAdded);
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
71 cat.UnitRemoved+=new ObjectRemoveDelegate(Army_UnitRemoved);
83
89cc29b4c012 Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents: 82
diff changeset
72 cat.FailedRequirement+=new FailedUnitRequirementDelegate(Army_FailedRequirement);
58
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
73 }
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
74 }
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
75
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
76 return categories;
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
77 }
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
78 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
79
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
80 public ArmyCategory[] Categories
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
81 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
82 get
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
83 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
84 return DictionaryUtils.ToArray<Category, ArmyCategory>(ArmyCategories);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
85 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
86 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
87
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
88 public Race Race
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
89 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
90 get { return armyRace; }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
91 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
92
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
93 public GameSystem GameSystem
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
94 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
95 get { return (armyRace!=null ? armyRace.GameSystem : null); }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
96 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
97
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
98 protected void OnUnitAdded(Unit unit)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
99 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
100 OnUnitAdded(unit, null);
89
cb3759c3ea19 * Code clean-up (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
101 }
cb3759c3ea19 * Code clean-up (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
102
cb3759c3ea19 * Code clean-up (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
103 protected void OnUnitAdded(Unit unit, List<FailedUnitRequirement> failedReqs)
cb3759c3ea19 * Code clean-up (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
104 {
cb3759c3ea19 * Code clean-up (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
105 if (UnitAdded != null)
cb3759c3ea19 * Code clean-up (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
106 {
cb3759c3ea19 * Code clean-up (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
107 UnitAdded(unit);
cb3759c3ea19 * Code clean-up (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
108 }
cb3759c3ea19 * Code clean-up (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
109
cb3759c3ea19 * Code clean-up (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
110 OnFailedRequirement(failedReqs);
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
111 }
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
112
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
113 protected void OnUnitRemoved(Unit unit)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
114 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
115 OnUnitRemoved(unit, null);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
116 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
117
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
118 protected void OnUnitRemoved(Unit unit, List<FailedUnitRequirement> failedReqs)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
119 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
120 if (UnitRemoved!=null)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
121 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
122 UnitRemoved(unit);
89
cb3759c3ea19 * Code clean-up (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
123 }
cb3759c3ea19 * Code clean-up (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
124
83
89cc29b4c012 Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents: 82
diff changeset
125 OnFailedRequirement(failedReqs);
89
cb3759c3ea19 * Code clean-up (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
126 }
cb3759c3ea19 * Code clean-up (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
127
cb3759c3ea19 * Code clean-up (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
128 protected void OnFailedRequirement(List<FailedUnitRequirement> failedReqs)
cb3759c3ea19 * Code clean-up (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
129 {
cb3759c3ea19 * Code clean-up (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
130 if (FailedRequirement != null && failedReqs != null && failedReqs.Count > 0)
cb3759c3ea19 * Code clean-up (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
131 {
cb3759c3ea19 * Code clean-up (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
132 FailedRequirement(failedReqs);
cb3759c3ea19 * Code clean-up (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
133 }
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
134 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
135
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
136 private void OnPointsValueChanged(double oldValue, double newValue)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
137 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
138 if (PointsValueChanged!=null)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
139 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
140 PointsValueChanged(this, oldValue, newValue);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
141 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
142 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
143
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
144 private double TotalPoints
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
145 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
146 get { return pointsTotal; }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
147 set
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
148 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
149 double oldPoints = pointsTotal;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
150 pointsTotal = value;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
151
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
152 if (oldPoints!=pointsTotal)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
153 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
154 OnPointsValueChanged(oldPoints, pointsTotal);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
155 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
156 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
157 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
158
143
7f13ffcb8765 Re #164: Show unit cost in army tree
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
159 [Obsolete("Use Points instead")]
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
160 public double PointsTotal
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
161 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
162 get { return TotalPoints; }
58
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
163 }
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
164
143
7f13ffcb8765 Re #164: Show unit cost in army tree
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
165 public double Points
7f13ffcb8765 Re #164: Show unit cost in army tree
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
166 {
7f13ffcb8765 Re #164: Show unit cost in army tree
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
167 get { return TotalPoints; }
7f13ffcb8765 Re #164: Show unit cost in army tree
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
168 }
7f13ffcb8765 Re #164: Show unit cost in army tree
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
169
58
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
170 public void AddUnit(Unit unit)
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
171 {
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
172 ArmyCategory armyCat = GetCategory(unit.UnitType.MainCategory);
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
173 armyCat.AddUnit(unit);
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
174 }
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
175
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
176 public void RemoveUnit(Unit unit)
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
177 {
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
178 unit.Category.RemoveUnit(unit);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
179 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
180
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
181 public Unit[] GetUnits(Category cat)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
182 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
183 return GetUnits(this.GetCategory(cat));
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
184 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
185
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
186 public Unit[] GetUnits(ArmyCategory cat)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
187 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
188 return cat.GetUnits();
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
189 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
190
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
191 public Unit[] GetUnits()
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
192 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
193 List<Unit> fullList = new List<Unit>();
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
194
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
195 foreach(ArmyCategory cat in Categories)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
196 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
197 fullList.AddRange(cat.GetUnits());
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
198 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
199
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
200 return fullList.ToArray();
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
201 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
202
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
203 public int MaxPoints
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
204 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
205 get { return maxPoints; }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
206 set
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
207 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
208 if (value > 0)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
209 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
210 maxPoints = value;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
211 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
212 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
213 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
214
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
215 private void PointsValueChangedHandler(WarFoundryObject obj, double oldVal, double newVal)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
216 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
217 if (obj is ArmyCategory)
58
e53ed2d613a1 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
218 {
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
219 double points = 0;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
220
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
221 foreach (ArmyCategory cat in Categories)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
222 {
143
7f13ffcb8765 Re #164: Show unit cost in army tree
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
223 points+= cat.Points;
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
224 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
225
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
226 TotalPoints = points;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
227 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
228 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
229
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
230 public List<FailedUnitRequirement> CanAddUnit(Unit unit)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
231 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
232 return CanAddUnitType(unit.UnitType);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
233 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
234
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
235 public List<FailedUnitRequirement> CanAddUnitType(UnitType unitType)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
236 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
237 return unitType.CanAddToArmy(this);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
238 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
239
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
240 public List<FailedUnitRequirement> CanRemoveUnit(Unit unit)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
241 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
242 return CanRemoveUnitType(unit.UnitType);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
243 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
244
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
245 public List<FailedUnitRequirement> CanRemoveUnitType(UnitType unitType)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
246 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
247 return unitType.CanRemoveFromArmy(this);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
248 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
249
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
250 public int GetUnitTypeCount(UnitType unitType)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
251 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
252 int count = 0;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
253
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
254 foreach (ArmyCategory cat in Categories)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
255 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
256 count+= cat.GetUnitTypeCount(unitType);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
257 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
258
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
259 return count;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
260 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
261
83
89cc29b4c012 Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents: 82
diff changeset
262 private void Army_UnitAdded(WarFoundryObject val)
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
263 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
264 OnUnitAdded((Unit)val);
89
cb3759c3ea19 * Code clean-up (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
265 }
cb3759c3ea19 * Code clean-up (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
266
83
89cc29b4c012 Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents: 82
diff changeset
267 private void Army_UnitRemoved(WarFoundryObject val)
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
268 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
269 OnUnitRemoved((Unit)val);
89
cb3759c3ea19 * Code clean-up (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
270 }
cb3759c3ea19 * Code clean-up (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
271
cb3759c3ea19 * Code clean-up (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
272 private void Army_FailedRequirement(List<FailedUnitRequirement> val)
cb3759c3ea19 * Code clean-up (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
273 {
cb3759c3ea19 * Code clean-up (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
274 OnFailedRequirement(val);
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
275 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
276 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
277 }