diff --git a/src/items/attachment.cpp b/src/items/attachment.cpp index d688ddb72..04a83ed8d 100644 --- a/src/items/attachment.cpp +++ b/src/items/attachment.cpp @@ -225,10 +225,7 @@ void Attachment::clear() */ void Attachment::hitBanana(Item *item, int new_attachment) { - const KartProperties *kp = m_kart->getKartProperties(); - const StateManager::ActivePlayer *const ap = m_kart->getController() - ->getPlayer(); - if(ap && ap->getConstProfile()==PlayerManager::getCurrentPlayer()) + if(m_kart->getController()->canGetAchievements()) PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_BANANA, "banana",1 ); //Bubble gum shield effect: @@ -250,6 +247,7 @@ void Attachment::hitBanana(Item *item, int new_attachment) return; } + const KartProperties *kp = m_kart->getKartProperties(); switch(getType()) // If there already is an attachment, make it worse :) { case ATTACH_BOMB: diff --git a/src/items/powerup.cpp b/src/items/powerup.cpp index fe617e412..6e5d5ca94 100644 --- a/src/items/powerup.cpp +++ b/src/items/powerup.cpp @@ -174,9 +174,8 @@ void Powerup::use() const KartProperties *kp = m_owner->getKartProperties(); // The player gets an achievement point for using a powerup - StateManager::ActivePlayer * player = m_owner->getController()->getPlayer(); - if (m_type != PowerupManager::POWERUP_NOTHING && - player != NULL && player->getConstProfile() == PlayerManager::getCurrentPlayer()) + if (m_type != PowerupManager::POWERUP_NOTHING && + m_owner->getController()->canGetAchievements() ) { PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_POWERUP_LOVER, "poweruplover"); } diff --git a/src/items/swatter.cpp b/src/items/swatter.cpp index 166a7fd5e..0a148f4e8 100644 --- a/src/items/swatter.cpp +++ b/src/items/swatter.cpp @@ -290,13 +290,11 @@ void Swatter::squashThingsAround() m_closest_kart->setSquash(kp->getSwatterSquashDuration(), kp->getSwatterSquashSlowdown()); - //Handle achievement if the swatter is used by the current player - const StateManager::ActivePlayer *const ap = m_kart->getController() - ->getPlayer(); - if (ap && ap->getConstProfile() == PlayerManager::getCurrentPlayer()) + // Handle achievement if the swatter is used by the current player + if (m_kart->getController()->canGetAchievements()) { PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_MOSQUITO, - "swatter", 1); + "swatter", 1); } if (m_closest_kart->getAttachment()->getType()==Attachment::ATTACH_BOMB) diff --git a/src/karts/controller/controller.cpp b/src/karts/controller/controller.cpp index 08a9fdef1..57d83369c 100644 --- a/src/karts/controller/controller.cpp +++ b/src/karts/controller/controller.cpp @@ -22,6 +22,7 @@ #include "karts/controller/controller.hpp" +#include "config/player_manager.hpp" #include "karts/abstract_kart.hpp" /** Constructor, saves the kart pointer and a pointer to the KartControl @@ -38,3 +39,14 @@ Controller::Controller(AbstractKart *kart, StateManager::ActivePlayer *player) } // Controller // ---------------------------------------------------------------------------- +/** Returns true if the player of this controller can collect achievements. +* At the moment only the current player can collect them. +* TODO: check this, possible all local players should be able to +* collect achievements - synching to online account will happen +* next time the account gets online. +*/ +bool Controller::canGetAchievements() const +{ + return m_player && m_player->getConstProfile() + == PlayerManager::getCurrentPlayer(); +} // canGetAchievements diff --git a/src/karts/controller/controller.hpp b/src/karts/controller/controller.hpp index db3752740..4fc28a82a 100644 --- a/src/karts/controller/controller.hpp +++ b/src/karts/controller/controller.hpp @@ -61,6 +61,7 @@ public: Controller (AbstractKart *kart, StateManager::ActivePlayer *player=NULL); virtual ~Controller () {}; + virtual bool canGetAchievements () const; virtual void reset () = 0; virtual void update (float dt) = 0; virtual void handleZipper (bool play_sound) = 0; @@ -93,7 +94,6 @@ public: // --------------------------------------------------------------------------- /** Returns the player object (or NULL if it's a computer controller). */ const StateManager::ActivePlayer *getPlayer () const { return m_player; } - // ------------------------------------------------------------------------ /** Default: ignore actions. Only PlayerController get them. */ virtual void action(PlayerAction action, int value) = 0; diff --git a/src/karts/controller/end_controller.cpp b/src/karts/controller/end_controller.cpp index 38a32e123..99d9ead90 100644 --- a/src/karts/controller/end_controller.cpp +++ b/src/karts/controller/end_controller.cpp @@ -50,9 +50,9 @@ #include "utils/constants.hpp" #include "utils/log.hpp" -EndController::EndController(AbstractKart *kart, StateManager::ActivePlayer *player, +EndController::EndController(AbstractKart *kart, Controller *prev_controller) - : AIBaseLapController(kart, player) + : AIBaseLapController(kart, NULL) { m_previous_controller = prev_controller; if(race_manager->getMinorMode()!=RaceManager::MINOR_MODE_3_STRIKES && diff --git a/src/karts/controller/end_controller.hpp b/src/karts/controller/end_controller.hpp index 5d59105b4..db69e6957 100644 --- a/src/karts/controller/end_controller.hpp +++ b/src/karts/controller/end_controller.hpp @@ -82,17 +82,33 @@ private: int calcSteps(); public: EndController(AbstractKart *kart, - StateManager::ActivePlayer* player, Controller *prev_controller); ~EndController(); virtual void update (float delta) ; virtual void reset (); + virtual void action (PlayerAction action, int value); + virtual void newLap (int lap); + // ------------------------------------------------------------------------ + virtual bool canGetAchievements() const + { + return m_previous_controller->canGetAchievements(); + } // canGetAchievements + // ------------------------------------------------------------------------ /** Returns if the original controller of the kart was a player * controller. This way e.g. highscores can still be assigned * to the right player. */ - virtual bool isPlayerController () const {return getPlayer()!=NULL;} - virtual void action (PlayerAction action, int value); - virtual void newLap (int lap); + virtual bool isPlayerController () const + { + return m_previous_controller->isPlayerController(); + } // isPlayerController + // ------------------------------------------------------------------------ + /** Returns if the original controller of the kart was a local player + * controller. This way e.g. highscores can still be assigned + * to the right player. */ + virtual bool isLocalPlayerController () const + { + return m_previous_controller->isLocalPlayerController(); + } // isLocalPlayerController }; // EndKart diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index 14e1cb718..41adaad28 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -868,8 +868,7 @@ void Kart::finishedRace(float time) { // Save for music handling in race result gui setRaceResult(); - setController(new EndController(this, m_controller->getPlayer(), - m_controller)); + setController(new EndController(this, m_controller)); // Skip animation if this kart is eliminated if (m_eliminated) return; diff --git a/src/karts/skidding.cpp b/src/karts/skidding.cpp index 15aafaf25..3b8dab760 100644 --- a/src/karts/skidding.cpp +++ b/src/karts/skidding.cpp @@ -416,10 +416,10 @@ void Skidding::update(float dt, bool is_on_ground, bonus_force, bonus_time, /*fade-out-time*/ 1.0f); - StateManager::ActivePlayer *c = m_kart->getController()->getPlayer(); - if (c && c->getConstProfile() == PlayerManager::getCurrentPlayer()) + if (m_kart->getController()->canGetAchievements()) { - PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_SKIDDING, "skidding"); + PlayerManager::increaseAchievement( + AchievementInfo::ACHIEVE_SKIDDING, "skidding"); } } else { diff --git a/src/modes/linear_world.cpp b/src/modes/linear_world.cpp index d6fc49185..cca42320c 100644 --- a/src/modes/linear_world.cpp +++ b/src/modes/linear_world.cpp @@ -247,9 +247,8 @@ void LinearWorld::newLap(unsigned int kart_index) AbstractKart *kart = m_karts[kart_index]; // Reset reset-after-lap achievements - StateManager::ActivePlayer *c = kart->getController()->getPlayer(); PlayerProfile *p = PlayerManager::getCurrentPlayer(); - if (c && c->getConstProfile() == p) + if (kart->getController()->canGetAchievements()) { p->getAchievementsStatus()->onLapEnd(); } diff --git a/src/modes/world.cpp b/src/modes/world.cpp index 339c203d7..2567988e2 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -500,8 +500,7 @@ void World::terminateRace() for(unsigned int i = 0; i < kart_amount; i++) { // Retrieve the current player - StateManager::ActivePlayer* p = m_karts[i]->getController()->getPlayer(); - if (p && p->getConstProfile() == PlayerManager::getCurrentPlayer()) + if (m_karts[i]->getController()->canGetAchievements()) { // Check if the player has won if (m_karts[i]->getPosition() == winner_position && kart_amount > opponents ) @@ -525,8 +524,7 @@ void World::terminateRace() for(unsigned int i = 0; i < kart_amount; i++) { // Retrieve the current player - StateManager::ActivePlayer* p = m_karts[i]->getController()->getPlayer(); - if (p && p->getConstProfile() == PlayerManager::getCurrentPlayer()) + if (m_karts[i]->getController()->canGetAchievements()) { // Check if the player has won if (m_karts[i]->getPosition() == 1 ) @@ -1091,6 +1089,7 @@ void World::updateHighscores(int* best_highscore_rank) (LocalPlayerController*)(k->getController()); int highscore_rank = 0; + // The player is a local player, so it is sure that getPlayer() exists. if (controller->getPlayer()->getProfile() != NULL) // if we have the player profile here highscore_rank = highscores->addData(k->getIdent(), controller->getPlayer()->getProfile()->getName(), diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index 216d74998..dec3565b1 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -307,15 +307,14 @@ void Physics::update(float dt) // Check for achievements AbstractKart * kart = World::getWorld()->getKart(f->getOwnerId()); - LocalPlayerController *c = + LocalPlayerController *lpc = dynamic_cast(kart->getController()); // Check that it's not a kart hitting itself (this can // happen at the time a flyable is shot - release too close // to the kart, and it's the current player. At this stage // only the current player can get achievements. - if (target_kart != kart && c && - c->getPlayer()->getConstProfile() == PlayerManager::getCurrentPlayer()) + if (target_kart != kart && lpc && lpc->canGetAchievements()) { // Compare the current value of hits with the 'hit' goal value // (otherwise it would be compared with the kart id goal value, diff --git a/src/states_screens/race_result_gui.cpp b/src/states_screens/race_result_gui.cpp index 01e9ace29..4ab8bb9aa 100644 --- a/src/states_screens/race_result_gui.cpp +++ b/src/states_screens/race_result_gui.cpp @@ -476,8 +476,6 @@ void RaceResultGUI::determineTableLayout() RowInfo *ri = &(m_all_row_infos[position-first_position]); ri->m_is_player_kart = kart->getController()->isLocalPlayerController(); ri->m_kart_name = translations->fribidize(kart->getName()); - ri->m_player = ri->m_is_player_kart - ? kart->getController()->getPlayer() : NULL; video::ITexture *icon = kart->getKartProperties()->getIconMaterial()->getTexture(); @@ -844,8 +842,6 @@ void RaceResultGUI::determineGPLayout() kart->getKartProperties()->getIconMaterial()->getTexture(); ri->m_kart_name = translations->fribidize(kart->getName()); ri->m_is_player_kart = kart->getController()->isLocalPlayerController(); - ri->m_player = ri->m_is_player_kart - ? kart->getController()->getPlayer() : NULL; // In FTL karts do have a time, which is shown even when the kart // is eliminated diff --git a/src/states_screens/race_result_gui.hpp b/src/states_screens/race_result_gui.hpp index ed4cb1a6a..8b6a4e37e 100644 --- a/src/states_screens/race_result_gui.hpp +++ b/src/states_screens/race_result_gui.hpp @@ -82,8 +82,6 @@ private: float m_y_pos; /** True if kart is a player kart. */ bool m_is_player_kart; - /** Only if m_is_player_kart is true */ - const StateManager::ActivePlayer* m_player; /** The radius to use when sorting the entries. Positive values will rotate downwards, negatives are upwards. */ float m_radius;