summaryrefslogtreecommitdiff
path: root/src/train_cmd.cpp
diff options
context:
space:
mode:
authorVít Šefl <vituscze@gmail.com>2021-08-15 11:17:05 +0200
committerGitHub <noreply@github.com>2021-08-15 11:17:05 +0200
commit2183fd4dabe72bd96b264bf8cdb3a2a8be625cf8 (patch)
tree7a94f94723ac65e43d5ab856d5945b3bce9a5b31 /src/train_cmd.cpp
parent579f393374c4fae2458523a674c453349fce7c59 (diff)
downloadopenttd-2183fd4dabe72bd96b264bf8cdb3a2a8be625cf8.tar.xz
Feature: [NewGRF] Maximum curve speed modifier for rail vehicles (#9346)
Diffstat (limited to 'src/train_cmd.cpp')
-rw-r--r--src/train_cmd.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 17e298c33..1498a5fad 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -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;