From 38cf4728ef8bd5920a86ff2a9872c08aa3657e7c Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 21 Dec 2019 10:04:00 -0300 Subject: [PATCH] Make Map::map_get_nth_element_at() use CoordsXY (#10411) --- src/openrct2/world/Map.cpp | 5 ++-- src/openrct2/world/Map.h | 2 +- src/openrct2/world/TileInspector.cpp | 38 ++++++++++++++-------------- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 6452fa425f..86728343e0 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -164,9 +164,10 @@ TileElement* map_get_first_element_at(int32_t x, int32_t y) return gTileElementTilePointers[x + y * MAXIMUM_MAP_SIZE_TECHNICAL]; } -TileElement* map_get_nth_element_at(int32_t x, int32_t y, int32_t n) +TileElement* map_get_nth_element_at(const CoordsXY& coords, int32_t n) { - TileElement* tileElement = map_get_first_element_at(x, y); + auto tileCoords = TileCoordsXY{ coords }; + TileElement* tileElement = map_get_first_element_at(tileCoords.x, tileCoords.y); if (tileElement == nullptr) { return nullptr; diff --git a/src/openrct2/world/Map.h b/src/openrct2/world/Map.h index ece6b008e9..7db619f8f0 100644 --- a/src/openrct2/world/Map.h +++ b/src/openrct2/world/Map.h @@ -137,7 +137,7 @@ void map_count_remaining_land_rights(); void map_strip_ghost_flag_from_elements(); void map_update_tile_pointers(); TileElement* map_get_first_element_at(int32_t x, int32_t y); -TileElement* map_get_nth_element_at(int32_t x, int32_t y, int32_t n); +TileElement* map_get_nth_element_at(const CoordsXY& coords, int32_t n); void map_set_tile_elements(int32_t x, int32_t y, TileElement* elements); int32_t map_height_from_slope(const CoordsXY& coords, int32_t slope, bool isSloped); BannerElement* map_get_banner_element_at(int32_t x, int32_t y, int32_t z, uint8_t direction); diff --git a/src/openrct2/world/TileInspector.cpp b/src/openrct2/world/TileInspector.cpp index 508f32c8b6..d5a0b491ce 100644 --- a/src/openrct2/world/TileInspector.cpp +++ b/src/openrct2/world/TileInspector.cpp @@ -38,8 +38,8 @@ int32_t windowTileInspectorSelectedIndex; static bool map_swap_elements_at(CoordsXY loc, int16_t first, int16_t second) { - TileElement* const firstElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, first); - TileElement* const secondElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, second); + TileElement* const firstElement = map_get_nth_element_at(loc, first); + TileElement* const secondElement = map_get_nth_element_at(loc, second); if (firstElement == nullptr) { @@ -98,7 +98,7 @@ GameActionResult::Ptr tile_inspector_insert_corrupt_at(CoordsXY loc, int16_t ele corruptElement->SetType(TILE_ELEMENT_TYPE_CORRUPT); // Set the base height to be the same as the selected element - TileElement* const selectedElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex + 1); + TileElement* const selectedElement = map_get_nth_element_at(loc, elementIndex + 1); if (selectedElement == nullptr) { return std::make_unique(GA_ERROR::UNKNOWN, STR_NONE); @@ -152,7 +152,7 @@ GameActionResult::Ptr tile_inspector_remove_element_at(CoordsXY loc, int16_t ele if (isExecuting) { // Forcefully remove the element - TileElement* const tileElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex); + TileElement* const tileElement = map_get_nth_element_at(loc, elementIndex); if (tileElement == nullptr) { return std::make_unique(GA_ERROR::UNKNOWN, STR_NONE); @@ -217,7 +217,7 @@ GameActionResult::Ptr tile_inspector_rotate_element_at(CoordsXY loc, int32_t ele { uint8_t newRotation, pathEdges, pathCorners; - TileElement* const tileElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex); + TileElement* const tileElement = map_get_nth_element_at(loc, elementIndex); if (tileElement == nullptr) { return std::make_unique(GA_ERROR::UNKNOWN, STR_NONE); @@ -412,7 +412,7 @@ GameActionResult::Ptr tile_inspector_sort_elements_at(CoordsXY loc, bool isExecu GameActionResult::Ptr tile_inspector_any_base_height_offset( CoordsXY loc, int16_t elementIndex, int8_t heightOffset, bool isExecuting) { - TileElement* const tileElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex); + TileElement* const tileElement = map_get_nth_element_at(loc, elementIndex); if (tileElement == nullptr) return std::make_unique(GA_ERROR::UNKNOWN, STR_NONE); @@ -602,7 +602,7 @@ GameActionResult::Ptr tile_inspector_surface_toggle_diagonal(CoordsXY loc, bool GameActionResult::Ptr tile_inspector_path_set_sloped(CoordsXY loc, int32_t elementIndex, bool sloped, bool isExecuting) { - TileElement* const pathElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex); + TileElement* const pathElement = map_get_nth_element_at(loc, elementIndex); if (pathElement == nullptr || pathElement->GetType() != TILE_ELEMENT_TYPE_PATH) return std::make_unique(GA_ERROR::UNKNOWN, STR_NONE); @@ -626,7 +626,7 @@ GameActionResult::Ptr tile_inspector_path_set_sloped(CoordsXY loc, int32_t eleme GameActionResult::Ptr tile_inspector_path_set_broken(CoordsXY loc, int32_t elementIndex, bool broken, bool isExecuting) { - TileElement* const pathElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex); + TileElement* const pathElement = map_get_nth_element_at(loc, elementIndex); if (pathElement == nullptr || pathElement->GetType() != TILE_ELEMENT_TYPE_PATH) return std::make_unique(GA_ERROR::UNKNOWN, STR_NONE); @@ -650,7 +650,7 @@ GameActionResult::Ptr tile_inspector_path_set_broken(CoordsXY loc, int32_t eleme GameActionResult::Ptr tile_inspector_path_toggle_edge(CoordsXY loc, int32_t elementIndex, int32_t edgeIndex, bool isExecuting) { - TileElement* const pathElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex); + TileElement* const pathElement = map_get_nth_element_at(loc, elementIndex); if (pathElement == nullptr || pathElement->GetType() != TILE_ELEMENT_TYPE_PATH) return std::make_unique(GA_ERROR::UNKNOWN, STR_NONE); @@ -675,7 +675,7 @@ GameActionResult::Ptr tile_inspector_path_toggle_edge(CoordsXY loc, int32_t elem GameActionResult::Ptr tile_inspector_entrance_make_usable(CoordsXY loc, int32_t elementIndex, bool isExecuting) { - TileElement* const entranceElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex); + TileElement* const entranceElement = map_get_nth_element_at(loc, elementIndex); if (entranceElement == nullptr || entranceElement->GetType() != TILE_ELEMENT_TYPE_ENTRANCE) return std::make_unique(GA_ERROR::UNKNOWN, STR_NONE); @@ -715,7 +715,7 @@ GameActionResult::Ptr tile_inspector_entrance_make_usable(CoordsXY loc, int32_t GameActionResult::Ptr tile_inspector_wall_set_slope(CoordsXY loc, int32_t elementIndex, int32_t slopeValue, bool isExecuting) { - TileElement* const wallElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex); + TileElement* const wallElement = map_get_nth_element_at(loc, elementIndex); if (wallElement == nullptr || wallElement->GetType() != TILE_ELEMENT_TYPE_WALL) return std::make_unique(GA_ERROR::UNKNOWN, STR_NONE); @@ -746,7 +746,7 @@ GameActionResult::Ptr tile_inspector_track_base_height_offset( if (offset == 0) return std::make_unique(); - TileElement* const trackElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex); + TileElement* const trackElement = map_get_nth_element_at(loc, elementIndex); if (trackElement == nullptr || trackElement->GetType() != TILE_ELEMENT_TYPE_TRACK) return std::make_unique(GA_ERROR::UNKNOWN, STR_NONE); @@ -842,7 +842,7 @@ GameActionResult::Ptr tile_inspector_track_base_height_offset( GameActionResult::Ptr tile_inspector_track_set_chain( CoordsXY loc, int32_t elementIndex, bool entireTrackBlock, bool setChain, bool isExecuting) { - TileElement* const trackElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex); + TileElement* const trackElement = map_get_nth_element_at(loc, elementIndex); if (trackElement == nullptr || trackElement->GetType() != TILE_ELEMENT_TYPE_TRACK) return std::make_unique(GA_ERROR::UNKNOWN, STR_NONE); @@ -949,7 +949,7 @@ GameActionResult::Ptr tile_inspector_track_set_chain( GameActionResult::Ptr tile_inspector_track_set_block_brake( CoordsXY loc, int32_t elementIndex, bool blockBrake, bool isExecuting) { - TileElement* const trackElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex); + TileElement* const trackElement = map_get_nth_element_at(loc, elementIndex); if (trackElement == nullptr || trackElement->GetType() != TILE_ELEMENT_TYPE_TRACK) return std::make_unique(GA_ERROR::UNKNOWN, STR_NONE); @@ -974,7 +974,7 @@ GameActionResult::Ptr tile_inspector_track_set_block_brake( GameActionResult::Ptr tile_inspector_track_set_indestructible( CoordsXY loc, int32_t elementIndex, bool isIndestructible, bool isExecuting) { - TileElement* const trackElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex); + TileElement* const trackElement = map_get_nth_element_at(loc, elementIndex); if (trackElement == nullptr || trackElement->GetType() != TILE_ELEMENT_TYPE_TRACK) return std::make_unique(GA_ERROR::UNKNOWN, STR_NONE); @@ -999,7 +999,7 @@ GameActionResult::Ptr tile_inspector_track_set_indestructible( GameActionResult::Ptr tile_inspector_scenery_set_quarter_location( CoordsXY loc, int32_t elementIndex, int32_t quarterIndex, bool isExecuting) { - TileElement* const tileElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex); + TileElement* const tileElement = map_get_nth_element_at(loc, elementIndex); if (tileElement == nullptr || tileElement->GetType() != TILE_ELEMENT_TYPE_SMALL_SCENERY) return std::make_unique(GA_ERROR::UNKNOWN, STR_NONE); @@ -1025,7 +1025,7 @@ GameActionResult::Ptr tile_inspector_scenery_set_quarter_location( GameActionResult::Ptr tile_inspector_scenery_set_quarter_collision( CoordsXY loc, int32_t elementIndex, int32_t quarterIndex, bool isExecuting) { - TileElement* const tileElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex); + TileElement* const tileElement = map_get_nth_element_at(loc, elementIndex); if (tileElement == nullptr || tileElement->GetType() != TILE_ELEMENT_TYPE_SMALL_SCENERY) return std::make_unique(GA_ERROR::UNKNOWN, STR_NONE); @@ -1049,7 +1049,7 @@ GameActionResult::Ptr tile_inspector_scenery_set_quarter_collision( GameActionResult::Ptr tile_inspector_banner_toggle_blocking_edge( CoordsXY loc, int32_t elementIndex, int32_t edgeIndex, bool isExecuting) { - TileElement* const bannerElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex); + TileElement* const bannerElement = map_get_nth_element_at(loc, elementIndex); if (bannerElement == nullptr || bannerElement->GetType() != TILE_ELEMENT_TYPE_BANNER) return std::make_unique(GA_ERROR::UNKNOWN, STR_NONE); @@ -1071,7 +1071,7 @@ GameActionResult::Ptr tile_inspector_banner_toggle_blocking_edge( GameActionResult::Ptr tile_inspector_corrupt_clamp(CoordsXY loc, int32_t elementIndex, bool isExecuting) { - TileElement* const corruptElement = map_get_nth_element_at(loc.x / 32, loc.y / 32, elementIndex); + TileElement* const corruptElement = map_get_nth_element_at(loc, elementIndex); if (corruptElement == nullptr || corruptElement->GetType() != TILE_ELEMENT_TYPE_CORRUPT) return std::make_unique(GA_ERROR::UNKNOWN, STR_NONE);