From 1b6f752a005e2911e3621b8eb3b5610ad4bb2c32 Mon Sep 17 00:00:00 2001 From: Adrian Wielgosik Date: Thu, 19 Feb 2015 17:33:26 +0100 Subject: [PATCH 1/2] Decompiled window_top_toolbar_land_tool_drag --- src/game.h | 6 +- src/localisation/string_ids.h | 2 + src/windows/top_toolbar.c | 126 +++++++++++++++++++++++++++++++++- 3 files changed, 130 insertions(+), 4 deletions(-) diff --git a/src/game.h b/src/game.h index add79df908..94f54a81a2 100644 --- a/src/game.h +++ b/src/game.h @@ -45,9 +45,9 @@ enum GAME_COMMAND { GAME_COMMAND_CHANGE_SURFACE_STYLE, //20 GAME_COMMAND_21, GAME_COMMAND_22, //To do with text input - GAME_COMMAND_23, - GAME_COMMAND_24, - GAME_COMMAND_25, + GAME_COMMAND_RAISE_LAND, + GAME_COMMAND_LOWER_LAND, + GAME_COMMAND_EDIT_LAND_SMOOTH, GAME_COMMAND_RAISE_WATER, GAME_COMMAND_LOWER_WATER, GAME_COMMAND_28, diff --git a/src/localisation/string_ids.h b/src/localisation/string_ids.h index 8505a1797a..9ad5a3291c 100644 --- a/src/localisation/string_ids.h +++ b/src/localisation/string_ids.h @@ -103,6 +103,8 @@ enum { STR_DROPDOWN_GLYPH = 876, STR_TOO_LOW = 877, STR_TOO_HIGH = 878, + STR_CANT_LOWER_LAND_HERE = 879, + STR_CANT_RAISE_LAND_HERE = 880, STR_LOAD_GAME = 882, STR_SAVE_GAME = 883, diff --git a/src/windows/top_toolbar.c b/src/windows/top_toolbar.c index 8f1cc2fbec..9ff656fd9c 100644 --- a/src/windows/top_toolbar.c +++ b/src/windows/top_toolbar.c @@ -771,6 +771,130 @@ static void window_top_toolbar_tool_down(){ } } +/** +* +* rct2: 0x006644DD +*/ +void sub_6644DD(int ebx){ + + int ax = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_A_X, uint16); + int cx = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_A_Y, uint16); + ax += RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_B_X, uint16); + cx += RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_B_Y, uint16); + ax >>= 1; + cx >>= 1; + ax += 0x10; + cx += 0x10; + uint32 dx = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_B_X, uint16); + uint32 bp = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_B_Y, uint16); + dx <<= 16; + bp <<= 16; + dx += RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_A_X, uint16); + bp += RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_A_Y, uint16); + + RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_STRING_ID, rct_string_id) = STR_CANT_RAISE_LAND_HERE; + + if (RCT2_GLOBAL(RCT2_ADDRESS_LAND_TOOL_SIZE, sint16) == 0) { + int di = 1; + + game_do_command(ax, ebx, cx, dx, GAME_COMMAND_EDIT_LAND_SMOOTH, di, bp); + } + else { + int di = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_TYPE, uint16); + + game_do_command(ax, ebx, cx, dx, GAME_COMMAND_RAISE_LAND, di, bp); + } +} + +/** +* +* rct2: 0x006645B3 +*/ +void sub_6645B3(int ebx){ + + int ax = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_A_X, uint16); + int cx = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_A_Y, uint16); + ax += RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_B_X, uint16); + cx += RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_B_Y, uint16); + ax >>= 1; + cx >>= 1; + ax += 0x10; + cx += 0x10; + uint32 dx = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_B_X, uint16); + uint32 bp = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_B_Y, uint16); + dx <<= 16; + bp <<= 16; + dx += RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_A_X, uint16); + bp += RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_A_Y, uint16); + + RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_STRING_ID, rct_string_id) = STR_CANT_LOWER_LAND_HERE; + + if (RCT2_GLOBAL(RCT2_ADDRESS_LAND_TOOL_SIZE, sint16) == 0) { + int di = 0xFFFF; + + game_do_command(ax, ebx, cx, dx, GAME_COMMAND_EDIT_LAND_SMOOTH, di, bp); + } else { + int di = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_TYPE, uint16); + + game_do_command(ax, ebx, cx, dx, GAME_COMMAND_LOWER_LAND, di, bp); + } +} + +/** +* part of window_top_toolbar_tool_drag(0x0066CB4E) +* rct2: 0x00664454 +*/ +void window_top_toolbar_land_tool_drag(short x, short y, rct_window* w, short widgetIndex) +{ + //RCT2_CALLPROC_X(0x00664454, 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; + + y = (y & 0xFF00) | 1; // mov bl, 1 + + sub_6644DD(y); + + RCT2_GLOBAL(RCT2_ADDRESS_LAND_RAISE_COST, uint32) = 0x80000000; + RCT2_GLOBAL(RCT2_ADDRESS_LAND_LOWER_COST, uint32) = 0x80000000; + + return; + } + + dx = -dx; + + if (y >= dx) { + RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_Y, uint16) += dx; + + y = (y & 0xFF00) | 1; // mov bl, 1 + + sub_6645B3(y); + + RCT2_GLOBAL(RCT2_ADDRESS_LAND_RAISE_COST, uint32) = 0x80000000; + RCT2_GLOBAL(RCT2_ADDRESS_LAND_LOWER_COST, uint32) = 0x80000000; + + return; + } +} + /** * part of window_top_toolbar_tool_drag(0x0066CB4E) * rct2: 0x006E6D4B @@ -874,7 +998,7 @@ static void window_top_toolbar_tool_drag() RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TOOL, uint8) = 12; break; case WIDX_LAND: - RCT2_CALLPROC_X(0x00664454, x, y, 0, widgetIndex, (int)w, 0, 0); + window_top_toolbar_land_tool_drag(x, y, w, widgetIndex); break; case WIDX_WATER: window_top_toolbar_water_tool_drag(x, y, w, widgetIndex); From 1ae4bf42cee0337d133c2add4942007649ee7b80 Mon Sep 17 00:00:00 2001 From: Adrian Wielgosik Date: Thu, 19 Feb 2015 17:39:35 +0100 Subject: [PATCH 2/2] Removed unused arguments --- src/windows/top_toolbar.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/windows/top_toolbar.c b/src/windows/top_toolbar.c index 9ff656fd9c..747412cdaa 100644 --- a/src/windows/top_toolbar.c +++ b/src/windows/top_toolbar.c @@ -844,7 +844,7 @@ void sub_6645B3(int ebx){ * part of window_top_toolbar_tool_drag(0x0066CB4E) * rct2: 0x00664454 */ -void window_top_toolbar_land_tool_drag(short x, short y, rct_window* w, short widgetIndex) +void window_top_toolbar_land_tool_drag(short x, short y) { //RCT2_CALLPROC_X(0x00664454, x, y, 0, widgetIndex, (int)w, 0, 0); @@ -852,7 +852,7 @@ void window_top_toolbar_land_tool_drag(short x, short y, rct_window* w, short wi if (!window) return; int widget_index = window_find_widget_from_point(window, x, y); - if (widgetIndex == 0xFFFF) + if (widget_index == 0xFFFF) return; rct_widget *widget = &window->widgets[widget_index]; if (widget->type != WWT_VIEWPORT) @@ -899,7 +899,7 @@ void window_top_toolbar_land_tool_drag(short x, short y, rct_window* w, short wi * 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) +void window_top_toolbar_water_tool_drag(short x, short y) { //RCT2_CALLPROC_X(0x006E6D4B, x, y, 0, widgetIndex, (int)w, 0, 0); @@ -907,7 +907,7 @@ void window_top_toolbar_water_tool_drag(short x, short y, rct_window* w, short w if (!window) return; int widget_index = window_find_widget_from_point(window, x, y); - if (widgetIndex == 0xFFFF) + if (widget_index == 0xFFFF) return; rct_widget *widget = &window->widgets[widget_index]; if (widget->type != WWT_VIEWPORT) @@ -998,10 +998,10 @@ static void window_top_toolbar_tool_drag() RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TOOL, uint8) = 12; break; case WIDX_LAND: - window_top_toolbar_land_tool_drag(x, y, w, widgetIndex); + window_top_toolbar_land_tool_drag(x, y); break; case WIDX_WATER: - window_top_toolbar_water_tool_drag(x, y, w, widgetIndex); + window_top_toolbar_water_tool_drag(x, y); break; case WIDX_SCENERY: RCT2_CALLPROC_X(0x006E2CBC, x, y, 0, widgetIndex, (int)w, 0, 0);