Simplify selection of the most appropriate set of egg in egg hunts
This commit is contained in:
parent
f27a51f680
commit
fb7c82786a
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user