Add nitro multiplier and revamp parachutes and air friction

This commit is contained in:
Alayan-stk-2 2018-06-23 02:14:29 +02:00 committed by GitHub
parent be98a6c4c3
commit 1988cfe0be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 85 additions and 4 deletions

View File

@ -201,6 +201,8 @@ AbstractCharacteristic::ValueType AbstractCharacteristic::getType(
return TYPE_FLOAT;
case NITRO_ENGINE_FORCE:
return TYPE_FLOAT;
case NITRO_ENGINE_MULT:
return TYPE_FLOAT;
case NITRO_CONSUMPTION:
return TYPE_FLOAT;
case NITRO_SMALL_CONTAINER:
@ -437,6 +439,8 @@ std::string AbstractCharacteristic::getName(CharacteristicType type)
return "NITRO_DURATION";
case NITRO_ENGINE_FORCE:
return "NITRO_ENGINE_FORCE";
case NITRO_ENGINE_MULT:
return "NITRO_ENGINE_MULT";
case NITRO_CONSUMPTION:
return "NITRO_CONSUMPTION";
case NITRO_SMALL_CONTAINER:
@ -1395,6 +1399,18 @@ float AbstractCharacteristic::getNitroEngineForce() const
return result;
} // 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
{

View File

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

View File

@ -2545,6 +2545,54 @@ void Kart::updateEngineSFX(float dt)
}
} // 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
* the available power, and braking/steering.
@ -2554,9 +2602,14 @@ void Kart::updateEnginePowerAndBrakes(int ticks)
updateNitro(ticks);
float engine_power = getActualWheelForce();
// apply parachute physics if relevant
if(m_attachment->getType()==Attachment::ATTACH_PARACHUTE)
engine_power*=0.2f;
// apply nitro boost if relevant
if(getSpeedIncreaseTicksLeft(MaxSpeed::MS_INCREASE_NITRO) > 0)
{
engine_power*= m_kart_properties->getNitroEngineMult();
}
// This also applies parachute physics if relevant
engine_power = applyAirFriction(engine_power);
// apply bubblegum physics if relevant
if (m_bubblegum_ticks > 0)

View File

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

View File

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

View File

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

View File

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