Tools - random number function is now static. Fixed player number issue with network games (GUI player number needs to be 0), this still requires some work.
This commit is contained in:
@@ -73,6 +73,8 @@ protected:
|
||||
void SetGameData(const GameData &gameData);
|
||||
const StartData &GetStartData() const;
|
||||
void SetStartData(const StartData &startData);
|
||||
int GetGuiPlayerNum() const;
|
||||
void SetGuiPlayerNum(int guiPlayerNum);
|
||||
|
||||
boost::shared_ptr<Game> GetGame();
|
||||
|
||||
@@ -80,7 +82,7 @@ protected:
|
||||
|
||||
void AddPlayerData(boost::shared_ptr<PlayerData> playerData);
|
||||
void RemovePlayerData(unsigned playerId);
|
||||
const PlayerDataList &GetPlayerDataList() const;
|
||||
PlayerDataList GetMappedPlayerDataList() const;
|
||||
|
||||
private:
|
||||
|
||||
@@ -99,6 +101,7 @@ private:
|
||||
boost::shared_ptr<Game> m_game;
|
||||
|
||||
unsigned m_curGameId;
|
||||
int m_guiPlayerNum;
|
||||
|
||||
friend class ClientStateInit;
|
||||
friend class ClientStateStartResolve;
|
||||
|
||||
@@ -391,10 +391,11 @@ ClientStateWaitSession::Process(ClientThread &client)
|
||||
NetPacketJoinGameAck::Data joinGameAckData;
|
||||
tmpPacket->ToNetPacketJoinGameAck()->GetData(joinGameAckData);
|
||||
client.SetGameData(joinGameAckData.gameData);
|
||||
client.SetGuiPlayerNum(joinGameAckData.yourPlayerNum);
|
||||
|
||||
// TODO: Type Human is fixed here.
|
||||
boost::shared_ptr<PlayerData> playerData(
|
||||
new PlayerData(joinGameAckData.gameData.guiPlayerUniqueId, joinGameAckData.gameData.guiPlayerNum, PLAYER_TYPE_HUMAN));
|
||||
new PlayerData(joinGameAckData.yourPlayerUniqueId, joinGameAckData.yourPlayerNum, PLAYER_TYPE_HUMAN));
|
||||
playerData->SetName(context.GetPlayerName());
|
||||
client.AddPlayerData(playerData);
|
||||
|
||||
@@ -512,7 +513,9 @@ ClientStateWaitHand::Process(ClientThread &client)
|
||||
int myCards[2];
|
||||
myCards[0] = (int)tmpData.yourCards[0];
|
||||
myCards[1] = (int)tmpData.yourCards[1];
|
||||
client.GetGame()->getPlayerArray()[client.GetGame()->getGuiPlayerNum()]->setMyCards(myCards);
|
||||
client.GetGame()->getPlayerArray()[0]->setMyCards(myCards);
|
||||
client.GetGame()->initHand();
|
||||
client.GetGame()->startHand();
|
||||
client.GetGui().dealHoleCards();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ private:
|
||||
|
||||
|
||||
ClientThread::ClientThread(GuiInterface &gui)
|
||||
: m_curState(NULL), m_gui(gui), m_curGameId(0)
|
||||
: m_curState(NULL), m_gui(gui), m_curGameId(0), m_guiPlayerNum(0)
|
||||
{
|
||||
m_context.reset(new ClientContext);
|
||||
m_senderCallback.reset(new ClientSenderCallback(*this));
|
||||
@@ -118,7 +118,7 @@ ClientThread::Main()
|
||||
// EngineFactory erstellen
|
||||
boost::shared_ptr<EngineFactory> factory(new ClientEngineFactory); // LocalEngine erstellen
|
||||
|
||||
m_game.reset(new Game(&m_gui, factory, GetPlayerDataList(), GetGameData(), GetStartData(), m_curGameId++));
|
||||
m_game.reset(new Game(&m_gui, factory, GetMappedPlayerDataList(), GetGameData(), GetStartData(), m_curGameId++));
|
||||
GetCallback().SignalNetClientGameStart(m_game);
|
||||
}
|
||||
}
|
||||
@@ -196,6 +196,18 @@ ClientThread::SetStartData(const StartData &startData)
|
||||
m_startData = startData;
|
||||
}
|
||||
|
||||
int
|
||||
ClientThread::GetGuiPlayerNum() const
|
||||
{
|
||||
return m_guiPlayerNum;
|
||||
}
|
||||
|
||||
void
|
||||
ClientThread::SetGuiPlayerNum(int guiPlayerNum)
|
||||
{
|
||||
m_guiPlayerNum = guiPlayerNum;
|
||||
}
|
||||
|
||||
boost::shared_ptr<Game>
|
||||
ClientThread::GetGame()
|
||||
{
|
||||
@@ -215,9 +227,6 @@ ClientThread::AddPlayerData(boost::shared_ptr<PlayerData> playerData)
|
||||
if (playerData.get() && !playerData->GetName().empty())
|
||||
{
|
||||
m_playerDataList.push_back(playerData);
|
||||
// Sort the list by player number.
|
||||
m_playerDataList.sort(*boost::lambda::_1 < *boost::lambda::_2);
|
||||
|
||||
GetCallback().SignalNetClientPlayerJoined(playerData->GetName());
|
||||
}
|
||||
}
|
||||
@@ -244,9 +253,31 @@ ClientThread::RemovePlayerData(unsigned playerId)
|
||||
GetCallback().SignalNetClientPlayerLeft(playerName);
|
||||
}
|
||||
|
||||
const PlayerDataList &
|
||||
ClientThread::GetPlayerDataList() const
|
||||
PlayerDataList
|
||||
ClientThread::GetMappedPlayerDataList() const
|
||||
{
|
||||
return m_playerDataList;
|
||||
PlayerDataList mappedList;
|
||||
|
||||
PlayerDataList::const_iterator i = m_playerDataList.begin();
|
||||
PlayerDataList::const_iterator end = m_playerDataList.end();
|
||||
|
||||
// Create a copy of the player list so that the GUI player
|
||||
// is player 0. This is mapped because the GUI depends on it.
|
||||
while (i != end)
|
||||
{
|
||||
boost::shared_ptr<PlayerData> tmpData(new PlayerData(*(*i)));
|
||||
int numberDiff = tmpData->GetNumber() - GetGuiPlayerNum();
|
||||
if (numberDiff >= 0)
|
||||
tmpData->SetNumber(numberDiff);
|
||||
else
|
||||
tmpData->SetNumber(GetGameData().numberOfPlayers + numberDiff);
|
||||
mappedList.push_back(tmpData);
|
||||
++i;
|
||||
}
|
||||
|
||||
// Sort the list by player number.
|
||||
mappedList.sort(*boost::lambda::_1 < *boost::lambda::_2);
|
||||
|
||||
return mappedList;
|
||||
}
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ struct NetPacketPlayerLeftData
|
||||
struct NetPacketGameStartData
|
||||
{
|
||||
NetPacketHeader head;
|
||||
u_int16_t startDealerPos;
|
||||
u_int16_t startDealerPlayerId;
|
||||
u_int16_t reserved;
|
||||
};
|
||||
|
||||
@@ -528,13 +528,13 @@ NetPacketJoinGameAck::SetData(const NetPacketJoinGameAck::Data &inData)
|
||||
assert(tmpData);
|
||||
|
||||
tmpData->sessionId = htonl(inData.sessionId);
|
||||
tmpData->playerId = htons(inData.yourPlayerUniqueId);
|
||||
tmpData->playerNumber = htons(inData.yourPlayerNum);
|
||||
tmpData->numberOfPlayers = htons(inData.gameData.numberOfPlayers);
|
||||
tmpData->smallBlind = htons(inData.gameData.smallBlind);
|
||||
tmpData->handsBeforeRaise = htons(inData.gameData.handsBeforeRaise);
|
||||
tmpData->proposedGuiSpeed = htons(inData.gameData.guiSpeed);
|
||||
tmpData->startCash = htonl(inData.gameData.startCash);
|
||||
tmpData->playerId = htons(inData.gameData.guiPlayerUniqueId);
|
||||
tmpData->playerNumber = htons(inData.gameData.guiPlayerNum);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -544,13 +544,13 @@ NetPacketJoinGameAck::GetData(NetPacketJoinGameAck::Data &outData) const
|
||||
assert(tmpData);
|
||||
|
||||
outData.sessionId = ntohl(tmpData->sessionId);
|
||||
outData.yourPlayerUniqueId = ntohs(tmpData->playerId);
|
||||
outData.yourPlayerNum = ntohs(tmpData->playerNumber);
|
||||
outData.gameData.numberOfPlayers = ntohs(tmpData->numberOfPlayers);
|
||||
outData.gameData.smallBlind = ntohs(tmpData->smallBlind);
|
||||
outData.gameData.handsBeforeRaise = ntohs(tmpData->handsBeforeRaise);
|
||||
outData.gameData.guiSpeed = ntohs(tmpData->proposedGuiSpeed);
|
||||
outData.gameData.startCash = ntohl(tmpData->startCash);
|
||||
outData.gameData.guiPlayerUniqueId = ntohs(tmpData->playerId);
|
||||
outData.gameData.guiPlayerNum = ntohs(tmpData->playerNumber);
|
||||
}
|
||||
|
||||
const NetPacketJoinGameAck *
|
||||
@@ -761,7 +761,7 @@ NetPacketGameStart::SetData(const NetPacketGameStart::Data &inData)
|
||||
NetPacketGameStartData *tmpData = (NetPacketGameStartData *)GetRawData();
|
||||
assert(tmpData);
|
||||
|
||||
tmpData->startDealerPos = htons(inData.startData.startDealerPos);
|
||||
tmpData->startDealerPlayerId = htons(inData.startData.startDealerPlayerId);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -770,7 +770,7 @@ NetPacketGameStart::GetData(NetPacketGameStart::Data &outData) const
|
||||
NetPacketGameStartData *tmpData = (NetPacketGameStartData *)GetRawData();
|
||||
assert(tmpData);
|
||||
|
||||
outData.startData.startDealerPos = ntohs(tmpData->startDealerPos);
|
||||
outData.startData.startDealerPlayerId = ntohs(tmpData->startDealerPlayerId);
|
||||
}
|
||||
|
||||
const NetPacketGameStart *
|
||||
|
||||
@@ -154,9 +154,9 @@ ServerRecvStateInit::Process(ServerRecvThread &server)
|
||||
boost::shared_ptr<NetPacket> answer(new NetPacketJoinGameAck);
|
||||
NetPacketJoinGameAck::Data joinGameAckData;
|
||||
joinGameAckData.sessionId = session.sessionData->GetId(); // TODO: currently unused.
|
||||
joinGameAckData.yourPlayerUniqueId = tmpPlayerData->GetUniqueId();
|
||||
joinGameAckData.yourPlayerNum = tmpPlayerData->GetNumber();
|
||||
joinGameAckData.gameData = server.GetGameData();
|
||||
joinGameAckData.gameData.guiPlayerUniqueId = tmpPlayerData->GetUniqueId();
|
||||
joinGameAckData.gameData.guiPlayerNum = tmpPlayerData->GetNumber();
|
||||
static_cast<NetPacketJoinGameAck *>(answer.get())->SetData(joinGameAckData);
|
||||
server.GetSender().Send(recvSock, answer);
|
||||
|
||||
@@ -227,8 +227,9 @@ ServerRecvStateStartGame::Process(ServerRecvThread &server)
|
||||
{
|
||||
// Set dealer pos.
|
||||
StartData startData;
|
||||
Tools myTool;
|
||||
myTool.getRandNumber(0, server.GetGameData().numberOfPlayers-1, 1, &startData.startDealerPos, 0);
|
||||
int tmpDealerPos = 0;
|
||||
Tools::getRandNumber(0, server.GetGameData().numberOfPlayers-1, 1, &tmpDealerPos, 0);
|
||||
startData.startDealerPlayerId = static_cast<unsigned>(tmpDealerPos);
|
||||
server.SetStartData(startData);
|
||||
}
|
||||
|
||||
|
||||
@@ -120,6 +120,8 @@ public:
|
||||
struct Data
|
||||
{
|
||||
u_int32_t sessionId;
|
||||
int16_t yourPlayerNum;
|
||||
u_int16_t yourPlayerUniqueId;
|
||||
GameData gameData;
|
||||
};
|
||||
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
|
||||
typedef unsigned __int16 u_int16_t;
|
||||
typedef unsigned __int32 u_int32_t;
|
||||
typedef __int16 int16_t;
|
||||
typedef __int32 int32_t;
|
||||
typedef unsigned char u_char;
|
||||
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user