diff --git a/src/items/attachment.cpp b/src/items/attachment.cpp index 3f22ad2c3..0dd1ddf0f 100644 --- a/src/items/attachment.cpp +++ b/src/items/attachment.cpp @@ -311,8 +311,6 @@ void Attachment::rewindTo(BareNetworkString *buffer) if (m_type == new_type) { setTicksLeft(ticks_left); - if (m_type != new_type && new_type != ATTACH_SWATTER) - m_type = new_type; return; } @@ -536,13 +534,19 @@ void Attachment::update(int ticks) m_node->setVisible((division & 0x1) == 0); } - if(m_plugin) + if (m_plugin) { - bool discard = m_plugin->updateAndTestFinished(ticks); - if(discard) + int discard_ticks = m_plugin->updateAndTestFinished(ticks); + if (discard_ticks != -1) { - clear(); // also removes the plugin - return; + // Save it for rewinding + m_ticks_left = + discard_ticks - World::getWorld()->getTicksSinceStart(); + if (m_ticks_left <= 0) + { + clear(); // also removes the plugin + return; + } } } diff --git a/src/items/attachment_plugin.hpp b/src/items/attachment_plugin.hpp index 49eaa8197..7394d1180 100644 --- a/src/items/attachment_plugin.hpp +++ b/src/items/attachment_plugin.hpp @@ -53,8 +53,9 @@ public: // ------------------------------------------------------------------------ /** Updates a plugin. This is called once each time frame. If the - * function returns true, the attachment is discarded. */ - virtual bool updateAndTestFinished(int ticks) = 0; + * function returns a non-negative number, the attachment is discarded + * when world ticks >= that number. */ + virtual int updateAndTestFinished(int ticks) = 0; // ------------------------------------------------------------------------ /** Called when the animation of the Attachment's node is done. */ diff --git a/src/items/swatter.cpp b/src/items/swatter.cpp index 6d5eab858..b5d61a450 100644 --- a/src/items/swatter.cpp +++ b/src/items/swatter.cpp @@ -161,20 +161,20 @@ void Swatter::updateGrahpics(float dt) /** Updates an armed swatter: it checks for any karts that are close enough * and not invulnerable, it swats the kart. * \param dt Time step size. - * \return True if the attachment should be discarded. + * \return World ticks to discard the swatter. */ -bool Swatter::updateAndTestFinished(int ticks) +int Swatter::updateAndTestFinished(int ticks) { const int ticks_start = World::getWorld()->getTicksSinceStart(); if (m_removed_bomb_ticks != std::numeric_limits::max()) { if (ticks_start >= m_removed_bomb_ticks) - return true; - return false; + return m_removed_bomb_ticks; + return -1; } // if removing bomb if (RewindManager::get()->isRewinding()) - return false; + return -1; if (!m_discard_now) { @@ -186,7 +186,7 @@ bool Swatter::updateAndTestFinished(int ticks) // to make sure all clients know the existence of swatter each other if (ticks_start - m_swatter_start_ticks < 60 || m_swatter_end_ticks - ticks_start < 60) - return false; + return -1; chooseTarget(); pointToTarget(); @@ -258,15 +258,15 @@ bool Swatter::updateAndTestFinished(int ticks) if (m_discard_now) { - return ticks_start > m_end_swat_ticks; + return m_end_swat_ticks; } else if (ticks_start > m_end_swat_ticks) { m_animation_phase = SWATTER_AIMING; m_end_swat_ticks = std::numeric_limits::max(); - return false; + return -1; } - return false; + return -1; } // updateAndTestFinished // ---------------------------------------------------------------------------- diff --git a/src/items/swatter.hpp b/src/items/swatter.hpp index 24e089ba5..1c2166d3a 100644 --- a/src/items/swatter.hpp +++ b/src/items/swatter.hpp @@ -87,7 +87,7 @@ public: scene::ISceneNode* bomb_scene_node, int ticks); virtual ~Swatter(); void updateGrahpics(float dt) OVERRIDE; - bool updateAndTestFinished(int ticks) OVERRIDE; + int updateAndTestFinished(int ticks) OVERRIDE; // ------------------------------------------------------------------------ /** Returns if the swatter is currently aiming, i.e. can be used to