annotate api/Objects/Unit.cs @ 85:46ad6f478203

Re #50: Complete core loading of WarFoundry XML files * Start loading of UnitEquipmentItems * Fix XPath queries for equipment items and abilities * Allow UnitEquipmentItem to be created without a UnitType * Make adding UnitEquipmentItem to UnitType set UnitType of UnitEquipmentItem * Make loading of abilities and equipment items add the item to the race Also: * Code cleanup (line endings) * Make method to get equipment by ID return null instead of throwing "no such key" exception
author IBBoard <dev@ibboard.co.uk>
date Sat, 01 Aug 2009 16:06:25 +0000
parents 89cc29b4c012
children 110a7b0bcab5
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: 0
diff changeset
1 // This file (Unit.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: 0
diff changeset
2 //
306558904c2a Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
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: 0
diff changeset
4
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
5 using System;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
6 using System.Collections.Generic;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
7 using System.Text;
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 using System.Xml;
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
9 using IBBoard.Lang;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
10
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
11 namespace IBBoard.WarFoundry.API.Objects
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
12 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
13 /// <summary>
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
14 /// Summary description for UnitInstance.
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
15 /// </summary>
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
16 public class Unit : WarFoundryObject
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
17 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
18 private UnitType type;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
19 private int size;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
20 private Unit parentUnit;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
21 private double points;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
22 private ArmyCategory cat;
80
aa66dd18cdae Closes #81 - Resolve Unit Equipment problems in WinForms GUI
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
23 private Dictionary<UnitEquipmentItem, double> equipment = new Dictionary<UnitEquipmentItem, double>();
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
24 private List<Unit> containedUnits = new List<Unit>();
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
25 public event DoubleValChangedDelegate PointsValueChanged;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
26 public event IntValChangedDelegate UnitSizeChanged;
85
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
27 public event DoubleValChangedDelegate UnitEquipmentAmountChanged;
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
28
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
29 public Unit(UnitType unitType, ArmyCategory parentArmyCat) : this(unitType, unitType.MinSize, parentArmyCat) { }
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
30
83
89cc29b4c012 Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents: 82
diff changeset
31 public Unit(UnitType unitType, int startSize, ArmyCategory parentArmyCat)
85
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
32 {
83
89cc29b4c012 Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents: 82
diff changeset
33 Category = parentArmyCat;
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
34 type = unitType;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
35 Size = startSize;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
36 SetInitialEquipment();
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
37 CalcCost();
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
38 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
39
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
40 protected override string DefaultName()
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
41 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
42 if (type != null)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
43 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
44 if (size == 1)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
45 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
46 return type.Name;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
47 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
48 else
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
49 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
50 return String.Format(Translation.GetTranslation("defaultUnitName"), size, type.Name);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
51 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
52 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
53 else
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
54 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
55 return "Unknown Unit";
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
56 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
57 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
58
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
59 private void SetInitialEquipment()
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
60 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
61 foreach (UnitEquipmentItem unitEquip in UnitType.GetEquipmentItems())
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
62 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
63 if (unitEquip.IsRequired)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
64 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
65 if (CanEquipWithItem(unitEquip))
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
66 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
67 equipment[unitEquip] = unitEquip.MinNumber;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
68 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
69 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
70 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
71 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
72
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
73 private void CalcCost()
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
74 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
75 String oldName = HasDefaultName() ? Name : null;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
76 double oldpoints = points;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
77 points = type.CostPerTrooper * AdditionalTroopers + type.BaseUnitCost;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
78
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
79 foreach (UnitEquipmentItem unitEquipItem in equipment.Keys)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
80 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
81 double count = equipment[unitEquipItem];
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
83 if (unitEquipItem.IsRatioLimit)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
84 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
85 if (unitEquipItem.RoundNumberUp)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
86 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
87 points += Math.Ceiling(size * count) * unitEquipItem.Cost;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
88 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
89 else
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
90 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
91 points += Math.Floor(size * count) * unitEquipItem.Cost;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
92 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
93 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
94 else
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
95 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
96 if (count == WarFoundryCore.INFINITY)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
97 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
98 points += size * unitEquipItem.Cost;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
99 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
100 else
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
101 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
102 points += count * unitEquipItem.Cost;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
103 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
104 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
105 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
106
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
107 if (oldpoints!=points)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
108 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
109 OnPointsValueChanged(oldpoints, points);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
110 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
111
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
112 if (oldName!=null)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
113 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
114 OnNameChanged(oldName, Name);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
115 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
116 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
117
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
118 public int AdditionalTroopers
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
119 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
120 get { return Math.Max(Size - type.BaseSize, 0); }
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
121 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
122
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
123 public int Size
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
124 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
125 get { return size; }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
126 set
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
127 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
128 if (value!=size)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
129 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
130 int oldValue = size;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
131 size = (value>0 ? value : 1);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
132 CalcCost();
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
133 OnUnitSizeChanged(oldValue, size);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
134 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
135 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
136 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
137
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
138 public UnitType UnitType
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
139 {
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
140 get { return type; }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
141 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
142
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
143 public Army Army
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
144 {
83
89cc29b4c012 Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents: 82
diff changeset
145 get { return (Category == null ? null : Category.ParentArmy); }
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
146 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
147
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
148 public Race Race
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
149 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
150 get { return UnitType.Race; }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
151 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
152
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
153 public ArmyCategory Category
85
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
154 {
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
155 get
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
156 {
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
157 return cat;
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
158 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
159 set { cat = value; }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
160 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
161
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
162 public double PointsValue
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
163 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
164 get
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
165 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
166 if (points == 0)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
167 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
168 CalcCost();
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
169 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
170
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
171 return points;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
172 }
61
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
173 }
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
174
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
175 public Unit[] ContainedUnits
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
176 {
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
177 get { return containedUnits.ToArray(); }
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
178 }
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
179
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
180 public void AddContainedUnit(Unit unit)
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
181 {
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
182 if (UnitType.CanContainUnit(unit))
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
183 {
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
184 if (!containedUnits.Contains(unit))
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
185 {
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
186 containedUnits.Add(unit);
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
187 }
65
aa2d05a9c635 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
188
aa2d05a9c635 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
189 unit.ParentUnit = this;
61
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
190 }
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
191 else
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
192 {
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
193 throw new InvalidContainershipException(this, unit);
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
194 }
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
195 }
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
196
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
197 public void RemoveContainedUnit(Unit unit)
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
198 {
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
199 containedUnits.Remove(unit);
65
aa2d05a9c635 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
200 }
aa2d05a9c635 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
201
aa2d05a9c635 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
202 public Unit ParentUnit
aa2d05a9c635 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
203 {
aa2d05a9c635 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
204 get { return parentUnit; }
aa2d05a9c635 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
205 set
aa2d05a9c635 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
206 {
aa2d05a9c635 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
207 if (!(parentUnit == value || (parentUnit != null && parentUnit.Equals(value))))
aa2d05a9c635 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
208 {
aa2d05a9c635 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
209 parentUnit = value;
aa2d05a9c635 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
210
aa2d05a9c635 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
211 if (value!=null)
aa2d05a9c635 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
212 {
aa2d05a9c635 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
213 value.AddContainedUnit(this);
aa2d05a9c635 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
214 }
aa2d05a9c635 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
215 }
aa2d05a9c635 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
216 }
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
217 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
218
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
219 public UnitEquipmentItem[] GetAllowedOptionalEquipment()
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
220 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
221 List<UnitEquipmentItem> list = new List<UnitEquipmentItem>();
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
222
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
223 foreach (UnitEquipmentItem item in UnitType.GetEquipmentItems())
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
224 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
225 if (!item.IsRequired)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
226 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
227 list.Add(item);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
228 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
229 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
230
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
231 return list.ToArray();
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
232 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
233
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
234 public UnitEquipmentItem[] GetEquipment()
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
235 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
236 return DictionaryUtils.ToKeyArray(equipment);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
237 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
238
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
239 public EquipmentItem[] GetRequiredEquipment()
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
240 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
241 List<EquipmentItem> list = new List<EquipmentItem>();
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
242
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
243 foreach(UnitEquipmentItem item in GetEquipment())
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
244 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
245 if (item.IsRequired)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
246 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
247 list.Add(item.EquipmentItem);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
248 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
249 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
250
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
251 return list.ToArray();
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
252 }
64
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
253
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
254 public double GetEquipmentAmount(UnitEquipmentItem item)
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
255 {
80
aa66dd18cdae Closes #81 - Resolve Unit Equipment problems in WinForms GUI
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
256 return GetEquipmentAmount(item.ID);
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
257 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
258
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
259 public double GetEquipmentAmount(string equipID)
54
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
260 {
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
261 return GetEquipmentAmount(UnitType.GetEquipmentItem(equipID));
64
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
262 }
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
263
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
264 public void SetEquipmentAmount(UnitEquipmentItem equip, int amount)
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
265 {
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
266 if (equip.IsRatioLimit)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
267 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
268 throw new InvalidOperationException("Equipment with ID "+equip.ID+" for unit of type "+UnitType.ID+" has a ratio limit, not an absolute limit");
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
269 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
270
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
271 if (amount <1 && amount != WarFoundryCore.INFINITY)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
272 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
273 amount = 0;
54
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
274 }
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
275
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
276 SetEquipmentAmount(equip, amount);
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
277 }
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
278
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
279 public void SetEquipmentRatio(UnitEquipmentItem equip, double ratio)
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
280 {
80
aa66dd18cdae Closes #81 - Resolve Unit Equipment problems in WinForms GUI
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
281 if (!equip.IsRatioLimit)
54
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
282 {
64
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
283 throw new InvalidOperationException("Equipment with ID "+equip.ID+" for unit of type "+UnitType.ID+" has an absolute limit, not a ratio limit");
54
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
284 }
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
285
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
286 if (ratio > 1)
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
287 {
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
288 ratio = 1;
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
289 }
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
290 else if (ratio < 0)
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
291 {
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
292 ratio = 0;
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
293 }
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
294
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
295 SetEquipmentAmount(equip, ratio);
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
296 }
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
297
80
aa66dd18cdae Closes #81 - Resolve Unit Equipment problems in WinForms GUI
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
298 private void SetEquipmentAmount(UnitEquipmentItem equip, double amount)
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
299 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
300 double oldAmount = 0;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
301
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
302 if (equipment.ContainsKey(equip))
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
303 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
304 oldAmount = equipment[equip];
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
305 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
306
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
307 if (amount!=oldAmount)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
308 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
309 if (amount != 0)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
310 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
311 equipment[equip] = amount;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
312 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
313 else
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
314 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
315 equipment.Remove(equip);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
316 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
317
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
318 OnUnitEquipmentAmountChanged(equip, oldAmount, amount);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
319 CalcCost();
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
320 }
64
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
321 }
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
322
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
323 public bool CanEquipWithItem(UnitEquipmentItem item)
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
324 {
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
325 string mutex = item.MutexGroup;
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
326
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
327 if (mutex == "")
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
328 {
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
329 return true;
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
330 }
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
331
80
aa66dd18cdae Closes #81 - Resolve Unit Equipment problems in WinForms GUI
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
332 foreach (UnitEquipmentItem unitItem in GetEquipment())
64
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
333 {
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
334 if (unitItem.MutexGroup == mutex)
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
335 {
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
336 return false;
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
337 }
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
338 }
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
339
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
340 return true;
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
341 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
342
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
343 public bool CanEquipWithItem(string equipID)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
344 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
345 return CanEquipWithItem(UnitType.GetEquipmentItem(equipID));
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
346 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
347
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
348 private void OnPointsValueChanged(double oldValue, double newValue)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
349 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
350 if (PointsValueChanged!=null)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
351 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
352 PointsValueChanged(this, oldValue, newValue);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
353 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
354 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
355
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
356 private void OnUnitSizeChanged(int oldValue, int newValue)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
357 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
358 if (UnitSizeChanged!=null)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
359 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
360 UnitSizeChanged(this, oldValue, newValue);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
361 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
362 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
363
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
364 private void OnUnitEquipmentAmountChanged(UnitEquipmentItem equip, double oldValue, double newValue)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
365 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
366 if (UnitEquipmentAmountChanged!=null)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
367 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
368 UnitEquipmentAmountChanged(equip, oldValue, newValue);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
369 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
370 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
371
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
372 public Stat[] UnitStatsArray
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
373 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
374 get { return UnitType.UnitStatsArray; }
81
032b174fc17a Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
375 }
032b174fc17a Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
376
032b174fc17a Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
377 public Stat[] UnitStatsArrayWithName
032b174fc17a Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
378 {
032b174fc17a Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
379 get { return UnitType.UnitStatsArrayWithName; }
032b174fc17a Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
380 }
032b174fc17a Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
381
032b174fc17a Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
382 public string GetStatValue(string statName)
032b174fc17a Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
383 {
032b174fc17a Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
384 return UnitType.GetStatValue(statName);
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
385 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
386 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
387 }