diff --git a/src/interface/window.h b/src/interface/window.h index 347df9c53f..6e1d617eec 100644 --- a/src/interface/window.h +++ b/src/interface/window.h @@ -598,6 +598,10 @@ void window_ride_construct(rct_window *w); void window_ride_list_open(); rct_window *window_ride_construction_open(); rct_window *window_maze_construction_open(); +void ride_construction_toolupdate_entrance_exit(int screenX, int screenY); +void ride_construction_toolupdate_construct(int screenX, int screenY); +void ride_construction_tooldown_construct(int screenX, int screenY); + void window_maze_construction_update_pressed_widgets(); void window_track_place_open(); rct_window *window_new_ride_open(); diff --git a/src/windows/maze_construction.c b/src/windows/maze_construction.c index 3e08cee16d..9e68c4dd3e 100644 --- a/src/windows/maze_construction.c +++ b/src/windows/maze_construction.c @@ -46,6 +46,8 @@ enum { WIDX_MAZE_DIRECTION_NE, WIDX_MAZE_DIRECTION_SW, WIDX_MAZE_DIRECTION_SE, + WIDX_MAZE_ENTRANCE = 29, + WIDX_MAZE_EXIT, }; static rct_widget window_maze_construction_widgets[] = { @@ -94,8 +96,8 @@ static void window_maze_construction_mouseup(rct_window *w, int widgetIndex); static void window_maze_construction_resize(rct_window *w); static void window_maze_construction_mousedown(int widgetIndex, rct_window *w, rct_widget *widget); static void window_maze_construction_update(rct_window *w); -static void window_ride_construction_toolupdate(rct_window* w, int widgetIndex, int x, int y); -static void window_ride_construction_tooldown(rct_window* w, int widgetIndex, int x, int y); +static void window_maze_construction_toolupdate(rct_window* w, int widgetIndex, int x, int y); +static void window_maze_construction_tooldown(rct_window* w, int widgetIndex, int x, int y); static void window_maze_construction_invalidate(rct_window *w); static void window_maze_construction_paint(rct_window *w, rct_drawpixelinfo *dpi); @@ -110,8 +112,8 @@ static rct_window_event_list window_maze_construction_events = { window_maze_construction_update, NULL, NULL, - window_ride_construction_toolupdate, - window_ride_construction_tooldown, + window_maze_construction_toolupdate, + window_maze_construction_tooldown, NULL, NULL, NULL, @@ -183,13 +185,46 @@ static void window_maze_construction_close(rct_window *w) } } +static void window_maze_construction_entrance_mouseup(rct_window *w, int widgetIndex){ + if (tool_set(w, widgetIndex, 12)) + return; + + RCT2_GLOBAL(0x00F44191, uint8) = widgetIndex == WIDX_MAZE_ENTRANCE ? 0 : 1; + RCT2_GLOBAL(0x00F44192, uint8) = w->number; + RCT2_GLOBAL(0x00F44193, uint8) = 0; + RCT2_GLOBAL(RCT2_ADDRESS_INPUT_FLAGS, uint32) |= INPUT_FLAG_6; + + sub_6C9627(); + + // ??? + uint8 old_state = _rideConstructionState; + _rideConstructionState = 5; + if (old_state != 5) + _rideConstructionState = old_state; + window_maze_construction_update_pressed_widgets(); +} + /** * * rct2: 0x006CD461 */ static void window_maze_construction_mouseup(rct_window *w, int widgetIndex) { - RCT2_CALLPROC_X(0x006CD461, 0, 0, 0, widgetIndex, (int)w, 0, 0); + switch (widgetIndex){ + case WIDX_CLOSE: + window_close(w); + break; + case WIDX_MAZE_ENTRANCE: + case WIDX_MAZE_EXIT: + window_maze_construction_entrance_mouseup(w, widgetIndex); + break; + case WIDX_MAZE_DIRECTION_NW: + case WIDX_MAZE_DIRECTION_NE: + case WIDX_MAZE_DIRECTION_SE: + case WIDX_MAZE_DIRECTION_SW: + RCT2_CALLPROC_X(0x006CD4AB, 0, 0, 0, widgetIndex, (int)w, 0, 0); + break; + } } /** @@ -223,18 +258,84 @@ static void window_maze_construction_update(rct_window *w) * * rct2: 0x006CD63E */ -static void window_ride_construction_toolupdate(rct_window* w, int widgetIndex, int x, int y) +static void window_maze_construction_toolupdate(rct_window* w, int widgetIndex, int x, int y) { - RCT2_CALLPROC_X(0x006CD63E, x, y, 0, widgetIndex, (int)w, 0, 0); + switch (widgetIndex){ + case WIDX_MAZE_DIRECTION_GROUPBOX: + ride_construction_toolupdate_construct(x, y); + break; + case WIDX_MAZE_ENTRANCE: + case WIDX_MAZE_EXIT: + ride_construction_toolupdate_entrance_exit(x, y); + break; + } +} + +/* rct2: 0x006C825F */ +static void window_maze_construction_entrance_tooldown(int x, int y, rct_window* w){ + sub_6C9627(); + + map_invalidate_selection_rect(); + + RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_FLAGS, uint16) &= ~((1 << 0) | (1 << 2)); + + int direction = 0; + ride_get_entrance_or_exit_position_from_screen_position(x, y, &x, &y, &direction); + + if (RCT2_GLOBAL(0x00F44194, uint8) == 0xFF) + return; + + uint8 rideIndex = RCT2_GLOBAL(0x00F44192, uint8); + uint8 is_exit = RCT2_GLOBAL(0x00F44191, uint8); + RCT2_GLOBAL(0x00141E9AE, rct_string_id) = is_exit ? 1144 : 1145; + + money32 cost = game_do_command( + x, + GAME_COMMAND_FLAG_APPLY | ((direction ^ 2) << 8), + y, + rideIndex | (is_exit << 8), + GAME_COMMAND_PLACE_RIDE_ENTRANCE_OR_EXIT, + RCT2_GLOBAL(0x00F44193, uint8), + 0); + + if (cost == MONEY32_UNDEFINED) + return; + + sound_play_panned( + SOUND_PLACE_ITEM, + 0x8001, + RCT2_GLOBAL(0x009DEA5E, sint16), + RCT2_GLOBAL(0x009DEA60, sint16), + RCT2_GLOBAL(0x009DEA62, uint16)); + + rct_ride* ride = GET_RIDE(rideIndex); + if (ride_are_all_possible_entrances_and_exits_built(ride)){ + tool_cancel(); + if (ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_15)) + window_close(w); + } + else{ + RCT2_GLOBAL(0x00F44191, uint8) = is_exit ^ 1; + window_invalidate_by_class(WC_RIDE_CONSTRUCTION); + RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WIDGETINDEX, uint8) = is_exit ? WIDX_MAZE_ENTRANCE : WIDX_MAZE_EXIT; + } } /** * * rct2: 0x006CD65D */ -static void window_ride_construction_tooldown(rct_window* w, int widgetIndex, int x, int y) +static void window_maze_construction_tooldown(rct_window* w, int widgetIndex, int x, int y) { - RCT2_CALLPROC_X(0x006CD65D, x, y, 0, widgetIndex, (int)w, 0, 0); + switch (widgetIndex){ + case WIDX_MAZE_DIRECTION_GROUPBOX: + ride_construction_tooldown_construct(x, y); + break; + case WIDX_MAZE_ENTRANCE: + case WIDX_MAZE_EXIT: + window_maze_construction_entrance_tooldown(x, y, w); + break; + } } /** diff --git a/src/windows/ride_construction.c b/src/windows/ride_construction.c index 14d2327a5c..6e95b1b0e9 100644 --- a/src/windows/ride_construction.c +++ b/src/windows/ride_construction.c @@ -478,10 +478,6 @@ static void window_ride_construction_show_special_track_dropdown(rct_window *w, static void ride_selected_track_set_seat_rotation(int seatRotation); static void loc_6C7502(int al); static void ride_construction_set_brakes_speed(int brakesSpeed); - -static void ride_construction_toolupdate_construct(int screenX, int screenY); -static void ride_construction_toolupdate_entrance_exit(int screenX, int screenY); -static void ride_construction_tooldown_construct(int screenX, int screenY); static void ride_construction_tooldown_entrance_exit(int screenX, int screenY); uint8 *_currentPossibleRideConfigurations = (uint8*)0x00F4407C; @@ -3221,7 +3217,7 @@ static void ride_construction_set_brakes_speed(int brakesSpeed) * * rct2: 0x006CC6A8 */ -static void ride_construction_toolupdate_construct(int screenX, int screenY) +void ride_construction_toolupdate_construct(int screenX, int screenY) { int x, y, z, highestZ; rct_ride *ride; @@ -3311,7 +3307,26 @@ static void ride_construction_toolupdate_construct(int screenX, int screenY) _previousTrackPieceY = y; _previousTrackPieceZ = z; if (ride->type == RIDE_TYPE_MAZE) { - // goto loc_6CCA31 + for (;;) { + sub_6CA2DF(&trackType, &trackDirection, &rideIndex, &edxRS16, &x, &y, &z, NULL); + _currentTrackPrice = sub_6CA162(rideIndex, trackType, trackDirection, edxRS16, x, y, z); + if (_currentTrackPrice != MONEY32_UNDEFINED) + break; + + bx--; + if (bx == 0) + break; + + _currentTrackBeginZ -= 8; + if (_currentTrackBeginZ & 0x8000) + break; + + if (bx >= 0) + _currentTrackBeginZ += 16; + } + + window_maze_construction_update_pressed_widgets(); + map_invalidate_map_selection_tiles(); return; } @@ -3341,7 +3356,7 @@ static void ride_construction_toolupdate_construct(int screenX, int screenY) * * rct2: 0x006CD354 */ -static void ride_construction_toolupdate_entrance_exit(int screenX, int screenY) +void ride_construction_toolupdate_entrance_exit(int screenX, int screenY) { int x, y, direction; uint8 unk; @@ -3386,7 +3401,7 @@ static void ride_construction_toolupdate_entrance_exit(int screenX, int screenY) * * rct2: 0x006CCA73 */ -static void ride_construction_tooldown_construct(int screenX, int screenY) +void ride_construction_tooldown_construct(int screenX, int screenY) { int trackType, trackDirection, rideIndex, edxRS16, x, y, z, properties, highestZ; rct_window *w; @@ -3441,7 +3456,66 @@ static void ride_construction_tooldown_construct(int screenX, int screenY) } if (ride->type == RIDE_TYPE_MAZE) { - // goto loc_6CCDE4 + for (int zAttempts = 41; zAttempts >= 0; zAttempts--) { + _rideConstructionState = RIDE_CONSTRUCTION_STATE_6; + _currentTrackBeginX = x; + _currentTrackBeginY = y; + _currentTrackBeginZ = z; + _currentTrackSelectionFlags = 0; + _rideConstructionArrowPulseTime = 0; + window_maze_construction_update_pressed_widgets(); + w = window_find_by_class(WC_RIDE_CONSTRUCTION); + if (w == NULL) + break; + + RCT2_GLOBAL(0x009A8C29, uint8) |= 1; + + RCT2_GLOBAL(0x00141E9AE, rct_string_id) = 927; + RCT2_GLOBAL(0x00F44074, money32) = game_do_command( + _currentTrackBeginX, + GAME_COMMAND_FLAG_APPLY | (4 << 8), + _currentTrackBeginY, + _currentRideIndex, + GAME_COMMAND_SET_MAZE_TRACK, + _currentTrackBeginZ, + 0); + + RCT2_GLOBAL(0x009A8C29, uint8) &= ~1; + + if (RCT2_GLOBAL(0x00F44074, money32) == MONEY32_UNDEFINED) { + rct_string_id errorText = RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TEXT, rct_string_id); + z -= 8; + if ( + errorText == STR_NOT_ENOUGH_CASH_REQUIRES || + errorText == STR_CAN_ONLY_BUILD_THIS_UNDERWATER || + errorText == STR_CAN_ONLY_BUILD_THIS_ON_WATER || + errorText == STR_RIDE_CANT_BUILD_THIS_UNDERWATER || + errorText == STR_CAN_ONLY_BUILD_THIS_ABOVE_GROUND || + errorText == STR_TOO_HIGH_FOR_SUPPORTS || + zAttempts == 0 || + z < 0 + ) { + sound_play_panned(SOUND_ERROR, RCT2_GLOBAL(0x0142406C, sint32), x, y, z); + w = window_find_by_class(WC_RIDE_CONSTRUCTION); + if (w != NULL){ + tool_set(w, 23, 12); + RCT2_GLOBAL(0x009DE518, uint32) |= (1 << 6); + RCT2_GLOBAL(0x00F44159, uint8) = 0; + RCT2_GLOBAL(0x00F4415C, uint8) = 0; + } + window_maze_construction_update_pressed_widgets(); + break; + } + else if (zAttempts >= 0) { + z += 16; + } + } + else { + window_close_by_class(WC_ERROR); + sound_play_panned(SOUND_PLACE_ITEM, 0x8001, _currentTrackBeginX, _currentTrackBeginY, _currentTrackBeginZ); + break; + } + } return; }