From fe799f03a528dee75abc8b83208c6c1dc15d9832 Mon Sep 17 00:00:00 2001 From: Timmy Weerwag Date: Mon, 30 Mar 2015 17:28:36 +0200 Subject: [PATCH] Added footpath_bridge_get_info_from_pos --- src/interface/viewport.c | 26 ++++++++-------- src/interface/viewport.h | 2 +- src/interface/viewport_interaction.c | 4 +-- src/windows/footpath.c | 8 ++--- src/windows/guest.c | 2 +- src/windows/ride.c | 2 +- src/windows/staff.c | 2 +- src/windows/viewport.c | 2 +- src/world/footpath.c | 44 ++++++++++++++++++++++++++-- src/world/footpath.h | 2 +- 10 files changed, 68 insertions(+), 26 deletions(-) diff --git a/src/interface/viewport.c b/src/interface/viewport.c index b9ec084b69..151cfcca78 100644 --- a/src/interface/viewport.c +++ b/src/interface/viewport.c @@ -1676,28 +1676,29 @@ void viewport_set_visibility(uint8 mode) * y: cx * z: bl * mapElement: edx + * viewport: edi */ -void get_map_coordinates_from_pos(int screenX, int screenY, int flags, int *x, int *y, int *z, rct_map_element **mapElement) +void get_map_coordinates_from_pos(int screenX, int screenY, int flags, int *x, int *y, int *z, rct_map_element **mapElement, rct_viewport **viewport) { RCT2_GLOBAL(0x9AC154, uint16_t) = flags & 0xFFFF; RCT2_GLOBAL(0x9AC148, uint8_t) = 0; rct_window* window = window_find_from_point(screenX, screenY); if (window != NULL && window->viewport != NULL) { - rct_viewport* viewport = window->viewport; + rct_viewport* myviewport = window->viewport; RCT2_GLOBAL(0x9AC138 + 4, int16_t) = screenX; RCT2_GLOBAL(0x9AC138 + 6, int16_t) = screenY; - screenX -= (int)viewport->x; - screenY -= (int)viewport->y; - if (screenX >= 0 && screenX < (int)viewport->width && screenY >= 0 && screenY < (int)viewport->height) + screenX -= (int)myviewport->x; + screenY -= (int)myviewport->y; + if (screenX >= 0 && screenX < (int)myviewport->width && screenY >= 0 && screenY < (int)myviewport->height) { - screenX <<= viewport->zoom; - screenY <<= viewport->zoom; - screenX += (int)viewport->view_x; - screenY += (int)viewport->view_y; - RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_ZOOM, uint16_t) = viewport->zoom; - screenX &= (0xFFFF << viewport->zoom) & 0xFFFF; - screenY &= (0xFFFF << viewport->zoom) & 0xFFFF; + screenX <<= myviewport->zoom; + screenY <<= myviewport->zoom; + screenX += (int)myviewport->view_x; + screenY += (int)myviewport->view_y; + RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_ZOOM, uint16_t) = myviewport->zoom; + screenX &= (0xFFFF << myviewport->zoom) & 0xFFFF; + screenY &= (0xFFFF << myviewport->zoom) & 0xFFFF; RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_PAINT_X, int16_t) = screenX; RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_PAINT_Y, int16_t) = screenY; rct_drawpixelinfo* dpi = RCT2_ADDRESS(RCT2_ADDRESS_VIEWPORT_DPI, rct_drawpixelinfo); @@ -1713,6 +1714,7 @@ void get_map_coordinates_from_pos(int screenX, int screenY, int flags, int *x, i RCT2_CALLPROC_X(0x688217, 0, 0, 0, 0, 0, 0, 0); RCT2_CALLPROC_X(0x68862C, 0, 0, 0, 0, 0, 0, 0); } + if (viewport != NULL) *viewport = myviewport; } if (z != NULL) *z = RCT2_GLOBAL(0x9AC148, uint8_t); if (x != NULL) *x = (int)RCT2_GLOBAL(0x9AC14C, int16_t); diff --git a/src/interface/viewport.h b/src/interface/viewport.h index 27eae985d7..2712cee4ce 100644 --- a/src/interface/viewport.h +++ b/src/interface/viewport.h @@ -94,7 +94,7 @@ void show_construction_rights(); void hide_construction_rights(); void viewport_set_visibility(uint8 mode); -void get_map_coordinates_from_pos(int screenX, int screenY, int flags, int *x, int *y, int *z, rct_map_element **mapElement); +void get_map_coordinates_from_pos(int screenX, int screenY, int flags, int *x, int *y, int *z, rct_map_element **mapElement, rct_viewport **viewport); int viewport_interaction_get_item_left(int x, int y, viewport_interaction_info *info); int viewport_interaction_left_over(int x, int y); diff --git a/src/interface/viewport_interaction.c b/src/interface/viewport_interaction.c index d20a8204c4..9a33a1821d 100644 --- a/src/interface/viewport_interaction.c +++ b/src/interface/viewport_interaction.c @@ -58,7 +58,7 @@ int viewport_interaction_get_item_left(int x, int y, viewport_interaction_info * if ((RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & SCREEN_FLAGS_TRACK_DESIGNER) && s6Info->var_000 != 6) return info->type = VIEWPORT_INTERACTION_ITEM_NONE; - get_map_coordinates_from_pos(x, y, 0xFF79, &info->x, &info->y, &info->type, &info->mapElement); + get_map_coordinates_from_pos(x, y, 0xFF79, &info->x, &info->y, &info->type, &info->mapElement, NULL); mapElement = info->mapElement; sprite = (rct_sprite*)mapElement; @@ -178,7 +178,7 @@ int viewport_interaction_get_item_right(int x, int y, viewport_interaction_info if ((RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & SCREEN_FLAGS_TRACK_DESIGNER) && s6Info->var_000 != 6) return info->type = VIEWPORT_INTERACTION_ITEM_NONE; - get_map_coordinates_from_pos(x, y, 9, &info->x, &info->y, &info->type, &info->mapElement); + get_map_coordinates_from_pos(x, y, 9, &info->x, &info->y, &info->type, &info->mapElement, NULL); mapElement = info->mapElement; sprite = (rct_sprite*)mapElement; diff --git a/src/windows/footpath.c b/src/windows/footpath.c index d2de3966f0..da1c7b4437 100644 --- a/src/windows/footpath.c +++ b/src/windows/footpath.c @@ -673,7 +673,7 @@ static void window_footpath_set_provisional_path_at_point(int x, int y) map_invalidate_selection_rect(); RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_FLAGS, uint16) &= ~(1 << 2); - get_map_coordinates_from_pos(x, y, 0xFFDE, &x, &y, &z, &mapElement); + get_map_coordinates_from_pos(x, y, 0xFFDE, &x, &y, &z, &mapElement, NULL); if (z == 0) { RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_FLAGS, uint16) &= ~(1 << 0); @@ -716,7 +716,7 @@ static void window_footpath_set_selection_start_bridge_at_point(int screenX, int map_invalidate_selection_rect(); RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_FLAGS, uint16) &= ~(1 << 0) & ~(1 << 2); - sub_68A0C9(screenX, screenY, &x, &y, &direction, &mapElement); + footpath_bridge_get_info_from_pos(screenX, screenY, &x, &y, &direction, &mapElement); if (x == 0x8000) return; @@ -760,7 +760,7 @@ static void window_footpath_place_path_at_point(int x, int y) footpath_provisional_update(); - get_map_coordinates_from_pos(x, y, 0xFFDE, &x, &y, &z, &mapElement); + get_map_coordinates_from_pos(x, y, 0xFFDE, &x, &y, &z, &mapElement, NULL); if (z == 0) return; @@ -794,7 +794,7 @@ static void window_footpath_start_bridge_at_point(int screenX, int screenY) int x, y, z, direction; rct_map_element *mapElement; - sub_68A0C9(screenX, screenY, &x, &y, &direction, &mapElement); + footpath_bridge_get_info_from_pos(screenX, screenY, &x, &y, &direction, &mapElement); if (x == 0x8000) return; diff --git a/src/windows/guest.c b/src/windows/guest.c index d816d80bc9..75c06c0659 100644 --- a/src/windows/guest.c +++ b/src/windows/guest.c @@ -1160,7 +1160,7 @@ void window_guest_overview_tool_update(){ RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_SPRITE, sint32) = -1; int ebx; - get_map_coordinates_from_pos(x, y, 0, NULL, NULL, &ebx, NULL); + get_map_coordinates_from_pos(x, y, 0, NULL, NULL, &ebx, NULL, NULL); if (ebx == 0) return; diff --git a/src/windows/ride.c b/src/windows/ride.c index 5b16b8ea77..a1e57a2d88 100644 --- a/src/windows/ride.c +++ b/src/windows/ride.c @@ -3542,7 +3542,7 @@ static void window_ride_set_track_colour_scheme(rct_window *w, int x, int y) int z; - get_map_coordinates_from_pos(x, y, -5, &x, &y, &z, &mapElement); + get_map_coordinates_from_pos(x, y, -5, &x, &y, &z, &mapElement, NULL); // Get map coordinates from point /*int eax, ebx, ecx, edx, esi, edi, ebp; eax = x; diff --git a/src/windows/staff.c b/src/windows/staff.c index 4c9f71d0b8..f9c1095ed5 100644 --- a/src/windows/staff.c +++ b/src/windows/staff.c @@ -1086,7 +1086,7 @@ void window_staff_overview_tool_update(){ RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_SPRITE, sint32) = -1; int z; - get_map_coordinates_from_pos(x, y, 0, NULL, NULL, &z, NULL); + get_map_coordinates_from_pos(x, y, 0, NULL, NULL, &z, NULL, NULL); if (z == 0) return; diff --git a/src/windows/viewport.c b/src/windows/viewport.c index 924926ad1b..9fb7fcf6cc 100644 --- a/src/windows/viewport.c +++ b/src/windows/viewport.c @@ -176,7 +176,7 @@ static void window_viewport_mouseup() case WIDX_LOCATE: mainWindow = window_get_main(); if (mainWindow != NULL) { - get_map_coordinates_from_pos(w->x + (w->width / 2), w->y + (w->height / 2), 0, &x, &y, NULL, NULL); + get_map_coordinates_from_pos(w->x + (w->width / 2), w->y + (w->height / 2), 0, &x, &y, NULL, NULL, NULL); window_scroll_to_location(mainWindow, x, y, map_element_height(x, y)); } break; diff --git a/src/world/footpath.c b/src/world/footpath.c index 4a6ce75530..4ebe8b3aa9 100644 --- a/src/world/footpath.c +++ b/src/world/footpath.c @@ -21,6 +21,7 @@ #include "../addresses.h" #include "../game.h" #include "../localisation/localisation.h" +#include "../util/util.h" #include "footpath.h" #include "map.h" @@ -476,13 +477,52 @@ void footpath_provisional_update() /** * * rct2: 0x0068A0C9 + * screenX: eax + * screenY: ebx + * x: ax + * y: bx + * direction: cl + * mapElement: edx */ -void sub_68A0C9(int screenX, int screenY, int *x, int *y, int *direction, rct_map_element **mapElement) +void footpath_bridge_get_info_from_pos(int screenX, int screenY, int *x, int *y, int *direction, rct_map_element **mapElement) { + // First check if we point at an entrance or exit. In that case, we would want the path coming from the entrance/exit. + int z; + rct_viewport *viewport; + get_map_coordinates_from_pos(screenX, screenY, 0xFFFB, x, y, &z, mapElement, &viewport); + if (z == 3 + && viewport->flags & (VIEWPORT_FLAG_UNDERGROUND_INSIDE | VIEWPORT_FLAG_HIDE_BASE | VIEWPORT_FLAG_HIDE_VERTICAL) + && map_element_get_type(*mapElement) == MAP_ELEMENT_TYPE_ENTRANCE) { + int ebp = (*mapElement)->properties.entrance.type << 4; + int bl = (*mapElement)->properties.entrance.index & 0xF; + if (RCT2_GLOBAL(0x0097B974 + ebp + bl, uint16) & 0xF) { + int bx = bitscanforward(RCT2_GLOBAL(0x0097B974 + ebp + bl, uint16)); + bx += (*mapElement)->type; + bx &= 3; + if (direction != NULL) *direction = bx; + return; + } + } + + get_map_coordinates_from_pos(screenX, screenY, 0xFFDA, x, y, &z, mapElement, &viewport); + if (z == 3 && map_element_get_type(*mapElement) == MAP_ELEMENT_TYPE_ENTRANCE) { + int ebp = (*mapElement)->properties.entrance.type << 4; + int bl = (*mapElement)->properties.entrance.index & 0xF; // Seems to be always 0? + // The table at 0x0097B974 is only 48 bytes big + if (RCT2_GLOBAL(0x0097B974 + ebp + bl, uint16) & 0xF) { + int bx = bitscanforward(RCT2_GLOBAL(0x0097B974 + ebp + bl, uint16)); + bx += (*mapElement)->type; // First two bits seem to contain the direction of entrance/exit + bx &= 3; + if (direction != NULL) *direction = bx; + return; + } + } + + // We point at something else int eax, ebx, ecx, edx, esi, edi, ebp; eax = screenX; ebx = screenY; - RCT2_CALLFUNC_X(0x0068A0C9, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); + RCT2_CALLFUNC_X(0x00689726, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); if (x != NULL) *x = *((uint16*)&eax); if (y != NULL) *y = *((uint16*)&ebx); if (direction != NULL) *direction = *((uint8*)&ecx); diff --git a/src/world/footpath.h b/src/world/footpath.h index 957c0c7f93..e1df740b72 100644 --- a/src/world/footpath.h +++ b/src/world/footpath.h @@ -46,6 +46,6 @@ void footpath_remove(int x, int y, int z, int flags); money32 footpath_provisional_set(int type, int x, int y, int z, int slope); void footpath_provisional_remove(); void footpath_provisional_update(); -void sub_68A0C9(int screenX, int screenY, int *x, int *y, int *direction, rct_map_element **mapElement); +void footpath_bridge_get_info_from_pos(int screenX, int screenY, int *x, int *y, int *direction, rct_map_element **mapElement); #endif