Advanced Strategic Command
|
A Command is an action that the player initiates. More...
#include <command.h>
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< MapCoordinate > | getCoordinates () const |
this is for informational purposes, so the player can see where a Command has taken place when reviewing it More... | |
![]() | |
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 |
![]() | |
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 |
GameMap * | getMap () |
const GameMap * | getMap () const |
Additional Inherited Members | |
![]() | |
static GameAction * | readFromStream (tnstream &stream, GameMap *map) |
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:
enum Command::State |
|
protected |
Definition at line 26 of file command.cpp.
|
protectedvirtual |
Reimplemented in ServiceCommand, RepairUnitCommand, UnitCommand, and ContainerCommand.
Definition at line 82 of file command.cpp.
Referenced by runAction().
|
pure virtual |
Implemented in MoveUnitCommand, ServiceCommand, DirectResearchCommand, PutMineCommand, AttackCommand, PutObjectCommand, BuildProductionLineCommand, DiplomacyCommand, ConstructUnitCommand, DestructBuildingCommand, RemoveProductionLineCommand, RenameContainerCommand, ConstructBuildingCommand, RepairBuildingCommand, SetResourceProcessingRateCommand, TransferControlCommand, InternalAmmoTransferCommand, RepairUnitCommand, JumpDriveCommand, RecycleUnitCommand, CancelResearchCommand, CargoMoveCommand, TrainUnitCommand, PowerGenerationSwitchCommand, ReactionFireSwitchCommand, and DestructUnitCommand.
|
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 ActionWidget::getCoordinates(), and UnitCommand::getCoordinates().
|
inline |
Definition at line 125 of file command.h.
Referenced by GuiFunctions::RefuelUnitDialogCommand::execute(), CancelResearchCommand::go(), DestructUnitCommand::go(), DirectResearchCommand::go(), PowerGenerationSwitchCommand::go(), ReactionFireSwitchCommand::go(), CargoMoveCommand::go(), DiplomacyCommand::go(), TrainUnitCommand::go(), RecycleUnitCommand::go(), JumpDriveCommand::go(), RepairUnitCommand::go(), InternalAmmoTransferCommand::go(), TransferControlCommand::go(), SetResourceProcessingRateCommand::go(), ConstructBuildingCommand::go(), RepairBuildingCommand::go(), DestructBuildingCommand::go(), RenameContainerCommand::go(), RemoveProductionLineCommand::go(), ConstructUnitCommand::go(), BuildProductionLineCommand::go(), PutObjectCommand::go(), AttackCommand::go(), PutMineCommand::go(), MoveUnitCommand::go(), ServiceCommand::go(), MoveUnitCommand::rearm(), redo(), MoveUnitCommand::setDestination(), CancelResearchCommand::undoAction(), and DirectResearchCommand::undoAction().
|
protectedpure virtual |
Implemented in ServiceCommand, MoveUnitCommand, PutMineCommand, AttackCommand, PutObjectCommand, BuildProductionLineCommand, ConstructUnitCommand, DestructBuildingCommand, RemoveProductionLineCommand, RenameContainerCommand, ConstructBuildingCommand, RepairBuildingCommand, SetResourceProcessingRateCommand, TransferControlCommand, InternalAmmoTransferCommand, RepairUnitCommand, JumpDriveCommand, RecycleUnitCommand, CargoMoveCommand, DiplomacyCommand, TrainUnitCommand, PowerGenerationSwitchCommand, ReactionFireSwitchCommand, DestructUnitCommand, DirectResearchCommand, and CancelResearchCommand.
Referenced by redo(), and runAction().
|
protectedvirtual |
Implements GameAction.
Reimplemented in MoveUnitCommand, PutMineCommand, AttackCommand, DiplomacyCommand, ServiceCommand, PutObjectCommand, ConstructUnitCommand, DirectResearchCommand, DestructBuildingCommand, ConstructBuildingCommand, RepairUnitCommand, RenameContainerCommand, BuildProductionLineCommand, InternalAmmoTransferCommand, TransferControlCommand, RemoveProductionLineCommand, SetResourceProcessingRateCommand, JumpDriveCommand, RecycleUnitCommand, CancelResearchCommand, TrainUnitCommand, CargoMoveCommand, PowerGenerationSwitchCommand, ReactionFireSwitchCommand, RepairBuildingCommand, UnitCommand, DestructUnitCommand, and ContainerCommand.
Definition at line 31 of file command.cpp.
References tnstream::readInt().
Referenced by ContainerCommand::readData(), UnitCommand::readData(), CancelResearchCommand::readData(), DirectResearchCommand::readData(), and DiplomacyCommand::readData().
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().
|
protectedvirtual |
Implements GameAction.
Definition at line 50 of file command.cpp.
References checkExecutionPrecondition(), go(), and ActionResult::successful().
|
protected |
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().
|
protectedvirtual |
Implements GameAction.
Reimplemented in DirectResearchCommand, DiplomacyCommand, RenameContainerCommand, BuildProductionLineCommand, RemoveProductionLineCommand, SetResourceProcessingRateCommand, and CancelResearchCommand.
Definition at line 60 of file command.cpp.
Referenced by CancelResearchCommand::undoAction(), RemoveProductionLineCommand::undoAction(), SetResourceProcessingRateCommand::undoAction(), BuildProductionLineCommand::undoAction(), RenameContainerCommand::undoAction(), DiplomacyCommand::undoAction(), and DirectResearchCommand::undoAction().
|
protectedvirtual |
Implements GameAction.
Reimplemented in MoveUnitCommand, PutMineCommand, AttackCommand, DiplomacyCommand, ServiceCommand, PutObjectCommand, ConstructUnitCommand, DirectResearchCommand, DestructBuildingCommand, ConstructBuildingCommand, RepairUnitCommand, RenameContainerCommand, BuildProductionLineCommand, InternalAmmoTransferCommand, TransferControlCommand, RemoveProductionLineCommand, SetResourceProcessingRateCommand, JumpDriveCommand, RecycleUnitCommand, CancelResearchCommand, TrainUnitCommand, CargoMoveCommand, PowerGenerationSwitchCommand, ReactionFireSwitchCommand, RepairBuildingCommand, UnitCommand, DestructUnitCommand, and ContainerCommand.
Definition at line 38 of file command.cpp.
References tnstream::writeInt().
Referenced by ContainerCommand::writeData(), UnitCommand::writeData(), CancelResearchCommand::writeData(), DirectResearchCommand::writeData(), and DiplomacyCommand::writeData().