diff --git a/src/config/saved_grand_prix.hpp b/src/config/saved_grand_prix.hpp index a5c8eb70433..8d12d7d26a8 100644 --- a/src/config/saved_grand_prix.hpp +++ b/src/config/saved_grand_prix.hpp @@ -158,10 +158,6 @@ class SavedGrandPrix /** Returns time target used in Lap Trial mode */ float getTimeTarget() const { return m_time_target; } - // ------------------------------------------------------------------------ - /** Returns total laps in GP */ - int getPlayerTotalLaps() const { return m_player_total_laps; } - // ------------------------------------------------------------------------ /** Sets the index of the last track finished. */ void setNextTrack(int next_track) { m_next_track = next_track; } diff --git a/src/modes/world.cpp b/src/modes/world.cpp index d84f68796ba..eae6672c9ba 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -1256,14 +1256,13 @@ Highscores* World::getGPHighscores() const } // ---------------------------------------------------------------------------- -/** Called at the end of a race. Checks if the current times are worth a new - * score, if so it notifies the HighscoreManager so the new score is added - * and saved. +/** Called at the end of a race. + * Submits the valid new times through the addHighscore functions, which then handles + * checking if the new times are worth of a highscore and saving them. + * The best highscore rank is transmitted to highlight the best new highscore in the GUI. */ void World::updateHighscores(int* best_highscore_rank) { - *best_highscore_rank = -1; - if(!m_use_highscores) return; // Add times to highscore list. First compute the order of karts, @@ -1291,7 +1290,6 @@ void World::updateHighscores(int* best_highscore_rank) { // no kart claimed to be in this position, most likely means // the kart location data is wrong - #ifdef DEBUG Log::error("[World]", "Incorrect kart positions:"); for (unsigned int i=0; iisLapTrialMode() ? static_cast(getFinishedLapsOfKart(index[pos])) + : k->getFinishTime(); // The player is a local player, so there is a name: - if (RaceManager::get()->isLapTrialMode()) - { - highscore_rank = highscores->addData(k->getIdent(), - k->getController()->getName(), - static_cast(getFinishedLapsOfKart(index[pos]))); - } - else + int highscore_rank = highscores->addData(k->getIdent(), k->getController()->getName(), highscore_value); + + if (highscore_rank > 0 && (*best_highscore_rank == -1 || + highscore_rank < *best_highscore_rank)) { - highscore_rank = highscores->addData(k->getIdent(), - k->getController()->getName(), - k->getFinishTime() ); + *best_highscore_rank = highscore_rank; } - + } // next position + + // Handle GP highscores + if (RaceManager::get()->getMajorMode() == RaceManager::MAJOR_MODE_GRAND_PRIX && + RaceManager::get()->getNumOfTracks() == RaceManager::get()->getTrackNumber() + 1 && + !RaceManager::get()->getGrandPrix().isRandomGP() && + RaceManager::get()->getSkippedTracksInGP() == 0) + { + std::string gp_name = RaceManager::get()->getGrandPrix().getId(); - if (highscore_rank > 0) + for (unsigned int kart_id = 0; kart_id < RaceManager::get()->getNumberOfKarts(); kart_id++) { - if (*best_highscore_rank == -1 || - highscore_rank < *best_highscore_rank) - { - *best_highscore_rank = highscore_rank; - } + // Only record times for local player karts and only if + // they finished the race + if (!m_karts[kart_id]->getController()->isLocalPlayerController() || + !m_karts[kart_id]->hasFinishedRace() || + m_karts[kart_id]->isEliminated()) + continue; - Highscores::setSortOrder(Highscores::SO_DEFAULT); - highscore_manager->sortHighscores(false); + // The original lap trial GP code was a mess. I'm not fixing it... + if (RaceManager::get()->isLapTrialMode()) + continue; - highscore_manager->saveHighscores(); - } - } // next position - delete []index; + Kart *k = (Kart*)m_karts[kart_id].get(); + float full_time = RaceManager::get()->getOverallTime(kart_id); + Highscores* highscores = World::getWorld()->getGPHighscores(); + // The player is a local player, so there is a name: + highscores->addGPData(k->getIdent(), k->getController()->getName(), gp_name, full_time); + } // for kart_id + } // Handle GP highscores + + delete []index; } // updateHighscores //----------------------------------------------------------------------------- diff --git a/src/race/race_manager.cpp b/src/race/race_manager.cpp index 823ddf60680..f58d51985c3 100644 --- a/src/race/race_manager.cpp +++ b/src/race/race_manager.cpp @@ -138,7 +138,6 @@ RaceManager::RaceManager() m_flag_deactivated_ticks = stk_config->time2Ticks(3.0f); m_skipped_tracks_in_gp = 0; m_gp_time_target = 0.0f; - m_gp_total_laps = 0; setMaxGoal(0); setTimeTarget(0.0f); setReverseTrack(false); @@ -432,10 +431,7 @@ void RaceManager::startNew(bool from_overworld) m_skipped_tracks_in_gp = m_saved_gp->getSkippedTracks(); Log::info("RaceManager","%d",isLapTrialMode()); if (isLapTrialMode()) - { m_gp_time_target = m_saved_gp->getTimeTarget(); - m_gp_total_laps = m_saved_gp->getPlayerTotalLaps(); - } } // if m_saved_gp==NULL } // if m_continue_saved_gp } // if !network_world @@ -795,7 +791,7 @@ void RaceManager::saveGP() m_grand_prix.getReverseType(), m_skipped_tracks_in_gp, isLapTrialMode() ? m_gp_time_target : 0.0f, - isLapTrialMode() ? m_gp_total_laps : 0, + 0, m_kart_status); // If a new GP is saved, delete any other saved data for this diff --git a/src/race/race_manager.hpp b/src/race/race_manager.hpp index 69356f51004..18870138048 100644 --- a/src/race/race_manager.hpp +++ b/src/race/race_manager.hpp @@ -936,10 +936,6 @@ class RaceManager // ---------------------------------------------------------------------------------------- void setGPTimeTarget(float time_target) { m_gp_time_target = time_target; } // ---------------------------------------------------------------------------------------- - int getGPTotalLaps() const { return m_gp_total_laps; } - // ---------------------------------------------------------------------------------------- - void addGPTotalLaps(int laps) { m_gp_total_laps += laps; } - // ---------------------------------------------------------------------------------------- /** Whether the current game mode allow live joining even the current game *. started in network*/ bool supportsLiveJoining() const diff --git a/src/states_screens/race_result_gui.cpp b/src/states_screens/race_result_gui.cpp index 49a317c611d..43d4ec2bad2 100644 --- a/src/states_screens/race_result_gui.cpp +++ b/src/states_screens/race_result_gui.cpp @@ -207,27 +207,6 @@ void RaceResultGUI::init() MessageQueue::add(MessageQueue::MT_GENERIC, tips_string); } #endif - - if (RaceManager::get()->getMajorMode() == RaceManager::MAJOR_MODE_GRAND_PRIX && - !NetworkConfig::get()->isNetworking() && - (RaceManager::get()->getMinorMode() == RaceManager::MINOR_MODE_NORMAL_RACE || RaceManager::get()->getMinorMode() == RaceManager::MINOR_MODE_TIME_TRIAL || - RaceManager::get()->isLapTrialMode())) - { - const AbstractKart* k = RaceManager::get()->getKartWithGPRank(RaceManager::get()->getLocalPlayerGPRank(PLAYER_ID_GAME_MASTER)); - RaceManager::get()->addGPTotalLaps(World::getWorld()->getFinishedLapsOfKart(k->getWorldKartId())); - if (RaceManager::get()->getNumOfTracks() == RaceManager::get()->getTrackNumber() + 1 - && !RaceManager::get()->getGrandPrix().isRandomGP() && RaceManager::get()->getSkippedTracksInGP() == 0) - { - Highscores* highscores = World::getWorld()->getGPHighscores(); - float full_time; - if (RaceManager::get()->isLapTrialMode()) - full_time = static_cast(RaceManager::get()->getGPTotalLaps()); - else - full_time = RaceManager::get()->getOverallTime(RaceManager::get()->getLocalPlayerGPRank(PLAYER_ID_GAME_MASTER)); - std::string gp_name = RaceManager::get()->getGrandPrix().getId(); - highscores->addGPData(k->getIdent(), k->getController()->getName(), gp_name, full_time); - } - } } // init //-----------------------------------------------------------------------------