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:
@@ -123,6 +123,8 @@ void VehicleServiceInDepot(Vehicle *v)
|
||||
v->date_of_last_service = _date;
|
||||
v->breakdowns_since_last_service = 0;
|
||||
v->reliability = v->GetEngine()->reliability;
|
||||
/* Prevent vehicles from breaking down directly after exiting the depot. */
|
||||
v->breakdown_chance = 0;
|
||||
v = v->Next();
|
||||
} while (v != NULL && v->HasEngineType());
|
||||
}
|
||||
@@ -144,7 +146,7 @@ bool Vehicle::NeedsServicing() const
|
||||
if ((this->ServiceIntervalIsPercent() ?
|
||||
(this->reliability >= this->GetEngine()->reliability * (100 - this->service_interval) / 100) :
|
||||
(this->date_of_last_service + this->service_interval >= _date))
|
||||
&& !(this->type == VEH_TRAIN && HasBit(Train::From(this)->flags ,VRF_NEED_REPAIR))) {
|
||||
&& !(this->type == VEH_TRAIN && HasBit(Train::From(this)->flags, VRF_NEED_REPAIR))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1277,15 +1279,21 @@ void CheckVehicleBreakdown(Vehicle *v)
|
||||
return;
|
||||
}
|
||||
|
||||
uint32 r1 = Random();
|
||||
uint32 r2 = Random();
|
||||
uint32 r = Random();
|
||||
|
||||
/* increase chance of failure */
|
||||
int chance = v->breakdown_chance + 1;
|
||||
if (Chance16I(1, 25, r)) chance += 25;
|
||||
chance = min(255, chance);
|
||||
v->breakdown_chance = chance;
|
||||
|
||||
byte chance = 128;
|
||||
if (_settings_game.vehicle.improved_breakdowns) {
|
||||
/* Dual engines have their breakdown chances reduced to 70% of the normal value */
|
||||
chance = (v->type == VEH_TRAIN && Train::From(v)->IsMultiheaded()) ? v->First()->breakdown_chance * 7 / 10 : v->First()->breakdown_chance;
|
||||
} else if(v->type == VEH_SHIP) {
|
||||
chance = 64;
|
||||
if (v->type == VEH_TRAIN && Train::From(v)->IsMultiheaded()) {
|
||||
/* Dual engines have their breakdown chances reduced to 70% of the normal value */
|
||||
chance = chance * 7 / 10;
|
||||
}
|
||||
chance *= v->First()->breakdown_chance_factor;
|
||||
chance >>= 7;
|
||||
}
|
||||
/**
|
||||
* Chance is (1 - reliability) * breakdown_setting * breakdown_chance / 10.
|
||||
@@ -1295,9 +1303,12 @@ void CheckVehicleBreakdown(Vehicle *v)
|
||||
* However, because breakdowns are no longer by definition a complete stop,
|
||||
* their impact will be significantly less.
|
||||
*/
|
||||
uint32 r1 = Random();
|
||||
if ((uint32) (0xffff - v->reliability) * _settings_game.difficulty.vehicle_breakdowns * chance > GB(r1, 0, 24) * 10) {
|
||||
uint32 r2 = Random();
|
||||
v->breakdown_ctr = GB(r1, 24, 6) + 0xF;
|
||||
v->breakdown_delay = GB(r2, 0, 7) + 0x80;
|
||||
v->breakdown_chance = 0;
|
||||
DetermineBreakdownType(v, r2);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user