From d690ee64239425db49960f6886eda5048812feaa Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 27 Mar 2016 14:18:20 +0100 Subject: [PATCH] fix #3183: opening ride with construction window open Issue caused with boat hire rides as there is usually a ghost station present when the construction window is open. This causes vehicles to be created in the ghost station. Fixed by closing the construction window before the vehicles are created for the ride. --- src/ride/ride.c | 9 +++++++++ src/windows/ride.c | 7 ++++++- src/windows/ride_construction.c | 9 +++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/ride/ride.c b/src/ride/ride.c index fdf77fdbd0..6cad6750a1 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -5420,6 +5420,15 @@ void game_command_set_ride_status(int *eax, int *ebx, int *ecx, int *edx, int *e return; } + if (*ebx & GAME_COMMAND_FLAG_APPLY) { + // Fix #3183: Make sure we close the construction window so the ride finishes any editing code before opening + // otherwise vehicles get added to the ride incorrectly (such as to a ghost station) + rct_window *constructionWindow = window_find_by_number(WC_RIDE_CONSTRUCTION, rideIndex); + if (constructionWindow != NULL) { + window_close(constructionWindow); + } + } + if (targetStatus == RIDE_STATUS_TESTING) { if (!ride_is_valid_for_test(rideIndex, targetStatus == RIDE_STATUS_OPEN, *ebx & GAME_COMMAND_FLAG_APPLY)) { *ebx = MONEY32_UNDEFINED; diff --git a/src/windows/ride.c b/src/windows/ride.c index 53ab10bbc6..b23ac990ee 100644 --- a/src/windows/ride.c +++ b/src/windows/ride.c @@ -1678,6 +1678,7 @@ static void window_ride_rename(rct_window *w) */ static void window_ride_main_mouseup(rct_window *w, int widgetIndex) { + uint8 rideIndex; rct_ride *ride; int status; @@ -1698,7 +1699,11 @@ static void window_ride_main_mouseup(rct_window *w, int widgetIndex) window_ride_set_page(w, widgetIndex - WIDX_TAB_1); break; case WIDX_CONSTRUCTION: - ride_construct((uint8)w->number); + rideIndex = (uint8)w->number; + ride_construct(rideIndex); + if (window_find_by_number(WC_RIDE_CONSTRUCTION, rideIndex) != NULL) { + window_close(w); + } break; case WIDX_RENAME: window_ride_rename(w); diff --git a/src/windows/ride_construction.c b/src/windows/ride_construction.c index c9c3b4eef3..b322b0f417 100644 --- a/src/windows/ride_construction.c +++ b/src/windows/ride_construction.c @@ -1929,6 +1929,15 @@ static void window_ride_construction_exit_click(rct_window *w) */ static void window_ride_construction_update(rct_window *w) { + rct_ride *ride = get_ride(_currentRideIndex); + + // Close construction window if ride is not closed, + // editing ride while open will cause many issues until properly handled + if (ride->status != RIDE_STATUS_CLOSED) { + window_close(w); + return; + } + switch (_currentTrackCurve) { case 429: case 376: