1
0
Fork 0

Fix: Trains driving on railtypes only checked powerness of any engine, but ignored compatibility of all vehicles.

pull/9953/head
frosch 2022-07-17 21:56:45 +02:00
parent 77a85e9b4c
commit 81115d271d
2 changed files with 15 additions and 8 deletions

View File

@ -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)

View File

@ -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;