diff --git a/src/interface/viewport.c b/src/interface/viewport.c index ef09d18d8c..1aa26ded41 100644 --- a/src/interface/viewport.c +++ b/src/interface/viewport.c @@ -45,19 +45,34 @@ struct paint_struct{ uint32 var_04; uint16 attached_x; // 0x08 uint16 attached_y; // 0x0A - uint8 var_0C; - uint8 pad_0D; - paint_struct* next_attached_ps; //0x0E - uint8 pad_12[2]; + union { + struct { + uint8 var_0C; + uint8 pad_0D; + paint_struct* next_attached_ps; //0x0E + uint16 pad_12; + }; + struct { + uint16 some_x; // 0x0C + uint16 some_y; // 0x0E + uint16 other_x; // 0x10 + uint16 other_y; // 0x12 + }; + }; uint16 x; // 0x14 uint16 y; // 0x16 - uint8 pad_18[2]; + uint16 var_18; uint8 var_1A; - uint8 pad_1B; + uint8 var_1B; paint_struct* attached_ps; //0x1C paint_struct* var_20; paint_struct* var_24; uint8 sprite_type; //0x28 + uint8 var_29; + uint16 pad_2A; + uint16 map_x; // 0x2C + uint16 map_y; // 0x2E + rct_map_element *mapElement; // 0x30 }; /** @@ -1346,6 +1361,133 @@ void sub_0x68B6C2(){ } } +void sub_688217_helper(uint16 ax, uint8 flag) +{ + paint_struct *ps; + paint_struct *ps_next = RCT2_GLOBAL(0x00EE7884, paint_struct*); + + do { + ps = ps_next; + ps_next = ps_next->var_24; + if (ps_next == NULL) return; + } while (ax > ps_next->var_18); + + RCT2_GLOBAL(0x00F1AD14, paint_struct*) = ps; + + do { + ps = ps->var_24; + if (ps == NULL) break; + + if (ps->var_18 > ax + 1) { + ps->var_1B = 1 << 7; + } else if (ps->var_18 == ax + 1) { + ps->var_1B = (1 << 1) | (1 << 0); + } else if (ps->var_18 == ax) { + ps->var_1B = flag | (1 << 0); + } + } while (ps->var_18 <= ax + 1); + + ps = RCT2_GLOBAL(0x00F1AD14, paint_struct*); + + while (true) { + while (true) { + ps_next = ps->var_24; + if (ps_next == NULL) return; + if (ps_next->var_1B & (1 << 7)) return; + if (ps_next->var_1B & (1 << 0)) break; + ps = ps_next; + } + + ps_next->var_1B &= ~(1 << 0); + RCT2_GLOBAL(0x00F1AD18, paint_struct*) = ps; + + uint16 my_attached_x = ps_next->attached_x; + uint16 my_attached_y = ps_next->attached_y; + uint16 my_some_x = ps_next->some_x; + uint16 my_some_y = ps_next->some_y; + uint16 my_other_x = ps_next->other_x; + uint16 my_other_y = ps_next->other_y; + + while (true) { + ps = ps_next; + ps_next = ps_next->var_24; + if (ps_next == NULL) break; + if (ps_next->var_1B & (1 << 7)) break; + if (!(ps_next->var_1B & (1 << 1))) continue; + + int yes = 0; + switch (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, uint32)) { + case 0: + if (my_some_y >= ps_next->some_x && my_other_y >= ps_next->attached_y && my_other_x >= ps_next->attached_x + && !(my_some_x < ps_next->some_y && my_attached_y < ps_next->other_y && my_attached_x < ps_next->other_x)) + yes = 1; + break; + case 1: + if (my_some_y >= ps_next->some_x && my_other_y >= ps_next->attached_y && my_other_x < ps_next->attached_x + && !(my_some_x < ps_next->some_y && my_attached_y < ps_next->other_y && my_attached_x >= ps_next->other_x)) + yes = 1; + break; + case 2: + if (my_some_y >= ps_next->some_x && my_other_y < ps_next->attached_y && my_other_x < ps_next->attached_x + && !(my_some_x < ps_next->some_y && my_attached_y >= ps_next->other_y && my_attached_x >= ps_next->other_x)) + yes = 1; + break; + case 3: + if (my_some_y >= ps_next->some_x && my_other_y < ps_next->attached_y && my_other_x >= ps_next->attached_x + && !(my_some_x < ps_next->some_y && my_attached_y >= ps_next->other_y && my_attached_x < ps_next->other_x)) + yes = 1; + break; + } + + if (yes) { + ps->var_24 = ps_next->var_24; + paint_struct *ps_temp = RCT2_GLOBAL(0x00F1AD18, paint_struct*)->var_24; + RCT2_GLOBAL(0x00F1AD18, paint_struct*)->var_24 = ps_next; + ps_next->var_24 = ps_temp; + ps_next = ps; + } + } + + ps = RCT2_GLOBAL(0x00F1AD18, paint_struct*); + } +} + +/** +* +* rct2: 0x00688217 +*/ +void sub_688217() +{ + paint_struct *ps = RCT2_GLOBAL(0x00EE7888, paint_struct*); + paint_struct *ps_next; + RCT2_GLOBAL(0x00EE7888, uint32) += 0x34; // 0x34 is size of paint_struct? + RCT2_GLOBAL(0x00EE7884, paint_struct*) = ps; + ps->var_24 = NULL; + uint32 edi = RCT2_GLOBAL(0x00F1AD0C, uint32); + if (edi == -1) + return; + + do { + ps_next = RCT2_GLOBAL(0x00F1A50C + 4 * edi, paint_struct*); + if (ps_next != NULL) { + ps->var_24 = ps_next; + do { + ps = ps_next; + ps_next = ps_next->var_24; + } while (ps_next != NULL); + } + } while (++edi <= RCT2_GLOBAL(0x00F1AD10, uint32)); + + uint32 eax = RCT2_GLOBAL(0x00F1AD0C, uint32); + + sub_688217_helper(eax & 0xFFFF, 1 << 1); + + eax = RCT2_GLOBAL(0x00F1AD0C, uint32); + + while (++eax < RCT2_GLOBAL(0x00F1AD10, uint32)) + sub_688217_helper(eax & 0xFFFF, 0); +} + /** * * rct2:0x00685CBF @@ -1439,7 +1581,8 @@ void viewport_paint(rct_viewport* viewport, rct_drawpixelinfo* dpi, int left, in sub_0x68615B(0xEE788C); //Memory copy sub_0x68B6C2(); //RCT2_CALLPROC_X(0x68B6C2, 0, 0, 0, 0, 0, 0, 0); //Big function call 4 rotation versions - RCT2_CALLPROC_X(0x688217, start_x, ebx, ecx, (int)bits_pointer, esi, (int)dpi2, ebp); //Move memory + sub_688217(); + //RCT2_CALLPROC_X(0x688217, start_x, ebx, ecx, (int)bits_pointer, esi, (int)dpi2, ebp); //Move memory sub_688485(); //RCT2_CALLPROC_EBPSAFE(0x688485); //Big function call @@ -1466,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; } @@ -1727,6 +1870,79 @@ void viewport_set_visibility(uint8 mode) } } +/** + * Stores some info about the element pointed at, if requested for this particular type through the interaction mask. + * rct2: 0x00688697 + */ +void store_interaction_info(paint_struct *ps) +{ + if (RCT2_GLOBAL(0x0141F569, uint8) == 0) 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 == 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); + + if (!(RCT2_GLOBAL(0x009AC154, uint16) & mask)) { + RCT2_GLOBAL(0x009AC148, uint8) = ps->sprite_type; + RCT2_GLOBAL(0x009AC149, uint8) = ps->var_29; + RCT2_GLOBAL(0x009AC14C, uint32) = ps->map_x; + RCT2_GLOBAL(0x009AC14E, uint32) = ps->map_y; + RCT2_GLOBAL(0x009AC150, rct_map_element*) = ps->mapElement; + } +} + +/** + * rct2: 0x0068862C + */ +void sub_68862C() +{ + rct_drawpixelinfo *dpi = RCT2_GLOBAL(0x0140E9A8, rct_drawpixelinfo*); + paint_struct *ps = RCT2_GLOBAL(0x00EE7884, paint_struct*), *old_ps, *next_ps, *attached_ps; + uint32 eax = 0xBBBBBBBB, ebx = 0xBBBBBBBB, ecx = 0xBBBBBBBB, edx = 0xBBBBBBBB, esi = 0xBBBBBBBB, edi = 0xBBBBBBBB, ebp = 0xBBBBBBBB; + + while ((ps = ps->var_24) != NULL) { + old_ps = ps; + + next_ps = ps; + while (next_ps != NULL) { + ps = next_ps; + ebx = ps->image_id; + ecx = ps->x; + edx = ps->y; + edi = (uint32)dpi; + ebp = (uint32)ps; + //sub_679023(ps->image_id, ps->x, ps->y, dpi); + RCT2_CALLFUNC_X(0x00679023, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); + store_interaction_info(ps); + + next_ps = ps->var_20; + } + + attached_ps = ps->attached_ps; + while (attached_ps != NULL) { + esi = (uint32)attached_ps; + ebp = (uint32)ps; + ecx = (attached_ps->attached_x + ps->x) & 0xFFFF; + edx = (attached_ps->attached_y + ps->y) & 0xFFFF; + ebx = attached_ps->image_id; + //sub_679023(ebx, ecx, edx, dpi); + RCT2_CALLFUNC_X(0x00679023, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); + store_interaction_info(ps); + + attached_ps = attached_ps->next_attached_ps; + } + + ps = old_ps; + } +} + /** * * rct2: 0x00685ADC @@ -1739,7 +1955,7 @@ void viewport_set_visibility(uint8 mode) * 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; @@ -1772,12 +1988,12 @@ void get_map_coordinates_from_pos(int screenX, int screenY, int flags, int *x, i RCT2_GLOBAL(0x140E9A8, rct_drawpixelinfo*) = dpi; sub_0x68615B(0xEE788C); sub_0x68B6C2(); - RCT2_CALLPROC_X(0x688217, 0, 0, 0, 0, 0, 0, 0); - RCT2_CALLPROC_X(0x68862C, 0, 0, 0, 0, 0, 0, 0); + sub_688217(); + sub_68862C(); } 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*); diff --git a/src/interface/viewport.h b/src/interface/viewport.h index 22956f7974..6e809dcee2 100644 --- a/src/interface/viewport.h +++ b/src/interface/viewport.h @@ -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); diff --git a/src/interface/viewport_interaction.c b/src/interface/viewport_interaction.c index 0cd579746d..8843ea2be3 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, 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; } diff --git a/src/windows/footpath.c b/src/windows/footpath.c index da1c7b4437..64e9e9fa3a 100644 --- a/src/windows/footpath.c +++ b/src/windows/footpath.c @@ -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); diff --git a/src/windows/guest.c b/src/windows/guest.c index 4aff777c39..ddc3496df2 100644 --- a/src/windows/guest.c +++ b/src/windows/guest.c @@ -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; diff --git a/src/windows/ride.c b/src/windows/ride.c index df6f385f26..356131eea3 100644 --- a/src/windows/ride.c +++ b/src/windows/ride.c @@ -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; diff --git a/src/windows/staff.c b/src/windows/staff.c index 67222c706b..7d4f3c6015 100644 --- a/src/windows/staff.c +++ b/src/windows/staff.c @@ -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--; diff --git a/src/windows/viewport.c b/src/windows/viewport.c index 9fb7fcf6cc..0caaa347fe 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, 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; diff --git a/src/world/footpath.c b/src/world/footpath.c index c811074f36..e853ac5645 100644 --- a/src/world/footpath.c +++ b/src/world/footpath.c @@ -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