annotate api/Objects/Unit.cs @ 125:c60fd5664698

Re #53: Create WarFoundry save class to store army as file * Fix exceptions thrown by official .Net XML parsing of namespace names Also: * Remove unnecessary notification of name change no-open-ticket
author IBBoard <dev@ibboard.co.uk>
date Mon, 24 Aug 2009 21:12:18 +0000
parents 52e8c3cdde10
children 57f7b80757ea
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: 101
diff changeset
1 // This file (Unit.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 2007, 2008, IBBoard.
15
306558904c2a Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
2 //
104
2f3cafb69799 Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents: 101
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: 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;
96
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
23 private Dictionary<UnitEquipmentItem, AbstractUnitEquipmentItemSelection> equipment = new Dictionary<UnitEquipmentItem, AbstractUnitEquipmentItemSelection>();
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
123
52e8c3cdde10 Re #127: Unit creation always assigns default equipment
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
31 public Unit(UnitType unitType, int startSize, ArmyCategory parentArmyCat) : this("", "", startSize, unitType, parentArmyCat)
52e8c3cdde10 Re #127: Unit creation always assigns default equipment
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
32 {
52e8c3cdde10 Re #127: Unit creation always assigns default equipment
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
33 SetInitialEquipment();
52e8c3cdde10 Re #127: Unit creation always assigns default equipment
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
34 }
52e8c3cdde10 Re #127: Unit creation always assigns default equipment
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
35
52e8c3cdde10 Re #127: Unit creation always assigns default equipment
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
36 public Unit(string id, string name, int startSize, UnitType unitType, ArmyCategory parentArmyCat) : base(id, name)
85
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
37 {
83
89cc29b4c012 Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents: 82
diff changeset
38 Category = parentArmyCat;
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
39 type = unitType;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
40 Size = startSize;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
41 CalcCost();
96
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
42 UnitEquipmentAmountChanged+= new DoubleValChangedDelegate(UnitEquipmentAmountChangedHandler);
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
43 UnitSizeChanged+= new IntValChangedDelegate(UnitSizeChangedHandler);
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
44 }
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
45
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
46 private void UnitEquipmentAmountChangedHandler(WarFoundryObject obj, double oldVal, double newVal)
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
47 {
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
48 CalcCost();
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
49 }
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
50
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
51 private void UnitSizeChangedHandler(WarFoundryObject obj, int oldVal, int newVal)
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
52 {
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
53 CalcCost();
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
54
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
55 if (HasDefaultName())
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
56 {
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
57 OnNameChanged("", Name);
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
58 }
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
59 }
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 protected override string DefaultName()
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 (type != null)
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 (size == 1)
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 return type.Name;
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 else
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 return String.Format(Translation.GetTranslation("defaultUnitName"), size, type.Name);
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 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
74 else
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
75 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
76 return "Unknown Unit";
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
77 }
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
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
80 private void SetInitialEquipment()
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
81 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
82 foreach (UnitEquipmentItem unitEquip in UnitType.GetEquipmentItems())
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
83 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
84 if (unitEquip.IsRequired)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
85 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
86 if (CanEquipWithItem(unitEquip))
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
87 {
96
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
88 if (unitEquip.IsRatioLimit)
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
89 {
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
90 equipment[unitEquip] = new UnitEquipmentRatioSelection(this, unitEquip);
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
91 }
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
92 else
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
93 {
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
94 equipment[unitEquip] = new UnitEquipmentNumericSelection(this, unitEquip);
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
95 }
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
96 }
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 }
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
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
101 private void CalcCost()
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
102 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
103 double oldpoints = points;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
104 points = type.CostPerTrooper * AdditionalTroopers + type.BaseUnitCost;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
105
96
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
106 foreach (AbstractUnitEquipmentItemSelection equipSelection in equipment.Values)
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
107 {
96
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
108 points += equipSelection.TotalCost;
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
109 }
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 if (oldpoints!=points)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
112 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
113 OnPointsValueChanged(oldpoints, points);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
114 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
115 }
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 public int AdditionalTroopers
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
118 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
119 get { return Math.Max(Size - type.BaseSize, 0); }
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
120 }
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 public int Size
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
123 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
124 get { return size; }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
125 set
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
126 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
127 if (value!=size)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
128 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
129 int oldValue = size;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
130 size = (value>0 ? value : 1);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
131 OnUnitSizeChanged(oldValue, size);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
132 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
133 }
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 public UnitType UnitType
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
137 {
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
138 get { return type; }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
139 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
140
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
141 public Army Army
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
142 {
83
89cc29b4c012 Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents: 82
diff changeset
143 get { return (Category == null ? null : Category.ParentArmy); }
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
144 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
145
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
146 public Race Race
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 get { return UnitType.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
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
151 public ArmyCategory Category
85
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
152 {
46ad6f478203 Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
153 get
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 return cat;
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
156 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
157 set { cat = value; }
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
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
160 public double PointsValue
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 get
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 if (points == 0)
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 CalcCost();
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
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
169 return points;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
170 }
61
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
171 }
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
172
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
173 public Unit[] ContainedUnits
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 get { return containedUnits.ToArray(); }
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
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
178 public void AddContainedUnit(Unit unit)
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 if (UnitType.CanContainUnit(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 (!containedUnits.Contains(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 containedUnits.Add(unit);
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
185 }
65
aa2d05a9c635 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
186
aa2d05a9c635 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
187 unit.ParentUnit = this;
61
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
188 }
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
189 else
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 throw new InvalidContainershipException(this, unit);
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 }
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 public void RemoveContainedUnit(Unit unit)
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 containedUnits.Remove(unit);
65
aa2d05a9c635 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
198 }
aa2d05a9c635 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
199
aa2d05a9c635 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
200 public Unit ParentUnit
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 get { return parentUnit; }
aa2d05a9c635 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
203 set
aa2d05a9c635 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
204 {
aa2d05a9c635 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
205 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
206 {
aa2d05a9c635 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
207 parentUnit = 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 if (value!=null)
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 value.AddContainedUnit(this);
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 }
aa2d05a9c635 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
214 }
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
215 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
216
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
217 public UnitEquipmentItem[] GetAllowedOptionalEquipment()
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 List<UnitEquipmentItem> list = new List<UnitEquipmentItem>();
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 foreach (UnitEquipmentItem item in UnitType.GetEquipmentItems())
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 if (!item.IsRequired)
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 list.Add(item);
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 }
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 return list.ToArray();
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
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
232 public UnitEquipmentItem[] GetEquipment()
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 return DictionaryUtils.ToKeyArray(equipment);
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
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
237 public EquipmentItem[] GetRequiredEquipment()
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 List<EquipmentItem> list = new List<EquipmentItem>();
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 foreach(UnitEquipmentItem item in GetEquipment())
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 if (item.IsRequired)
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 list.Add(item.EquipmentItem);
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 }
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 return list.ToArray();
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
250 }
64
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
251
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
252 public double GetEquipmentAmount(UnitEquipmentItem item)
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
253 {
96
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
254 double amount = 0;
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
255 AbstractUnitEquipmentItemSelection selection = DictionaryUtils.GetValue(equipment, item);
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
256
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
257 if (selection != null)
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
258 {
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
259 amount = selection.AmountTaken;
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
260 }
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
261
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
262 return amount;
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
263 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
264
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
265 public double GetEquipmentAmount(string equipID)
54
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
266 {
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
267 return GetEquipmentAmount(UnitType.GetEquipmentItem(equipID));
64
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
268 }
101
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
269
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
270 public bool GetEquipmentAmountIsRatio(UnitEquipmentItem item)
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
271 {
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
272 return (DictionaryUtils.GetValue(equipment, item) is UnitEquipmentRatioSelection);
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
273 }
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
274
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
275 public bool GetEquipmentAmountIsRatio(string itemID)
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
276 {
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
277 return GetEquipmentAmountIsRatio(UnitType.GetEquipmentItem(itemID));
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
278 }
64
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
279
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
280 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
281 {
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
282 if (amount <1 && amount != WarFoundryCore.INFINITY)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
283 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
284 amount = 0;
54
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
96
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
287 if (amount == 0)
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
288 {
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
289 RemoveEquipmentItem(equip);
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
290 }
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
291 else
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
292 {
98
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
293 AbstractUnitEquipmentItemSelection currSelection = DictionaryUtils.GetValue(equipment, equip);
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
294 double oldAmount = (currSelection == null ? 0 : currSelection.AmountTaken);
96
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
295
98
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
296 if (amount != oldAmount)
96
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
297 {
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
298 if (oldAmount == 0)
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
299 {
98
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
300 AddEquipmentAmount(equip, amount);
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
301 }
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
302 else if (currSelection is UnitEquipmentNumericSelection)
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
303 {
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
304 //A UnitEquipmentItem shouldn't change its IsRatio value, so assume we already have the right sub-type
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
305 currSelection.AmountTaken = amount;
96
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
306 }
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
307 else
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
308 {
98
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
309 equipment.Remove(equip);
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
310 AddEquipmentAmount(equip, amount);
96
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
311 }
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
312
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
313 OnUnitEquipmentAmountChanged(equip, oldAmount, amount);
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
314 }
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
315 }
54
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
316 }
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
317
98
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
318 private void AddEquipmentAmount(UnitEquipmentItem equip, int amount)
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
319 {
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
320 AbstractUnitEquipmentItemSelection newItem = null;
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
321
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
322 if (equip.IsRatioLimit)
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
323 {
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
324 newItem = new UnitEquipmentNumericForRatioSelection(this, equip, amount);
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
325 }
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
326 else
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
327 {
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
328 newItem = new UnitEquipmentNumericSelection(this, equip, amount);
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
329 }
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
330
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
331 equipment[equip] = newItem;
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
332 }
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
333
54
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
334 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
335 {
80
aa66dd18cdae Closes #81 - Resolve Unit Equipment problems in WinForms GUI
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
336 if (!equip.IsRatioLimit)
54
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
337 {
64
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
338 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
339 }
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
340
101
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
341 if (ratio > 100)
54
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
342 {
101
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
343 ratio = 100;
54
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
344 }
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
345 else if (ratio < 0)
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
346 {
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
347 ratio = 0;
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
348 }
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
349
96
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
350 if (ratio == 0)
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
351 {
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
352 RemoveEquipmentItem(equip);
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
353 }
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
354 else
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
355 {
98
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
356 AbstractUnitEquipmentItemSelection currSelection = DictionaryUtils.GetValue(equipment, equip);
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
357 double oldRatio = (currSelection == null ? 0 : currSelection.AmountTaken);
96
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
358
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
359 if (ratio != oldRatio)
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
360 {
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
361 if (oldRatio == 0)
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
362 {
98
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
363 AddEquipmentRatio(equip, ratio);
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
364 }
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
365 else if (currSelection is UnitEquipmentRatioSelection)
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
366 {
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
367 currSelection.AmountTaken = ratio;
96
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
368 }
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
369 else
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
370 {
98
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
371 equipment.Remove(equip);
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
372 AddEquipmentRatio(equip, ratio);
96
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
373 }
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
374
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
375 OnUnitEquipmentAmountChanged(equip, oldRatio, ratio);
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
376 }
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
377 }
54
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
378 }
3a90f70dac73 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
379
98
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
380 private void AddEquipmentRatio(UnitEquipmentItem equip, double ratio)
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
381 {
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
382 equipment[equip] = new UnitEquipmentRatioSelection(this, equip, ratio);
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
383 }
4dd1c41c95b4 Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
384
96
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
385 private void RemoveEquipmentItem(UnitEquipmentItem equip)
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
386 {
96
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
387 double oldAmount = GetEquipmentAmount(equip);
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
388
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
389 if (oldAmount != 0)
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
390 {
96
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
391 equipment.Remove(equip);
ced5a18d9f52 Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
392 OnUnitEquipmentAmountChanged(equip, oldAmount, 0);
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
393 }
64
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
394 }
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
395
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
396 public bool CanEquipWithItem(UnitEquipmentItem item)
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
397 {
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
398 string mutex = item.MutexGroup;
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
399
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
400 if (mutex == "")
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
401 {
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
402 return true;
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
403 }
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
404
80
aa66dd18cdae Closes #81 - Resolve Unit Equipment problems in WinForms GUI
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
405 foreach (UnitEquipmentItem unitItem in GetEquipment())
64
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
406 {
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
407 if (unitItem.MutexGroup == mutex)
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
408 {
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
409 return false;
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
410 }
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
411 }
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
412
2094bd0ba652 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
413 return true;
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
414 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
415
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
416 public bool CanEquipWithItem(string equipID)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
417 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
418 return CanEquipWithItem(UnitType.GetEquipmentItem(equipID));
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
419 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
420
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
421 private void OnPointsValueChanged(double oldValue, double newValue)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
422 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
423 if (PointsValueChanged!=null)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
424 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
425 PointsValueChanged(this, oldValue, newValue);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
426 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
427 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
428
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
429 private void OnUnitSizeChanged(int oldValue, int newValue)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
430 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
431 if (UnitSizeChanged!=null)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
432 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
433 UnitSizeChanged(this, oldValue, newValue);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
434 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
435 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
436
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
437 private void OnUnitEquipmentAmountChanged(UnitEquipmentItem equip, double oldValue, double newValue)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
438 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
439 if (UnitEquipmentAmountChanged!=null)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
440 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
441 UnitEquipmentAmountChanged(equip, oldValue, newValue);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
442 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
443 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
444
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
445 public Stat[] UnitStatsArray
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
446 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
447 get { return UnitType.UnitStatsArray; }
81
032b174fc17a Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
448 }
032b174fc17a Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
449
032b174fc17a Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
450 public Stat[] UnitStatsArrayWithName
032b174fc17a Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
451 {
032b174fc17a Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
452 get { return UnitType.UnitStatsArrayWithName; }
032b174fc17a Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
453 }
032b174fc17a Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
454
032b174fc17a Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
455 public string GetStatValue(string statName)
032b174fc17a Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
456 {
032b174fc17a Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
457 return UnitType.GetStatValue(statName);
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
458 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
459 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 81
diff changeset
460 }