Skip to content

Commit

Permalink
Remove entrance/exit location functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Broxzier authored and ZehMatt committed Feb 18, 2022
1 parent 2137cea commit ad0a2a8
Show file tree
Hide file tree
Showing 18 changed files with 140 additions and 186 deletions.
7 changes: 4 additions & 3 deletions src/openrct2-ui/windows/Ride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions src/openrct2/actions/RideEntranceExitPlaceAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down Expand Up @@ -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);
Expand All @@ -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 });
Expand Down Expand Up @@ -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 });
}
Expand Down
5 changes: 3 additions & 2 deletions src/openrct2/actions/RideEntranceExitRemoveAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
32 changes: 16 additions & 16 deletions src/openrct2/entity/Guest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 });
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
22 changes: 11 additions & 11 deletions src/openrct2/entity/Staff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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())
{
Expand Down Expand Up @@ -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())
{
Expand Down
14 changes: 7 additions & 7 deletions src/openrct2/peep/GuestPathfinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2182,18 +2182,18 @@ int32_t guest_path_finding(Guest* peep)
int32_t numEntranceStations = 0;
BitSet<OpenRCT2::Limits::MaxStationsPerRide> 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;

const auto stationIndex = ride->GetStationIndex(&station);

numEntranceStations++;
entranceStations[stationNum] = true;
entranceStations[stationIndex.ToUnderlying()] = true;

TileCoordsXYZD entranceLocation = ride_get_entrance_location(ride, stationIndex);
TileCoordsXYZD entranceLocation = station.Entrance;
auto score = CalculateHeuristicPathingScore(entranceLocation, TileCoordsXYZ{ peep->NextLoc });
if (score < bestScore)
{
Expand Down Expand Up @@ -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;
Expand Down
48 changes: 22 additions & 26 deletions src/openrct2/rct1/S4Importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit ad0a2a8

Please sign in to comment.