Merge branch 'Characteristics' of git://github.com/STK-helper/stk-code into dev

This commit is contained in:
hiker 2018-11-13 22:52:44 +11:00
commit f1b97cdd44
9 changed files with 150 additions and 63 deletions

View File

@ -66,7 +66,7 @@
speed 10 the radius is 7.5 etc. speed 10 the radius is 7.5 etc.
The actual turn radius is piece-wise linearly interpolated. This The actual turn radius is piece-wise linearly interpolated. This
allows for tighter turning at lower speeds, and also avoids that allows for tighter turning at lower speeds, and also avoids that
the kart becomes too hard to control at high speed (speeds of the kart becomes too hard to control at high speed (speeds
higher than 25 can only be reached with powerups). higher than 25 can only be reached with powerups).
time-full-steer: This is the amount of change in steering depending time-full-steer: This is the amount of change in steering depending
on current steering. So if the steering is between 0 and 0.5, on current steering. So if the steering is between 0 and 0.5,
@ -84,7 +84,8 @@
time-reset-steer="0.1" /> time-reset-steer="0.1" />
<!-- Speed and acceleration <!-- Speed and acceleration
power: The power of the kart power: The power of the kart (the engine power needed to accelerate
at a given pace is proportional to mass)
max-speed: The base maximum speed of the kart in m/s max-speed: The base maximum speed of the kart in m/s
brake-factor: Value used when braking. brake-factor: Value used when braking.
brake-time-increase: The brake force is multiplied by brake-time-increase: The brake force is multiplied by
@ -93,18 +94,19 @@
max-speed-reverse-ratio is the percentage of max speed for reverse max-speed-reverse-ratio is the percentage of max speed for reverse
gear. gear.
--> -->
<engine power="875" max-speed="25" brake-factor="15" <engine power="950" max-speed="25" brake-factor="15"
brake-time-increase="6" max-speed-reverse-ratio="0.65" /> brake-time-increase="6" max-speed-reverse-ratio="0.65" />
<!-- Simulated gears <!-- Simulated gears
switch-ratio defines at what ratio of the maximum switch-ratio defines at what ratio of the maximum
speed what gear is selected, e.g. 0.25 means that if the speed is speed what gear is selected, e.g. 0.25 means that if the speed is
bigger or equal to 0.25 * maxSpeed then use gear 1, 0.5 means if inferior or equal to 0.25 * maxSpeed then use gear 1, 0.5 means if
the speed is bigger or equal to 0.5 x maxSpeed then gear 2. the speed is inferior or equal to 0.5 x maxSpeed then gear 2.
gear-power-increase contains the increase in max power (to simulate gear-power-increase contains the increase in max power (to simulate
different gears), e.g. 2.5 as first entry means: 2.5 * maxPower in gear 1 different gears), e.g. 2.5 as first entry means: 2.5 * maxPower in gear 1
| first | second | third | . --> | first | second | third | . -->
<gear switch-ratio="0.25 0.7 1.0" power-increase="2.2 1.7 1.3" /> <gear switch-ratio="0.2 0.45 0.7 1 1.25"
power-increase="2.5 2.1 1.7 1.4 1.2" />
<!-- Mass of a kart --> <!-- Mass of a kart -->
<mass value="350" /> <mass value="350" />
@ -205,9 +207,9 @@
<anvil duration="2.0" weight="150" speed-factor="0.2" /> <anvil duration="2.0" weight="150" speed-factor="0.2" />
<!-- Parachute <!-- Parachute
friction: The friction increase when a parachute is attached. friction: The friction factor when a parachute is attached.
duration: The time an attached parachute is active duration: The time an attached parachute is active
duration-other: The time a parachute attached from other kart works duration-other: Used when the parachute results from item use
duration-rank-mult: The multiplier applied to the duration of the duration-rank-mult: The multiplier applied to the duration of the
parachute on the 1st kart when affected by the item. Scale for parachute on the 1st kart when affected by the item. Scale for
intermediary ranks to 1.0 for the last affected. intermediary ranks to 1.0 for the last affected.
@ -220,9 +222,9 @@
detach parachute. E.g. at max-speed 50% of speed must be lost. detach parachute. E.g. at max-speed 50% of speed must be lost.
max-speed: A factor that decides the impact of rate of speed max-speed: A factor that decides the impact of rate of speed
(distance between bounds) --> (distance between bounds) -->
<parachute friction="2.0" duration="2.0" duration-other="2.6" <parachute friction="5.0" duration="3" duration-other="2.5"
duration-rank-mult="1.35" duration-speed-mult="2.0" duration-rank-mult="1.5" duration-speed-mult="1.35"
lbound-fraction="0.8" ubound-fraction="0.5" max-speed="23" /> lbound-fraction="0.5" ubound-fraction="0.3" max-speed="30" />
<!-- Bubblegum <!-- Bubblegum
duration: How long the bubblegum lasts. duration: How long the bubblegum lasts.
speed-fraction: To what fraction of top-speed the speed is reduced. speed-fraction: To what fraction of top-speed the speed is reduced.
@ -273,7 +275,7 @@
fields must have the same size, and must be sorted by fields must have the same size, and must be sorted by
increasing times. --> increasing times. -->
<startup time="0.3 0.5" <startup time="0.3 0.5"
boost="6 3" /> boost="8 4" />
<!-- Rescue <!-- Rescue
duration: How long it takes the kart to be raised. duration: How long it takes the kart to be raised.
@ -292,11 +294,12 @@
after being hit by an explosion. after being hit by an explosion.
radius: Kart closer to this value will be affected by radius: Kart closer to this value will be affected by
an explosion as well. --> an explosion as well. -->
<explosion duration="2" radius="5" <explosion duration="2" radius="6"
invulnerability-time="6" /> invulnerability-time="7" />
<!-- Nitro <!-- Nitro
engine-force: additional engine power engine-force: additional engine power
engine-mult: multiply the total engine power by this
consumption: nitro consumption - heavier characters can be set consumption: nitro consumption - heavier characters can be set
to need more nitro than lighter character. to need more nitro than lighter character.
small-container: how much energy a small container gives. small-container: how much energy a small container gives.
@ -308,8 +311,9 @@
fade-out-time: Duration during which the increased maximum fade-out-time: Duration during which the increased maximum
speed due to nitro fades out. speed due to nitro fades out.
max: How much nitro a kart can store. --> max: How much nitro a kart can store. -->
<nitro engine-force="600" consumption="1" small-container="1" big-container="3" <nitro engine-force="300" engine-mult="1.2" consumption="1"
max-speed-increase="5" duration="1" fade-out-time="2" max="20" /> small-container="1" big-container="3"
max-speed-increase="5" duration="1" fade-out-time="2.4" max="20" />
<!-- Slipstream <!-- Slipstream
base-speed: the speed for which length and width are valid. base-speed: the speed for which length and width are valid.
@ -331,22 +335,22 @@
fade-out-time: How long the slip stream speed increase will fade-out-time: How long the slip stream speed increase will
gradually be reduced. --> gradually be reduced. -->
<slipstream base-speed="20" length="8" width="4" inner-factor="0.5" <slipstream base-speed="20" length="8" width="4" inner-factor="0.5"
min-collect-time="3" max-collect-time="8" add-power="300" min-speed="8" min-collect-time="2.5" max-collect-time="8" add-power="300" min-speed="8"
max-speed-increase="5" duration-factor="1" fade-out-time="2" /> max-speed-increase="3" duration-factor="1" fade-out-time="2" />
</characteristic> </characteristic>
<!-- The different difficulties (like easy, medium, hard) --> <!-- The different difficulties (like easy, medium, hard) -->
<difficulties> <difficulties>
<characteristic name="easy"> <characteristic name="easy">
<engine power="*0.66" max-speed="*0.6" /> <engine power="*0.7" max-speed="*0.6" />
<plunger in-face-time="3" /> <plunger in-face-time="3" />
</characteristic> </characteristic>
<characteristic name="medium"> <characteristic name="medium">
<engine power="*0.77" max-speed="*0.8" /> <engine power="*0.83" max-speed="*0.8" />
<plunger in-face-time="4" /> <plunger in-face-time="4" />
</characteristic> </characteristic>
<characteristic name="hard"> <characteristic name="hard">
<engine power="*0.89" max-speed="*0.92" /> <engine power="*0.92" max-speed="*0.92" />
</characteristic> </characteristic>
<!-- This doesn't need to be changed because the most fast/heavy/extreme <!-- This doesn't need to be changed because the most fast/heavy/extreme
values should also be the default ones. --> values should also be the default ones. -->
@ -356,44 +360,40 @@
<!-- The different kart types, that can be specified in the kart.xml file --> <!-- The different kart types, that can be specified in the kart.xml file -->
<kart-types> <kart-types>
<characteristic name="light"> <characteristic name="light">
<engine power="*0.46" max-speed="*0.92" brake-factor="*1" <turn radius="0:2.0 10:7.5 25:15 45:30" />
max-speed-reverse-ratio="*0.77" /> <engine power="*0.8" max-speed="*0.95" brake-factor="*1"
<gear switch-ratio="0.20 0.55 1" power-increase="5 4 3" /> max-speed-reverse-ratio="*0.8" />
<mass value="*0.56" /> <gear switch-ratio="0.1 0.25 0.45 0.7 1.0 4.0"
<startup time="0.3 0.5" power-increase="2.8 2.3 1.9 1.5 1.25 1.0" />
boost="8.5 4.5" /> <mass value="*0.6" />
<explosion time="2.1" radius="5.5" <startup boost="*1 *1" />
invulnerability-time="7" /> <explosion time="*1" radius="*1" />
<nitro engine-force="350" max-speed-increase="4.5" duration="1.5" <nitro engine-force="*0.6" max-speed-increase="*0.9" duration="*1" />
fade-out-time="2.5" />
<slipstream length="*0.9" collect-time="*0.9" <slipstream length="*0.9" collect-time="*0.9"
duration-factor="*1" fade-out-time="*1" /> duration-factor="*1" fade-out-time="*1" />
</characteristic> </characteristic>
<characteristic name="medium"> <characteristic name="medium">
<engine power="*0.63" max-speed="*1" brake-factor="*0.73" <turn radius="0:2.3 10:8.625 25:17.25 45:34.5" />
max-speed-reverse-ratio="*0.62" /> <engine power="*0.875" max-speed="*1" brake-factor="*0.8"
<gear switch-ratio="0.30 0.7 1.0" power-increase="2.2 2.2 2.5" /> max-speed-reverse-ratio="*0.75" />
<mass value="*0.71" /> <gear switch-ratio="0.1 0.25 0.45 0.7 1 4"
<startup time="0.3 0.5" power-increase="2.4 2 1.7 1.4 1.2 1" />
boost="4.2 2.6" /> <mass value="*0.75" />
<explosion time="1.8" radius="5" <startup boost="*0.8 *0.8" />
invulnerability-time="6" /> <explosion time="*0.8" radius="*0.8" />
<nitro engine-force="425" consumption="1.4" duration="1" /> <nitro engine-force="*0.75" consumption="*1.25" />
<slipstream duration-factor="*0.8" fade-out-time="*1" /> <slipstream duration-factor="*0.8" fade-out-time="*1" />
</characteristic> </characteristic>
<characteristic name="heavy"> <characteristic name="heavy">
<engine power="*1" max-speed="*1" brake-factor="*0.66" <turn radius="0:2.6 10:9.75 25:19.5 45:39" />
max-speed-reverse-ratio="*1" /> <engine power="*1" max-speed="*1.05" brake-factor="*0.6"
<gear switch-ratio="0.45 0.70 1" power-increase="1.5 1.7 2.5" /> max-speed-reverse-ratio="*0.7" />
<gear switch-ratio="0.1 0.25 0.45 0.7 1 4"
power-increase="2 1.7 1.5 1.3 1.15 1" />
<mass value="*1" /> <mass value="*1" />
<swatter duration="10" distance="3" squash-duration="5" <startup boost="*0.6 *0.6" />
squash-slowdown="0.5" /> <explosion time="*0.6" radius="*0.6" />
<startup time="0.3 0.5" <nitro engine-force="*1" consumption="*1.67" max-speed-increase="*1.1" />
boost="3.8 2" />
<explosion time="1.5" radius="4"
invulnerability-time="6" />
<nitro engine-force="600" consumption="2" max-speed-increase="8"
duration="0.7" fade-out-time="1.3" />
<slipstream length="*1.1" collect-time="*1.1" <slipstream length="*1.1" collect-time="*1.1"
duration-factor="*0.6" fade-out-time="*1" /> duration-factor="*0.6" fade-out-time="*1" />
</characteristic> </characteristic>

