Command Class Reference

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

#include <command.h>

Inheritance diagram for Command:

Inheritance graph
[legend]
List of all members.

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

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

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() )
         command.release();
      else 
         reportError ( res ); 

See also:
GameAction

Definition at line 114 of file command.h.


Member Enumeration Documentation

enum Command::State

Enumerator:
Planned 
Evaluated 
SetUp 
Run  the command is completed this turn, but there is still something to do next turn
Finished  the command is totally done
Failed 

Definition at line 116 of file command.h.


Constructor & Destructor Documentation

Command::Command ( GameMap gamemap  )  [protected]

Definition at line 26 of file command.cpp.


Member Function Documentation

State Command::getState (  )  const [inline]

Definition at line 125 of file command.h.

Referenced by GuiFunctions::RefuelUnitDialogCommand::execute(), TransferControlCommand::go(), TrainUnitCommand::go(), SetResourceProcessingRateCommand::go(), ServiceCommand::go(), RepairUnitCommand::go(), RepairBuildingCommand::go(), RenameContainerCommand::go(), RemoveProductionLineCommand::go(), RecycleUnitCommand::go(), ReactionFireSwitchCommand::go(), PutObjectCommand::go(), PutMineCommand::go(), PowerGenerationSwitchCommand::go(), MoveUnitCommand::go(), JumpDriveCommand::go(), InternalAmmoTransferCommand::go(), DirectResearchCommand::go(), DiplomacyCommand::go(), DestructUnitCommand::go(), DestructBuildingCommand::go(), ConstructUnitCommand::go(), ConstructBuildingCommand::go(), CargoMoveCommand::go(), CancelResearchCommand::go(), BuildProductionLineCommand::go(), AttackCommand::go(), MoveUnitCommand::rearm(), redo(), MoveUnitCommand::setDestination(), DirectResearchCommand::undoAction(), and CancelResearchCommand::undoAction().

virtual ASCString Command::getCommandString (  )  const [pure virtual]

Implemented in AttackCommand, BuildProductionLineCommand, CancelResearchCommand, CargoMoveCommand, ConstructBuildingCommand, ConstructUnitCommand, DestructBuildingCommand, DestructUnitCommand, DiplomacyCommand, DirectResearchCommand, InternalAmmoTransferCommand, JumpDriveCommand, MoveUnitCommand, PowerGenerationSwitchCommand, PutMineCommand, PutObjectCommand, ReactionFireSwitchCommand, RecycleUnitCommand, RemoveProductionLineCommand, RenameContainerCommand, RepairBuildingCommand, RepairUnitCommand, ServiceCommand, SetResourceProcessingRateCommand, TrainUnitCommand, and TransferControlCommand.

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().

vector< MapCoordinate > Command::getCoordinates (  )  const [virtual]

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 UnitCommand::getCoordinates(), and ActionWidget::getCoordinates().

void Command::setState ( State  state  )  [protected]

Definition at line 44 of file command.cpp.

Referenced by DestructUnitCommand::DestructUnitCommand(), TransferControlCommand::go(), TrainUnitCommand::go(), SetResourceProcessingRateCommand::go(), ServiceCommand::go(), RenameContainerCommand::go(), RemoveProductionLineCommand::go(), RecycleUnitCommand::go(), PutObjectCommand::go(), PutMineCommand::go(), MoveUnitCommand::go(), JumpDriveCommand::go(), DirectResearchCommand::go(), DiplomacyCommand::go(), ConstructUnitCommand::go(), CancelResearchCommand::go(), BuildProductionLineCommand::go(), AttackCommand::go(), DiplomacyCommand::newstate(), MoveUnitCommand::rearm(), redo(), RepairBuildingCommand::RepairBuildingCommand(), ServiceCommand::saveTransfers(), PutObjectCommand::searchFields(), PutMineCommand::searchFields(), MoveUnitCommand::searchFields(), PutMineCommand::setCreationTarget(), MoveUnitCommand::setDestination(), JumpDriveCommand::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(), ConstructUnitCommand::setTargetPosition(), ConstructBuildingCommand::setTargetPosition(), DirectResearchCommand::setTechnology(), TrainUnitCommand::setUnit(), RecycleUnitCommand::setUnit(), ConstructUnitCommand::setVehicleType(), and DiplomacyCommand::sneakAttack().

