From 124324a13312b45ae10c32ec24cac73c60251771 Mon Sep 17 00:00:00 2001 From: Benau Date: Mon, 20 Aug 2018 13:03:20 +0800 Subject: [PATCH] Clear powerups when rescue or direct hit in CTF --- src/karts/abstract_kart_animation.cpp | 20 ++++++++++++++++++-- src/karts/abstract_kart_animation.hpp | 2 +- src/karts/explosion_animation.cpp | 10 +++++++--- src/karts/explosion_animation.hpp | 2 ++ src/karts/rescue_animation.cpp | 4 +++- 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/karts/abstract_kart_animation.cpp b/src/karts/abstract_kart_animation.cpp index 2d52f2912..e7250392a 100644 --- a/src/karts/abstract_kart_animation.cpp +++ b/src/karts/abstract_kart_animation.cpp @@ -19,6 +19,7 @@ #include "karts/abstract_kart_animation.hpp" #include "graphics/slip_stream.hpp" +#include "items/powerup.hpp" #include "karts/abstract_kart.hpp" #include "karts/kart_model.hpp" #include "karts/skidding.hpp" @@ -124,16 +125,31 @@ AbstractKartAnimation::~AbstractKartAnimation() } // ~AbstractKartAnimation // ---------------------------------------------------------------------------- -void AbstractKartAnimation::addNetworkAnimationChecker() +void AbstractKartAnimation::addNetworkAnimationChecker(bool reset_powerup) { + Powerup* p = NULL; + if (reset_powerup) + { + if (m_kart) + { + p = m_kart->getPowerup(); + p->set(PowerupManager::POWERUP_NOTHING); + } + } + if (NetworkConfig::get()->isNetworking() && NetworkConfig::get()->isClient()) { + // Prevent access to deleted kart animation object std::weak_ptr cct = m_check_created_ticks; RewindManager::get()->addRewindInfoEventFunction(new RewindInfoEventFunction(m_created_ticks, [](){}, - [](){}, + /*replay_function*/[p]() + { + if (p) + p->set(PowerupManager::POWERUP_NOTHING); + }, /*delete_function*/[cct]() { auto cct_sp = cct.lock(); diff --git a/src/karts/abstract_kart_animation.hpp b/src/karts/abstract_kart_animation.hpp index b83c23986..8750f4f14 100644 --- a/src/karts/abstract_kart_animation.hpp +++ b/src/karts/abstract_kart_animation.hpp @@ -65,7 +65,7 @@ protected: int m_end_ticks; // ------------------------------------------------------------------------ - void addNetworkAnimationChecker(); + void addNetworkAnimationChecker(bool reset_powerup); public: AbstractKartAnimation(AbstractKart *kart, const std::string &name); diff --git a/src/karts/explosion_animation.cpp b/src/karts/explosion_animation.cpp index 621c460bc..8fcb2efd8 100644 --- a/src/karts/explosion_animation.cpp +++ b/src/karts/explosion_animation.cpp @@ -82,9 +82,10 @@ ExplosionAnimation::ExplosionAnimation(AbstractKart *kart, m_kart->playCustomSFX(SFXManager::CUSTOM_EXPLODE); float timer = m_kart->getKartProperties()->getExplosionDuration(); m_timer = stk_config->time2Ticks(timer); + m_direct_hit = direct_hit; // Non-direct hits will be only affected half as much. - if (!direct_hit) + if (!m_direct_hit) { timer *= 0.5f; m_timer /= 2; @@ -108,7 +109,7 @@ ExplosionAnimation::ExplosionAnimation(AbstractKart *kart, m_curr_rotation.setPitch(m_kart->getPitch()); m_curr_rotation.setRoll(m_kart->getRoll()); - const int max_rotation = direct_hit ? 2 : 1; + const int max_rotation = m_direct_hit ? 2 : 1; // To get rotations in both directions for each axis we determine a random // number between -(max_rotation-1) and +(max_rotation-1) float f = 2.0f * M_PI / timer; @@ -122,7 +123,10 @@ ExplosionAnimation::ExplosionAnimation(AbstractKart *kart, m_kart->showStarEffect(t); m_kart->getAttachment()->clear(); - addNetworkAnimationChecker(); + // Clear powerups when direct hit in CTF + addNetworkAnimationChecker(m_direct_hit && + race_manager->getMajorMode() == + RaceManager::MAJOR_MODE_CAPTURE_THE_FLAG); } // ExplosionAnimation //----------------------------------------------------------------------------- diff --git a/src/karts/explosion_animation.hpp b/src/karts/explosion_animation.hpp index f5bb01b6d..0014bfd50 100644 --- a/src/karts/explosion_animation.hpp +++ b/src/karts/explosion_animation.hpp @@ -64,6 +64,8 @@ protected: * on difficulty (so that on easy you can drive again earlier. */ float m_duration; + bool m_direct_hit; + ExplosionAnimation(AbstractKart *kart); ExplosionAnimation(AbstractKart *kart, const Vec3 &pos, bool direct_hit); diff --git a/src/karts/rescue_animation.cpp b/src/karts/rescue_animation.cpp index be1ab3dae..2387b849b 100644 --- a/src/karts/rescue_animation.cpp +++ b/src/karts/rescue_animation.cpp @@ -113,7 +113,9 @@ RescueAnimation::RescueAnimation(AbstractKart *kart, bool is_auto_rescue) } } - addNetworkAnimationChecker(); + // Clear powerups when rescue in CTF + addNetworkAnimationChecker(race_manager->getMajorMode() == + RaceManager::MAJOR_MODE_CAPTURE_THE_FLAG); } // RescueAnimation //-----------------------------------------------------------------------------