Let the PlayerMoveCmd decide whether it is human independent.

It fixes problems when trying to replay turns on a loaded game.
This commit is contained in:
Olivier Teulière 2012-10-05 00:01:18 +02:00
parent 74d4572a0a
commit 58c88a3078
5 changed files with 7 additions and 12 deletions

View file

@ -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);
}
}

View file

@ -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();

View file

@ -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();

View file

@ -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());
}

View file

@ -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);
}