From a7455f8b31e6ebb233c1831590e0c6dbfa3acb29 Mon Sep 17 00:00:00 2001 From: Adrian Wielgosik Date: Wed, 18 Feb 2015 20:26:16 +0100 Subject: [PATCH] Decompiled window_top_toolbar_water_tool_drag --- src/game.h | 4 +- src/localisation/string_ids.h | 3 ++ src/windows/top_toolbar.c | 71 ++++++++++++++++++++++++++++++++++- 3 files changed, 75 insertions(+), 3 deletions(-) diff --git a/src/game.h b/src/game.h index 37c69cbdb7..add79df908 100644 --- a/src/game.h +++ b/src/game.h @@ -48,8 +48,8 @@ enum GAME_COMMAND { GAME_COMMAND_23, GAME_COMMAND_24, GAME_COMMAND_25, - GAME_COMMAND_26, - GAME_COMMAND_27, + GAME_COMMAND_RAISE_WATER, + GAME_COMMAND_LOWER_WATER, GAME_COMMAND_28, GAME_COMMAND_HIRE_NEW_STAFF_MEMBER, // 29 GAME_COMMAND_SET_STAFF_PATROL, //30 diff --git a/src/localisation/string_ids.h b/src/localisation/string_ids.h index 328c974847..8505a1797a 100644 --- a/src/localisation/string_ids.h +++ b/src/localisation/string_ids.h @@ -309,6 +309,9 @@ enum { STR_PLACE_SCENERY_TIP = 1159, STR_ADJUST_WATER_TIP = 1160, + STR_CANT_LOWER_WATER_LEVEL_HERE = 1166, + STR_CANT_RAISE_WATER_LEVEL_HERE = 1167, + STR_OPTIONS_TITLE = 1168, STR_SOUND_NONE = 1169, diff --git a/src/windows/top_toolbar.c b/src/windows/top_toolbar.c index e65ff0bb2d..8f1cc2fbec 100644 --- a/src/windows/top_toolbar.c +++ b/src/windows/top_toolbar.c @@ -771,6 +771,75 @@ static void window_top_toolbar_tool_down(){ } } +/** +* part of window_top_toolbar_tool_drag(0x0066CB4E) +* rct2: 0x006E6D4B +*/ +void window_top_toolbar_water_tool_drag(short x, short y, rct_window* w, short widgetIndex) +{ + //RCT2_CALLPROC_X(0x006E6D4B, x, y, 0, widgetIndex, (int)w, 0, 0); + + rct_window *window = window_find_from_point(x, y); + if (!window) + return; + int widget_index = window_find_widget_from_point(window, x, y); + if (widgetIndex == 0xFFFF) + return; + rct_widget *widget = &window->widgets[widget_index]; + if (widget->type != WWT_VIEWPORT) + return; + rct_viewport *viewport = window->viewport; + if (!viewport) + return; + + sint16 dx = 0xFFF0; + dx >>= viewport->zoom; + + y -= RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_Y, uint16); + + if (y <= dx) { + RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_Y, uint16) += dx; + + RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_STRING_ID, rct_string_id) = STR_CANT_RAISE_WATER_LEVEL_HERE; + + game_do_command( + RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_A_X, uint16), + 1, + RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_A_Y, uint16), + dx, + GAME_COMMAND_RAISE_WATER, + RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_B_X, uint16), + RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_B_Y, uint16) + ); + RCT2_GLOBAL(RCT2_ADDRESS_WATER_RAISE_COST, uint32) = 0x80000000; + RCT2_GLOBAL(RCT2_ADDRESS_WATER_LOWER_COST, uint32) = 0x80000000; + + return; + } + + dx = -dx; + + if (y >= dx) { + RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_Y, uint16) += dx; + + RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_STRING_ID, rct_string_id) = STR_CANT_LOWER_WATER_LEVEL_HERE; + + game_do_command( + RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_A_X, uint16), + 1, + RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_A_Y, uint16), + dx, + GAME_COMMAND_LOWER_WATER, + RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_B_X, uint16), + RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_B_Y, uint16) + ); + RCT2_GLOBAL(RCT2_ADDRESS_WATER_RAISE_COST, uint32) = 0x80000000; + RCT2_GLOBAL(RCT2_ADDRESS_WATER_LOWER_COST, uint32) = 0x80000000; + + return; + } +} + /** * * rct2: 0x0066CB4E @@ -808,7 +877,7 @@ static void window_top_toolbar_tool_drag() RCT2_CALLPROC_X(0x00664454, x, y, 0, widgetIndex, (int)w, 0, 0); break; case WIDX_WATER: - RCT2_CALLPROC_X(0x006E6D4B, x, y, 0, widgetIndex, (int)w, 0, 0); + window_top_toolbar_water_tool_drag(x, y, w, widgetIndex); break; case WIDX_SCENERY: RCT2_CALLPROC_X(0x006E2CBC, x, y, 0, widgetIndex, (int)w, 0, 0);