summaryrefslogtreecommitdiff
path: root/src/rail_gui.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-02-04 17:08:48 +0000
committerrubidium <rubidium@openttd.org>2010-02-04 17:08:48 +0000
commitcc8fd6e910374b337dd080522d997d80212a1b03 (patch)
tree8fed519cf854b5ad9861a991024c4ada908470e4 /src/rail_gui.cpp
parentfbb9b4760a7b85867817b4a089aeca0506bdb8be (diff)
downloadopenttd-cc8fd6e910374b337dd080522d997d80212a1b03.tar.xz
(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.
Diffstat (limited to 'src/rail_gui.cpp')
-rw-r--r--src/rail_gui.cpp56
1 files changed, 27 insertions, 29 deletions
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;