From accb4ea691a33057985f99ac790e84625f65f6e8 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Wed, 4 Dec 2019 08:39:33 -0300 Subject: [PATCH 1/3] Use CoordsXY on TopToolbar and TrackDesignPlace rotations --- src/openrct2-ui/windows/TopToolbar.cpp | 11 ++- src/openrct2-ui/windows/TrackDesignPlace.cpp | 74 ++++++++++---------- src/openrct2/ride/Ride.cpp | 5 +- src/openrct2/ride/TrackDesign.cpp | 15 ++-- src/openrct2/world/Map.cpp | 10 +-- src/openrct2/world/Map.h | 2 +- 6 files changed, 55 insertions(+), 62 deletions(-) diff --git a/src/openrct2-ui/windows/TopToolbar.cpp b/src/openrct2-ui/windows/TopToolbar.cpp index 0604afaf3a..550c7b4cab 100644 --- a/src/openrct2-ui/windows/TopToolbar.cpp +++ b/src/openrct2-ui/windows/TopToolbar.cpp @@ -2832,14 +2832,13 @@ static void top_toolbar_tool_update_scenery(int16_t x, int16_t y) for (rct_large_scenery_tile* tile = scenery->large_scenery.tiles; tile->x_offset != (int16_t)(uint16_t)0xFFFF; tile++) { - LocationXY16 tileLocation = { tile->x_offset, tile->y_offset }; + CoordsXY tileLocation = { tile->x_offset, tile->y_offset }; + auto rotatedTileCoords = tileLocation.Rotate((parameter1 >> 8) & 0xFF); - rotate_map_coordinates(&tileLocation.x, &tileLocation.y, (parameter1 >> 8) & 0xFF); + rotatedTileCoords.x += mapTile.x; + rotatedTileCoords.y += mapTile.y; - tileLocation.x += mapTile.x; - tileLocation.y += mapTile.y; - - gMapSelectionTiles.push_back({ tileLocation.x, tileLocation.y }); + gMapSelectionTiles.push_back(rotatedTileCoords); } gMapSelectFlags |= MAP_SELECT_FLAG_ENABLE_CONSTRUCT; diff --git a/src/openrct2-ui/windows/TrackDesignPlace.cpp b/src/openrct2-ui/windows/TrackDesignPlace.cpp index 5c62835ee6..770b309c98 100644 --- a/src/openrct2-ui/windows/TrackDesignPlace.cpp +++ b/src/openrct2-ui/windows/TrackDesignPlace.cpp @@ -125,9 +125,9 @@ static void window_track_place_attempt_placement( static void window_track_place_clear_mini_preview(); static void window_track_place_draw_mini_preview(TrackDesign* td6); static void window_track_place_draw_mini_preview_track( - TrackDesign* td6, int32_t pass, LocationXY16 origin, LocationXY16* min, LocationXY16* max); + TrackDesign* td6, int32_t pass, CoordsXY origin, CoordsXY& min, CoordsXY& max); static void window_track_place_draw_mini_preview_maze( - TrackDesign* td6, int32_t pass, LocationXY16 origin, LocationXY16* min, LocationXY16* max); + TrackDesign* td6, int32_t pass, CoordsXY origin, CoordsXY& min, CoordsXY& max); static LocationXY16 draw_mini_preview_get_pixel_position(int16_t x, int16_t y); static bool draw_mini_preview_is_pixel_in_bounds(LocationXY16 pixel); static uint8_t* draw_mini_preview_get_pixel_ptr(LocationXY16 pixel); @@ -502,11 +502,11 @@ static void window_track_place_draw_mini_preview(TrackDesign* td6) window_track_place_clear_mini_preview(); // First pass is used to determine the width and height of the image so it can centre it - LocationXY16 min = { 0, 0 }; - LocationXY16 max = { 0, 0 }; + CoordsXY min = { 0, 0 }; + CoordsXY max = { 0, 0 }; for (int32_t pass = 0; pass < 2; pass++) { - LocationXY16 origin = { 0, 0 }; + CoordsXY origin = { 0, 0 }; if (pass == 1) { origin.x -= ((max.x + min.x) >> 6) * 32; @@ -515,17 +515,17 @@ static void window_track_place_draw_mini_preview(TrackDesign* td6) if (td6->type == RIDE_TYPE_MAZE) { - window_track_place_draw_mini_preview_maze(td6, pass, origin, &min, &max); + window_track_place_draw_mini_preview_maze(td6, pass, origin, min, max); } else { - window_track_place_draw_mini_preview_track(td6, pass, origin, &min, &max); + window_track_place_draw_mini_preview_track(td6, pass, origin, min, max); } } } static void window_track_place_draw_mini_preview_track( - TrackDesign* td6, int32_t pass, LocationXY16 origin, LocationXY16* min, LocationXY16* max) + TrackDesign* td6, int32_t pass, CoordsXY origin, CoordsXY& min, CoordsXY& max) { uint8_t rotation = (_currentTrackPieceDirection + get_current_rotation()) & 3; @@ -543,20 +543,20 @@ static void window_track_place_draw_mini_preview_track( const rct_preview_track* trackBlock = trackBlockArray[trackType]; while (trackBlock->index != 255) { - int16_t x = origin.x; - int16_t y = origin.y; - map_offset_with_rotation(&x, &y, trackBlock->x, trackBlock->y, rotation); + auto rotatedAndOffsetTrackBlock = map_offset_with_rotation( + { origin.x, origin.y }, { trackBlock->x, trackBlock->y }, rotation); if (pass == 0) { - min->x = std::min(min->x, x); - max->x = std::max(max->x, x); - min->y = std::min(min->y, y); - max->y = std::max(max->y, y); + min.x = std::min(min.x, rotatedAndOffsetTrackBlock.x); + max.x = std::max(max.x, rotatedAndOffsetTrackBlock.x); + min.y = std::min(min.y, rotatedAndOffsetTrackBlock.y); + max.y = std::max(max.y, rotatedAndOffsetTrackBlock.y); } else { - LocationXY16 pixelPosition = draw_mini_preview_get_pixel_position(x, y); + LocationXY16 pixelPosition = draw_mini_preview_get_pixel_position( + rotatedAndOffsetTrackBlock.x, rotatedAndOffsetTrackBlock.y); if (draw_mini_preview_is_pixel_in_bounds(pixelPosition)) { uint8_t* pixel = draw_mini_preview_get_pixel_ptr(pixelPosition); @@ -589,7 +589,8 @@ static void window_track_place_draw_mini_preview_track( const rct_track_coordinates* track_coordinate = &TrackCoordinates[trackType]; trackType *= 10; - map_offset_with_rotation(&origin.x, &origin.y, track_coordinate->x, track_coordinate->y, rotation); + auto rotatedAndOfffsetTrack = map_offset_with_rotation( + { origin.x, origin.y }, { track_coordinate->x, track_coordinate->y }, rotation); rotation += track_coordinate->rotation_end - track_coordinate->rotation_begin; rotation &= 3; if (track_coordinate->rotation_end & 4) @@ -598,28 +599,27 @@ static void window_track_place_draw_mini_preview_track( } if (!(rotation & 4)) { - origin.x += CoordsDirectionDelta[rotation].x; - origin.y += CoordsDirectionDelta[rotation].y; + origin.x = rotatedAndOfffsetTrack.x + CoordsDirectionDelta[rotation].x; + origin.y = rotatedAndOfffsetTrack.x + CoordsDirectionDelta[rotation].y; } } // Draw entrance and exit preview. for (const auto& entrance : td6->entrance_elements) { - int16_t x = origin.x; - int16_t y = origin.y; - map_offset_with_rotation(&x, &y, entrance.x, entrance.y, rotation); + auto rotatedAndOffsetEntrance = map_offset_with_rotation({ origin.x, origin.y }, { entrance.x, entrance.y }, rotation); if (pass == 0) { - min->x = std::min(min->x, x); - max->x = std::max(max->x, x); - min->y = std::min(min->y, y); - max->y = std::max(max->y, y); + min.x = std::min(min.x, rotatedAndOffsetEntrance.x); + max.x = std::max(max.x, rotatedAndOffsetEntrance.x); + min.y = std::min(min.y, rotatedAndOffsetEntrance.y); + max.y = std::max(max.y, rotatedAndOffsetEntrance.y); } else { - LocationXY16 pixelPosition = draw_mini_preview_get_pixel_position(x, y); + LocationXY16 pixelPosition = draw_mini_preview_get_pixel_position( + rotatedAndOffsetEntrance.x, rotatedAndOffsetEntrance.y); if (draw_mini_preview_is_pixel_in_bounds(pixelPosition)) { uint8_t* pixel = draw_mini_preview_get_pixel_ptr(pixelPosition); @@ -637,28 +637,26 @@ static void window_track_place_draw_mini_preview_track( } static void window_track_place_draw_mini_preview_maze( - TrackDesign* td6, int32_t pass, LocationXY16 origin, LocationXY16* min, LocationXY16* max) + TrackDesign* td6, int32_t pass, CoordsXY origin, CoordsXY& min, CoordsXY& max) { uint8_t rotation = (_currentTrackPieceDirection + get_current_rotation()) & 3; for (const auto& mazeElement : td6->maze_elements) { - int16_t x = mazeElement.x * 32; - int16_t y = mazeElement.y * 32; - rotate_map_coordinates(&x, &y, rotation); + CoordsXY mazeCoords{ mazeElement.x * 32, mazeElement.y * 32 }; + auto rotatedMazeCoords = mazeCoords.Rotate(rotation); - x += origin.x; - y += origin.y; + rotatedMazeCoords += origin; if (pass == 0) { - min->x = std::min(min->x, x); - max->x = std::max(max->x, x); - min->y = std::min(min->y, y); - max->y = std::max(max->y, y); + min.x = std::min(min.x, rotatedMazeCoords.x); + max.x = std::max(max.x, rotatedMazeCoords.x); + min.y = std::min(min.y, rotatedMazeCoords.y); + max.y = std::max(max.y, rotatedMazeCoords.y); } else { - LocationXY16 pixelPosition = draw_mini_preview_get_pixel_position(x, y); + LocationXY16 pixelPosition = draw_mini_preview_get_pixel_position(rotatedMazeCoords.x, rotatedMazeCoords.y); if (draw_mini_preview_is_pixel_in_bounds(pixelPosition)) { uint8_t* pixel = draw_mini_preview_get_pixel_ptr(pixelPosition); diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 722a0cfb9a..3292629df4 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -6977,8 +6977,9 @@ void sub_6CB945(Ride* ride) const rct_preview_track* trackBlock = get_track_def_from_ride(ride, tileElement->AsTrack()->GetTrackType()); while ((++trackBlock)->index != 0xFF) { - LocationXYZ16 blockLocation = location; - map_offset_with_rotation(&blockLocation.x, &blockLocation.y, trackBlock->x, trackBlock->y, direction); + auto blockLocationXY = map_offset_with_rotation( + { location.x, location.y }, { trackBlock->x, trackBlock->y }, direction); + CoordsXYZ blockLocation{ blockLocationXY.x, blockLocationXY.y, location.z }; bool trackFound = false; tileElement = map_get_first_element_at(blockLocation.x >> 5, blockLocation.y >> 5); diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index 7cef17655f..9e11be9d32 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -1472,8 +1472,7 @@ static bool track_design_place_ride(TrackDesign* td6, int16_t x, int16_t y, int1 case PTD_OPERATION_DRAW_OUTLINES: for (const rct_preview_track* trackBlock = trackBlockArray[trackType]; trackBlock->index != 0xFF; trackBlock++) { - LocationXY16 tile = { x, y }; - map_offset_with_rotation(&tile.x, &tile.y, trackBlock->x, trackBlock->y, rotation); + auto tile = map_offset_with_rotation({ x, y }, { trackBlock->x, trackBlock->y }, rotation); track_design_update_max_min_coordinates(tile.x, tile.y, z); track_design_add_selection_tile(tile.x, tile.y); } @@ -1552,16 +1551,13 @@ static bool track_design_place_ride(TrackDesign* td6, int16_t x, int16_t y, int1 int32_t tempZ = z - TrackCoordinates[trackType].z_begin; for (const rct_preview_track* trackBlock = trackBlockArray[trackType]; trackBlock->index != 0xFF; trackBlock++) { - int16_t tmpX = x; - int16_t tmpY = y; - map_offset_with_rotation(&tmpX, &tmpY, trackBlock->x, trackBlock->y, rotation); - CoordsXY tile = { tmpX, tmpY }; + auto tile = map_offset_with_rotation({ x, y }, { trackBlock->x, trackBlock->y }, rotation); if (tile.x < 0 || tile.y < 0 || tile.x >= (256 * 32) || tile.y >= (256 * 32)) { continue; } - auto surfaceElement = map_get_surface_element_at(tile); + auto surfaceElement = map_get_surface_element_at({ tile.x, tile.y }); if (surfaceElement == nullptr) { return false; @@ -1593,7 +1589,10 @@ static bool track_design_place_ride(TrackDesign* td6, int16_t x, int16_t y, int1 } const rct_track_coordinates* track_coordinates = &TrackCoordinates[trackType]; - map_offset_with_rotation(&x, &y, track_coordinates->x, track_coordinates->y, rotation); + auto offsetAndRotatedTrack = map_offset_with_rotation( + { x, y }, { track_coordinates->x, track_coordinates->y }, rotation); + x = offsetAndRotatedTrack.x; + y = offsetAndRotatedTrack.y; z -= track_coordinates->z_begin; z += track_coordinates->z_end; diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 752abaf806..75f67536f6 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -2353,14 +2353,10 @@ TileElement* map_get_track_element_at_with_direction_from_ride( return nullptr; }; -void map_offset_with_rotation(int16_t* x, int16_t* y, int16_t offsetX, int16_t offsetY, uint8_t rotation) +TileCoordsXY map_offset_with_rotation(TileCoordsXY position, TileCoordsXY offset, uint8_t rotation) { - TileCoordsXY offsets = { offsetX, offsetY }; - TileCoordsXY newCoords = { *x, *y }; - newCoords += offsets.Rotate(rotation); - - *x = (int16_t)newCoords.x; - *y = (int16_t)newCoords.y; + position += offset.Rotate(rotation); + return position; } WallElement* map_get_wall_element_at(int32_t x, int32_t y, int32_t z, int32_t direction) diff --git a/src/openrct2/world/Map.h b/src/openrct2/world/Map.h index f4fdf3bf82..21683c8bfb 100644 --- a/src/openrct2/world/Map.h +++ b/src/openrct2/world/Map.h @@ -231,7 +231,7 @@ bool map_large_scenery_get_origin( int32_t x, int32_t y, int32_t z, int32_t direction, int32_t sequence, int32_t* outX, int32_t* outY, int32_t* outZ, LargeSceneryElement** outElement); -void map_offset_with_rotation(int16_t* x, int16_t* y, int16_t offsetX, int16_t offsetY, uint8_t rotation); +TileCoordsXY map_offset_with_rotation(TileCoordsXY position, TileCoordsXY offset, uint8_t rotation); ScreenCoordsXY translate_3d_to_2d_with_z(int32_t rotation, const CoordsXYZ& pos); TrackElement* map_get_track_element_at(int32_t x, int32_t y, int32_t z); From 68e0519c5e6957518f5f223192f36894a26a1290 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Mon, 9 Dec 2019 17:55:57 -0300 Subject: [PATCH 2/3] Remove Map::map_offset_with_rotation() --- src/openrct2-ui/windows/TrackDesignPlace.cpp | 16 +++++----------- src/openrct2/ride/Ride.cpp | 11 +++-------- src/openrct2/ride/TrackDesign.cpp | 9 ++++----- src/openrct2/world/Location.hpp | 5 +++++ src/openrct2/world/Map.cpp | 6 ------ src/openrct2/world/Map.h | 1 - 6 files changed, 17 insertions(+), 31 deletions(-) diff --git a/src/openrct2-ui/windows/TrackDesignPlace.cpp b/src/openrct2-ui/windows/TrackDesignPlace.cpp index 770b309c98..ec699e56f3 100644 --- a/src/openrct2-ui/windows/TrackDesignPlace.cpp +++ b/src/openrct2-ui/windows/TrackDesignPlace.cpp @@ -543,8 +543,7 @@ static void window_track_place_draw_mini_preview_track( const rct_preview_track* trackBlock = trackBlockArray[trackType]; while (trackBlock->index != 255) { - auto rotatedAndOffsetTrackBlock = map_offset_with_rotation( - { origin.x, origin.y }, { trackBlock->x, trackBlock->y }, rotation); + auto rotatedAndOffsetTrackBlock = origin + CoordsXY{ trackBlock->x, trackBlock->y }.Rotate(rotation); if (pass == 0) { @@ -589,8 +588,7 @@ static void window_track_place_draw_mini_preview_track( const rct_track_coordinates* track_coordinate = &TrackCoordinates[trackType]; trackType *= 10; - auto rotatedAndOfffsetTrack = map_offset_with_rotation( - { origin.x, origin.y }, { track_coordinate->x, track_coordinate->y }, rotation); + auto rotatedAndOfffsetTrack = origin + CoordsXY{ track_coordinate->x, track_coordinate->y }.Rotate(rotation); rotation += track_coordinate->rotation_end - track_coordinate->rotation_begin; rotation &= 3; if (track_coordinate->rotation_end & 4) @@ -599,15 +597,14 @@ static void window_track_place_draw_mini_preview_track( } if (!(rotation & 4)) { - origin.x = rotatedAndOfffsetTrack.x + CoordsDirectionDelta[rotation].x; - origin.y = rotatedAndOfffsetTrack.x + CoordsDirectionDelta[rotation].y; + origin = rotatedAndOfffsetTrack + CoordsDirectionDelta[rotation]; } } // Draw entrance and exit preview. for (const auto& entrance : td6->entrance_elements) { - auto rotatedAndOffsetEntrance = map_offset_with_rotation({ origin.x, origin.y }, { entrance.x, entrance.y }, rotation); + auto rotatedAndOffsetEntrance = origin + CoordsXY{ entrance.x, entrance.y }.Rotate(rotation); if (pass == 0) { @@ -642,10 +639,7 @@ static void window_track_place_draw_mini_preview_maze( uint8_t rotation = (_currentTrackPieceDirection + get_current_rotation()) & 3; for (const auto& mazeElement : td6->maze_elements) { - CoordsXY mazeCoords{ mazeElement.x * 32, mazeElement.y * 32 }; - auto rotatedMazeCoords = mazeCoords.Rotate(rotation); - - rotatedMazeCoords += origin; + auto rotatedMazeCoords = origin + CoordsXY{ mazeElement.x * 32, mazeElement.y * 32 }.Rotate(rotation); if (pass == 0) { diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 3292629df4..c4f3f073ac 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -6915,11 +6915,8 @@ void sub_6CB945(Ride* ride) if (ride->stations[stationId].Start.xy == RCT_XY8_UNDEFINED) continue; - LocationXYZ16 location = { - (int16_t)(ride->stations[stationId].Start.x * 32), - (int16_t)(ride->stations[stationId].Start.y * 32), - (ride->stations[stationId].Height), - }; + CoordsXYZ location = { ride->stations[stationId].Start.x * 32, ride->stations[stationId].Start.y * 32, + ride->stations[stationId].Height * 8 }; uint8_t direction = 0xFF; bool specialTrack = false; @@ -6977,9 +6974,7 @@ void sub_6CB945(Ride* ride) const rct_preview_track* trackBlock = get_track_def_from_ride(ride, tileElement->AsTrack()->GetTrackType()); while ((++trackBlock)->index != 0xFF) { - auto blockLocationXY = map_offset_with_rotation( - { location.x, location.y }, { trackBlock->x, trackBlock->y }, direction); - CoordsXYZ blockLocation{ blockLocationXY.x, blockLocationXY.y, location.z }; + CoordsXYZ blockLocation = location + CoordsXYZ{ CoordsXY{ trackBlock->x, trackBlock->y }.Rotate(direction), 0 }; bool trackFound = false; tileElement = map_get_first_element_at(blockLocation.x >> 5, blockLocation.y >> 5); diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index 9e11be9d32..0488444cd7 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -1472,7 +1472,7 @@ static bool track_design_place_ride(TrackDesign* td6, int16_t x, int16_t y, int1 case PTD_OPERATION_DRAW_OUTLINES: for (const rct_preview_track* trackBlock = trackBlockArray[trackType]; trackBlock->index != 0xFF; trackBlock++) { - auto tile = map_offset_with_rotation({ x, y }, { trackBlock->x, trackBlock->y }, rotation); + auto tile = CoordsXY{ x, y } + CoordsXY{ trackBlock->x, trackBlock->y }.Rotate(rotation); track_design_update_max_min_coordinates(tile.x, tile.y, z); track_design_add_selection_tile(tile.x, tile.y); } @@ -1551,13 +1551,13 @@ static bool track_design_place_ride(TrackDesign* td6, int16_t x, int16_t y, int1 int32_t tempZ = z - TrackCoordinates[trackType].z_begin; for (const rct_preview_track* trackBlock = trackBlockArray[trackType]; trackBlock->index != 0xFF; trackBlock++) { - auto tile = map_offset_with_rotation({ x, y }, { trackBlock->x, trackBlock->y }, rotation); + auto tile = CoordsXY{ x, y } + CoordsXY{ trackBlock->x, trackBlock->y }.Rotate(rotation); if (tile.x < 0 || tile.y < 0 || tile.x >= (256 * 32) || tile.y >= (256 * 32)) { continue; } - auto surfaceElement = map_get_surface_element_at({ tile.x, tile.y }); + auto surfaceElement = map_get_surface_element_at(tile); if (surfaceElement == nullptr) { return false; @@ -1589,8 +1589,7 @@ static bool track_design_place_ride(TrackDesign* td6, int16_t x, int16_t y, int1 } const rct_track_coordinates* track_coordinates = &TrackCoordinates[trackType]; - auto offsetAndRotatedTrack = map_offset_with_rotation( - { x, y }, { track_coordinates->x, track_coordinates->y }, rotation); + auto offsetAndRotatedTrack = CoordsXY{ x, y } + CoordsXY{ track_coordinates->x, track_coordinates->y }.Rotate(rotation); x = offsetAndRotatedTrack.x; y = offsetAndRotatedTrack.y; z -= track_coordinates->z_begin; diff --git a/src/openrct2/world/Location.hpp b/src/openrct2/world/Location.hpp index 4d3aa1e6ba..f0c9e9c0d5 100644 --- a/src/openrct2/world/Location.hpp +++ b/src/openrct2/world/Location.hpp @@ -224,6 +224,11 @@ struct CoordsXYZ : public CoordsXY { } + const CoordsXYZ operator+(const CoordsXYZ& rhs) const + { + return { x + rhs.x, y + rhs.y, z + rhs.z }; + } + bool operator==(const CoordsXYZ& other) const { return x == other.x && y == other.y && z == other.z; diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 75f67536f6..2e224f7832 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -2353,12 +2353,6 @@ TileElement* map_get_track_element_at_with_direction_from_ride( return nullptr; }; -TileCoordsXY map_offset_with_rotation(TileCoordsXY position, TileCoordsXY offset, uint8_t rotation) -{ - position += offset.Rotate(rotation); - return position; -} - WallElement* map_get_wall_element_at(int32_t x, int32_t y, int32_t z, int32_t direction) { TileElement* tileElement = map_get_first_element_at(x >> 5, y >> 5); diff --git a/src/openrct2/world/Map.h b/src/openrct2/world/Map.h index 21683c8bfb..59091b97aa 100644 --- a/src/openrct2/world/Map.h +++ b/src/openrct2/world/Map.h @@ -231,7 +231,6 @@ bool map_large_scenery_get_origin( int32_t x, int32_t y, int32_t z, int32_t direction, int32_t sequence, int32_t* outX, int32_t* outY, int32_t* outZ, LargeSceneryElement** outElement); -TileCoordsXY map_offset_with_rotation(TileCoordsXY position, TileCoordsXY offset, uint8_t rotation); ScreenCoordsXY translate_3d_to_2d_with_z(int32_t rotation, const CoordsXYZ& pos); TrackElement* map_get_track_element_at(int32_t x, int32_t y, int32_t z); From 43366a0a51e88e5e237cd3d0d6be023789aff643 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Tue, 10 Dec 2019 23:33:53 -0300 Subject: [PATCH 3/3] Make sure height comparisons are done against TileCoords --- src/openrct2/ride/Ride.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index c4f3f073ac..fb65bd1bb9 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -6917,6 +6917,7 @@ void sub_6CB945(Ride* ride) CoordsXYZ location = { ride->stations[stationId].Start.x * 32, ride->stations[stationId].Start.y * 32, ride->stations[stationId].Height * 8 }; + auto tileHeight = TileCoordsXYZ(location).z; uint8_t direction = 0xFF; bool specialTrack = false; @@ -6936,7 +6937,7 @@ void sub_6CB945(Ride* ride) bool trackFound = false; do { - if (tileElement->base_height != location.z) + if (tileElement->base_height != tileHeight) continue; if (tileElement->GetType() != TILE_ELEMENT_TYPE_TRACK) continue; @@ -6975,6 +6976,7 @@ void sub_6CB945(Ride* ride) while ((++trackBlock)->index != 0xFF) { CoordsXYZ blockLocation = location + CoordsXYZ{ CoordsXY{ trackBlock->x, trackBlock->y }.Rotate(direction), 0 }; + auto blockTileHeight = TileCoordsXYZ(blockLocation).z; bool trackFound = false; tileElement = map_get_first_element_at(blockLocation.x >> 5, blockLocation.y >> 5); @@ -6982,7 +6984,7 @@ void sub_6CB945(Ride* ride) break; do { - if (blockLocation.z != tileElement->base_height) + if (blockTileHeight != tileElement->base_height) continue; if (tileElement->GetType() != TILE_ELEMENT_TYPE_TRACK) continue;