Changeset 146
- Timestamp:
- 06/27/09 14:39:04 (14 months ago)
- Location:
- IBBoard.WarFoundry.API/trunk/api
- Files:
-
- 4 modified
-
Commands/CreateAndAddUnitCommand.cs (modified) (4 diffs)
-
Objects/Army.cs (modified) (6 diffs)
-
Objects/ArmyCategory.cs (modified) (3 diffs)
-
Objects/Unit.cs (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
IBBoard.WarFoundry.API/trunk/api/Commands/CreateAndAddUnitCommand.cs
r143 r146 13 13 { 14 14 private UnitType addedUnitType; 15 private Army army;15 private ArmyCategory armyCat; 16 16 private Unit addedUnit; 17 17 18 public CreateAndAddUnitCommand(UnitType toAdd, Army armyTo)18 public CreateAndAddUnitCommand(UnitType toAdd, ArmyCategory armyCatTo) 19 19 { 20 20 addedUnitType = toAdd; 21 army = armyTo;21 armyCat = armyCatTo; 22 22 } 23 23 24 24 [Obsolete("Use two parameter constructor instead")] 25 public CreateAndAddUnitCommand(UnitType toAdd, ArmyCategory catTo, Army armyTo) : this(toAdd, armyTo)25 public CreateAndAddUnitCommand(UnitType toAdd, ArmyCategory catTo, Army armyTo) : this(toAdd, catTo) 26 26 { 27 27 } … … 34 34 public override bool CanExecute() 35 35 { 36 return (addedUnitType!=null && army !=null);36 return (addedUnitType!=null && armyCat!=null); 37 37 } 38 38 … … 49 49 public override bool Execute() 50 50 { 51 addedUnit = new Unit(addedUnitType, army );51 addedUnit = new Unit(addedUnitType, armyCat); 52 52 this.Redo(); 53 53 return true; … … 56 56 public override void Redo() 57 57 { 58 army .AddUnit(addedUnit);58 armyCat.AddUnit(addedUnit); 59 59 } 60 60 61 61 public override void Undo() 62 62 { 63 army .RemoveUnit(addedUnit);63 armyCat.RemoveUnit(addedUnit); 64 64 } 65 65 -
IBBoard.WarFoundry.API/trunk/api/Objects/Army.cs
r143 r146 70 70 cat.UnitAdded+=new ObjectAddDelegate(Army_UnitAdded); 71 71 cat.UnitRemoved+=new ObjectRemoveDelegate(Army_UnitRemoved); 72 cat.FailedRequirement+=new FailedUnitRequirementDelegate(Army_FailedRequirement); 72 73 } 73 74 } … … 102 103 protected void OnUnitAdded(Unit unit, List<FailedUnitRequirement> failedReqs) 103 104 { 104 if (UnitAdded !=null)105 if (UnitAdded != null) 105 106 { 106 107 UnitAdded(unit); 107 108 } 108 109 109 if (FailedRequirement!=null && failedReqs!=null && failedReqs.Count > 0) 110 { 111 FailedRequirement(failedReqs); 112 } 110 OnFailedRequirement(failedReqs); 113 111 } 114 112 … … 125 123 } 126 124 127 if (FailedRequirement!=null && failedReqs!=null && failedReqs.Count > 0) 125 OnFailedRequirement(failedReqs); 126 } 127 128 protected void OnFailedRequirement(List<FailedUnitRequirement> failedReqs) 129 { 130 if (FailedRequirement != null && failedReqs != null && failedReqs.Count > 0) 128 131 { 129 132 FailedRequirement(failedReqs); … … 161 164 public void AddUnit(Unit unit) 162 165 { 163 unit.Army = this;164 166 ArmyCategory armyCat = GetCategory(unit.UnitType.MainCategory); 165 167 armyCat.AddUnit(unit); … … 168 170 public void RemoveUnit(Unit unit) 169 171 { 170 List<FailedUnitRequirement> failedReqs = CanRemoveUnit(unit);171 unit.Army = null;172 172 unit.Category.RemoveUnit(unit); 173 OnUnitRemoved(unit, failedReqs);174 173 } 175 174 … … 255 254 } 256 255 257 private void Army_UnitAdded( object val)256 private void Army_UnitAdded(WarFoundryObject val) 258 257 { 259 258 OnUnitAdded((Unit)val); 260 259 } 261 260 262 private void Army_UnitRemoved( object val)261 private void Army_UnitRemoved(WarFoundryObject val) 263 262 { 264 263 OnUnitRemoved((Unit)val); 264 } 265 266 private void Army_FailedRequirement(List<FailedUnitRequirement> val) 267 { 268 OnFailedRequirement(val); 265 269 } 266 270 } -
IBBoard.WarFoundry.API/trunk/api/Objects/ArmyCategory.cs
r143 r146 23 23 public event ObjectAddDelegate UnitAdded; 24 24 public event ObjectRemoveDelegate UnitRemoved; 25 public event FailedUnitRequirementDelegate FailedRequirement; 25 26 26 27 public ArmyCategory(Army army, Category cat) : base() … … 75 76 unitTypes[unit.UnitType.ID] = (int)unitTypeCount + 1; 76 77 TotalPoints+= unit.PointsValue; 77 OnUnitAdded(unit );78 OnUnitAdded(unit, failedReqs); 78 79 } 79 80 80 81 internal void RemoveUnit(Unit unit) 81 82 { 83 List<FailedUnitRequirement> failedReqs = ParentArmy.CanRemoveUnit(unit); 82 84 units.Remove(unit); 83 85 unitTypes[unit.UnitType.ID] = ((int)unitTypes[unit.UnitType.ID])-1; 84 86 TotalPoints-= unit.PointsValue; 85 87 unit.PointsValueChanged-= PointsValueChangedMethod; 86 OnUnitRemoved(unit );88 OnUnitRemoved(unit, failedReqs); 87 89 } 88 90 … … 126 128 } 127 129 128 pr ivatevoid OnUnitAdded(Unit unit)130 protected void OnUnitAdded(Unit unit) 129 131 { 130 if (UnitAdded!=null) 132 OnUnitAdded(unit, null); 133 } 134 135 protected void OnUnitAdded(Unit unit, List<FailedUnitRequirement> failedReqs) 136 { 137 if (UnitAdded != null) 131 138 { 132 139 UnitAdded(unit); 133 140 } 141 142 if (FailedRequirement != null && failedReqs != null && failedReqs.Count > 0) 143 { 144 FailedRequirement(failedReqs); 145 } 134 146 } 135 147 136 pr ivatevoid OnUnitRemoved(Unit unit)148 protected void OnUnitRemoved(Unit unit) 137 149 { 138 if (UnitRemoved!=null) 150 OnUnitRemoved(unit, null); 151 } 152 153 protected void OnUnitRemoved(Unit unit, List<FailedUnitRequirement> failedReqs) 154 { 155 if (UnitRemoved != null) 139 156 { 140 157 UnitRemoved(unit); 158 } 159 160 if (FailedRequirement != null && failedReqs != null && failedReqs.Count > 0) 161 { 162 FailedRequirement(failedReqs); 141 163 } 142 164 } -
IBBoard.WarFoundry.API/trunk/api/Objects/Unit.cs
r143 r146 18 18 private UnitType type; 19 19 private int size; 20 private Army army;21 20 private Unit parentUnit; 22 21 private double points; … … 28 27 public event DoubleValChangedDelegate UnitEquipmentAmountChanged; 29 28 30 public Unit(UnitType unitType, Army parentArmy) : this(unitType, unitType.MinSize, parentArmy){}31 32 public Unit(UnitType unitType, int startSize, Army parentArmy)33 { 34 Army = parentArmy;29 public Unit(UnitType unitType, ArmyCategory parentArmyCat) : this(unitType, unitType.MinSize, parentArmyCat) { } 30 31 public Unit(UnitType unitType, int startSize, ArmyCategory parentArmyCat) 32 { 33 Category = parentArmyCat; 35 34 type = unitType; 36 35 Size = startSize; … … 144 143 public Army Army 145 144 { 146 get { return army; } 147 set 148 { 149 army = value; 150 151 if (army == null) 152 { 153 Category = null; 154 } 155 } 145 get { return (Category == null ? null : Category.ParentArmy); } 156 146 } 157 147 … … 163 153 public ArmyCategory Category 164 154 { 165 get 166 { 167 if (cat==null) 168 { 169 if (Army!=null) 170 { 171 return Army.GetCategory(UnitType.MainCategory); 172 } 173 else 174 { 175 return null; 176 } 177 } 178 else 179 { 180 return cat; 181 } 155 get 156 { 157 return cat; 182 158 } 183 159 set { cat = value; }
WarFoundry - Development