From cc8fd6e910374b337dd080522d997d80212a1b03 Mon Sep 17 00:00:00 2001 From: rubidium Date: Thu, 4 Feb 2010 17:08:48 +0000 Subject: (svn r19006) -Fix (r18970): default rail type determination failed causing 'A'/SHIFT-F4 not to work the first time. As rail types can now be anything the explicit options for the different railtypes have been removed, leaving the most used rail type and first/last available rail types. --- src/rail_gui.cpp | 56 +++++++++++++++++++++++++++----------------------------- 1 file changed, 27 insertions(+), 29 deletions(-) (limited to 'src/rail_gui.cpp') diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index 1b187f85b..753426fd0 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -1912,40 +1912,38 @@ static void SetDefaultRailGui() if (_local_company == COMPANY_SPECTATOR || !Company::IsValidID(_local_company)) return; extern RailType _last_built_railtype; - RailType rt = (RailType)_settings_client.gui.default_rail_type; - if (rt >= RAILTYPE_END) { - if (rt == DEF_RAILTYPE_MOST_USED) { - /* Find the most used rail type */ - RailType count[RAILTYPE_END]; - memset(count, 0, sizeof(count)); - for (TileIndex t = 0; t < MapSize(); t++) { - if (IsTileType(t, MP_RAILWAY) || IsLevelCrossingTile(t) || HasStationTileRail(t) || - (IsTileType(t, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL)) { - count[GetRailType(t)]++; - } - } - - rt = RAILTYPE_RAIL; - for (RailType r = RAILTYPE_ELECTRIC; r < RAILTYPE_END; r++) { - if (count[r] >= count[rt]) rt = r; + RailType rt = (RailType)(_settings_client.gui.default_rail_type + RAILTYPE_END); + if (rt == DEF_RAILTYPE_MOST_USED) { + /* Find the most used rail type */ + RailType count[RAILTYPE_END]; + memset(count, 0, sizeof(count)); + for (TileIndex t = 0; t < MapSize(); t++) { + if (IsTileType(t, MP_RAILWAY) || IsLevelCrossingTile(t) || HasStationTileRail(t) || + (IsTileType(t, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL)) { + count[GetRailType(t)]++; } + } - /* No rail, just get the first available one */ - if (count[rt] == 0) rt = DEF_RAILTYPE_FIRST; + rt = RAILTYPE_RAIL; + for (RailType r = RAILTYPE_ELECTRIC; r < RAILTYPE_END; r++) { + if (count[r] >= count[rt]) rt = r; } - switch (rt) { - case DEF_RAILTYPE_FIRST: - rt = RAILTYPE_RAIL; - while (rt < RAILTYPE_END && !HasRailtypeAvail(_local_company, rt)) rt++; - break; - case DEF_RAILTYPE_LAST: - rt = GetBestRailtype(_local_company); - break; + /* No rail, just get the first available one */ + if (count[rt] == 0) rt = DEF_RAILTYPE_FIRST; + } + switch (rt) { + case DEF_RAILTYPE_FIRST: + rt = RAILTYPE_RAIL; + while (rt < RAILTYPE_END && !HasRailtypeAvail(_local_company, rt)) rt++; + break; - default: - break; - } + case DEF_RAILTYPE_LAST: + rt = GetBestRailtype(_local_company); + break; + + default: + break; } _last_built_railtype = _cur_railtype = rt; -- cgit v1.2.3-54-g00ecf