diff --git a/contributors.md b/contributors.md index 73253cdd2c..e106fc10c9 100644 --- a/contributors.md +++ b/contributors.md @@ -151,6 +151,7 @@ The following people are not part of the development team, but have been contrib * Sidney Kuyateh (autinerd) * Łukasz Pękalski (Lukasz-Pe) * (quale) +* Arran Ireland (ion232) ## Toolchain * (Balletie) - macOS diff --git a/src/openrct2/actions/TrackRemoveAction.hpp b/src/openrct2/actions/TrackRemoveAction.hpp index 7554d54603..50cecfede5 100644 --- a/src/openrct2/actions/TrackRemoveAction.hpp +++ b/src/openrct2/actions/TrackRemoveAction.hpp @@ -216,7 +216,7 @@ public: if (entranceDirections & TRACK_SEQUENCE_FLAG_ORIGIN && (tileElement->AsTrack()->GetSequenceIndex() == 0)) { - if (!track_remove_station_element(mapLoc.x, mapLoc.y, mapLoc.z / 8, _origin.direction, rideIndex, 0)) + if (!track_remove_station_element({ mapLoc, _origin.direction }, rideIndex, 0)) { return MakeResult(GA_ERROR::UNKNOWN, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, gGameCommandErrorText); } @@ -406,7 +406,7 @@ public: if (entranceDirections & TRACK_SEQUENCE_FLAG_ORIGIN && (tileElement->AsTrack()->GetSequenceIndex() == 0)) { - if (!track_remove_station_element(mapLoc.x, mapLoc.y, mapLoc.z / 8, _origin.direction, rideIndex, 0)) + if (!track_remove_station_element({ mapLoc, _origin.direction }, rideIndex, 0)) { return MakeResult(GA_ERROR::UNKNOWN, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, gGameCommandErrorText); } @@ -429,8 +429,7 @@ public: if (entranceDirections & TRACK_SEQUENCE_FLAG_ORIGIN && (tileElement->AsTrack()->GetSequenceIndex() == 0)) { - if (!track_remove_station_element( - mapLoc.x, mapLoc.y, mapLoc.z / 8, _origin.direction, rideIndex, GAME_COMMAND_FLAG_APPLY)) + if (!track_remove_station_element({ mapLoc, _origin.direction }, rideIndex, GAME_COMMAND_FLAG_APPLY)) { return MakeResult(GA_ERROR::UNKNOWN, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, gGameCommandErrorText); } diff --git a/src/openrct2/ride/Track.cpp b/src/openrct2/ride/Track.cpp index 76fb860939..cbc1ae7b14 100644 --- a/src/openrct2/ride/Track.cpp +++ b/src/openrct2/ride/Track.cpp @@ -797,29 +797,26 @@ bool track_add_station_element(CoordsXYZD loc, ride_id_t rideIndex, int32_t flag * * rct2: 0x006C494B */ -bool track_remove_station_element(int32_t x, int32_t y, int32_t z, Direction direction, ride_id_t rideIndex, int32_t flags) +bool track_remove_station_element(const CoordsXYZD& loc, ride_id_t rideIndex, int32_t flags) { auto ride = get_ride(rideIndex); if (ride == nullptr) return false; - int32_t removeX = x; - int32_t removeY = y; - int32_t stationX0 = x; - int32_t stationY0 = y; - int32_t stationX1 = x; - int32_t stationY1 = y; + CoordsXYZD removeLoc = loc; + CoordsXYZD stationBackLoc = loc; + CoordsXYZD stationFrontLoc = loc; int32_t stationLength = 0; int32_t byte_F441D1 = -1; if (ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_HAS_SINGLE_PIECE_STATION)) { - TileElement* tileElement = map_get_track_element_at_with_direction_from_ride({ x, y, z << 3, direction }, rideIndex); + TileElement* tileElement = map_get_track_element_at_with_direction_from_ride(loc, rideIndex); if (tileElement != nullptr) { if (flags & GAME_COMMAND_FLAG_APPLY) { - ride_remove_station(ride, { x, y, z * COORDS_Z_STEP }); + ride_remove_station(ride, loc); } } return true; @@ -828,55 +825,47 @@ bool track_remove_station_element(int32_t x, int32_t y, int32_t z, Direction dir TileElement* stationElement; // Search backwards for more station - x = stationX0; - y = stationY0; - while ((stationElement = find_station_element({ x, y, z * COORDS_Z_STEP, direction }, rideIndex)) != nullptr) + CoordsXYZD currentLoc = stationBackLoc; + while ((stationElement = find_station_element(currentLoc, rideIndex)) != nullptr) { if (stationElement->AsTrack()->GetTrackType() == TRACK_ELEM_END_STATION) { if (flags & GAME_COMMAND_FLAG_APPLY) { - ride_remove_station(ride, { x, y, z * COORDS_Z_STEP }); + ride_remove_station(ride, currentLoc); } } - stationX0 = x; - stationY0 = y; + stationBackLoc = currentLoc; byte_F441D1++; - x -= CoordsDirectionDelta[direction].x; - y -= CoordsDirectionDelta[direction].y; + currentLoc -= CoordsDirectionDelta[currentLoc.direction]; } // Search forwards for more station - x = stationX1; - y = stationY1; + currentLoc = stationFrontLoc; do { - x += CoordsDirectionDelta[direction].x; - y += CoordsDirectionDelta[direction].y; + currentLoc += CoordsDirectionDelta[currentLoc.direction]; - stationElement = find_station_element({ x, y, z * COORDS_Z_STEP, direction }, rideIndex); + stationElement = find_station_element(currentLoc, rideIndex); if (stationElement != nullptr) { if (stationElement->AsTrack()->GetTrackType() == TRACK_ELEM_END_STATION) { if (flags & GAME_COMMAND_FLAG_APPLY) { - ride_remove_station(ride, { x, y, z * COORDS_Z_STEP }); + ride_remove_station(ride, currentLoc); } } - - stationX1 = x; - stationY1 = y; + stationFrontLoc = currentLoc; stationLength++; } } while (stationElement != nullptr); if (!(flags & GAME_COMMAND_FLAG_APPLY)) { - if ((removeX != stationX0 || removeY != stationY0) && (removeX != stationX1 || removeY != stationY1) - && ride->num_stations >= MAX_STATIONS) + if ((removeLoc != stationBackLoc) && (removeLoc != stationFrontLoc) && ride->num_stations >= MAX_STATIONS) { gGameCommandErrorText = STR_NO_MORE_STATIONS_ALLOWED_ON_THIS_RIDE; return false; @@ -887,21 +876,19 @@ bool track_remove_station_element(int32_t x, int32_t y, int32_t z, Direction dir } } - x = stationX1; - y = stationY1; + currentLoc = stationFrontLoc; bool finaliseStationDone; do { finaliseStationDone = true; - if (x != removeX || y != removeY) + if (currentLoc != removeLoc) { - stationElement = find_station_element({ x, y, z * COORDS_Z_STEP, direction }, rideIndex); + stationElement = find_station_element(currentLoc, rideIndex); if (stationElement != nullptr) { int32_t targetTrackType; - if ((x == stationX1 && y == stationY1) - || (x + CoordsDirectionDelta[direction].x == removeX && y + CoordsDirectionDelta[direction].y == removeY)) + if ((currentLoc == stationFrontLoc) || (currentLoc + CoordsDirectionDelta[currentLoc.direction] == removeLoc)) { auto stationIndex = ride_get_first_empty_station_start(ride); if (stationIndex == STATION_INDEX_NULL) @@ -910,9 +897,8 @@ bool track_remove_station_element(int32_t x, int32_t y, int32_t z, Direction dir } else { - ride->stations[stationIndex].Start.x = x; - ride->stations[stationIndex].Start.y = y; - ride->stations[stationIndex].Height = z; + ride->stations[stationIndex].Start = currentLoc; + ride->stations[stationIndex].Height = currentLoc.z / COORDS_Z_STEP; ride->stations[stationIndex].Depart = 1; ride->stations[stationIndex].Length = stationLength != 0 ? stationLength : byte_F441D1; ride->num_stations++; @@ -923,13 +909,13 @@ bool track_remove_station_element(int32_t x, int32_t y, int32_t z, Direction dir } else { - if (x - CoordsDirectionDelta[direction].x == removeX && y - CoordsDirectionDelta[direction].y == removeY) + if (currentLoc - CoordsDirectionDelta[currentLoc.direction] == removeLoc) { targetTrackType = TRACK_ELEM_BEGIN_STATION; } else { - if (x == stationX0 && y == stationY0) + if (currentLoc == stationBackLoc) { targetTrackType = TRACK_ELEM_BEGIN_STATION; } @@ -941,14 +927,13 @@ bool track_remove_station_element(int32_t x, int32_t y, int32_t z, Direction dir } stationElement->AsTrack()->SetTrackType(targetTrackType); - map_invalidate_element({ x, y }, stationElement); + map_invalidate_element(currentLoc, stationElement); } } - if (x != stationX0 || y != stationY0) + if (currentLoc != stationBackLoc) { - x -= CoordsDirectionDelta[direction].x; - y -= CoordsDirectionDelta[direction].y; + currentLoc -= CoordsDirectionDelta[currentLoc.direction]; finaliseStationDone = false; } } while (!finaliseStationDone); diff --git a/src/openrct2/ride/Track.h b/src/openrct2/ride/Track.h index ce94f0ed5e..0646213ed0 100644 --- a/src/openrct2/ride/Track.h +++ b/src/openrct2/ride/Track.h @@ -580,7 +580,7 @@ roll_type_t track_get_actual_bank_2(int32_t rideType, bool isInverted, roll_type roll_type_t track_get_actual_bank_3(bool useInvertedSprites, TileElement* tileElement); bool track_add_station_element(CoordsXYZD loc, ride_id_t rideIndex, int32_t flags, bool fromTrackDesign); -bool track_remove_station_element(int32_t x, int32_t y, int32_t z, Direction direction, ride_id_t rideIndex, int32_t flags); +bool track_remove_station_element(const CoordsXYZD& loc, ride_id_t rideIndex, int32_t flags); money32 maze_set_track( uint16_t x, uint16_t y, uint16_t z, uint8_t flags, bool initialPlacement, uint8_t direction, ride_id_t rideIndex, diff --git a/src/openrct2/world/Location.hpp b/src/openrct2/world/Location.hpp index 7f69b12970..b29f8cf5b5 100644 --- a/src/openrct2/world/Location.hpp +++ b/src/openrct2/world/Location.hpp @@ -553,6 +553,11 @@ struct CoordsXYZD : public CoordsXYZ return { x + rhs.x, y + rhs.y, z + rhs.z, direction }; } + const CoordsXYZD operator-(const CoordsXY& rhs) const + { + return { x - rhs.x, y - rhs.y, z, direction }; + } + const CoordsXYZD operator-(const CoordsXYZ& rhs) const { return { x - rhs.x, y - rhs.y, z - rhs.z, direction };