New "auto-executable" flag for commands, not yet used

This commit is contained in:
Olivier Teulière 2012-02-19 16:25:27 +01:00
parent de2d2777e2
commit e915e5f2cf
4 changed files with 15 additions and 1 deletions

View file

@ -26,7 +26,7 @@ INIT_LOGGER(game, Command);
Command::Command()
: m_executed(false), m_humanIndependent(true)
: m_executed(false), m_humanIndependent(true), m_autoExecutable(true)
{
}

View file

@ -61,6 +61,8 @@ class Command
* allowed to call undo()), false otherwise.
*/
bool isExecuted() const { return m_executed; }
/// Return true if the command is auto-executable
virtual bool isAutoExecutable() const { return m_autoExecutable; }
/**
* Mark the command as human independent, which means that it will
@ -82,9 +84,19 @@ class Command
virtual void doExecute() = 0;
virtual void doUndo() = 0;
/**
* Mark the command as auto-executable.
* When the commands history is set to a particular turn, all the
* auto-executable commands for this turn will be executed until
* the first non-auto-executable one (excluded).
* This allows replaying some actions (like setting the rack) at the beginning of a turn.
*/
void setAutoExecutable(bool autoExec) { m_autoExecutable = autoExec; }
private:
bool m_executed;
bool m_humanIndependent;
bool m_autoExecutable;
};
#endif

View file

@ -37,6 +37,7 @@ GameMoveCmd::GameMoveCmd(Game &ioGame, const Move &iMove,
m_moveRack(ioGame.getPlayer(iPlayerId).getHistory().getPreviousTurn().getPlayedRack()),
m_playerId(iPlayerId)
{
setAutoExecutable(false);
}

View file

@ -31,6 +31,7 @@ INIT_LOGGER(game, PlayerMoveCmd);
PlayerMoveCmd::PlayerMoveCmd(Player &ioPlayer, const Move &iMove)
: m_player(ioPlayer), m_move(iMove)
{
setAutoExecutable(false);
}