From 2cb1f1fc78eee0a4b83178cea30494a33e54f6a4 Mon Sep 17 00:00:00 2001 From: hiker Date: Mon, 24 Feb 2014 23:25:56 +1100 Subject: [PATCH] Let only hits from the current player trigger an achievement. --- src/physics/physics.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index ffdbb1aa5..52c8b6b25 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -28,6 +28,7 @@ #include "items/flyable.hpp" #include "karts/kart_properties.hpp" #include "karts/rescue_animation.hpp" +#include "karts/controller/player_controller.hpp" #include "modes/soccer_world.hpp" #include "modes/world.hpp" #include "karts/explosion_animation.hpp" @@ -258,12 +259,26 @@ void Physics::update(float dt) PowerupManager::PowerupType type = p->getUserPointer(0)->getPointerFlyable()->getType(); if(type != PowerupManager::POWERUP_BOWLING || !target_kart->isInvulnerable()) { - p->getUserPointer(0)->getPointerFlyable()->hit(target_kart); + Flyable *f = p->getUserPointer(0)->getPointerFlyable(); + f->hit(target_kart); + + // Implement strike achievement if (type == PowerupManager::POWERUP_BOWLING) { - PlayerManager::increaseAchievement( - AchievementInfo::ACHIEVE_STRIKE, "ball", 1); - } + // + AbstractKart * kart = World::getWorld()->getKart(f->getOwnerId()); + PlayerController *c = dynamic_cast(kart->getController()); + // Check that it's not a kart hitting itself (this can + // happen at the time the ball 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::get()->getCurrentPlayer()) + { + PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_STRIKE, + "ball", 1); + } // if target_kart != kart && is a player kart and is current player + } // is bowling ball } }