diff --git a/src/ground_vehicle.cpp b/src/ground_vehicle.cpp index d57445203e..7a16b6df7c 100644 --- a/src/ground_vehicle.cpp +++ b/src/ground_vehicle.cpp @@ -56,12 +56,14 @@ void GroundVehicle::PowerChanged() this->gcache.cached_air_drag = air_drag + 3 * air_drag * number_of_parts / 20; + if (total_power == 0) { + /* Ensure that vehicles are never completely stuck */ + total_power = 1; + } + max_te *= GROUND_ACCELERATION; // Tractive effort in (tonnes * 1000 * 9.8 =) N. max_te /= 256; // Tractive effort is a [0-255] coefficient. if (this->gcache.cached_power != total_power || this->gcache.cached_max_te != max_te) { - /* Stop the vehicle if it has no power. */ - if (total_power == 0) this->vehstatus |= VS_STOPPED; - this->gcache.cached_power = total_power; this->gcache.cached_max_te = max_te; SetWindowDirty(WC_VEHICLE_DETAILS, this->index); diff --git a/src/rail_type.h b/src/rail_type.h index 1d7c244d2a..ed8dc5b6c7 100644 --- a/src/rail_type.h +++ b/src/rail_type.h @@ -47,6 +47,7 @@ enum RailTypes : uint64_t { 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 a6b64967c2..8be5a2e3f6 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 : EngineID::Invalid(); 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; int16_t min_curve_speed_mod = INT16_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;