From a32834e518a53c6a08e2f8277f589872246159ae Mon Sep 17 00:00:00 2001 From: Alayan Date: Tue, 2 Oct 2018 12:36:20 +0200 Subject: [PATCH] Make Powerup Love use a generic counter --- src/achievements/achievements_status.cpp | 12 +++++++++++- src/achievements/achievements_status.hpp | 7 +++++-- src/items/powerup.cpp | 3 ++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/achievements/achievements_status.cpp b/src/achievements/achievements_status.cpp index ff3303bed..b81b2c175 100644 --- a/src/achievements/achievements_status.cpp +++ b/src/achievements/achievements_status.cpp @@ -218,6 +218,14 @@ void AchievementsStatus::updateAchievementsProgress(unsigned int achieve_data_id gold_driver->increase("std_timetrial", "std_timetrial", m_variables[ACHIEVE_WON_TT_RACES].counter); gold_driver->increase("follow_leader", "follow_leader", m_variables[ACHIEVE_WON_FTL_RACES].counter); } + + Achievement *powerup_lover = PlayerManager::getCurrentAchievementsStatus()->getAchievement(AchievementInfo::ACHIEVE_POWERUP_LOVER); + + if (!powerup_lover->isAchieved()) + { + powerup_lover->reset(); + powerup_lover->increase("poweruplover", "poweruplover", m_variables[ACHIEVE_POWERUP_USED_1RACE].counter); + } } // ---------------------------------------------------------------------------- @@ -256,13 +264,15 @@ void AchievementsStatus::resetDataVar(unsigned int achieve_data_id) } // resetDataVar // ---------------------------------------------------------------------------- -void AchievementsStatus::onRaceEnd() +void AchievementsStatus::onRaceEnd(bool aborted) { //reset all values that need to be reset std::map::iterator iter; for ( iter = m_achievements.begin(); iter != m_achievements.end(); ++iter ) { iter->second->onRaceEnd(); } + + m_variables[ACHIEVE_POWERUP_USED_1RACE].counter = 0; } // onRaceEnd // ---------------------------------------------------------------------------- diff --git a/src/achievements/achievements_status.hpp b/src/achievements/achievements_status.hpp index c2bf15457..679dc7772 100644 --- a/src/achievements/achievements_status.hpp +++ b/src/achievements/achievements_status.hpp @@ -53,8 +53,11 @@ public : ACHIEVE_CONS_WON_RACES = 4, // Won races in (at least) hard requires at least 5 AI opponents ACHIEVE_CONS_WON_RACES_HARD = 5, + // Count the number of powerups used by the player. + ACHIEVE_POWERUP_USED = 6, + ACHIEVE_POWERUP_USED_1RACE = 7, - ACHIEVE_DATA_NUM = 6 + ACHIEVE_DATA_NUM = 8 }; private: @@ -96,7 +99,7 @@ public : void updateAchievementsProgress(unsigned int achieve_data_id); void increaseDataVar(unsigned int achieve_data_id, int increase); void resetDataVar(unsigned int achieve_data_id); - void onRaceEnd(); + void onRaceEnd(bool aborted=false); void onLapEnd(); // ------------------------------------------------------------------------ const std::map& getAllAchievements() diff --git a/src/items/powerup.cpp b/src/items/powerup.cpp index 0771e0b7c..1b28e7316 100644 --- a/src/items/powerup.cpp +++ b/src/items/powerup.cpp @@ -254,7 +254,8 @@ void Powerup::use() if (m_type != PowerupManager::POWERUP_NOTHING && m_kart->getController()->canGetAchievements() ) { - PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_POWERUP_LOVER, "poweruplover"); + PlayerManager::increaseAchievement(AchievementsStatus::ACHIEVE_POWERUP_USED, 1); + PlayerManager::increaseAchievement(AchievementsStatus::ACHIEVE_POWERUP_USED_1RACE, 1); } // Play custom kart sound when collectible is used //TODO: what about the bubble gum?