Skip to content

Commit

Permalink
Merge pull request #16515
Browse files Browse the repository at this point in the history
  • Loading branch information
Broxzier committed Feb 19, 2022
2 parents 7ead709 + 5c5f86a commit 8dce36b
Show file tree
Hide file tree
Showing 46 changed files with 698 additions and 667 deletions.
9 changes: 5 additions & 4 deletions src/openrct2-ui/interface/ViewportInteraction.cpp
Expand Up @@ -244,7 +244,7 @@ bool ViewportInteractionLeftClick(const ScreenCoordsXY& screenCoords)
InteractionInfo ViewportInteractionGetItemRight(const ScreenCoordsXY& screenCoords)
{
Ride* ride;
int32_t i, stationIndex;
int32_t i;
InteractionInfo info{};
// No click input for title screen or track manager
if (gScreenFlags & (SCREEN_FLAGS_TITLE_DEMO | SCREEN_FLAGS_TRACK_MANAGER))
Expand Down Expand Up @@ -370,13 +370,14 @@ InteractionInfo ViewportInteractionGetItemRight(const ScreenCoordsXY& screenCoor
const auto& rtd = ride->GetRideTypeDescriptor();
ft.Add<rct_string_id>(GetRideComponentName(rtd.NameConvention.station).capitalised);

StationIndex::UnderlyingType stationIndex;
if (tileElement->GetType() == TileElementType::Entrance)
stationIndex = tileElement->AsEntrance()->GetStationIndex();
stationIndex = tileElement->AsEntrance()->GetStationIndex().ToUnderlying();
else
stationIndex = tileElement->AsTrack()->GetStationIndex();
stationIndex = tileElement->AsTrack()->GetStationIndex().ToUnderlying();

for (i = stationIndex; i >= 0; i--)
if (ride->stations[i].Start.IsNull())
if (ride->GetStations()[i].Start.IsNull())
stationIndex--;
stationIndex++;
ft.Add<uint16_t>(stationIndex);
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2-ui/windows/MazeConstruction.cpp
Expand Up @@ -302,7 +302,7 @@ class MazeConstructionWindow final : public Window

gRideEntranceExitPlaceType = widgetIndex == WIDX_MAZE_ENTRANCE ? ENTRANCE_TYPE_RIDE_ENTRANCE : ENTRANCE_TYPE_RIDE_EXIT;
gRideEntranceExitPlaceRideIndex = rideId;
gRideEntranceExitPlaceStationIndex = 0;
gRideEntranceExitPlaceStationIndex = StationIndex::FromUnderlying(0);
input_set_flag(INPUT_FLAG_6, true);

ride_construction_invalidate_current_track();
Expand Down
38 changes: 19 additions & 19 deletions src/openrct2-ui/windows/Ride.cpp
Expand Up @@ -1224,15 +1224,15 @@ static rct_window* WindowRideOpenStation(Ride* ride, StationIndex stationIndex)
WindowInitScrollWidgets(w);

// View
for (int32_t i = stationIndex; i >= 0; i--)
for (int32_t i = stationIndex.ToUnderlying(); i >= 0; i--)
{
if (ride->stations[i].Start.IsNull())
if (ride->GetStations()[i].Start.IsNull())
{
stationIndex--;
stationIndex = StationIndex::FromUnderlying(stationIndex.ToUnderlying() - 1);
}
}

w->ride.view = 1 + ride->num_vehicles + stationIndex;
w->ride.view = 1 + ride->num_vehicles + stationIndex.ToUnderlying();
WindowRideInitViewport(w);

return w;
Expand Down Expand Up @@ -1456,15 +1456,12 @@ static std::optional<StationIndex> GetStationIndexFromViewSelection(const rct_wi
return std::nullopt;
}

for (StationIndex index = 0; index < std::size(ride->stations); ++index)
for (const auto& station : ride->GetStations())
{
const auto& station = ride->stations[index];
if (!station.Start.IsNull())
if (!station.Start.IsNull() && viewSelectionIndex-- == 0)
{
if (viewSelectionIndex-- == 0)
{
return { index };
}
const auto stationIndex = ride->GetStationIndex(&station);
return std::make_optional(stationIndex);
}
}
return std::nullopt;
Expand Down Expand Up @@ -1513,7 +1510,7 @@ static void WindowRideInitViewport(rct_window* w)
auto stationIndex = GetStationIndexFromViewSelection(*w);
if (stationIndex)
{
const auto location = ride->stations[*stationIndex].GetStart();
const auto location = ride->GetStation(*stationIndex).GetStart();
focus = Focus(location);
}
}
Expand Down Expand Up @@ -2451,7 +2448,7 @@ static rct_string_id WindowRideGetStatusVehicle(rct_window* w, Formatter& ft)
ft.Add<uint16_t>(speedInMph);
const RideComponentName stationName = GetRideComponentName(ride->GetRideTypeDescriptor().NameConvention.station);
ft.Add<rct_string_id>(ride->num_stations > 1 ? stationName.number : stationName.singular);
ft.Add<uint16_t>(vehicle->current_station + 1);
ft.Add<uint16_t>(vehicle->current_station.ToUnderlying() + 1);
return stringId != STR_CRASHING && stringId != STR_CRASHED_0 ? STR_BLACK_STRING : STR_RED_OUTLINED_STRING;
}

