Skip to content

Commit

Permalink
Fix random player position in FTL
Browse files Browse the repository at this point in the history
  • Loading branch information
Benau committed Oct 5, 2021
1 parent 6f7c8c3 commit 39f7e64
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/race/race_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,20 +491,6 @@ void RaceManager::startNew(bool from_overworld)
init_gp_rank ++;
}

const bool random_pos_available = !NetworkConfig::get()->isNetworking() &&
(RaceManager::get()->getMinorMode() == RaceManager::MINOR_MODE_NORMAL_RACE
|| RaceManager::get()->getMinorMode() == RaceManager::MINOR_MODE_TIME_TRIAL
|| RaceManager::get()->getMinorMode() == RaceManager::MINOR_MODE_FOLLOW_LEADER);

if (UserConfigParams::m_random_player_pos)
{
if (random_pos_available)
{
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::shuffle(m_kart_status.begin(), m_kart_status.end(), std::default_random_engine(seed));
}
}

m_track_number = 0;
if (m_major_mode == MAJOR_MODE_GRAND_PRIX)
{
Expand Down Expand Up @@ -565,15 +551,14 @@ void RaceManager::startNextRace()

m_num_finished_karts = 0;
m_num_finished_players = 0;
// In follow the leader mode do not change the first kart,
// since it's always the leader.
int offset = (m_minor_mode==MINOR_MODE_FOLLOW_LEADER) ? 1 : 0;

// if subsequent race, sort kart status structure
// ==============================================
if (m_track_number > 0)
{
// In follow the leader mode do not change the first kart,
// since it's always the leader.
int offset = (m_minor_mode==MINOR_MODE_FOLLOW_LEADER) ? 1 : 0;

// Keep players at the end if needed
int player_last_offset = 0;
if (UserConfigParams::m_gp_player_last)
Expand All @@ -594,6 +579,23 @@ void RaceManager::startNextRace()
m_kart_status.end() - player_last_offset);
}
} // not first race
else
{
const bool random_pos_available = !NetworkConfig::get()->isNetworking() &&
(RaceManager::get()->getMinorMode() == RaceManager::MINOR_MODE_NORMAL_RACE
|| RaceManager::get()->getMinorMode() == RaceManager::MINOR_MODE_TIME_TRIAL
|| RaceManager::get()->getMinorMode() == RaceManager::MINOR_MODE_FOLLOW_LEADER);

if (UserConfigParams::m_random_player_pos)
{
if (random_pos_available)
{
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::shuffle(m_kart_status.begin() + offset, m_kart_status.end(),
std::default_random_engine(seed));
}
}
}

// set boosted AI status for AI karts
int boosted_ai_count = std::min<int>((int)m_ai_kart_list.size(),
Expand Down

0 comments on commit 39f7e64

Please sign in to comment.