Move end-race achievement counter updates to a dedicated function

This commit is contained in:
Alayan 2018-10-03 17:02:36 +02:00 committed by auriamg
parent 43dd2f2f82
commit a90890d0b3
3 changed files with 91 additions and 82 deletions

View File

@ -51,7 +51,7 @@
<poweruplover goal="10"/> <poweruplover goal="10"/>
</achievement> </achievement>
<achievement id="8" check-type="all-at-least" reset-type="never" <achievement id="8" check-type="all-at-least" reset-type="never"
name="Beyond Luck" description="Win 5 single races in a row against at least 3 AIs. Beware, restarting a race count as a loss."> name="Beyond Luck" description="Win 5 single races in a row against at least 3 AIs. Beware, restarting a race counts as a loss.">
<wins goal="5"/> <wins goal="5"/>
</achievement> </achievement>
<achievement id="9" check-type="all-at-least" reset-type="race" <achievement id="9" check-type="all-at-least" reset-type="race"
@ -66,7 +66,7 @@
<swatter goal="5"/> <swatter goal="5"/>
</achievement> </achievement>
<achievement id="12" check-type="all-at-least" reset-type="never" <achievement id="12" check-type="all-at-least" reset-type="never"
name="Unstoppable" description="Win 10 single races in a row in Expert or SuperTux against at least 5 AIs. Beware, restarting a race count as a loss."> name="Unstoppable" description="Win 10 single races in a row in Expert or SuperTux against at least 5 AIs. Beware, restarting a race counts as a loss.">
<wins goal="10"/> <wins goal="10"/>
</achievement> </achievement>
</achievements> </achievements>

View File

