Adjust realistic braking physics

Realistic acceleration uses 4 x the mass for acceleration as braking
Use 4 x mass for realistic braking as well to match
Increase per train length braking force
Add a power-based per train length braking force
This commit is contained in:
Jonathan G Rennison
2021-04-11 23:39:54 +01:00
parent 49d7afe7ae
commit 5d5100449e
3 changed files with 24 additions and 14 deletions

View File

@@ -192,7 +192,7 @@ GroundVehicleAcceleration GroundVehicle<T, Type>::GetAcceleration()
/* This value allows to know if the vehicle is accelerating or braking. */
AccelStatus mode = v->GetAccelerationStatus();
const int braking_power = power;
int braking_power = power;
/* handle breakdown power reduction */
uint32 max_te = this->gcache.cached_max_te; // [N]
@@ -225,6 +225,10 @@ GroundVehicleAcceleration GroundVehicle<T, Type>::GetAcceleration()
braking_force = force;
}
if (Type == VEH_TRAIN && _settings_game.vehicle.train_braking_model == TBM_REALISTIC) {
braking_power += (Train::From(this)->gcache.cached_total_length * (int64)RBC_BRAKE_POWER_PER_LENGTH);
}
/* If power is 0 because of a breakdown, we make the force 0 if accelerating */
if (Type == VEH_TRAIN && mode == AS_ACCEL && HasBit(Train::From(this)->flags, VRF_BREAKDOWN_POWER) && power == 0) {
force = 0;
@@ -265,7 +269,7 @@ GroundVehicleAcceleration GroundVehicle<T, Type>::GetAcceleration()
/* Assume that every part of a train is braked, not just the engine.
* Exceptionally heavy freight trains should still have a sensible braking distance.
* The total braking force is generally larger than the total tractive force. */
braking_accel = ClampToI32((-braking_force - resistance - (this->gcache.cached_total_length * 300)) / mass);
braking_accel = ClampToI32((-braking_force - resistance - (Train::From(this)->gcache.cached_total_length * (int64)RBC_BRAKE_FORCE_PER_LENGTH)) / (mass * 4));
/* Defensive driving: prevent ridiculously fast deceleration.
* -130 corresponds to a braking distance of about 6.2 tiles from 160 km/h. */