1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-04 13:42:55 +01:00

Deciphered flags and z param of get_map_coordinates_from_pos

This commit is contained in:
Timmy Weerwag
2015-04-16 20:09:07 +02:00
parent 5f7c7828a5
commit 10c4722a86
9 changed files with 71 additions and 54 deletions

View File

@@ -70,9 +70,9 @@ struct paint_struct{
uint8 sprite_type; //0x28
uint8 var_29;
uint16 pad_2A;
uint16 map_x;
uint16 map_y;
rct_map_element *mapElement;
uint16 map_x; // 0x2C
uint16 map_y; // 0x2E
rct_map_element *mapElement; // 0x30
};
/**
@@ -1609,10 +1609,10 @@ void viewport_paint(rct_viewport* viewport, rct_drawpixelinfo* dpi, int left, in
* viewport: edi
*/
void sub_688972(int screenX, int screenY, sint16 *x, sint16 *y, rct_viewport **viewport) {
int my_x, my_y, z;
int my_x, my_y, z, interactionType;
rct_viewport *myViewport;
get_map_coordinates_from_pos(screenX, screenY, 0xFFFE, &my_x, &my_y, &z, NULL, &myViewport);
if (z == 0) {
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;
}
@@ -1877,10 +1877,13 @@ void sub_688697(paint_struct *ps)
{
if (RCT2_GLOBAL(0x0141F569, uint8) == 0) return;
if (ps->sprite_type == 0 || ps->sprite_type == 11 || ps->sprite_type > 12) return;
if (ps->sprite_type == VIEWPORT_INTERACTION_ITEM_NONE
|| ps->sprite_type == 11 // 11 as a type seems to not exist, maybe part of the typo mentioned later on.
|| ps->sprite_type > VIEWPORT_INTERACTION_ITEM_BANNER) return;
uint16 mask;
if (ps->sprite_type == 12)
if (ps->sprite_type == VIEWPORT_INTERACTION_ITEM_BANNER)
// I think CS made a typo here. Let's replicate the original behaviour.
mask = 1 << 9;
else
mask = 1 << (ps->sprite_type - 1);
@@ -1951,7 +1954,7 @@ void sub_68862C()
* 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, rct_viewport **viewport)
void get_map_coordinates_from_pos(int screenX, int screenY, int flags, int *x, int *y, int *interactionType, rct_map_element **mapElement, rct_viewport **viewport)
{
RCT2_GLOBAL(0x9AC154, uint16_t) = flags & 0xFFFF;
RCT2_GLOBAL(0x9AC148, uint8_t) = 0;
@@ -1989,7 +1992,7 @@ void get_map_coordinates_from_pos(int screenX, int screenY, int flags, int *x, i
}
if (viewport != NULL) *viewport = myviewport;
}
if (z != NULL) *z = RCT2_GLOBAL(0x9AC148, uint8_t);
if (interactionType != NULL) *interactionType = RCT2_GLOBAL(0x9AC148, uint8_t);
if (x != NULL) *x = (int)RCT2_GLOBAL(0x9AC14C, int16_t);
if (y != NULL) *y = (int)RCT2_GLOBAL(0x9AC14E, int16_t);
if (mapElement != NULL) *mapElement = RCT2_GLOBAL(0x9AC150, rct_map_element*);

View File

@@ -46,10 +46,11 @@ enum {
enum {
VIEWPORT_INTERACTION_ITEM_NONE,
VIEWPORT_INTERACTION_ITEM_SPRITE = 2,
VIEWPORT_INTERACTION_ITEM_TERRAIN,
VIEWPORT_INTERACTION_ITEM_SPRITE,
VIEWPORT_INTERACTION_ITEM_RIDE,
VIEWPORT_INTERACTION_ITEM_SCENERY = 5,
VIEWPORT_INTERACTION_ITEM_WATER,
VIEWPORT_INTERACTION_ITEM_SCENERY,
VIEWPORT_INTERACTION_ITEM_FOOTPATH,
VIEWPORT_INTERACTION_ITEM_FOOTPATH_ITEM,
VIEWPORT_INTERACTION_ITEM_PARK,
@@ -59,6 +60,21 @@ enum {
};
enum {
VIEWPORT_INTERACTION_MASK_NONE = 0,
VIEWPORT_INTERACTION_MASK_TERRAIN = ~(1 << (VIEWPORT_INTERACTION_ITEM_TERRAIN - 1)),
VIEWPORT_INTERACTION_MASK_SPRITE = ~(1 << (VIEWPORT_INTERACTION_ITEM_SPRITE - 1)),
VIEWPORT_INTERACTION_MASK_RIDE = ~(1 << (VIEWPORT_INTERACTION_ITEM_RIDE - 1)),
VIEWPORT_INTERACTION_MASK_WATER = ~(1 << (VIEWPORT_INTERACTION_ITEM_WATER - 1)),
VIEWPORT_INTERACTION_MASK_SCENERY = ~(1 << (VIEWPORT_INTERACTION_ITEM_SCENERY - 1)),
VIEWPORT_INTERACTION_MASK_FOOTPATH = ~(1 << (VIEWPORT_INTERACTION_ITEM_FOOTPATH - 1)),
VIEWPORT_INTERACTION_MASK_FOOTPATH_ITEM = ~(1 << (VIEWPORT_INTERACTION_ITEM_FOOTPATH_ITEM - 1)),
VIEWPORT_INTERACTION_MASK_PARK = ~(1 << (VIEWPORT_INTERACTION_ITEM_PARK - 1)),
VIEWPORT_INTERACTION_MASK_WALL = ~(1 << (VIEWPORT_INTERACTION_ITEM_WALL - 1)),
VIEWPORT_INTERACTION_MASK_LARGE_SCENERY = ~(1 << (VIEWPORT_INTERACTION_ITEM_LARGE_SCENERY - 1)),
VIEWPORT_INTERACTION_MASK_BANNER = ~(1 << (VIEWPORT_INTERACTION_ITEM_BANNER - 1)),
};
typedef struct {
int type;
int x;
@@ -97,7 +113,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, rct_viewport **viewport);
void get_map_coordinates_from_pos(int screenX, int screenY, int flags, int *x, int *y, int *interactionType, 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, NULL);
get_map_coordinates_from_pos(x, y, VIEWPORT_INTERACTION_MASK_SPRITE & VIEWPORT_INTERACTION_MASK_RIDE & VIEWPORT_INTERACTION_MASK_PARK, &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, NULL);
get_map_coordinates_from_pos(x, y, ~(VIEWPORT_INTERACTION_MASK_TERRAIN & VIEWPORT_INTERACTION_MASK_WATER), &info->x, &info->y, &info->type, &info->mapElement, NULL);
mapElement = info->mapElement;
sprite = (rct_sprite*)mapElement;
@@ -565,21 +565,20 @@ static rct_peep *viewport_interaction_get_closest_peep(int x, int y, int maxDist
*/
void sub_68A15E(int screenX, int screenY, short *x, short *y, int *direction, rct_map_element **mapElement)
{
int my_x, my_y, z;
int my_x, my_y, z, interactionType;
rct_map_element *myMapElement;
rct_viewport *viewport;
get_map_coordinates_from_pos(screenX, screenY, 0xFFF6, &my_x, &my_y, &z, &myMapElement, &viewport);
get_map_coordinates_from_pos(screenX, screenY, VIEWPORT_INTERACTION_MASK_SPRITE & VIEWPORT_INTERACTION_MASK_WATER, &my_x, &my_y, &interactionType, &myMapElement, &viewport);
if (z == 0) {
if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE) {
*x = 0x8000;
return;
}
RCT2_GLOBAL(0x00F1AD3E, uint8) = z;
RCT2_GLOBAL(0x00F1AD3E, uint8) = interactionType;
RCT2_GLOBAL(0x00F1AD30, rct_map_element*) = myMapElement;
if (z == 4) {
// myMapElement appears to be water
if (interactionType == VIEWPORT_INTERACTION_ITEM_WATER) {
z = myMapElement->properties.surface.terrain;
z = (z & MAP_ELEMENT_WATER_HEIGHT_MASK) << 4;
}

View File

@@ -667,15 +667,15 @@ static void window_footpath_mousedown_slope(int slope)
*/
static void window_footpath_set_provisional_path_at_point(int x, int y)
{
int z, slope, pathType;
int slope, pathType, interactionType;
rct_map_element *mapElement;
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, NULL);
get_map_coordinates_from_pos(x, y, VIEWPORT_INTERACTION_MASK_FOOTPATH & VIEWPORT_INTERACTION_MASK_TERRAIN, &x, &y, &interactionType, &mapElement, NULL);
if (z == 0) {
if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE) {
RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_FLAGS, uint16) &= ~(1 << 0);
footpath_provisional_update();
} else {
@@ -695,7 +695,7 @@ static void window_footpath_set_provisional_path_at_point(int x, int y)
// Set provisional path
slope = RCT2_ADDRESS(0x0098D8B4, uint8)[mapElement->properties.surface.slope & 0x1F];
if (z == 6)
if (interactionType == VIEWPORT_INTERACTION_ITEM_FOOTPATH)
slope = mapElement->properties.surface.slope & 7;
pathType = (RCT2_GLOBAL(RCT2_ADDRESS_SELECTED_PATH_TYPE, uint8) << 7) + RCT2_GLOBAL(RCT2_ADDRESS_SELECTED_PATH_ID, uint8);
@@ -752,7 +752,7 @@ static void window_footpath_set_selection_start_bridge_at_point(int screenX, int
*/
static void window_footpath_place_path_at_point(int x, int y)
{
int z, presentType, selectedType, cost;
int interactionType, presentType, selectedType, z, cost;
rct_map_element *mapElement;
if (RCT2_GLOBAL(RCT2_ADDRESS_PATH_ERROR_OCCURED, uint8) != 0)
@@ -760,13 +760,13 @@ 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, NULL);
if (z == 0)
get_map_coordinates_from_pos(x, y, VIEWPORT_INTERACTION_MASK_FOOTPATH & VIEWPORT_INTERACTION_MASK_TERRAIN, &x, &y, &interactionType, &mapElement, NULL);
if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE)
return;
// Set path
presentType = RCT2_ADDRESS(0x0098D8B4, uint8)[mapElement->properties.path.type & 0x1F];
if (z == 6)
if (interactionType == VIEWPORT_INTERACTION_ITEM_FOOTPATH)
presentType = mapElement->properties.path.type & 7;
z = mapElement->base_height;
selectedType = (RCT2_GLOBAL(RCT2_ADDRESS_SELECTED_PATH_TYPE, uint8) << 7) + RCT2_GLOBAL(RCT2_ADDRESS_SELECTED_PATH_ID, uint8);

View File

@@ -1157,9 +1157,9 @@ 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, NULL);
if (ebx == 0)
int interactionType;
get_map_coordinates_from_pos(x, y, VIEWPORT_INTERACTION_MASK_NONE, NULL, NULL, &interactionType, NULL, NULL);
if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE)
return;
x--;
@@ -1171,7 +1171,7 @@ void window_guest_overview_tool_update(){
rct_peep* peep;
peep = GET_PEEP(w->number);
ebx = (RCT2_ADDRESS(0x982708, uint32*)[peep->sprite_type * 2])[22];
int ebx = (RCT2_ADDRESS(0x982708, uint32*)[peep->sprite_type * 2])[22];
ebx += w->var_492 >> 2;
int ebp = peep->tshirt_colour << 19;

View File

@@ -3545,9 +3545,9 @@ static void window_ride_set_track_colour_scheme(rct_window *w, int x, int y)
newColourScheme = (uint8)(*((uint16*)&w->var_494));
int z;
int interactionType;
get_map_coordinates_from_pos(x, y, -5, &x, &y, &z, &mapElement, NULL);
get_map_coordinates_from_pos(x, y, VIEWPORT_INTERACTION_MASK_RIDE, &x, &y, &interactionType, &mapElement, NULL);
// Get map coordinates from point
/*int eax, ebx, ecx, edx, esi, edi, ebp;
eax = x;
@@ -3558,7 +3558,7 @@ static void window_ride_set_track_colour_scheme(rct_window *w, int x, int y)
y = ecx & 0xFFFF;
mapElement = (rct_map_element*)edx;*/
if ((/*ebx*/z & 0xFF) != 3)
if (interactionType != VIEWPORT_INTERACTION_ITEM_RIDE)
return;
if (mapElement->properties.track.ride_index != w->number)
return;

View File

@@ -1084,9 +1084,9 @@ 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, NULL);
if (z == 0)
int interactionType;
get_map_coordinates_from_pos(x, y, VIEWPORT_INTERACTION_MASK_NONE, NULL, NULL, &interactionType, NULL, NULL);
if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE)
return;
x--;

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, NULL);
get_map_coordinates_from_pos(w->x + (w->width / 2), w->y + (w->height / 2), VIEWPORT_INTERACTION_MASK_NONE, &x, &y, NULL, NULL, NULL);
window_scroll_to_location(mainWindow, x, y, map_element_height(x, y));
}
break;

View File

@@ -491,23 +491,22 @@ void footpath_provisional_update()
*/
void footpath_get_coordinates_from_pos(int screenX, int screenY, int *x, int *y, int *direction, rct_map_element **mapElement)
{
int z;
int z, interactionType;
rct_map_element *myMapElement;
rct_viewport *viewport;
get_map_coordinates_from_pos(screenX, screenY, 0xFFDF, x, y, &z, &myMapElement, &viewport);
if (z != 6 || !(viewport->flags & (VIEWPORT_FLAG_UNDERGROUND_INSIDE | VIEWPORT_FLAG_HIDE_BASE | VIEWPORT_FLAG_HIDE_VERTICAL))) {
get_map_coordinates_from_pos(screenX, screenY, 0xFFDE, x, y, &z, &myMapElement, &viewport);
if (z == 0) {
get_map_coordinates_from_pos(screenX, screenY, VIEWPORT_INTERACTION_MASK_FOOTPATH, x, y, &interactionType, &myMapElement, &viewport);
if (interactionType != VIEWPORT_INTERACTION_ITEM_FOOTPATH || !(viewport->flags & (VIEWPORT_FLAG_UNDERGROUND_INSIDE | VIEWPORT_FLAG_HIDE_BASE | VIEWPORT_FLAG_HIDE_VERTICAL))) {
get_map_coordinates_from_pos(screenX, screenY, VIEWPORT_INTERACTION_MASK_FOOTPATH & VIEWPORT_INTERACTION_MASK_TERRAIN, x, y, &interactionType, &myMapElement, &viewport);
if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE) {
if (x != NULL) *x = 0x8000;
return;
}
}
RCT2_GLOBAL(0x00F1AD3E, uint8) = z;
RCT2_GLOBAL(0x00F1AD3E, uint8) = interactionType;
RCT2_GLOBAL(0x00F1AD30, rct_map_element*) = myMapElement;
if (z == 6) {
// mapElement appears to be a footpath
if (interactionType == VIEWPORT_INTERACTION_ITEM_FOOTPATH) {
z = myMapElement->base_height * 8;
if (myMapElement->properties.path.type & (1 << 2))
z += 8;
@@ -573,10 +572,10 @@ void footpath_get_coordinates_from_pos(int screenX, int screenY, int *x, int *y,
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;
int interactionType;
rct_viewport *viewport;
get_map_coordinates_from_pos(screenX, screenY, 0xFFFB, x, y, &z, mapElement, &viewport);
if (z == 3
get_map_coordinates_from_pos(screenX, screenY, VIEWPORT_INTERACTION_MASK_RIDE, x, y, &interactionType, mapElement, &viewport);
if (interactionType == VIEWPORT_INTERACTION_ITEM_RIDE
&& 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;
@@ -590,8 +589,8 @@ void footpath_bridge_get_info_from_pos(int screenX, int screenY, int *x, int *y,
}
}
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) {
get_map_coordinates_from_pos(screenX, screenY, VIEWPORT_INTERACTION_MASK_RIDE & VIEWPORT_INTERACTION_MASK_FOOTPATH & VIEWPORT_INTERACTION_MASK_TERRAIN, x, y, &interactionType, mapElement, &viewport);
if (interactionType == VIEWPORT_INTERACTION_ITEM_RIDE && 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