From 81115d271db1aeaccae5bb994d33bd24e8c8ecbd Mon Sep 17 00:00:00 2001 From: frosch Date: Sun, 17 Jul 2022 21:56:45 +0200 Subject: [PATCH] Fix: Trains driving on railtypes only checked powerness of any engine, but ignored compatibility of all vehicles. --- src/rail_type.h | 1 + src/train_cmd.cpp | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/rail_type.h b/src/rail_type.h index 874a8ebbb6..ca40f84a53 100644 --- a/src/rail_type.h +++ b/src/rail_type.h @@ -49,6 +49,7 @@ enum RailTypes : uint64 { RAILTYPES_ELECTRIC = 1 << RAILTYPE_ELECTRIC, ///< Electrified rails RAILTYPES_MONO = 1 << RAILTYPE_MONO, ///< Monorail! RAILTYPES_MAGLEV = 1 << RAILTYPE_MAGLEV, ///< Ever fast maglev + RAILTYPES_ALL = UINT64_MAX, ///< All railtypes INVALID_RAILTYPES = UINT64_MAX, ///< Invalid railtypes }; DECLARE_ENUM_AS_BIT_SET(RailTypes) diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 983b5ccd1c..15a1d27b6a 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -114,7 +114,8 @@ void Train::ConsistChanged(ConsistChangeFlags allowed_changes) const RailVehicleInfo *rvi_v = RailVehInfo(this->engine_type); EngineID first_engine = this->IsFrontEngine() ? this->engine_type : INVALID_ENGINE; this->gcache.cached_total_length = 0; - this->compatible_railtypes = RAILTYPES_NONE; + RailTypes all_compatible = RAILTYPES_ALL; + RailTypes any_powered = RAILTYPES_NONE; bool train_can_tilt = true; int min_curve_speed_mod = INT_MAX; @@ -169,17 +170,20 @@ void Train::ConsistChanged(ConsistChangeFlags allowed_changes) } if (!u->IsArticulatedPart()) { - /* Do not count powered wagons for the compatible railtypes, as wagons always - have railtype normal */ - if (rvi_u->power > 0) { - this->compatible_railtypes |= GetRailTypeInfo(u->railtype)->powered_railtypes; - } - /* Some electric engines can be allowed to run on normal rail. It happens to all * existing electric engines when elrails are disabled and then re-enabled */ if (HasBit(u->flags, VRF_EL_ENGINE_ALLOWED_NORMAL_RAIL)) { u->railtype = RAILTYPE_RAIL; - u->compatible_railtypes |= RAILTYPES_RAIL; + } + + /* collect railtypes compatible with every vehicle */ + all_compatible &= GetRailTypeInfo(u->railtype)->compatible_railtypes; + + /* Do not count powered wagons for the compatible railtypes, as wagons always + have railtype normal */ + if (rvi_u->power > 0) { + /* collect railtypes powering any engine */ + any_powered |= GetRailTypeInfo(u->railtype)->powered_railtypes; } /* max speed is the minimum of the speed limits of all vehicles in the consist */ @@ -230,6 +234,8 @@ void Train::ConsistChanged(ConsistChangeFlags allowed_changes) u->InvalidateNewGRFCache(); } + this->compatible_railtypes = all_compatible & any_powered; + /* store consist weight/max speed in cache */ this->vcache.cached_max_speed = max_speed; this->tcache.cached_tilt = train_can_tilt;