diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 6be8d0cbc7..5851de2e3b 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -3217,11 +3217,12 @@ bool AfterLoadGame() // So set it to 0 just in case there was garbage in there. if (SlXvIsFeatureMissing(XSLFI_MORE_RAIL_TYPES)) { for (TileIndex t = 0; t < map_size; t++) { - if (_m[t].type == MP_RAILWAY || - _m[t].type == MP_ROAD || - _m[t].type == MP_STATION || - _m[t].type == MP_TUNNELBRIDGE) { - SB(_m[t].m1, 7, 1, 0); + if (GetTileType(t) == MP_RAILWAY || + IsLevelCrossingTile(t) || + IsRailStationTile(t) || + IsRailWaypointTile(t) || + IsRailTunnelBridgeTile(t)) { + ClrBit(_m[t].m1, 7); } } } @@ -3263,6 +3264,21 @@ bool AfterLoadGame() */ void ReloadNewGRFData() { + TileIndex map_size = MapSize(); + + /* Backup railtype labels for all rail tiles. The railtype info array will be resorted. */ + std::map rail_type_label_backups; + + for (TileIndex t = 0; t < map_size; t++) { + if (GetTileType(t) == MP_RAILWAY || + IsLevelCrossingTile(t) || + IsRailStationTile(t) || + IsRailWaypointTile(t) || + IsRailTunnelBridgeTile(t)) { + rail_type_label_backups[t] = GetRailTypeInfo(GetRailType(t))->label; + } + } + /* reload grf data */ GfxLoadSprites(); LoadStringWidthTable(); @@ -3288,4 +3304,16 @@ void ReloadNewGRFData() MarkWholeScreenDirty(); CheckTrainsLengths(); AfterLoadTemplateVehiclesUpdateImage(); + + /* Restore correct railtype for all rail tiles.*/ + for (TileIndex t = 0; t < map_size; t++) { + if (GetTileType(t) == MP_RAILWAY || + IsLevelCrossingTile(t) || + IsRailStationTile(t) || + IsRailWaypointTile(t) || + IsRailTunnelBridgeTile(t)) { + RailType old_type = GetRailTypeByLabel(rail_type_label_backups[t]); + SetRailType(t, (old_type == INVALID_RAILTYPE) ? RAILTYPE_RAIL : old_type); + } + } } diff --git a/src/tunnelbridge_map.h b/src/tunnelbridge_map.h index 2196f794f1..46129983c5 100644 --- a/src/tunnelbridge_map.h +++ b/src/tunnelbridge_map.h @@ -14,6 +14,7 @@ #include "bridge_map.h" #include "tunnel_map.h" +#include "cmd_helper.h" /** @@ -57,6 +58,19 @@ static inline bool HasTunnelBridgeSnowOrDesert(TileIndex t) return HasBit(_me[t].m7, 5); } + +/** +* Is this a rail bridge or tunnel? +* @param t the tile that might be a rail bridge or tunnel +* @return true if and only if this tile is a rail bridge or tunnel +*/ +static inline bool IsRailTunnelBridgeTile(TileIndex t) +{ + TransportType tt = Extract(_m[t].m5); + + return IsTileType(t, MP_TUNNELBRIDGE) && (tt == TRANSPORT_RAIL); +} + /** * Tunnel: Places this tunnel entrance in a snowy or desert area, or takes it out of there. * Bridge: Sets whether the bridge ramp lies in a snow or desert area.