Expand All @@ -2471,25 +2468,26 @@ 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, static_cast<uint8_t>(*stationIndex)).IsNull())
if (station.Entrance.IsNull())
stringId = STR_NO_ENTRANCE;
else if (ride_get_exit_location(ride, static_cast<uint8_t>(*stationIndex)).IsNull())
else if (station.Exit.IsNull())
stringId = STR_NO_EXIT;
}
else
{
if (ride_get_entrance_location(ride, static_cast<uint8_t>(*stationIndex)).IsNull())
if (station.Entrance.IsNull())
stringId = STR_EXIT_ONLY;
}
// Queue length
if (stringId == STR_EMPTY)
{
stringId = STR_QUEUE_EMPTY;
uint16_t queueLength = ride->stations[*stationIndex].QueueLength;
uint16_t queueLength = ride->GetStation(*stationIndex).QueueLength;
if (queueLength == 1)
stringId = STR_QUEUE_ONE_PERSON;
else if (queueLength > 1)
Expand Down Expand Up @@ -5565,7 +5563,8 @@ static void WindowRideMeasurementsPaint(rct_window* w, rct_drawpixelinfo* dpi)
int32_t numTimes = 0;
for (int32_t i = 0; i < ride->num_stations; i++)
{
auto time = ride->stations[numTimes].SegmentTime;
StationIndex stationIndex = StationIndex::FromUnderlying(numTimes);
auto time = ride->GetStation(stationIndex).SegmentTime;
if (time != 0)
{
ft.Add<uint16_t>(STR_RIDE_TIME_ENTRY_WITH_SEPARATOR);
Expand Down Expand Up @@ -5602,7 +5601,8 @@ static void WindowRideMeasurementsPaint(rct_window* w, rct_drawpixelinfo* dpi)
int32_t numLengths = 0;
for (int32_t i = 0; i < ride->num_stations; i++)
{
auto length = ride->stations[i].SegmentLength;
StationIndex stationIndex = StationIndex::FromUnderlying(i);
auto length = ride->GetStation(stationIndex).SegmentLength;
if (length != 0)
{
length >>= 16;
Expand Down
4 changes: 2 additions & 2 deletions src/openrct2-ui/windows/RideConstruction.cpp
Expand Up @@ -1715,7 +1715,7 @@ static void WindowRideConstructionEntranceClick(rct_window* w)
{
gRideEntranceExitPlaceType = ENTRANCE_TYPE_RIDE_ENTRANCE;
gRideEntranceExitPlaceRideIndex = w->rideId;
gRideEntranceExitPlaceStationIndex = 0;
gRideEntranceExitPlaceStationIndex = StationIndex::FromUnderlying(0);
input_set_flag(INPUT_FLAG_6, true);
ride_construction_invalidate_current_track();
if (_rideConstructionState != RideConstructionState::EntranceExit)
Expand Down Expand Up @@ -1745,7 +1745,7 @@ static void WindowRideConstructionExitClick(rct_window* w)
{
gRideEntranceExitPlaceType = ENTRANCE_TYPE_RIDE_EXIT;
gRideEntranceExitPlaceRideIndex = w->rideId;
gRideEntranceExitPlaceStationIndex = 0;
gRideEntranceExitPlaceStationIndex = StationIndex::FromUnderlying(0);
input_set_flag(INPUT_FLAG_6, true);
ride_construction_invalidate_current_track();
if (_rideConstructionState != RideConstructionState::EntranceExit)
Expand Down
10 changes: 5 additions & 5 deletions src/openrct2-ui/windows/TileInspector.cpp
Expand Up @@ -1940,10 +1940,10 @@ static void WindowTileInspectorPaint(rct_window* w, rct_drawpixelinfo* dpi)
dpi, screenCoords + ScreenCoordsXY{ 0, 44 }, STR_TILE_INSPECTOR_TRACK_SEQUENCE, ft, { w->colours[1] });
if (trackElement->IsStation())
{
int16_t stationIndex = trackElement->GetStationIndex();
auto stationIndex = trackElement->GetStationIndex();
ft = Formatter();
ft.Add<rct_string_id>(STR_COMMA16);
ft.Add<int16_t>(stationIndex);
ft.Add<int16_t>(stationIndex.ToUnderlying());
DrawTextBasic(
dpi, screenCoords + ScreenCoordsXY{ 0, 55 }, STR_TILE_INSPECTOR_STATION_INDEX, ft, { w->colours[1] });
}
Expand Down Expand Up @@ -2050,7 +2050,7 @@ static void WindowTileInspectorPaint(rct_window* w, rct_drawpixelinfo* dpi)
else
{
ft = Formatter();
ft.Add<int16_t>(tileElement->AsEntrance()->GetStationIndex());
ft.Add<int16_t>(tileElement->AsEntrance()->GetStationIndex().ToUnderlying());
if (tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_RIDE_ENTRANCE)
{
// Ride entrance ID
Expand Down Expand Up @@ -2084,10 +2084,10 @@ static void WindowTileInspectorPaint(rct_window* w, rct_drawpixelinfo* dpi)
dpi, screenCoords + ScreenCoordsXY{ 0, 22 }, STR_TILE_INSPECTOR_ENTRANCE_RIDE_ID, ft,
{ w->colours[1] });
// Station index
int16_t stationIndex = tileElement->AsEntrance()->GetStationIndex();
auto stationIndex = tileElement->AsEntrance()->GetStationIndex();
ft = Formatter();
ft.Add<rct_string_id>(STR_COMMA16);
ft.Add<int16_t>(stationIndex);
ft.Add<int16_t>(stationIndex.ToUnderlying());
DrawTextBasic(
dpi, screenCoords + ScreenCoordsXY{ 0, 33 }, STR_TILE_INSPECTOR_STATION_INDEX, ft, { w->colours[1] });
}
Expand Down
8 changes: 4 additions & 4 deletions src/openrct2/Game.cpp
Expand Up @@ -359,7 +359,7 @@ void game_fix_save_vars()
// Fix possibly invalid field values
for (auto peep : EntityList<Guest>())
{
if (peep->CurrentRideStation >= OpenRCT2::Limits::MaxStationsPerRide)
if (peep->CurrentRideStation.ToUnderlying() >= OpenRCT2::Limits::MaxStationsPerRide)
{
const auto srcStation = peep->CurrentRideStation;
const auto rideIdx = peep->CurrentRide;
Expand All @@ -376,10 +376,10 @@ void game_fix_save_vars()
}
auto curName = peep->GetName();
log_warning(
"Peep %u (%s) has invalid ride station = %u for ride %u.", peep->sprite_index, curName.c_str(), srcStation,
rideIdx);
"Peep %u (%s) has invalid ride station = %u for ride %u.", peep->sprite_index, curName.c_str(),
srcStation.ToUnderlying(), rideIdx);
auto station = ride_get_first_valid_station_exit(ride);
if (station == STATION_INDEX_NULL)
if (station.IsNull())
{
log_warning("Couldn't find station, removing peep %u", peep->sprite_index);
peepsToRemove.push_back(peep);
Expand Down
6 changes: 2 additions & 4 deletions src/openrct2/Identifiers.h
Expand Up @@ -14,10 +14,8 @@

#include <limits>

using ParkEntranceIndex = TIdentifier<uint8_t, std::numeric_limits<uint8_t>::max(), struct ParkEntranceIndexTag>;

using BannerIndex = TIdentifier<uint16_t, std::numeric_limits<uint16_t>::max(), struct BannerIndexTag>;

using ParkEntranceIndex = TIdentifier<uint8_t, std::numeric_limits<uint8_t>::max(), struct ParkEntranceIndexTag>;
using RideId = TIdentifier<uint16_t, std::numeric_limits<uint16_t>::max(), struct RideIdTag>;

using EntityId = TIdentifier<uint16_t, std::numeric_limits<uint16_t>::max(), struct EntityIdTag>;
using StationIndex = TIdentifier<uint8_t, std::numeric_limits<uint8_t>::max(), struct StationIndexTag>;
4 changes: 2 additions & 2 deletions src/openrct2/actions/MazePlaceTrackAction.cpp
Expand Up @@ -178,8 +178,8 @@ GameActions::Result MazePlaceTrackAction::Execute() const
map_invalidate_tile_full(startLoc);

ride->maze_tiles++;
ride->stations[0].SetBaseZ(trackElement->GetBaseZ());
ride->stations[0].Start = { 0, 0 };
ride->GetStation().SetBaseZ(trackElement->GetBaseZ());
ride->GetStation().Start = { 0, 0 };

if (ride->maze_tiles == 1)
{
Expand Down
4 changes: 2 additions & 2 deletions src/openrct2/actions/MazeSetTrackAction.cpp
Expand Up @@ -193,8 +193,8 @@ GameActions::Result MazeSetTrackAction::Execute() const
map_invalidate_tile_full(startLoc);

ride->maze_tiles++;
ride->stations[0].SetBaseZ(tileElement->GetBaseZ());
ride->stations[0].Start = { 0, 0 };
ride->GetStation().SetBaseZ(tileElement->GetBaseZ());
ride->GetStation().Start = { 0, 0 };

if (_initialPlacement && !(flags & GAME_COMMAND_FLAG_GHOST))
{
Expand Down
12 changes: 6 additions & 6 deletions src/openrct2/actions/RideCreateAction.cpp
Expand Up @@ -138,13 +138,13 @@ GameActions::Result RideCreateAction::Execute() const
ride->overall_view.SetNull();
ride->SetNameToDefault();

for (int32_t i = 0; i < OpenRCT2::Limits::MaxStationsPerRide; i++)
for (auto& station : ride->GetStations())
{
ride->stations[i].Start.SetNull();
ride_clear_entrance_location(ride, i);
ride_clear_exit_location(ride, i);
ride->stations[i].TrainAtStation = RideStation::NO_TRAIN;
ride->stations[i].QueueTime = 0;
station.Start.SetNull();
station.Entrance.SetNull();
station.Exit.SetNull();
station.TrainAtStation = RideStation::NO_TRAIN;
station.QueueTime = 0;
}

std::fill(std::begin(ride->vehicles), std::end(ride->vehicles), EntityId::GetNull());
Expand Down
22 changes: 12 additions & 10 deletions src/openrct2/actions/RideEntranceExitPlaceAction.cpp
Expand Up @@ -59,9 +59,9 @@ GameActions::Result RideEntranceExitPlaceAction::Query() const
return GameActions::Result(GameActions::Status::InvalidParameters, errorTitle, STR_NONE);
}

if (_stationNum >= OpenRCT2::Limits::MaxStationsPerRide)
if (_stationNum.ToUnderlying() >= OpenRCT2::Limits::MaxStationsPerRide)
{
log_warning("Invalid station number for ride. stationNum: %u", _stationNum);
log_warning("Invalid station number for ride. stationNum: %u", _stationNum.ToUnderlying());
return GameActions::Result(GameActions::Status::InvalidParameters, errorTitle, STR_NONE);
}

Expand All @@ -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 All @@ -90,7 +91,7 @@ GameActions::Result RideEntranceExitPlaceAction::Query() const
}
}

auto z = ride->stations[_stationNum].GetBaseZ();
auto z = ride->GetStation(_stationNum).GetBaseZ();
if (!LocationValid(_loc) || (!gCheatsSandboxMode && !map_is_location_owned({ _loc, z })))
{
return GameActions::Result(GameActions::Status::NotOwned, errorTitle, STR_LAND_NOT_OWNED_BY_PARK);
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->stations[_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->stations[_stationNum].LastPeepInQueue = EntityId::GetNull();
ride->stations[_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
2 changes: 1 addition & 1 deletion src/openrct2/actions/RideEntranceExitPlaceAction.h
Expand Up @@ -18,7 +18,7 @@ class RideEntranceExitPlaceAction final : public GameActionBase<GameCommand::Pla
CoordsXY _loc;
Direction _direction{ INVALID_DIRECTION };
RideId _rideIndex{ RideId::GetNull() };
StationIndex _stationNum{ STATION_INDEX_NULL };
StationIndex _stationNum{ StationIndex::GetNull() };
bool _isExit{};

public:
Expand Down
11 changes: 6 additions & 5 deletions src/openrct2/actions/RideEntranceExitRemoveAction.cpp
Expand Up @@ -46,7 +46,7 @@ void RideEntranceExitRemoveAction::Serialise(DataSerialiser& stream)
}

static TileElement* FindEntranceElement(
const CoordsXY& loc, RideId rideIndex, int32_t stationNum, int32_t entranceType, uint32_t flags)
const CoordsXY& loc, RideId rideIndex, StationIndex stationNum, int32_t entranceType, uint32_t flags)
{
const bool isGhost = flags & GAME_COMMAND_FLAG_GHOST;
for (auto* entranceElement : TileElementsView<EntranceElement>(loc))
Expand Down Expand Up @@ -99,8 +99,8 @@ GameActions::Result RideEntranceExitRemoveAction::Query() const
if (entranceElement == nullptr)
{
log_warning(
"Track Element not found. x = %d, y = %d, ride = %u, station = %d", _loc.x, _loc.y, _rideIndex.ToUnderlying(),
_stationNum);
"Track Element not found. x = %d, y = %d, ride = %u, station = %u", _loc.x, _loc.y, _rideIndex.ToUnderlying(),
_stationNum.ToUnderlying());
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
}

Expand Down 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
2 changes: 1 addition & 1 deletion src/openrct2/actions/RideEntranceExitRemoveAction.h
Expand Up @@ -16,7 +16,7 @@ class RideEntranceExitRemoveAction final : public GameActionBase<GameCommand::Re
private:
CoordsXY _loc;
RideId _rideIndex{ RideId::GetNull() };
StationIndex _stationNum{ STATION_INDEX_NULL };
StationIndex _stationNum{ StationIndex::GetNull() };
bool _isExit{};

public:
Expand Down

0 comments on commit 8dce36b

Please sign in to comment.