mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-04 13:42:55 +01:00
Use CoordsXY on action rotation (#10332)
* Use CoordsXY on action rotation * Don't use intermediate CoordsXY variable just for Rotating it next * Standardize operations on Coords and Rotated Coords * Remove unwanted linebreak addition
This commit is contained in:
@@ -153,10 +153,7 @@ public:
|
||||
uint8_t tileNum = 0;
|
||||
for (rct_large_scenery_tile* tile = sceneryEntry->large_scenery.tiles; tile->x_offset != -1; tile++, tileNum++)
|
||||
{
|
||||
auto tempX = tile->x_offset;
|
||||
auto tempY = tile->y_offset;
|
||||
rotate_map_coordinates(&tempX, &tempY, _loc.direction);
|
||||
CoordsXY curTile = { tempX, tempY };
|
||||
auto curTile = CoordsXY{ tile->x_offset, tile->y_offset }.Rotate(_loc.direction);
|
||||
|
||||
curTile.x += _loc.x;
|
||||
curTile.y += _loc.y;
|
||||
@@ -285,10 +282,7 @@ public:
|
||||
uint8_t tileNum = 0;
|
||||
for (rct_large_scenery_tile* tile = sceneryEntry->large_scenery.tiles; tile->x_offset != -1; tile++, tileNum++)
|
||||
{
|
||||
auto tempX = tile->x_offset;
|
||||
auto tempY = tile->y_offset;
|
||||
rotate_map_coordinates(&tempX, &tempY, _loc.direction);
|
||||
CoordsXY curTile = { tempX, tempY };
|
||||
auto curTile = CoordsXY{ tile->x_offset, tile->y_offset }.Rotate(_loc.direction);
|
||||
|
||||
curTile.x += _loc.x;
|
||||
curTile.y += _loc.y;
|
||||
@@ -356,10 +350,7 @@ private:
|
||||
int16_t maxHeight = -1;
|
||||
for (rct_large_scenery_tile* tile = tiles; tile->x_offset != -1; tile++)
|
||||
{
|
||||
auto tempX = tile->x_offset;
|
||||
auto tempY = tile->y_offset;
|
||||
rotate_map_coordinates(&tempX, &tempY, _loc.direction);
|
||||
CoordsXY curTile = { tempX, tempY };
|
||||
auto curTile = CoordsXY{ tile->x_offset, tile->y_offset }.Rotate(_loc.direction);
|
||||
|
||||
curTile.x += _loc.x;
|
||||
curTile.y += _loc.y;
|
||||
|
||||
@@ -72,27 +72,22 @@ public:
|
||||
|
||||
rct_scenery_entry* scenery_entry = tileElement->AsLargeScenery()->GetEntry();
|
||||
|
||||
LocationXYZ16 firstTile = { scenery_entry->large_scenery.tiles[_tileIndex].x_offset,
|
||||
scenery_entry->large_scenery.tiles[_tileIndex].y_offset,
|
||||
static_cast<int16_t>((_loc.z) - scenery_entry->large_scenery.tiles[_tileIndex].z_offset) };
|
||||
auto rotatedOffsets = CoordsXYZ{ CoordsXY{ scenery_entry->large_scenery.tiles[_tileIndex].x_offset,
|
||||
scenery_entry->large_scenery.tiles[_tileIndex].y_offset }
|
||||
.Rotate(_loc.direction),
|
||||
scenery_entry->large_scenery.tiles[_tileIndex].z_offset };
|
||||
|
||||
rotate_map_coordinates(&firstTile.x, &firstTile.y, _loc.direction);
|
||||
|
||||
firstTile.x = _loc.x - firstTile.x;
|
||||
firstTile.y = _loc.y - firstTile.y;
|
||||
auto firstTile = CoordsXYZ{ _loc.x, _loc.y, _loc.z } - rotatedOffsets;
|
||||
|
||||
bool calculate_cost = true;
|
||||
for (int32_t i = 0; scenery_entry->large_scenery.tiles[i].x_offset != -1; i++)
|
||||
{
|
||||
LocationXYZ16 currentTile = { scenery_entry->large_scenery.tiles[i].x_offset,
|
||||
scenery_entry->large_scenery.tiles[i].y_offset,
|
||||
scenery_entry->large_scenery.tiles[i].z_offset };
|
||||
auto currentTileRotatedOffset = CoordsXYZ{ CoordsXY{ scenery_entry->large_scenery.tiles[i].x_offset,
|
||||
scenery_entry->large_scenery.tiles[i].y_offset }
|
||||
.Rotate(_loc.direction),
|
||||
scenery_entry->large_scenery.tiles[i].z_offset };
|
||||
|
||||
rotate_map_coordinates(¤tTile.x, ¤tTile.y, _loc.direction);
|
||||
|
||||
currentTile.x += firstTile.x;
|
||||
currentTile.y += firstTile.y;
|
||||
currentTile.z += firstTile.z;
|
||||
auto currentTile = CoordsXYZ{ firstTile.x, firstTile.y, firstTile.z } + currentTileRotatedOffset;
|
||||
|
||||
if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gCheatsSandboxMode)
|
||||
{
|
||||
@@ -144,26 +139,21 @@ public:
|
||||
|
||||
rct_scenery_entry* scenery_entry = tileElement->AsLargeScenery()->GetEntry();
|
||||
|
||||
LocationXYZ16 firstTile = { scenery_entry->large_scenery.tiles[_tileIndex].x_offset,
|
||||
scenery_entry->large_scenery.tiles[_tileIndex].y_offset,
|
||||
static_cast<int16_t>((_loc.z) - scenery_entry->large_scenery.tiles[_tileIndex].z_offset) };
|
||||
auto rotatedFirstTile = CoordsXYZ{ CoordsXY{ scenery_entry->large_scenery.tiles[_tileIndex].x_offset,
|
||||
scenery_entry->large_scenery.tiles[_tileIndex].y_offset }
|
||||
.Rotate(_loc.direction),
|
||||
scenery_entry->large_scenery.tiles[_tileIndex].z_offset };
|
||||
|
||||
rotate_map_coordinates(&firstTile.x, &firstTile.y, _loc.direction);
|
||||
|
||||
firstTile.x = _loc.x - firstTile.x;
|
||||
firstTile.y = _loc.y - firstTile.y;
|
||||
auto firstTile = CoordsXYZ{ _loc.x, _loc.y, _loc.z } - rotatedFirstTile;
|
||||
|
||||
for (int32_t i = 0; scenery_entry->large_scenery.tiles[i].x_offset != -1; i++)
|
||||
{
|
||||
LocationXYZ16 currentTile = { scenery_entry->large_scenery.tiles[i].x_offset,
|
||||
scenery_entry->large_scenery.tiles[i].y_offset,
|
||||
scenery_entry->large_scenery.tiles[i].z_offset };
|
||||
auto rotatedCurrentTile = CoordsXYZ{ CoordsXY{ scenery_entry->large_scenery.tiles[i].x_offset,
|
||||
scenery_entry->large_scenery.tiles[i].y_offset }
|
||||
.Rotate(_loc.direction),
|
||||
scenery_entry->large_scenery.tiles[i].z_offset };
|
||||
|
||||
rotate_map_coordinates(¤tTile.x, ¤tTile.y, _loc.direction);
|
||||
|
||||
currentTile.x += firstTile.x;
|
||||
currentTile.y += firstTile.y;
|
||||
currentTile.z += firstTile.z;
|
||||
auto currentTile = CoordsXYZ{ firstTile.x, firstTile.y, firstTile.z } + rotatedCurrentTile;
|
||||
|
||||
if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gCheatsSandboxMode)
|
||||
{
|
||||
|
||||
@@ -106,21 +106,20 @@ private:
|
||||
return MakeResult(GA_ERROR::UNKNOWN, STR_CANT_REPAINT_THIS);
|
||||
}
|
||||
// Work out the base tile coordinates (Tile with index 0)
|
||||
auto baseX = sceneryEntry->large_scenery.tiles[_tileIndex].x_offset;
|
||||
auto baseY = sceneryEntry->large_scenery.tiles[_tileIndex].y_offset;
|
||||
rotate_map_coordinates(&baseX, &baseY, _loc.direction);
|
||||
auto rotatedBaseCoordsOffset = CoordsXYZ{ CoordsXY{ sceneryEntry->large_scenery.tiles[_tileIndex].x_offset,
|
||||
sceneryEntry->large_scenery.tiles[_tileIndex].y_offset }
|
||||
.Rotate(_loc.direction),
|
||||
sceneryEntry->large_scenery.tiles[_tileIndex].z_offset };
|
||||
|
||||
CoordsXYZ baseTile = { _loc.x - baseX, _loc.y - baseY,
|
||||
_loc.z - sceneryEntry->large_scenery.tiles[_tileIndex].z_offset };
|
||||
auto baseTile = CoordsXYZ{ _loc.x, _loc.y, _loc.z } - rotatedBaseCoordsOffset;
|
||||
|
||||
auto i = 0;
|
||||
for (auto tile = sceneryEntry->large_scenery.tiles; tile->x_offset != -1; ++tile, ++i)
|
||||
{
|
||||
// Work out the current tile coordinates
|
||||
auto tileX = tile->x_offset;
|
||||
auto tileY = tile->y_offset;
|
||||
rotate_map_coordinates(&tileX, &tileY, _loc.direction);
|
||||
CoordsXYZ currentTile = { tileX + baseTile.x, tileY + baseTile.y, tile->z_offset + baseTile.z };
|
||||
auto rotatedTileCoords = CoordsXYZ{ CoordsXY{ tile->x_offset, tile->y_offset }.Rotate(_loc.direction),
|
||||
tile->z_offset };
|
||||
auto currentTile = CoordsXYZ{ baseTile.x, baseTile.y, baseTile.z } + rotatedTileCoords;
|
||||
|
||||
if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gCheatsSandboxMode)
|
||||
{
|
||||
|
||||
@@ -165,11 +165,8 @@ public:
|
||||
// First check if any of the track pieces are outside the park
|
||||
for (; trackBlock->index != 0xFF; trackBlock++)
|
||||
{
|
||||
CoordsXYZ tileCoords{ _origin.x, _origin.y, _origin.z };
|
||||
LocationXY16 track{ trackBlock->x, trackBlock->y };
|
||||
rotate_map_coordinates(&track.x, &track.y, _origin.direction);
|
||||
tileCoords.x += track.x;
|
||||
tileCoords.y += track.y;
|
||||
auto rotatedTrack = CoordsXYZ{ CoordsXY{ trackBlock->x, trackBlock->y }.Rotate(_origin.direction), 0 };
|
||||
auto tileCoords = CoordsXYZ{ _origin.x, _origin.y, _origin.z } + rotatedTrack;
|
||||
|
||||
if (!map_is_location_owned(tileCoords) && !gCheatsSandboxMode)
|
||||
{
|
||||
@@ -204,12 +201,8 @@ public:
|
||||
|
||||
for (int32_t blockIndex = 0; trackBlock->index != 0xFF; trackBlock++, blockIndex++)
|
||||
{
|
||||
CoordsXYZ mapLoc{ _origin.x, _origin.y, _origin.z };
|
||||
LocationXY16 track{ trackBlock->x, trackBlock->y };
|
||||
rotate_map_coordinates(&track.x, &track.y, _origin.direction);
|
||||
mapLoc.x += track.x;
|
||||
mapLoc.y += track.y;
|
||||
mapLoc.z += trackBlock->z;
|
||||
auto rotatedTrack = CoordsXYZ{ CoordsXY{ trackBlock->x, trackBlock->y }.Rotate(_origin.direction), trackBlock->z };
|
||||
auto mapLoc = CoordsXYZ{ _origin.x, _origin.y, _origin.z } + rotatedTrack;
|
||||
auto quarterTile = trackBlock->var_08.Rotate(_origin.direction);
|
||||
|
||||
if (mapLoc.z < 16)
|
||||
@@ -444,12 +437,8 @@ public:
|
||||
trackBlock = get_track_def_from_ride(ride, _trackType);
|
||||
for (int32_t blockIndex = 0; trackBlock->index != 0xFF; trackBlock++, blockIndex++)
|
||||
{
|
||||
CoordsXYZ mapLoc{ _origin.x, _origin.y, _origin.z };
|
||||
LocationXY16 track{ trackBlock->x, trackBlock->y };
|
||||
rotate_map_coordinates(&track.x, &track.y, _origin.direction);
|
||||
mapLoc.x += track.x;
|
||||
mapLoc.y += track.y;
|
||||
mapLoc.z += trackBlock->z;
|
||||
auto rotatedTrack = CoordsXYZ{ CoordsXY{ trackBlock->x, trackBlock->y }.Rotate(_origin.direction), trackBlock->z };
|
||||
auto mapLoc = CoordsXYZ{ _origin.x, _origin.y, _origin.z } + rotatedTrack;
|
||||
|
||||
auto quarterTile = trackBlock->var_08.Rotate(_origin.direction);
|
||||
|
||||
|
||||
@@ -138,11 +138,10 @@ public:
|
||||
auto startLoc = _origin;
|
||||
startLoc.direction = tileElement->GetDirection();
|
||||
|
||||
LocationXY16 trackLoc = { trackBlock->x, trackBlock->y };
|
||||
rotate_map_coordinates(&trackLoc.x, &trackLoc.y, startLoc.direction);
|
||||
startLoc.x -= trackLoc.x;
|
||||
startLoc.y -= trackLoc.y;
|
||||
startLoc.z -= trackBlock->z;
|
||||
auto rotatedTrack = CoordsXYZ{ CoordsXY{ trackBlock->x, trackBlock->y }.Rotate(startLoc.direction), trackBlock->z };
|
||||
startLoc.x -= rotatedTrack.x;
|
||||
startLoc.y -= rotatedTrack.y;
|
||||
startLoc.z -= rotatedTrack.z;
|
||||
res->Position.x = startLoc.x;
|
||||
res->Position.y = startLoc.y;
|
||||
res->Position.z = startLoc.z;
|
||||
@@ -152,12 +151,8 @@ public:
|
||||
trackBlock = get_track_def_from_ride(ride, trackType);
|
||||
for (; trackBlock->index != 255; trackBlock++)
|
||||
{
|
||||
CoordsXYZ mapLoc{ startLoc.x, startLoc.y, startLoc.z };
|
||||
trackLoc = { trackBlock->x, trackBlock->y };
|
||||
rotate_map_coordinates(&trackLoc.x, &trackLoc.y, startLoc.direction);
|
||||
mapLoc.x += trackLoc.x;
|
||||
mapLoc.y += trackLoc.y;
|
||||
mapLoc.z += trackBlock->z;
|
||||
rotatedTrack = CoordsXYZ{ CoordsXY{ trackBlock->x, trackBlock->y }.Rotate(startLoc.direction), trackBlock->z };
|
||||
auto mapLoc = CoordsXYZ{ startLoc.x, startLoc.y, startLoc.z } + rotatedTrack;
|
||||
|
||||
map_invalidate_tile_full(mapLoc.x, mapLoc.y);
|
||||
|
||||
@@ -334,11 +329,10 @@ public:
|
||||
auto startLoc = _origin;
|
||||
startLoc.direction = tileElement->GetDirection();
|
||||
|
||||
LocationXY16 trackLoc = { trackBlock->x, trackBlock->y };
|
||||
rotate_map_coordinates(&trackLoc.x, &trackLoc.y, startLoc.direction);
|
||||
startLoc.x -= trackLoc.x;
|
||||
startLoc.y -= trackLoc.y;
|
||||
startLoc.z -= trackBlock->z;
|
||||
auto rotatedTrackLoc = CoordsXYZ{ CoordsXY{ trackBlock->x, trackBlock->y }.Rotate(startLoc.direction), trackBlock->z };
|
||||
startLoc.x -= rotatedTrackLoc.x;
|
||||
startLoc.y -= rotatedTrackLoc.y;
|
||||
startLoc.z -= rotatedTrackLoc.z;
|
||||
res->Position.x = startLoc.x;
|
||||
res->Position.y = startLoc.y;
|
||||
res->Position.z = startLoc.z;
|
||||
@@ -347,12 +341,8 @@ public:
|
||||
trackBlock = get_track_def_from_ride(ride, trackType);
|
||||
for (; trackBlock->index != 255; trackBlock++)
|
||||
{
|
||||
CoordsXYZ mapLoc{ startLoc.x, startLoc.y, startLoc.z };
|
||||
trackLoc = { trackBlock->x, trackBlock->y };
|
||||
rotate_map_coordinates(&trackLoc.x, &trackLoc.y, startLoc.direction);
|
||||
mapLoc.x += trackLoc.x;
|
||||
mapLoc.y += trackLoc.y;
|
||||
mapLoc.z += trackBlock->z;
|
||||
rotatedTrackLoc = CoordsXYZ{ CoordsXY{ trackBlock->x, trackBlock->y }.Rotate(startLoc.direction), trackBlock->z };
|
||||
auto mapLoc = CoordsXYZ{ startLoc.x, startLoc.y, startLoc.z } + rotatedTrackLoc;
|
||||
|
||||
map_invalidate_tile_full(mapLoc.x, mapLoc.y);
|
||||
|
||||
|
||||
@@ -229,6 +229,11 @@ struct CoordsXYZ : public CoordsXY
|
||||
return { x + rhs.x, y + rhs.y, z + rhs.z };
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user