Advanced Strategic Command
Public Types | Public Member Functions | Protected Member Functions | List of all members
Command Class Referenceabstract

A Command is an action that the player initiates. More...

#include <command.h>

Inheritance diagram for Command:
Inheritance graph

Public Types

enum  State {
  Planned, Evaluated, SetUp, Run,
  Finished, Failed

Public Member Functions

State getState () const
virtual ASCString getCommandString () const =0
ActionResult redo (const Context &context)
virtual vector< MapCoordinategetCoordinates () const
 this is for informational purposes, so the player can see where a Command has taken place when reviewing it More...
- Public Member Functions inherited from GameAction
ActionResult execute (const Context &context)
ActionResult undo (const Context &context)
void read (tnstream &stream)
void write (tnstream &stream) const
void write (tnstream &stream, bool persistChildren) const
virtual ASCString getDescription () const =0
virtual ~GameAction ()

Protected Member Functions

 Command (GameMap *gamemap)
void setState (State state)
virtual ActionResult go (const Context &context)=0
virtual ActionResult runAction (const Context &context)
virtual ActionResult undoAction (const Context &context)
virtual void readData (tnstream &stream)
virtual void writeData (tnstream &stream) const
virtual ActionResult checkExecutionPrecondition () const
- Protected Member Functions inherited from GameAction
void deleteChildren ()
 GameAction (GameMap *map)
void addChild (GameAction *action)
 adds a child action. Ownership of the child action is passed to THIS More...
virtual ActionResult preCheck ()
 preCheck is called before an action is redone and should check the preconditions for the action. More...
virtual ActionResult postCheck ()
 postCheck is called after an action has been redone and should check that the state of the map is exactly the same as it was after the action has been executed the first time. More...
virtual bool undoOrderChildFirst () const
 determines the order in which the child actions are undone. More...
virtual GameActionID getID () const =0
GameMapgetMap ()
const GameMapgetMap () const

Additional Inherited Members

- Static Public Member Functions inherited from GameAction
static GameActionreadFromStream (tnstream &stream, GameMap *map)

Detailed Description

A Command is an action that the player initiates.

It contains all the logic about when the command is available and which options it may be given. For example, the PutObjectCommand will provide all information which objects a unit may produce, and on which fields this is possible.

Unlike the atomic GameAction, a prepared but not yet executed Command can still be run in a changed environment compared to the time it was initially issued. It may, of course, report a failure if the intervening map modification has negative impacts on the command.

Once a Command is successfully completed, it adds itself automatically to the undo list of the current GameMap. By doing so, ownership of the Command object passes to the GameMap.

If a Command does NOT complete successfully, it must be manually disposed (auto_ptr is very useful to do that reliably).

Typcial usage pattern of a command is:

auto_ptr<DoSomethingCommand> command ( new DoSomethingCommand( subject ));
command->prepareCommand( whatEverInput );
ActionResult result = command->execute( context );
if ( result.successful() )
reportError ( res );
See Also

Definition at line 114 of file command.h.

Member Enumeration Documentation


the command is completed this turn, but there is still something to do next turn


the command is totally done


Definition at line 116 of file command.h.

Constructor & Destructor Documentation

Command::Command ( GameMap gamemap)

Definition at line 26 of file command.cpp.

Member Function Documentation

ActionResult Command::checkExecutionPrecondition ( ) const

Reimplemented in ServiceCommand, RepairUnitCommand, UnitCommand, and ContainerCommand.

Definition at line 82 of file command.cpp.

Referenced by runAction().

virtual ASCString Command::getCommandString ( ) const
pure virtual
vector< MapCoordinate > Command::getCoordinates ( ) const

this is for informational purposes, so the player can see where a Command has taken place when reviewing it

Reimplemented in MoveUnitCommand, and UnitCommand.

Definition at line 77 of file command.cpp.

Referenced by ActionWidget::getCoordinates(), and UnitCommand::getCoordinates().

State Command::getState ( ) const
virtual ActionResult Command::go ( const Context context)
protectedpure virtual
void Command::readData ( tnstream stream)
ActionResult Command::redo ( const Context context)

Definition at line 65 of file command.cpp.

References GameAction::deleteChildren(), Finished, getState(), go(), Run, setState(), and SetUp.

Referenced by trunreplay::execnextreplaymove().

ActionResult Command::runAction ( const Context context)

Implements GameAction.

Definition at line 50 of file command.cpp.

References checkExecutionPrecondition(), go(), and ActionResult::successful().

void Command::setState ( State  state)

Definition at line 44 of file command.cpp.

Referenced by DestructUnitCommand::DestructUnitCommand(), CancelResearchCommand::go(), DirectResearchCommand::go(), DiplomacyCommand::go(), TrainUnitCommand::go(), RecycleUnitCommand::go(), JumpDriveCommand::go(), InternalAmmoTransferCommand::go(), SetResourceProcessingRateCommand::go(), TransferControlCommand::go(), RemoveProductionLineCommand::go(), RenameContainerCommand::go(), ConstructUnitCommand::go(), BuildProductionLineCommand::go(), PutObjectCommand::go(), AttackCommand::go(), PutMineCommand::go(), MoveUnitCommand::go(), ServiceCommand::go(), DiplomacyCommand::newstate(), MoveUnitCommand::rearm(), redo(), RepairBuildingCommand::RepairBuildingCommand(), ServiceCommand::saveTransfers(), PutObjectCommand::searchFields(), PutMineCommand::searchFields(), MoveUnitCommand::searchFields(), AttackCommand::searchTargets(), PutMineCommand::setCreationTarget(), JumpDriveCommand::setDestination(), MoveUnitCommand::setDestination(), CargoMoveCommand::setMode(), RenameContainerCommand::setName(), ReactionFireSwitchCommand::setNewState(), PowerGenerationSwitchCommand::setNewState(), CancelResearchCommand::setPlayer(), BuildProductionLineCommand::setProduction(), TransferControlCommand::setReceiver(), RemoveProductionLineCommand::setRemoval(), PutMineCommand::setRemovalTarget(), SetResourceProcessingRateCommand::SetResourceProcessingRateCommand(), RepairUnitCommand::setTarget(), PutObjectCommand::setTarget(), AttackCommand::setTarget(), CargoMoveCommand::setTargetCarrier(), DestructBuildingCommand::setTargetPosition(), ConstructBuildingCommand::setTargetPosition(), ConstructUnitCommand::setTargetPosition(), DirectResearchCommand::setTechnology(), TrainUnitCommand::setUnit(), RecycleUnitCommand::setUnit(), ConstructUnitCommand::setVehicleType(), and DiplomacyCommand::sneakAttack().

ActionResult Command::undoAction ( const Context context)
void Command::writeData ( tnstream stream) const

The documentation for this class was generated from the following files: