Added support for a bonus zipper if a kart uses skidding. This

is disabled for now till work on the new skidding is finished.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@10626 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk
2012-01-09 05:58:29 +00:00
parent cd5ff43c5d
commit e18ffedf44
6 changed files with 141 additions and 35 deletions

View File

@@ -161,12 +161,16 @@
max: maximum skidding factor = maximum increase of steering angle.
time-till-max: Time till maximum skidding is reached.
visual: Additional graphical rotation of kart.
visual-time: How long it takes for the visual skid to reach maximum.
angular-velocity: Angular velocity to be used for the kart when skidding.
bonus-time: How long a kart needs to skid in order to get a bonus. -->
time-till-bonus: How long a kart needs to skid in order to get a bonus.
bonus-force: A speedup applied to the kart whick skidded for a while.
bonus-time: How long the bonus-force is applied. -->
<!-- Note: for now skidding is disabled, set angular-velocity to 2 to test it -->
<skid increase="1.05" decrease="0.95" max="2.5" time-till-max="0.4"
visual="0.16"
angular-velocity="0" bonus-time="5"/>
visual="0.16" visual-time="0"
angular-velocity="0" time-till-bonus="1.5 2"
bonus-force="100 200" bonus-time="3.0 3.0"/>
<!-- Slipstream: length: How far behind a kart slipstream works
collect-time: How many seconds of sstream give maximum benefit

View File

