mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-29 17:54:50 +01:00
implement remaining screen_get_map_xy... functions
This commit is contained in:
@@ -2075,56 +2075,13 @@ void viewport_paint(rct_viewport* viewport, rct_drawpixelinfo* dpi, int left, in
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* rct2: 0x00688972
|
||||
* In:
|
||||
* screen_x: eax
|
||||
* screen_y: ebx
|
||||
* Out:
|
||||
* x: ax
|
||||
* y: bx
|
||||
* map_element: edx ?
|
||||
* viewport: edi
|
||||
*/
|
||||
void sub_688972(int screenX, int screenY, sint16 *x, sint16 *y, rct_viewport **viewport) {
|
||||
sint16 my_x, my_y;
|
||||
int z, interactionType;
|
||||
rct_viewport *myViewport;
|
||||
get_map_coordinates_from_pos(screenX, screenY, VIEWPORT_INTERACTION_MASK_TERRAIN, &my_x, &my_y, &interactionType, NULL, &myViewport);
|
||||
if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE) {
|
||||
*x = 0x8000;
|
||||
return;
|
||||
}
|
||||
|
||||
RCT2_GLOBAL(0x00F1AD34, sint16) = my_x;
|
||||
RCT2_GLOBAL(0x00F1AD36, sint16) = my_y;
|
||||
RCT2_GLOBAL(0x00F1AD38, sint16) = my_x + 31;
|
||||
RCT2_GLOBAL(0x00F1AD3A, sint16) = my_y + 31;
|
||||
|
||||
rct_xy16 start_vp_pos = screen_coord_to_viewport_coord(myViewport, screenX, screenY);
|
||||
rct_xy16 map_pos = { my_x + 16, my_y + 16 };
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
z = map_element_height(map_pos.x, map_pos.y);
|
||||
map_pos = viewport_coord_to_map_coord(start_vp_pos.x, start_vp_pos.y, z);
|
||||
map_pos.x = clamp(RCT2_GLOBAL(0x00F1AD34, sint16), map_pos.x, RCT2_GLOBAL(0x00F1AD38, sint16));
|
||||
map_pos.y = clamp(RCT2_GLOBAL(0x00F1AD36, sint16), map_pos.y, RCT2_GLOBAL(0x00F1AD3A, sint16));
|
||||
}
|
||||
|
||||
*x = map_pos.x;
|
||||
*y = map_pos.y;
|
||||
|
||||
if (viewport != NULL) *viewport = myViewport;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* rct2: 0x0068958D
|
||||
*/
|
||||
void screen_pos_to_map_pos(sint16 *x, sint16 *y, int *direction)
|
||||
{
|
||||
sub_688972(*x, *y, x, y, NULL);
|
||||
screen_get_map_xy(*x, *y, x, y, NULL);
|
||||
if (*x == (sint16)0x8000)
|
||||
return;
|
||||
|
||||
@@ -2532,11 +2489,54 @@ rct_viewport *viewport_find_from_point(int screenX, int screenY)
|
||||
return viewport;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* rct2: 0x00688972
|
||||
* In:
|
||||
* screen_x: eax
|
||||
* screen_y: ebx
|
||||
* Out:
|
||||
* x: ax
|
||||
* y: bx
|
||||
* map_element: edx ?
|
||||
* viewport: edi
|
||||
*/
|
||||
void screen_get_map_xy(int screenX, int screenY, sint16 *x, sint16 *y, rct_viewport **viewport) {
|
||||
sint16 my_x, my_y;
|
||||
int z, interactionType;
|
||||
rct_viewport *myViewport;
|
||||
get_map_coordinates_from_pos(screenX, screenY, VIEWPORT_INTERACTION_MASK_TERRAIN, &my_x, &my_y, &interactionType, NULL, &myViewport);
|
||||
if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE) {
|
||||
*x = 0x8000;
|
||||
return;
|
||||
}
|
||||
|
||||
RCT2_GLOBAL(0x00F1AD34, sint16) = my_x;
|
||||
RCT2_GLOBAL(0x00F1AD36, sint16) = my_y;
|
||||
RCT2_GLOBAL(0x00F1AD38, sint16) = my_x + 31;
|
||||
RCT2_GLOBAL(0x00F1AD3A, sint16) = my_y + 31;
|
||||
|
||||
rct_xy16 start_vp_pos = screen_coord_to_viewport_coord(myViewport, screenX, screenY);
|
||||
rct_xy16 map_pos = { my_x + 16, my_y + 16 };
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
z = map_element_height(map_pos.x, map_pos.y);
|
||||
map_pos = viewport_coord_to_map_coord(start_vp_pos.x, start_vp_pos.y, z);
|
||||
map_pos.x = clamp(RCT2_GLOBAL(0x00F1AD34, sint16), map_pos.x, RCT2_GLOBAL(0x00F1AD38, sint16));
|
||||
map_pos.y = clamp(RCT2_GLOBAL(0x00F1AD36, sint16), map_pos.y, RCT2_GLOBAL(0x00F1AD3A, sint16));
|
||||
}
|
||||
|
||||
*x = map_pos.x;
|
||||
*y = map_pos.y;
|
||||
|
||||
if (viewport != NULL) *viewport = myViewport;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* rct2: 0x006894D4
|
||||
*/
|
||||
void sub_6894D4(sint16 screenX, sint16 screenY, sint16 z, sint16 *mapX, sint16 *mapY)
|
||||
void screen_get_map_xy_with_z(sint16 screenX, sint16 screenY, sint16 z, sint16 *mapX, sint16 *mapY)
|
||||
{
|
||||
rct_viewport *viewport = viewport_find_from_point(screenX, screenY);
|
||||
if (viewport == NULL) {
|
||||
@@ -2556,3 +2556,67 @@ void sub_6894D4(sint16 screenX, sint16 screenY, sint16 z, sint16 *mapX, sint16 *
|
||||
*mapX = mapPosition.x;
|
||||
*mapY = mapPosition.y;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* rct2: 0x00689604
|
||||
*/
|
||||
void screen_get_map_xy_quadrant(sint16 screenX, sint16 screenY, sint16 *mapX, sint16 *mapY, uint8 *quadrant)
|
||||
{
|
||||
rct_viewport *viewport;
|
||||
|
||||
screen_get_map_xy(screenX, screenY, mapX, mapY, &viewport);
|
||||
if (*mapX == (sint16)0x8000)
|
||||
return;
|
||||
|
||||
*quadrant = map_get_tile_quadrant(*mapX, *mapY);
|
||||
*mapX = floor2(*mapX, 32);
|
||||
*mapY = floor2(*mapY, 32);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* rct2: 0x0068964B
|
||||
*/
|
||||
void screen_get_map_xy_quadrant_with_z(sint16 screenX, sint16 screenY, sint16 z, sint16 *mapX, sint16 *mapY, uint8 *quadrant)
|
||||
{
|
||||
screen_get_map_xy_with_z(screenX, screenY, z, mapX, mapY);
|
||||
if (*mapX == (sint16)0x8000)
|
||||
return;
|
||||
|
||||
*quadrant = map_get_tile_quadrant(*mapX, *mapY);
|
||||
*mapX = floor2(*mapX, 32);
|
||||
*mapY = floor2(*mapY, 32);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* rct2: 0x00689692
|
||||
*/
|
||||
void screen_get_map_xy_side(sint16 screenX, sint16 screenY, sint16 *mapX, sint16 *mapY, uint8 *side)
|
||||
{
|
||||
rct_viewport *viewport;
|
||||
|
||||
screen_get_map_xy(screenX, screenY, mapX, mapY, &viewport);
|
||||
if (*mapX == (sint16)0x8000)
|
||||
return;
|
||||
|
||||
*side = map_get_tile_side(*mapX, *mapY);
|
||||
*mapX = floor2(*mapX, 32);
|
||||
*mapY = floor2(*mapY, 32);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* rct2: 0x006896DC
|
||||
*/
|
||||
void screen_get_map_xy_side_with_z(sint16 screenX, sint16 screenY, sint16 z, sint16 *mapX, sint16 *mapY, uint8 *side)
|
||||
{
|
||||
screen_get_map_xy_with_z(screenX, screenY, z, mapX, mapY);
|
||||
if (*mapX == (sint16)0x8000)
|
||||
return;
|
||||
|
||||
*side = map_get_tile_side(*mapX, *mapY);
|
||||
*mapX = floor2(*mapX, 32);
|
||||
*mapY = floor2(*mapY, 32);
|
||||
}
|
||||
|
||||
@@ -104,7 +104,6 @@ void sub_689174(sint16* x, sint16* y, sint16 *z);
|
||||
|
||||
rct_xy16 screen_coord_to_viewport_coord(rct_viewport *viewport, uint16 x, uint16 y);
|
||||
rct_xy16 viewport_coord_to_map_coord(int x, int y, int z);
|
||||
void sub_688972(int screenX, int screenY, sint16 *x, sint16 *y, rct_viewport **viewport);
|
||||
void screen_pos_to_map_pos(sint16 *x, sint16 *y, int *direction);
|
||||
|
||||
void show_gridlines();
|
||||
@@ -133,6 +132,11 @@ void sub_688217();
|
||||
|
||||
void viewport_invalidate(rct_viewport *viewport, int left, int top, int right, int bottom);
|
||||
|
||||
void sub_6894D4(sint16 screenX, sint16 screenY, sint16 z, sint16 *mapX, sint16 *mapY);
|
||||
void screen_get_map_xy(int screenX, int screenY, sint16 *x, sint16 *y, rct_viewport **viewport);
|
||||
void screen_get_map_xy_with_z(sint16 screenX, sint16 screenY, sint16 z, sint16 *mapX, sint16 *mapY);
|
||||
void screen_get_map_xy_quadrant(sint16 screenX, sint16 screenY, sint16 *mapX, sint16 *mapY, uint8 *quadrant);
|
||||
void screen_get_map_xy_quadrant_with_z(sint16 screenX, sint16 screenY, sint16 z, sint16 *mapX, sint16 *mapY, uint8 *quadrant);
|
||||
void screen_get_map_xy_side(sint16 screenX, sint16 screenY, sint16 *mapX, sint16 *mapY, uint8 *side);
|
||||
void screen_get_map_xy_side_with_z(sint16 screenX, sint16 screenY, sint16 z, sint16 *mapX, sint16 *mapY, uint8 *side);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1374,7 +1374,7 @@ void window_rotate_camera(rct_window *w, int direction)
|
||||
|
||||
//has something to do with checking if middle of the viewport is obstructed
|
||||
rct_viewport *other;
|
||||
sub_688972(x, y, &x, &y, &other);
|
||||
screen_get_map_xy(x, y, &x, &y, &other);
|
||||
|
||||
// other != viewport probably triggers on viewports in ride or guest window?
|
||||
// x is 0x8000 if middle of viewport is obstructed by another window?
|
||||
|
||||
Reference in New Issue
Block a user