Clear powerups when rescue or direct hit in CTF

This commit is contained in:
Benau 2018-08-20 13:03:20 +08:00
parent eca9ffb508
commit 124324a133
5 changed files with 31 additions and 7 deletions

View File

@ -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<int> 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();

View File

@ -65,7 +65,7 @@ protected:
int m_end_ticks;
// ------------------------------------------------------------------------
void addNetworkAnimationChecker();
void addNetworkAnimationChecker(bool reset_powerup);
public:
AbstractKartAnimation(AbstractKart *kart,
const std::string &name);

View File

@ -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
//-----------------------------------------------------------------------------

View File

@ -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);

View File

@ -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
//-----------------------------------------------------------------------------