Fix speed reduction after critical breakdowns.
Previous code set vcache.cached_max_speed directly (and incorrectly), which did not survive across save/load or network joins. Instead add a struct Train field to store the number of critical breakdowns since last service and do the speed reduction properly in Train::ConsistChanged. Slightly tweak algorithm for speed reduction.
This commit is contained in:
@@ -104,6 +104,7 @@ void VehicleServiceInDepot(Vehicle *v)
|
||||
if (v->Next() != NULL) VehicleServiceInDepot(v->Next());
|
||||
if (!(Train::From(v)->IsEngine()) && !(Train::From(v)->IsRearDualheaded())) return;
|
||||
ClrBit(Train::From(v)->flags,VRF_NEED_REPAIR);
|
||||
Train::From(v)->critical_breakdown_count = 0;
|
||||
const RailVehicleInfo *rvi = &e->u.rail;
|
||||
v->vcache.cached_max_speed = rvi->max_speed;
|
||||
if (Train::From(v)->IsFrontEngine()) {
|
||||
@@ -1352,17 +1353,12 @@ bool Vehicle::HandleBreakdown()
|
||||
}
|
||||
/* Max Speed reduction*/
|
||||
if (_settings_game.vehicle.improved_breakdowns) {
|
||||
const Engine *e = Engine::Get(this->engine_type);
|
||||
const RailVehicleInfo *rvi = &e->u.rail;
|
||||
if (!HasBit(Train::From(this)->flags,VRF_NEED_REPAIR)) {
|
||||
if (rvi->max_speed > this->vcache.cached_max_speed) {
|
||||
this->vcache.cached_max_speed = rvi->max_speed;
|
||||
}
|
||||
if (!HasBit(Train::From(this)->flags, VRF_NEED_REPAIR)) {
|
||||
SetBit(Train::From(this)->flags, VRF_NEED_REPAIR);
|
||||
Train::From(this)->critical_breakdown_count = 1;
|
||||
} else if (Train::From(this)->critical_breakdown_count != 255) {
|
||||
Train::From(this)->critical_breakdown_count++;
|
||||
}
|
||||
uint16 target_max_speed = min(this->vcache.cached_max_speed -
|
||||
(this->vcache.cached_max_speed >> 1) / Train::From(this->First())->tcache.cached_num_engines + 1, this->vcache.cached_max_speed);
|
||||
this->vcache.cached_max_speed = max(target_max_speed, min<uint16>(rvi->max_speed / 4, 28));
|
||||
SetBit(Train::From(this)->flags, VRF_NEED_REPAIR);
|
||||
Train::From(this->First())->ConsistChanged(CCF_TRACK);
|
||||
}
|
||||
/* FALL THROUGH */
|
||||
|
Reference in New Issue
Block a user