diff --git a/src/openrct2/actions/MazePlaceTrackAction.hpp b/src/openrct2/actions/MazePlaceTrackAction.hpp index ca35a905ec..514a2fec00 100644 --- a/src/openrct2/actions/MazePlaceTrackAction.hpp +++ b/src/openrct2/actions/MazePlaceTrackAction.hpp @@ -40,9 +40,7 @@ public: { auto res = std::make_unique(); - res->Position.x = _loc.x + 8; - res->Position.y = _loc.y + 8; - res->Position.z = _loc.z; + res->Position = _loc + CoordsXYZ{ 8, 8, 0 }; res->Expenditure = ExpenditureType::RideConstruction; res->ErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE; if (!map_check_free_elements_and_reorganise(1)) @@ -130,9 +128,7 @@ public: { auto res = std::make_unique(); - res->Position.x = _loc.x + 8; - res->Position.y = _loc.y + 8; - res->Position.z = _loc.z; + res->Position = _loc + CoordsXYZ{ 8, 8, 0 }; res->Expenditure = ExpenditureType::RideConstruction; res->ErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE; @@ -172,10 +168,9 @@ public: money32 price = (((RideTrackCosts[ride->type].track_price * TrackPricing[TRACK_ELEM_MAZE]) >> 16)); res->Cost = clearCost + price / 2 * 10; - uint16_t flooredX = floor2(_loc.x, 32); - uint16_t flooredY = floor2(_loc.y, 32); + auto startLoc = _loc.ToTileStart(); - auto tileElement = tile_element_insert({ _loc.x / 32, _loc.y / 32, baseHeight }, 0b1111); + auto tileElement = tile_element_insert({ TileCoordsXY{ _loc }, baseHeight }, 0b1111); assert(tileElement != nullptr); tileElement->clearance_height = clearanceHeight + 4; @@ -190,17 +185,16 @@ public: tileElement->SetGhost(true); } - map_invalidate_tile_full({ flooredX, flooredY }); + map_invalidate_tile_full(startLoc); ride->maze_tiles++; ride->stations[0].SetBaseZ(tileElement->GetBaseZ()); - ride->stations[0].Start.x = 0; - ride->stations[0].Start.y = 0; + ride->stations[0].Start = { 0, 0 }; if (ride->maze_tiles == 1) { - ride->overall_view.x = flooredX / 32; - ride->overall_view.y = flooredY / 32; + auto tileStartLoc = TileCoordsXY{ startLoc }; + ride->overall_view = tileStartLoc; } return res; diff --git a/src/openrct2/actions/MazeSetTrackAction.hpp b/src/openrct2/actions/MazeSetTrackAction.hpp index 9568ce78f7..4b793cccb9 100644 --- a/src/openrct2/actions/MazeSetTrackAction.hpp +++ b/src/openrct2/actions/MazeSetTrackAction.hpp @@ -76,9 +76,7 @@ public: { auto res = std::make_unique(); - res->Position.x = _loc.x + 8; - res->Position.y = _loc.y + 8; - res->Position.z = _loc.z; + res->Position = _loc + CoordsXYZ{ 8, 8, 0 }; res->Expenditure = ExpenditureType::RideConstruction; res->ErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE; if (!map_check_free_elements_and_reorganise(1)) @@ -175,9 +173,7 @@ public: { auto res = std::make_unique(); - res->Position.x = _loc.x + 8; - res->Position.y = _loc.y + 8; - res->Position.z = _loc.z; + res->Position = _loc + CoordsXYZ{ 8, 8, 0 }; res->Expenditure = ExpenditureType::RideConstruction; res->ErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE; @@ -212,10 +208,9 @@ public: money32 price = (((RideTrackCosts[ride->type].track_price * TrackPricing[TRACK_ELEM_MAZE]) >> 16)); res->Cost = price / 2 * 10; - uint16_t flooredX = floor2(_loc.x, 32); - uint16_t flooredY = floor2(_loc.y, 32); + auto startLoc = _loc.ToTileStart(); - tileElement = tile_element_insert({ _loc.x / 32, _loc.y / 32, baseHeight }, 0b1111); + tileElement = tile_element_insert({ TileCoordsXY{ _loc }, baseHeight }, 0b1111); assert(tileElement != nullptr); tileElement->clearance_height = clearanceHeight; @@ -230,17 +225,16 @@ public: tileElement->SetGhost(true); } - map_invalidate_tile_full({ flooredX, flooredY }); + map_invalidate_tile_full(startLoc); ride->maze_tiles++; ride->stations[0].SetBaseZ(tileElement->GetBaseZ()); - ride->stations[0].Start.x = 0; - ride->stations[0].Start.y = 0; + ride->stations[0].Start = { 0, 0 }; if (_initialPlacement && !(flags & GAME_COMMAND_FLAG_GHOST)) { - ride->overall_view.x = flooredX / 32; - ride->overall_view.y = flooredY / 32; + auto tileStartLoc = TileCoordsXY{ startLoc }; + ride->overall_view = tileStartLoc; } } @@ -260,11 +254,10 @@ public: uint8_t temp_edx = byte_993CFC[segmentOffset]; if (temp_edx != 0xFF) { - uint16_t previousElementX = floor2(_loc.x, 32) - CoordsDirectionDelta[_loc.direction].x; - uint16_t previousElementY = floor2(_loc.y, 32) - CoordsDirectionDelta[_loc.direction].y; + auto previousElementLoc = CoordsXY{ _loc }.ToTileStart() - CoordsDirectionDelta[_loc.direction]; TileElement* previousTileElement = map_get_track_element_at_of_type_from_ride( - { previousElementX, previousElementY, _loc.z }, TRACK_ELEM_MAZE, _rideIndex); + { previousElementLoc, _loc.z }, TRACK_ELEM_MAZE, _rideIndex); if (previousTileElement != nullptr) { @@ -286,13 +279,13 @@ public: case GC_SET_MAZE_TRACK_FILL: if (!_initialPlacement) { - uint16_t previousSegmentX = _loc.x - CoordsDirectionDelta[_loc.direction].x / 2; - uint16_t previousSegmentY = _loc.y - CoordsDirectionDelta[_loc.direction].y / 2; + auto previousSegment = CoordsXY{ _loc.x - CoordsDirectionDelta[_loc.direction].x / 2, + _loc.y - CoordsDirectionDelta[_loc.direction].y / 2 }; tileElement = map_get_track_element_at_of_type_from_ride( - { previousSegmentX, previousSegmentY, _loc.z }, TRACK_ELEM_MAZE, _rideIndex); + { previousSegment, _loc.z }, TRACK_ELEM_MAZE, _rideIndex); - map_invalidate_tile_full(CoordsXY{ previousSegmentX, previousSegmentY }.ToTileStart()); + map_invalidate_tile_full(previousSegment.ToTileStart()); if (tileElement == nullptr) { log_error("No surface found"); @@ -301,7 +294,7 @@ public: return res; } - uint32_t segmentBit = MazeGetSegmentBit(previousSegmentX, previousSegmentY); + uint32_t segmentBit = MazeGetSegmentBit(previousSegment.x, previousSegment.y); tileElement->AsTrack()->MazeEntryAdd(1 << segmentBit); segmentBit--; @@ -315,11 +308,10 @@ public: tileElement->AsTrack()->MazeEntryAdd(1 << segmentBit); uint32_t direction1 = byte_993D0C[segmentBit]; - uint16_t nextElementX = floor2(previousSegmentX, 32) + CoordsDirectionDelta[direction1].x; - uint16_t nextElementY = floor2(previousSegmentY, 32) + CoordsDirectionDelta[direction1].y; + auto nextElementLoc = previousSegment.ToTileStart() + CoordsDirectionDelta[direction1]; TileElement* tmp_tileElement = map_get_track_element_at_of_type_from_ride( - { nextElementX, nextElementY, _loc.z }, TRACK_ELEM_MAZE, _rideIndex); + { nextElementLoc, _loc.z }, TRACK_ELEM_MAZE, _rideIndex); if (tmp_tileElement != nullptr) { diff --git a/src/openrct2/actions/PlacePeepSpawnAction.hpp b/src/openrct2/actions/PlacePeepSpawnAction.hpp index 3ff6906443..02a9548bc8 100644 --- a/src/openrct2/actions/PlacePeepSpawnAction.hpp +++ b/src/openrct2/actions/PlacePeepSpawnAction.hpp @@ -55,7 +55,7 @@ public: auto res = std::make_unique(); res->Expenditure = ExpenditureType::LandPurchase; - res->Position = CoordsXYZ{ _location.x, _location.y, _location.z / 8 }; + res->Position = _location; if (!map_check_free_elements_and_reorganise(3)) { @@ -70,7 +70,7 @@ public: } // Verify footpath exists at location, and retrieve coordinates - auto pathElement = map_get_path_element_at({ _location.x >> 5, _location.y >> 5, _location.z / 8 }); + auto pathElement = map_get_path_element_at(TileCoordsXYZ{ _location }); if (pathElement == nullptr) { return std::make_unique( @@ -96,27 +96,24 @@ public: { auto res = std::make_unique(); res->Expenditure = ExpenditureType::LandPurchase; - res->Position = CoordsXYZ{ _location.x, _location.y, _location.z / 8 }; + res->Position = _location; // If we have reached our max peep spawns, remove the oldest spawns while (gPeepSpawns.size() >= MAX_PEEP_SPAWNS) { auto oldestSpawn = gPeepSpawns.begin(); - auto oldX = oldestSpawn->x; - auto oldY = oldestSpawn->y; gPeepSpawns.erase(oldestSpawn); - map_invalidate_tile_full({ oldX, oldY }); + map_invalidate_tile_full(*oldestSpawn); } - // Shift the spawn point to the middle of the tile - int32_t middleX, middleY; - middleX = _location.x + 16 + (DirectionOffsets[_location.direction].x * 15); - middleY = _location.y + 16 + (DirectionOffsets[_location.direction].y * 15); + // Shift the spawn point to the edge of the tile + auto spawnPos = CoordsXY{ _location.ToTileCentre() } + + CoordsXY{ DirectionOffsets[_location.direction].x * 15, DirectionOffsets[_location.direction].y * 15 }; // Set peep spawn PeepSpawn spawn; - spawn.x = middleX; - spawn.y = middleY; + spawn.x = spawnPos.x; + spawn.y = spawnPos.y; spawn.z = _location.z; spawn.direction = _location.direction; gPeepSpawns.push_back(spawn); diff --git a/src/openrct2/actions/SetCheatAction.hpp b/src/openrct2/actions/SetCheatAction.hpp index b5058289d0..802629edab 100644 --- a/src/openrct2/actions/SetCheatAction.hpp +++ b/src/openrct2/actions/SetCheatAction.hpp @@ -359,11 +359,9 @@ private: void SetGrassLength(int32_t length) const { - int32_t x, y; - - for (y = 0; y < MAXIMUM_MAP_SIZE_TECHNICAL; y++) + for (int32_t y = 0; y < MAXIMUM_MAP_SIZE_TECHNICAL; y++) { - for (x = 0; x < MAXIMUM_MAP_SIZE_TECHNICAL; x++) + for (int32_t x = 0; x < MAXIMUM_MAP_SIZE_TECHNICAL; x++) { auto surfaceElement = map_get_surface_element_at(TileCoordsXY{ x, y }.ToCoordsXY()); if (surfaceElement == nullptr) @@ -761,18 +759,13 @@ private: // Completely unown peep spawn points for (const auto& spawn : gPeepSpawns) { - int32_t x = spawn.x; - int32_t y = spawn.y; - if (x != PEEP_SPAWN_UNDEFINED) + auto* surfaceElement = map_get_surface_element_at(spawn); + if (surfaceElement != nullptr) { - auto* surfaceElement = map_get_surface_element_at(CoordsXY{ x, y }); - if (surfaceElement != nullptr) - { - surfaceElement->SetOwnership(OWNERSHIP_UNOWNED); - update_park_fences_around_tile({ x, y }); - uint16_t baseHeight = surfaceElement->GetBaseZ(); - map_invalidate_tile({ x, y, baseHeight, baseHeight + 16 }); - } + surfaceElement->SetOwnership(OWNERSHIP_UNOWNED); + update_park_fences_around_tile(spawn); + uint16_t baseHeight = surfaceElement->GetBaseZ(); + map_invalidate_tile({ spawn, baseHeight, baseHeight + 16 }); } } diff --git a/src/openrct2/actions/SurfaceSetStyleAction.hpp b/src/openrct2/actions/SurfaceSetStyleAction.hpp index 47f47666a7..84e8d15727 100644 --- a/src/openrct2/actions/SurfaceSetStyleAction.hpp +++ b/src/openrct2/actions/SurfaceSetStyleAction.hpp @@ -114,17 +114,18 @@ public: money32 surfaceCost = 0; money32 edgeCost = 0; - for (int32_t x = validRange.GetLeft(); x <= validRange.GetRight(); x += COORDS_XY_STEP) + for (CoordsXY coords = { validRange.GetLeft(), validRange.GetTop() }; coords.x <= validRange.GetRight(); + coords.x += COORDS_XY_STEP) { - for (int32_t y = validRange.GetTop(); y <= validRange.GetBottom(); y += COORDS_XY_STEP) + for (coords.y = validRange.GetTop(); coords.y <= validRange.GetBottom(); coords.y += COORDS_XY_STEP) { if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gCheatsSandboxMode) { - if (!map_is_location_in_park({ x, y })) + if (!map_is_location_in_park(coords)) continue; } - auto surfaceElement = map_get_surface_element_at(CoordsXY{ x, y }); + auto surfaceElement = map_get_surface_element_at(coords); if (surfaceElement == nullptr) { continue; @@ -185,17 +186,18 @@ public: money32 surfaceCost = 0; money32 edgeCost = 0; - for (int32_t x = validRange.GetLeft(); x <= validRange.GetRight(); x += COORDS_XY_STEP) + for (CoordsXY coords = { validRange.GetLeft(), validRange.GetTop() }; coords.x <= validRange.GetRight(); + coords.x += COORDS_XY_STEP) { - for (int32_t y = validRange.GetTop(); y <= validRange.GetBottom(); y += COORDS_XY_STEP) + for (coords.y = validRange.GetTop(); coords.y <= validRange.GetBottom(); coords.y += COORDS_XY_STEP) { if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gCheatsSandboxMode) { - if (!map_is_location_in_park({ x, y })) + if (!map_is_location_in_park(coords)) continue; } - auto surfaceElement = map_get_surface_element_at(CoordsXY{ x, y }); + auto surfaceElement = map_get_surface_element_at(coords); if (surfaceElement == nullptr) { continue; @@ -216,8 +218,8 @@ public: surfaceElement->SetSurfaceStyle(_surfaceStyle); - map_invalidate_tile_full({ x, y }); - footpath_remove_litter(x, y, tile_element_height({ x, y })); + map_invalidate_tile_full(coords); + footpath_remove_litter(coords.x, coords.y, tile_element_height(coords)); } } } @@ -231,14 +233,14 @@ public: edgeCost += 100; surfaceElement->SetEdgeStyle(_edgeStyle); - map_invalidate_tile_full({ x, y }); + map_invalidate_tile_full(coords); } } if (surfaceElement->CanGrassGrow() && (surfaceElement->GetGrassLength() & 7) != GRASS_LENGTH_CLEAR_0) { surfaceElement->SetGrassLength(GRASS_LENGTH_CLEAR_0); - map_invalidate_tile_full({ x, y }); + map_invalidate_tile_full(coords); } } } diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 2fa480778b..819e04696f 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -2707,13 +2707,9 @@ static void ride_call_closest_mechanic(Ride* ride) Peep* ride_find_closest_mechanic(Ride* ride, int32_t forInspection) { - int32_t x, y, z, stationIndex; - TileCoordsXYZD location; - TileElement* tileElement; - // Get either exit position or entrance position if there is no exit - stationIndex = ride->inspection_station; - location = ride_get_exit_location(ride, stationIndex); + int32_t stationIndex = ride->inspection_station; + TileCoordsXYZD location = ride_get_exit_location(ride, stationIndex); if (location.isNull()) { location = ride_get_entrance_location(ride, stationIndex); @@ -2722,21 +2718,15 @@ Peep* ride_find_closest_mechanic(Ride* ride, int32_t forInspection) } // Get station start track element and position - x = location.x; - y = location.y; - z = location.z; - tileElement = ride_get_station_exit_element(x, y, z); + auto mapLocation = location.ToCoordsXYZ(); + TileElement* tileElement = ride_get_station_exit_element(mapLocation); if (tileElement == nullptr) return nullptr; - x *= 32; - y *= 32; - // Set x,y to centre of the station exit for the mechanic search. - x += 16; - y += 16; + auto centreMapLocation = mapLocation.ToTileCentre(); - return find_closest_mechanic(x, y, forInspection); + return find_closest_mechanic(centreMapLocation.x, centreMapLocation.y, forInspection); } /** diff --git a/src/openrct2/ride/Ride.h b/src/openrct2/ride/Ride.h index c165f33ed8..d13a83c463 100644 --- a/src/openrct2/ride/Ride.h +++ b/src/openrct2/ride/Ride.h @@ -1173,7 +1173,7 @@ int32_t ride_music_params_update(CoordsXYZ rideCoords, Ride* ride, uint16_t samp void ride_music_update_final(); void ride_prepare_breakdown(Ride* ride, int32_t breakdownReason); TileElement* ride_get_station_start_track_element(Ride* ride, int32_t stationIndex); -TileElement* ride_get_station_exit_element(int32_t x, int32_t y, int32_t z); +TileElement* ride_get_station_exit_element(const CoordsXYZ& elementPos); void ride_set_status(Ride* ride, int32_t status); void ride_set_name(Ride* ride, const char* name, uint32_t flags); int32_t ride_get_refund_price(const Ride* ride); diff --git a/src/openrct2/ride/Station.cpp b/src/openrct2/ride/Station.cpp index 24d1951181..16098aacc4 100644 --- a/src/openrct2/ride/Station.cpp +++ b/src/openrct2/ride/Station.cpp @@ -318,8 +318,7 @@ static void ride_race_init_vehicle_speeds(Ride* ride) */ static void ride_invalidate_station_start(Ride* ride, int32_t stationIndex, bool greenLight) { - int32_t x = ride->stations[stationIndex].Start.x * 32; - int32_t y = ride->stations[stationIndex].Start.y * 32; + auto startPos = ride->stations[stationIndex].GetStart(); TileElement* tileElement = ride_get_station_start_track_element(ride, stationIndex); // If no station track found return @@ -329,7 +328,7 @@ static void ride_invalidate_station_start(Ride* ride, int32_t stationIndex, bool tileElement->AsTrack()->SetHasGreenLight(greenLight); // Invalidate map tile - map_invalidate_tile_zoom1({ x, y, tileElement->GetBaseZ(), tileElement->GetClearanceZ() }); + map_invalidate_tile_zoom1({ startPos, tileElement->GetBaseZ(), tileElement->GetClearanceZ() }); } TileElement* ride_get_station_start_track_element(Ride* ride, int32_t stationIndex) @@ -350,17 +349,17 @@ TileElement* ride_get_station_start_track_element(Ride* ride, int32_t stationInd return nullptr; } -TileElement* ride_get_station_exit_element(int32_t x, int32_t y, int32_t z) +TileElement* ride_get_station_exit_element(const CoordsXYZ& elementPos) { // Find the station track element - TileElement* tileElement = map_get_first_element_at(TileCoordsXY{ x, y }.ToCoordsXY()); + TileElement* tileElement = map_get_first_element_at(elementPos); if (tileElement == nullptr) return nullptr; do { if (tileElement == nullptr) break; - if (tileElement->GetType() == TILE_ELEMENT_TYPE_ENTRANCE && z == tileElement->base_height) + if (tileElement->GetType() == TILE_ELEMENT_TYPE_ENTRANCE && elementPos.z == tileElement->GetBaseZ()) return tileElement; } while (!(tileElement++)->IsLastForTile());