virtual ActionResult Command::go ( const Context context  )  [protected, pure virtual]

Implemented in AttackCommand, BuildProductionLineCommand, CancelResearchCommand, CargoMoveCommand, ConstructBuildingCommand, ConstructUnitCommand, DestructBuildingCommand, DestructUnitCommand, DiplomacyCommand, DirectResearchCommand, InternalAmmoTransferCommand, JumpDriveCommand, MoveUnitCommand, PowerGenerationSwitchCommand, PutMineCommand, PutObjectCommand, ReactionFireSwitchCommand, RecycleUnitCommand, RemoveProductionLineCommand, RenameContainerCommand, RepairBuildingCommand, RepairUnitCommand, ServiceCommand, SetResourceProcessingRateCommand, TrainUnitCommand, and TransferControlCommand.

Referenced by redo(), and runAction().

ActionResult Command::runAction ( const Context context  )  [protected, virtual]

Implements GameAction.

Definition at line 50 of file command.cpp.

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

ActionResult Command::undoAction ( const Context context  )  [protected, virtual]

Implements GameAction.

Reimplemented in BuildProductionLineCommand, CancelResearchCommand, DiplomacyCommand, DirectResearchCommand, RemoveProductionLineCommand, RenameContainerCommand, and SetResourceProcessingRateCommand.

Definition at line 60 of file command.cpp.

Referenced by SetResourceProcessingRateCommand::undoAction(), RenameContainerCommand::undoAction(), RemoveProductionLineCommand::undoAction(), DirectResearchCommand::undoAction(), DiplomacyCommand::undoAction(), CancelResearchCommand::undoAction(), and BuildProductionLineCommand::undoAction().

void Command::readData ( tnstream stream  )  [protected, virtual]

Implements GameAction.

Reimplemented in AttackCommand, BuildProductionLineCommand, CancelResearchCommand, CargoMoveCommand, ConstructBuildingCommand, ConstructUnitCommand, ContainerCommand, DestructBuildingCommand, DestructUnitCommand, DiplomacyCommand, DirectResearchCommand, InternalAmmoTransferCommand, JumpDriveCommand, MoveUnitCommand, PowerGenerationSwitchCommand, PutMineCommand, PutObjectCommand, ReactionFireSwitchCommand, RecycleUnitCommand, RemoveProductionLineCommand, RenameContainerCommand, RepairBuildingCommand, RepairUnitCommand, ServiceCommand, SetResourceProcessingRateCommand, TrainUnitCommand, TransferControlCommand, and UnitCommand.

Definition at line 31 of file command.cpp.

References tnstream::readInt().

Referenced by UnitCommand::readData(), DirectResearchCommand::readData(), DiplomacyCommand::readData(), ContainerCommand::readData(), and CancelResearchCommand::readData().

void Command::writeData ( tnstream stream  )  const [protected, virtual]

Implements GameAction.

Reimplemented in AttackCommand, BuildProductionLineCommand, CancelResearchCommand, CargoMoveCommand, ConstructBuildingCommand, ConstructUnitCommand, ContainerCommand, DestructBuildingCommand, DestructUnitCommand, DiplomacyCommand, DirectResearchCommand, InternalAmmoTransferCommand, JumpDriveCommand, MoveUnitCommand, PowerGenerationSwitchCommand, PutMineCommand, PutObjectCommand, ReactionFireSwitchCommand, RecycleUnitCommand, RemoveProductionLineCommand, RenameContainerCommand, RepairBuildingCommand, RepairUnitCommand, ServiceCommand, SetResourceProcessingRateCommand, TrainUnitCommand, TransferControlCommand, and UnitCommand.

Definition at line 38 of file command.cpp.

References tnstream::writeInt().

Referenced by UnitCommand::writeData(), DirectResearchCommand::writeData(), DiplomacyCommand::writeData(), ContainerCommand::writeData(), and CancelResearchCommand::writeData().

ActionResult Command::checkExecutionPrecondition (  )  const [protected, virtual]

Reimplemented in ContainerCommand, RepairUnitCommand, ServiceCommand, and UnitCommand.

Definition at line 82 of file command.cpp.

Referenced by runAction().


The documentation for this class was generated from the following files:
Generated on Mon Jan 30 01:43:40 2012 for Advanced Strategic Command by  doxygen 1.5.1