From c040a69fecdb4404a5da5df03b29d36f3d7a25f2 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Wed, 9 Feb 2022 02:13:46 +0000 Subject: [PATCH] Handle case where rail waypoint runs out of station spec slots --- src/waypoint_cmd.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/waypoint_cmd.cpp b/src/waypoint_cmd.cpp index 6d665eb4df..7f88554636 100644 --- a/src/waypoint_cmd.cpp +++ b/src/waypoint_cmd.cpp @@ -280,6 +280,10 @@ CommandCost CmdBuildRailWaypoint(TileIndex start_tile, DoCommandFlag flags, uint if (!Waypoint::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING); } + /* Check if we can allocate a custom stationspec to this station */ + int map_spec_index = AllocateSpecToStation(spec, wp, (flags & DC_EXEC) != 0); + if (map_spec_index == -1) return_cmd_error(STR_ERROR_TOO_MANY_STATION_SPECS); + if (flags & DC_EXEC) { if (wp == nullptr) { wp = new Waypoint(start_tile); @@ -301,8 +305,6 @@ CommandCost CmdBuildRailWaypoint(TileIndex start_tile, DoCommandFlag flags, uint wp->UpdateVirtCoord(); - byte map_spec_index = AllocateSpecToStation(spec, wp, true); - Company *c = Company::Get(wp->owner); for (int i = 0; i < count; i++) { TileIndex tile = start_tile + i * offset;