1
0
Fork 0

Fix: Don't assume engclass 2 should be elrail. (#10315)

When disabling/enabling elrail, there is an assumption that `engclass` of 2
means the engine will run on elrail. While this holds for default engines,
NewGRFs can do other things.

To resolve this we store the intended railtype so that toggling elrail will
restore to the correct type.
pull/10317/head
PeterN 2023-01-06 00:44:57 +00:00 committed by GitHub
parent 8f350c9ae6
commit 1b1aa682a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 7 deletions

View File

@ -597,16 +597,14 @@ void SettingsDisableElrail(int32 new_value)
{ {
bool disable = (new_value != 0); bool disable = (new_value != 0);
/* we will now walk through all electric train engines and change their railtypes if it is the wrong one*/ /* pick appropriate railtype for elrail engines depending on setting */
const RailType old_railtype = disable ? RAILTYPE_ELECTRIC : RAILTYPE_RAIL;
const RailType new_railtype = disable ? RAILTYPE_RAIL : RAILTYPE_ELECTRIC; const RailType new_railtype = disable ? RAILTYPE_RAIL : RAILTYPE_ELECTRIC;
/* walk through all train engines */ /* walk through all train engines */
for (Engine *e : Engine::IterateType(VEH_TRAIN)) { for (Engine *e : Engine::IterateType(VEH_TRAIN)) {
RailVehicleInfo *rv_info = &e->u.rail; RailVehicleInfo *rv_info = &e->u.rail;
/* if it is an electric rail engine and its railtype is the wrong one */ /* update railtype of engines intended to use elrail */
if (rv_info->engclass == 2 && rv_info->railtype == old_railtype) { if (rv_info->intended_railtype == RAILTYPE_ELECTRIC) {
/* change it to the proper one */
rv_info->railtype = new_railtype; rv_info->railtype = new_railtype;
} }
} }

View File

@ -43,7 +43,8 @@ struct RailVehicleInfo {
byte image_index; byte image_index;
RailVehicleTypes railveh_type; RailVehicleTypes railveh_type;
byte cost_factor; ///< Purchase cost factor; For multiheaded engines the sum of both engine prices. byte cost_factor; ///< Purchase cost factor; For multiheaded engines the sum of both engine prices.
RailType railtype; RailType railtype; ///< Railtype, mangled if elrail is disabled.
RailType intended_railtype; ///< Intended railtype, regardless of elrail being enabled or disabled.
uint16 max_speed; ///< Maximum speed (1 unit = 1/1.6 mph = 1 km-ish/h) uint16 max_speed; ///< Maximum speed (1 unit = 1/1.6 mph = 1 km-ish/h)
uint16 power; ///< Power of engine (hp); For multiheaded engines the sum of both engine powers. uint16 power; ///< Power of engine (hp); For multiheaded engines the sum of both engine powers.
uint16 weight; ///< Weight of vehicle (tons); For multiheaded engines the weight of each single engine. uint16 weight; ///< Weight of vehicle (tons); For multiheaded engines the weight of each single engine.

View File

@ -9804,6 +9804,7 @@ static void AfterLoadGRFs()
e->info.climates = 0; e->info.climates = 0;
} else { } else {
e->u.rail.railtype = railtype; e->u.rail.railtype = railtype;
e->u.rail.intended_railtype = railtype;
} }
} }

View File

@ -386,7 +386,7 @@ static const EngineInfo _orig_engine_info[] = {
* Tractive effort coefficient by default is the same as TTDPatch, 0.30*256=76 * Tractive effort coefficient by default is the same as TTDPatch, 0.30*256=76
* Air drag value depends on the top speed of the vehicle. * Air drag value depends on the top speed of the vehicle.
*/ */
#define RVI(a, b, c, d, e, f, g, h, i, j, k) { a, b, c, j, d, e, f, g, h, k, i, 0, 0, 0, VE_DEFAULT, 0, 76, 0, 0, 0 } #define RVI(a, b, c, d, e, f, g, h, i, j, k) { a, b, c, j, j, d, e, f, g, h, k, i, 0, 0, 0, VE_DEFAULT, 0, 76, 0, 0, 0 }
#define M RAILVEH_MULTIHEAD #define M RAILVEH_MULTIHEAD
#define W RAILVEH_WAGON #define W RAILVEH_WAGON
#define G RAILVEH_SINGLEHEAD #define G RAILVEH_SINGLEHEAD