From 552028e7914cde20088a1ad94a8b8e8171474978 Mon Sep 17 00:00:00 2001 From: Benau Date: Mon, 20 Aug 2018 14:33:17 +0800 Subject: [PATCH] Put the kart back to its own flag base like rescue if direct hit in CTF --- src/graphics/camera_normal.cpp | 4 +- src/karts/explosion_animation.cpp | 67 ++++++++++++++++++++++++------- src/karts/explosion_animation.hpp | 9 +++++ src/karts/rescue_animation.cpp | 14 ------- src/modes/capture_the_flag.cpp | 11 +++-- src/modes/capture_the_flag.hpp | 5 ++- 6 files changed, 76 insertions(+), 34 deletions(-) diff --git a/src/graphics/camera_normal.cpp b/src/graphics/camera_normal.cpp index 4e1064509..5c158b0f4 100644 --- a/src/graphics/camera_normal.cpp +++ b/src/graphics/camera_normal.cpp @@ -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(m_kart->getKartAnimation())) + ExplosionAnimation* ea = + dynamic_cast(m_kart->getKartAnimation()); + if (ea && !ea->hasResetAlready()) { float above_kart, cam_angle, side_way, distance; bool smoothing; diff --git a/src/karts/explosion_animation.cpp b/src/karts/explosion_animation.cpp index 8fcb2efd8..b488d288f 100644 --- a/src/karts/explosion_animation.cpp +++ b/src/karts/explosion_animation.cpp @@ -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 //----------------------------------------------------------------------------- @@ -156,8 +178,8 @@ ExplosionAnimation::~ExplosionAnimation() void ExplosionAnimation::update(int ticks) { float dt = stk_config->ticks2Time(ticks); - m_velocity -= dt*Track::getCurrentTrack()->getGravity(); - m_xyz = m_xyz + dt*m_velocity*m_normal; + m_velocity -= dt * Track::getCurrentTrack()->getGravity(); + m_xyz = m_xyz + dt * m_velocity * m_normal; // Make sure the kart does not end up under the track if ((m_xyz - m_orig_xyz).dot(m_normal)<0) @@ -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; + m_curr_rotation += dt * m_add_rotation; btQuaternion q(m_curr_rotation.getHeading(), m_curr_rotation.getPitch(), m_curr_rotation.getRoll()); - m_kart->setRotation(q); + + 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 diff --git a/src/karts/explosion_animation.hpp b/src/karts/explosion_animation.hpp index 0014bfd50..c79424ee9 100644 --- a/src/karts/explosion_animation.hpp +++ b/src/karts/explosion_animation.hpp @@ -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 diff --git a/src/karts/rescue_animation.cpp b/src/karts/rescue_animation.cpp index 12b746131..18c8a8459 100644 --- a/src/karts/rescue_animation.cpp +++ b/src/karts/rescue_animation.cpp @@ -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 -#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(Camera::getCamera(i)); - if (camera && camera->getKart() == m_kart && - dynamic_cast(camera)) - { - camera->setMode(Camera::CM_NORMAL); - camera->snapToPosition(); - } - } - m_up_vector = m_kart->getTrans().getBasis().getColumn(1); m_xyz = m_kart->getXYZ(); diff --git a/src/modes/capture_the_flag.cpp b/src/modes/capture_the_flag.cpp index ccae50c3b..6150cc374 100644 --- a/src/modes/capture_the_flag.cpp +++ b/src/modes/capture_the_flag.cpp @@ -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 diff --git a/src/modes/capture_the_flag.hpp b/src/modes/capture_the_flag.hpp index 5db592c3b..29046db13 100644 --- a/src/modes/capture_the_flag.hpp +++ b/src/modes/capture_the_flag.hpp @@ -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);