diff --git a/game/command.cpp b/game/command.cpp index 8386143..80eea3e 100644 --- a/game/command.cpp +++ b/game/command.cpp @@ -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) { } diff --git a/game/command.h b/game/command.h index 336dcd2..226fcaa 100644 --- a/game/command.h +++ b/game/command.h @@ -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 diff --git a/game/game_move_cmd.cpp b/game/game_move_cmd.cpp index ea54cde..c61ea98 100644 --- a/game/game_move_cmd.cpp +++ b/game/game_move_cmd.cpp @@ -37,6 +37,7 @@ GameMoveCmd::GameMoveCmd(Game &ioGame, const Move &iMove, m_moveRack(ioGame.getPlayer(iPlayerId).getHistory().getPreviousTurn().getPlayedRack()), m_playerId(iPlayerId) { + setAutoExecutable(false); } diff --git a/game/player_move_cmd.cpp b/game/player_move_cmd.cpp index 0f483fa..56ddd9c 100644 --- a/game/player_move_cmd.cpp +++ b/game/player_move_cmd.cpp @@ -31,6 +31,7 @@ INIT_LOGGER(game, PlayerMoveCmd); PlayerMoveCmd::PlayerMoveCmd(Player &ioPlayer, const Move &iMove) : m_player(ioPlayer), m_move(iMove) { + setAutoExecutable(false); }