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 diff --git a/src/window.c b/src/window.c index 355d5770bf..4351d90d1a 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->width - 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 @@ -1511,3 +1544,4 @@ void window_align_tabs( rct_window *w, uint8 start_tab_id, uint8 end_tab_id ) } } } + diff --git a/src/window.h b/src/window.h index b25b0d021a..e6c79619e6 100644 --- a/src/window.h +++ b/src/window.h @@ -402,6 +402,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(); diff --git a/src/window_footpath.c b/src/window_footpath.c index 451816cb38..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); - RCT2_CALLPROC_EBPSAFE(0x006EE65A); + window_push_others_right(window); show_gridlines(); window->colours[0] = 24; window->colours[1] = 24; @@ -825,4 +825,5 @@ loc_6A78EF: loc_6A79B0: RCT2_CALLPROC_EBPSAFE(0x006A855C); -} \ No newline at end of file +} +