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
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 (CreateAndAddUnitCommand.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
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using System;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using IBBoard.Commands;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using IBBoard.Lang;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 using IBBoard.WarFoundry.API.Objects;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 namespace IBBoard.WarFoundry.API.Commands
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 public class CreateAndAddUnitCommand : Command
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 private UnitType addedUnitType;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 public CreateAndAddUnitCommand(UnitType toAdd, Category catTo, Army armyTo) : this (toAdd, armyTo.GetCategory(catTo), armyTo)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 public override bool CanExecute()
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 return (addedUnitType!=null && army!=null);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 public override string Description
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 get { return "Add unit of "+StringManipulation.CutToLength(addedUnitType.Name, 20)+" to the army"; }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 public override string UndoDescription
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 get { return "Remove unit of "+StringManipulation.CutToLength(addedUnitType.Name, 20)+" from army"; }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 public override bool Execute()
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51 addedUnit = new Unit(addedUnitType, army);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
52 this.Redo();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53 return true;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56 public override void Redo()
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
60
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
61 public override void Undo()
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
67 public override string Name
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
68 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
69 get { return "Add new unit"; }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
70 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
71 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
72 }