Set place for all players (not only first place) in ranked games. Simple version (all players who leave/lose at the same time get the same place).
This commit is contained in:
@@ -295,6 +295,44 @@ ServerGame::InitRankingMap(const PlayerDataList &playerDataList)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ServerGame::UpdateRankingMap()
|
||||||
|
{
|
||||||
|
list<boost::shared_ptr<PlayerInterface> > activePlayers = *m_game->getActivePlayerList();
|
||||||
|
size_t currentRank = activePlayers.size();
|
||||||
|
list<boost::shared_ptr<PlayerInterface> > tmpRemovedPlayers;
|
||||||
|
PlayerListIterator active_i = activePlayers.begin();
|
||||||
|
PlayerListIterator active_end = activePlayers.end();
|
||||||
|
PlayerListIterator next_i = active_i;
|
||||||
|
while(active_i != active_end)
|
||||||
|
{
|
||||||
|
++next_i;
|
||||||
|
if ((*active_i)->getMyCash() < 1)
|
||||||
|
{
|
||||||
|
tmpRemovedPlayers.push_back(*active_i);
|
||||||
|
activePlayers.erase(active_i);
|
||||||
|
}
|
||||||
|
active_i = next_i;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!tmpRemovedPlayers.empty())
|
||||||
|
{
|
||||||
|
currentRank = currentRank - tmpRemovedPlayers.size() + 1;
|
||||||
|
PlayerListConstIterator removed_i = tmpRemovedPlayers.begin();
|
||||||
|
PlayerListConstIterator removed_end = tmpRemovedPlayers.end();
|
||||||
|
while (removed_i != removed_end)
|
||||||
|
{
|
||||||
|
SetPlayerPlace((*removed_i)->getMyUniqueID(), currentRank);
|
||||||
|
++removed_i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Last player is winner.
|
||||||
|
if (activePlayers.size() == 1)
|
||||||
|
{
|
||||||
|
SetPlayerPlace((*(activePlayers.begin()))->getMyUniqueID(), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ServerGame::SetPlayerPlace(unsigned playerId, int place)
|
ServerGame::SetPlayerPlace(unsigned playerId, int place)
|
||||||
{
|
{
|
||||||
@@ -736,7 +774,7 @@ void
|
|||||||
ServerGame::RemoveDisconnectedPlayers()
|
ServerGame::RemoveDisconnectedPlayers()
|
||||||
{
|
{
|
||||||
// This should only be called between hands.
|
// This should only be called between hands.
|
||||||
if (m_game.get())
|
if (m_game)
|
||||||
{
|
{
|
||||||
PlayerListIterator i = m_game->getSeatsList()->begin();
|
PlayerListIterator i = m_game->getSeatsList()->begin();
|
||||||
PlayerListIterator end = m_game->getSeatsList()->end();
|
PlayerListIterator end = m_game->getSeatsList()->end();
|
||||||
|
|||||||
@@ -919,6 +919,9 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> server)
|
|||||||
// Remove disconnected players. This is the one and only place to do this.
|
// Remove disconnected players. This is the one and only place to do this.
|
||||||
server->RemoveDisconnectedPlayers();
|
server->RemoveDisconnectedPlayers();
|
||||||
|
|
||||||
|
// Update rankings of all remaining players.
|
||||||
|
server->UpdateRankingMap();
|
||||||
|
|
||||||
// Start next hand - if enough players are left.
|
// Start next hand - if enough players are left.
|
||||||
list<boost::shared_ptr<PlayerInterface> > playersWithCash = *curGame.getActivePlayerList();
|
list<boost::shared_ptr<PlayerInterface> > playersWithCash = *curGame.getActivePlayerList();
|
||||||
playersWithCash.remove_if(boost::bind(&PlayerInterface::getMyCash, _1) < 1);
|
playersWithCash.remove_if(boost::bind(&PlayerInterface::getMyCash, _1) < 1);
|
||||||
@@ -931,7 +934,6 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> server)
|
|||||||
else if (playersWithCash.size() == 1)
|
else if (playersWithCash.size() == 1)
|
||||||
{
|
{
|
||||||
boost::shared_ptr<PlayerInterface> winnerPlayer = *(playersWithCash.begin());
|
boost::shared_ptr<PlayerInterface> winnerPlayer = *(playersWithCash.begin());
|
||||||
server->SetPlayerPlace(winnerPlayer->getMyUniqueID(), 1);
|
|
||||||
server->InternalEndGame();
|
server->InternalEndGame();
|
||||||
|
|
||||||
// View a dialog for a new game - delayed.
|
// View a dialog for a new game - delayed.
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ public:
|
|||||||
|
|
||||||
void SendToAllPlayers(boost::shared_ptr<NetPacket> packet, SessionData::State state);
|
void SendToAllPlayers(boost::shared_ptr<NetPacket> packet, SessionData::State state);
|
||||||
void SendToAllButOnePlayers(boost::shared_ptr<NetPacket> packet, SessionId except, SessionData::State state);
|
void SendToAllButOnePlayers(boost::shared_ptr<NetPacket> packet, SessionId except, SessionData::State state);
|
||||||
void RemoveAllSessions();
|
void RemoveAllSessions();
|
||||||
|
|
||||||
bool IsPasswordProtected() const;
|
bool IsPasswordProtected() const;
|
||||||
bool CheckPassword(const std::string &password) const;
|
bool CheckPassword(const std::string &password) const;
|
||||||
@@ -106,6 +106,7 @@ protected:
|
|||||||
|
|
||||||
void InternalStartGame();
|
void InternalStartGame();
|
||||||
void InitRankingMap(const PlayerDataList &playerDataList);
|
void InitRankingMap(const PlayerDataList &playerDataList);
|
||||||
|
void UpdateRankingMap();
|
||||||
void SetPlayerPlace(unsigned playerId, int place);
|
void SetPlayerPlace(unsigned playerId, int place);
|
||||||
void InternalEndGame();
|
void InternalEndGame();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user