Feature: [NewGRF] Maximum curve speed modifier for rail vehicles (#9346)
This commit is contained in:
@@ -115,6 +115,7 @@ void Train::ConsistChanged(ConsistChangeFlags allowed_changes)
|
||||
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(ConsistChangeFlags allowed_changes)
|
||||
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(ConsistChangeFlags allowed_changes)
|
||||
/* 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;
|
||||
|
Reference in New Issue
Block a user