annotate API/Objects/Army.cs @ 436:dc842b41adfd

Fixes #378: Add default files to source control * Add default race and system (copied from local GTK# project)
author IBBoard <dev@ibboard.co.uk>
date Mon, 28 Nov 2011 20:11:33 +0000
parents d992758b0150
children 676f5ce04176
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
337
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 // This file (Army.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard.
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
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.
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using System;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using System.IO;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using System.Collections.Generic;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 using System.Text;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 using System.Xml;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 using IBBoard.WarFoundry.API;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 using IBBoard.WarFoundry.API.Factories;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 using ICSharpCode.SharpZipLib.Zip;
353
65fccdd51aec Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 348
diff changeset
13 using IBBoard.WarFoundry.API.Objects.Requirement;
423
314b8b8bf4f1 * Give Army objects a sensible default name, as we've been doing in UI
IBBoard <dev@ibboard.co.uk>
parents: 413
diff changeset
14 using IBBoard.Lang;
337
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 namespace IBBoard.WarFoundry.API.Objects
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 /// <summary>
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 /// Summary description for Army.
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 /// </summary>
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 public class Army : WarFoundryLoadedObject, ICostedWarFoundryObject
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 {
423
314b8b8bf4f1 * Give Army objects a sensible default name, as we've been doing in UI
IBBoard <dev@ibboard.co.uk>
parents: 413
diff changeset
23 public static string GenerateDefaultName(Race race, int points, string ptsAbbrev)
314b8b8bf4f1 * Give Army objects a sensible default name, as we've been doing in UI
IBBoard <dev@ibboard.co.uk>
parents: 413
diff changeset
24 {
314b8b8bf4f1 * Give Army objects a sensible default name, as we've been doing in UI
IBBoard <dev@ibboard.co.uk>
parents: 413
diff changeset
25 return String.Format(race.ArmyDefaultName, Translation.GetTranslation("armySizePts", "{0}{1}", points, ptsAbbrev));
314b8b8bf4f1 * Give Army objects a sensible default name, as we've been doing in UI
IBBoard <dev@ibboard.co.uk>
parents: 413
diff changeset
26 }
314b8b8bf4f1 * Give Army objects a sensible default name, as we've been doing in UI
IBBoard <dev@ibboard.co.uk>
parents: 413
diff changeset
27
337
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 //private GameSystem system;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 private Race armyRace;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 private int maxPoints;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 private double pointsTotal;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 private Dictionary<Category, ArmyCategory> categories;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 public event ObjectAddDelegate UnitAdded;
413
3f297a60db1e Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents: 367
diff changeset
35 public event ObjectRemoveDelegate UnitRemoved;
3f297a60db1e Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents: 367
diff changeset
36 public event IntValChangedDelegate MaxPointsValueChanged;
337
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 public event DoubleValChangedDelegate PointsValueChanged;
424
d992758b0150 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 423
diff changeset
38 public event MethodInvoker ArmyCompositionChanged;
337
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 private DoubleValChangedDelegate PointsValueChangedMethod;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 public Army(Race race, string armyName, int maxArmyPoints) : this(race, armyName, maxArmyPoints, null)
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 public Army(Race race, string armyName, int maxArmyPoints, ZipFile file) : base(armyName)
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47 armyRace = race;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48 Name = armyName;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 maxPoints = maxArmyPoints;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50 PointsValueChangedMethod = new DoubleValChangedDelegate(PointsValueChangedHandler);
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51 }
423
314b8b8bf4f1 * Give Army objects a sensible default name, as we've been doing in UI
IBBoard <dev@ibboard.co.uk>
parents: 413
diff changeset
52
314b8b8bf4f1 * Give Army objects a sensible default name, as we've been doing in UI
IBBoard <dev@ibboard.co.uk>
parents: 413
diff changeset
53 protected override string DefaultName()
314b8b8bf4f1 * Give Army objects a sensible default name, as we've been doing in UI
IBBoard <dev@ibboard.co.uk>
parents: 413
diff changeset
54 {
314b8b8bf4f1 * Give Army objects a sensible default name, as we've been doing in UI
IBBoard <dev@ibboard.co.uk>
parents: 413
diff changeset
55 return Army.GenerateDefaultName(Race, MaxPoints, GameSystem.GetPointsAbbrev(MaxPoints));
314b8b8bf4f1 * Give Army objects a sensible default name, as we've been doing in UI
IBBoard <dev@ibboard.co.uk>
parents: 413
diff changeset
56 }
337
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 public ArmyCategory GetCategory(Category cat)
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
60 ArmyCategory armyCat = null;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
61 ArmyCategories.TryGetValue(cat, out armyCat);
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
62 return armyCat;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
63 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65 private Dictionary<Category, ArmyCategory> ArmyCategories
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
67 get
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
68 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
69 if (categories==null)
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
70 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
71 categories = new Dictionary<Category, ArmyCategory>();
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
72 Category[] raceCats = Race.Categories;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
73 ArmyCategory cat;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
74 int raceCatCount = raceCats.Length;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
75
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
76 for (int i = 0; i < raceCatCount; i++)
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
77 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
78 Category raceCat = raceCats[i];
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
79 cat = new ArmyCategory(this, raceCat);
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
80 categories[raceCat] = cat;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
81 cat.PointsValueChanged+= PointsValueChangedMethod;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
82 cat.UnitAdded+=new ObjectAddDelegate(Army_UnitAdded);
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
83 cat.UnitRemoved+=new ObjectRemoveDelegate(Army_UnitRemoved);
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
84 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
85 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
86
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
87 return categories;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
88 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
89 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
90
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
91 public ArmyCategory[] Categories
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
92 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
93 get
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
94 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
95 return DictionaryUtils.ToArray<Category, ArmyCategory>(ArmyCategories);
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
96 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
97 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
98
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
99 public Race Race
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
100 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
101 get { return armyRace; }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
102 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
103
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
104 public GameSystem GameSystem
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
105 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
106 get { return (armyRace!=null ? armyRace.GameSystem : null); }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
107 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
108
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
109 protected void OnUnitAdded(Unit unit)
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
110 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
111 if (UnitAdded != null)
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
112 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
113 UnitAdded(unit);
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
114 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
115 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
116
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
117 protected void OnUnitRemoved(Unit unit)
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
118 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
119 if (UnitRemoved!=null)
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
120 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
121 UnitRemoved(unit);
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
122 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
123 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
124
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
125 private void OnPointsValueChanged(double oldValue, double newValue)
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
126 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
127 if (PointsValueChanged!=null)
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
128 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
129 PointsValueChanged(this, oldValue, newValue);
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
130 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
131 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
132
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
133 private double TotalPoints
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
134 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
135 get { return pointsTotal; }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
136 set
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
137 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
138 double oldPoints = pointsTotal;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
139 pointsTotal = value;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
140
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
141 if (oldPoints!=pointsTotal)
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
142 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
143 OnPointsValueChanged(oldPoints, pointsTotal);
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
144 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
145 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
146 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
147
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
148 public double Points
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
149 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
150 get { return TotalPoints; }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
151 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
152
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
153 public void AddUnit(Unit unit)
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
154 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
155 Category category = unit.UnitType.MainCategory;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
156 AddUnit(unit, category);
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
157 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
158
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
159 public void AddUnit(Unit unit, Category category)
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
160 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
161 ArmyCategory armyCat = GetCategory(category);
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
162 armyCat.AddUnit(unit);
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
163 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
164
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
165 public void RemoveUnit(Unit unit)
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
166 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
167 unit.Category.RemoveUnit(unit);
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
168 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
169
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
170 public Unit[] GetUnits(Category cat)
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
171 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
172 return GetUnits(this.GetCategory(cat));
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
173 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
174
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
175 public Unit[] GetUnits(ArmyCategory cat)
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
176 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
177 return cat.GetUnits();
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
178 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
179
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
180 public Unit[] GetUnits()
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
181 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
182 List<Unit> fullList = new List<Unit>();
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
183
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
184 foreach(ArmyCategory cat in Categories)
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
185 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
186 fullList.AddRange(cat.GetUnits());
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
187 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
188
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
189 return fullList.ToArray();
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
190 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
191
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
192 public int MaxPoints
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
193 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
194 get { return maxPoints; }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
195 set
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
196 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
197 if (value > 0)
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
198 {
413
3f297a60db1e Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents: 367
diff changeset
199 int oldPoints = maxPoints;
3f297a60db1e Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents: 367
diff changeset
200 maxPoints = value;
3f297a60db1e Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents: 367
diff changeset
201
3f297a60db1e Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents: 367
diff changeset
202 if (MaxPointsValueChanged != null)
3f297a60db1e Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents: 367
diff changeset
203 {
3f297a60db1e Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents: 367
diff changeset
204 MaxPointsValueChanged(this, oldPoints, maxPoints);
3f297a60db1e Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents: 367
diff changeset
205 }
423
314b8b8bf4f1 * Give Army objects a sensible default name, as we've been doing in UI
IBBoard <dev@ibboard.co.uk>
parents: 413
diff changeset
206
314b8b8bf4f1 * Give Army objects a sensible default name, as we've been doing in UI
IBBoard <dev@ibboard.co.uk>
parents: 413
diff changeset
207 if (HasDefaultName())
314b8b8bf4f1 * Give Army objects a sensible default name, as we've been doing in UI
IBBoard <dev@ibboard.co.uk>
parents: 413
diff changeset
208 {
314b8b8bf4f1 * Give Army objects a sensible default name, as we've been doing in UI
IBBoard <dev@ibboard.co.uk>
parents: 413
diff changeset
209 OnNameChanged("", Name);
314b8b8bf4f1 * Give Army objects a sensible default name, as we've been doing in UI
IBBoard <dev@ibboard.co.uk>
parents: 413
diff changeset
210 }
337
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
211 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
212 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
213 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
214
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
215 private void PointsValueChangedHandler(WarFoundryObject obj, double oldVal, double newVal)
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
216 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
217 if (obj is ArmyCategory)
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
218 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
219 double points = 0;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
220
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
221 foreach (ArmyCategory cat in Categories)
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
222 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
223 points+= cat.Points;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
224 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
225
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
226 TotalPoints = points;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
227 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
228 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
229
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
230 public int GetUnitTypeCount(UnitType unitType)
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
231 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
232 int count = 0;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
233
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
234 foreach (ArmyCategory cat in Categories)
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
235 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
236 count+= cat.GetUnitTypeCount(unitType);
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
237 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
238
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
239 return count;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
240 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
241
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
242 private void Army_UnitAdded(WarFoundryObject val)
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
243 {
424
d992758b0150 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 423
diff changeset
244 Unit unit = (Unit)val;
d992758b0150 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 423
diff changeset
245 OnUnitAdded(unit);
d992758b0150 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 423
diff changeset
246 OnArmyCompositionChanged();
d992758b0150 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 423
diff changeset
247 unit.UnitEquipmentAmountChanged += HandleUnitUnitEquipmentAmountChanged;
d992758b0150 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 423
diff changeset
248 unit.UnitSizeChanged += HandleUnitUnitSizeChanged;
337
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
249 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
250
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
251 private void Army_UnitRemoved(WarFoundryObject val)
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
252 {
424
d992758b0150 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 423
diff changeset
253 Unit unit = (Unit)val;
d992758b0150 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 423
diff changeset
254 OnUnitRemoved(unit);
d992758b0150 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 423
diff changeset
255 OnArmyCompositionChanged();
d992758b0150 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 423
diff changeset
256 unit.UnitEquipmentAmountChanged -= HandleUnitUnitEquipmentAmountChanged;
d992758b0150 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 423
diff changeset
257 unit.UnitSizeChanged -= HandleUnitUnitSizeChanged;
d992758b0150 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 423
diff changeset
258 }
d992758b0150 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 423
diff changeset
259
d992758b0150 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 423
diff changeset
260 private void HandleUnitUnitEquipmentAmountChanged (WarFoundryObject obj, double oldValue, double newValue)
d992758b0150 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 423
diff changeset
261 {
d992758b0150 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 423
diff changeset
262 OnArmyCompositionChanged();
d992758b0150 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 423
diff changeset
263 }
d992758b0150 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 423
diff changeset
264
d992758b0150 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 423
diff changeset
265 private void HandleUnitUnitSizeChanged (WarFoundryObject obj, int oldValue, int newValue)
d992758b0150 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 423
diff changeset
266 {
d992758b0150 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 423
diff changeset
267 OnArmyCompositionChanged();
337
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
268 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
269
353
65fccdd51aec Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 348
diff changeset
270 public ICollection<IRequirement> GetRequirements ()
65fccdd51aec Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 348
diff changeset
271 {
65fccdd51aec Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 348
diff changeset
272 return Race.GetRequirements();
65fccdd51aec Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 348
diff changeset
273 }
424
d992758b0150 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 423
diff changeset
274
d992758b0150 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 423
diff changeset
275 internal void OnArmyCompositionChanged()
d992758b0150 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 423
diff changeset
276 {
d992758b0150 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 423
diff changeset
277 if (ArmyCompositionChanged != null)
d992758b0150 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 423
diff changeset
278 {
d992758b0150 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 423
diff changeset
279 ArmyCompositionChanged();
d992758b0150 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 423
diff changeset
280 }
d992758b0150 Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents: 423
diff changeset
281 }
337
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
282 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
283 }