Mercurial > repos > IBBoard.WarFoundry.API
annotate api/Commands/CreateAndAddUnitCommand.cs @ 64:2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
* Make Unit work with EquipmentItem objects as it doesn't need to know about the limits
* Add methods to UnitType to check limits on an EquipmentItem
Also:
* Remove some unnecessary casting now that we're using genericed lists
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Thu, 09 Apr 2009 15:36:22 +0000 |
parents | e53ed2d613a1 |
children | 3ea0ab04352b |
rev | line source |
---|---|
15 | 1 // This file (CreateAndAddUnitCommand.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard. |
2 // | |
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. | |
4 | |
0 | 5 using System; |
6 using IBBoard.Commands; | |
7 using IBBoard.Lang; | |
8 using IBBoard.WarFoundry.API.Objects; | |
9 | |
10 namespace IBBoard.WarFoundry.API.Commands | |
11 { | |
12 public class CreateAndAddUnitCommand : Command | |
13 { | |
14 private UnitType addedUnitType; | |
15 private Army army; | |
58
e53ed2d613a1
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
16 private Unit addedUnit; |
e53ed2d613a1
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
17 |
e53ed2d613a1
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
18 public CreateAndAddUnitCommand(UnitType toAdd, Army armyTo) |
e53ed2d613a1
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
19 { |
e53ed2d613a1
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
20 addedUnitType = toAdd; |
e53ed2d613a1
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
21 army = armyTo; |
e53ed2d613a1
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
22 } |
e53ed2d613a1
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
23 |
e53ed2d613a1
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
24 [Obsolete("Use two parameter constructor instead")] |
e53ed2d613a1
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
25 public CreateAndAddUnitCommand(UnitType toAdd, ArmyCategory catTo, Army armyTo) : this(toAdd, armyTo) |
0 | 26 { |
27 } | |
58
e53ed2d613a1
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
28 |
e53ed2d613a1
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
29 [Obsolete("Use two parameter constructor instead")] |
0 | 30 public CreateAndAddUnitCommand(UnitType toAdd, Category catTo, Army armyTo) : this (toAdd, armyTo.GetCategory(catTo), armyTo) |
31 { | |
32 } | |
33 | |
34 public override bool CanExecute() | |
35 { | |
36 return (addedUnitType!=null && army!=null); | |
37 } | |
38 | |
39 public override string Description | |
40 { | |
41 get { return "Add unit of "+StringManipulation.CutToLength(addedUnitType.Name, 20)+" to the army"; } | |
42 } | |
43 | |
44 public override string UndoDescription | |
45 { | |
46 get { return "Remove unit of "+StringManipulation.CutToLength(addedUnitType.Name, 20)+" from army"; } | |
47 } | |
48 | |
49 public override bool Execute() | |
50 { | |
51 addedUnit = new Unit(addedUnitType, army); | |
52 this.Redo(); | |
53 return true; | |
54 } | |
55 | |
56 public override void Redo() | |
57 { | |
58
e53ed2d613a1
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
58 army.AddUnit(addedUnit); |
0 | 59 } |
60 | |
61 public override void Undo() | |
62 { | |
58
e53ed2d613a1
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
63 army.RemoveUnit(addedUnit); |
0 | 64 } |
65 | |
66 | |
67 public override string Name | |
68 { | |
69 get { return "Add new unit"; } | |
70 } | |
71 } | |
72 } |