diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -115,6 +115,7 @@ void Train::ConsistChanged(ConsistChange this->compatible_railtypes = RAILTYPES_NONE; bool train_can_tilt = true; + int min_curve_speed_mod = INT_MAX; for (Train *u = this; u != nullptr; u = u->Next()) { const RailVehicleInfo *rvi_u = RailVehInfo(u->engine_type); @@ -146,6 +147,7 @@ void Train::ConsistChanged(ConsistChange const RailVehicleInfo *rvi_u = &e_u->u.rail; if (!HasBit(e_u->info.misc_flags, EF_RAIL_TILTS)) train_can_tilt = false; + min_curve_speed_mod = std::min(min_curve_speed_mod, u->GetCurveSpeedModifier()); /* Cache wagon override sprite group. nullptr is returned if there is none */ u->tcache.cached_override = GetWagonOverrideSpriteSet(u->engine_type, u->cargo_type, u->gcache.first_engine); @@ -229,6 +231,7 @@ void Train::ConsistChanged(ConsistChange /* store consist weight/max speed in cache */ this->vcache.cached_max_speed = max_speed; this->tcache.cached_tilt = train_can_tilt; + this->tcache.cached_curve_speed_mod = min_curve_speed_mod; this->tcache.cached_max_curve_speed = this->GetCurveSpeedLimit(); /* recalculate cached weights and power too (we do this *after* the rest, so it is known which wagons are powered and need extra weight added) */ @@ -357,6 +360,11 @@ int Train::GetCurveSpeedLimit() const /* Apply max_speed bonus of 20% for a tilting train */ max_speed += max_speed / 5; } + + /* Apply max_speed modifier (cached value is fixed-point binary with 8 fractional bits) + * and clamp the result to an acceptable range. */ + max_speed += (max_speed * this->tcache.cached_curve_speed_mod) >> 8; + max_speed = Clamp(max_speed, 2, absolute_max_speed); } return max_speed;