diff --git a/src/elrail.cpp b/src/elrail.cpp --- a/src/elrail.cpp +++ b/src/elrail.cpp @@ -597,16 +597,14 @@ void SettingsDisableElrail(int32 new_val { bool disable = (new_value != 0); - /* we will now walk through all electric train engines and change their railtypes if it is the wrong one*/ - const RailType old_railtype = disable ? RAILTYPE_ELECTRIC : RAILTYPE_RAIL; + /* pick appropriate railtype for elrail engines depending on setting */ const RailType new_railtype = disable ? RAILTYPE_RAIL : RAILTYPE_ELECTRIC; /* walk through all train engines */ for (Engine *e : Engine::IterateType(VEH_TRAIN)) { RailVehicleInfo *rv_info = &e->u.rail; - /* if it is an electric rail engine and its railtype is the wrong one */ - if (rv_info->engclass == 2 && rv_info->railtype == old_railtype) { - /* change it to the proper one */ + /* update railtype of engines intended to use elrail */ + if (rv_info->intended_railtype == RAILTYPE_ELECTRIC) { rv_info->railtype = new_railtype; } } diff --git a/src/engine_type.h b/src/engine_type.h --- a/src/engine_type.h +++ b/src/engine_type.h @@ -43,7 +43,8 @@ struct RailVehicleInfo { byte image_index; RailVehicleTypes railveh_type; 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 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. diff --git a/src/newgrf.cpp b/src/newgrf.cpp --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -9804,6 +9804,7 @@ static void AfterLoadGRFs() e->info.climates = 0; } else { e->u.rail.railtype = railtype; + e->u.rail.intended_railtype = railtype; } } diff --git a/src/table/engines.h b/src/table/engines.h --- a/src/table/engines.h +++ b/src/table/engines.h @@ -386,7 +386,7 @@ static const EngineInfo _orig_engine_inf * 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. */ -#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 W RAILVEH_WAGON #define G RAILVEH_SINGLEHEAD