Mercurial > repos > IBBoard.WarFoundry.API
comparison API/Objects/ArmyCategory.cs @ 367:1a70ca80ef41
Re #27: Define unit requirements
* Remove remaining references to old Requirements namespace
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 28 May 2011 15:51:54 +0000 |
parents | 3c4a6403a88c |
children | 0a2068897793 |
comparison
equal
deleted
inserted
replaced
366:4993e6f7c509 | 367:1a70ca80ef41 |
---|---|
2 // | 2 // |
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. | 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. |
4 | 4 |
5 using System; | 5 using System; |
6 using System.Collections.Generic; | 6 using System.Collections.Generic; |
7 using IBBoard.WarFoundry.API.Requirements; | |
8 | 7 |
9 namespace IBBoard.WarFoundry.API.Objects | 8 namespace IBBoard.WarFoundry.API.Objects |
10 { | 9 { |
11 /// <summary> | 10 /// <summary> |
12 /// Summary description for ArmyCategory. | 11 /// Summary description for ArmyCategory. |
19 private List<Unit> units; | 18 private List<Unit> units; |
20 private Dictionary<string, int> unitTypes; | 19 private Dictionary<string, int> unitTypes; |
21 private DoubleValChangedDelegate PointsValueChangedMethod; | 20 private DoubleValChangedDelegate PointsValueChangedMethod; |
22 public event ObjectAddDelegate UnitAdded; | 21 public event ObjectAddDelegate UnitAdded; |
23 public event ObjectRemoveDelegate UnitRemoved; | 22 public event ObjectRemoveDelegate UnitRemoved; |
24 public event FailedUnitRequirementDelegate FailedRequirement; | |
25 public event DoubleValChangedDelegate PointsValueChanged; | 23 public event DoubleValChangedDelegate PointsValueChanged; |
26 | 24 |
27 public ArmyCategory(Army army, Category cat) : base() | 25 public ArmyCategory(Army army, Category cat) : base() |
28 { | 26 { |
29 parentArmy = army; | 27 parentArmy = army; |
65 } | 63 } |
66 } | 64 } |
67 | 65 |
68 internal void AddUnit(Unit unit) | 66 internal void AddUnit(Unit unit) |
69 { | 67 { |
70 List<FailedUnitRequirement> failedReqs = ParentArmy.CanAddUnit(unit); | 68 //TODO: Put back a similar check |
69 //List<FailedUnitRequirement> failedReqs = ParentArmy.CanAddUnit(unit); | |
71 units.Add(unit); | 70 units.Add(unit); |
72 unit.Category = this; | 71 unit.Category = this; |
73 unit.PointsValueChanged+= PointsValueChangedMethod; | 72 unit.PointsValueChanged+= PointsValueChangedMethod; |
74 int unitTypeCount; | 73 int unitTypeCount; |
75 unitTypes.TryGetValue(unit.UnitType.ID, out unitTypeCount); | 74 unitTypes.TryGetValue(unit.UnitType.ID, out unitTypeCount); |
76 unitTypes[unit.UnitType.ID] = (int)unitTypeCount + 1; | 75 unitTypes[unit.UnitType.ID] = (int)unitTypeCount + 1; |
77 TotalPoints+= unit.Points; | 76 TotalPoints+= unit.Points; |
78 OnUnitAdded(unit, failedReqs); | 77 OnUnitAdded(unit); |
79 } | 78 } |
80 | 79 |
81 internal void RemoveUnit(Unit unit) | 80 internal void RemoveUnit(Unit unit) |
82 { | 81 { |
83 List<FailedUnitRequirement> failedReqs = ParentArmy.CanRemoveUnit(unit); | 82 //TODO: Put back a similar check |
83 //List<FailedUnitRequirement> failedReqs = ParentArmy.CanRemoveUnit(unit); | |
84 units.Remove(unit); | 84 units.Remove(unit); |
85 unitTypes[unit.UnitType.ID] = ((int)unitTypes[unit.UnitType.ID])-1; | 85 unitTypes[unit.UnitType.ID] = ((int)unitTypes[unit.UnitType.ID])-1; |
86 TotalPoints-= unit.Points; | 86 TotalPoints-= unit.Points; |
87 unit.PointsValueChanged-= PointsValueChangedMethod; | 87 unit.PointsValueChanged-= PointsValueChangedMethod; |
88 OnUnitRemoved(unit, failedReqs); | 88 OnUnitRemoved(unit); |
89 } | 89 } |
90 | 90 |
91 public int GetUnitTypeCount(UnitType unitType) | 91 public int GetUnitTypeCount(UnitType unitType) |
92 { | 92 { |
93 return unitTypes.ContainsKey(unitType.ID) ? (int)unitTypes[unitType.ID] : 0; | 93 return unitTypes.ContainsKey(unitType.ID) ? (int)unitTypes[unitType.ID] : 0; |
127 } | 127 } |
128 } | 128 } |
129 | 129 |
130 protected void OnUnitAdded(Unit unit) | 130 protected void OnUnitAdded(Unit unit) |
131 { | 131 { |
132 OnUnitAdded(unit, null); | |
133 } | |
134 | |
135 protected void OnUnitAdded(Unit unit, List<FailedUnitRequirement> failedReqs) | |
136 { | |
137 if (UnitAdded != null) | 132 if (UnitAdded != null) |
138 { | 133 { |
139 UnitAdded(unit); | 134 UnitAdded(unit); |
140 } | |
141 | |
142 if (FailedRequirement != null && failedReqs != null && failedReqs.Count > 0) | |
143 { | |
144 FailedRequirement(failedReqs); | |
145 } | 135 } |
146 } | 136 } |
147 | 137 |
148 protected void OnUnitRemoved(Unit unit) | 138 protected void OnUnitRemoved(Unit unit) |
149 { | 139 { |
150 OnUnitRemoved(unit, null); | |
151 } | |
152 | |
153 protected void OnUnitRemoved(Unit unit, List<FailedUnitRequirement> failedReqs) | |
154 { | |
155 if (UnitRemoved != null) | 140 if (UnitRemoved != null) |
156 { | 141 { |
157 UnitRemoved(unit); | 142 UnitRemoved(unit); |
158 } | |
159 | |
160 if (FailedRequirement != null && failedReqs != null && failedReqs.Count > 0) | |
161 { | |
162 FailedRequirement(failedReqs); | |
163 } | 143 } |
164 } | 144 } |
165 | 145 |
166 protected virtual void OnPointsValueChanged(double oldValue, double newValue) | 146 protected virtual void OnPointsValueChanged(double oldValue, double newValue) |
167 { | 147 { |