Shuffle player list for the 1st track in grand prix
This commit is contained in:
parent
52e2a64893
commit
02ecb9f914
@ -30,6 +30,7 @@
|
|||||||
#include "utils/log.hpp"
|
#include "utils/log.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <random>
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
/** Update and see if any player disconnects.
|
/** Update and see if any player disconnects.
|
||||||
@ -139,14 +140,23 @@ void GameSetup::addServerInfo(NetworkString* ns)
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void GameSetup::sortPlayersForGrandPrix()
|
void GameSetup::sortPlayersForGrandPrix()
|
||||||
{
|
{
|
||||||
if (!isGrandPrix() || m_tracks.size() == 1)
|
if (!isGrandPrix())
|
||||||
return;
|
return;
|
||||||
std::lock_guard<std::mutex> lock(m_players_mutex);
|
std::lock_guard<std::mutex> lock(m_players_mutex);
|
||||||
|
|
||||||
|
if (m_tracks.size() == 1)
|
||||||
|
{
|
||||||
|
std::random_device rd;
|
||||||
|
std::mt19937 g(rd());
|
||||||
|
std::shuffle(m_players.begin(), m_players.end(), g);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
std::sort(m_players.begin(), m_players.end(),
|
std::sort(m_players.begin(), m_players.end(),
|
||||||
[](const std::weak_ptr<NetworkPlayerProfile>& a,
|
[](const std::weak_ptr<NetworkPlayerProfile>& a,
|
||||||
const std::weak_ptr<NetworkPlayerProfile>& b)
|
const std::weak_ptr<NetworkPlayerProfile>& b)
|
||||||
{
|
{
|
||||||
// They should never expired
|
// They should be never expired
|
||||||
auto c = a.lock();
|
auto c = a.lock();
|
||||||
assert(c);
|
assert(c);
|
||||||
auto d = b.lock();
|
auto d = b.lock();
|
||||||
|
Loading…
Reference in New Issue
Block a user