@ -634,86 +634,7 @@ void World::terminateRace()
updateHighscores(&best_highscore_rank); updateHighscores(&best_highscore_rank);
} }
//TODO : move this stuff to a sub-function updateAchievementDataEndRace();
// Increment won races counts and track finished counts
if (race_manager->isLinearRaceMode())
{
for(unsigned int i = 0; i < kart_amount; i++)
{
// TODO : does this work in multiplayer ?
// TODO : check what happens when abandonning a race in a GP
// Retrieve the current player
if (m_karts[i]->getController()->canGetAchievements())
{
AchievementsStatus::AchievementData diff;
diff = (race_manager->getDifficulty() == RaceManager::DIFFICULTY_EASY) ? AchievementsStatus::EASY_FINISHED :
(race_manager->getDifficulty() == RaceManager::DIFFICULTY_MEDIUM) ? AchievementsStatus::MEDIUM_FINISHED :
(race_manager->getDifficulty() == RaceManager::DIFFICULTY_HARD) ? AchievementsStatus::HARD_FINISHED :
AchievementsStatus::BEST_FINISHED;
PlayerManager::increaseAchievement(diff,1);
PlayerManager::trackEvent(race_manager->getTrackName(), AchievementsStatus::TR_FINISHED);
if (race_manager->getReverseTrack())
PlayerManager::trackEvent(race_manager->getTrackName(), AchievementsStatus::TR_FINISHED_REVERSE);
if (race_manager->modeHasLaps())
{
Track* track = track_manager->getTrack(race_manager->getTrackName());
int default_lap_num = track->getDefaultNumberOfLaps();
if (race_manager->getNumLaps() < default_lap_num)
{
PlayerManager::trackEvent(race_manager->getTrackName(), AchievementsStatus::TR_LESS_LAPS);
}
else if (race_manager->getNumLaps() > default_lap_num)
{
PlayerManager::trackEvent(race_manager->getTrackName(), AchievementsStatus::TR_MORE_LAPS);
if (race_manager->getNumLaps() >= 2*default_lap_num)
PlayerManager::trackEvent(race_manager->getTrackName(), AchievementsStatus::TR_MIN_TWICE_LAPS);
}
}
int winner_position = 1;
//TODO : check this always work : what happens if the leader is overtaken between the last elimination
// and the results screen ?
if (race_manager->isFollowMode()) winner_position = 2;
// Check if the player has won
if (m_karts[i]->getPosition() == winner_position)
{
if (race_manager->getNumNonGhostKarts() >= 2)
PlayerManager::trackEvent(race_manager->getTrackName(), AchievementsStatus::TR_WON);
else
PlayerManager::trackEvent(race_manager->getTrackName(), AchievementsStatus::TR_FINISHED_ALONE);
if (race_manager->getNumberOfAIKarts() >= 3)
{
PlayerManager::increaseAchievement(AchievementsStatus::ACHIEVE_WON_RACES,1);
PlayerManager::increaseAchievement(AchievementsStatus::ACHIEVE_CONS_WON_RACES,1);
if (race_manager->isTimeTrialMode())
PlayerManager::increaseAchievement(AchievementsStatus::ACHIEVE_WON_TT_RACES,1);
else if (race_manager->isFollowMode())
PlayerManager::increaseAchievement(AchievementsStatus::ACHIEVE_WON_FTL_RACES,1);
else // normal race
PlayerManager::increaseAchievement(AchievementsStatus::ACHIEVE_WON_NORMAL_RACES,1);
}
if (race_manager->getNumberOfAIKarts() >= 5 &&
(race_manager->getDifficulty() == RaceManager::DIFFICULTY_HARD ||
race_manager->getDifficulty() == RaceManager::DIFFICULTY_BEST))
PlayerManager::increaseAchievement(AchievementsStatus::ACHIEVE_CONS_WON_RACES_HARD,1);
}
// Race lost, reset the consecutive wins counters
else if (m_karts[i]->getPosition() > winner_position)
{
PlayerManager::resetAchievementData(AchievementsStatus::ACHIEVE_CONS_WON_RACES);
PlayerManager::resetAchievementData(AchievementsStatus::ACHIEVE_CONS_WON_RACES_HARD);
}
}
} // for i<kart_amount
} // if isLinearRaceMode
// Increment egg hunt finished count
if (race_manager->isEggHuntMode())
{
PlayerManager::trackEvent(race_manager->getTrackName(), AchievementsStatus::TR_EGG_HUNT_FINISHED);
}
PlayerManager::getCurrentPlayer()->raceFinished(); PlayerManager::getCurrentPlayer()->raceFinished();
@ -1646,3 +1567,90 @@ void World::setAITeam()
Log::debug("World", "Blue AI: %d red AI: %d", m_blue_ai, m_red_ai); Log::debug("World", "Blue AI: %d red AI: %d", m_blue_ai, m_red_ai);
} // setAITeam } // setAITeam
//-----------------------------------------------------------------------------
/* This function takes care to update all relevant achievements
* and statistics counters related to a finished race. */
void World::updateAchievementDataEndRace()
{
const unsigned int kart_amount = getNumKarts();
// Increment won races counts and track finished counts
if (race_manager->isLinearRaceMode())
{
for(unsigned int i = 0; i < kart_amount; i++)
{
// TODO : does this work in multiplayer ?
// TODO : check what happens when abandonning a race in a GP
// Retrieve the current player
if (m_karts[i]->getController()->canGetAchievements())
{
AchievementsStatus::AchievementData diff;
diff = (race_manager->getDifficulty() == RaceManager::DIFFICULTY_EASY) ? AchievementsStatus::EASY_FINISHED :
(race_manager->getDifficulty() == RaceManager::DIFFICULTY_MEDIUM) ? AchievementsStatus::MEDIUM_FINISHED :
(race_manager->getDifficulty() == RaceManager::DIFFICULTY_HARD) ? AchievementsStatus::HARD_FINISHED :
AchievementsStatus::BEST_FINISHED;
PlayerManager::increaseAchievement(diff,1);
PlayerManager::trackEvent(race_manager->getTrackName(), AchievementsStatus::TR_FINISHED);
if (race_manager->getReverseTrack())
PlayerManager::trackEvent(race_manager->getTrackName(), AchievementsStatus::TR_FINISHED_REVERSE);
if (race_manager->modeHasLaps())
{
Track* track = track_manager->getTrack(race_manager->getTrackName());
int default_lap_num = track->getDefaultNumberOfLaps();
if (race_manager->getNumLaps() < default_lap_num)
{
PlayerManager::trackEvent(race_manager->getTrackName(), AchievementsStatus::TR_LESS_LAPS);
}
else if (race_manager->getNumLaps() > default_lap_num)
{
PlayerManager::trackEvent(race_manager->getTrackName(), AchievementsStatus::TR_MORE_LAPS);
if (race_manager->getNumLaps() >= 2*default_lap_num)
PlayerManager::trackEvent(race_manager->getTrackName(), AchievementsStatus::TR_MIN_TWICE_LAPS);
}
}
int winner_position = 1;
//TODO : check this always work : what happens if the leader is overtaken between the last elimination
// and the results screen ?
if (race_manager->isFollowMode()) winner_position = 2;
// Check if the player has won
if (m_karts[i]->getPosition() == winner_position)
{
if (race_manager->getNumNonGhostKarts() >= 2)
PlayerManager::trackEvent(race_manager->getTrackName(), AchievementsStatus::TR_WON);
else
PlayerManager::trackEvent(race_manager->getTrackName(), AchievementsStatus::TR_FINISHED_ALONE);
if (race_manager->getNumberOfAIKarts() >= 3)
{
PlayerManager::increaseAchievement(AchievementsStatus::ACHIEVE_WON_RACES,1);
PlayerManager::increaseAchievement(AchievementsStatus::ACHIEVE_CONS_WON_RACES,1);
if (race_manager->isTimeTrialMode())
PlayerManager::increaseAchievement(AchievementsStatus::ACHIEVE_WON_TT_RACES,1);
else if (race_manager->isFollowMode())
PlayerManager::increaseAchievement(AchievementsStatus::ACHIEVE_WON_FTL_RACES,1);
else // normal race
PlayerManager::increaseAchievement(AchievementsStatus::ACHIEVE_WON_NORMAL_RACES,1);
}
if (race_manager->getNumberOfAIKarts() >= 5 &&
(race_manager->getDifficulty() == RaceManager::DIFFICULTY_HARD ||
race_manager->getDifficulty() == RaceManager::DIFFICULTY_BEST))
PlayerManager::increaseAchievement(AchievementsStatus::ACHIEVE_CONS_WON_RACES_HARD,1);
}
// Race lost, reset the consecutive wins counters
else if (m_karts[i]->getPosition() > winner_position)
{
PlayerManager::resetAchievementData(AchievementsStatus::ACHIEVE_CONS_WON_RACES);
PlayerManager::resetAchievementData(AchievementsStatus::ACHIEVE_CONS_WON_RACES_HARD);
}
}
} // for i<kart_amount
} // if isLinearRaceMode
// Increment egg hunt finished count
if (race_manager->isEggHuntMode())
{
PlayerManager::trackEvent(race_manager->getTrackName(), AchievementsStatus::TR_EGG_HUNT_FINISHED);
}
} // updateAchievementDataEndRace

View File

@ -195,6 +195,7 @@ protected:
{return getTime(); } {return getTime(); }
/** Set the team arrow on karts if necessary*/ /** Set the team arrow on karts if necessary*/
void initTeamArrows(); void initTeamArrows();
void updateAchievementDataEndRace();
public: public:
World(); World();