std::shuffle players list for randomized starting position
This commit is contained in:
parent
4c534dc28c
commit
950695769c
@ -265,19 +265,25 @@ void GameSetup::sortPlayersForGrandPrix()
|
||||
} // sortPlayersForGrandPrix
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void GameSetup::sortPlayersForTeamGame()
|
||||
void GameSetup::sortPlayersForGame()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_players_mutex);
|
||||
if (!isGrandPrix())
|
||||
{
|
||||
std::random_device rd;
|
||||
std::mt19937 g(rd());
|
||||
std::shuffle(m_players.begin(), m_players.end(), g);
|
||||
}
|
||||
if (!race_manager->teamEnabled() ||
|
||||
ServerConfig::m_team_choosing)
|
||||
return;
|
||||
std::lock_guard<std::mutex> lock(m_players_mutex);
|
||||
for (unsigned i = 0; i < m_players.size(); i++)
|
||||
{
|
||||
auto player = m_players[i].lock();
|
||||
assert(player);
|
||||
player->setTeam((KartTeam)(i % 2));
|
||||
}
|
||||
} // sortPlayersForTeamGame
|
||||
} // sortPlayersForGame
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
std::pair<int, int> GameSetup::getPlayerTeamInfo() const
|
||||
|
@ -165,7 +165,7 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
void sortPlayersForGrandPrix();
|
||||
// ------------------------------------------------------------------------
|
||||
void sortPlayersForTeamGame();
|
||||
void sortPlayersForGame();
|
||||
// ------------------------------------------------------------------------
|
||||
void setHitCaptureTime(int hc, float time)
|
||||
{
|
||||
|
@ -509,7 +509,7 @@ void ServerLobby::asynchronousUpdate()
|
||||
// Remove disconnected player (if any) one last time
|
||||
m_game_setup->update(true);
|
||||
m_game_setup->sortPlayersForGrandPrix();
|
||||
m_game_setup->sortPlayersForTeamGame();
|
||||
m_game_setup->sortPlayersForGame();
|
||||
auto players = m_game_setup->getConnectedPlayers();
|
||||
for (auto& player : players)
|
||||
player->getPeer()->clearAvailableKartIDs();
|
||||
|
Loading…
Reference in New Issue
Block a user