diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index b48867fdbf..70739ca8bf 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -2468,18 +2468,19 @@ static rct_string_id WindowRideGetStatusStation(rct_window* w, Formatter& ft) return STR_NONE; } + const auto& station = ride->GetStation(*stationIndex); rct_string_id stringId = STR_EMPTY; // Entrance / exit if (ride->status == RideStatus::Closed) { - if (ride_get_entrance_location(ride, *stationIndex).IsNull()) + if (station.Entrance.IsNull()) stringId = STR_NO_ENTRANCE; - else if (ride_get_exit_location(ride, *stationIndex).IsNull()) + else if (station.Exit.IsNull()) stringId = STR_NO_EXIT; } else { - if (ride_get_entrance_location(ride, *stationIndex).IsNull()) + if (station.Entrance.IsNull()) stringId = STR_EXIT_ONLY; } // Queue length diff --git a/src/openrct2/actions/RideEntranceExitPlaceAction.cpp b/src/openrct2/actions/RideEntranceExitPlaceAction.cpp index 6c22785ffb..392368957d 100644 --- a/src/openrct2/actions/RideEntranceExitPlaceAction.cpp +++ b/src/openrct2/actions/RideEntranceExitPlaceAction.cpp @@ -75,7 +75,8 @@ GameActions::Result RideEntranceExitPlaceAction::Query() const return GameActions::Result(GameActions::Status::Disallowed, errorTitle, STR_NOT_ALLOWED_TO_MODIFY_STATION); } - const auto location = _isExit ? ride_get_exit_location(ride, _stationNum) : ride_get_entrance_location(ride, _stationNum); + const auto& station = ride->GetStation(_stationNum); + const auto location = _isExit ? station.Exit : station.Entrance; if (!location.IsNull()) { @@ -145,7 +146,8 @@ GameActions::Result RideEntranceExitPlaceAction::Execute() const ride->RemovePeeps(); } - const auto location = _isExit ? ride_get_exit_location(ride, _stationNum) : ride_get_entrance_location(ride, _stationNum); + auto& station = ride->GetStation(_stationNum); + const auto location = _isExit ? station.Exit : station.Entrance; if (!location.IsNull()) { auto rideEntranceExitRemove = RideEntranceExitRemoveAction(location.ToCoordsXY(), _rideIndex, _stationNum, _isExit); @@ -159,7 +161,7 @@ GameActions::Result RideEntranceExitPlaceAction::Execute() const } } - auto z = ride->GetStation(_stationNum).GetBaseZ(); + auto z = station.GetBaseZ(); if (!(GetFlags() & GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED) && !(GetFlags() & GAME_COMMAND_FLAG_GHOST)) { footpath_remove_litter({ _loc, z }); @@ -191,13 +193,13 @@ GameActions::Result RideEntranceExitPlaceAction::Execute() const if (_isExit) { - ride_set_exit_location(ride, _stationNum, TileCoordsXYZD(CoordsXYZD{ _loc, z, entranceElement->GetDirection() })); + station.Exit = TileCoordsXYZD(CoordsXYZD{ _loc, z, entranceElement->GetDirection() }); } else { - ride_set_entrance_location(ride, _stationNum, TileCoordsXYZD(CoordsXYZD{ _loc, z, entranceElement->GetDirection() })); - ride->GetStation(_stationNum).LastPeepInQueue = EntityId::GetNull(); - ride->GetStation(_stationNum).QueueLength = 0; + station.Entrance = TileCoordsXYZD(CoordsXYZD{ _loc, z, entranceElement->GetDirection() }); + station.LastPeepInQueue = EntityId::GetNull(); + station.QueueLength = 0; map_animation_create(MAP_ANIMATION_TYPE_RIDE_ENTRANCE, { _loc, z }); } diff --git a/src/openrct2/actions/RideEntranceExitRemoveAction.cpp b/src/openrct2/actions/RideEntranceExitRemoveAction.cpp index 31086e237a..b43647e6dd 100644 --- a/src/openrct2/actions/RideEntranceExitRemoveAction.cpp +++ b/src/openrct2/actions/RideEntranceExitRemoveAction.cpp @@ -146,13 +146,14 @@ GameActions::Result RideEntranceExitRemoveAction::Execute() const tile_element_remove(entranceElement); + auto& station = ride->GetStation(_stationNum); if (_isExit) { - ride_clear_exit_location(ride, _stationNum); + station.Exit.SetNull(); } else { - ride_clear_entrance_location(ride, _stationNum); + station.Entrance.SetNull(); } footpath_update_queue_chains(); diff --git a/src/openrct2/entity/Guest.cpp b/src/openrct2/entity/Guest.cpp index 8c2d086473..0944ef5dc7 100644 --- a/src/openrct2/entity/Guest.cpp +++ b/src/openrct2/entity/Guest.cpp @@ -2474,14 +2474,14 @@ static void peep_choose_seat_from_car(Peep* peep, Ride* ride, Vehicle* vehicle) */ void Guest::GoToRideEntrance(Ride* ride) { - TileCoordsXYZD tileLocation = ride_get_entrance_location(ride, CurrentRideStation); - if (tileLocation.IsNull()) + const auto& station = ride->GetStation(CurrentRideStation); + if (station.Entrance.IsNull()) { RemoveFromQueue(); return; } - auto location = tileLocation.ToCoordsXYZD().ToTileCentre(); + auto location = station.Entrance.ToCoordsXYZD().ToTileCentre(); int16_t x_shift = DirectionOffsets[location.direction].x; int16_t y_shift = DirectionOffsets[location.direction].y; @@ -3430,7 +3430,8 @@ void Guest::UpdateRideAtEntrance() int16_t actionZ = z; if (xy_distance < 16) { - auto entrance = ride_get_entrance_location(ride, CurrentRideStation).ToCoordsXYZ(); + const auto& station = ride->GetStation(CurrentRideStation); + auto entrance = station.Entrance.ToCoordsXYZ(); actionZ = entrance.z + 2; } MoveTo({ loc.value(), actionZ }); @@ -3564,9 +3565,9 @@ uint8_t Guest::GetWaypointedSeatLocation(const Ride& ride, rct_ride_entry_vehicl void Guest::UpdateRideLeaveEntranceWaypoints(const Ride& ride) { - TileCoordsXYZD entranceLocation = ride_get_entrance_location(&ride, CurrentRideStation); - Guard::Assert(!entranceLocation.IsNull()); - uint8_t direction_entrance = entranceLocation.direction; + const auto& station = ride.GetStation(CurrentRideStation); + Guard::Assert(!station.Entrance.IsNull()); + uint8_t direction_entrance = station.Entrance.direction; CoordsXY waypoint = ride.GetStation(CurrentRideStation).Start.ToTileCentre(); @@ -3647,7 +3648,8 @@ void Guest::UpdateRideAdvanceThroughEntrance() Guard::Assert(RideSubState == PeepRideSubState::LeaveEntrance, "Peep ridesubstate should be LeaveEntrance"); if (ride->GetRideTypeDescriptor().HasFlag(RIDE_TYPE_FLAG_NO_VEHICLES)) { - auto entranceLocation = ride_get_entrance_location(ride, CurrentRideStation).ToCoordsXYZD(); + const auto& station = ride->GetStation(CurrentRideStation); + auto entranceLocation = station.Entrance.ToCoordsXYZD(); Guard::Assert(!entranceLocation.IsNull()); if (ride->type == RIDE_TYPE_MAZE) @@ -3757,7 +3759,7 @@ static void peep_go_to_ride_exit(Peep* peep, Ride* ride, int16_t x, int16_t y, i peep->MoveTo({ x, y, z }); Guard::Assert(peep->CurrentRideStation.ToUnderlying() < OpenRCT2::Limits::MaxStationsPerRide); - auto exit = ride_get_exit_location(ride, peep->CurrentRideStation); + auto exit = ride->GetStation(peep->CurrentRideStation).Exit; Guard::Assert(!exit.IsNull()); x = exit.x; y = exit.y; @@ -3861,7 +3863,7 @@ void Guest::UpdateRideFreeVehicleEnterRide(Ride* ride) */ static void peep_update_ride_no_free_vehicle_rejoin_queue(Guest* peep, Ride* ride) { - TileCoordsXYZD entranceLocation = ride_get_entrance_location(ride, peep->CurrentRideStation); + TileCoordsXYZD entranceLocation = ride->GetStation(peep->CurrentRideStation).Entrance; int32_t x = entranceLocation.x * 32; int32_t y = entranceLocation.y * 32; @@ -4283,10 +4285,8 @@ void Guest::UpdateRidePrepareForExit() if (ride == nullptr || CurrentRideStation.ToUnderlying() >= std::size(ride->GetStations())) return; - auto exit = ride_get_exit_location(ride, CurrentRideStation); - + auto exit = ride->GetStation(CurrentRideStation).Exit; auto newDestination = exit.ToCoordsXY().ToTileCentre(); - auto xShift = DirectionOffsets[exit.direction].x; auto yShift = DirectionOffsets[exit.direction].y; @@ -4514,7 +4514,7 @@ void Guest::UpdateRideApproachExitWaypoints() Var37 |= 3; - auto targetLoc = ride_get_exit_location(ride, CurrentRideStation).ToCoordsXYZD().ToTileCentre(); + auto targetLoc = ride->GetStation(CurrentRideStation).Exit.ToCoordsXYZD().ToTileCentre(); uint8_t exit_direction = direction_reverse(targetLoc.direction); int16_t x_shift = DirectionOffsets[exit_direction].x; @@ -4583,7 +4583,7 @@ void Guest::UpdateRideApproachSpiralSlide() if (lastRide) { - auto exit = ride_get_exit_location(ride, CurrentRideStation); + auto exit = ride->GetStation(CurrentRideStation).Exit; waypoint = 1; Var37 = (exit.direction * 4) | (Var37 & 0x30) | waypoint; CoordsXY targetLoc = ride->GetStation(CurrentRideStation).Start; @@ -4746,7 +4746,7 @@ void Guest::UpdateRideLeaveSpiralSlide() // Actually force the final waypoint Var37 |= 3; - auto targetLoc = ride_get_exit_location(ride, CurrentRideStation).ToCoordsXYZD().ToTileCentre(); + auto targetLoc = ride->GetStation(CurrentRideStation).Exit.ToCoordsXYZD().ToTileCentre(); int16_t xShift = DirectionOffsets[direction_reverse(targetLoc.direction)].x; int16_t yShift = DirectionOffsets[direction_reverse(targetLoc.direction)].y; diff --git a/src/openrct2/entity/Staff.cpp b/src/openrct2/entity/Staff.cpp index adf1da23c3..141cf2d9d5 100644 --- a/src/openrct2/entity/Staff.cpp +++ b/src/openrct2/entity/Staff.cpp @@ -685,10 +685,10 @@ Direction Staff::MechanicDirectionSurface() const auto ride = get_ride(CurrentRide); if (ride != nullptr && (State == PeepState::Answering || State == PeepState::HeadingToInspection) && (scenario_rand() & 1)) { - auto location = ride_get_exit_location(ride, CurrentRideStation); + auto location = ride->GetStation(CurrentRideStation).Exit; if (location.IsNull()) { - location = ride_get_entrance_location(ride, CurrentRideStation); + location = ride->GetStation(CurrentRideStation).Entrance; } direction = DirectionFromTo(CoordsXY(x, y), location.ToCoordsXY()); @@ -766,10 +766,10 @@ Direction Staff::MechanicDirectionPath(uint8_t validDirections, PathElement* pat { /* Find location of the exit for the target ride station * or if the ride has no exit, the entrance. */ - TileCoordsXYZD location = ride_get_exit_location(ride, CurrentRideStation); + TileCoordsXYZD location = ride->GetStation(CurrentRideStation).Exit; if (location.IsNull()) { - location = ride_get_entrance_location(ride, CurrentRideStation); + location = ride->GetStation(CurrentRideStation).Entrance; // If no entrance is present either. This is an incorrect state. if (location.IsNull()) @@ -1354,7 +1354,7 @@ void Staff::UpdateHeadingToInspect() return; } - if (ride_get_exit_location(ride, CurrentRideStation).IsNull()) + if (ride->GetStation(CurrentRideStation).Exit.IsNull()) { ride->lifecycle_flags &= ~RIDE_LIFECYCLE_DUE_INSPECTION; SetState(PeepState::Falling); @@ -1408,7 +1408,7 @@ void Staff::UpdateHeadingToInspect() if (pathingResult & PATHING_RIDE_ENTRANCE) { - if (!ride_get_exit_location(ride, exitIndex).IsNull()) + if (!ride->GetStation(exitIndex).Exit.IsNull()) { return; } @@ -1513,7 +1513,7 @@ void Staff::UpdateAnswering() if (pathingResult & PATHING_RIDE_ENTRANCE) { - if (!ride_get_exit_location(ride, exitIndex).IsNull()) + if (!ride->GetStation(exitIndex).Exit.IsNull()) { return; } @@ -2474,10 +2474,10 @@ bool Staff::UpdateFixingMoveToStationExit(bool firstRun, const Ride* ride) { if (!firstRun) { - auto stationPosition = ride_get_exit_location(ride, CurrentRideStation).ToCoordsXY(); + auto stationPosition = ride->GetStation(CurrentRideStation).Exit.ToCoordsXY(); if (stationPosition.IsNull()) { - stationPosition = ride_get_entrance_location(ride, CurrentRideStation).ToCoordsXY(); + stationPosition = ride->GetStation(CurrentRideStation).Entrance.ToCoordsXY(); if (stationPosition.IsNull()) { @@ -2554,10 +2554,10 @@ bool Staff::UpdateFixingLeaveByEntranceExit(bool firstRun, const Ride* ride) { if (!firstRun) { - auto exitPosition = ride_get_exit_location(ride, CurrentRideStation).ToCoordsXY(); + auto exitPosition = ride->GetStation(CurrentRideStation).Exit.ToCoordsXY(); if (exitPosition.IsNull()) { - exitPosition = ride_get_entrance_location(ride, CurrentRideStation).ToCoordsXY(); + exitPosition = ride->GetStation(CurrentRideStation).Entrance.ToCoordsXY(); if (exitPosition.IsNull()) { diff --git a/src/openrct2/peep/GuestPathfinding.cpp b/src/openrct2/peep/GuestPathfinding.cpp index 1c944fa684..3b4056ad3f 100644 --- a/src/openrct2/peep/GuestPathfinding.cpp +++ b/src/openrct2/peep/GuestPathfinding.cpp @@ -2182,18 +2182,18 @@ int32_t guest_path_finding(Guest* peep) int32_t numEntranceStations = 0; BitSet entranceStations = {}; - for (StationIndex::UnderlyingType stationNum = 0; stationNum < OpenRCT2::Limits::MaxStationsPerRide; ++stationNum) + for (const auto& station : ride->GetStations()) { - const auto stationIndex = StationIndex::FromUnderlying(stationNum); - // Skip if stationNum has no entrance (so presumably an exit only station) - if (ride_get_entrance_location(ride, stationIndex).IsNull()) + if (station.Entrance.IsNull()) continue; - numEntranceStations++; - entranceStations[stationNum] = true; + const auto stationIndex = ride->GetStationIndex(&station); - TileCoordsXYZD entranceLocation = ride_get_entrance_location(ride, stationIndex); + numEntranceStations++; + entranceStations[stationIndex.ToUnderlying()] = true; + + TileCoordsXYZD entranceLocation = station.Entrance; auto score = CalculateHeuristicPathingScore(entranceLocation, TileCoordsXYZ{ peep->NextLoc }); if (score < bestScore) { @@ -2223,7 +2223,7 @@ int32_t guest_path_finding(Guest* peep) } else { - TileCoordsXYZD entranceXYZD = ride_get_entrance_location(ride, closestStationNum); + TileCoordsXYZD entranceXYZD = ride->GetStation(closestStationNum).Entrance; loc.x = entranceXYZD.x; loc.y = entranceXYZD.y; loc.z = entranceXYZD.z; diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 84b0a5162a..0c0a8cf09a 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -844,53 +844,49 @@ namespace RCT1 for (StationIndex::UnderlyingType i = 0; i < Limits::MaxStationsPerRide; i++) { - const StationIndex stationIndex = StationIndex::FromUnderlying(i); + auto& dstStation = dst->GetStation(StationIndex::FromUnderlying(i)); if (src->station_starts[i].IsNull()) { - dst->GetStation(stationIndex).Start.SetNull(); + dstStation.Start.SetNull(); } else { auto tileStartLoc = TileCoordsXY{ src->station_starts[i].x, src->station_starts[i].y }; - dst->GetStation(stationIndex).Start = tileStartLoc.ToCoordsXY(); + dstStation.Start = tileStartLoc.ToCoordsXY(); } - dst->GetStation(stationIndex).SetBaseZ(src->station_height[i] * Limits::CoordsZStep); - dst->GetStation(stationIndex).Length = src->station_length[i]; - dst->GetStation(stationIndex).Depart = src->station_light[i]; + dstStation.SetBaseZ(src->station_height[i] * Limits::CoordsZStep); + dstStation.Length = src->station_length[i]; + dstStation.Depart = src->station_light[i]; - dst->GetStation(stationIndex).TrainAtStation = src->station_depart[i]; + dstStation.TrainAtStation = src->station_depart[i]; // Direction is fixed later. if (src->entrance[i].IsNull()) - ride_clear_entrance_location(dst, StationIndex::FromUnderlying(i)); + dstStation.Entrance.SetNull(); else - ride_set_entrance_location( - dst, StationIndex::FromUnderlying(i), - { src->entrance[i].x, src->entrance[i].y, src->station_height[i] / 2, 0 }); + dstStation.Entrance = { src->entrance[i].x, src->entrance[i].y, src->station_height[i] / 2, 0 }; if (src->exit[i].IsNull()) - ride_clear_exit_location(dst, StationIndex::FromUnderlying(i)); + dstStation.Exit.SetNull(); else - ride_set_exit_location( - dst, StationIndex::FromUnderlying(i), - { src->exit[i].x, src->exit[i].y, src->station_height[i] / 2, 0 }); + dstStation.Exit = { src->exit[i].x, src->exit[i].y, src->station_height[i] / 2, 0 }; - dst->GetStation(stationIndex).QueueTime = src->queue_time[i]; - dst->GetStation(stationIndex).LastPeepInQueue = EntityId::FromUnderlying(src->last_peep_in_queue[i]); - dst->GetStation(stationIndex).QueueLength = src->num_peeps_in_queue[i]; + dstStation.QueueTime = src->queue_time[i]; + dstStation.LastPeepInQueue = EntityId::FromUnderlying(src->last_peep_in_queue[i]); + dstStation.QueueLength = src->num_peeps_in_queue[i]; - dst->GetStation(stationIndex).SegmentTime = src->time[i]; - dst->GetStation(stationIndex).SegmentLength = src->length[i]; + dstStation.SegmentTime = src->time[i]; + dstStation.SegmentLength = src->length[i]; } // All other values take 0 as their default. Since they're already memset to that, no need to do it again. for (int32_t i = Limits::MaxStationsPerRide; i < OpenRCT2::Limits::MaxStationsPerRide; i++) { - const StationIndex stationIndex = StationIndex::FromUnderlying(i); - dst->GetStation(stationIndex).Start.SetNull(); - dst->GetStation(stationIndex).TrainAtStation = RideStation::NO_TRAIN; - ride_clear_entrance_location(dst, StationIndex::FromUnderlying(i)); - ride_clear_exit_location(dst, StationIndex::FromUnderlying(i)); - dst->GetStation(stationIndex).LastPeepInQueue = EntityId::GetNull(); + auto& dstStation = dst->GetStation(StationIndex::FromUnderlying(i)); + dstStation.Start.SetNull(); + dstStation.TrainAtStation = RideStation::NO_TRAIN; + dstStation.Entrance.SetNull(); + dstStation.Exit.SetNull(); + dstStation.LastPeepInQueue = EntityId::GetNull(); } dst->num_stations = src->num_stations; diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index ff4d54f723..0719444af2 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -698,17 +698,14 @@ namespace RCT2 // Direction is fixed later. if (src->entrances[i].IsNull()) - ride_clear_entrance_location(dst, StationIndex::FromUnderlying(i)); + destStation.Entrance.SetNull(); else - ride_set_entrance_location( - dst, StationIndex::FromUnderlying(i), - { src->entrances[i].x, src->entrances[i].y, src->station_heights[i], 0 }); + destStation.Entrance = { src->entrances[i].x, src->entrances[i].y, src->station_heights[i], 0 }; if (src->exits[i].IsNull()) - ride_clear_exit_location(dst, StationIndex::FromUnderlying(i)); + destStation.Exit.SetNull(); else - ride_set_exit_location( - dst, StationIndex::FromUnderlying(i), { src->exits[i].x, src->exits[i].y, src->station_heights[i], 0 }); + destStation.Exit = { src->exits[i].x, src->exits[i].y, src->station_heights[i], 0 }; destStation.LastPeepInQueue = EntityId::FromUnderlying(src->last_peep_in_queue[i]); @@ -727,8 +724,8 @@ namespace RCT2 destStation.Start.SetNull(); destStation.TrainAtStation = RideStation::NO_TRAIN; - ride_clear_entrance_location(dst, StationIndex::FromUnderlying(i)); - ride_clear_exit_location(dst, StationIndex::FromUnderlying(i)); + destStation.Entrance.SetNull(); + destStation.Exit.SetNull(); destStation.LastPeepInQueue = EntityId::GetNull(); } diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 93d50562cf..a63708af37 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -1692,12 +1692,12 @@ static void ride_call_closest_mechanic(Ride* ride) Staff* ride_find_closest_mechanic(Ride* ride, int32_t forInspection) { // Get either exit position or entrance position if there is no exit - auto stationIndex = ride->inspection_station; - TileCoordsXYZD location = ride_get_exit_location(ride, stationIndex); + auto& station = ride->GetStation(ride->inspection_station); + TileCoordsXYZD location = station.Exit; if (location.IsNull()) { - location = ride_get_entrance_location(ride, stationIndex); - if (location.IsNull()) + location = station.Entrance; + if (station.Entrance.IsNull()) return nullptr; } @@ -2428,7 +2428,7 @@ static void ride_entrance_set_map_tooltip(TileElement* tileElement) { // Get the queue length int32_t queueLength = 0; - if (!ride_get_entrance_location(ride, stationIndex).IsNull()) + if (!ride->GetStation(stationIndex).Entrance.IsNull()) queueLength = ride->GetStation(stationIndex).QueueLength; auto ft = Formatter(); @@ -5580,9 +5580,9 @@ void determine_ride_entrance_and_exit_locations() for (auto& ride : GetRideManager()) { - for (StationIndex::UnderlyingType stationIndex = 0; stationIndex < OpenRCT2::Limits::MaxStationsPerRide; stationIndex++) + for (auto& station : ride.GetStations()) { - auto& station = ride.GetStation(StationIndex::FromUnderlying(stationIndex)); + auto stationIndex = ride.GetStationIndex(&station); TileCoordsXYZD entranceLoc = station.Entrance; TileCoordsXYZD exitLoc = station.Exit; bool fixEntrance = false; @@ -5594,7 +5594,7 @@ void determine_ride_entrance_and_exit_locations() const EntranceElement* entranceElement = map_get_ride_entrance_element_at(entranceLoc.ToCoordsXYZD(), false); if (entranceElement == nullptr || entranceElement->GetRideIndex() != ride.id - || entranceElement->GetStationIndex() != StationIndex::FromUnderlying(stationIndex)) + || entranceElement->GetStationIndex() != stationIndex) { fixEntrance = true; } @@ -5609,7 +5609,7 @@ void determine_ride_entrance_and_exit_locations() const EntranceElement* entranceElement = map_get_ride_exit_element_at(exitLoc.ToCoordsXYZD(), false); if (entranceElement == nullptr || entranceElement->GetRideIndex() != ride.id - || entranceElement->GetStationIndex() != StationIndex::FromUnderlying(stationIndex)) + || entranceElement->GetStationIndex() != stationIndex) { fixExit = true; } @@ -5647,7 +5647,7 @@ void determine_ride_entrance_and_exit_locations() { continue; } - if (entranceElement->GetStationIndex() != StationIndex::FromUnderlying(stationIndex)) + if (entranceElement->GetStationIndex() != stationIndex) { continue; } @@ -5666,13 +5666,8 @@ void determine_ride_entrance_and_exit_locations() } // Found our entrance - TileCoordsXYZD newEntranceLoc = { - x, - y, - entranceElement->base_height, - static_cast(entranceElement->GetDirection()), - }; - ride_set_entrance_location(&ride, StationIndex::FromUnderlying(stationIndex), newEntranceLoc); + station.Entrance = { x, y, entranceElement->base_height, + static_cast(entranceElement->GetDirection()) }; alreadyFoundEntrance = true; log_verbose( @@ -5690,10 +5685,8 @@ void determine_ride_entrance_and_exit_locations() } // Found our exit - ride_set_exit_location( - &ride, StationIndex::FromUnderlying(stationIndex), - { x, y, entranceElement->base_height, - static_cast(entranceElement->GetDirection()) }); + station.Exit = { x, y, entranceElement->base_height, + static_cast(entranceElement->GetDirection()) }; alreadyFoundExit = true; log_verbose( @@ -5707,12 +5700,12 @@ void determine_ride_entrance_and_exit_locations() if (fixEntrance && !alreadyFoundEntrance) { - ride_clear_entrance_location(&ride, StationIndex::FromUnderlying(stationIndex)); + station.Entrance.SetNull(); log_verbose("Cleared disconnected entrance of ride %d, station %d.", ride.id, stationIndex); } if (fixExit && !alreadyFoundExit) { - ride_clear_exit_location(&ride, StationIndex::FromUnderlying(stationIndex)); + station.Exit.SetNull(); log_verbose("Cleared disconnected exit of ride %d, station %d.", ride.id, stationIndex); } } diff --git a/src/openrct2/ride/RideConstruction.cpp b/src/openrct2/ride/RideConstruction.cpp index bf99969bc3..01b88f6254 100644 --- a/src/openrct2/ride/RideConstruction.cpp +++ b/src/openrct2/ride/RideConstruction.cpp @@ -261,7 +261,7 @@ void Ride::RemovePeeps() auto exitPosition = CoordsXYZD{ 0, 0, 0, INVALID_DIRECTION }; if (!stationIndex.IsNull()) { - auto location = ride_get_exit_location(this, stationIndex).ToCoordsXYZD(); + auto location = GetStation(stationIndex).Exit.ToCoordsXYZD(); if (!location.IsNull()) { auto direction = direction_reverse(location.direction); @@ -1542,23 +1542,25 @@ void Ride::ValidateStations() stationId = trackElement->AsTrack()->GetStationIndex(); } + + auto& station = GetStation(stationId); if (tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_RIDE_EXIT) { // if the location is already set for this station, big problem! - if (!ride_get_exit_location(this, stationId).IsNull()) + if (!station.Exit.IsNull()) break; // set the station's exit location to this one - CoordsXYZD loc = { location, stations[stationId.ToUnderlying()].GetBaseZ(), tileElement->GetDirection() }; - ride_set_exit_location(this, stationId, TileCoordsXYZD{ loc }); + CoordsXYZD loc = { location, station.GetBaseZ(), tileElement->GetDirection() }; + station.Exit = TileCoordsXYZD{ loc }; } else { // if the location is already set for this station, big problem! - if (!ride_get_entrance_location(this, stationId).IsNull()) + if (!station.Entrance.IsNull()) break; // set the station's entrance location to this one - CoordsXYZD loc = { location, stations[stationId.ToUnderlying()].GetBaseZ(), tileElement->GetDirection() }; - ride_set_entrance_location(this, stationId, TileCoordsXYZD{ loc }); + CoordsXYZD loc = { location, station.GetBaseZ(), tileElement->GetDirection() }; + station.Entrance = TileCoordsXYZD{ loc }; } // set the entrance's StationIndex as this station tileElement->AsEntrance()->SetStationIndex(stationId); diff --git a/src/openrct2/ride/RideRatings.cpp b/src/openrct2/ride/RideRatings.cpp index 8cad20a952..9ff01a8ce9 100644 --- a/src/openrct2/ride/RideRatings.cpp +++ b/src/openrct2/ride/RideRatings.cpp @@ -238,7 +238,7 @@ static void ride_ratings_update_state_2(RideRatingUpdateState& state) { auto entranceIndex = tileElement->AsTrack()->GetStationIndex(); state.StationFlags &= ~RIDE_RATING_STATION_FLAG_NO_ENTRANCE; - if (ride_get_entrance_location(ride, entranceIndex).IsNull()) + if (ride->GetStation(entranceIndex).Entrance.IsNull()) { state.StationFlags |= RIDE_RATING_STATION_FLAG_NO_ENTRANCE; } @@ -1437,7 +1437,7 @@ static int32_t ride_ratings_get_scenery_score(Ride* ride) if (ride->type == RIDE_TYPE_MAZE) { - location = ride_get_entrance_location(ride, StationIndex::FromUnderlying(0)).ToCoordsXY(); + location = ride->GetStation().Entrance.ToCoordsXY(); } else { diff --git a/src/openrct2/ride/Station.cpp b/src/openrct2/ride/Station.cpp index 5524c32153..52ea593499 100644 --- a/src/openrct2/ride/Station.cpp +++ b/src/openrct2/ride/Station.cpp @@ -404,36 +404,6 @@ StationIndex ride_get_first_empty_station_start(const Ride* ride) return StationIndex::GetNull(); } -TileCoordsXYZD ride_get_entrance_location(const Ride* ride, const StationIndex stationIndex) -{ - return ride->GetStation(stationIndex).Entrance; -} - -TileCoordsXYZD ride_get_exit_location(const Ride* ride, const StationIndex stationIndex) -{ - return ride->GetStation(stationIndex).Exit; -} - -void ride_clear_entrance_location(Ride* ride, const StationIndex stationIndex) -{ - ride->GetStation(stationIndex).Entrance.SetNull(); -} - -void ride_clear_exit_location(Ride* ride, const StationIndex stationIndex) -{ - ride->GetStation(stationIndex).Exit.SetNull(); -} - -void ride_set_entrance_location(Ride* ride, const StationIndex stationIndex, const TileCoordsXYZD& location) -{ - ride->GetStation(stationIndex).Entrance = location; -} - -void ride_set_exit_location(Ride* ride, const StationIndex stationIndex, const TileCoordsXYZD& location) -{ - ride->GetStation(stationIndex).Exit = location; -} - int32_t RideStation::GetBaseZ() const { return Height * COORDS_Z_STEP; diff --git a/src/openrct2/ride/Station.h b/src/openrct2/ride/Station.h index 5b25649514..91b9f007b7 100644 --- a/src/openrct2/ride/Station.h +++ b/src/openrct2/ride/Station.h @@ -19,12 +19,3 @@ void ride_update_station(Ride* ride, StationIndex stationIndex); StationIndex ride_get_first_valid_station_exit(Ride* ride); StationIndex ride_get_first_valid_station_start(const Ride* ride); StationIndex ride_get_first_empty_station_start(const Ride* ride); - -TileCoordsXYZD ride_get_entrance_location(const Ride* ride, const StationIndex stationIndex); -TileCoordsXYZD ride_get_exit_location(const Ride* ride, const StationIndex stationIndex); - -void ride_clear_entrance_location(Ride* ride, const StationIndex stationIndex); -void ride_clear_exit_location(Ride* ride, const StationIndex stationIndex); - -void ride_set_entrance_location(Ride* ride, const StationIndex stationIndex, const TileCoordsXYZD& location); -void ride_set_exit_location(Ride* ride, const StationIndex stationIndex, const TileCoordsXYZD& location); diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index bff57c1936..586588e485 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -374,7 +374,7 @@ rct_string_id TrackDesign::CreateTrackDesignMaze(TrackDesignState& tds, const Ri x = 0; } - auto location = ride_get_entrance_location(&ride, StationIndex::FromUnderlying(0)); + auto location = ride.GetStation().Entrance; if (location.IsNull()) { return STR_TRACK_TOO_LARGE_OR_TOO_MUCH_SCENERY; @@ -403,7 +403,7 @@ rct_string_id TrackDesign::CreateTrackDesignMaze(TrackDesignState& tds, const Ri mazeEntrance.y = static_cast((entranceLoc.y - startLoc.y) / 32); maze_elements.push_back(mazeEntrance); - location = ride_get_exit_location(&ride, StationIndex::FromUnderlying(0)); + location = ride.GetStation().Exit; if (location.IsNull()) { return STR_TRACK_TOO_LARGE_OR_TOO_MUCH_SCENERY; diff --git a/src/openrct2/ride/TrackPaint.cpp b/src/openrct2/ride/TrackPaint.cpp index 51a84a1bef..9435290e54 100644 --- a/src/openrct2/ride/TrackPaint.cpp +++ b/src/openrct2/ride/TrackPaint.cpp @@ -255,12 +255,10 @@ bool track_paint_util_has_fence( } auto entranceLoc = TileCoordsXY(position) + offset; - auto entranceId = trackElement.GetStationIndex(); - const TileCoordsXYZD entrance = ride_get_entrance_location(&ride, entranceId); - const TileCoordsXYZD exit = ride_get_exit_location(&ride, entranceId); + const auto& station = ride.GetStation(entranceId); - return (entranceLoc != entrance && entranceLoc != exit); + return (entranceLoc != station.Entrance && entranceLoc != station.Exit); } void track_paint_util_paint_floor( diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 00c9c56040..ef8e5a8a5a 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -1434,7 +1434,8 @@ void Vehicle::UpdateMeasurements() if (curRide->current_test_station.IsNull()) return; - if (!ride_get_entrance_location(curRide, curRide->current_test_station).IsNull()) + const auto& currentStation = curRide->GetStation(curRide->current_test_station); + if (!currentStation.Entrance.IsNull()) { uint8_t test_segment = curRide->current_test_segment; StationIndex stationIndex = StationIndex::FromUnderlying(test_segment); @@ -1494,7 +1495,7 @@ void Vehicle::UpdateMeasurements() { curRide->CurTestTrackLocation = curTrackLoc; - if (ride_get_entrance_location(curRide, curRide->current_test_station).IsNull()) + if (currentStation.Entrance.IsNull()) return; auto trackElemType = GetTrackType(); @@ -1710,7 +1711,7 @@ void Vehicle::UpdateMeasurements() } } - if (ride_get_entrance_location(curRide, curRide->current_test_station).IsNull()) + if (currentStation.Entrance.IsNull()) return; if (x == LOCATION_NULL) @@ -2360,10 +2361,12 @@ void Vehicle::UpdateDodgemsMode() */ void Vehicle::UpdateWaitingToDepart() { - auto curRide = GetRide(); + auto* curRide = GetRide(); if (curRide == nullptr) return; + const auto& currentStation = curRide->GetStation(curRide->current_test_station); + bool shouldBreak = false; if (curRide->lifecycle_flags & RIDE_LIFECYCLE_BROKEN_DOWN) { @@ -2395,7 +2398,7 @@ void Vehicle::UpdateWaitingToDepart() } else { - if (!ride_get_exit_location(curRide, current_station).IsNull()) + if (!currentStation.Exit.IsNull()) { SetState(Vehicle::Status::UnloadingPassengers); return; @@ -2409,7 +2412,7 @@ void Vehicle::UpdateWaitingToDepart() { if (trainCar->num_peeps != 0) { - if (!ride_get_exit_location(curRide, current_station).IsNull()) + if (!currentStation.Exit.IsNull()) { SetState(Vehicle::Status::UnloadingPassengers); return; @@ -2422,7 +2425,7 @@ void Vehicle::UpdateWaitingToDepart() if (!skipCheck) { - if (!(curRide->GetStation(current_station).Depart & STATION_DEPART_FLAG)) + if (!(currentStation.Depart & STATION_DEPART_FLAG)) return; } @@ -3998,10 +4001,12 @@ void Vehicle::UpdateUnloadingPassengers() } } - auto curRide = GetRide(); + const auto* curRide = GetRide(); if (curRide == nullptr) return; + const auto& currentStation = curRide->GetStation(current_station); + if (curRide->mode == RideMode::ForwardRotation || curRide->mode == RideMode::BackwardRotation) { uint8_t seat = ((-Pitch) >> 3) & 0xF; @@ -4030,7 +4035,7 @@ void Vehicle::UpdateUnloadingPassengers() } else { - if (ride_get_exit_location(curRide, current_station).IsNull()) + if (currentStation.Exit.IsNull()) { if (sub_state != 1) return; diff --git a/src/openrct2/world/TileInspector.cpp b/src/openrct2/world/TileInspector.cpp index 7c8a651568..431842e274 100644 --- a/src/openrct2/world/TileInspector.cpp +++ b/src/openrct2/world/TileInspector.cpp @@ -247,8 +247,9 @@ namespace OpenRCT2::TileInspector if (ride != nullptr) { auto stationIndex = tileElement->AsEntrance()->GetStationIndex(); - auto entrance = ride_get_entrance_location(ride, stationIndex); - auto exit = ride_get_exit_location(ride, stationIndex); + auto& station = ride->GetStation(stationIndex); + auto entrance = station.Entrance; + auto exit = station.Exit; uint8_t entranceType = tileElement->AsEntrance()->GetEntranceType(); uint8_t z = tileElement->base_height; @@ -256,13 +257,13 @@ namespace OpenRCT2::TileInspector if (entranceType == ENTRANCE_TYPE_RIDE_ENTRANCE && entrance.x == loc.x / 32 && entrance.y == loc.y / 32 && entrance.z == z) { - ride_set_entrance_location(ride, stationIndex, { entrance.x, entrance.y, entrance.z, newRotation }); + station.Entrance = { entrance.x, entrance.y, entrance.z, newRotation }; } else if ( entranceType == ENTRANCE_TYPE_RIDE_EXIT && exit.x == loc.x / 32 && exit.y == loc.y / 32 && exit.z == z) { - ride_set_exit_location(ride, stationIndex, { exit.x, exit.y, exit.z, newRotation }); + station.Exit = { exit.x, exit.y, exit.z, newRotation }; } } break; @@ -481,16 +482,16 @@ namespace OpenRCT2::TileInspector if (ride != nullptr) { auto entranceIndex = tileElement->AsEntrance()->GetStationIndex(); - auto entrance = ride_get_entrance_location(ride, entranceIndex); - auto exit = ride_get_exit_location(ride, entranceIndex); + auto& station = ride->GetStation(entranceIndex); + auto entrance = station.Entrance; + auto exit = station.Exit; uint8_t z = tileElement->base_height; // Make sure this is the correct entrance or exit if (entranceType == ENTRANCE_TYPE_RIDE_ENTRANCE && entrance == TileCoordsXYZ{ loc, z }) - ride_set_entrance_location( - ride, entranceIndex, { entrance.x, entrance.y, z + heightOffset, entrance.direction }); + station.Entrance = { entrance.x, entrance.y, z + heightOffset, entrance.direction }; else if (entranceType == ENTRANCE_TYPE_RIDE_EXIT && exit == TileCoordsXYZ{ loc, z }) - ride_set_exit_location(ride, entranceIndex, { exit.x, exit.y, z + heightOffset, exit.direction }); + station.Exit = { exit.x, exit.y, z + heightOffset, exit.direction }; } } } @@ -693,20 +694,17 @@ namespace OpenRCT2::TileInspector if (isExecuting) { auto stationIndex = entranceElement->AsEntrance()->GetStationIndex(); + auto& station = ride->GetStation(stationIndex); switch (entranceElement->AsEntrance()->GetEntranceType()) { case ENTRANCE_TYPE_RIDE_ENTRANCE: - ride_set_entrance_location( - ride, stationIndex, - { loc.x / 32, loc.y / 32, entranceElement->base_height, - static_cast(entranceElement->GetDirection()) }); + station.Entrance = { loc.x / 32, loc.y / 32, entranceElement->base_height, + static_cast(entranceElement->GetDirection()) }; break; case ENTRANCE_TYPE_RIDE_EXIT: - ride_set_exit_location( - ride, stationIndex, - { loc.x / 32, loc.y / 32, entranceElement->base_height, - static_cast(entranceElement->GetDirection()) }); + station.Exit = { loc.x / 32, loc.y / 32, entranceElement->base_height, + static_cast(entranceElement->GetDirection()) }; break; } diff --git a/test/tests/Pathfinding.cpp b/test/tests/Pathfinding.cpp index c6ce245d19..d7e040390e 100644 --- a/test/tests/Pathfinding.cpp +++ b/test/tests/Pathfinding.cpp @@ -198,7 +198,7 @@ TEST_P(SimplePathfindingTest, CanFindPathFromStartToGoal) auto ride = FindRideByName(scenario.name); ASSERT_NE(ride, nullptr); - auto entrancePos = ride_get_entrance_location(ride, StationIndex::FromUnderlying(0)); + auto entrancePos = ride->GetStation().Entrance; TileCoordsXYZ goal = TileCoordsXYZ( entrancePos.x - TileDirectionDelta[entrancePos.direction].x, entrancePos.y - TileDirectionDelta[entrancePos.direction].y, entrancePos.z); @@ -236,7 +236,7 @@ TEST_P(ImpossiblePathfindingTest, CannotFindPathFromStartToGoal) auto ride = FindRideByName(scenario.name); ASSERT_NE(ride, nullptr); - auto entrancePos = ride_get_entrance_location(ride, StationIndex::FromUnderlying(0)); + auto entrancePos = ride->GetStation().Entrance; TileCoordsXYZ goal = TileCoordsXYZ( entrancePos.x + TileDirectionDelta[entrancePos.direction].x, entrancePos.y + TileDirectionDelta[entrancePos.direction].y, entrancePos.z);