From 79e3d298ce679de0ae001baa223476ce9523fb4f Mon Sep 17 00:00:00 2001 From: Alayan-stk-2 Date: Mon, 4 Jun 2018 01:50:24 +0200 Subject: [PATCH] Correct finish time for GPs when skipping a race (#3276) * Make human players have a correct finish time when skipping a GP race * Don't compute the estimated finish time twice --- src/modes/standard_race.cpp | 38 ++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/modes/standard_race.cpp b/src/modes/standard_race.cpp index 0fa6f72d3..e701c6e6b 100644 --- a/src/modes/standard_race.cpp +++ b/src/modes/standard_race.cpp @@ -98,36 +98,56 @@ void StandardRace::endRaceEarly() std::vector active_players; // Required for debugging purposes beginSetKartPositions(); + float worse_finish_time = 0.0f; + for (unsigned int i = 1; i <= kart_amount; i++) { int kartid = m_position_index[i-1]; AbstractKart* kart = m_karts[kartid]; + if (kart->hasFinishedRace()) { + if (kart->getFinishTime() > worse_finish_time) + worse_finish_time = kart->getFinishTime(); + // Have to do this to keep endSetKartPosition happy setKartPosition(kartid, kart->getPosition()); - continue; } - if (kart->getController()->isPlayerController()) - { - // Keep active players apart for now - active_players.push_back(kartid); - } else { + float estimated_finish_time = estimateFinishTimeForKart(kart); + if (estimated_finish_time > worse_finish_time) + worse_finish_time = estimated_finish_time; + + // Keep active players apart for now + if (kart->getController()->isPlayerController()) + { + active_players.push_back(kartid); + } // AI karts finish - setKartPosition(kartid, i - (unsigned int) active_players.size()); - kart->finishedRace(estimateFinishTimeForKart(kart)); + else + { + setKartPosition(kartid, i - (unsigned int) active_players.size()); + kart->finishedRace(estimated_finish_time); + } } } // i <= kart_amount + // Now make the active players finish for (unsigned int i = 0; i < active_players.size(); i++) { int kartid = active_players[i]; int position = getNumKarts() - (int) active_players.size() + 1 + i; setKartPosition(kartid, position); - m_karts[kartid]->eliminate(); + float punished_time = estimateFinishTimeForKart(m_karts[kartid]) + + worse_finish_time - WorldStatus::getTime(); + m_karts[kartid]->finishedRace(punished_time); + + // In networked races, endRaceEarly will be called if a player + // takes too much time to finish, so don't mark him as eliminated + if (!isNetworkWorld()) + m_karts[kartid]->eliminate(); } // Finish the active players endSetKartPositions(); setPhase(RESULT_DISPLAY_PHASE);