From 2cfb2908dee1412726e2bd704f3e7c6e4fefe10e Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 31 Aug 2014 15:40:08 +0100 Subject: [PATCH 1/5] add ride track functions, for window ride branch --- src/map.c | 3 -- src/map.h | 2 ++ src/ride.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ride.h | 4 +++ 4 files changed, 94 insertions(+), 3 deletions(-) diff --git a/src/map.c b/src/map.c index c82fd6dc48..ac086487e4 100644 --- a/src/map.c +++ b/src/map.c @@ -23,9 +23,6 @@ #include "date.h" #include "map.h" -#define GET_MAP_ELEMENT(x) (&(RCT2_ADDRESS(RCT2_ADDRESS_MAP_ELEMENTS, rct_map_element)[x])) -#define TILE_MAP_ELEMENT_POINTER(x) (RCT2_ADDRESS(RCT2_ADDRESS_TILE_MAP_ELEMENT_POINTERS, rct_map_element*)[x]) - static void tiles_init(); void map_element_set_terrain(rct_map_element *element, int terrain) diff --git a/src/map.h b/src/map.h index 8aa4e171fd..6c2cbf8b32 100644 --- a/src/map.h +++ b/src/map.h @@ -199,5 +199,7 @@ int map_element_height(int x, int y); void sub_68B089(); int map_coord_is_connected(uint16 coordinate, uint8 height, uint8 face_direction); +#define GET_MAP_ELEMENT(x) (&(RCT2_ADDRESS(RCT2_ADDRESS_MAP_ELEMENTS, rct_map_element)[x])) +#define TILE_MAP_ELEMENT_POINTER(x) (RCT2_ADDRESS(RCT2_ADDRESS_TILE_MAP_ELEMENT_POINTERS, rct_map_element*)[x]) #endif diff --git a/src/ride.c b/src/ride.c index bc5ae32544..546817e186 100644 --- a/src/ride.c +++ b/src/ride.c @@ -344,3 +344,91 @@ void ride_check_all_reachable() } } +/** + * + * rct2: 0x006CAF80 + * ax result x + * bx result y + * dl ride index + * esi result map element + */ +rct_map_element *sub_6CAF80(int rideIndex, int *outX, int *outY) +{ + rct_map_element *resultMapElement, *mapElement; + int foundSpecialTrackPiece; + + resultMapElement = (rct_map_element*)-1; + foundSpecialTrackPiece = 0; + + uint16 x, y; + for (x = 0; x < 256; x++) { + for (y = 0; y < 256; y++) { + // Iterate through map elements on tile + int tileIndex = (y << 8) | x; + mapElement = TILE_MAP_ELEMENT_POINTER(tileIndex); + do { + if ((mapElement->type & MAP_ELEMENT_TYPE_MASK) != MAP_ELEMENT_TYPE_TRACK) + continue; + if (rideIndex != mapElement->properties.track.ride_index) + continue; + + // Found a track piece for target ride + + // Check if its a ??? + int specialTrackPiece = ( + (mapElement->properties.track.type != 2 && mapElement->properties.track.type != 3) && + (RCT2_ADDRESS(0x0099BA64, uint8)[mapElement->properties.track.type * 16] & 0x10) + ); + + // Set result tile to this track piece if first found track or a ??? + if (resultMapElement == (rct_map_element*)-1 || specialTrackPiece) { + resultMapElement = mapElement; + + if (outX != NULL) *outX = x * 32; + if (outY != NULL) *outY = y * 32; + } + + if (specialTrackPiece) { + foundSpecialTrackPiece = 1; + return resultMapElement; + } + } while (!(mapElement->flags & MAP_ELEMENT_FLAG_LAST_TILE) && mapElement++); + } + } + return resultMapElement; +} + +/** + * + * rct2: 0x006CB02F + * ax result x + * bx result y + * esi input / output map element + */ +rct_map_element *ride_find_track_gap(rct_map_element *startTrackElement, int *outX, int *outY) +{ + int eax, ebx, ecx, edx, esi, edi, ebp; + esi = (int)startTrackElement; + eax = *outX; + ebx = 0; + ecx = *outY; + edx = 0; + edi = 0; + ebp = 0; + RCT2_CALLFUNC_X(0x006CB02F, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); + + if (outX != NULL) *outX = eax & 0xFFFF; + if (outY != NULL) *outY = ecx & 0xFFFF; + return (rct_map_element*)esi; +} + +/** + * + * rct2: 0x006CC056 + */ +int ride_try_construct(rct_map_element *trackMapElement) +{ + // Success stored in carry flag which can't be accessed after call using is macro + RCT2_CALLPROC_X(0x006CC056, 0, 0, 0, (int)trackMapElement, 0, 0, 0); + return 1; +} \ No newline at end of file diff --git a/src/ride.h b/src/ride.h index 77f4013831..dca498d637 100644 --- a/src/ride.h +++ b/src/ride.h @@ -21,6 +21,7 @@ #ifndef _RIDE_H_ #define _RIDE_H_ +#include "map.h" #include "rct2.h" #include "string_ids.h" @@ -381,5 +382,8 @@ void ride_init_all(); void reset_all_ride_build_dates(); void ride_update_favourited_stat(); void ride_check_all_reachable(); +rct_map_element *sub_6CAF80(int rideIndex, int *outX, int *outY); +rct_map_element *ride_find_track_gap(rct_map_element *startTrackElement, int *outX, int *outY); +int ride_try_construct(rct_map_element *trackMapElement); #endif From ba6d0bee30fd1fcf57c99c7a6d93cfa4406f6519 Mon Sep 17 00:00:00 2001 From: Jackson Davis Date: Mon, 1 Sep 2014 16:55:51 +0100 Subject: [PATCH 2/5] First pass at 6EE65A --- src/window_footpath.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/window_footpath.c b/src/window_footpath.c index 451816cb38..db6146c5a8 100644 --- a/src/window_footpath.c +++ b/src/window_footpath.c @@ -120,6 +120,7 @@ static void window_footpath_tooldrag(); static void window_footpath_toolup(); static void window_footpath_invalidate(); static void window_footpath_paint(); +static void sub_6EE65A(rct_window* w); static void* window_footpath_events[] = { window_footpath_close, @@ -201,7 +202,7 @@ void window_footpath_open() (1 << WIDX_CONSTRUCT_BRIDGE_OR_TUNNEL); window_init_scroll_widgets(window); - RCT2_CALLPROC_EBPSAFE(0x006EE65A); + sub_6EE65A(window); //RCT2_CALLPROC_EBPSAFE(0x006EE65A); show_gridlines(); window->colours[0] = 24; window->colours[1] = 24; @@ -825,4 +826,38 @@ loc_6A78EF: loc_6A79B0: RCT2_CALLPROC_EBPSAFE(0x006A855C); -} \ No newline at end of file +} + +static void sub_6EE65A(rct_window* window) +{ + uint16 ax = window->x; + uint16 bx = window->y; + uint16 cx = window->width; + uint16 dx = window->height; + cx += ax; + dx += bx; + for (rct_window* w = g_window_list; w < RCT2_GLOBAL(RCT2_ADDRESS_NEW_WINDOW_PTR, rct_window*); w++) { + if (w == window) + continue; + if (w->flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT)) + continue; + if (w->x >= cx) + continue; + if (w->x + w->width <= ax) + continue; + if (w->y >= dx) + continue; + if (w->y + w->height <= bx) + continue; + window_invalidate(w); + cx += 13; + if (cx >= RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, uint16)) + continue; + cx -= 10; + cx -= w->x; + w->x += cx; + window_invalidate(w); + if (w->viewport != NULL) + w->viewport->x += cx; + } +} From f0d42616598c60b792bf1fbfec58a526cd1a8997 Mon Sep 17 00:00:00 2001 From: Jackson Davis Date: Mon, 1 Sep 2014 17:10:15 +0100 Subject: [PATCH 3/5] Move 6EE65A to window.c + minor refactor --- src/window.c | 35 +++++++++++++++++++++++++++++++++++ src/window.h | 1 + src/window_footpath.c | 36 +----------------------------------- 3 files changed, 37 insertions(+), 35 deletions(-) diff --git a/src/window.c b/src/window.c index 355d5770bf..e81a530965 100644 --- a/src/window.c +++ b/src/window.c @@ -1511,3 +1511,38 @@ void window_align_tabs( rct_window *w, uint8 start_tab_id, uint8 end_tab_id ) } } } + +/** + * Finds overlapping windows and moves them if possible + * rct2: 0x006EE65A + */ +void window_move_overlapping(rct_window* window) +{ + uint16 cx = window->width + window->x; + uint16 dx = window->height + window->y; + + for (rct_window* w = g_window_list; w < RCT2_GLOBAL(RCT2_ADDRESS_NEW_WINDOW_PTR, rct_window*); w++) { + if (w == window) + continue; + if (w->flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT)) + continue; + if (w->x >= cx) + continue; + if (w->x + w->width <= window->x) + continue; + if (w->y >= dx) + continue; + if (w->y + w->height <= window->y) + continue; + window_invalidate(w); + cx += 13; + if (cx >= RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, uint16)) + continue; + cx -= 10; + cx -= w->x; + w->x += cx; + window_invalidate(w); + if (w->viewport != NULL) + w->viewport->x += cx; + } +} diff --git a/src/window.h b/src/window.h index 1098eba380..440ed28b40 100644 --- a/src/window.h +++ b/src/window.h @@ -469,6 +469,7 @@ void window_staff_init_vars(); void window_event_helper(rct_window* w, short widgetIndex, WINDOW_EVENTS event); void RCT2_CALLPROC_WE_MOUSE_DOWN(int address, int widgetIndex, rct_window*w, rct_widget* widget); +void window_move_overlapping(rct_window* window); #ifdef _MSC_VER #define window_get_register(w) \ diff --git a/src/window_footpath.c b/src/window_footpath.c index db6146c5a8..f852be5ecc 100644 --- a/src/window_footpath.c +++ b/src/window_footpath.c @@ -120,7 +120,6 @@ static void window_footpath_tooldrag(); static void window_footpath_toolup(); static void window_footpath_invalidate(); static void window_footpath_paint(); -static void sub_6EE65A(rct_window* w); static void* window_footpath_events[] = { window_footpath_close, @@ -202,7 +201,7 @@ void window_footpath_open() (1 << WIDX_CONSTRUCT_BRIDGE_OR_TUNNEL); window_init_scroll_widgets(window); - sub_6EE65A(window); //RCT2_CALLPROC_EBPSAFE(0x006EE65A); + window_move_overlapping(window); show_gridlines(); window->colours[0] = 24; window->colours[1] = 24; @@ -828,36 +827,3 @@ loc_6A79B0: RCT2_CALLPROC_EBPSAFE(0x006A855C); } -static void sub_6EE65A(rct_window* window) -{ - uint16 ax = window->x; - uint16 bx = window->y; - uint16 cx = window->width; - uint16 dx = window->height; - cx += ax; - dx += bx; - for (rct_window* w = g_window_list; w < RCT2_GLOBAL(RCT2_ADDRESS_NEW_WINDOW_PTR, rct_window*); w++) { - if (w == window) - continue; - if (w->flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT)) - continue; - if (w->x >= cx) - continue; - if (w->x + w->width <= ax) - continue; - if (w->y >= dx) - continue; - if (w->y + w->height <= bx) - continue; - window_invalidate(w); - cx += 13; - if (cx >= RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, uint16)) - continue; - cx -= 10; - cx -= w->x; - w->x += cx; - window_invalidate(w); - if (w->viewport != NULL) - w->viewport->x += cx; - } -} From fc2c3bdb51a1d3a9f925bc3d1ff2696f5c29f981 Mon Sep 17 00:00:00 2001 From: Jackson Davis Date: Mon, 1 Sep 2014 22:06:50 +0200 Subject: [PATCH 4/5] Rename 6EE65A to push_others_right + refactor --- src/window.c | 67 +++++++++++++++++++++---------------------- src/window.h | 2 +- src/window_footpath.c | 2 +- 3 files changed, 35 insertions(+), 36 deletions(-) diff --git a/src/window.c b/src/window.c index e81a530965..9e04d0982e 100644 --- a/src/window.c +++ b/src/window.c @@ -828,6 +828,38 @@ rct_window *window_bring_to_front(rct_window *w) return w; } +/** + * + * rct2: 0x006EE65A + */ +void window_push_others_right(rct_window* window) +{ + + for (rct_window* w = g_window_list; w < RCT2_GLOBAL(RCT2_ADDRESS_NEW_WINDOW_PTR, rct_window*); w++) { + if (w == window) + continue; + if (w->flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT)) + continue; + if (w->x >= window->x + window->width) + continue; + if (w->x + w->width <= window->x) + continue; + if (w->y >= window->y + window->height) + continue; + if (w->y + w->height <= window->y) + continue; + + window_invalidate(w); + if (window->x + window->width + 13 >= RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, uint16)) + continue; + uint16 push_amount = window->x + window->height - w->x + 3; + w->x += push_amount; + window_invalidate(w); + if (w->viewport != NULL) + w->viewport->x += push_amount; + } +} + /** * * rct2: 0x006EE6EA @@ -871,6 +903,7 @@ void window_push_others_below(rct_window *w1) } } + /** * * rct2: 0x006EE2E4 @@ -1512,37 +1545,3 @@ void window_align_tabs( rct_window *w, uint8 start_tab_id, uint8 end_tab_id ) } } -/** - * Finds overlapping windows and moves them if possible - * rct2: 0x006EE65A - */ -void window_move_overlapping(rct_window* window) -{ - uint16 cx = window->width + window->x; - uint16 dx = window->height + window->y; - - for (rct_window* w = g_window_list; w < RCT2_GLOBAL(RCT2_ADDRESS_NEW_WINDOW_PTR, rct_window*); w++) { - if (w == window) - continue; - if (w->flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT)) - continue; - if (w->x >= cx) - continue; - if (w->x + w->width <= window->x) - continue; - if (w->y >= dx) - continue; - if (w->y + w->height <= window->y) - continue; - window_invalidate(w); - cx += 13; - if (cx >= RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, uint16)) - continue; - cx -= 10; - cx -= w->x; - w->x += cx; - window_invalidate(w); - if (w->viewport != NULL) - w->viewport->x += cx; - } -} diff --git a/src/window.h b/src/window.h index 440ed28b40..86aa034349 100644 --- a/src/window.h +++ b/src/window.h @@ -396,6 +396,7 @@ int window_get_scroll_size(rct_window *w, int scrollIndex, int *width, int *heig rct_window *window_bring_to_front_by_id(rct_windowclass cls, rct_windownumber number); rct_window *window_bring_to_front(rct_window *w); +void window_push_others_right(rct_window *w); void window_push_others_below(rct_window *w1); rct_window *window_get_main(); @@ -469,7 +470,6 @@ void window_staff_init_vars(); void window_event_helper(rct_window* w, short widgetIndex, WINDOW_EVENTS event); void RCT2_CALLPROC_WE_MOUSE_DOWN(int address, int widgetIndex, rct_window*w, rct_widget* widget); -void window_move_overlapping(rct_window* window); #ifdef _MSC_VER #define window_get_register(w) \ diff --git a/src/window_footpath.c b/src/window_footpath.c index f852be5ecc..01e4db3cb5 100644 --- a/src/window_footpath.c +++ b/src/window_footpath.c @@ -201,7 +201,7 @@ void window_footpath_open() (1 << WIDX_CONSTRUCT_BRIDGE_OR_TUNNEL); window_init_scroll_widgets(window); - window_move_overlapping(window); + window_push_others_right(window); show_gridlines(); window->colours[0] = 24; window->colours[1] = 24; From 4b3150449aaf99de86dfe409408c3e6b1b1206b1 Mon Sep 17 00:00:00 2001 From: Jackson Davis Date: Mon, 1 Sep 2014 22:22:54 +0200 Subject: [PATCH 5/5] Fix typo --- src/window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/window.c b/src/window.c index 9e04d0982e..4351d90d1a 100644 --- a/src/window.c +++ b/src/window.c @@ -852,7 +852,7 @@ void window_push_others_right(rct_window* window) window_invalidate(w); if (window->x + window->width + 13 >= RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, uint16)) continue; - uint16 push_amount = window->x + window->height - w->x + 3; + uint16 push_amount = window->x + window->width - w->x + 3; w->x += push_amount; window_invalidate(w); if (w->viewport != NULL)