From 733bc5a981070c85ad47e21943bf706b72a408fe Mon Sep 17 00:00:00 2001 From: Duncan Date: Sun, 2 Aug 2020 08:32:59 +0100 Subject: [PATCH] Close #12518: Viewport Refactor (#12541) * Remove viewport pointer from get_map_coordinates_from_pos * Removed viewport from get_window * Return a InteractionInfo from get_map_coord... * Remove viewport_interaction_info struct * Add Entity union to simplify code * Name the enum used for viewport interaction * Simplify functions further by returning the info struct * Add default switches --- .../interface/ViewportInteraction.cpp | 251 ++++++++++-------- src/openrct2-ui/scripting/CustomMenu.cpp | 19 +- src/openrct2-ui/windows/Footpath.cpp | 65 +++-- src/openrct2-ui/windows/Guest.cpp | 7 +- src/openrct2-ui/windows/Ride.cpp | 50 ++-- src/openrct2-ui/windows/RideConstruction.cpp | 9 +- src/openrct2-ui/windows/Staff.cpp | 7 +- src/openrct2-ui/windows/TileInspector.cpp | 8 +- .../windows/TitleCommandEditor.cpp | 27 +- src/openrct2-ui/windows/TopToolbar.cpp | 130 ++++----- src/openrct2-ui/windows/Viewport.cpp | 8 +- src/openrct2/interface/InteractiveConsole.cpp | 10 +- src/openrct2/interface/Viewport.cpp | 89 +++---- src/openrct2/interface/Viewport.h | 42 ++- src/openrct2/paint/Paint.h | 7 +- src/openrct2/ride/Ride.cpp | 38 ++- src/openrct2/world/Footpath.cpp | 60 ++--- 17 files changed, 376 insertions(+), 451 deletions(-) diff --git a/src/openrct2-ui/interface/ViewportInteraction.cpp b/src/openrct2-ui/interface/ViewportInteraction.cpp index a35a147af0..c3ee5124f4 100644 --- a/src/openrct2-ui/interface/ViewportInteraction.cpp +++ b/src/openrct2-ui/interface/ViewportInteraction.cpp @@ -51,35 +51,35 @@ static Peep* viewport_interaction_get_closest_peep(ScreenCoordsXY screenCoords, * * rct2: 0x006ED9D0 */ -int32_t viewport_interaction_get_item_left(const ScreenCoordsXY& screenCoords, viewport_interaction_info* info) +InteractionInfo viewport_interaction_get_item_left(const ScreenCoordsXY& screenCoords) { + InteractionInfo info{}; // No click input for scenario editor or track manager if (gScreenFlags & (SCREEN_FLAGS_SCENARIO_EDITOR | SCREEN_FLAGS_TRACK_MANAGER)) - return info->type = VIEWPORT_INTERACTION_ITEM_NONE; + return info; // if ((gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) && gS6Info.editor_step != EDITOR_STEP_ROLLERCOASTER_DESIGNER) - return info->type = VIEWPORT_INTERACTION_ITEM_NONE; + return info; - CoordsXY mapCoord = {}; - get_map_coordinates_from_pos( - screenCoords, VIEWPORT_INTERACTION_MASK_SPRITE & VIEWPORT_INTERACTION_MASK_RIDE & VIEWPORT_INTERACTION_MASK_PARK, - mapCoord, &info->type, &info->tileElement, nullptr); - info->x = mapCoord.x; - info->y = mapCoord.y; - auto tileElement = info->tileElement; - auto sprite = info->sprite; + info = get_map_coordinates_from_pos( + screenCoords, VIEWPORT_INTERACTION_MASK_SPRITE & VIEWPORT_INTERACTION_MASK_RIDE & VIEWPORT_INTERACTION_MASK_PARK); + auto tileElement = info.SpriteType != VIEWPORT_INTERACTION_ITEM_SPRITE ? info.Element : nullptr; + auto sprite = info.SpriteType == VIEWPORT_INTERACTION_ITEM_SPRITE ? info.Entity : nullptr; // Allows only balloons to be popped and ducks to be quacked in title screen if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) { - if (info->type == VIEWPORT_INTERACTION_ITEM_SPRITE && (sprite->Is() || sprite->Is())) - return info->type; + if (info.SpriteType == VIEWPORT_INTERACTION_ITEM_SPRITE && (sprite->Is() || sprite->Is())) + return info; else - return info->type = VIEWPORT_INTERACTION_ITEM_NONE; + { + info.SpriteType = VIEWPORT_INTERACTION_ITEM_NONE; + return info; + } } - switch (info->type) + switch (info.SpriteType) { case VIEWPORT_INTERACTION_ITEM_SPRITE: switch (sprite->sprite_identifier) @@ -90,7 +90,7 @@ int32_t viewport_interaction_get_item_left(const ScreenCoordsXY& screenCoords, v if (vehicle != nullptr && vehicle->ride_subtype != RIDE_ENTRY_INDEX_NULL) vehicle->SetMapToolbar(); else - info->type = VIEWPORT_INTERACTION_ITEM_NONE; + info.SpriteType = VIEWPORT_INTERACTION_ITEM_NONE; } break; case SPRITE_IDENTIFIER_PEEP: @@ -102,7 +102,7 @@ int32_t viewport_interaction_get_item_left(const ScreenCoordsXY& screenCoords, v } else { - info->type = VIEWPORT_INTERACTION_ITEM_NONE; + info.SpriteType = VIEWPORT_INTERACTION_ITEM_NONE; } } break; @@ -122,79 +122,81 @@ int32_t viewport_interaction_get_item_left(const ScreenCoordsXY& screenCoords, v break; } default: - info->type = VIEWPORT_INTERACTION_ITEM_NONE; + info.SpriteType = VIEWPORT_INTERACTION_ITEM_NONE; break; } // If nothing is under cursor, find a close by peep - if (info->type == VIEWPORT_INTERACTION_ITEM_NONE) + if (info.SpriteType == VIEWPORT_INTERACTION_ITEM_NONE) { auto peep = viewport_interaction_get_closest_peep(screenCoords, 32); - if (peep == nullptr) - return VIEWPORT_INTERACTION_ITEM_NONE; - - info->sprite = peep; - info->type = VIEWPORT_INTERACTION_ITEM_SPRITE; - info->x = peep->x; - info->y = peep->y; - peep_set_map_tooltip(peep); + if (peep != nullptr) + { + info.Entity = peep; + info.SpriteType = VIEWPORT_INTERACTION_ITEM_SPRITE; + info.Loc.x = peep->x; + info.Loc.y = peep->y; + peep_set_map_tooltip(peep); + } } - return info->type; + return info; } -int32_t viewport_interaction_left_over(const ScreenCoordsXY& screenCoords) +bool viewport_interaction_left_over(const ScreenCoordsXY& screenCoords) { - viewport_interaction_info info; + auto info = viewport_interaction_get_item_left(screenCoords); - switch (viewport_interaction_get_item_left(screenCoords, &info)) + switch (info.SpriteType) { case VIEWPORT_INTERACTION_ITEM_SPRITE: case VIEWPORT_INTERACTION_ITEM_RIDE: case VIEWPORT_INTERACTION_ITEM_PARK: - return 1; + return true; default: - return 0; + return false; } } -int32_t viewport_interaction_left_click(const ScreenCoordsXY& screenCoords) +bool viewport_interaction_left_click(const ScreenCoordsXY& screenCoords) { - viewport_interaction_info info; + auto info = viewport_interaction_get_item_left(screenCoords); - switch (viewport_interaction_get_item_left(screenCoords, &info)) + switch (info.SpriteType) { case VIEWPORT_INTERACTION_ITEM_SPRITE: - switch (info.sprite->sprite_identifier) + { + auto entity = info.Entity; + switch (entity->sprite_identifier) { case SPRITE_IDENTIFIER_VEHICLE: { auto intent = Intent(WD_VEHICLE); - intent.putExtra(INTENT_EXTRA_VEHICLE, info.sprite); + intent.putExtra(INTENT_EXTRA_VEHICLE, entity); context_open_intent(&intent); break; } case SPRITE_IDENTIFIER_PEEP: { auto intent = Intent(WC_PEEP); - intent.putExtra(INTENT_EXTRA_PEEP, info.sprite); + intent.putExtra(INTENT_EXTRA_PEEP, entity); context_open_intent(&intent); break; } case SPRITE_IDENTIFIER_MISC: if (game_is_not_paused()) { - switch (info.sprite->type) + switch (entity->type) { case SPRITE_MISC_BALLOON: { - auto balloonPress = BalloonPressAction(info.sprite->sprite_index); + auto balloonPress = BalloonPressAction(entity->sprite_index); GameActions::Execute(&balloonPress); } break; case SPRITE_MISC_DUCK: { - auto duck = info.sprite->As(); + auto duck = entity->As(); if (duck != nullptr) { duck_press(duck); @@ -205,19 +207,20 @@ int32_t viewport_interaction_left_click(const ScreenCoordsXY& screenCoords) } break; } - return 1; + return true; + } case VIEWPORT_INTERACTION_ITEM_RIDE: { auto intent = Intent(WD_TRACK); - intent.putExtra(INTENT_EXTRA_TILE_ELEMENT, info.tileElement); + intent.putExtra(INTENT_EXTRA_TILE_ELEMENT, info.Element); context_open_intent(&intent); return true; } case VIEWPORT_INTERACTION_ITEM_PARK: context_open_window(WC_PARK_INFORMATION); - return 1; + return true; default: - return 0; + return false; } } @@ -225,41 +228,39 @@ int32_t viewport_interaction_left_click(const ScreenCoordsXY& screenCoords) * * rct2: 0x006EDE88 */ -int32_t viewport_interaction_get_item_right(const ScreenCoordsXY& screenCoords, viewport_interaction_info* info) +InteractionInfo viewport_interaction_get_item_right(const ScreenCoordsXY& screenCoords) { - TileElement* tileElement; rct_scenery_entry* sceneryEntry; Ride* ride; int32_t i, stationIndex; - + InteractionInfo info{}; // No click input for title screen or track manager if (gScreenFlags & (SCREEN_FLAGS_TITLE_DEMO | SCREEN_FLAGS_TRACK_MANAGER)) - return info->type = VIEWPORT_INTERACTION_ITEM_NONE; + return info; // if ((gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) && gS6Info.editor_step != EDITOR_STEP_ROLLERCOASTER_DESIGNER) - return info->type = VIEWPORT_INTERACTION_ITEM_NONE; + return info; - CoordsXY mapCoord = {}; - get_map_coordinates_from_pos( - screenCoords, ~(VIEWPORT_INTERACTION_MASK_TERRAIN & VIEWPORT_INTERACTION_MASK_WATER), mapCoord, &info->type, - &info->tileElement, nullptr); - info->x = mapCoord.x; - info->y = mapCoord.y; - tileElement = info->tileElement; - auto sprite = info->sprite; + info = get_map_coordinates_from_pos(screenCoords, ~(VIEWPORT_INTERACTION_MASK_TERRAIN & VIEWPORT_INTERACTION_MASK_WATER)); + auto tileElement = info.Element; - switch (info->type) + switch (info.SpriteType) { case VIEWPORT_INTERACTION_ITEM_SPRITE: { + auto sprite = info.Entity; if ((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || sprite->sprite_identifier != SPRITE_IDENTIFIER_VEHICLE) - return info->type = VIEWPORT_INTERACTION_ITEM_NONE; + { + info.SpriteType = VIEWPORT_INTERACTION_ITEM_NONE; + return info; + } auto vehicle = sprite->As(); if (vehicle == nullptr) { - return info->type = VIEWPORT_INTERACTION_ITEM_NONE; + info.SpriteType = VIEWPORT_INTERACTION_ITEM_NONE; + return info; } ride = get_ride(vehicle->ride); if (ride != nullptr && ride->status == RIDE_STATUS_CLOSED) @@ -268,21 +269,30 @@ int32_t viewport_interaction_get_item_right(const ScreenCoordsXY& screenCoords, ft.Add(STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY); ride->FormatNameTo(ft); } - return info->type; + return info; } case VIEWPORT_INTERACTION_ITEM_RIDE: { if (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) - return info->type = VIEWPORT_INTERACTION_ITEM_NONE; + { + info.SpriteType = VIEWPORT_INTERACTION_ITEM_NONE; + return info; + } if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH) - return info->type = VIEWPORT_INTERACTION_ITEM_NONE; + { + info.SpriteType = VIEWPORT_INTERACTION_ITEM_NONE; + return info; + } ride = get_ride(tile_element_get_ride_index(tileElement)); if (ride == nullptr) - return info->type = VIEWPORT_INTERACTION_ITEM_NONE; + { + info.SpriteType = VIEWPORT_INTERACTION_ITEM_NONE; + return info; + } if (ride->status != RIDE_STATUS_CLOSED) - return info->type; + return info; auto ft = Formatter::MapTooltip(); ft.Add(STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY); @@ -330,13 +340,14 @@ int32_t viewport_interaction_get_item_right(const ScreenCoordsXY& screenCoords, else { // FIXME: Why does it *2 the value? - if (!gCheatsSandboxMode && !map_is_location_owned({ info->x, info->y, tileElement->GetBaseZ() * 2 })) + if (!gCheatsSandboxMode && !map_is_location_owned({ info.Loc, tileElement->GetBaseZ() * 2 })) { - return info->type = VIEWPORT_INTERACTION_ITEM_NONE; + info.SpriteType = VIEWPORT_INTERACTION_ITEM_NONE; + return info; } ride->FormatNameTo(ft); - return info->type; + return info; } ride->FormatNameTo(ft); @@ -352,7 +363,7 @@ int32_t viewport_interaction_get_item_right(const ScreenCoordsXY& screenCoords, stationIndex--; stationIndex++; ft.Add(stationIndex); - return info->type; + return info; } case VIEWPORT_INTERACTION_ITEM_WALL: sceneryEntry = tileElement->AsWall()->GetEntry(); @@ -366,7 +377,7 @@ int32_t viewport_interaction_get_item_right(const ScreenCoordsXY& screenCoords, banner->FormatTextTo(ft); ft.Add(STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY); ft.Add(sceneryEntry->name); - return info->type; + return info; } } break; @@ -383,7 +394,7 @@ int32_t viewport_interaction_get_item_right(const ScreenCoordsXY& screenCoords, banner->FormatTextTo(ft); ft.Add(STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY); ft.Add(sceneryEntry->name); - return info->type; + return info; } } break; @@ -398,26 +409,29 @@ int32_t viewport_interaction_get_item_right(const ScreenCoordsXY& screenCoords, banner->FormatTextTo(ft, /*addColour*/ true); ft.Add(STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY); ft.Add(sceneryEntry->name); - return info->type; + return info; } + default: + break; } if (!(input_test_flag(INPUT_FLAG_6)) || !(input_test_flag(INPUT_FLAG_TOOL_ACTIVE))) { if (window_find_by_class(WC_RIDE_CONSTRUCTION) == nullptr && window_find_by_class(WC_FOOTPATH) == nullptr) { - return info->type = VIEWPORT_INTERACTION_ITEM_NONE; + info.SpriteType = VIEWPORT_INTERACTION_ITEM_NONE; + return info; } } auto ft = Formatter::MapTooltip(); - switch (info->type) + switch (info.SpriteType) { case VIEWPORT_INTERACTION_ITEM_SCENERY: sceneryEntry = tileElement->AsSmallScenery()->GetEntry(); ft.Add(STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE); ft.Add(sceneryEntry->name); - return info->type; + return info; case VIEWPORT_INTERACTION_ITEM_FOOTPATH: ft.Add(STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE); @@ -425,7 +439,7 @@ int32_t viewport_interaction_get_item_right(const ScreenCoordsXY& screenCoords, ft.Add(STR_QUEUE_LINE_MAP_TIP); else ft.Add(STR_FOOTPATH_MAP_TIP); - return info->type; + return info; case VIEWPORT_INTERACTION_ITEM_FOOTPATH_ITEM: sceneryEntry = tileElement->AsPath()->GetAdditionEntry(); @@ -435,7 +449,7 @@ int32_t viewport_interaction_get_item_right(const ScreenCoordsXY& screenCoords, ft.Add(STR_BROKEN); } ft.Add(sceneryEntry->name); - return info->type; + return info; case VIEWPORT_INTERACTION_ITEM_PARK: if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gCheatsSandboxMode) @@ -446,49 +460,57 @@ int32_t viewport_interaction_get_item_right(const ScreenCoordsXY& screenCoords, ft.Add(STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE); ft.Add(STR_OBJECT_SELECTION_PARK_ENTRANCE); - return info->type; + return info; case VIEWPORT_INTERACTION_ITEM_WALL: sceneryEntry = tileElement->AsWall()->GetEntry(); ft.Add(STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE); ft.Add(sceneryEntry->name); - return info->type; + return info; case VIEWPORT_INTERACTION_ITEM_LARGE_SCENERY: sceneryEntry = tileElement->AsLargeScenery()->GetEntry(); ft.Add(STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE); ft.Add(sceneryEntry->name); - return info->type; + return info; + default: + break; } - return info->type = VIEWPORT_INTERACTION_ITEM_NONE; + info.SpriteType = VIEWPORT_INTERACTION_ITEM_NONE; + return info; } -int32_t viewport_interaction_right_over(const ScreenCoordsXY& screenCoords) +bool viewport_interaction_right_over(const ScreenCoordsXY& screenCoords) { - viewport_interaction_info info; + auto info = viewport_interaction_get_item_right(screenCoords); - return viewport_interaction_get_item_right(screenCoords, &info) != 0; + return info.SpriteType != VIEWPORT_INTERACTION_ITEM_NONE; } /** * * rct2: 0x006E8A62 */ -int32_t viewport_interaction_right_click(const ScreenCoordsXY& screenCoords) +bool viewport_interaction_right_click(const ScreenCoordsXY& screenCoords) { CoordsXYE tileElement; - viewport_interaction_info info; + auto info = viewport_interaction_get_item_right(screenCoords); - switch (viewport_interaction_get_item_right(screenCoords, &info)) + switch (info.SpriteType) { case VIEWPORT_INTERACTION_ITEM_NONE: - return 0; + case VIEWPORT_INTERACTION_ITEM_TERRAIN: + case VIEWPORT_INTERACTION_ITEM_WATER: + case VIEWPORT_INTERACTION_ITEM_LABEL: + return false; case VIEWPORT_INTERACTION_ITEM_SPRITE: - if (info.sprite->sprite_identifier == SPRITE_IDENTIFIER_VEHICLE) + { + auto entity = info.Entity; + if (entity->sprite_identifier == SPRITE_IDENTIFIER_VEHICLE) { - auto vehicle = info.sprite->As(); + auto vehicle = entity->As(); if (vehicle == nullptr) { break; @@ -499,37 +521,36 @@ int32_t viewport_interaction_right_click(const ScreenCoordsXY& screenCoords) ride_construct(ride); } } - break; + } + break; case VIEWPORT_INTERACTION_ITEM_RIDE: - tileElement.x = info.x; - tileElement.y = info.y; - tileElement.element = info.tileElement; + tileElement = { info.Loc, info.Element }; ride_modify(&tileElement); break; case VIEWPORT_INTERACTION_ITEM_SCENERY: - viewport_interaction_remove_scenery(info.tileElement, { info.x, info.y }); + viewport_interaction_remove_scenery(info.Element, info.Loc); break; case VIEWPORT_INTERACTION_ITEM_FOOTPATH: - viewport_interaction_remove_footpath(info.tileElement, { info.x, info.y }); + viewport_interaction_remove_footpath(info.Element, info.Loc); break; case VIEWPORT_INTERACTION_ITEM_FOOTPATH_ITEM: - viewport_interaction_remove_footpath_item(info.tileElement, { info.x, info.y }); + viewport_interaction_remove_footpath_item(info.Element, info.Loc); break; case VIEWPORT_INTERACTION_ITEM_PARK: - viewport_interaction_remove_park_entrance(info.tileElement, { info.x, info.y }); + viewport_interaction_remove_park_entrance(info.Element, info.Loc); break; case VIEWPORT_INTERACTION_ITEM_WALL: - viewport_interaction_remove_park_wall(info.tileElement, { info.x, info.y }); + viewport_interaction_remove_park_wall(info.Element, info.Loc); break; case VIEWPORT_INTERACTION_ITEM_LARGE_SCENERY: - viewport_interaction_remove_large_scenery(info.tileElement, { info.x, info.y }); + viewport_interaction_remove_large_scenery(info.Element, info.Loc); break; case VIEWPORT_INTERACTION_ITEM_BANNER: - context_open_detail_window(WD_BANNER, info.tileElement->AsBanner()->GetIndex()); + context_open_detail_window(WD_BANNER, info.Element->AsBanner()->GetIndex()); break; } - return 1; + return true; } /** @@ -688,26 +709,22 @@ static Peep* viewport_interaction_get_closest_peep(ScreenCoordsXY screenCoords, */ CoordsXY sub_68A15E(const ScreenCoordsXY& screenCoords) { - CoordsXY mapCoords; - CoordsXY initialPos{}; - int32_t interactionType; - TileElement* tileElement; - rct_viewport* viewport; - get_map_coordinates_from_pos( - screenCoords, VIEWPORT_INTERACTION_MASK_TERRAIN & VIEWPORT_INTERACTION_MASK_WATER, mapCoords, &interactionType, - &tileElement, &viewport); - initialPos = mapCoords; + rct_window* window = window_find_from_point(screenCoords); + auto viewport = window->viewport; + auto info = get_map_coordinates_from_pos_window( + window, screenCoords, VIEWPORT_INTERACTION_MASK_TERRAIN & VIEWPORT_INTERACTION_MASK_WATER); + auto initialPos = info.Loc; - if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE) + if (info.SpriteType == VIEWPORT_INTERACTION_ITEM_NONE) { initialPos.setNull(); return initialPos; } int16_t waterHeight = 0; - if (interactionType == VIEWPORT_INTERACTION_ITEM_WATER) + if (info.SpriteType == VIEWPORT_INTERACTION_ITEM_WATER) { - waterHeight = tileElement->AsSurface()->GetWaterHeight(); + waterHeight = info.Element->AsSurface()->GetWaterHeight(); } auto initialVPPos = screen_coord_to_viewport_coord(viewport, screenCoords); @@ -716,7 +733,7 @@ CoordsXY sub_68A15E(const ScreenCoordsXY& screenCoords) for (int32_t i = 0; i < 5; i++) { int16_t z = waterHeight; - if (interactionType != VIEWPORT_INTERACTION_ITEM_WATER) + if (info.SpriteType != VIEWPORT_INTERACTION_ITEM_WATER) { z = tile_element_height(mapPos); } diff --git a/src/openrct2-ui/scripting/CustomMenu.cpp b/src/openrct2-ui/scripting/CustomMenu.cpp index 28c3b9d2bf..d157f46a72 100644 --- a/src/openrct2-ui/scripting/CustomMenu.cpp +++ b/src/openrct2-ui/scripting/CustomMenu.cpp @@ -121,31 +121,26 @@ namespace OpenRCT2::Scripting auto ctx = dukHandler.context(); auto flags = 0; - CoordsXY mapCoords{}; - int32_t interactionType = 0; - TileElement* tileElement{}; - get_map_coordinates_from_pos(screenCoords, flags, mapCoords, &interactionType, &tileElement, nullptr); + auto info = get_map_coordinates_from_pos(screenCoords, flags); DukObject obj(dukHandler.context()); obj.Set("isDown", MouseDown); obj.Set("screenCoords", ToDuk(ctx, screenCoords)); - obj.Set("mapCoords", ToDuk(ctx, mapCoords)); + obj.Set("mapCoords", ToDuk(ctx, info.Loc)); - if (interactionType == VIEWPORT_INTERACTION_ITEM_SPRITE && tileElement != nullptr) + if (info.SpriteType == VIEWPORT_INTERACTION_ITEM_SPRITE && info.Entity != nullptr) { - // get_map_coordinates_from_pos returns the sprite using tileElement... ugh - auto sprite = reinterpret_cast(tileElement); - obj.Set("entityId", sprite->generic.sprite_index); + obj.Set("entityId", info.Entity->sprite_index); } - else if (tileElement != nullptr) + else if (info.Element != nullptr) { int32_t index = 0; - auto el = map_get_first_element_at(mapCoords); + auto el = map_get_first_element_at(info.Loc); if (el != nullptr) { do { - if (el == tileElement) + if (el == info.Element) { obj.Set("tileElementIndex", index); break; diff --git a/src/openrct2-ui/windows/Footpath.cpp b/src/openrct2-ui/windows/Footpath.cpp index f27bdddb61..77971956f0 100644 --- a/src/openrct2-ui/windows/Footpath.cpp +++ b/src/openrct2-ui/windows/Footpath.cpp @@ -720,14 +720,10 @@ static void window_footpath_set_provisional_path_at_point(const ScreenCoordsXY& map_invalidate_selection_rect(); gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE_ARROW; - int32_t interactionType{}; - TileElement* tileElement{}; - CoordsXY mapCoord = {}; - get_map_coordinates_from_pos( - screenCoords, VIEWPORT_INTERACTION_MASK_FOOTPATH & VIEWPORT_INTERACTION_MASK_TERRAIN, mapCoord, &interactionType, - &tileElement, nullptr); + auto info = get_map_coordinates_from_pos( + screenCoords, VIEWPORT_INTERACTION_MASK_FOOTPATH & VIEWPORT_INTERACTION_MASK_TERRAIN); - if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE || tileElement == nullptr) + if (info.SpriteType == VIEWPORT_INTERACTION_ITEM_NONE || info.Element == nullptr) { gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE; footpath_provisional_update(); @@ -735,8 +731,8 @@ static void window_footpath_set_provisional_path_at_point(const ScreenCoordsXY& else { // Check for change - if ((gFootpathProvisionalFlags & PROVISIONAL_PATH_FLAG_1) && gFootpathProvisionalPosition.x == mapCoord.x - && gFootpathProvisionalPosition.y == mapCoord.y && gFootpathProvisionalPosition.z == tileElement->GetBaseZ()) + if ((gFootpathProvisionalFlags & PROVISIONAL_PATH_FLAG_1) + && gFootpathProvisionalPosition == CoordsXYZ{ info.Loc, info.Element->GetBaseZ() }) { return; } @@ -744,18 +740,18 @@ static void window_footpath_set_provisional_path_at_point(const ScreenCoordsXY& // Set map selection gMapSelectFlags |= MAP_SELECT_FLAG_ENABLE; gMapSelectType = MAP_SELECT_TYPE_FULL; - gMapSelectPositionA = mapCoord; - gMapSelectPositionB = mapCoord; + gMapSelectPositionA = info.Loc; + gMapSelectPositionB = info.Loc; footpath_provisional_update(); // Set provisional path int32_t slope = 0; - switch (interactionType) + switch (info.SpriteType) { case VIEWPORT_INTERACTION_ITEM_TERRAIN: { - auto surfaceElement = tileElement->AsSurface(); + auto surfaceElement = info.Element->AsSurface(); if (surfaceElement != nullptr) { slope = DefaultPathSlope[surfaceElement->GetSlope() & TILE_ELEMENT_SURFACE_RAISED_CORNERS_MASK]; @@ -764,7 +760,7 @@ static void window_footpath_set_provisional_path_at_point(const ScreenCoordsXY& } case VIEWPORT_INTERACTION_ITEM_FOOTPATH: { - auto pathElement = tileElement->AsPath(); + auto pathElement = info.Element->AsPath(); if (pathElement != nullptr) { slope = pathElement->GetSlopeDirection(); @@ -775,8 +771,10 @@ static void window_footpath_set_provisional_path_at_point(const ScreenCoordsXY& } break; } + default: + break; } - auto z = tileElement->GetBaseZ(); + auto z = info.Element->GetBaseZ(); if (slope & RAISE_FOOTPATH_FLAG) { slope &= ~RAISE_FOOTPATH_FLAG; @@ -784,7 +782,7 @@ static void window_footpath_set_provisional_path_at_point(const ScreenCoordsXY& } int32_t pathType = (gFootpathSelectedType << 7) + (gFootpathSelectedId & 0xFF); - _window_footpath_cost = footpath_provisional_set(pathType, { mapCoord, z }, slope); + _window_footpath_cost = footpath_provisional_set(pathType, { info.Loc, z }, slope); window_invalidate_by_class(WC_FOOTPATH); } } @@ -839,9 +837,6 @@ static void window_footpath_set_selection_start_bridge_at_point(const ScreenCoor */ static void window_footpath_place_path_at_point(const ScreenCoordsXY& screenCoords) { - int32_t interactionType, currentType, selectedType, z; - TileElement* tileElement; - if (_footpathErrorOccured) { return; @@ -849,42 +844,42 @@ static void window_footpath_place_path_at_point(const ScreenCoordsXY& screenCoor footpath_provisional_update(); - CoordsXY mapCoord = {}; - get_map_coordinates_from_pos( - screenCoords, VIEWPORT_INTERACTION_MASK_FOOTPATH & VIEWPORT_INTERACTION_MASK_TERRAIN, mapCoord, &interactionType, - &tileElement, nullptr); + const auto info = get_map_coordinates_from_pos( + screenCoords, VIEWPORT_INTERACTION_MASK_FOOTPATH & VIEWPORT_INTERACTION_MASK_TERRAIN); - if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE) + if (info.SpriteType == VIEWPORT_INTERACTION_ITEM_NONE) { return; } // Set path - currentType = 0; - switch (interactionType) + auto slope = 0; + switch (info.SpriteType) { case VIEWPORT_INTERACTION_ITEM_TERRAIN: - currentType = DefaultPathSlope[tileElement->AsSurface()->GetSlope() & TILE_ELEMENT_SURFACE_RAISED_CORNERS_MASK]; + slope = DefaultPathSlope[info.Element->AsSurface()->GetSlope() & TILE_ELEMENT_SURFACE_RAISED_CORNERS_MASK]; break; case VIEWPORT_INTERACTION_ITEM_FOOTPATH: - currentType = tileElement->AsPath()->GetSlopeDirection(); - if (tileElement->AsPath()->IsSloped()) + slope = info.Element->AsPath()->GetSlopeDirection(); + if (info.Element->AsPath()->IsSloped()) { - currentType |= FOOTPATH_PROPERTIES_FLAG_IS_SLOPED; + slope |= FOOTPATH_PROPERTIES_FLAG_IS_SLOPED; } break; + default: + break; } - z = tileElement->GetBaseZ(); - if (currentType & RAISE_FOOTPATH_FLAG) + auto z = info.Element->GetBaseZ(); + if (slope & RAISE_FOOTPATH_FLAG) { - currentType &= ~RAISE_FOOTPATH_FLAG; + slope &= ~RAISE_FOOTPATH_FLAG; z += PATH_HEIGHT_STEP; } - selectedType = (gFootpathSelectedType << 7) + (gFootpathSelectedId & 0xFF); + auto selectedType = (gFootpathSelectedType << 7) + (gFootpathSelectedId & 0xFF); // Try and place path gGameCommandErrorTitle = STR_CANT_BUILD_FOOTPATH_HERE; - auto footpathPlaceAction = FootpathPlaceAction({ mapCoord.x, mapCoord.y, z }, currentType, selectedType); + auto footpathPlaceAction = FootpathPlaceAction({ info.Loc, z }, slope, selectedType); footpathPlaceAction.SetCallback([](const GameAction* ga, const GameActionResult* result) { if (result->Error == GA_ERROR::OK) { diff --git a/src/openrct2-ui/windows/Guest.cpp b/src/openrct2-ui/windows/Guest.cpp index c8e59a995b..d81be82e94 100644 --- a/src/openrct2-ui/windows/Guest.cpp +++ b/src/openrct2-ui/windows/Guest.cpp @@ -1285,11 +1285,8 @@ void window_guest_overview_tool_update(rct_window* w, rct_widgetindex widgetInde gPickupPeepImage = UINT32_MAX; - int32_t interactionType; - CoordsXY unusedCoords; - get_map_coordinates_from_pos( - screenCoords, VIEWPORT_INTERACTION_MASK_NONE, unusedCoords, &interactionType, nullptr, nullptr); - if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE) + auto info = get_map_coordinates_from_pos(screenCoords, VIEWPORT_INTERACTION_MASK_NONE); + if (info.SpriteType == VIEWPORT_INTERACTION_ITEM_NONE) return; gPickupPeepX = screenCoords.x - 1; diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index 2a40eaf5ca..99240d031a 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -4335,28 +4335,22 @@ static int32_t window_ride_has_track_colour(Ride* ride, int32_t trackColour) static void window_ride_set_track_colour_scheme(rct_window* w, const ScreenCoordsXY& screenPos) { - TileElement* tileElement; - uint8_t newColourScheme; - int32_t interactionType, z, direction; + auto newColourScheme = static_cast(w->ride_colour); + auto info = get_map_coordinates_from_pos(screenPos, VIEWPORT_INTERACTION_MASK_RIDE); - newColourScheme = static_cast(w->ride_colour); - - CoordsXY mapCoord = {}; - get_map_coordinates_from_pos(screenPos, VIEWPORT_INTERACTION_MASK_RIDE, mapCoord, &interactionType, &tileElement, nullptr); - - if (interactionType != VIEWPORT_INTERACTION_ITEM_RIDE) + if (info.SpriteType != VIEWPORT_INTERACTION_ITEM_RIDE) return; - if (tileElement->GetType() != TILE_ELEMENT_TYPE_TRACK) + if (info.Element->GetType() != TILE_ELEMENT_TYPE_TRACK) return; - if (tileElement->AsTrack()->GetRideIndex() != w->number) + if (info.Element->AsTrack()->GetRideIndex() != w->number) return; - if (tileElement->AsTrack()->GetColourScheme() == newColourScheme) + if (info.Element->AsTrack()->GetColourScheme() == newColourScheme) return; - z = tileElement->GetBaseZ(); - direction = tileElement->GetDirection(); + auto z = info.Element->GetBaseZ(); + auto direction = info.Element->GetDirection(); auto gameAction = RideSetColourSchemeAction( - CoordsXYZD{ mapCoord, z, static_cast(direction) }, tileElement->AsTrack()->GetTrackType(), newColourScheme); + CoordsXYZD{ info.Loc, z, static_cast(direction) }, info.Element->AsTrack()->GetTrackType(), newColourScheme); GameActions::Execute(&gameAction); } @@ -5527,23 +5521,21 @@ static void window_ride_measurements_update(rct_window* w) */ static void window_ride_measurements_tooldown(rct_window* w, rct_widgetindex widgetIndex, const ScreenCoordsXY& screenCoords) { - TileElement* tileElement; - CoordsXY mapCoords; - int32_t interactionType; - _lastSceneryX = screenCoords.x; _lastSceneryY = screenCoords.y; _collectTrackDesignScenery = true; // Default to true in case user does not select anything valid - get_map_coordinates_from_pos(screenCoords, 0xFCCF, mapCoords, &interactionType, &tileElement, nullptr); - switch (interactionType) + auto info = get_map_coordinates_from_pos(screenCoords, 0xFCCF); + switch (info.SpriteType) { case VIEWPORT_INTERACTION_ITEM_SCENERY: case VIEWPORT_INTERACTION_ITEM_LARGE_SCENERY: case VIEWPORT_INTERACTION_ITEM_WALL: case VIEWPORT_INTERACTION_ITEM_FOOTPATH: - _collectTrackDesignScenery = !track_design_save_contains_tile_element(tileElement); - track_design_save_select_tile_element(interactionType, mapCoords, tileElement, _collectTrackDesignScenery); + _collectTrackDesignScenery = !track_design_save_contains_tile_element(info.Element); + track_design_save_select_tile_element(info.SpriteType, info.Loc, info.Element, _collectTrackDesignScenery); + break; + default: break; } } @@ -5555,18 +5547,16 @@ static void window_ride_measurements_tooldrag(rct_window* w, rct_widgetindex wid _lastSceneryX = screenCoords.x; _lastSceneryY = screenCoords.y; - TileElement* tileElement; - CoordsXY mapCoords; - int32_t interactionType; - - get_map_coordinates_from_pos(screenCoords, 0xFCCF, mapCoords, &interactionType, &tileElement, nullptr); - switch (interactionType) + auto info = get_map_coordinates_from_pos(screenCoords, 0xFCCF); + switch (info.SpriteType) { case VIEWPORT_INTERACTION_ITEM_SCENERY: case VIEWPORT_INTERACTION_ITEM_LARGE_SCENERY: case VIEWPORT_INTERACTION_ITEM_WALL: case VIEWPORT_INTERACTION_ITEM_FOOTPATH: - track_design_save_select_tile_element(interactionType, mapCoords, tileElement, _collectTrackDesignScenery); + track_design_save_select_tile_element(info.SpriteType, info.Loc, info.Element, _collectTrackDesignScenery); + break; + default: break; } } diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index 5c175c8b74..2b56111548 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -2112,13 +2112,10 @@ static std::optional ride_get_place_position_from_screen_position(Scre { if (gInputPlaceObjectModifier & PLACE_OBJECT_MODIFIER_COPY_Z) { - TileElement* tileElement; - rct_viewport* viewport = nullptr; - int32_t interactionType; - get_map_coordinates_from_pos(screenCoords, 0xFCCA, mapCoords, &interactionType, &tileElement, &viewport); - if (interactionType != 0) + auto info = get_map_coordinates_from_pos(screenCoords, 0xFCCA); + if (info.SpriteType != VIEWPORT_INTERACTION_ITEM_NONE) { - _trackPlaceCtrlZ = tileElement->GetBaseZ(); + _trackPlaceCtrlZ = info.Element->GetBaseZ(); _trackPlaceCtrlState = true; } } diff --git a/src/openrct2-ui/windows/Staff.cpp b/src/openrct2-ui/windows/Staff.cpp index 29c5fd12a1..24ed715ad4 100644 --- a/src/openrct2-ui/windows/Staff.cpp +++ b/src/openrct2-ui/windows/Staff.cpp @@ -1210,11 +1210,8 @@ void window_staff_overview_tool_update(rct_window* w, rct_widgetindex widgetInde gPickupPeepImage = UINT32_MAX; - int32_t interactionType; - CoordsXY unusedCoords; - get_map_coordinates_from_pos( - screenCoords, VIEWPORT_INTERACTION_MASK_NONE, unusedCoords, &interactionType, nullptr, nullptr); - if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE) + auto info = get_map_coordinates_from_pos(screenCoords, VIEWPORT_INTERACTION_MASK_NONE); + if (info.SpriteType == VIEWPORT_INTERACTION_ITEM_NONE) return; gPickupPeepX = screenCoords.x - 1; diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index c731e0c1c2..0a4db9723c 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -1209,7 +1209,9 @@ static void window_tile_inspector_tool_update(rct_window* w, rct_widgetindex wid bool mouseOnViewport = false; if (input_test_place_object_modifier(PLACE_OBJECT_MODIFIER_COPY_Z)) { - get_map_coordinates_from_pos(screenCoords, ViewportInteractionFlags, mapCoords, nullptr, &clickedElement, nullptr); + auto info = get_map_coordinates_from_pos(screenCoords, ViewportInteractionFlags); + clickedElement = info.Element; + mapCoords = info.Loc; } // Even if Ctrl was pressed, fall back to normal selection when there was nothing under the cursor @@ -1259,7 +1261,9 @@ static void window_tile_inspector_update_selected_tile(rct_window* w, const Scre TileElement* clickedElement = nullptr; if (ctrlIsHeldDown) { - get_map_coordinates_from_pos(screenCoords, ViewportInteractionFlags, mapCoords, nullptr, &clickedElement, nullptr); + auto info = get_map_coordinates_from_pos(screenCoords, ViewportInteractionFlags); + clickedElement = info.Element; + mapCoords = info.Loc; } // Even if Ctrl was pressed, fall back to normal selection when there was nothing under the cursor diff --git a/src/openrct2-ui/windows/TitleCommandEditor.cpp b/src/openrct2-ui/windows/TitleCommandEditor.cpp index 9b03ccfa23..1682d7902b 100644 --- a/src/openrct2-ui/windows/TitleCommandEditor.cpp +++ b/src/openrct2-ui/windows/TitleCommandEditor.cpp @@ -190,12 +190,9 @@ static TileCoordsXY get_location() rct_window* w = window_get_main(); if (w != nullptr) { - int32_t interactionType; - TileElement* tileElement; - CoordsXY mapCoord; - get_map_coordinates_from_pos_window( - w, { w->viewport->view_width / 2, w->viewport->view_height / 2 }, VIEWPORT_INTERACTION_MASK_TERRAIN, mapCoord, - &interactionType, &tileElement, nullptr); + auto info = get_map_coordinates_from_pos_window( + w, { w->viewport->view_width / 2, w->viewport->view_height / 2 }, VIEWPORT_INTERACTION_MASK_TERRAIN); + auto mapCoord = info.Loc; mapCoord.x -= 16; mapCoord.y -= 16; tileCoord = TileCoordsXY{ mapCoord }; @@ -608,17 +605,17 @@ static void window_title_command_editor_update(rct_window* w) static void window_title_command_editor_tool_down( rct_window* w, rct_widgetindex widgetIndex, const ScreenCoordsXY& screenCoords) { - viewport_interaction_info info; - viewport_interaction_get_item_left(screenCoords, &info); + auto info = viewport_interaction_get_item_left(screenCoords); - if (info.type == VIEWPORT_INTERACTION_ITEM_SPRITE) + if (info.SpriteType == VIEWPORT_INTERACTION_ITEM_SPRITE) { + auto entity = info.Entity; bool validSprite = false; - auto peep = info.sprite->As(); - auto vehicle = info.sprite->As(); - auto litter = info.sprite->As(); - auto duck = info.sprite->As(); - auto balloon = info.sprite->As(); + auto peep = entity->As(); + auto vehicle = entity->As(); + auto litter = entity->As(); + auto duck = entity->As(); + auto balloon = entity->As(); if (peep != nullptr) { validSprite = true; @@ -661,7 +658,7 @@ static void window_title_command_editor_tool_down( if (validSprite) { - command.SpriteIndex = info.sprite->sprite_index; + command.SpriteIndex = entity->sprite_index; window_follow_sprite(w, static_cast(command.SpriteIndex)); tool_cancel(); w->Invalidate(); diff --git a/src/openrct2-ui/windows/TopToolbar.cpp b/src/openrct2-ui/windows/TopToolbar.cpp index 879b58e23b..8e56f59a85 100644 --- a/src/openrct2-ui/windows/TopToolbar.cpp +++ b/src/openrct2-ui/windows/TopToolbar.cpp @@ -982,78 +982,71 @@ static void window_top_toolbar_paint(rct_window* w, rct_drawpixelinfo* dpi) */ static void repaint_scenery_tool_down(const ScreenCoordsXY& windowPos, rct_widgetindex widgetIndex) { - // ax, cx, bl - int32_t type; - // edx - TileElement* tile_element; auto flags = VIEWPORT_INTERACTION_MASK_SCENERY & VIEWPORT_INTERACTION_MASK_WALL & VIEWPORT_INTERACTION_MASK_LARGE_SCENERY & VIEWPORT_INTERACTION_MASK_BANNER; // This is -2 as banner is 12 but flags are offset different - // not used - rct_viewport* viewport; - CoordsXY gridCoords; - get_map_coordinates_from_pos(windowPos, flags, gridCoords, &type, &tile_element, &viewport); + auto info = get_map_coordinates_from_pos(windowPos, flags); - switch (type) + switch (info.SpriteType) { case VIEWPORT_INTERACTION_ITEM_SCENERY: { - rct_scenery_entry* scenery_entry = tile_element->AsSmallScenery()->GetEntry(); + rct_scenery_entry* scenery_entry = info.Element->AsSmallScenery()->GetEntry(); // If can't repaint if (!scenery_small_entry_has_flag( scenery_entry, SMALL_SCENERY_FLAG_HAS_PRIMARY_COLOUR | SMALL_SCENERY_FLAG_HAS_GLASS)) return; - uint8_t quadrant = tile_element->AsSmallScenery()->GetSceneryQuadrant(); + uint8_t quadrant = info.Element->AsSmallScenery()->GetSceneryQuadrant(); auto repaintScenery = SmallScenerySetColourAction( - { gridCoords.x, gridCoords.y, tile_element->GetBaseZ() }, quadrant, - tile_element->AsSmallScenery()->GetEntryIndex(), gWindowSceneryPrimaryColour, gWindowScenerySecondaryColour); + { info.Loc, info.Element->GetBaseZ() }, quadrant, info.Element->AsSmallScenery()->GetEntryIndex(), + gWindowSceneryPrimaryColour, gWindowScenerySecondaryColour); GameActions::Execute(&repaintScenery); break; } case VIEWPORT_INTERACTION_ITEM_WALL: { - rct_scenery_entry* scenery_entry = tile_element->AsWall()->GetEntry(); + rct_scenery_entry* scenery_entry = info.Element->AsWall()->GetEntry(); // If can't repaint if (!(scenery_entry->wall.flags & (WALL_SCENERY_HAS_PRIMARY_COLOUR | WALL_SCENERY_HAS_GLASS))) return; auto repaintScenery = WallSetColourAction( - { gridCoords.x, gridCoords.y, tile_element->GetBaseZ(), tile_element->GetDirection() }, - gWindowSceneryPrimaryColour, gWindowScenerySecondaryColour, gWindowSceneryTertiaryColour); + { info.Loc, info.Element->GetBaseZ(), info.Element->GetDirection() }, gWindowSceneryPrimaryColour, + gWindowScenerySecondaryColour, gWindowSceneryTertiaryColour); GameActions::Execute(&repaintScenery); break; } case VIEWPORT_INTERACTION_ITEM_LARGE_SCENERY: { - rct_scenery_entry* scenery_entry = tile_element->AsLargeScenery()->GetEntry(); + rct_scenery_entry* scenery_entry = info.Element->AsLargeScenery()->GetEntry(); // If can't repaint if (!(scenery_entry->large_scenery.flags & LARGE_SCENERY_FLAG_HAS_PRIMARY_COLOUR)) return; auto repaintScenery = LargeScenerySetColourAction( - { gridCoords.x, gridCoords.y, tile_element->GetBaseZ(), tile_element->GetDirection() }, - tile_element->AsLargeScenery()->GetSequenceIndex(), gWindowSceneryPrimaryColour, gWindowScenerySecondaryColour); + { info.Loc, info.Element->GetBaseZ(), info.Element->GetDirection() }, + info.Element->AsLargeScenery()->GetSequenceIndex(), gWindowSceneryPrimaryColour, gWindowScenerySecondaryColour); GameActions::Execute(&repaintScenery); break; } case VIEWPORT_INTERACTION_ITEM_BANNER: { - auto banner = tile_element->AsBanner()->GetBanner(); + auto banner = info.Element->AsBanner()->GetBanner(); if (banner != nullptr) { auto scenery_entry = get_banner_entry(banner->type); if (scenery_entry->banner.flags & BANNER_ENTRY_FLAG_HAS_PRIMARY_COLOUR) { auto repaintScenery = BannerSetColourAction( - { gridCoords.x, gridCoords.y, tile_element->GetBaseZ(), tile_element->AsBanner()->GetPosition() }, + { info.Loc, info.Element->GetBaseZ(), info.Element->AsBanner()->GetPosition() }, gWindowSceneryPrimaryColour); GameActions::Execute(&repaintScenery); @@ -1071,17 +1064,13 @@ static void scenery_eyedropper_tool_down(const ScreenCoordsXY& windowPos, rct_wi auto flags = VIEWPORT_INTERACTION_MASK_SCENERY & VIEWPORT_INTERACTION_MASK_WALL & VIEWPORT_INTERACTION_MASK_LARGE_SCENERY & VIEWPORT_INTERACTION_MASK_BANNER & VIEWPORT_INTERACTION_MASK_FOOTPATH_ITEM; - int32_t type; - TileElement* tileElement; - rct_viewport* viewport; - CoordsXY unusedCoords; - get_map_coordinates_from_pos(windowPos, flags, unusedCoords, &type, &tileElement, &viewport); + auto info = get_map_coordinates_from_pos(windowPos, flags); - switch (type) + switch (info.SpriteType) { case VIEWPORT_INTERACTION_ITEM_SCENERY: { - SmallSceneryElement* sceneryElement = tileElement->AsSmallScenery(); + SmallSceneryElement* sceneryElement = info.Element->AsSmallScenery(); auto entryIndex = sceneryElement->GetEntryIndex(); rct_scenery_entry* sceneryEntry = get_small_scenery_entry(entryIndex); if (sceneryEntry != nullptr) @@ -1098,15 +1087,15 @@ static void scenery_eyedropper_tool_down(const ScreenCoordsXY& windowPos, rct_wi } case VIEWPORT_INTERACTION_ITEM_WALL: { - auto entryIndex = tileElement->AsWall()->GetEntryIndex(); + auto entryIndex = info.Element->AsWall()->GetEntryIndex(); rct_scenery_entry* sceneryEntry = get_wall_entry(entryIndex); if (sceneryEntry != nullptr) { if (window_scenery_set_selected_item({ SCENERY_TYPE_WALL, entryIndex })) { - gWindowSceneryPrimaryColour = tileElement->AsWall()->GetPrimaryColour(); - gWindowScenerySecondaryColour = tileElement->AsWall()->GetSecondaryColour(); - gWindowSceneryTertiaryColour = tileElement->AsWall()->GetTertiaryColour(); + gWindowSceneryPrimaryColour = info.Element->AsWall()->GetPrimaryColour(); + gWindowScenerySecondaryColour = info.Element->AsWall()->GetSecondaryColour(); + gWindowSceneryTertiaryColour = info.Element->AsWall()->GetTertiaryColour(); gWindowSceneryEyedropperEnabled = false; } } @@ -1114,15 +1103,15 @@ static void scenery_eyedropper_tool_down(const ScreenCoordsXY& windowPos, rct_wi } case VIEWPORT_INTERACTION_ITEM_LARGE_SCENERY: { - auto entryIndex = tileElement->AsLargeScenery()->GetEntryIndex(); + auto entryIndex = info.Element->AsLargeScenery()->GetEntryIndex(); rct_scenery_entry* sceneryEntry = get_large_scenery_entry(entryIndex); if (sceneryEntry != nullptr) { if (window_scenery_set_selected_item({ SCENERY_TYPE_LARGE, entryIndex })) { - gWindowSceneryRotation = (get_current_rotation() + tileElement->GetDirection()) & 3; - gWindowSceneryPrimaryColour = tileElement->AsLargeScenery()->GetPrimaryColour(); - gWindowScenerySecondaryColour = tileElement->AsLargeScenery()->GetSecondaryColour(); + gWindowSceneryRotation = (get_current_rotation() + info.Element->GetDirection()) & 3; + gWindowSceneryPrimaryColour = info.Element->AsLargeScenery()->GetPrimaryColour(); + gWindowScenerySecondaryColour = info.Element->AsLargeScenery()->GetSecondaryColour(); gWindowSceneryEyedropperEnabled = false; } } @@ -1130,7 +1119,7 @@ static void scenery_eyedropper_tool_down(const ScreenCoordsXY& windowPos, rct_wi } case VIEWPORT_INTERACTION_ITEM_BANNER: { - auto banner = tileElement->AsBanner()->GetBanner(); + auto banner = info.Element->AsBanner()->GetBanner(); if (banner != nullptr) { auto sceneryEntry = get_banner_entry(banner->type); @@ -1146,7 +1135,7 @@ static void scenery_eyedropper_tool_down(const ScreenCoordsXY& windowPos, rct_wi } case VIEWPORT_INTERACTION_ITEM_FOOTPATH_ITEM: { - auto entryIndex = tileElement->AsPath()->GetAdditionEntryIndex(); + auto entryIndex = info.Element->AsPath()->GetAdditionEntryIndex(); rct_scenery_entry* sceneryEntry = get_footpath_item_entry(entryIndex); if (sceneryEntry != nullptr) { @@ -1157,6 +1146,8 @@ static void scenery_eyedropper_tool_down(const ScreenCoordsXY& windowPos, rct_wi } break; } + default: + break; } } @@ -1231,18 +1222,15 @@ static void sub_6E1F34( if (input_test_place_object_modifier(PLACE_OBJECT_MODIFIER_COPY_Z)) { // CTRL pressed - TileElement* tile_element; auto flags = VIEWPORT_INTERACTION_MASK_TERRAIN & VIEWPORT_INTERACTION_MASK_RIDE & VIEWPORT_INTERACTION_MASK_SCENERY & VIEWPORT_INTERACTION_MASK_FOOTPATH & VIEWPORT_INTERACTION_MASK_WALL & VIEWPORT_INTERACTION_MASK_LARGE_SCENERY; - int32_t interaction_type; - CoordsXY unusedCoords; - get_map_coordinates_from_pos(screenPos, flags, unusedCoords, &interaction_type, &tile_element, nullptr); + auto info = get_map_coordinates_from_pos(screenPos, flags); - if (interaction_type != VIEWPORT_INTERACTION_ITEM_NONE) + if (info.SpriteType != VIEWPORT_INTERACTION_ITEM_NONE) { gSceneryCtrlPressed = true; - gSceneryCtrlPressZ = tile_element->GetBaseZ(); + gSceneryCtrlPressZ = info.Element->GetBaseZ(); } } } @@ -1386,14 +1374,11 @@ static void sub_6E1F34( if (!gSceneryCtrlPressed) { auto flags = VIEWPORT_INTERACTION_MASK_TERRAIN & VIEWPORT_INTERACTION_MASK_WATER; - int32_t interaction_type = 0; - TileElement* tile_element; - CoordsXY gridCoords; - get_map_coordinates_from_pos(screenPos, flags, gridCoords, &interaction_type, &tile_element, nullptr); - gridPos = gridCoords; + auto info = get_map_coordinates_from_pos(screenPos, flags); + gridPos = info.Loc; - if (interaction_type == VIEWPORT_INTERACTION_ITEM_NONE) + if (info.SpriteType == VIEWPORT_INTERACTION_ITEM_NONE) { gridPos.setNull(); return; @@ -1468,25 +1453,22 @@ static void sub_6E1F34( { // Path bits auto flags = VIEWPORT_INTERACTION_MASK_FOOTPATH & VIEWPORT_INTERACTION_MASK_FOOTPATH_ITEM; - int32_t interaction_type = 0; - TileElement* tile_element; - CoordsXY gridCoords; - get_map_coordinates_from_pos(screenPos, flags, gridCoords, &interaction_type, &tile_element, nullptr); - gridPos = gridCoords; + auto info = get_map_coordinates_from_pos(screenPos, flags); + gridPos = info.Loc; - if (interaction_type == VIEWPORT_INTERACTION_ITEM_NONE) + if (info.SpriteType == VIEWPORT_INTERACTION_ITEM_NONE) { gridPos.setNull(); return; } - *parameter_1 = tile_element->AsPath()->GetSlopeDirection() << 8; - if (tile_element->AsPath()->IsSloped()) + *parameter_1 = info.Element->AsPath()->GetSlopeDirection() << 8; + if (info.Element->AsPath()->IsSloped()) *parameter_1 |= FOOTPATH_PROPERTIES_FLAG_IS_SLOPED << 8; - *parameter_2 = tile_element->base_height; - *parameter_2 |= (tile_element->AsPath()->GetSurfaceEntryIndex() << 8); - if (tile_element->AsPath()->IsQueue()) + *parameter_2 = info.Element->base_height; + *parameter_2 |= (info.Element->AsPath()->GetSurfaceEntryIndex() << 8); + if (info.Element->AsPath()->IsQueue()) { *parameter_2 |= LOCATION_NULL; } @@ -1637,14 +1619,11 @@ static void sub_6E1F34( { // Banner auto flags = VIEWPORT_INTERACTION_MASK_FOOTPATH & VIEWPORT_INTERACTION_MASK_FOOTPATH_ITEM; - int32_t interaction_type = 0; - TileElement* tile_element; - CoordsXY gridCoords; - get_map_coordinates_from_pos(screenPos, flags, gridCoords, &interaction_type, &tile_element, nullptr); - gridPos = gridCoords; + auto info = get_map_coordinates_from_pos(screenPos, flags); + gridPos = info.Loc; - if (interaction_type == VIEWPORT_INTERACTION_ITEM_NONE) + if (info.SpriteType == VIEWPORT_INTERACTION_ITEM_NONE) { gridPos.setNull(); return; @@ -1654,11 +1633,11 @@ static void sub_6E1F34( rotation -= get_current_rotation(); rotation &= 0x3; - int16_t z = tile_element->base_height; + int16_t z = info.Element->base_height; - if (tile_element->AsPath()->IsSloped()) + if (info.Element->AsPath()->IsSloped()) { - if (rotation != direction_reverse(tile_element->AsPath()->GetSlopeDirection())) + if (rotation != direction_reverse(info.Element->AsPath()->GetSlopeDirection())) { z += 2; } @@ -2402,13 +2381,9 @@ static void top_toolbar_tool_update_water(const ScreenCoordsXY& screenPos) gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE; - CoordsXY mapTile = {}; - int32_t interaction_type = 0; - get_map_coordinates_from_pos( - screenPos, VIEWPORT_INTERACTION_MASK_TERRAIN & VIEWPORT_INTERACTION_MASK_WATER, mapTile, &interaction_type, nullptr, - nullptr); + auto info = get_map_coordinates_from_pos(screenPos, VIEWPORT_INTERACTION_MASK_TERRAIN & VIEWPORT_INTERACTION_MASK_WATER); - if (interaction_type == VIEWPORT_INTERACTION_ITEM_NONE) + if (info.SpriteType == VIEWPORT_INTERACTION_ITEM_NONE) { if (gWaterToolRaiseCost != MONEY32_UNDEFINED || gWaterToolLowerCost != MONEY32_UNDEFINED) { @@ -2419,8 +2394,7 @@ static void top_toolbar_tool_update_water(const ScreenCoordsXY& screenPos) return; } - mapTile.x += 16; - mapTile.y += 16; + auto mapTile = info.Loc.ToTileCentre(); uint8_t state_changed = 0; diff --git a/src/openrct2-ui/windows/Viewport.cpp b/src/openrct2-ui/windows/Viewport.cpp index 7c6ed150b5..12321c45cc 100644 --- a/src/openrct2-ui/windows/Viewport.cpp +++ b/src/openrct2-ui/windows/Viewport.cpp @@ -145,11 +145,9 @@ static void window_viewport_mouseup(rct_window* w, rct_widgetindex widgetIndex) mainWindow = window_get_main(); if (mainWindow != nullptr) { - CoordsXY mapCoords; - get_map_coordinates_from_pos( - { w->windowPos.x + (w->width / 2), w->windowPos.y + (w->height / 2) }, VIEWPORT_INTERACTION_MASK_NONE, - mapCoords, nullptr, nullptr, nullptr); - window_scroll_to_location(mainWindow, { mapCoords, tile_element_height(mapCoords) }); + auto info = get_map_coordinates_from_pos( + { w->windowPos.x + (w->width / 2), w->windowPos.y + (w->height / 2) }, VIEWPORT_INTERACTION_MASK_NONE); + window_scroll_to_location(mainWindow, { info.Loc, tile_element_height(info.Loc) }); } break; } diff --git a/src/openrct2/interface/InteractiveConsole.cpp b/src/openrct2/interface/InteractiveConsole.cpp index b2c7e425a1..e134d5b4e0 100644 --- a/src/openrct2/interface/InteractiveConsole.cpp +++ b/src/openrct2/interface/InteractiveConsole.cpp @@ -652,15 +652,11 @@ static int32_t cc_get(InteractiveConsole& console, const arguments_t& argv) rct_window* w = window_get_main(); if (w != nullptr) { - int32_t interactionType; - TileElement* tileElement; - CoordsXY mapCoord = {}; rct_viewport* viewport = window_get_viewport(w); - get_map_coordinates_from_pos( - { viewport->view_width / 2, viewport->view_height / 2 }, VIEWPORT_INTERACTION_MASK_TERRAIN, mapCoord, - &interactionType, &tileElement, nullptr); + auto info = get_map_coordinates_from_pos( + { viewport->view_width / 2, viewport->view_height / 2 }, VIEWPORT_INTERACTION_MASK_TERRAIN); - auto tileMapCoord = TileCoordsXY(mapCoord); + auto tileMapCoord = TileCoordsXY(info.Loc); console.WriteFormatLine("location %d %d", tileMapCoord.x, tileMapCoord.y); } } diff --git a/src/openrct2/interface/Viewport.cpp b/src/openrct2/interface/Viewport.cpp index 917f356321..6600d80d17 100644 --- a/src/openrct2/interface/Viewport.cpp +++ b/src/openrct2/interface/Viewport.cpp @@ -1632,57 +1632,48 @@ InteractionInfo set_interaction_info_from_paint_session(paint_session* session, * tileElement: edx * viewport: edi */ -void get_map_coordinates_from_pos( - const ScreenCoordsXY& screenCoords, int32_t flags, CoordsXY& mapCoords, int32_t* interactionType, TileElement** tileElement, - rct_viewport** viewport) +InteractionInfo get_map_coordinates_from_pos(const ScreenCoordsXY& screenCoords, int32_t flags) { rct_window* window = window_find_from_point(screenCoords); - get_map_coordinates_from_pos_window(window, screenCoords, flags, mapCoords, interactionType, tileElement, viewport); + return get_map_coordinates_from_pos_window(window, screenCoords, flags); } -void get_map_coordinates_from_pos_window( - rct_window* window, ScreenCoordsXY screenCoords, int32_t flags, CoordsXY& mapCoords, int32_t* interactionType, - TileElement** tileElement, rct_viewport** viewport) +InteractionInfo get_map_coordinates_from_pos_window(rct_window* window, const ScreenCoordsXY& screenCoords, int32_t flags) { InteractionInfo info{}; - if (window != nullptr && window->viewport != nullptr) + if (window == nullptr || window->viewport == nullptr) { - rct_viewport* myviewport = window->viewport; - screenCoords -= myviewport->pos; - if (screenCoords.x >= 0 && screenCoords.x < static_cast(myviewport->width) && screenCoords.y >= 0 - && screenCoords.y < static_cast(myviewport->height)) - { - screenCoords.x = screenCoords.x * myviewport->zoom; - screenCoords.y = screenCoords.y * myviewport->zoom; - screenCoords += myviewport->viewPos; - if (myviewport->zoom > 0) - { - screenCoords.x &= (0xFFFF * myviewport->zoom) & 0xFFFF; - screenCoords.y &= (0xFFFF * myviewport->zoom) & 0xFFFF; - } - rct_drawpixelinfo dpi; - dpi.x = screenCoords.x; - dpi.y = screenCoords.y; - dpi.height = 1; - dpi.zoom_level = myviewport->zoom; - dpi.width = 1; - - paint_session* session = paint_session_alloc(&dpi, myviewport->flags); - paint_session_generate(session); - paint_session_arrange(session); - info = set_interaction_info_from_paint_session(session, flags & 0xFFFF); - paint_session_free(session); - } - if (viewport != nullptr) - *viewport = myviewport; + return info; } - if (interactionType != nullptr) - *interactionType = info.SpriteType; - mapCoords = info.Loc; + rct_viewport* myviewport = window->viewport; + auto viewLoc = screenCoords; + viewLoc -= myviewport->pos; + if (viewLoc.x >= 0 && viewLoc.x < static_cast(myviewport->width) && viewLoc.y >= 0 + && viewLoc.y < static_cast(myviewport->height)) + { + viewLoc.x = viewLoc.x * myviewport->zoom; + viewLoc.y = viewLoc.y * myviewport->zoom; + viewLoc += myviewport->viewPos; + if (myviewport->zoom > 0) + { + viewLoc.x &= (0xFFFF * myviewport->zoom) & 0xFFFF; + viewLoc.y &= (0xFFFF * myviewport->zoom) & 0xFFFF; + } + rct_drawpixelinfo dpi; + dpi.x = viewLoc.x; + dpi.y = viewLoc.y; + dpi.height = 1; + dpi.zoom_level = myviewport->zoom; + dpi.width = 1; - if (tileElement != nullptr) - *tileElement = info.Element; + paint_session* session = paint_session_alloc(&dpi, myviewport->flags); + paint_session_generate(session); + paint_session_arrange(session); + info = set_interaction_info_from_paint_session(session, flags & 0xFFFF); + paint_session_free(session); + } + return info; } /** @@ -1768,27 +1759,25 @@ static rct_viewport* viewport_find_from_point(const ScreenCoordsXY& screenCoords */ std::optional screen_get_map_xy(const ScreenCoordsXY& screenCoords, rct_viewport** viewport) { - int32_t interactionType; - rct_viewport* myViewport = nullptr; - CoordsXY tileLoc; // This will get the tile location but we will need the more accuracy - get_map_coordinates_from_pos( - screenCoords, VIEWPORT_INTERACTION_MASK_TERRAIN, tileLoc, &interactionType, nullptr, &myViewport); - if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE) + rct_window* window = window_find_from_point(screenCoords); + auto myViewport = window->viewport; + auto info = get_map_coordinates_from_pos_window(window, screenCoords, VIEWPORT_INTERACTION_MASK_TERRAIN); + if (info.SpriteType == VIEWPORT_INTERACTION_ITEM_NONE) { return std::nullopt; } auto start_vp_pos = screen_coord_to_viewport_coord(myViewport, screenCoords); - CoordsXY cursorMapPos = { tileLoc.x + 16, tileLoc.y + 16 }; + CoordsXY cursorMapPos = info.Loc.ToTileCentre(); // Iterates the cursor location to work out exactly where on the tile it is for (int32_t i = 0; i < 5; i++) { int32_t z = tile_element_height(cursorMapPos); cursorMapPos = viewport_coord_to_map_coord(start_vp_pos, z); - cursorMapPos.x = std::clamp(cursorMapPos.x, tileLoc.x, tileLoc.x + 31); - cursorMapPos.y = std::clamp(cursorMapPos.y, tileLoc.y, tileLoc.y + 31); + cursorMapPos.x = std::clamp(cursorMapPos.x, info.Loc.x, info.Loc.x + 31); + cursorMapPos.y = std::clamp(cursorMapPos.y, info.Loc.y, info.Loc.y + 31); } if (viewport != nullptr) diff --git a/src/openrct2/interface/Viewport.h b/src/openrct2/interface/Viewport.h index de6f30fb50..55d6db150e 100644 --- a/src/openrct2/interface/Viewport.h +++ b/src/openrct2/interface/Viewport.h @@ -49,7 +49,7 @@ enum VIEWPORT_FLAG_TRANSPARENT_BACKGROUND = (1 << 19), }; -enum +enum ViewportInteractionItem : uint8_t { VIEWPORT_INTERACTION_ITEM_NONE, VIEWPORT_INTERACTION_ITEM_TERRAIN, @@ -83,25 +83,17 @@ enum VIEWPORT_INTERACTION_MASK_BANNER = ~(1 << (VIEWPORT_INTERACTION_ITEM_BANNER - 2)), // Note the -2 for BANNER }; -struct viewport_interaction_info -{ - int32_t type; - int32_t x; - int32_t y; - union - { - TileElement* tileElement; - SpriteBase* sprite; - }; -}; - struct InteractionInfo { InteractionInfo() = default; InteractionInfo(const paint_struct* ps); CoordsXY Loc; - TileElement* Element = nullptr; - uint8_t SpriteType; + union + { + TileElement* Element = nullptr; + SpriteBase* Entity; + }; + ViewportInteractionItem SpriteType = VIEWPORT_INTERACTION_ITEM_NONE; }; #define MAX_VIEWPORT_COUNT WINDOW_LIMIT_MAX @@ -156,20 +148,16 @@ void show_construction_rights(); void hide_construction_rights(); void viewport_set_visibility(uint8_t mode); -void get_map_coordinates_from_pos( - const ScreenCoordsXY& screenCoords, int32_t flags, CoordsXY& mapCoords, int32_t* interactionType, TileElement** tileElement, - rct_viewport** viewport); -void get_map_coordinates_from_pos_window( - rct_window* window, ScreenCoordsXY screenCoords, int32_t flags, CoordsXY& mapCoords, int32_t* interactionType, - TileElement** tileElement, rct_viewport** viewport); +InteractionInfo get_map_coordinates_from_pos(const ScreenCoordsXY& screenCoords, int32_t flags); +InteractionInfo get_map_coordinates_from_pos_window(rct_window* window, const ScreenCoordsXY& screenCoords, int32_t flags); InteractionInfo set_interaction_info_from_paint_session(paint_session* session, uint16_t filter); -int32_t viewport_interaction_get_item_left(const ScreenCoordsXY& screenCoords, viewport_interaction_info* info); -int32_t viewport_interaction_left_over(const ScreenCoordsXY& screenCoords); -int32_t viewport_interaction_left_click(const ScreenCoordsXY& screenCoords); -int32_t viewport_interaction_get_item_right(const ScreenCoordsXY& screenCoords, viewport_interaction_info* info); -int32_t viewport_interaction_right_over(const ScreenCoordsXY& screenCoords); -int32_t viewport_interaction_right_click(const ScreenCoordsXY& screenCoords); +InteractionInfo viewport_interaction_get_item_left(const ScreenCoordsXY& screenCoords); +bool viewport_interaction_left_over(const ScreenCoordsXY& screenCoords); +bool viewport_interaction_left_click(const ScreenCoordsXY& screenCoords); +InteractionInfo viewport_interaction_get_item_right(const ScreenCoordsXY& screenCoords); +bool viewport_interaction_right_over(const ScreenCoordsXY& screenCoords); +bool viewport_interaction_right_click(const ScreenCoordsXY& screenCoords); CoordsXY sub_68A15E(const ScreenCoordsXY& screenCoords); void sub_68B2B7(paint_session* session, const CoordsXY& mapCoords); diff --git a/src/openrct2/paint/Paint.h b/src/openrct2/paint/Paint.h index 650442c291..02009051d7 100644 --- a/src/openrct2/paint/Paint.h +++ b/src/openrct2/paint/Paint.h @@ -15,6 +15,7 @@ #include "../world/Location.hpp" struct TileElement; +enum ViewportInteractionItem : uint8_t; #pragma pack(push, 1) /* size 0x12 */ @@ -73,8 +74,8 @@ struct paint_struct uint8_t quadrant_flags; attached_paint_struct* attached_ps; // 0x1C paint_struct* children; - paint_struct* next_quadrant_ps; // 0x24 - uint8_t sprite_type; // 0x28 + paint_struct* next_quadrant_ps; // 0x24 + ViewportInteractionItem sprite_type; // 0x28 uint8_t var_29; uint16_t pad_2A; uint16_t map_x; // 0x2C @@ -148,7 +149,7 @@ struct paint_session CoordsXY SpritePosition; paint_struct* LastRootPS; attached_paint_struct* UnkF1AD2C; - uint8_t InteractionType; + ViewportInteractionItem InteractionType; uint8_t CurrentRotation; support_height SupportSegments[9]; support_height Support; diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index c8709f0434..7685c821d2 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -6046,38 +6046,32 @@ static int32_t loc_6CD18E( */ CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(const ScreenCoordsXY& screenCoords) { - int16_t entranceMinX, entranceMinY, entranceMaxX, entranceMaxY, word_F4418C, word_F4418E; - int32_t interactionType, stationDirection; - TileElement* tileElement; - rct_viewport* viewport; - Ride* ride; CoordsXYZD entranceExitCoords{}; gRideEntranceExitPlaceDirection = INVALID_DIRECTION; - CoordsXY unusedCoords; - get_map_coordinates_from_pos(screenCoords, 0xFFFB, unusedCoords, &interactionType, &tileElement, &viewport); - if (interactionType != 0) + auto info = get_map_coordinates_from_pos(screenCoords, 0xFFFB); + if (info.SpriteType != 0) { - if (tileElement->GetType() == TILE_ELEMENT_TYPE_TRACK) + if (info.Element->GetType() == TILE_ELEMENT_TYPE_TRACK) { - if (tileElement->AsTrack()->GetRideIndex() == gRideEntranceExitPlaceRideIndex) + if (info.Element->AsTrack()->GetRideIndex() == gRideEntranceExitPlaceRideIndex) { - if (TrackSequenceProperties[tileElement->AsTrack()->GetTrackType()][0] & TRACK_SEQUENCE_FLAG_ORIGIN) + if (TrackSequenceProperties[info.Element->AsTrack()->GetTrackType()][0] & TRACK_SEQUENCE_FLAG_ORIGIN) { - if (tileElement->AsTrack()->GetTrackType() == TRACK_ELEM_MAZE) + if (info.Element->AsTrack()->GetTrackType() == TRACK_ELEM_MAZE) { gRideEntranceExitPlaceStationIndex = 0; } else { - gRideEntranceExitPlaceStationIndex = tileElement->AsTrack()->GetStationIndex(); + gRideEntranceExitPlaceStationIndex = info.Element->AsTrack()->GetStationIndex(); } } } } } - ride = get_ride(gRideEntranceExitPlaceRideIndex); + auto ride = get_ride(gRideEntranceExitPlaceRideIndex); if (ride == nullptr) { entranceExitCoords.setNull(); @@ -6093,8 +6087,8 @@ CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(const ScreenC return entranceExitCoords; } - word_F4418C = coords->x; - word_F4418E = coords->y; + auto word_F4418C = coords->x; + auto word_F4418E = coords->y; entranceExitCoords = { coords->ToTileStart(), stationBaseZ, INVALID_DIRECTION }; @@ -6130,7 +6124,7 @@ CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(const ScreenC mapY = entranceExitCoords.y + CoordsDirectionDelta[entranceExitCoords.direction].y; if (map_is_location_valid({ mapX, mapY })) { - tileElement = map_get_first_element_at({ mapX, mapY }); + auto tileElement = map_get_first_element_at({ mapX, mapY }); if (tileElement == nullptr) continue; do @@ -6170,17 +6164,19 @@ CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(const ScreenC { auto mapX = stationStart.x; auto mapY = stationStart.y; - entranceMinX = mapX; - entranceMinY = mapY; + auto entranceMinX = mapX; + auto entranceMinY = mapY; + auto entranceMaxX = mapX; + auto entranceMaxY = mapY; - tileElement = ride_get_station_start_track_element(ride, gRideEntranceExitPlaceStationIndex); + auto tileElement = ride_get_station_start_track_element(ride, gRideEntranceExitPlaceStationIndex); if (tileElement == nullptr) { entranceExitCoords.setNull(); return entranceExitCoords; } entranceExitCoords.direction = tileElement->GetDirection(); - stationDirection = entranceExitCoords.direction; + auto stationDirection = entranceExitCoords.direction; while (true) { diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index d330cb43d9..afb9ef1141 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -15,6 +15,7 @@ #include "../actions/FootpathRemoveAction.hpp" #include "../actions/LandSetRightsAction.hpp" #include "../core/Guard.hpp" +#include "../interface/Window_internal.h" #include "../localisation/Localisation.h" #include "../management/Finance.h" #include "../network/network.h" @@ -246,32 +247,28 @@ void footpath_provisional_update() */ CoordsXY footpath_get_coordinates_from_pos(const ScreenCoordsXY& screenCoords, int32_t* direction, TileElement** tileElement) { - int32_t z = 0, interactionType; - TileElement* myTileElement; - rct_viewport* viewport; - CoordsXY position = {}; - - get_map_coordinates_from_pos( - screenCoords, VIEWPORT_INTERACTION_MASK_FOOTPATH, position, &interactionType, &myTileElement, &viewport); - if (interactionType != VIEWPORT_INTERACTION_ITEM_FOOTPATH + rct_window* window = window_find_from_point(screenCoords); + auto viewport = window->viewport; + auto info = get_map_coordinates_from_pos_window(window, screenCoords, VIEWPORT_INTERACTION_MASK_FOOTPATH); + if (info.SpriteType != VIEWPORT_INTERACTION_ITEM_FOOTPATH || !(viewport->flags & (VIEWPORT_FLAG_UNDERGROUND_INSIDE | VIEWPORT_FLAG_HIDE_BASE | VIEWPORT_FLAG_HIDE_VERTICAL))) { - get_map_coordinates_from_pos( - screenCoords, VIEWPORT_INTERACTION_MASK_FOOTPATH & VIEWPORT_INTERACTION_MASK_TERRAIN, position, &interactionType, - &myTileElement, &viewport); - if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE) + info = get_map_coordinates_from_pos_window( + window, screenCoords, VIEWPORT_INTERACTION_MASK_FOOTPATH & VIEWPORT_INTERACTION_MASK_TERRAIN); + if (info.SpriteType == VIEWPORT_INTERACTION_ITEM_NONE) { + auto position = info.Loc; position.setNull(); return position; } } - auto minPosition = position; - auto maxPosition = position + CoordsXY{ 31, 31 }; - - position += CoordsXY{ 16, 16 }; - - if (interactionType == VIEWPORT_INTERACTION_ITEM_FOOTPATH) + auto minPosition = info.Loc; + auto maxPosition = info.Loc + CoordsXY{ 31, 31 }; + auto myTileElement = info.Element; + auto position = info.Loc.ToTileCentre(); + auto z = 0; + if (info.SpriteType == VIEWPORT_INTERACTION_ITEM_FOOTPATH) { z = myTileElement->GetBaseZ(); if (myTileElement->AsPath()->IsSloped()) @@ -284,7 +281,7 @@ CoordsXY footpath_get_coordinates_from_pos(const ScreenCoordsXY& screenCoords, i for (int32_t i = 0; i < 5; i++) { - if (interactionType != VIEWPORT_INTERACTION_ITEM_FOOTPATH) + if (info.SpriteType != VIEWPORT_INTERACTION_ITEM_FOOTPATH) { z = tile_element_height(position); } @@ -342,14 +339,11 @@ CoordsXY footpath_get_coordinates_from_pos(const ScreenCoordsXY& screenCoords, i CoordsXY footpath_bridge_get_info_from_pos(const ScreenCoordsXY& screenCoords, int32_t* direction, TileElement** tileElement) { // First check if we point at an entrance or exit. In that case, we would want the path coming from the entrance/exit. - int32_t interactionType; - rct_viewport* viewport; - - CoordsXY map_pos = {}; - get_map_coordinates_from_pos( - screenCoords, VIEWPORT_INTERACTION_MASK_RIDE, map_pos, &interactionType, tileElement, &viewport); - - if (interactionType == VIEWPORT_INTERACTION_ITEM_RIDE + rct_window* window = window_find_from_point(screenCoords); + auto viewport = window->viewport; + auto info = get_map_coordinates_from_pos_window(window, screenCoords, VIEWPORT_INTERACTION_MASK_RIDE); + *tileElement = info.Element; + if (info.SpriteType == VIEWPORT_INTERACTION_ITEM_RIDE && viewport->flags & (VIEWPORT_FLAG_UNDERGROUND_INSIDE | VIEWPORT_FLAG_HIDE_BASE | VIEWPORT_FLAG_HIDE_VERTICAL) && (*tileElement)->GetType() == TILE_ELEMENT_TYPE_ENTRANCE) { @@ -361,14 +355,14 @@ CoordsXY footpath_bridge_get_info_from_pos(const ScreenCoordsXY& screenCoords, i bx &= 3; if (direction != nullptr) *direction = bx; - return map_pos; + return info.Loc; } } - get_map_coordinates_from_pos( - screenCoords, VIEWPORT_INTERACTION_MASK_RIDE & VIEWPORT_INTERACTION_MASK_FOOTPATH & VIEWPORT_INTERACTION_MASK_TERRAIN, - map_pos, &interactionType, tileElement, &viewport); - if (interactionType == VIEWPORT_INTERACTION_ITEM_RIDE && (*tileElement)->GetType() == TILE_ELEMENT_TYPE_ENTRANCE) + info = get_map_coordinates_from_pos_window( + window, screenCoords, + VIEWPORT_INTERACTION_MASK_RIDE & VIEWPORT_INTERACTION_MASK_FOOTPATH & VIEWPORT_INTERACTION_MASK_TERRAIN); + if (info.SpriteType == VIEWPORT_INTERACTION_ITEM_RIDE && (*tileElement)->GetType() == TILE_ELEMENT_TYPE_ENTRANCE) { int32_t directions = entrance_get_directions(*tileElement); if (directions & 0x0F) @@ -376,7 +370,7 @@ CoordsXY footpath_bridge_get_info_from_pos(const ScreenCoordsXY& screenCoords, i int32_t bx = (*tileElement)->GetDirectionWithOffset(bitscanforward(directions)); if (direction != nullptr) *direction = bx; - return map_pos; + return info.Loc; } }