Put the kart back to its own flag base like rescue if direct hit in CTF
This commit is contained in:
parent
d885a87600
commit
552028e791
@ -248,7 +248,9 @@ void CameraNormal::update(float dt)
|
||||
|
||||
// If an explosion is happening, stop moving the camera,
|
||||
// but keep it target on the kart.
|
||||
if (dynamic_cast<ExplosionAnimation*>(m_kart->getKartAnimation()))
|
||||
ExplosionAnimation* ea =
|
||||
dynamic_cast<ExplosionAnimation*>(m_kart->getKartAnimation());
|
||||
if (ea && !ea->hasResetAlready())
|
||||
{
|
||||
float above_kart, cam_angle, side_way, distance;
|
||||
bool smoothing;
|
||||
|
@ -75,14 +75,11 @@ ExplosionAnimation::ExplosionAnimation(AbstractKart *kart,
|
||||
bool direct_hit)
|
||||
: AbstractKartAnimation(kart, "ExplosionAnimation")
|
||||
{
|
||||
m_end_transform = m_kart->getTrans();
|
||||
m_xyz = m_kart->getXYZ();
|
||||
m_orig_xyz = m_xyz;
|
||||
m_normal = m_kart->getNormal();
|
||||
m_kart->playCustomSFX(SFXManager::CUSTOM_EXPLODE);
|
||||
m_direct_hit = direct_hit;
|
||||
m_reset_ticks = -1;
|
||||
float timer = m_kart->getKartProperties()->getExplosionDuration();
|
||||
m_timer = stk_config->time2Ticks(timer);
|
||||
m_direct_hit = direct_hit;
|
||||
m_normal = m_kart->getNormal();
|
||||
|
||||
// Non-direct hits will be only affected half as much.
|
||||
if (!m_direct_hit)
|
||||
@ -91,6 +88,33 @@ ExplosionAnimation::ExplosionAnimation(AbstractKart *kart,
|
||||
m_timer /= 2;
|
||||
}
|
||||
|
||||
// Put the kart back to its own flag base like rescue if direct hit in CTF
|
||||
if (race_manager->getMajorMode() ==
|
||||
RaceManager::MAJOR_MODE_CAPTURE_THE_FLAG && m_direct_hit)
|
||||
{
|
||||
m_reset_ticks = stk_config->time2Ticks(timer * 0.2f);
|
||||
}
|
||||
|
||||
if (m_reset_ticks != -1)
|
||||
{
|
||||
m_xyz = m_kart->getXYZ();
|
||||
m_orig_xyz = m_xyz;
|
||||
btTransform prev_trans = kart->getTrans();
|
||||
World::getWorld()->moveKartAfterRescue(kart);
|
||||
m_end_transform = kart->getTrans();
|
||||
m_reset_xyz = m_end_transform.getOrigin();
|
||||
m_reset_normal = m_end_transform.getBasis().getColumn(1);
|
||||
kart->getBody()->setCenterOfMassTransform(prev_trans);
|
||||
kart->setTrans(prev_trans);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_end_transform = m_kart->getTrans();
|
||||
m_xyz = m_kart->getXYZ();
|
||||
m_orig_xyz = m_xyz;
|
||||
}
|
||||
m_kart->playCustomSFX(SFXManager::CUSTOM_EXPLODE);
|
||||
|
||||
if (NetworkConfig::get()->isNetworking() &&
|
||||
NetworkConfig::get()->isServer())
|
||||
{
|
||||
@ -124,9 +148,7 @@ ExplosionAnimation::ExplosionAnimation(AbstractKart *kart,
|
||||
|
||||
m_kart->getAttachment()->clear();
|
||||
// Clear powerups when direct hit in CTF
|
||||
addNetworkAnimationChecker(m_direct_hit &&
|
||||
race_manager->getMajorMode() ==
|
||||
RaceManager::MAJOR_MODE_CAPTURE_THE_FLAG);
|
||||
addNetworkAnimationChecker(m_reset_ticks != -1);
|
||||
} // ExplosionAnimation
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -167,11 +189,28 @@ void ExplosionAnimation::update(int ticks)
|
||||
if (!NetworkConfig::get()->isNetworking())
|
||||
m_timer = -1;
|
||||
}
|
||||
m_kart->setXYZ(m_xyz);
|
||||
m_curr_rotation += dt * m_add_rotation;
|
||||
btQuaternion q(m_curr_rotation.getHeading(), m_curr_rotation.getPitch(),
|
||||
m_curr_rotation.getRoll());
|
||||
|
||||
if (m_reset_ticks != -1)
|
||||
{
|
||||
m_reset_xyz = m_reset_xyz + dt * m_velocity * m_reset_normal;
|
||||
if ((m_reset_xyz - m_end_transform.getOrigin()).dot(m_reset_normal) <
|
||||
0.0f)
|
||||
m_reset_xyz = m_end_transform.getOrigin();
|
||||
}
|
||||
if (m_reset_ticks != -1 && m_timer < m_reset_ticks)
|
||||
{
|
||||
m_kart->setXYZ(m_reset_xyz);
|
||||
m_kart->setRotation(m_end_transform.getRotation());
|
||||
m_kart->getBody()->setCenterOfMassTransform(m_kart->getTrans());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_kart->setXYZ(m_xyz);
|
||||
m_kart->setRotation(q);
|
||||
}
|
||||
|
||||
AbstractKartAnimation::update(ticks);
|
||||
} // update
|
||||
|
@ -66,6 +66,13 @@ protected:
|
||||
|
||||
bool m_direct_hit;
|
||||
|
||||
/** If not -1, when > m_timer it will use m_reset_xyz below for
|
||||
* animation. */
|
||||
int m_reset_ticks;
|
||||
|
||||
/** Used for reset kart back to flag base in CTF. */
|
||||
Vec3 m_reset_xyz, m_reset_normal;
|
||||
|
||||
ExplosionAnimation(AbstractKart *kart);
|
||||
ExplosionAnimation(AbstractKart *kart, const Vec3 &pos,
|
||||
bool direct_hit);
|
||||
@ -76,5 +83,7 @@ public:
|
||||
|
||||
virtual ~ExplosionAnimation();
|
||||
virtual void update(int ticks);
|
||||
bool hasResetAlready() const
|
||||
{ return m_reset_ticks != -1 && m_timer < m_reset_ticks; }
|
||||
}; // ExplosionAnimation
|
||||
#endif
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include "karts/rescue_animation.hpp"
|
||||
|
||||
#include "config/user_config.hpp"
|
||||
#include "graphics/camera.hpp"
|
||||
#include "graphics/referee.hpp"
|
||||
#include "items/attachment.hpp"
|
||||
#include "karts/abstract_kart.hpp"
|
||||
@ -37,7 +36,6 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "graphics/camera_normal.hpp"
|
||||
/** The constructor stores a pointer to the kart this object is animating,
|
||||
* and initialised the timer.
|
||||
* \param kart Pointer to the kart which is animated.
|
||||
@ -144,18 +142,6 @@ void RescueAnimation::update(int ticks)
|
||||
m_kart_on_track = true;
|
||||
m_kart->getBody()->setCenterOfMassTransform(m_end_transform);
|
||||
m_kart->setTrans(m_end_transform);
|
||||
for (unsigned int i = 0; i < Camera::getNumCameras(); i++)
|
||||
{
|
||||
CameraNormal* camera =
|
||||
dynamic_cast<CameraNormal*>(Camera::getCamera(i));
|
||||
if (camera && camera->getKart() == m_kart &&
|
||||
dynamic_cast<CameraNormal*>(camera))
|
||||
{
|
||||
camera->setMode(Camera::CM_NORMAL);
|
||||
camera->snapToPosition();
|
||||
}
|
||||
}
|
||||
|
||||
m_up_vector = m_kart->getTrans().getBasis().getColumn(1);
|
||||
m_xyz = m_kart->getXYZ();
|
||||
|
||||
|
@ -379,7 +379,7 @@ void CaptureTheFlag::resetFlag(NetworkString& ns)
|
||||
else
|
||||
{
|
||||
btTransform t = m_orig_blue_trans;
|
||||
// I18N: Show when the red flag is returned to its base in CTF
|
||||
// I18N: Show when the blue flag is returned to its base in CTF
|
||||
if (!with_custom_transform)
|
||||
returned_msg = _("The blue flag has returned!");
|
||||
else
|
||||
@ -401,7 +401,6 @@ void CaptureTheFlag::resetFlag(NetworkString& ns)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
bool CaptureTheFlag::getDroppedFlagTrans(const btTransform& kt,
|
||||
bool red_flag,
|
||||
btTransform* out) const
|
||||
{
|
||||
Vec3 from = kt.getOrigin() + kt.getBasis().getColumn(1);
|
||||
@ -459,7 +458,7 @@ bool CaptureTheFlag::kartHit(int kart_id, int hitter)
|
||||
btTransform dropped_trans = reset_red_flag ?
|
||||
m_orig_red_trans : m_orig_blue_trans;
|
||||
bool succeed = getDroppedFlagTrans(
|
||||
getKart(kart_id)->getTrans(), reset_red_flag, &dropped_trans);
|
||||
getKart(kart_id)->getTrans(), &dropped_trans);
|
||||
NetworkString p(PROTOCOL_GAME_EVENTS);
|
||||
p.setSynchronous(true);
|
||||
// If reset red flag
|
||||
@ -489,3 +488,9 @@ bool CaptureTheFlag::kartHit(int kart_id, int hitter)
|
||||
}
|
||||
return true;
|
||||
} // kartHit
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
unsigned int CaptureTheFlag::getRescuePositionIndex(AbstractKart *kart)
|
||||
{
|
||||
return m_kart_position_map.at(kart->getWorldKartId());
|
||||
} // getRescuePositionIndex
|
||||
|
@ -51,8 +51,7 @@ private:
|
||||
// ------------------------------------------------------------------------
|
||||
void updateFlagNodes();
|
||||
// ------------------------------------------------------------------------
|
||||
bool getDroppedFlagTrans(const btTransform& kt, bool red_flag,
|
||||
btTransform* out) const;
|
||||
bool getDroppedFlagTrans(const btTransform& kt, btTransform* out) const;
|
||||
// ------------------------------------------------------------------------
|
||||
virtual video::SColor getColor(unsigned int kart_id) const OVERRIDE;
|
||||
|
||||
@ -76,6 +75,8 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
virtual bool kartHit(int kart_id, int hitter = -1) OVERRIDE;
|
||||
// ------------------------------------------------------------------------
|
||||
virtual unsigned int getRescuePositionIndex(AbstractKart *kart) OVERRIDE;
|
||||
// ------------------------------------------------------------------------
|
||||
void attachFlag(NetworkString& ns);
|
||||
// ------------------------------------------------------------------------
|
||||
void resetFlag(NetworkString& ns);
|
||||
|
Loading…
Reference in New Issue
Block a user