Initial support for terrain dependent slow downs (at the moment

only set for grass, sand, sandgrass textures).


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2838 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk
2009-01-05 22:55:25 +00:00
parent 2d48b0e1c2
commit 3b7f2a878d
4 changed files with 63 additions and 25 deletions

View File

@@ -326,11 +326,13 @@ void Kart::reset()
m_rescue = false;
m_finish_time = 0.0f;
m_zipper_time_left = 0.0f;
m_collected_energy = 0;
m_collected_energy = 50;
m_wheel_rotation = 0;
m_bounce_back_time = 0.0f;
m_skidding = 1.0f;
m_time_last_crash = 0.0f;
m_max_speed_reduction = 0.0f;
m_power_reduction = 50.0f;
m_controls.m_steer = 0.0f;
m_controls.m_accel = 0.0f;
@@ -414,7 +416,7 @@ float Kart::getActualWheelForce()
const std::vector<float>& gear_ratio=m_kart_properties->getGearSwitchRatio();
for(unsigned int i=0; i<gear_ratio.size(); i++)
{
if(m_speed <= m_max_speed*gear_ratio[i])
if(m_speed <= getMaxSpeed()*gear_ratio[i])
{
m_current_gear_ratio = gear_ratio[i];
return getMaxPower()*m_kart_properties->getGearPowerIncrease()[i]+zipperF;
@@ -569,6 +571,7 @@ void Kart::update(float dt)
TerrainInfo::update(pos_plus_epsilon);
const Material* material=getMaterial();
m_power_reduction = 50.0f;
if (getHoT()==Track::NOHIT) // kart falling off the track
{
// let kart fall a bit before rescuing
@@ -587,6 +590,18 @@ void Kart::update(float dt)
// track again)
if (material->isReset() && isOnGround()) forceRescue();
else if(material->isZipper() && isOnGround()) handleZipper();
else
{
m_power_reduction = material->getSlowDown();
// Normal driving on terrain. Adjust for maximum terrain speed
float max_speed_here = material->getMaxSpeedFraction()*m_max_speed;
// If the speed is too fast, reduce the maximum speed gradually.
// The actual capping happens in updatePhysics
if(max_speed_here<m_speed)
m_max_speed_reduction += dt*material->getSlowDown();
else
m_max_speed_reduction = 0.0f;
}
} // if there is material
// Check if any item was hit.
@@ -709,7 +724,9 @@ void Kart::updatePhysics (float dt)
// wall, he needs to be able to start again quickly after going backwards)
else if(m_speed < 0.0f)
engine_power *= 5.0f;
// Engine slow down due to terrain (see m_power_reduction is set in
// update() depending on terrain type.
engine_power *= m_power_reduction/50.0f;
m_vehicle->applyEngineForce(engine_power, 2);
m_vehicle->applyEngineForce(engine_power, 3);
// Either all or no brake is set, so test only one to avoid
@@ -738,7 +755,7 @@ void Kart::updatePhysics (float dt)
{
resetBrakes();
// going backward, apply reverse gear ratio (unless he goes too fast backwards)
if ( fabs(m_speed) < m_max_speed*m_max_speed_reverse_ratio )
if ( fabs(m_speed) < getMaxSpeed()*m_max_speed_reverse_ratio )
{
// the backwards acceleration is artificially increased to allow
// players to get "unstuck" quicker if they hit e.g. a wall

View File

@@ -55,6 +55,10 @@ protected:
KartControl m_controls; // The position of the karts controls
float m_max_speed; // maximum speed of the kart, computed from
/** Depending on terrain a certain reduction to the maximum speed applies.
* This reduction is accumulated in m_max_speed_reduction. */
float m_max_speed_reduction;
float m_power_reduction;
float m_max_gear_rpm; //maximum engine rpm's for the current gear
float m_max_speed_reverse_ratio;
float m_zipper_time_left; // zipper time left
@@ -96,6 +100,7 @@ private:
float m_view_blocked_by_plunger;
float m_speed;
float m_rpm;
float m_current_gear_ratio;
bool m_rescue;
@@ -181,7 +186,8 @@ public:
getControls () const {return m_controls; }
/** Sets the kart controls. Used e.g. by replaying history. */
void setControls(const KartControl &c) { m_controls = c; }
float getMaxSpeed () const {return m_max_speed; }
float getMaxSpeed () const {return m_max_speed-
m_max_speed_reduction; }
/** Returns the length of the kart. */
float getKartLength () const
{return m_kart_properties->getKartModel()->getLength(); }

View File

@@ -99,15 +99,20 @@ Material::Material(const std::string& fname, char *description,
m_clamp_tex = parseBool (&description) ? UCLAMP : 0 ;
m_clamp_tex += parseBool (&description) ? VCLAMP : 0 ;
m_transparency = parseBool (&description);
m_alpha_ref = parseFloat(&description);
m_lighting = parseBool (&description);
m_sphere_map = parseBool (&description);
m_friction = parseFloat(&description);
m_ignore = parseBool (&description);
m_zipper = parseBool (&description);
m_resetter = parseBool (&description);
m_collideable = parseBool (&description);
m_transparency = parseBool (&description);
m_alpha_ref = parseFloat(&description);
m_lighting = parseBool (&description);
m_sphere_map = parseBool (&description);
m_friction = parseFloat(&description);
m_ignore = parseBool (&description);
m_zipper = parseBool (&description);
m_resetter = parseBool (&description);
m_collideable = parseBool (&description);
m_max_speed_fraction = parseFloat(&description);
m_slowdown = parseFloat(&description);
// Set the optional parameters.
if(m_max_speed_fraction <= 0.0f) m_max_speed_fraction = 1.0f;
if(m_slowdown <= 0.0f) m_slowdown = 50.0f;
}
install(is_full_path);
} // Material

View File

@@ -42,6 +42,10 @@ private:
bool m_transparency;
float m_alpha_ref;
float m_friction;
/** How much the top speed is reduced per second. */
float m_slowdown;
/** Maximum speed at which no more slow down occurs. */
float m_max_speed_fraction;
bool parseBool ( char **p );
int parseInt ( char **p );
@@ -61,18 +65,23 @@ public:
int matches ( char *tx ) ;
ssgSimpleState
*getState () const { return m_state ; }
bool isIgnore () const { return m_ignore; }
bool isZipper () const { return m_zipper; }
bool isSphereMap () const { return m_sphere_map; }
bool isCrashable () const { return m_collideable; }
bool isReset () const { return m_resetter; }
float getFriction () const { return m_friction; }
*getState () const { return m_state ; }
bool isIgnore () const { return m_ignore; }
bool isZipper () const { return m_zipper; }
bool isSphereMap () const { return m_sphere_map; }
bool isCrashable () const { return m_collideable; }
bool isReset () const { return m_resetter; }
float getFriction () const { return m_friction; }
const std::string&
getTexFname () const { return m_texname; }
int getIndex () const { return m_index; }
void apply () { m_state ->apply(); }
void force () { m_state ->force(); }
getTexFname () const { return m_texname; }
int getIndex () const { return m_index; }
/** Returns the fraction of maximum speed on this material. */
float getMaxSpeedFraction() const { return m_max_speed_fraction; }
/** Returns the slowdown that happens if a kart is
* faster than the maximum speed. */
float getSlowDown () const { return m_slowdown; }
void apply () { m_state ->apply(); }
void force () { m_state ->force(); }
void applyToLeaf ( ssgLeaf *l ) ;
@@ -82,3 +91,4 @@ public:
#endif
/* EOF */