Added support in MaxSpeed for an additional engine force
to work while a speed increase is active. This simplifies existing code (for slipstream, nitro). Additional engine force is also added for skidding, which should make skidding more worthwhile (since usually adjusting the heading when stop skidding will use up the actual bonus speed). git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@11450 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
5f0f8e0346
commit
203ae69ce6
@ -142,7 +142,7 @@
|
||||
necessary. -->
|
||||
<rescue vert-offset="0.0" time="1.2" height="2"/>
|
||||
|
||||
<!-- Nitro: power-boost: increase in engine power, i.e. 1=plus 100%
|
||||
<!-- Nitro: engine-force: additional engine power
|
||||
consumption: nitro consumption - heavier characters can be set
|
||||
to need more nitro than lighter character.
|
||||
small-container: how much energy a small container gives.
|
||||
@ -153,7 +153,7 @@
|
||||
the kart stops using nitro (and the fade-out-time starts).
|
||||
fade-out-time: Duration during which the increased maximum
|
||||
speed due to nitro fades out. -->
|
||||
<nitro power-boost="3" consumption="1" small-container="1" big-container="3"
|
||||
<nitro engine-force="500" consumption="1" small-container="1" big-container="3"
|
||||
max-speed-increase="5" duration="1" fade-out-time="2"/>
|
||||
|
||||
<!-- time is the time a zipper is active. force is the additional
|
||||
@ -176,6 +176,9 @@
|
||||
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.
|
||||
bonus-force: Additional engine force (this is used to offset the fact
|
||||
that turning after skidding (e.g. to correct direction) often uses
|
||||
up the skid bonus).
|
||||
post-skid-rotate-factor: a factor to be used to determine how much
|
||||
the chassis of a kart should rotate to match the graphical view.
|
||||
A factor of 1 is identical, a smaller factor will rotate the kart
|
||||
@ -191,6 +194,7 @@
|
||||
visual="1.0" visual-time="0"
|
||||
time-till-bonus="1.0 3.0"
|
||||
bonus-speed="4.5 6.5" bonus-time="3.0 4.0"
|
||||
bonus-force="250 350"
|
||||
post-skid-rotate-factor="1" jump-time="0.4"
|
||||
reduce-turn-min="0.4" reduce-turn-max="0.8"/>
|
||||
|
||||
|
@ -523,15 +523,17 @@ Material::Material(const XMLNode *node, int index)
|
||||
else if (child_node->getName() == "zipper")
|
||||
{
|
||||
// Track version 4 uses a separate node:
|
||||
m_zipper = true;
|
||||
m_zipper_duration = 3.5f;
|
||||
m_zipper = true;
|
||||
m_zipper_duration = 3.5f;
|
||||
m_zipper_max_speed_increase = 15.0f;
|
||||
m_zipper_fade_out_time = 3.0f;
|
||||
m_zipper_speed_gain = 4.5f;
|
||||
m_zipper_fade_out_time = 3.0f;
|
||||
m_zipper_speed_gain = 4.5f;
|
||||
m_zipper_engine_force = 250;
|
||||
child_node->get("duration", &m_zipper_duration );
|
||||
child_node->get("fade-out-time", &m_zipper_fade_out_time );
|
||||
child_node->get("max-speed-increase",&m_zipper_max_speed_increase);
|
||||
child_node->get("speed-gain", &m_zipper_speed_gain );
|
||||
child_node->get("sengine-force", &m_zipper_engine_force );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -602,6 +604,7 @@ void Material::init(unsigned int index)
|
||||
m_zipper_fade_out_time = -1.0f;
|
||||
m_zipper_max_speed_increase = -1.0f;
|
||||
m_zipper_speed_gain = -1.0f;
|
||||
m_zipper_engine_force = -1.0f;
|
||||
m_normal_map = false;
|
||||
//m_normal_map_uv2 = false;
|
||||
m_parallax_map = false;
|
||||
|
@ -202,6 +202,8 @@ private:
|
||||
/** Time it takes for the zipper advantage to fade out. If this value
|
||||
* is <0 the kart specific value will be used. */
|
||||
float m_zipper_fade_out_time;
|
||||
/** Additional engine force. */
|
||||
float m_zipper_engine_force;
|
||||
|
||||
std::string m_mask;
|
||||
|
||||
@ -314,12 +316,14 @@ public:
|
||||
void getZipperParameter(float *zipper_max_speed_increase,
|
||||
float *zipper_duration,
|
||||
float *zipper_speed_gain,
|
||||
float *zipper_fade_out_time) const
|
||||
float *zipper_fade_out_time,
|
||||
float *zipper_engine_force) const
|
||||
{
|
||||
*zipper_max_speed_increase = m_zipper_max_speed_increase;
|
||||
*zipper_duration = m_zipper_duration;
|
||||
*zipper_speed_gain = m_zipper_speed_gain;
|
||||
*zipper_fade_out_time = m_zipper_fade_out_time;
|
||||
*zipper_engine_force = m_zipper_engine_force;
|
||||
} // getZipperParameter
|
||||
|
||||
bool isNormalMap() const { return m_normal_map; }
|
||||
|
@ -299,26 +299,25 @@ bool SlipStream::isSlipstreamReady() const
|
||||
/** Returns the additional force being applied to the kart because of
|
||||
* slipstreaming.
|
||||
*/
|
||||
float SlipStream::getSlipstreamPower()
|
||||
void SlipStream::updateSlipstreamPower()
|
||||
{
|
||||
// Low level AIs should not do any slipstreaming.
|
||||
if(!m_kart->getController()->isPlayerController() &&
|
||||
race_manager->getDifficulty()==RaceManager::RD_EASY) return 0;
|
||||
race_manager->getDifficulty()==RaceManager::RD_EASY) return;
|
||||
|
||||
// First see if we are currently using accumulated slipstream credits:
|
||||
// -------------------------------------------------------------------
|
||||
// See if we are currently using accumulated slipstream credits:
|
||||
// -------------------------------------------------------------
|
||||
if(m_slipstream_mode==SS_USE)
|
||||
{
|
||||
setIntensity(2.0f, NULL);
|
||||
const KartProperties *kp=m_kart->getKartProperties();
|
||||
m_kart->increaseMaxSpeed(MaxSpeed::MS_INCREASE_SLIPSTREAM,
|
||||
kp->getSlipstreamMaxSpeedIncrease(),
|
||||
kp->getSlipstreamAddPower(),
|
||||
kp->getSlipstreamDuration(),
|
||||
kp->getSlipstreamFadeOutTime() );
|
||||
return kp->getSlipstreamAddPower();
|
||||
}
|
||||
return 0;
|
||||
} // getSlipstreamPower
|
||||
} // upateSlipstreamPower
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Sets the color of the debug mesh (which shows the area in which slipstream
|
||||
@ -358,6 +357,8 @@ void SlipStream::update(float dt)
|
||||
if(m_slipstream_time<0) m_slipstream_mode=SS_NONE;
|
||||
}
|
||||
|
||||
updateSlipstreamPower();
|
||||
|
||||
// If this kart is too slow for slipstreaming taking effect, do nothing
|
||||
// --------------------------------------------------------------------
|
||||
// Define this to get slipstream effect shown even when the karts are
|
||||
|
@ -88,7 +88,7 @@ public:
|
||||
void reset();
|
||||
virtual void update(float dt);
|
||||
void setIntensity(float f, const AbstractKart* kart);
|
||||
float getSlipstreamPower();
|
||||
void updateSlipstreamPower();
|
||||
bool isSlipstreamReady() const;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
@ -180,6 +180,7 @@ void RubberBand::update(float dt)
|
||||
m_owner->getBody()->applyCentralForce(diff*force);
|
||||
m_owner->increaseMaxSpeed(MaxSpeed::MS_INCREASE_RUBBER,
|
||||
m_owner->getKartProperties()->getRubberBandSpeedIncrease(),
|
||||
/*engine_force*/ 0.0f,
|
||||
/*duration*/0.1f,
|
||||
m_owner->getKartProperties()->getRubberBandFadeOutTime());
|
||||
if(m_attached_state==RB_TO_KART)
|
||||
|
@ -227,11 +227,13 @@ public:
|
||||
/** Sets an increased maximum speed for a category.
|
||||
* \param category The category for which to set the higher maximum speed.
|
||||
* \param add_speed How much speed (in m/s) is added to the maximum speed.
|
||||
* \param engine_force Additional engine force to affect the kart.
|
||||
* \param duration How long the speed increase will last.
|
||||
* \param fade_out_time How long the maximum speed will fade out linearly.
|
||||
*/
|
||||
virtual void increaseMaxSpeed(unsigned int category, float add_speed,
|
||||
float duration, float fade_out_time) = 0;
|
||||
float engine_force, float duration,
|
||||
float fade_out_time) = 0;
|
||||
// ------------------------------------------------------------------------
|
||||
/** Defines a slowdown, which is in fraction of top speed.
|
||||
* \param category The category for which the speed is increased.
|
||||
|
@ -406,9 +406,11 @@ void Kart::reset()
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void Kart::increaseMaxSpeed(unsigned int category, float add_speed,
|
||||
float duration, float fade_out_time)
|
||||
float engine_force, float duration,
|
||||
float fade_out_time)
|
||||
{
|
||||
m_max_speed->increaseMaxSpeed(category, add_speed, duration, fade_out_time);
|
||||
m_max_speed->increaseMaxSpeed(category, add_speed, engine_force, duration,
|
||||
fade_out_time);
|
||||
} // increaseMaxSpeed
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -869,10 +871,8 @@ void Kart::collectedItem(Item *item, int add_info)
|
||||
*/
|
||||
float Kart::getActualWheelForce()
|
||||
{
|
||||
float time_left =
|
||||
m_max_speed->getSpeedIncreaseTimeLeft(MaxSpeed::MS_INCREASE_ZIPPER);
|
||||
float zipper_force = time_left>0.0f ? m_kart_properties->getZipperForce()
|
||||
: 0.0f;
|
||||
float add_force = m_max_speed->getCurrentAdditionalEngineForce();
|
||||
|
||||
const std::vector<float>& gear_ratio=m_kart_properties->getGearSwitchRatio();
|
||||
for(unsigned int i=0; i<gear_ratio.size(); i++)
|
||||
{
|
||||
@ -880,10 +880,10 @@ float Kart::getActualWheelForce()
|
||||
{
|
||||
return m_kart_properties->getMaxPower()
|
||||
*m_kart_properties->getGearPowerIncrease()[i]
|
||||
+zipper_force;
|
||||
+add_force;
|
||||
}
|
||||
}
|
||||
return m_kart_properties->getMaxPower()+zipper_force;
|
||||
return m_kart_properties->getMaxPower()+add_force;
|
||||
|
||||
} // getActualWheelForce
|
||||
|
||||
@ -1450,11 +1450,13 @@ void Kart::handleZipper(const Material *material, bool play_sound)
|
||||
float speed_gain;
|
||||
/** Time it takes for the zipper advantage to fade out. */
|
||||
float fade_out_time;
|
||||
/** Additional engine force. */
|
||||
float engine_force;
|
||||
|
||||
if(material)
|
||||
{
|
||||
material->getZipperParameter(&max_speed_increase, &duration,
|
||||
&speed_gain, &fade_out_time);
|
||||
&speed_gain, &fade_out_time, &engine_force);
|
||||
if(max_speed_increase<0)
|
||||
max_speed_increase = m_kart_properties->getZipperMaxSpeedIncrease();
|
||||
if(duration<0)
|
||||
@ -1463,6 +1465,8 @@ void Kart::handleZipper(const Material *material, bool play_sound)
|
||||
speed_gain = m_kart_properties->getZipperSpeedGain();
|
||||
if(fade_out_time<0)
|
||||
fade_out_time = m_kart_properties->getZipperFadeOutTime();
|
||||
if(engine_force<0)
|
||||
engine_force = m_kart_properties->getZipperForce();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1470,39 +1474,38 @@ void Kart::handleZipper(const Material *material, bool play_sound)
|
||||
duration = m_kart_properties->getZipperTime();
|
||||
speed_gain = m_kart_properties->getZipperSpeedGain();
|
||||
fade_out_time = m_kart_properties->getZipperFadeOutTime();
|
||||
engine_force = m_kart_properties->getZipperForce();
|
||||
}
|
||||
// Ignore a zipper that's activated while braking
|
||||
if(m_controls.m_brake || m_speed<0) return;
|
||||
|
||||
m_max_speed->instantSpeedIncrease(MaxSpeed::MS_INCREASE_ZIPPER,
|
||||
max_speed_increase, speed_gain,
|
||||
duration, fade_out_time);
|
||||
engine_force, duration, fade_out_time);
|
||||
// Play custom character sound (weee!)
|
||||
playCustomSFX(SFXManager::CUSTOM_ZIPPER);
|
||||
m_controller->handleZipper(play_sound);
|
||||
} // handleZipper
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Returned an additional engine power boost when using nitro.
|
||||
/** Updates the current nitro status.
|
||||
* \param dt Time step size.
|
||||
*/
|
||||
float Kart::handleNitro(float dt)
|
||||
void Kart::updateNitro(float dt)
|
||||
{
|
||||
if(!m_controls.m_nitro || !isOnGround()) return 0.0;
|
||||
if(!m_controls.m_nitro || !isOnGround()) return;
|
||||
m_collected_energy -= dt * m_kart_properties->getNitroConsumption();
|
||||
if(m_collected_energy<0)
|
||||
{
|
||||
m_collected_energy = 0;
|
||||
return 0.0;
|
||||
return;
|
||||
}
|
||||
m_max_speed->increaseMaxSpeed(MaxSpeed::MS_INCREASE_NITRO,
|
||||
m_kart_properties->getNitroMaxSpeedIncrease(),
|
||||
m_kart_properties->getNitroDuration(),
|
||||
m_kart_properties->getNitroFadeOutTime() );
|
||||
return m_kart_properties->getNitroPowerBoost()
|
||||
* m_kart_properties->getMaxPower();
|
||||
|
||||
} // handleNitro
|
||||
m_kart_properties->getNitroMaxSpeedIncrease(),
|
||||
m_kart_properties->getNitroEngineForce(),
|
||||
m_kart_properties->getNitroDuration(),
|
||||
m_kart_properties->getNitroFadeOutTime() );
|
||||
} // updateNitro
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Activates a slipstream effect */
|
||||
@ -1745,8 +1748,10 @@ void Kart::updatePhysics(float dt)
|
||||
{
|
||||
m_has_started = true;
|
||||
float f = m_kart_properties->getStartupBoost();
|
||||
m_max_speed->instantSpeedIncrease(MaxSpeed::MS_INCREASE_ZIPPER, 0.9f*f,
|
||||
f, /*duration*/5.0f,
|
||||
m_max_speed->instantSpeedIncrease(MaxSpeed::MS_INCREASE_ZIPPER,
|
||||
0.9f*f, f,
|
||||
/*engine_force*/200.0f,
|
||||
/*duration*/5.0f,
|
||||
/*fade_out_time*/5.0f);
|
||||
}
|
||||
|
||||
@ -1866,8 +1871,8 @@ void Kart::updateEngineSFX()
|
||||
*/
|
||||
void Kart::updateEnginePowerAndBrakes(float dt)
|
||||
{
|
||||
float engine_power = getActualWheelForce() + handleNitro(dt)
|
||||
+ m_slipstream->getSlipstreamPower();
|
||||
updateNitro(dt);
|
||||
float engine_power = getActualWheelForce();
|
||||
|
||||
// apply parachute physics if relevant
|
||||
if(m_attachment->getType()==Attachment::ATTACH_PARACHUTE)
|
||||
|
@ -212,7 +212,7 @@ private:
|
||||
void updateSliding();
|
||||
void updateEnginePowerAndBrakes(float dt);
|
||||
void updateEngineSFX();
|
||||
float handleNitro(float dt);
|
||||
void updateNitro(float dt);
|
||||
float getActualWheelForce();
|
||||
void crashed();
|
||||
void loadData(RaceManager::KartType type, bool is_first_kart,
|
||||
@ -237,7 +237,8 @@ public:
|
||||
virtual void startEngineSFX ();
|
||||
virtual void adjustSpeed (float f);
|
||||
virtual void increaseMaxSpeed(unsigned int category, float add_speed,
|
||||
float duration, float fade_out_time);
|
||||
float engine_force, float duration,
|
||||
float fade_out_time);
|
||||
virtual void setSlowdown(unsigned int category, float max_speed_fraction,
|
||||
float fade_in_time);
|
||||
virtual float getSpeedIncreaseTimeLeft(unsigned int category) const;
|
||||
|
@ -66,7 +66,7 @@ KartProperties::KartProperties(const std::string &filename)
|
||||
m_mass = m_brake_factor = m_engine_power[0] = m_engine_power[1] =
|
||||
m_engine_power[2] = m_max_speed[0] = m_max_speed[1] = m_max_speed[2] =
|
||||
m_time_full_steer = m_time_full_steer_ai =
|
||||
m_nitro_power_boost = m_nitro_consumption =
|
||||
m_nitro_consumption = m_nitro_engine_force =
|
||||
m_nitro_small_container = m_nitro_big_container =
|
||||
m_nitro_max_speed_increase = m_nitro_duration = m_nitro_fade_out_time =
|
||||
m_suspension_stiffness = m_wheel_damping_relaxation = m_wheel_base =
|
||||
@ -289,11 +289,11 @@ void KartProperties::getAllData(const XMLNode * root)
|
||||
|
||||
if(const XMLNode *nitro_node = root->getNode("nitro"))
|
||||
{
|
||||
nitro_node->get("power-boost", &m_nitro_power_boost );
|
||||
nitro_node->get("consumption", &m_nitro_consumption );
|
||||
nitro_node->get("small-container", &m_nitro_small_container );
|
||||
nitro_node->get("big-container", &m_nitro_big_container );
|
||||
nitro_node->get("max-speed-increase", &m_nitro_max_speed_increase);
|
||||
nitro_node->get("engine-force", &m_nitro_engine_force );
|
||||
nitro_node->get("duration", &m_nitro_duration );
|
||||
nitro_node->get("fade-out-time", &m_nitro_fade_out_time );
|
||||
|
||||
@ -654,11 +654,11 @@ void KartProperties::checkAllSet(const std::string &filename)
|
||||
CHECK_NEG(m_camera_distance, "camera distance" );
|
||||
CHECK_NEG(m_camera_forward_up_angle, "camera forward-up-angle" );
|
||||
CHECK_NEG(m_camera_backward_up_angle, "camera forward-up-angle" );
|
||||
CHECK_NEG(m_nitro_power_boost, "nitro power-boost" );
|
||||
CHECK_NEG(m_nitro_consumption, "nitro consumption" );
|
||||
CHECK_NEG(m_nitro_big_container, "nitro big-container" );
|
||||
CHECK_NEG(m_nitro_small_container, "nitro small-container" );
|
||||
CHECK_NEG(m_nitro_max_speed_increase, "nitro max-speed-increase" );
|
||||
CHECK_NEG(m_nitro_engine_force, "nitro engine-force" );
|
||||
CHECK_NEG(m_nitro_duration, "nitro duration" );
|
||||
CHECK_NEG(m_nitro_fade_out_time, "nitro fade-out-time" );
|
||||
CHECK_NEG(m_swatter_distance2, "swatter distance" );
|
||||
|
@ -191,8 +191,6 @@ private:
|
||||
float m_plunger_in_face_duration[3];
|
||||
/** Wheel base of the kart. */
|
||||
float m_wheel_base;
|
||||
/** Nitro power boost. */
|
||||
float m_nitro_power_boost;
|
||||
/** Nitro consumption. */
|
||||
float m_nitro_consumption;
|
||||
/** Nitro amount for small bottle. */
|
||||
@ -201,6 +199,8 @@ private:
|
||||
float m_nitro_big_container;
|
||||
/* How much the speed of a kart might exceed its maximum speed (in m/s). */
|
||||
float m_nitro_max_speed_increase;
|
||||
/** Additional engine force to affect the kart. */
|
||||
float m_nitro_engine_force;
|
||||
/** How long the increased nitro max speed will be valid after
|
||||
* the kart stops using nitro (and the fade-out-time starts). */
|
||||
float m_nitro_duration;
|
||||
@ -463,9 +463,6 @@ public:
|
||||
float getMaxSpeed () const {return
|
||||
m_max_speed[race_manager->getDifficulty()];}
|
||||
|
||||
/** Returns the nitro power boost. */
|
||||
float getNitroPowerBoost () const {return m_nitro_power_boost; }
|
||||
|
||||
/** Returns the nitro consumption. */
|
||||
float getNitroConsumption () const {return m_nitro_consumption; }
|
||||
|
||||
@ -479,6 +476,7 @@ public:
|
||||
float getNitroMaxSpeedIncrease () const
|
||||
{return m_nitro_max_speed_increase; }
|
||||
|
||||
float getNitroEngineForce () const {return m_nitro_engine_force; }
|
||||
/** Returns how long the increased nitro max speed will be valid after
|
||||
* the kart stops using nitro (and the fade-out-time starts). */
|
||||
float getNitroDuration () const {return m_nitro_duration; }
|
||||
|
@ -81,14 +81,16 @@ void MaxSpeed::reset()
|
||||
* \param fade_out_time How long the maximum speed will fade out linearly.
|
||||
*/
|
||||
void MaxSpeed::increaseMaxSpeed(unsigned int category, float add_speed,
|
||||
float duration, float fade_out_time)
|
||||
float engine_force, float duration,
|
||||
float fade_out_time)
|
||||
{
|
||||
assert(fade_out_time>0.01f);
|
||||
assert(category>=MS_INCREASE_MIN && category <MS_INCREASE_MAX);
|
||||
m_speed_increase[category].m_max_add_speed = add_speed;
|
||||
m_speed_increase[category].m_duration = duration;
|
||||
m_speed_increase[category].m_fade_out_time = fade_out_time;
|
||||
m_speed_increase[category].m_max_add_speed = add_speed;
|
||||
m_speed_increase[category].m_current_speedup = add_speed;
|
||||
m_speed_increase[category].m_engine_force = engine_force;
|
||||
} // increaseMaxSpeed
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -101,14 +103,17 @@ void MaxSpeed::increaseMaxSpeed(unsigned int category, float add_speed,
|
||||
* \param category The category for which the speed is increased.
|
||||
* \param add_max_speed Increase of the maximum allowed speed.
|
||||
* \param speed_boost An instant speed increase for this kart.
|
||||
* \param engine_force Additional engine force.
|
||||
* \param duration Duration of the increased speed.
|
||||
* \param fade_out_time How long the maximum speed will fade out linearly.
|
||||
*/
|
||||
void MaxSpeed::instantSpeedIncrease(unsigned int category,
|
||||
float add_max_speed, float speed_boost,
|
||||
float duration, float fade_out_time)
|
||||
float engine_force, float duration,
|
||||
float fade_out_time)
|
||||
{
|
||||
increaseMaxSpeed(category, add_max_speed, duration, fade_out_time);
|
||||
increaseMaxSpeed(category, add_max_speed, engine_force, duration,
|
||||
fade_out_time);
|
||||
// This will result in all max speed settings updated, but no
|
||||
// changes to any slow downs since dt=0
|
||||
update(0);
|
||||
@ -204,6 +209,8 @@ void MaxSpeed::update(float dt)
|
||||
slowdown.update(dt);
|
||||
f = std::min(f, slowdown.getSlowdownFraction());
|
||||
}
|
||||
|
||||
m_add_engine_force = 0;
|
||||
m_current_max_speed = m_kart->getKartProperties()->getMaxSpeed() * f;
|
||||
|
||||
// Then add the speed increase from each category
|
||||
@ -213,6 +220,7 @@ void MaxSpeed::update(float dt)
|
||||
SpeedIncrease &speedup = m_speed_increase[i];
|
||||
speedup.update(dt);
|
||||
m_current_max_speed += speedup.getSpeedIncrease();
|
||||
m_add_engine_force += speedup.getEngineForce();
|
||||
}
|
||||
|
||||
// Then cap the current speed of the kart
|
||||
|
@ -52,6 +52,9 @@ private:
|
||||
/** The current maximum speed. */
|
||||
float m_current_max_speed;
|
||||
|
||||
/** Additional engine force, summed from all SpeedIncrease engine forces. */
|
||||
float m_add_engine_force;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** An internal class to store and handle speed increase related data. */
|
||||
class SpeedIncrease
|
||||
@ -68,6 +71,8 @@ private:
|
||||
float m_fade_out_time;
|
||||
/** The current max speed increase value. */
|
||||
float m_current_speedup;
|
||||
/** Additional engine force. */
|
||||
float m_engine_force;
|
||||
|
||||
/** The constructor initialised the values with a no-increase
|
||||
* entry, i.e. an entry that does affect top speed at all. */
|
||||
@ -77,15 +82,24 @@ private:
|
||||
m_duration = -9999999;
|
||||
m_fade_out_time = 0;
|
||||
m_current_speedup = 0;
|
||||
m_engine_force = 0;
|
||||
} // SpeedIncrease
|
||||
// --------------------------------------------------------------------
|
||||
void update(float dt);
|
||||
/** Returns the current speedup for this category. */
|
||||
// --------------------------------------------------------------------
|
||||
float getSpeedIncrease() const {return m_current_speedup;}
|
||||
/** Returns the remaining time till the fade out time starts.
|
||||
* Note that this function will return a negative value if
|
||||
* the fade_out time has started or this speed increase has
|
||||
* expired. */
|
||||
float getTimeLeft() const {return m_duration; }
|
||||
// --------------------------------------------------------------------
|
||||
/** Returns the additional engine force for this speed increase. */
|
||||
float getEngineForce() const
|
||||
{
|
||||
return m_duration > 0 ? m_engine_force : 0;
|
||||
}
|
||||
}; // SpeedIncrease
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
@ -110,6 +124,7 @@ private:
|
||||
m_current_fraction = 1.0f;
|
||||
} // SpeedDecrease
|
||||
void update(float dt);
|
||||
// --------------------------------------------------------------------
|
||||
/** Returns the current slowdown fracftion, taking a 'fade in'
|
||||
* into account. */
|
||||
float getSlowdownFraction() const {return m_current_fraction;}
|
||||
@ -128,17 +143,22 @@ public:
|
||||
MaxSpeed(AbstractKart *kart);
|
||||
|
||||
void increaseMaxSpeed(unsigned int category, float add_speed,
|
||||
float duration, float fade_out_time);
|
||||
void instantSpeedIncrease(unsigned int category,
|
||||
float add_speed, float speed_boost,
|
||||
float duration, float fade_out_time=1.0f);
|
||||
float engine_force, float duration,
|
||||
float fade_out_time);
|
||||
void instantSpeedIncrease(unsigned int category,
|
||||
float add_speed, float speed_boost,
|
||||
float engine_force, float duration,
|
||||
float fade_out_time/*=1.0f*/);
|
||||
void setSlowdown(unsigned int category, float max_speed_fraction,
|
||||
float fade_in_time);
|
||||
float getSpeedIncreaseTimeLeft(unsigned int category);
|
||||
void update(float dt);
|
||||
void reset();
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the current maximum speed for this kart. */
|
||||
float getCurrentMaxSpeed() const { return m_current_max_speed; }
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the additional engine force. */
|
||||
float getCurrentAdditionalEngineForce() const { return m_add_engine_force;}
|
||||
}; // MaxSpeed
|
||||
#endif
|
||||
|
@ -302,9 +302,9 @@ void Skidding::update(float dt, bool is_on_ground,
|
||||
m_kart->getKartProperties()->getMaxSteerAngle(m_kart->getSpeed()));
|
||||
#endif
|
||||
m_skid_time += dt;
|
||||
float bonus_time, bonus_speed;
|
||||
unsigned int level = getSkidBonus(&bonus_time,
|
||||
&bonus_speed);
|
||||
float bonus_time, bonus_speed, bonus_force;
|
||||
unsigned int level = getSkidBonus(&bonus_time, &bonus_speed,
|
||||
&bonus_force);
|
||||
// If at least level 1 bonus is reached, show appropriate gfx
|
||||
if(level>0) m_kart->getKartGFX()->setSkidLevel(level);
|
||||
// If player stops skidding, trigger bonus, and change state to
|
||||
@ -328,8 +328,8 @@ void Skidding::update(float dt, bool is_on_ground,
|
||||
->setCreationRateRelative(KartGFX::KGFX_SKID, 1.0f);
|
||||
m_kart->m_max_speed->
|
||||
instantSpeedIncrease(MaxSpeed::MS_INCREASE_SKIDDING,
|
||||
bonus_speed, bonus_speed,
|
||||
bonus_time,
|
||||
bonus_speed, bonus_speed,
|
||||
bonus_force, bonus_time,
|
||||
/*fade-out-time*/ 1.0f);
|
||||
}
|
||||
else
|
||||
@ -356,18 +356,22 @@ void Skidding::update(float dt, bool is_on_ground,
|
||||
* m_skid_time.
|
||||
* \param bonus_time On return contains how long the bonus should be active.
|
||||
* \param bonus_speed How much additional speed the kart should get.
|
||||
* \param bonus_force Additional engine force.
|
||||
* \return The bonus level: 0 = no bonus, 1 = first entry in bonus array etc.
|
||||
*/
|
||||
unsigned int Skidding::getSkidBonus(float *bonus_time,
|
||||
float *bonus_speed) const
|
||||
float *bonus_speed,
|
||||
float *bonus_force) const
|
||||
{
|
||||
*bonus_time = 0;
|
||||
*bonus_speed = 0;
|
||||
*bonus_force = 0;
|
||||
for(unsigned int i=0; i<m_skid_bonus_speed.size(); i++)
|
||||
{
|
||||
if(m_skid_time<=m_skid_time_till_bonus[i]) return i;
|
||||
*bonus_speed = m_skid_bonus_speed[i];
|
||||
*bonus_time= m_skid_bonus_time[i];
|
||||
*bonus_time = m_skid_bonus_time[i];
|
||||
*bonus_force = m_skid_bonus_force[i];
|
||||
}
|
||||
return m_skid_bonus_speed.size();
|
||||
} // getSkidBonusForce
|
||||
|
@ -82,7 +82,8 @@ private:
|
||||
ShowCurve *m_actual_curve;
|
||||
#endif
|
||||
|
||||
unsigned int getSkidBonus(float *bonus_time, float *bonus_speed) const;
|
||||
unsigned int getSkidBonus(float *bonus_time, float *bonus_speed,
|
||||
float *bonus_force) const;
|
||||
void updateSteering(float steer);
|
||||
public:
|
||||
Skidding(Kart *kart, const SkiddingProperties *sp);
|
||||
|
@ -41,6 +41,7 @@ SkiddingProperties::SkiddingProperties()
|
||||
m_skid_bonus_time.clear();
|
||||
m_skid_bonus_speed.clear();
|
||||
m_skid_time_till_bonus.clear();
|
||||
m_skid_bonus_force.clear();
|
||||
} // SkiddingProperties
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -59,6 +60,7 @@ void SkiddingProperties::load(const XMLNode *skid_node)
|
||||
skid_node->get("bonus-time", &m_skid_bonus_time );
|
||||
skid_node->get("bonus-speed", &m_skid_bonus_speed );
|
||||
skid_node->get("time-till-bonus", &m_skid_time_till_bonus );
|
||||
skid_node->get("bonus-force", &m_skid_bonus_force );
|
||||
skid_node->get("jump-time", &m_jump_time );
|
||||
} // load
|
||||
|
||||
@ -84,7 +86,7 @@ void SkiddingProperties::checkAllSet(const std::string &filename) const
|
||||
fprintf(stderr, "Warning: no skid time declared, can be ignored.\n");
|
||||
if(m_skid_time_till_bonus.size()!=m_skid_bonus_speed.size())
|
||||
{
|
||||
fprintf(stderr, "Warning: skid time-till-bonus and bonus-force\n");
|
||||
fprintf(stderr, "Warning: skid time-till-bonus and bonus-speed\n");
|
||||
fprintf(stderr, " must have same number of elements.\n");
|
||||
exit(-1);
|
||||
}
|
||||
@ -94,6 +96,12 @@ void SkiddingProperties::checkAllSet(const std::string &filename) const
|
||||
fprintf(stderr, " have same number of elements.\n");
|
||||
exit(-1);
|
||||
}
|
||||
if(m_skid_time_till_bonus.size()!=m_skid_bonus_force.size())
|
||||
{
|
||||
fprintf(stderr, "Warning: skid time-till-bonus and bonus-force 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])
|
||||
|
@ -80,6 +80,12 @@ protected:
|
||||
* time, i.e. longer skidding gives more bonus. */
|
||||
std::vector<float> m_skid_bonus_time;
|
||||
|
||||
/** Additional force accelerating the kart (in addition to the immediate
|
||||
* speed bonus). Without this force turning to correct the direction
|
||||
* after skidding will use up nearly all of the additional speed (turning
|
||||
* reduces the forward engine impulse) */
|
||||
std::vector<float> m_skid_bonus_force;
|
||||
|
||||
/** A factor is used to reduce the amount of steering while skidding. This
|
||||
* is the minimum factor used (i.e. resulting in the largest turn
|
||||
* radius). */
|
||||
@ -90,6 +96,7 @@ protected:
|
||||
* radius). */
|
||||
float m_skid_reduce_turn_max;
|
||||
|
||||
|
||||
/** Kart leaves skid marks. */
|
||||
bool m_has_skidmarks;
|
||||
|
||||
|
@ -245,17 +245,17 @@ Controller* World::loadAIController(AbstractKart *kart)
|
||||
// const int NUM_ROBOTS = 1;
|
||||
// For now: instead of random switching, use each
|
||||
// robot in turns: switch(m_random.get(NUM_ROBOTS))
|
||||
#define USE_PRESENT_AI
|
||||
#undef USE_PRESENT_AI
|
||||
#undef USE_SKIDDING_AI
|
||||
#undef USE_ALL_AIS
|
||||
#define USE_ALL_AIS
|
||||
|
||||
#ifdef USE_PRESENT_AI
|
||||
int turn = 2;
|
||||
#elif defined(USE_SKIDDING_AI)
|
||||
int turn = 1;
|
||||
#elif defined(USE_ALL_AIS)
|
||||
static int turn=1;
|
||||
turn=(turn+1) % 3; // %2 would switch betwen default and skidding
|
||||
static int turn=0;
|
||||
turn=(turn+1) % 2; // %2 would switch betwen default and skidding
|
||||
#else
|
||||
int turn=0; // use default AU
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user