From 2eacf36d0a6e3a327ecba227e66e3d6a8bf1ff1a Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Wed, 20 Sep 2023 20:59:25 +0100 Subject: [PATCH] Codechange: List fallback station names by ID instead of magic number. This improves readability and intention of the station name generator. --- src/station_cmd.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 2ab50585e9..04b14dc37c 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -354,7 +354,23 @@ static StringID GenerateStationName(Station *st, TileIndex tile, StationNaming n (TileX(tile) < TileX(t->xy)) + (TileY(tile) < TileY(t->xy)) * 2]; - tmp = free_names & ((1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 6) | (1 << 7) | (1 << 12) | (1 << 26) | (1 << 27) | (1 << 28) | (1 << 29) | (1 << 30)); + /** Bitmask of remaining station names that can be used when a more specific name has not been used. */ + static const uint32_t fallback_names = ( + (1U << M(STR_SV_STNAME_NORTH)) | + (1U << M(STR_SV_STNAME_SOUTH)) | + (1U << M(STR_SV_STNAME_EAST)) | + (1U << M(STR_SV_STNAME_WEST)) | + (1U << M(STR_SV_STNAME_TRANSFER)) | + (1U << M(STR_SV_STNAME_HALT)) | + (1U << M(STR_SV_STNAME_EXCHANGE)) | + (1U << M(STR_SV_STNAME_ANNEXE)) | + (1U << M(STR_SV_STNAME_SIDINGS)) | + (1U << M(STR_SV_STNAME_BRANCH)) | + (1U << M(STR_SV_STNAME_UPPER)) | + (1U << M(STR_SV_STNAME_LOWER)) + ); + + tmp = free_names & fallback_names; return (tmp == 0) ? STR_SV_STNAME_FALLBACK : (STR_SV_STNAME + FindFirstBit(tmp)); } #undef M