1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-24 00:03:11 +01:00

Added footpath_bridge_get_info_from_pos

This commit is contained in:
Timmy Weerwag
2015-03-30 17:28:36 +02:00
parent c3ca883c77
commit fe799f03a5
10 changed files with 68 additions and 26 deletions

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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);

View File

@@ -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