1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-29 15:14:33 +01:00

Codechange: Store the rail type of rail engines as a RailTypes bitmask.

This commit is contained in:
Michael Lutz
2025-06-13 21:01:31 +02:00
parent 0715903b24
commit 3ac1a2f1e4
27 changed files with 184 additions and 87 deletions

View File

@@ -580,15 +580,13 @@ void SettingsDisableElrail(int32_t new_value)
void UpdateDisableElrailSettingState(bool disable, bool update_vehicles)
{
/* 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;
/* update railtype of engines intended to use elrail */
if (rv_info->intended_railtype == RAILTYPE_ELECTRIC) {
rv_info->railtype = new_railtype;
if (rv_info->intended_railtypes.Test(RAILTYPE_ELECTRIC)) {
rv_info->railtypes.Set(RAILTYPE_ELECTRIC, !disable);
rv_info->railtypes.Set(RAILTYPE_RAIL, disable);
}
}
@@ -596,11 +594,12 @@ void UpdateDisableElrailSettingState(bool disable, bool update_vehicles)
* normal rail too */
if (disable) {
for (Train *t : Train::Iterate()) {
if (t->railtype == RAILTYPE_ELECTRIC) {
if (t->railtypes.Test(RAILTYPE_ELECTRIC)) {
/* this railroad vehicle is now compatible only with elrail,
* so add there also normal rail compatibility */
t->compatible_railtypes.Set(RAILTYPE_RAIL);
t->railtype = RAILTYPE_RAIL;
t->railtypes.Reset(RAILTYPE_ELECTRIC);
t->railtypes.Set(RAILTYPE_RAIL);
t->flags.Set(VehicleRailFlag::AllowedOnNormalRail);
}
}