summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2019-12-18 00:48:03 +0100
committerCharles Pigott <charlespigott@googlemail.com>2019-12-23 17:23:20 +0000
commit3d29c9483b180791f3d5b5f9a6664fc1322d4f52 (patch)
treef662c198163810e2f3c38ca7641a5c13c43fe613
parent7f351fd7c1e853918d2ce7bfd1c9c6c5a2af84ef (diff)
downloadopenttd-3d29c9483b180791f3d5b5f9a6664fc1322d4f52.tar.xz
Codechange: Use a switch with fall-through instead of a if-sequence with context data between cases.
-rw-r--r--src/rail_gui.cpp46
-rw-r--r--src/rail_type.h4
2 files changed, 25 insertions, 25 deletions
diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp
index 2cf2f38e4..cd0d93c8f 100644
--- a/src/rail_gui.cpp
+++ b/src/rail_gui.cpp
@@ -1908,38 +1908,42 @@ 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 + RAILTYPE_END);
- if (rt == DEF_RAILTYPE_MOST_USED) {
- /* Find the most used rail type */
- uint 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)]++;
+ RailType rt;
+ switch (_settings_client.gui.default_rail_type) {
+ case 2: {
+ /* Find the most used rail type */
+ uint 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;
- }
+ rt = RAILTYPE_RAIL;
+ for (RailType r = RAILTYPE_ELECTRIC; r < RAILTYPE_END; r++) {
+ if (count[r] >= count[rt]) rt = r;
+ }
- /* No rail, just get the first available one */
- if (count[rt] == 0) rt = DEF_RAILTYPE_FIRST;
- }
- switch (rt) {
- case DEF_RAILTYPE_FIRST:
+ if (count[rt] > 0) break;
+
+ /* No rail, just get the first available one */
+ FALLTHROUGH;
+ }
+ case 0:
+ /* Use first available type */
rt = RAILTYPE_RAIL;
while (rt < RAILTYPE_END && !HasRailtypeAvail(_local_company, rt)) rt++;
break;
- case DEF_RAILTYPE_LAST:
+ case 1:
+ /* Use last available type */
rt = GetBestRailtype(_local_company);
break;
default:
- break;
+ NOT_REACHED();
}
_last_built_railtype = _cur_railtype = rt;
diff --git a/src/rail_type.h b/src/rail_type.h
index be30ffd6f..874a8ebbb 100644
--- a/src/rail_type.h
+++ b/src/rail_type.h
@@ -32,10 +32,6 @@ enum RailType : byte {
RAILTYPE_MAGLEV = 3, ///< Maglev
RAILTYPE_END = 64, ///< Used for iterations
INVALID_RAILTYPE = 0xFF, ///< Flag for invalid railtype
-
- DEF_RAILTYPE_FIRST = RAILTYPE_END, ///< Default railtype: first available
- DEF_RAILTYPE_LAST, ///< Default railtype: last available
- DEF_RAILTYPE_MOST_USED, ///< Default railtype: most used
};
/** Allow incrementing of Track variables */