From 58c88a30786cdddef2406bee76d85b3812e0293d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Teuli=C3=A8re?= Date: Fri, 5 Oct 2012 00:01:18 +0200 Subject: [PATCH] Let the PlayerMoveCmd decide whether it is human independent. It fixes problems when trying to replay turns on a loaded game. --- game/duplicate.cpp | 3 --- game/freegame.cpp | 12 +++++------- game/freegame.h | 2 +- game/player_move_cmd.cpp | 1 + game/training.cpp | 1 - 5 files changed, 7 insertions(+), 12 deletions(-) diff --git a/game/duplicate.cpp b/game/duplicate.cpp index b567d66..926a480 100644 --- a/game/duplicate.cpp +++ b/game/duplicate.cpp @@ -221,7 +221,6 @@ void Duplicate::recordPlayerMove(Player &ioPlayer, const Move &iMove) if (cmd == 0) { Command *pCmd = new PlayerMoveCmd(ioPlayer, iMove, isArbitrationGame()); - pCmd->setHumanIndependent(!ioPlayer.isHuman()); accessNavigation().addAndExecute(pCmd); } else @@ -231,7 +230,6 @@ void Duplicate::recordPlayerMove(Player &ioPlayer, const Move &iMove) if (!isArbitrationGame() && !getNavigation().isLastTurn()) throw GameException("Cannot add a command to an old turn"); Command *pCmd = new PlayerMoveCmd(ioPlayer, iMove, isArbitrationGame()); - pCmd->setHumanIndependent(!ioPlayer.isHuman()); accessNavigation().replaceCommand(*cmd, pCmd); } } @@ -431,7 +429,6 @@ void Duplicate::setGameAndPlayersRack(const PlayedRack &iRack) BOOST_FOREACH(Player *player, m_players) { Command *pCmd = new PlayerMoveCmd(*player, Move(), true); - pCmd->setHumanIndependent(!player->isHuman()); accessNavigation().addAndExecute(pCmd); } } diff --git a/game/freegame.cpp b/game/freegame.cpp index da2d04a..4bd457a 100644 --- a/game/freegame.cpp +++ b/game/freegame.cpp @@ -71,7 +71,7 @@ int FreeGame::play(const wstring &iCoord, const wstring &iWord) Move move(round); // Update the rack and the score of the current player - recordPlayerMove(move, *m_players[m_currPlayer], true); + recordPlayerMove(move, *m_players[m_currPlayer]); } else { @@ -81,7 +81,7 @@ int FreeGame::play(const wstring &iCoord, const wstring &iWord) Move move(dispWord, iCoord); // Record the invalid move of the player - recordPlayerMove(move, *m_players[m_currPlayer], true); + recordPlayerMove(move, *m_players[m_currPlayer]); } // Next turn @@ -107,18 +107,16 @@ void FreeGame::playAI(unsigned int p) } // Update the rack and the score of the current player - recordPlayerMove(move, *player, false); + recordPlayerMove(move, *player); endTurn(); } -void FreeGame::recordPlayerMove(const Move &iMove, Player &ioPlayer, - bool isForHuman) +void FreeGame::recordPlayerMove(const Move &iMove, Player &ioPlayer) { LOG_INFO("Player " << ioPlayer.getId() << " plays: " << lfw(iMove.toString())); Command *pCmd = new PlayerMoveCmd(ioPlayer, iMove); - pCmd->setHumanIndependent(!isForHuman); accessNavigation().addAndExecute(pCmd); } @@ -312,7 +310,7 @@ int FreeGame::pass(const wstring &iToChange) Move move(iToChange); // End the player's turn - recordPlayerMove(move, player, true); + recordPlayerMove(move, player); // Next game turn endTurn(); diff --git a/game/freegame.h b/game/freegame.h index 4090d17..930bd0a 100644 --- a/game/freegame.h +++ b/game/freegame.h @@ -88,7 +88,7 @@ private: void playAI(unsigned int p); /// Record a player move - void recordPlayerMove(const Move &iMove, Player &ioPlayer, bool isForHuman); + void recordPlayerMove(const Move &iMove, Player &ioPlayer); /// Finish the current turn int endTurn(); diff --git a/game/player_move_cmd.cpp b/game/player_move_cmd.cpp index 185a882..4d09b0f 100644 --- a/game/player_move_cmd.cpp +++ b/game/player_move_cmd.cpp @@ -31,6 +31,7 @@ PlayerMoveCmd::PlayerMoveCmd(Player &ioPlayer, const Move &iMove, bool iAutoExec : m_player(ioPlayer), m_move(iMove) { setAutoExecutable(iAutoExec || iMove.isNull()); + setHumanIndependent(!ioPlayer.isHuman()); } diff --git a/game/training.cpp b/game/training.cpp index 7154c04..0f69305 100644 --- a/game/training.cpp +++ b/game/training.cpp @@ -123,7 +123,6 @@ void Training::recordPlayerMove(const Move &iMove, Player &ioPlayer) // (called in this class in endTurn()). // See the big comment in game.cpp, line 96 Command *pCmd = new PlayerMoveCmd(ioPlayer, iMove); - pCmd->setHumanIndependent(false); accessNavigation().addAndExecute(pCmd); }