From c709976703fa98ff3b0f707e0dafc2b996a8cf89 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Thu, 18 Apr 2024 12:21:36 +0100 Subject: [PATCH] Feature: [NewGRF] Allow fixed layout up to 256 tiles per NewGRF rail station. Allow using up to 256 tile layouts in property 0E or callback 24, which defines the layout to be saved into the map. This was originally limited to 8, because station graphics above 8 referred to other station types but that was changed in 2007. 1) More efficient than using callback 14, as that needs to be checked every time a station tile is rendered. 2) The layout does not get changed when the station is changed (this may or may not be desirable!) Using more than 256 layouts still requires callback 14. (cherry picked from commit 6e553410d3b569c347311167e52a5bde292b2f6a) --- src/newgrf.cpp | 6 +++--- src/newgrf_callbacks.h | 2 +- src/station_cmd.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 90a00a07ad..72ab78e0db 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -2035,11 +2035,11 @@ static ChangeInfoResult StationChangeInfo(uint stid, int numinfo, int prop, cons const uint8_t *layout = buf->ReadBytes(length * number); statspec->layouts[length - 1][number - 1].assign(layout, layout + length * number); - /* Validate tile values are only the permitted 00, 02, 04 and 06. */ + /* Ensure the first bit, axis, is zero. The rest of the value is validated during rendering, as we don't know the range yet. */ for (auto &tile : statspec->layouts[length - 1][number - 1]) { - if ((tile & 6) != tile) { + if ((tile & ~1U) != tile) { GrfMsg(1, "StationChangeInfo: Invalid tile {} in layout {}x{}", tile, length, number); - tile &= 6; + tile &= ~1U; } } } diff --git a/src/newgrf_callbacks.h b/src/newgrf_callbacks.h index 947c161129..d9b8c5db2d 100644 --- a/src/newgrf_callbacks.h +++ b/src/newgrf_callbacks.h @@ -38,7 +38,7 @@ enum CallbackID { /** Determine whether a newstation should be made available to build. */ CBID_STATION_AVAILABILITY = 0x13, // 8 bit callback - /** Choose a tile layout to draw, instead of the standard 0-7 range. */ + /** Choose a tile layout to draw, instead of the standard range. */ CBID_STATION_DRAW_TILE_LAYOUT = 0x14, /** diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index a688595d3b..1f8a1ca442 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -1668,7 +1668,7 @@ CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32_ /* As the station is not yet completely finished, the station does not yet exist. */ uint16_t callback = GetStationCallback(CBID_STATION_BUILD_TILE_LAYOUT, platinfo, 0, statspec, nullptr, tile, rt); if (callback != CALLBACK_FAILED) { - if (callback < 8) { + if (callback <= UINT8_MAX) { SetStationGfx(tile, (callback & ~1) + axis); } else { ErrorUnknownCallbackResult(statspec->grf_prop.grffile->grfid, CBID_STATION_BUILD_TILE_LAYOUT, callback);