Improved breakdowns: Various changes and fixes.
* Revert breakdown_chance to (mostly) its original behaviour. * Create a new breakdown_chance_factor to hold breakdown_chance from improved breakdowns logic. * Revert airport crash probabilities back to original behaviour, with modified behaviour only during emergency landings. * Low power breakdowns now only reduce the power of the engine which has broken down. * Low power breakdowns no longer reduce speed directly. * Add callback function to run whenever improved breakdowns setting is changed. Reset breakdown_chance_factor where required. * More whitespace/formatting...
This commit is contained in:
@@ -78,14 +78,15 @@ void GroundVehicle<T, Type>::CalculatePower(uint32& total_power, uint32& max_te,
|
||||
|
||||
for (const T *u = v; u != NULL; u = u->Next()) {
|
||||
uint32 current_power = u->GetPower() + u->GetPoweredPartPower(u);
|
||||
|
||||
if (breakdowns && u->breakdown_ctr == 1 && u->breakdown_type == BREAKDOWN_LOW_POWER) {
|
||||
current_power = current_power * u->breakdown_severity / 256;
|
||||
}
|
||||
|
||||
total_power += current_power;
|
||||
|
||||
/* Only powered parts add tractive effort. */
|
||||
if (current_power > 0) max_te += u->GetWeight() * u->GetTractiveEffort();
|
||||
|
||||
if (breakdowns && u->breakdown_ctr == 1 && u->breakdown_type == BREAKDOWN_LOW_POWER) {
|
||||
total_power = total_power * u->breakdown_severity / 256;
|
||||
}
|
||||
}
|
||||
|
||||
max_te *= 10000; // Tractive effort in (tonnes * 1000 * 10 =) N.
|
||||
@@ -138,7 +139,6 @@ int GroundVehicle<T, Type>::GetAcceleration()
|
||||
* and km/h to m/s conversion below result in a maxium of
|
||||
* about 1.1E11, way more than 4.3E9 of int32. */
|
||||
int64 power = this->gcache.cached_power * 746ll;
|
||||
uint32 max_te = this->gcache.cached_max_te; // [N]
|
||||
|
||||
/* This is constructed from:
|
||||
* - axle resistance: U16 power * 10 for 128 vehicles.
|
||||
@@ -171,6 +171,7 @@ int GroundVehicle<T, Type>::GetAcceleration()
|
||||
AccelStatus mode = v->GetAccelerationStatus();
|
||||
|
||||
/* handle breakdown power reduction */
|
||||
uint32 max_te = this->gcache.cached_max_te; // [N]
|
||||
if (Type == VEH_TRAIN && mode == AS_ACCEL && HasBit(Train::From(this)->flags, VRF_BREAKDOWN_POWER)) {
|
||||
/* We'd like to cache this, but changing cached_power has too many unwanted side-effects */
|
||||
uint32 power_temp;
|
||||
@@ -219,9 +220,7 @@ int GroundVehicle<T, Type>::GetAcceleration()
|
||||
breakdown_factor /= (Train::From(this)->tcache.cached_num_engines + 2);
|
||||
}
|
||||
/* breakdown_chance is at least 5 (5 / 128 = ~4% of the normal chance) */
|
||||
this->breakdown_chance = max(breakdown_factor >> 16, (uint64)5);
|
||||
} else {
|
||||
this->breakdown_chance = 128;
|
||||
this->breakdown_chance_factor = max(breakdown_factor >> 16, (uint64)5);
|
||||
}
|
||||
|
||||
if (mode == AS_ACCEL) {
|
||||
@@ -235,7 +234,7 @@ int GroundVehicle<T, Type>::GetAcceleration()
|
||||
* same (maximum) speed. */
|
||||
int accel = ClampToI32((force - resistance) / (mass * 4));
|
||||
accel = force < resistance ? min(-1, accel) : max(1, accel);
|
||||
if (this->type == VEH_TRAIN ) {
|
||||
if (this->type == VEH_TRAIN) {
|
||||
if(_settings_game.vehicle.train_acceleration_model == AM_ORIGINAL &&
|
||||
HasBit(Train::From(this)->flags, VRF_BREAKDOWN_POWER)) {
|
||||
/* We need to apply the power reducation for non-realistic acceleration here */
|
||||
|
Reference in New Issue
Block a user