From b6138357569013bd2d997e1508a1f8ed7d674cf8 Mon Sep 17 00:00:00 2001 From: Matt Date: Fri, 19 Feb 2021 18:39:08 +0200 Subject: [PATCH] Remove more duplicate code --- src/openrct2/world/TileInspector.cpp | 74 ++++------------------------ 1 file changed, 10 insertions(+), 64 deletions(-) diff --git a/src/openrct2/world/TileInspector.cpp b/src/openrct2/world/TileInspector.cpp index 08b73ecd8e..5d92db1514 100644 --- a/src/openrct2/world/TileInspector.cpp +++ b/src/openrct2/world/TileInspector.cpp @@ -820,42 +820,13 @@ namespace OpenRCT2::TileInspector trackBlock = TrackBlocks[type]; for (; trackBlock->index != 255; trackBlock++) { - CoordsXY elem = { originX, originY }; - int16_t elemZ = originZ; + CoordsXYZD elem = { originX, originY, originZ + trackBlock->z, rotation }; offsets.x = trackBlock->x; offsets.y = trackBlock->y; elem += offsets.Rotate(originDirection); - elemZ += trackBlock->z; - map_invalidate_tile_full(elem); - - bool found = false; - TileElement* tileElement = map_get_first_element_at({ elem.x, elem.y }); - do - { - if (tileElement == nullptr) - break; - - if (tileElement->GetBaseZ() != elemZ) - continue; - - if (tileElement->GetType() != TILE_ELEMENT_TYPE_TRACK) - continue; - - if (tileElement->GetDirection() != rotation) - continue; - - if (tileElement->AsTrack()->GetSequenceIndex() != trackBlock->index) - continue; - - if (tileElement->AsTrack()->GetTrackType() != type) - continue; - - found = true; - break; - } while (!(tileElement++)->IsLastForTile()); - - if (!found) + TrackElement* tileElement = map_get_track_element_at_of_type_seq(elem, type, trackBlock->index); + if (tileElement == nullptr) { log_error("Track map element part not found!"); return std::make_unique(GameActions::Status::Unknown, STR_NONE); @@ -865,6 +836,8 @@ namespace OpenRCT2::TileInspector // for when you decrease the map size. openrct2_assert(map_get_surface_element_at(elem) != nullptr, "No surface at %d,%d", elem.x >> 5, elem.y >> 5); + map_invalidate_tile_full(elem); + // Keep? // invalidate_test_results(ride); @@ -927,42 +900,13 @@ namespace OpenRCT2::TileInspector trackBlock = TrackBlocks[type]; for (; trackBlock->index != 255; trackBlock++) { - CoordsXY elem = { originX, originY }; - int16_t elemZ = originZ; + CoordsXYZD elem = { originX, originY, originZ + trackBlock->z, rotation }; offsets.x = trackBlock->x; offsets.y = trackBlock->y; elem += offsets.Rotate(originDirection); - elemZ += trackBlock->z; - map_invalidate_tile_full(elem); - - bool found = false; - TileElement* tileElement = map_get_first_element_at({ elem.x, elem.y }); - do - { - if (tileElement == nullptr) - break; - - if (tileElement->GetBaseZ() != elemZ) - continue; - - if (tileElement->GetType() != TILE_ELEMENT_TYPE_TRACK) - continue; - - if (tileElement->GetDirection() != rotation) - continue; - - if (tileElement->AsTrack()->GetSequenceIndex() != trackBlock->index) - continue; - - if (tileElement->AsTrack()->GetTrackType() != type) - continue; - - found = true; - break; - } while (!(tileElement++)->IsLastForTile()); - - if (!found) + TrackElement* tileElement = map_get_track_element_at_of_type_seq(elem, type, trackBlock->index); + if (tileElement == nullptr) { log_error("Track map element part not found!"); return std::make_unique(GameActions::Status::Unknown, STR_NONE); @@ -972,6 +916,8 @@ namespace OpenRCT2::TileInspector // for when you decrease the map size. openrct2_assert(map_get_surface_element_at(elem) != nullptr, "No surface at %d,%d", elem.x >> 5, elem.y >> 5); + map_invalidate_tile_full(elem); + // Keep? // invalidate_test_results(ride);