View File

@ -201,6 +201,8 @@ AbstractCharacteristic::ValueType AbstractCharacteristic::getType(
return TYPE_FLOAT; return TYPE_FLOAT;
case NITRO_ENGINE_FORCE: case NITRO_ENGINE_FORCE:
return TYPE_FLOAT; return TYPE_FLOAT;
case NITRO_ENGINE_MULT:
return TYPE_FLOAT;
case NITRO_CONSUMPTION: case NITRO_CONSUMPTION:
return TYPE_FLOAT; return TYPE_FLOAT;
case NITRO_SMALL_CONTAINER: case NITRO_SMALL_CONTAINER:
@ -437,6 +439,8 @@ std::string AbstractCharacteristic::getName(CharacteristicType type)
return "NITRO_DURATION"; return "NITRO_DURATION";
case NITRO_ENGINE_FORCE: case NITRO_ENGINE_FORCE:
return "NITRO_ENGINE_FORCE"; return "NITRO_ENGINE_FORCE";
case NITRO_ENGINE_MULT:
return "NITRO_ENGINE_MULT";
case NITRO_CONSUMPTION: case NITRO_CONSUMPTION:
return "NITRO_CONSUMPTION"; return "NITRO_CONSUMPTION";
case NITRO_SMALL_CONTAINER: case NITRO_SMALL_CONTAINER:
@ -1395,6 +1399,18 @@ float AbstractCharacteristic::getNitroEngineForce() const
return result; return result;
} // getNitroEngineForce } // getNitroEngineForce
// ----------------------------------------------------------------------------
float AbstractCharacteristic::getNitroEngineMult() const
{
float result;
bool is_set = false;
process(NITRO_ENGINE_MULT, &result, &is_set);
if (!is_set)
Log::fatal("AbstractCharacteristic", "Can't get characteristic %s",
getName(NITRO_ENGINE_MULT).c_str());
return result;
} // getNitroEngineMult
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
float AbstractCharacteristic::getNitroConsumption() const float AbstractCharacteristic::getNitroConsumption() const
{ {

View File

@ -185,6 +185,7 @@ public:
// Nitro // Nitro
NITRO_DURATION, NITRO_DURATION,
NITRO_ENGINE_FORCE, NITRO_ENGINE_FORCE,
NITRO_ENGINE_MULT,
NITRO_CONSUMPTION, NITRO_CONSUMPTION,
NITRO_SMALL_CONTAINER, NITRO_SMALL_CONTAINER,
NITRO_BIG_CONTAINER, NITRO_BIG_CONTAINER,
@ -354,6 +355,7 @@ public:
float getNitroDuration() const; float getNitroDuration() const;
float getNitroEngineForce() const; float getNitroEngineForce() const;
float getNitroEngineMult() const;
float getNitroConsumption() const; float getNitroConsumption() const;
float getNitroSmallContainer() const; float getNitroSmallContainer() const;
float getNitroBigContainer() const; float getNitroBigContainer() const;

View File

@ -2651,6 +2651,54 @@ void Kart::updateEngineSFX(float dt)
} }
} // updateEngineSFX } // updateEngineSFX
//-----------------------------------------------------------------------------
/** Reduces the engine power according to speed
*
* TODO : find where the physics already apply a linear force decrease
* TODO : While this work fine, it should ideally be in physics
* However, the function use some kart properties and parachute
* effect needs to be applied, so keep both working if moving
* \param engine_power : the engine power on which to apply the decrease
*/
float Kart::applyAirFriction(float engine_power)
{
//The physics already do that a certain amount of engine force is needed to keep going
//at a given speed (~39,33 engine force = 1 speed for a mass of 350)
//But it's either too slow to accelerate to a target speed or makes it
//too easy to accelerate farther.
//Instead of making increasing gears have enormous power gaps, apply friction
float mass_factor = m_kart_properties->getMass()/350.0f;
float compense_linear_slowdown = 39.33f*getSpeed()*mass_factor;
engine_power += compense_linear_slowdown;
// The result will always be a positive number
float friction_intensity = fabsf(getSpeed());
// Not a pure quadratic evolution as it would be too brutal
friction_intensity *= sqrt(friction_intensity)*5;
// Apply parachute physics
// Currently, all karts have the same base friction
// If this is changed, a compensation needs to be added here
if(m_attachment->getType()==Attachment::ATTACH_PARACHUTE)
friction_intensity *= m_kart_properties->getParachuteFriction();
if (friction_intensity < 0.0f) friction_intensity = 0.0f;
// We substract the friction from the engine power
// 1)This is the logical behavior
// 2)That way, engine boosts remain useful at high speed
// 3)It helps heavier karts, who have an higher engine power
engine_power-=friction_intensity;
return engine_power;
} //applyAirFriction
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/** Sets the engine power. It considers the engine specs, items that influence /** Sets the engine power. It considers the engine specs, items that influence
* the available power, and braking/steering. * the available power, and braking/steering.
@ -2661,9 +2709,11 @@ void Kart::updateEnginePowerAndBrakes(int ticks)
updateNitro(ticks); updateNitro(ticks);
float engine_power = getActualWheelForce(); float engine_power = getActualWheelForce();
// apply parachute physics if relevant // apply nitro boost if relevant
if(m_attachment->getType()==Attachment::ATTACH_PARACHUTE) if(getSpeedIncreaseTicksLeft(MaxSpeed::MS_INCREASE_NITRO) > 0)
engine_power*=0.2f; {
engine_power*= m_kart_properties->getNitroEngineMult();
}
// apply bubblegum physics if relevant // apply bubblegum physics if relevant
if (m_bubblegum_ticks > 0) if (m_bubblegum_ticks > 0)
@ -2689,6 +2739,9 @@ void Kart::updateEnginePowerAndBrakes(int ticks)
m_kart_properties->getSkidVisualTime() == 0) m_kart_properties->getSkidVisualTime() == 0)
engine_power *= 0.5f; engine_power *= 0.5f;
// This also applies parachute physics if relevant
engine_power = applyAirFriction(engine_power);
applyEngineForce(engine_power*m_controls.getAccel()); applyEngineForce(engine_power*m_controls.getAccel());
// Either all or no brake is set, so test only one to avoid // Either all or no brake is set, so test only one to avoid
@ -2698,14 +2751,20 @@ void Kart::updateEnginePowerAndBrakes(int ticks)
m_vehicle->setAllBrakes(0); m_vehicle->setAllBrakes(0);
m_brake_ticks = 0; m_brake_ticks = 0;
} }
else else // not accelerating
{ // not accelerating {
//The engine power is still guaranteed >= 0 at this point
float braking_power = engine_power;
// This also applies parachute physics if relevant
engine_power = applyAirFriction(engine_power);
if(m_controls.getBrake()) if(m_controls.getBrake())
{ // check if the player is currently only slowing down { // check if the player is currently only slowing down
// or moving backwards // or moving backwards
if(m_speed > 0.0f) if(m_speed > 0.0f)
{ // Still going forward while braking { // Still going forward while braking
applyEngineForce(-engine_power*2.5f); applyEngineForce(engine_power-braking_power*3);
m_brake_ticks += ticks; m_brake_ticks += ticks;
// Apply the brakes - include the time dependent brake increase // Apply the brakes - include the time dependent brake increase
float f = 1.0f + stk_config->ticks2Time(m_brake_ticks) float f = 1.0f + stk_config->ticks2Time(m_brake_ticks)
@ -2723,7 +2782,7 @@ void Kart::updateEnginePowerAndBrakes(int ticks)
// The backwards acceleration is artificially increased to // The backwards acceleration is artificially increased to
// allow players to get "unstuck" quicker if they hit e.g. // allow players to get "unstuck" quicker if they hit e.g.
// a wall. // a wall.
applyEngineForce(-engine_power*2.5f); applyEngineForce(engine_power-braking_power*3);
} }
else // -m_speed >= max speed on this terrain else // -m_speed >= max speed on this terrain
{ {
@ -2732,13 +2791,13 @@ void Kart::updateEnginePowerAndBrakes(int ticks)
} // m_speed <00 } // m_speed <00
} }
else // !m_brake else // no braking and no acceleration
{ {
m_brake_ticks = 0; m_brake_ticks = 0;
// lift the foot from throttle, brakes with 10% engine_power // lift the foot from throttle, let friction slow it down
assert(!std::isnan(m_controls.getAccel())); assert(!std::isnan(m_controls.getAccel()));
assert(!std::isnan(engine_power)); assert(!std::isnan(engine_power));
applyEngineForce(-m_controls.getAccel()*engine_power*0.1f); applyEngineForce(engine_power-braking_power);
// If not giving power (forward or reverse gear), and speed is low // If not giving power (forward or reverse gear), and speed is low
// we are "parking" the kart, so in battle mode we can ambush people // we are "parking" the kart, so in battle mode we can ambush people
@ -2746,7 +2805,7 @@ void Kart::updateEnginePowerAndBrakes(int ticks)
m_vehicle->setAllBrakes(20.0f); m_vehicle->setAllBrakes(20.0f);
else else
m_vehicle->setAllBrakes(0); m_vehicle->setAllBrakes(0);
} // !m_brake } // no braking and no acceleration
} // not accelerating } // not accelerating
} // updateEnginePowerAndBrakes } // updateEnginePowerAndBrakes

View File

@ -264,6 +264,7 @@ protected:
void updateEngineSFX(float dt); void updateEngineSFX(float dt);
void updateSpeed(); void updateSpeed();
void updateNitro(int ticks); void updateNitro(int ticks);
float applyAirFriction (float engine_power);
float getActualWheelForce(); float getActualWheelForce();
void playCrashSFX(const Material* m, AbstractKart *k); void playCrashSFX(const Material* m, AbstractKart *k);
void loadData(RaceManager::KartType type, bool animatedModel); void loadData(RaceManager::KartType type, bool animatedModel);

View File

@ -1017,6 +1017,12 @@ float KartProperties::getNitroEngineForce() const
return m_cached_characteristic->getNitroEngineForce(); return m_cached_characteristic->getNitroEngineForce();
} // getNitroEngineForce } // getNitroEngineForce
// ----------------------------------------------------------------------------
float KartProperties::getNitroEngineMult() const
{
return m_cached_characteristic->getNitroEngineMult();
} // getNitroEngineMult
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
float KartProperties::getNitroConsumption() const float KartProperties::getNitroConsumption() const
{ {

View File

@ -469,6 +469,7 @@ public:
float getNitroDuration() const; float getNitroDuration() const;
float getNitroEngineForce() const; float getNitroEngineForce() const;
float getNitroEngineMult() const;
float getNitroConsumption() const; float getNitroConsumption() const;
float getNitroSmallContainer() const; float getNitroSmallContainer() const;
float getNitroBigContainer() const; float getNitroBigContainer() const;

View File

@ -545,7 +545,7 @@ void Skidding::update(int ticks, bool is_on_ground,
MaxSpeed::MS_INCREASE_RED_SKIDDING; MaxSpeed::MS_INCREASE_RED_SKIDDING;
m_kart->m_max_speed-> m_kart->m_max_speed->
instantSpeedIncrease(bonus_cat, instantSpeedIncrease(bonus_cat,
bonus_speed, bonus_speed, bonus_speed, bonus_speed/2,
bonus_force, bonus_force,
stk_config->time2Ticks(bonus_time), stk_config->time2Ticks(bonus_time),
/*fade-out-time*/ stk_config->time2Ticks(1.0f)); /*fade-out-time*/ stk_config->time2Ticks(1.0f));

View File

@ -545,6 +545,8 @@ void XmlCharacteristic::load(const XMLNode *node)
&m_values[NITRO_DURATION]); &m_values[NITRO_DURATION]);
sub_node->get("engine-force", sub_node->get("engine-force",
&m_values[NITRO_ENGINE_FORCE]); &m_values[NITRO_ENGINE_FORCE]);
sub_node->get("engine-mult",
&m_values[NITRO_ENGINE_MULT]);
sub_node->get("consumption", sub_node->get("consumption",
&m_values[NITRO_CONSUMPTION]); &m_values[NITRO_CONSUMPTION]);
sub_node->get("small-container", sub_node->get("small-container",