Added support for a texture specific minimum speed. This fixes issues with

AI karts (esp. EndController) not being able to do long jumps. Added setting
for minimum speed to Enterprise track (EndController were not able to finish
the jump on the ramp).


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@14710 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk
2013-12-11 22:12:14 +00:00
parent 1a776381d5
commit bce4a075ba
5 changed files with 36 additions and 2 deletions

View File

@@ -137,6 +137,7 @@ Material::Material(const XMLNode *node, int index, bool deprecated)
node->get("additive", &m_add );
node->get("max-speed", &m_max_speed_fraction);
node->get("min-speed", &m_min_speed );
node->get("slowdown-time", &m_slowdown_time );
node->get("backface-culling", &m_backface_culling );
node->get("disable-z-write", &m_disable_z_write );
@@ -386,6 +387,7 @@ void Material::init(unsigned int index)
m_water_shader_speed_2 = 4.0f;
m_fog = true;
m_max_speed_fraction = 1.0f;
m_min_speed = -1.0f;
m_slowdown_time = 1.0f;
m_sfx_name = "";
m_sfx_min_speed = 0.0f;

View File

@@ -173,6 +173,10 @@ private:
float m_slowdown_time;
/** Maximum speed at which no more slow down occurs. */
float m_max_speed_fraction;
/** Minimum speed on this terrain. This is used for zippers on a ramp to
* guarantee the right jump distance. A negative value indicates no
* minimum speed. */
float m_min_speed;
/** The minimum speed at which a special sfx is started to be played. */
float m_sfx_min_speed;
/** The speed at which the maximum pitch is used. */
@@ -266,6 +270,11 @@ public:
/** Returns the fraction of maximum speed on this material. */
float getMaxSpeedFraction() const { return m_max_speed_fraction; }
// ------------------------------------------------------------------------
/** Returns the minimum speed of a kart on this material. This is used
* for zippers on a ramp to guarantee the right jump distance even
* on lower speeds. A negative value indicates no minimum speed. */
float getMinSpeed() const { return m_min_speed; }
// ------------------------------------------------------------------------
/** Returns how long it will take for a slowdown to take effect.
* It is the time it takes till the full slowdown applies to
* karts. So a short time will slowdown a kart much faster. */

View File

@@ -2002,6 +2002,8 @@ void Kart::updatePhysics(float dt)
m_speed *= -1.f;
// Cap speed if necessary
m_max_speed->setMinSpeed(getMaterial() ? getMaterial()->getMinSpeed()
: -1.0f );
m_max_speed->update(dt);
// To avoid tunneling (which can happen on long falls), clamp the

View File

@@ -61,6 +61,8 @@ MaxSpeed::MaxSpeed(AbstractKart *kart)
void MaxSpeed::reset()
{
m_current_max_speed = m_kart->getKartProperties()->getMaxSpeed();
m_min_speed = -1.0f;
for(unsigned int i=MS_DECREASE_MIN; i<MS_DECREASE_MAX; i++)
{
SpeedDecrease sd;
@@ -122,7 +124,12 @@ void MaxSpeed::instantSpeedIncrease(unsigned int category,
// changes to any slow downs since dt=0
update(0);
float speed = std::min(m_kart->getSpeed()+ speed_boost,
MaxSpeed::getCurrentMaxSpeed() );
getCurrentMaxSpeed() );
// If there is a min_speed defined, make sure that the kart is still
// fast enough (otherwise e.g. on easy difficulty even with zipper
// the speed might be too low for certain jumps).
if(speed < m_min_speed) speed = m_min_speed;
m_kart->getVehicle()->instantSpeedIncreaseTo(speed);
@@ -248,7 +255,11 @@ void MaxSpeed::update(float dt)
// Then cap the current speed of the kart
// --------------------------------------
if ( m_kart->getSpeed()>m_current_max_speed && m_kart->isOnGround() )
if(m_min_speed > 0 && m_kart->getSpeed() < m_min_speed)
{
m_kart->getVehicle()->instantSpeedIncreaseTo(m_min_speed);
}
else if ( m_kart->getSpeed()>m_current_max_speed && m_kart->isOnGround() )
m_kart->getVehicle()->capSpeed(m_current_max_speed);
} // update

View File

@@ -56,6 +56,9 @@ private:
/** Additional engine force, summed from all SpeedIncrease engine forces. */
float m_add_engine_force;
/** If >0 then the minimum speed a kart should have (used for zippers). */
float m_min_speed;
// ------------------------------------------------------------------------
/** An internal class to store and handle speed increase related data. */
class SpeedIncrease
@@ -145,6 +148,7 @@ private:
* for each possible category. */
SpeedIncrease m_speed_increase[MS_INCREASE_MAX];
public:
MaxSpeed(AbstractKart *kart);
@@ -161,6 +165,12 @@ public:
void update(float dt);
void reset();
// ------------------------------------------------------------------------
/** Sets the minimum speed a kart should have. This is used to guarantee
* that e.g. zippers on ramps will always fast enough for the karts to
* reach the other end. If set to a negative number, it will have
* no effect. */
void setMinSpeed(float s) { m_min_speed = s; }
// ------------------------------------------------------------------------
/** Returns the current maximum speed for this kart. */
float getCurrentMaxSpeed() const { return m_current_max_speed; }
// ------------------------------------------------------------------------