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:
Jonathan G Rennison
2016-01-18 18:27:51 +00:00
parent b652d1c42a
commit 5e924262f4
5 changed files with 20 additions and 16 deletions

View File

@@ -191,6 +191,12 @@ void Train::ConsistChanged(ConsistChangeFlags allowed_changes)
u->tcache.user_def_data = GetVehicleProperty(u, PROP_TRAIN_USER_DATA, u->tcache.user_def_data);
this->InvalidateNewGRFCache();
u->InvalidateNewGRFCache();
if (!u->IsArticulatedPart()) {
if (u->IsEngine() || u->IsMultiheaded()) {
this->tcache.cached_num_engines++;
}
}
}
for (Train *u = this; u != NULL; u = u->Next()) {
@@ -233,13 +239,13 @@ void Train::ConsistChanged(ConsistChangeFlags allowed_changes)
/* max speed is the minimum of the speed limits of all vehicles in the consist */
if ((rvi_u->railveh_type != RAILVEH_WAGON || _settings_game.vehicle.wagon_speed_limits) && !UsesWagonOverride(u)) {
uint16 speed = GetVehicleProperty(u, PROP_TRAIN_SPEED, rvi_u->max_speed);
if (HasBit(u->flags, VRF_NEED_REPAIR)) speed = u->vcache.cached_max_speed;
if (HasBit(u->flags, VRF_NEED_REPAIR) && this->IsFrontEngine()) {
for (uint i = 0; i < u->critical_breakdown_count; i++) {
speed = min(speed - (speed / (this->tcache.cached_num_engines + 2)) + 1, speed);
}
}
if (speed != 0) max_speed = min(speed, max_speed);
}
if (u->IsEngine() || u-> IsMultiheaded()) {
this->tcache.cached_num_engines++;
}
}
uint16 new_cap = e_u->DetermineCapacity(u);