@@ -561,6 +561,7 @@ void Kart::reset()
m_bubblegum_time = 0.0f;
m_invulnerable_time = 0.0f;
m_squash_time = 0.0f;
m_skid_time = 0.0f;
m_node->setScale(core::vector3df(1.0f, 1.0f, 1.0f));
m_collected_energy = 0;
m_has_started = false;
@@ -1610,23 +1611,23 @@ void Kart::updatePhysics(float dt)
updateSkidding(dt);
updateSliding();
float steering = getMaxSteerAngle() * m_controls.m_steer*m_skidding;
float steering;
// FIXME: Misuse (for now) the skid visual time to disable the new
// skidding code
if(m_kart_properties->getSkidVisualTime()==0)
{
steering = getMaxSteerAngle() * m_controls.m_steer*m_skidding;
}
else if(m_controls.m_drift)
{
steering = getMaxSteerAngle() * m_controls.m_steer/sqrt(m_skidding)*1.2f;
}
else
steering = getMaxSteerAngle() * m_controls.m_steer*m_skidding*m_skidding;
m_vehicle->setSteeringValue(steering, 0);
m_vehicle->setSteeringValue(steering, 1);
// Handle skidding
float ang_vel = 0;
if(m_controls.m_drift)
{
if(m_controls.m_steer>0)
ang_vel = m_kart_properties->getSkidAngularVelocity();
else if (m_controls.m_steer<0)
ang_vel = -m_kart_properties->getSkidAngularVelocity();
}
m_vehicle->setSkidAngularVelocity(ang_vel);
// Only compute the current speed if this is not the client. On a client the
// speed is actually received from the server.
if(network_manager->getMode()!=NetworkManager::NW_CLIENT)
@@ -1767,8 +1768,37 @@ void Kart::updateSkidding(float dt)
m_skid_sound->stop();
}
// Handle skidding
float ang_vel = 0;
if(m_controls.m_drift)
{
m_skid_time += dt;
if(m_controls.m_steer>0)
ang_vel = m_kart_properties->getSkidAngularVelocity();
else if (m_controls.m_steer<0)
ang_vel = -m_kart_properties->getSkidAngularVelocity();
}
else if(m_skid_time>0 &&
// FIXME hiker: remove once the new skidding code is finished.
m_kart_properties->getSkidVisualTime()>0)
// See if a skid bonus is applied
{
float bonus_time, bonus_force;
m_kart_properties->getSkidBonus(m_skid_time,
&bonus_time, &bonus_force);
printf("skid time %f bonus %f bonus-time %f\n",
m_skid_time, bonus_time, bonus_force);
m_skid_time = 0;
if(bonus_time>0)
{
MaxSpeed::increaseMaxSpeed(MaxSpeed::MS_INCREASE_SKIDDING,
10, bonus_time, 1);
// FIXME hiker: for now just misuse the zipper code
handleZipper(0);
}
}
m_vehicle->setSkidAngularVelocity(ang_vel);
} // updateSkidding
//-----------------------------------------------------------------------------
@@ -2010,8 +2040,8 @@ void Kart::loadData(RaceManager::KartType type, bool is_first_kart,
core::vector3df(0.0f, 40.0f, 100.0f),
getNode());
// FIXME: in multiplayer mode, this will result in several instances of the heightmap being calculated
// and kept in memory
// FIXME: in multiplayer mode, this will result in several instances
// of the heightmap being calculated and kept in memory
m_sky_particles_emitter->addHeightMapAffector(track);
}
@@ -2164,6 +2194,12 @@ void Kart::updateGraphics(float dt, const Vec3& offset_xyz,
float speed_ratio = getSpeed()/MaxSpeed::getCurrentMaxSpeed();
float offset_heading = getSteerPercent()*m_kart_properties->getSkidVisual()
* speed_ratio * m_skidding*m_skidding;
if(m_kart_properties->getSkidVisualTime()>0 &&
m_skid_time < m_kart_properties->getSkidVisualTime())
{
offset_heading *= m_skid_time/m_kart_properties->getSkidVisualTime();
}
Moveable::updateGraphics(dt, center_shift,
btQuaternion(offset_heading, 0, 0));

View File

@@ -76,6 +76,10 @@ private:
/** Accumulated skidding factor. */
float m_skidding;
/** Keeps track on how long a kart has been skidding, in order to
* trigger the skidding bonus. */
float m_skid_time;
/** The main controller of this object, used for driving. This
* controller is used to run the kart. It will be replaced
* with an end kart controller when the kart finishes the race. */

View File

@@ -83,10 +83,9 @@ KartProperties::KartProperties(const std::string &filename)
m_plunger_in_face_duration[1] = m_plunger_in_face_duration[2] =
m_zipper_time = m_zipper_force = m_zipper_speed_gain =
m_zipper_max_speed_increase = m_zipper_fade_out_time =
m_time_till_max_skid =
m_time_till_max_skid = m_skid_angular_velocity =
m_skid_decrease = m_skid_increase = m_skid_visual = m_skid_max =
m_skid_angular_velocity = m_skid_bonus_time =
m_slipstream_length = m_slipstream_collect_time =
m_skid_visual_time = m_slipstream_length = m_slipstream_collect_time =
m_slipstream_use_time = m_slipstream_add_power =
m_slipstream_min_speed = m_slipstream_max_speed_increase =
m_slipstream_duration = m_slipstream_fade_out_time =
@@ -97,6 +96,10 @@ KartProperties::KartProperties(const std::string &filename)
m_swatter_distance2 = m_swatter_duration = m_squash_slowdown =
m_squash_duration = m_downward_impulse_factor = UNDEFINED;
m_skid_bonus_time.clear();
m_skid_bonus_force.clear();
m_skid_time_till_bonus.clear();
m_gravity_center_shift = Vec3(UNDEFINED);
m_bevel_factor = Vec3(UNDEFINED);
m_exp_spring_response = false;
@@ -296,7 +299,10 @@ void KartProperties::getAllData(const XMLNode * root)
skid_node->get("max", &m_skid_max );
skid_node->get("time-till-max", &m_time_till_max_skid );
skid_node->get("visual", &m_skid_visual );
skid_node->get("visual-time", &m_skid_visual_time );
skid_node->get("enable", &m_has_skidmarks );
skid_node->get("time-till-bonus", &m_skid_time_till_bonus );
skid_node->get("bonus-force", &m_skid_bonus_force );
skid_node->get("bonus-time", &m_skid_bonus_time );
skid_node->get("angular-velocity", &m_skid_angular_velocity);
}
@@ -625,8 +631,8 @@ void KartProperties::checkAllSet(const std::string &filename)
CHECK_NEG(m_skid_increase, "skid increase" );
CHECK_NEG(m_skid_max, "skid max" );
CHECK_NEG(m_skid_visual, "skid visual" );
CHECK_NEG(m_skid_visual_time, "skid visual-time" );
CHECK_NEG(m_skid_angular_velocity, "skid angular-velocity" );
CHECK_NEG(m_skid_bonus_time, "skid bonus-time" );
CHECK_NEG(m_slipstream_length, "slipstream length" );
CHECK_NEG(m_slipstream_collect_time, "slipstream collect-time" );
CHECK_NEG(m_slipstream_use_time, "slipstream use-time" );
@@ -660,6 +666,29 @@ void KartProperties::checkAllSet(const std::string &filename)
CHECK_NEG(m_explosion_radius, "explosion radius" );
CHECK_NEG(m_ai_steering_variation, "ai steering-variation" );
if(m_skid_time_till_bonus.size()==0)
fprintf(stderr, "Warning: no skid time declared, can be ignored.\n");
if(m_skid_time_till_bonus.size()!=m_skid_bonus_force.size())
{
fprintf(stderr, "Warning: skid time-till-bonus and bonus-force\n");
fprintf(stderr, " must have same number of elements.\n");
exit(-1);
}
if(m_skid_time_till_bonus.size()!=m_skid_bonus_time.size())
{
fprintf(stderr, "Warning: skid time-till-bonus and bonus-time must\n");
fprintf(stderr, " have same number of elements.\n");
exit(-1);
}
for(unsigned int i=0; i<m_skid_time_till_bonus.size()-1; i++)
{
if(m_skid_time_till_bonus[i]>=m_skid_time_till_bonus[i+1])
{
fprintf(stderr, "Warning: skid time-till-bonus not sorted.\n");
exit(-1);
}
} // for i
} // checkAllSet
// ----------------------------------------------------------------------------
@@ -683,6 +712,25 @@ float KartProperties::getMaxSteerAngle(float speed) const
return 0; // avoid compiler warning
} // getMaxSteerAngle
// ----------------------------------------------------------------------------
/** Returns the bonus force to be applied to a kart which has skidded for the
* specified amount of time.
* \param t Time the kart has skidded.
*/
void KartProperties::getSkidBonus(float t, float *bonus_time,
float *bonus_force) const
{
*bonus_time = 0;
*bonus_force = 0;
for(unsigned int i=0; i<m_skid_bonus_force.size(); i++)
{
if(t<=m_skid_time_till_bonus[i]) return ;
*bonus_force = m_skid_bonus_force[i];
*bonus_time= m_skid_bonus_time[i];
}
return;
} // getSkidBonusForce
// ----------------------------------------------------------------------------
/** Called the first time a kart accelerates after 'ready-set-go'. It searches
* through m_startup_times to find the appropriate slot, and returns the

View File

@@ -268,9 +268,6 @@ private:
float m_upright_tolerance;
float m_upright_max_force;
/** Additional rotation of 3d model when skidding. */
float m_skid_visual;
/** How far behind a kart slipstreaming is effective. */
float m_slipstream_length;
/** Time after which sstream gives a bonus. */
@@ -300,12 +297,25 @@ private:
float m_time_till_max_skid;
/** Kart leaves skid marks. */
bool m_has_skidmarks;
/** Additional rotation of 3d model when skidding. */
float m_skid_visual;
/** How long it takes for visual skid to reach maximum. */
float m_skid_visual_time;
/** Angular velocity to be applied when skidding. */
float m_skid_angular_velocity;
/** Time of skidding before you get a bonus boost. */
float m_skid_bonus_time;
/** Time of skidding before you get a bonus boost. It's possible to
* define more than one time, i.e. longer skidding gives more bonus. */
std::vector<float> m_skid_time_till_bonus;
/** How much additional speed a kart gets when skidding. It's possible to
* define more than one force, i.e. longer skidding gives more bonus. */
std::vector<float> m_skid_bonus_force;
/** How long the bonus will last. It's possible to define more than one
* time, i.e. longer skidding gives more bonus. */
std::vector<float> m_skid_bonus_time;
/** Make the AI to steer at slightly different points to make it less
* likely that the AI creates 'trains' - the kart behind getting
@@ -348,11 +358,12 @@ public:
KartProperties (const std::string &filename="");
~KartProperties ();
void getAllData (const XMLNode * root);
void checkAllSet(const std::string &filename);
float getStartupBoost() const;
void checkAllSet (const std::string &filename);
float getStartupBoost () const;
/** Returns the maximum steering angle (depending on speed). */
float getMaxSteerAngle (float speed) const;
float getMaxSteerAngle (float speed) const;
void getSkidBonus(float t, float *bonus_time, float *bonus_force) const;
/** Returns the material for the kart icons. */
Material* getIconMaterial () const {return m_icon_material; }
@@ -589,6 +600,9 @@ public:
/** Returns additional rotation of 3d model when skidding. */
float getSkidVisual () const {return m_skid_visual; }
/** Returns the time for the visual skid to reach maximum. */
float getSkidVisualTime () const {return m_skid_visual_time; }
/** Returns how far behind a kart slipstreaming works. */
float getSlipstreamLength () const {return m_slipstream_length; }
@@ -613,6 +627,7 @@ public:
/** Returns how long the higher speed lasts after slipstream
* stopped working. */
float getSlipstreamDuration () const { return m_slipstream_duration; }
/** Returns how long the slip stream speed increase will gradually
* be reduced. */
float getSlipstreamFadeOutTime () const
@@ -652,9 +667,6 @@ public:
/** Returns the angular velocity to be applied when skidding. */
float getSkidAngularVelocity() const { return m_skid_angular_velocity; }
/** Returns the time of skidding before you get a bonus boost. */
float getSkidBonusTime() const { return m_skid_bonus_time; }
/** Returns ratio of current speed to max speed at which the gear will
* change (for our simualated gears = simple change of engine power). */
const std::vector<float>&

View File

@@ -27,12 +27,14 @@ class MaxSpeed
{
public:
/** The categories to use for increasing the speed of a kart:
* Increase due to zipper, slipstream, nitro, rubber band usage. */
* Increase due to zipper, slipstream, nitro, rubber band,
* skidding usage. */
enum {MS_INCREASE_MIN,
MS_INCREASE_ZIPPER = MS_INCREASE_MIN,
MS_INCREASE_SLIPSTREAM,
MS_INCREASE_NITRO,
MS_INCREASE_RUBBER,
MS_INCREASE_SKIDDING,
MS_INCREASE_MAX};
/** The categories to use for decreasing the speed of a kart: