Split squashed timer and squashed status
This commit is contained in:
@@ -91,6 +91,7 @@
|
||||
|
||||
#include <algorithm> // for min and max
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
#include <cmath>
|
||||
|
||||
|
||||
@@ -129,7 +130,7 @@ Kart::Kart (const std::string& ident, unsigned int world_kart_id,
|
||||
m_bubblegum_ticks = 0;
|
||||
m_bubblegum_torque = 0.0f;
|
||||
m_invulnerable_ticks = 0;
|
||||
m_squash_ticks = 0;
|
||||
m_squash_time = std::numeric_limits<float>::max();
|
||||
|
||||
m_shadow = NULL;
|
||||
m_wheel_box = NULL;
|
||||
@@ -366,7 +367,7 @@ void Kart::reset()
|
||||
m_bubblegum_ticks = 0;
|
||||
m_bubblegum_torque = 0.0f;
|
||||
m_invulnerable_ticks = 0;
|
||||
m_squash_ticks = 0;
|
||||
m_squash_time = std::numeric_limits<float>::max();
|
||||
m_node->setScale(core::vector3df(1.0f, 1.0f, 1.0f));
|
||||
m_collected_energy = 0;
|
||||
m_has_started = false;
|
||||
@@ -1275,28 +1276,6 @@ void Kart::update(int ticks)
|
||||
// Reset any instand speed increase in the bullet kart
|
||||
m_vehicle->setMinSpeed(0);
|
||||
|
||||
if(m_squash_ticks>=0)
|
||||
{
|
||||
m_squash_ticks-=ticks;
|
||||
// If squasing time ends, reset the model
|
||||
if(m_squash_ticks<=0)
|
||||
{
|
||||
m_node->setScale(core::vector3df(1.0f, 1.0f, 1.0f));
|
||||
scene::ISceneNode* node =
|
||||
m_kart_model->getAnimatedNode() ?
|
||||
m_kart_model->getAnimatedNode() : m_node;
|
||||
if (m_vehicle->getNumWheels() > 0)
|
||||
{
|
||||
scene::ISceneNode **wheels = m_kart_model->getWheelNodes();
|
||||
for (int i = 0; i < 4 && i < m_vehicle->getNumWheels(); ++i)
|
||||
{
|
||||
if (wheels[i])
|
||||
wheels[i]->setParent(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // if squashed
|
||||
|
||||
if (m_bubblegum_ticks > 0)
|
||||
{
|
||||
m_bubblegum_ticks -= ticks;
|
||||
@@ -1752,23 +1731,42 @@ void Kart::setSquash(float time, float slowdown)
|
||||
ExplosionAnimation::create(this);
|
||||
return;
|
||||
}
|
||||
m_node->setScale(core::vector3df(1.0f, 0.5f, 1.0f));
|
||||
|
||||
m_max_speed->setSlowdown(MaxSpeed::MS_DECREASE_SQUASH, slowdown,
|
||||
stk_config->time2Ticks(0.1f),
|
||||
stk_config->time2Ticks(time));
|
||||
if (m_vehicle->getNumWheels() > 0)
|
||||
|
||||
#ifndef SERVER_ONLY
|
||||
if (m_squash_time == std::numeric_limits<float>::max())
|
||||
{
|
||||
if (!m_wheel_box)
|
||||
m_wheel_box = irr_driver->getSceneManager()->addDummyTransformationSceneNode(m_node);
|
||||
scene::ISceneNode **wheels = m_kart_model->getWheelNodes();
|
||||
for (int i = 0; i < 4 && i < m_vehicle->getNumWheels(); ++i)
|
||||
m_node->setScale(core::vector3df(1.0f, 0.5f, 1.0f));
|
||||
if (m_vehicle->getNumWheels() > 0)
|
||||
{
|
||||
if (wheels[i])
|
||||
wheels[i]->setParent(m_wheel_box);
|
||||
if (!m_wheel_box)
|
||||
{
|
||||
m_wheel_box = irr_driver->getSceneManager()
|
||||
->addDummyTransformationSceneNode(m_node);
|
||||
}
|
||||
scene::ISceneNode **wheels = m_kart_model->getWheelNodes();
|
||||
for (int i = 0; i < 4 && i < m_vehicle->getNumWheels(); i++)
|
||||
{
|
||||
if (wheels[i])
|
||||
wheels[i]->setParent(m_wheel_box);
|
||||
}
|
||||
m_wheel_box->getRelativeTransformationMatrix()
|
||||
.setScale(core::vector3df(1.0f, 2.0f, 1.0f));
|
||||
}
|
||||
m_wheel_box->getRelativeTransformationMatrix().setScale(core::vector3df(1.0f, 2.0f, 1.0f));
|
||||
m_squash_time = time;
|
||||
}
|
||||
m_squash_ticks = stk_config->time2Ticks(time);
|
||||
#endif
|
||||
} // setSquash
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Returns if the kart is currently being squashed
|
||||
*/
|
||||
bool Kart::isSquashed() const
|
||||
{
|
||||
return m_max_speed->isSpeedDecreaseActive(MaxSpeed::MS_DECREASE_SQUASH);
|
||||
} // setSquash
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -2941,6 +2939,30 @@ void Kart::updateGraphics(float dt)
|
||||
if (m_custom_sounds[n] != NULL) m_custom_sounds[n]->position(getXYZ());
|
||||
}
|
||||
*/
|
||||
|
||||
if (m_squash_time != std::numeric_limits<float>::max())
|
||||
{
|
||||
m_squash_time -= dt;
|
||||
// If squasing time ends, reset the model
|
||||
if (m_squash_time <= 0.0f)
|
||||
{
|
||||
m_squash_time = std::numeric_limits<float>::max();
|
||||
m_node->setScale(core::vector3df(1.0f, 1.0f, 1.0f));
|
||||
scene::ISceneNode* node =
|
||||
m_kart_model->getAnimatedNode() ?
|
||||
m_kart_model->getAnimatedNode() : m_node;
|
||||
if (m_vehicle->getNumWheels() > 0)
|
||||
{
|
||||
scene::ISceneNode **wheels = m_kart_model->getWheelNodes();
|
||||
for (int i = 0; i < 4 && i < m_vehicle->getNumWheels(); ++i)
|
||||
{
|
||||
if (wheels[i])
|
||||
wheels[i]->setParent(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // if squashed
|
||||
|
||||
for (int i = 0; i < EMITTER_COUNT; i++)
|
||||
m_emitters[i]->setPosition(getXYZ());
|
||||
m_skid_sound->setPosition(getXYZ());
|
||||
|
||||
@@ -164,7 +164,7 @@ protected:
|
||||
|
||||
/** How long a kart is being squashed. If this is >0
|
||||
* the kart is squashed. */
|
||||
int16_t m_squash_ticks;
|
||||
float m_squash_time;
|
||||
|
||||
/** Current leaning of the kart. */
|
||||
float m_current_lean;
|
||||
@@ -496,7 +496,7 @@ public:
|
||||
virtual bool isOnMinNitroTime() const OVERRIDE { return m_min_nitro_ticks > 0; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns if the kart is currently being squashed. */
|
||||
virtual bool isSquashed() const OVERRIDE { return m_squash_ticks >0; }
|
||||
virtual bool isSquashed() const OVERRIDE;
|
||||
// ------------------------------------------------------------------------
|
||||
/** Shows the star effect for a certain time. */
|
||||
virtual void showStarEffect(float t) OVERRIDE;
|
||||
|
||||
@@ -146,7 +146,6 @@ BareNetworkString* KartRewinder::saveState(std::vector<std::string>* ru)
|
||||
// 6) Firing and related handling
|
||||
// -----------
|
||||
buffer->addUInt16(m_bubblegum_ticks);
|
||||
buffer->addUInt16(m_squash_ticks);
|
||||
buffer->addUInt16(m_view_blocked_by_plunger);
|
||||
// m_invulnerable_ticks will not be negative
|
||||
uint16_t fire_and_invulnerable = (m_fire_clicked ? 1 << 15 : 0) |
|
||||
@@ -223,7 +222,6 @@ void KartRewinder::restoreState(BareNetworkString *buffer, int count)
|
||||
// 6) Firing and related handling
|
||||
// -----------
|
||||
m_bubblegum_ticks = buffer->getUInt16();
|
||||
m_squash_ticks = buffer->getUInt16();
|
||||
m_view_blocked_by_plunger = buffer->getUInt16();
|
||||
uint16_t fire_and_invulnerable = buffer->getUInt16();
|
||||
m_fire_clicked = (fire_and_invulnerable >> 15) == 1;
|
||||
|
||||
@@ -280,6 +280,15 @@ int MaxSpeed::getSpeedIncreaseTicksLeft(unsigned int category)
|
||||
return m_speed_increase[category].getTimeLeft();
|
||||
} // getSpeedIncreaseTimeLeft
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Returns if decreased speed is active in the given category.
|
||||
* \param category Which category to report on.
|
||||
*/
|
||||
int MaxSpeed::isSpeedDecreaseActive(unsigned int category)
|
||||
{
|
||||
return m_speed_decrease[category].isActive();
|
||||
} // isSpeedDecreaseActive
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Updates all speed increase and decrease objects, and determines the
|
||||
* current maximum speed. Note that the function can be called with
|
||||
|
||||
@@ -158,11 +158,13 @@ private:
|
||||
// --------------------------------------------------------------------
|
||||
/** Returns the current slowdown fracftion, taking a 'fade in'
|
||||
* into account. */
|
||||
float getSlowdownFraction() const {return m_current_fraction;}
|
||||
float getSlowdownFraction() const { return m_current_fraction; }
|
||||
// --------------------------------------------------------------------
|
||||
int getTimeLeft() const { return m_duration; }
|
||||
// --------------------------------------------------------------------
|
||||
/** Returns if this speed decrease is active atm. A duration of
|
||||
* -1 indicates an ongoing effect. */
|
||||
bool isActive() const { return m_duration > 0 || m_duration <= -1.0f; }
|
||||
bool isActive() const { return m_duration > 0 || m_duration <= -1; }
|
||||
}; // SpeedDecrease
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
@@ -188,6 +190,7 @@ public:
|
||||
void setSlowdown(unsigned int category, float max_speed_fraction,
|
||||
int fade_in_time, int duration=-1);
|
||||
int getSpeedIncreaseTicksLeft(unsigned int category);
|
||||
int isSpeedDecreaseActive(unsigned int category);
|
||||
void update(int ticks);
|
||||
void reset();
|
||||
void saveState(BareNetworkString *buffer) const;
|
||||
|
||||
Reference in New Issue
Block a user