summaryrefslogtreecommitdiff
path: root/src/rail_gui.cpp
diff options
context:
space:
mode:
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;