diff --git a/src/karts/abstract_characteristic.cpp b/src/karts/abstract_characteristic.cpp index af7ba896c..778812c0a 100644 --- a/src/karts/abstract_characteristic.cpp +++ b/src/karts/abstract_characteristic.cpp @@ -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 { diff --git a/src/karts/abstract_characteristic.hpp b/src/karts/abstract_characteristic.hpp index f4fb2406c..23cbd60c7 100644 --- a/src/karts/abstract_characteristic.hpp +++ b/src/karts/abstract_characteristic.hpp @@ -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; diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index a65f076f4..c32b58be6 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -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) diff --git a/src/karts/kart.hpp b/src/karts/kart.hpp index 5133d3305..bd5a0677c 100644 --- a/src/karts/kart.hpp +++ b/src/karts/kart.hpp @@ -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); diff --git a/src/karts/kart_properties.cpp b/src/karts/kart_properties.cpp index 9281504bc..6acecee95 100644 --- a/src/karts/kart_properties.cpp +++ b/src/karts/kart_properties.cpp @@ -558,7 +558,7 @@ float KartProperties::getAvgPower() const for (unsigned int i = 0; i < gear_power_increase.size(); ++i) sum += gear_power_increase[i] * power; return sum / gear_power_increase.size(); -} // getAvgPower +} // getAvgPower // ---------------------------------------------------------------------------- // Script-generated content generated by tools/create_kart_properties.py getter @@ -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 { diff --git a/src/karts/kart_properties.hpp b/src/karts/kart_properties.hpp index 74b2e78f1..e7d45dbc5 100644 --- a/src/karts/kart_properties.hpp +++ b/src/karts/kart_properties.hpp @@ -470,6 +470,7 @@ public: float getNitroDuration() const; float getNitroEngineForce() const; + float getNitroEngineMult() const; float getNitroConsumption() const; float getNitroSmallContainer() const; float getNitroBigContainer() const; diff --git a/src/karts/xml_characteristic.cpp b/src/karts/xml_characteristic.cpp index 2e9a34676..9a4e9f95e 100644 --- a/src/karts/xml_characteristic.cpp +++ b/src/karts/xml_characteristic.cpp @@ -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",