This commit is contained in:
Benau 2018-11-27 14:45:23 +08:00
parent 9e066706aa
commit e5c601b35e
3 changed files with 45 additions and 2 deletions

View File

@ -39,7 +39,7 @@
#include "karts/controller/controller.hpp"
#include "karts/explosion_animation.hpp"
#include "karts/kart_properties.hpp"
#include "modes/world.hpp"
#include "modes/capture_the_flag.hpp"
#include "network/network_config.hpp"
#include "network/rewind_info.hpp"
#include "network/rewind_manager.hpp"
@ -369,6 +369,13 @@ void Swatter::squashThingsAround()
World::getWorld()->kartHit(m_closest_kart->getWorldKartId(),
m_kart->getWorldKartId());
CaptureTheFlag* ctf = dynamic_cast<CaptureTheFlag*>(World::getWorld());
if (ctf)
{
int reset_ticks = (ctf->getTicksSinceStart() / 10) * 10 + 80;
ctf->resetKartForSwatterHit(m_closest_kart->getWorldKartId(),
reset_ticks);
}
// Handle achievement if the swatter is used by the current player
if (m_kart->getController()->canGetAchievements())
{

View File

@ -18,6 +18,7 @@
#include "modes/capture_the_flag.hpp"
#include "audio/sfx_base.hpp"
#include "io/file_manager.hpp"
#include "items/powerup.hpp"
#include "graphics/irr_driver.hpp"
#include "karts/abstract_kart.hpp"
#include "karts/controller/controller.hpp"
@ -115,6 +116,7 @@ void CaptureTheFlag::reset(bool restart)
m_blue_scores = 0;
m_red_holder = m_blue_holder = -1;
updateFlagNodes();
m_swatter_reset_kart_ticks.clear();
} // reset
// ----------------------------------------------------------------------------
@ -157,6 +159,36 @@ void CaptureTheFlag::update(int ticks)
FreeForAll::update(ticks);
for (auto it = m_swatter_reset_kart_ticks.begin();
it != m_swatter_reset_kart_ticks.end();)
{
if (it->second < getTicksSinceStart() - 1000)
{
it = m_swatter_reset_kart_ticks.erase(it);
}
else
{
if (it->second == getTicksSinceStart())
{
AbstractKart* kart = m_karts[it->first].get();
if (kart->isEliminated() || !kart->isSquashed())
{
it++;
continue;
}
unsigned int index = getRescuePositionIndex(kart);
btTransform t = getRescueTransform(index);
t.setOrigin(t.getOrigin() + t.getBasis().getColumn(1) * 3.0f);
kart->getBody()->setLinearVelocity(Vec3(0.0f));
kart->getBody()->setAngularVelocity(Vec3(0.0f));
kart->getBody()->proceedToTransform(t);
kart->setTrans(t);
kart->getPowerup()->reset();
}
it++;
}
}
if (!NetworkConfig::get()->isNetworking() ||
NetworkConfig::get()->isClient())
return;

View File

@ -54,6 +54,8 @@ private:
int m_red_return_ticks, m_blue_return_ticks;
std::map<int, int> m_swatter_reset_kart_ticks;
// ------------------------------------------------------------------------
void updateFlagNodes();
// ------------------------------------------------------------------------
@ -133,7 +135,9 @@ public:
const Vec3& getBlueFlag() const { return (Vec3&)m_blue_trans.getOrigin(); }
// ------------------------------------------------------------------------
void loseFlagForKart(int kart_id);
// ------------------------------------------------------------------------
void resetKartForSwatterHit(int kart_id, int at_world_ticks)
{ m_swatter_reset_kart_ticks[kart_id] = at_world_ticks; }
}; // CaptureTheFlag
#endif