From 201d13577e5bb039806db060912976a1e614d4be Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sun, 12 Jan 2020 22:20:29 -0300 Subject: [PATCH] Use CoordsXY for footpath_get_coordinates_from_pos() --- src/openrct2-ui/windows/Guest.cpp | 18 ++++++-------- src/openrct2-ui/windows/Map.cpp | 8 +++--- src/openrct2-ui/windows/Staff.cpp | 36 +++++++++++---------------- src/openrct2-ui/windows/StaffList.cpp | 3 +-- src/openrct2/world/Footpath.cpp | 18 ++++++-------- src/openrct2/world/Footpath.h | 3 +-- 6 files changed, 36 insertions(+), 50 deletions(-) diff --git a/src/openrct2-ui/windows/Guest.cpp b/src/openrct2-ui/windows/Guest.cpp index a0ff3b520f..034539f9b9 100644 --- a/src/openrct2-ui/windows/Guest.cpp +++ b/src/openrct2-ui/windows/Guest.cpp @@ -1230,16 +1230,13 @@ void window_guest_overview_tool_update(rct_window* w, rct_widgetindex widgetInde gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE; - int32_t map_x, map_y; - footpath_get_coordinates_from_pos({ screenCoords.x, screenCoords.y + 16 }, &map_x, &map_y, nullptr, nullptr); - if (map_x != LOCATION_NULL) + auto mapCoords = footpath_get_coordinates_from_pos({ screenCoords.x, screenCoords.y + 16 }, nullptr, nullptr); + if (!mapCoords.isNull()) { gMapSelectFlags |= MAP_SELECT_FLAG_ENABLE; gMapSelectType = MAP_SELECT_TYPE_FULL; - gMapSelectPositionA.x = map_x; - gMapSelectPositionB.x = map_x; - gMapSelectPositionA.y = map_y; - gMapSelectPositionB.y = map_y; + gMapSelectPositionA = mapCoords; + gMapSelectPositionB = mapCoords; map_invalidate_selection_rect(); } @@ -1281,15 +1278,14 @@ void window_guest_overview_tool_down(rct_window* w, rct_widgetindex widgetIndex, if (widgetIndex != WIDX_PICKUP) return; - int32_t dest_x, dest_y; TileElement* tileElement; - footpath_get_coordinates_from_pos({ screenCoords.x, screenCoords.y + 16 }, &dest_x, &dest_y, nullptr, &tileElement); + auto destCoords = footpath_get_coordinates_from_pos({ screenCoords.x, screenCoords.y + 16 }, nullptr, &tileElement); - if (dest_x == LOCATION_NULL) + if (destCoords.isNull()) return; PeepPickupAction pickupAction{ - PeepPickupType::Place, w->number, { dest_x, dest_y, tileElement->base_height }, network_get_current_player_id() + PeepPickupType::Place, w->number, { destCoords, tileElement->base_height }, network_get_current_player_id() }; pickupAction.SetCallback([](const GameAction* ga, const GameActionResult* result) { if (result->Error != GA_ERROR::OK) diff --git a/src/openrct2-ui/windows/Map.cpp b/src/openrct2-ui/windows/Map.cpp index bc49f74bdb..f445fc3c75 100644 --- a/src/openrct2-ui/windows/Map.cpp +++ b/src/openrct2-ui/windows/Map.cpp @@ -1327,16 +1327,16 @@ static void window_map_place_park_entrance_tool_down(ScreenCoordsXY screenCoords static void window_map_set_peep_spawn_tool_down(ScreenCoordsXY screenCoords) { TileElement* tileElement; - int32_t mapX, mapY, mapZ, direction; + int32_t mapZ, direction; // Verify footpath exists at location, and retrieve coordinates - footpath_get_coordinates_from_pos(screenCoords, &mapX, &mapY, &direction, &tileElement); - if (mapX == LOCATION_NULL) + auto mapCoords = footpath_get_coordinates_from_pos(screenCoords, &direction, &tileElement); + if (mapCoords.isNull()) return; mapZ = tileElement->GetBaseZ(); - auto gameAction = PlacePeepSpawnAction({ mapX, mapY, mapZ, static_cast(direction) }); + auto gameAction = PlacePeepSpawnAction({ mapCoords, mapZ, static_cast(direction) }); auto result = GameActions::Execute(&gameAction); if (result->Error == GA_ERROR::OK) { diff --git a/src/openrct2-ui/windows/Staff.cpp b/src/openrct2-ui/windows/Staff.cpp index 2ef09a4b68..4974dab08b 100644 --- a/src/openrct2-ui/windows/Staff.cpp +++ b/src/openrct2-ui/windows/Staff.cpp @@ -1146,16 +1146,13 @@ void window_staff_overview_tool_update(rct_window* w, rct_widgetindex widgetInde gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE; - int32_t map_x, map_y; - footpath_get_coordinates_from_pos({ screenCoords.x, screenCoords.y + 16 }, &map_x, &map_y, nullptr, nullptr); - if (map_x != LOCATION_NULL) + auto mapCoords = footpath_get_coordinates_from_pos({ screenCoords.x, screenCoords.y + 16 }, nullptr, nullptr); + if (!mapCoords.isNull()) { gMapSelectFlags |= MAP_SELECT_FLAG_ENABLE; gMapSelectType = MAP_SELECT_TYPE_FULL; - gMapSelectPositionA.x = map_x; - gMapSelectPositionB.x = map_x; - gMapSelectPositionA.y = map_y; - gMapSelectPositionB.y = map_y; + gMapSelectPositionA = mapCoords; + gMapSelectPositionB = mapCoords; map_invalidate_selection_rect(); } @@ -1196,15 +1193,14 @@ void window_staff_overview_tool_down(rct_window* w, rct_widgetindex widgetIndex, { if (widgetIndex == WIDX_PICKUP) { - int32_t dest_x, dest_y; TileElement* tileElement; - footpath_get_coordinates_from_pos({ screenCoords.x, screenCoords.y + 16 }, &dest_x, &dest_y, nullptr, &tileElement); + auto destCoords = footpath_get_coordinates_from_pos({ screenCoords.x, screenCoords.y + 16 }, nullptr, &tileElement); - if (dest_x == LOCATION_NULL) + if (destCoords.isNull()) return; PeepPickupAction pickupAction{ - PeepPickupType::Place, w->number, { dest_x, dest_y, tileElement->base_height }, network_get_current_player_id() + PeepPickupType::Place, w->number, { destCoords, tileElement->base_height }, network_get_current_player_id() }; pickupAction.SetCallback([](const GameAction* ga, const GameActionResult* result) { if (result->Error != GA_ERROR::OK) @@ -1216,10 +1212,9 @@ void window_staff_overview_tool_down(rct_window* w, rct_widgetindex widgetIndex, } else if (widgetIndex == WIDX_PATROL) { - int32_t dest_x, dest_y; - footpath_get_coordinates_from_pos(screenCoords, &dest_x, &dest_y, nullptr, nullptr); + auto destCoords = footpath_get_coordinates_from_pos(screenCoords, nullptr, nullptr); - if (dest_x == LOCATION_NULL) + if (destCoords.isNull()) return; rct_sprite* sprite = try_get_sprite(w->number); @@ -1231,7 +1226,7 @@ void window_staff_overview_tool_down(rct_window* w, rct_widgetindex widgetIndex, return; auto staff = peep.AsStaff(); - if (staff->IsPatrolAreaSet({ dest_x, dest_y })) + if (staff->IsPatrolAreaSet(destCoords)) { _staffPatrolAreaPaintValue = PatrolAreaValue::UNSET; } @@ -1239,7 +1234,7 @@ void window_staff_overview_tool_down(rct_window* w, rct_widgetindex widgetIndex, { _staffPatrolAreaPaintValue = PatrolAreaValue::SET; } - auto staffSetPatrolAreaAction = StaffSetPatrolAreaAction(w->number, { dest_x, dest_y }); + auto staffSetPatrolAreaAction = StaffSetPatrolAreaAction(w->number, destCoords); GameActions::Execute(&staffSetPatrolAreaAction); } } @@ -1258,10 +1253,9 @@ void window_staff_overview_tool_drag(rct_window* w, rct_widgetindex widgetIndex, if (_staffPatrolAreaPaintValue == PatrolAreaValue::NONE) return; // Do nothing if we do not have a paintvalue(this should never happen) - int32_t dest_x, dest_y; - footpath_get_coordinates_from_pos(screenCoords, &dest_x, &dest_y, nullptr, nullptr); + auto destCoords = footpath_get_coordinates_from_pos(screenCoords, nullptr, nullptr); - if (dest_x == LOCATION_NULL) + if (destCoords.isNull()) return; rct_sprite* sprite = try_get_sprite(w->number); @@ -1272,13 +1266,13 @@ void window_staff_overview_tool_drag(rct_window* w, rct_widgetindex widgetIndex, if (peep.type != PEEP_TYPE_STAFF) return; - bool patrolAreaValue = peep.AsStaff()->IsPatrolAreaSet({ dest_x, dest_y }); + bool patrolAreaValue = peep.AsStaff()->IsPatrolAreaSet(destCoords); if (_staffPatrolAreaPaintValue == PatrolAreaValue::SET && patrolAreaValue) return; // Since area is already the value we want, skip... if (_staffPatrolAreaPaintValue == PatrolAreaValue::UNSET && !patrolAreaValue) return; // Since area is already the value we want, skip... - auto staffSetPatrolAreaAction = StaffSetPatrolAreaAction(w->number, { dest_x, dest_y }); + auto staffSetPatrolAreaAction = StaffSetPatrolAreaAction(w->number, destCoords); GameActions::Execute(&staffSetPatrolAreaAction); } diff --git a/src/openrct2-ui/windows/StaffList.cpp b/src/openrct2-ui/windows/StaffList.cpp index dd17572877..49ef4c1054 100644 --- a/src/openrct2-ui/windows/StaffList.cpp +++ b/src/openrct2-ui/windows/StaffList.cpp @@ -342,8 +342,7 @@ static void window_staff_list_tooldown(rct_window* w, rct_widgetindex widgetInde int32_t direction; TileElement* tileElement; - CoordsXY footpathCoords; - footpath_get_coordinates_from_pos(screenCoords, &footpathCoords.x, &footpathCoords.y, &direction, &tileElement); + auto footpathCoords = footpath_get_coordinates_from_pos(screenCoords, &direction, &tileElement); if (footpathCoords.isNull()) return; diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index e312ba1f2f..35d3f2fbad 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -244,8 +244,7 @@ void footpath_provisional_update() * direction: ecx * tileElement: edx */ -void footpath_get_coordinates_from_pos( - ScreenCoordsXY screenCoords, int32_t* x, int32_t* y, int32_t* direction, TileElement** tileElement) +CoordsXY footpath_get_coordinates_from_pos(ScreenCoordsXY screenCoords, int32_t* direction, TileElement** tileElement) { int32_t z = 0, interactionType; TileElement* myTileElement; @@ -262,9 +261,8 @@ void footpath_get_coordinates_from_pos( &myTileElement, &viewport); if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE) { - if (x != nullptr) - *x = LOCATION_NULL; - return; + position.setNull(); + return position; } } @@ -323,14 +321,12 @@ void footpath_get_coordinates_from_pos( position = position.ToTileStart(); - if (x != nullptr) - *x = position.x; - if (y != nullptr) - *y = position.y; if (direction != nullptr) *direction = myDirection; if (tileElement != nullptr) *tileElement = myTileElement; + + return position; } /** @@ -390,7 +386,9 @@ void footpath_bridge_get_info_from_pos( } // We point at something else - footpath_get_coordinates_from_pos(screenCoords, x, y, direction, tileElement); + auto coords = footpath_get_coordinates_from_pos(screenCoords, direction, tileElement); + *x = coords.x; + *y = coords.y; } /** diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index 1a2d213261..b73f0383f7 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -183,8 +183,7 @@ money32 footpath_remove(CoordsXYZ footpathLoc, int32_t flags); money32 footpath_provisional_set(int32_t type, CoordsXYZ footpathLoc, int32_t slope); void footpath_provisional_remove(); void footpath_provisional_update(); -void footpath_get_coordinates_from_pos( - ScreenCoordsXY screenCoords, int32_t* x, int32_t* y, int32_t* direction, TileElement** tileElement); +CoordsXY footpath_get_coordinates_from_pos(ScreenCoordsXY screenCoords, int32_t* direction, TileElement** tileElement); void footpath_bridge_get_info_from_pos( ScreenCoordsXY screenCoords, int32_t* x, int32_t* y, int32_t* direction, TileElement** tileElement); void footpath_remove_litter(const CoordsXYZ& footpathPos);