From fb7c82786a27a15251445d0d0e47f4ff64eb7904 Mon Sep 17 00:00:00 2001 From: Alayan Date: Sun, 5 May 2019 00:15:07 +0200 Subject: [PATCH] Simplify selection of the most appropriate set of egg in egg hunts --- src/modes/easter_egg_hunt.cpp | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/src/modes/easter_egg_hunt.cpp b/src/modes/easter_egg_hunt.cpp index 4c995d4ef..d91ee15b8 100644 --- a/src/modes/easter_egg_hunt.cpp +++ b/src/modes/easter_egg_hunt.cpp @@ -87,39 +87,25 @@ void EasterEggHunt::readData(const std::string &filename) return; } - // Search for the closest difficulty set of egg. + // Search for the most relevant set of egg const XMLNode *data = NULL; RaceManager::Difficulty difficulty = race_manager->getDifficulty(); RaceManager::Difficulty act_difficulty = RaceManager::DIFFICULTY_COUNT; - for(int i=difficulty; i<=RaceManager::DIFFICULTY_LAST; i++) + + for(int i=RaceManager::DIFFICULTY_FIRST; i<=RaceManager::DIFFICULTY_LAST; i++) { - std::string diff_name= - race_manager->getDifficultyAsString((RaceManager::Difficulty)i); + std::string diff_name = race_manager->getDifficultyAsString((RaceManager::Difficulty)i); const XMLNode * cur_data = easter->getNode(diff_name); if (cur_data) { data = cur_data; act_difficulty = (RaceManager::Difficulty)i; - break; + // Stop at the easiest difficulty which is equal or harder than the desired one. + // If none is equal or harder, this will default to the hardest defined set. + if (act_difficulty >= difficulty) + break; } } - // If there is no data for an equal or harder placement, - // check for the most difficult placement that is easier: - if(!data) - { - for(int i=difficulty-1; i>=RaceManager::DIFFICULTY_FIRST; i--) - { - std::string diff_name= - race_manager->getDifficultyAsString((RaceManager::Difficulty)i); - const XMLNode * cur_data = easter->getNode(diff_name); - if (cur_data) - { - data = cur_data; - act_difficulty = (RaceManager::Difficulty)i; - break; - } - } // for i - } // if !data if(!data) {