# HG changeset patch # User tron # Date 1145950142 0 # Node ID 4e75522d698d78893e6dff29f26a64e56ccc316e # Parent ed8ce86fb21974ccc35e3cb37ebc14586ca5ec7e (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic diff -r ed8ce86fb219 -r 4e75522d698d openttd.c --- a/openttd.c Tue Apr 25 06:56:22 2006 +0000 +++ b/openttd.c Tue Apr 25 07:29:02 2006 +0000 @@ -1082,6 +1082,13 @@ extern void UpdateOldAircraft( void ); extern void UpdateOilRig( void ); + +static inline RailType UpdateRailType(RailType rt, RailType min) +{ + return rt >= min ? (RailType)(rt + 1): rt; +} + + bool AfterLoadGame(void) { Window *w; @@ -1247,7 +1254,7 @@ Vehicle* v; uint i; TileIndex t; - bool make_elrail = false; + RailType min_rail = RAILTYPE_ELECTRIC; for (i = 0; i < lengthof(_engines); i++) { Engine* e = GetEngine(i); @@ -1262,7 +1269,7 @@ RailType rt = GetEngine(v->engine_type)->railtype; v->u.rail.railtype = rt; - if (rt == RAILTYPE_ELECTRIC) make_elrail = true; + if (rt == RAILTYPE_ELECTRIC) min_rail = RAILTYPE_RAIL; } } @@ -1270,34 +1277,38 @@ for (t = 0; t < MapSize(); t++) { switch (GetTileType(t)) { case MP_RAILWAY: - if (GetRailType(t) > RAILTYPE_RAIL || make_elrail) AB(_m[t].m3, 0, 4, 1); + SetRailType(t, UpdateRailType(GetRailType(t), min_rail)); break; case MP_STREET: - if (IsLevelCrossing(t) && (GetRailTypeCrossing(t) > RAILTYPE_RAIL || make_elrail)) AB(_m[t].m4, 0, 4, 1); + if (IsLevelCrossing(t)) { + SetRailTypeCrossing(t, UpdateRailType(GetRailTypeCrossing(t), min_rail)); + } break; case MP_STATION: - if (IsRailwayStation(t) && (GetRailType(t) > RAILTYPE_RAIL || make_elrail)) AB(_m[t].m3, 0, 4, 1); + if (IsRailwayStation(t)) { + SetRailType(t, UpdateRailType(GetRailType(t), min_rail)); + } break; case MP_TUNNELBRIDGE: if (IsTunnel(t)) { if (GetTunnelTransportType(t) == TRANSPORT_RAIL) { - if (GetRailType(t) > RAILTYPE_RAIL || make_elrail) AB(_m[t].m3, 0, 4, 1); + SetRailType(t, UpdateRailType(GetRailType(t), min_rail)); } } else { if (GetBridgeTransportType(t) == TRANSPORT_RAIL) { if (IsBridgeRamp(t)) { - if (GetRailType(t) > RAILTYPE_RAIL || make_elrail) AB(_m[t].m3, 0, 4, 1); + SetRailType(t, UpdateRailType(GetRailType(t), min_rail)); } else { - if (GetRailTypeOnBridge(t) > RAILTYPE_RAIL || make_elrail) AB(_m[t].m3, 4, 4, 1); + SetRailTypeOnBridge(t, UpdateRailType(GetRailTypeOnBridge(t), min_rail)); } } if (IsBridgeMiddle(t) && IsTransportUnderBridge(t) && GetTransportTypeUnderBridge(t) == TRANSPORT_RAIL) { - if (GetRailType(t) > RAILTYPE_RAIL || make_elrail) AB(_m[t].m3, 0, 4, 1); + SetRailType(t, UpdateRailType(GetRailType(t), min_rail)); } } break;