Fixed running more than the first hand in network games.

This commit is contained in:
lotodore
2007-05-27 13:24:52 +00:00
parent 5325897122
commit 1232017e3a
3 changed files with 80 additions and 78 deletions
+64 -64
View File
@@ -33,7 +33,7 @@
using namespace std;
#define SERVER_WAIT_TIMEOUT_MSEC 50
#define SERVER_NEXT_HAND_DELAY_SEC 5
#define SERVER_NEXT_HAND_DELAY_SEC 10
ServerRecvState::~ServerRecvState()
@@ -459,24 +459,24 @@ ServerRecvStateStartRound::Process(ServerRecvThread &server)
curGame.getCurrentHand()->getRiver()->postRiverRun();
// Count active players. If only one player is left, no cards are shown.
int activePlayersCounter = 0;
std::list<PlayerInterface *> activePlayers;
for (int i = 0; i < curGame.getActualQuantityPlayers() ; i++)
{
if (curGame.getPlayerArray()[i]->getMyActiveStatus()
&& curGame.getPlayerArray()[i]->getMyAction() != PLAYER_ACTION_FOLD)
{
activePlayersCounter++;
activePlayers.push_back(curGame.getPlayerArray()[i]);
}
}
assert(activePlayersCounter);
assert(!activePlayers.empty());
if (activePlayersCounter == 1)
{
// End of Hand, but keep cards hidden.
PlayerInterface *player = activePlayers.front();
int activePlayersCounter = 0;
std::list<PlayerInterface *> activePlayers;
for (int i = 0; i < curGame.getActualQuantityPlayers() ; i++)
{
if (curGame.getPlayerArray()[i]->getMyActiveStatus()
&& curGame.getPlayerArray()[i]->getMyAction() != PLAYER_ACTION_FOLD)
{
activePlayersCounter++;
activePlayers.push_back(curGame.getPlayerArray()[i]);
}
}
assert(activePlayersCounter);
assert(!activePlayers.empty());
if (activePlayersCounter == 1)
{
// End of Hand, but keep cards hidden.
PlayerInterface *player = activePlayers.front();
boost::shared_ptr<NetPacket> endHand(new NetPacketEndOfHandHideCards);
NetPacketEndOfHandHideCards::Data endHandData;
endHandData.playerId = player->getMyUniqueID();
@@ -484,58 +484,58 @@ ServerRecvStateStartRound::Process(ServerRecvThread &server)
endHandData.playerMoney = player->getMyCash();
static_cast<NetPacketEndOfHandHideCards *>(endHand.get())->SetData(endHandData);
server.SendToAllPlayers(endHand);
}
else
{
// End of Hand - show cards of active players.
server.SendToAllPlayers(endHand);
}
else
{
// End of Hand - show cards of active players.
boost::shared_ptr<NetPacket> endHand(new NetPacketEndOfHandShowCards);
NetPacketEndOfHandShowCards::Data endHandData;
std::list<PlayerInterface *>::iterator i = activePlayers.begin();
std::list<PlayerInterface *>::iterator end = activePlayers.end();
while (i != end)
{
NetPacketEndOfHandShowCards::PlayerResult tmpPlayerResult;
tmpPlayerResult.playerId = (*i)->getMyUniqueID();
int tmpCards[2];
(*i)->getMyCards(tmpCards);
tmpPlayerResult.cards[0] = static_cast<u_int16_t>(tmpCards[0]);
tmpPlayerResult.cards[1] = static_cast<u_int16_t>(tmpCards[1]);
for (int num = 0; num < 5; num++)
tmpPlayerResult.bestHandPos[num] = (*i)->getMyBestHandPosition()[num];
tmpPlayerResult.valueOfCards = (*i)->getMyCardsValueInt();
tmpPlayerResult.moneyWon = 0; // TODO
tmpPlayerResult.playerMoney = (*i)->getMyCash();
endHandData.playerResults.push_back(tmpPlayerResult);
++i;
}
std::list<PlayerInterface *>::iterator i = activePlayers.begin();
std::list<PlayerInterface *>::iterator end = activePlayers.end();
while (i != end)
{
NetPacketEndOfHandShowCards::PlayerResult tmpPlayerResult;
tmpPlayerResult.playerId = (*i)->getMyUniqueID();
int tmpCards[2];
(*i)->getMyCards(tmpCards);
tmpPlayerResult.cards[0] = static_cast<u_int16_t>(tmpCards[0]);
tmpPlayerResult.cards[1] = static_cast<u_int16_t>(tmpCards[1]);
for (int num = 0; num < 5; num++)
tmpPlayerResult.bestHandPos[num] = (*i)->getMyBestHandPosition()[num];
tmpPlayerResult.valueOfCards = (*i)->getMyCardsValueInt();
tmpPlayerResult.moneyWon = 0; // TODO
tmpPlayerResult.playerMoney = (*i)->getMyCash();
endHandData.playerResults.push_back(tmpPlayerResult);
++i;
}
static_cast<NetPacketEndOfHandShowCards *>(endHand.get())->SetData(endHandData);
server.SendToAllPlayers(endHand);
}
// Start next hand - if enough players are left.
int playersPositiveCashCounter = 0;
for (int i = 0; i < curGame.getStartQuantityPlayers(); i++)
{
if (curGame.getCurrentHand()->getPlayerArray()[i]->getMyCash() > 0)
playersPositiveCashCounter++;
}
if (playersPositiveCashCounter == 1)
server.SetState(ServerRecvStateFinal::Instance()); // TODO
else
{
server.SendToAllPlayers(endHand);
}
// Start next hand - if enough players are left.
int playersPositiveCashCounter = 0;
for (int i = 0; i < curGame.getStartQuantityPlayers(); i++)
{
if (curGame.getCurrentHand()->getPlayerArray()[i]->getMyCash() > 0)
playersPositiveCashCounter++;
}
if (playersPositiveCashCounter == 1)
server.SetState(ServerRecvStateFinal::Instance()); // TODO
else
{
boost::microsec_timer delayTimer;
delayTimer.start();
ServerRecvStateNextHand::Instance().SetTimer(delayTimer);
server.SetState(ServerRecvStateNextHand::Instance());
retVal = MSG_NET_GAME_SERVER_HAND_END;
}
server.SetState(ServerRecvStateNextHand::Instance());
retVal = MSG_NET_GAME_SERVER_HAND_END;
}
}
return retVal;
}