mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2024-12-25 21:59:30 +01:00
TurnData: remove the m_playerId member
This commit is contained in:
parent
7f3f29df31
commit
cdcb5c25b7
13 changed files with 18 additions and 36 deletions
|
@ -21,7 +21,6 @@
|
|||
#include <sstream>
|
||||
|
||||
#include "cmd/game_move_cmd.h"
|
||||
#include "player.h"
|
||||
#include "game_params.h"
|
||||
#include "game.h"
|
||||
#include "rack.h"
|
||||
|
@ -31,11 +30,9 @@
|
|||
INIT_LOGGER(game, GameMoveCmd);
|
||||
|
||||
|
||||
GameMoveCmd::GameMoveCmd(Game &ioGame, const Move &iMove,
|
||||
unsigned int iPlayerId)
|
||||
GameMoveCmd::GameMoveCmd(Game &ioGame, const Move &iMove)
|
||||
: m_game(ioGame), m_move(iMove),
|
||||
m_moveRack(ioGame.getHistory().getCurrentRack()),
|
||||
m_playerId(iPlayerId)
|
||||
m_moveRack(ioGame.getHistory().getCurrentRack())
|
||||
{
|
||||
setAutoExecutable(false);
|
||||
}
|
||||
|
@ -48,7 +45,7 @@ void GameMoveCmd::doExecute()
|
|||
|
||||
// History of the game
|
||||
History &history = m_game.accessHistory();
|
||||
history.playMove(m_playerId, m_move, newRack);
|
||||
history.playMove(m_move, newRack);
|
||||
|
||||
// Points
|
||||
m_game.addPoints(m_move.getScore());
|
||||
|
|
|
@ -46,14 +46,12 @@ class GameMoveCmd: public Command
|
|||
DEFINE_LOGGER();
|
||||
|
||||
public:
|
||||
GameMoveCmd(Game &ioGame, const Move &iMove,
|
||||
unsigned int iPlayerId);
|
||||
GameMoveCmd(Game &ioGame, const Move &iMove);
|
||||
|
||||
virtual wstring toString() const;
|
||||
|
||||
// Getters
|
||||
const Move & getMove() const { return m_move; }
|
||||
unsigned int getPlayerId() const { return m_playerId; }
|
||||
|
||||
protected:
|
||||
virtual void doExecute();
|
||||
|
@ -64,7 +62,6 @@ class GameMoveCmd: public Command
|
|||
Move m_move;
|
||||
Round m_round;
|
||||
PlayedRack m_moveRack;
|
||||
unsigned int m_playerId;
|
||||
|
||||
void playRound();
|
||||
void unplayRound();
|
||||
|
|
|
@ -44,7 +44,7 @@ void PlayerMoveCmd::doExecute()
|
|||
const PlayedRack &newRack = Move::ComputeRackForMove(m_originalRack, m_move);
|
||||
|
||||
// Update the history and rack of the player
|
||||
m_player.accessHistory().playMove(m_player.getId(), m_move, newRack);
|
||||
m_player.accessHistory().playMove(m_move, newRack);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -311,7 +311,7 @@ void Duplicate::endTurn()
|
|||
// Play the master word on the board
|
||||
// We assign it to player 0 arbitrarily (this is only used
|
||||
// to retrieve the rack, which is the same for all players...)
|
||||
Command *pCmd = new GameMoveCmd(*this, m_masterMove, REF_PLAYER_ID);
|
||||
Command *pCmd = new GameMoveCmd(*this, m_masterMove);
|
||||
accessNavigation().addAndExecute(pCmd);
|
||||
|
||||
// Change the turn after doing all the game changes.
|
||||
|
|
|
@ -153,7 +153,7 @@ int FreeGame::endTurn()
|
|||
|
||||
const Move &move = getCurrentPlayer().getLastMove();
|
||||
// Update the game
|
||||
Command *pCmd = new GameMoveCmd(*this, move, m_currPlayer);
|
||||
Command *pCmd = new GameMoveCmd(*this, move);
|
||||
accessNavigation().addAndExecute(pCmd);
|
||||
|
||||
// Complete the rack for the player that just played
|
||||
|
|
|
@ -96,14 +96,12 @@ bool History::beforeFirstRound() const
|
|||
}
|
||||
|
||||
|
||||
void History::playMove(unsigned int iPlayer,
|
||||
const Move &iMove,
|
||||
void History::playMove(const Move &iMove,
|
||||
const PlayedRack &iNewRack)
|
||||
{
|
||||
TurnData * current_turn = m_history.back();
|
||||
|
||||
// Set the number and the round
|
||||
current_turn->setPlayer(iPlayer);
|
||||
current_turn->setMove(iMove);
|
||||
|
||||
// Create a new turn
|
||||
|
@ -125,11 +123,10 @@ void History::removeLastTurn()
|
|||
delete t;
|
||||
}
|
||||
|
||||
#ifdef BACK_REMOVE_RACK_NEW_PART
|
||||
// Now we have the previous played round in back()
|
||||
TurnData *t = m_history.back();
|
||||
t->setPlayer(0);
|
||||
//t->setRound(Round());
|
||||
#ifdef BACK_REMOVE_RACK_NEW_PART
|
||||
t->getPlayedRound().setNew(Rack());
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -83,8 +83,7 @@ public:
|
|||
bool beforeFirstRound() const;
|
||||
|
||||
/// Update the history with the given move and complete the turn.
|
||||
void playMove(unsigned int player, const Move &iMove,
|
||||
const PlayedRack &iNewRack);
|
||||
void playMove(const Move &iMove, const PlayedRack &iNewRack);
|
||||
|
||||
/// Remove last turn
|
||||
void removeLastTurn();
|
||||
|
|
|
@ -180,7 +180,7 @@ void Topping::endTurn()
|
|||
{
|
||||
// Play the top move on the board
|
||||
const Move &move = getTopMove();
|
||||
Command *pCmd = new GameMoveCmd(*this, move, m_currPlayer);
|
||||
Command *pCmd = new GameMoveCmd(*this, move);
|
||||
accessNavigation().addAndExecute(pCmd);
|
||||
accessNavigation().newTurn();
|
||||
|
||||
|
|
|
@ -145,7 +145,7 @@ void Training::endTurn()
|
|||
move = getMoveFromMasterGame();
|
||||
else
|
||||
move = m_players[m_currPlayer]->getLastMove();
|
||||
Command *pCmd = new GameMoveCmd(*this, move, m_currPlayer);
|
||||
Command *pCmd = new GameMoveCmd(*this, move);
|
||||
accessNavigation().addAndExecute(pCmd);
|
||||
accessNavigation().newTurn();
|
||||
}
|
||||
|
|
|
@ -30,15 +30,13 @@ INIT_LOGGER(game, TurnData);
|
|||
// FIXME: move set to an arbitrary one (no move). It would be better to get rid of this
|
||||
// constructor completely
|
||||
TurnData::TurnData()
|
||||
: m_playerId(0), m_warningsNb(0),
|
||||
m_penaltyPoints(0), m_soloPoints(0), m_endGamePoints(0)
|
||||
: m_warningsNb(0), m_penaltyPoints(0), m_soloPoints(0), m_endGamePoints(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TurnData::TurnData(unsigned int iPlayerId, const PlayedRack& iPldRack,
|
||||
const Move& iMove)
|
||||
: m_playerId(iPlayerId), m_pldrack(iPldRack), m_move(iMove),
|
||||
TurnData::TurnData(const PlayedRack& iPldRack, const Move& iMove)
|
||||
: m_pldrack(iPldRack), m_move(iMove),
|
||||
m_warningsNb(0), m_penaltyPoints(0), m_soloPoints(0), m_endGamePoints(0)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -42,10 +42,8 @@ class TurnData
|
|||
DEFINE_LOGGER();
|
||||
public:
|
||||
TurnData();
|
||||
TurnData(unsigned int iPlayerId,
|
||||
const PlayedRack& iPldRack, const Move& iMove);
|
||||
TurnData(const PlayedRack& iPldRack, const Move& iMove);
|
||||
|
||||
void setPlayer(unsigned int iPlayerId) { m_playerId = iPlayerId; }
|
||||
void setPlayedRack(const PlayedRack& iPldRack) { m_pldrack = iPldRack; }
|
||||
void setMove(const Move& iMove) { m_move = iMove; }
|
||||
// Setters for events (warnings, penalties, solos, end game primes)
|
||||
|
@ -54,7 +52,6 @@ public:
|
|||
void addSoloPoints(int iPoints) { m_soloPoints += iPoints; }
|
||||
void addEndGamePoints(int iPoints) { m_endGamePoints += iPoints; }
|
||||
|
||||
unsigned int getPlayer() const { return m_playerId; }
|
||||
const PlayedRack& getPlayedRack() const { return m_pldrack; }
|
||||
const Move& getMove() const { return m_move; }
|
||||
// Getters for events (warnings, penalties, solos, end game primes)
|
||||
|
@ -66,7 +63,6 @@ public:
|
|||
wstring toString() const;
|
||||
|
||||
private:
|
||||
unsigned int m_playerId;
|
||||
PlayedRack m_pldrack;
|
||||
Move m_move;
|
||||
int m_warningsNb;
|
||||
|
|
|
@ -412,8 +412,7 @@ void XmlReader::endElement(const string& namespaceURI,
|
|||
else if (tag == "GameMove")
|
||||
{
|
||||
const Move &move = buildMove(*m_game, m_attributes, false);
|
||||
Player &p = getPlayer(m_players, m_attributes["playerId"], tag);
|
||||
GameMoveCmd *cmd = new GameMoveCmd(*m_game, move, p.getId());
|
||||
GameMoveCmd *cmd = new GameMoveCmd(*m_game, move);
|
||||
m_game->accessNavigation().addAndExecute(cmd);
|
||||
}
|
||||
|
||||
|
|
|
@ -251,9 +251,8 @@ void XmlWriter::write(const Game &iGame, const string &iFileName)
|
|||
else if (dynamic_cast<const GameMoveCmd*>(cmd))
|
||||
{
|
||||
const GameMoveCmd *moveCmd = static_cast<const GameMoveCmd*>(cmd);
|
||||
unsigned int id = moveCmd->getPlayerId();
|
||||
out << indent;
|
||||
writeMove(out, moveCmd->getMove(), "GameMove", id);
|
||||
writeMove(out, moveCmd->getMove(), "GameMove", -1);
|
||||
out << endl;
|
||||
}
|
||||
else if (dynamic_cast<const MasterMoveCmd*>(cmd))
|
||||
|
|
Loading…
Reference in a new issue