From 046c060e7497218df9c484c8122c04492f6da05b Mon Sep 17 00:00:00 2001 From: frutiemax Date: Sun, 22 Aug 2021 11:18:38 -0400 Subject: [PATCH] Part of #13874: Replace Track Sequence properties --- src/openrct2-ui/windows/Ride.cpp | 4 +++- src/openrct2-ui/windows/TrackDesignPlace.cpp | 2 +- src/openrct2/actions/TrackPlaceAction.cpp | 6 ++--- src/openrct2/actions/TrackRemoveAction.cpp | 4 ++-- src/openrct2/actions/WallPlaceAction.cpp | 2 +- src/openrct2/ride/Ride.cpp | 25 +++++++++++++------- src/openrct2/ride/RideConstruction.cpp | 24 ++++++++++++------- src/openrct2/ride/TrackData.cpp | 2 +- src/openrct2/ride/TrackData.h | 2 -- src/openrct2/ride/Vehicle.cpp | 6 +++-- src/openrct2/world/Footpath.cpp | 17 ++++++++----- 11 files changed, 57 insertions(+), 37 deletions(-) diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index 352c565272..5fc066517d 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -59,6 +59,7 @@ #include using namespace OpenRCT2; +using namespace OpenRCT2::TrackMetaData; static constexpr const rct_string_id WINDOW_TITLE = STR_RIDE_WINDOW_TITLE; static constexpr const int32_t WH = 207; @@ -1368,7 +1369,8 @@ rct_window* window_ride_open_track(TileElement* tileElement) // Open ride window in station view auto trackElement = tileElement->AsTrack(); auto trackType = trackElement->GetTrackType(); - if (TrackSequenceProperties[trackType][0] & TRACK_SEQUENCE_FLAG_ORIGIN) + const auto& teDescriptor = GetTrackElementDescriptor(trackType); + if (teDescriptor.TrackSequenceProperties[0] & TRACK_SEQUENCE_FLAG_ORIGIN) { auto stationIndex = trackElement->GetStationIndex(); return window_ride_open_station(ride, stationIndex); diff --git a/src/openrct2-ui/windows/TrackDesignPlace.cpp b/src/openrct2-ui/windows/TrackDesignPlace.cpp index 5896be7fe1..3ca11449c2 100644 --- a/src/openrct2-ui/windows/TrackDesignPlace.cpp +++ b/src/openrct2-ui/windows/TrackDesignPlace.cpp @@ -574,7 +574,7 @@ static void window_track_place_draw_mini_preview_track( auto bits = trackBlock->var_08.Rotate(curTrackRotation & 3).GetBaseQuarterOccupied(); // Station track is a lighter colour - uint8_t colour = (TrackSequenceProperties[trackType][0] & TRACK_SEQUENCE_FLAG_ORIGIN) + uint8_t colour = (teDescriptor.TrackSequenceProperties[0] & TRACK_SEQUENCE_FLAG_ORIGIN) ? _PaletteIndexColourStation : _PaletteIndexColourTrack; diff --git a/src/openrct2/actions/TrackPlaceAction.cpp b/src/openrct2/actions/TrackPlaceAction.cpp index e6948a5619..21131a1c3c 100644 --- a/src/openrct2/actions/TrackPlaceAction.cpp +++ b/src/openrct2/actions/TrackPlaceAction.cpp @@ -318,7 +318,7 @@ GameActions::Result::Ptr TrackPlaceAction::Query() const } } - int32_t entranceDirections = TrackSequenceProperties[_trackType][0]; + int32_t entranceDirections = teDescriptor.TrackSequenceProperties[0]; if ((entranceDirections & TRACK_SEQUENCE_FLAG_ORIGIN) && trackBlock->index == 0) { if (!track_add_station_element({ mapLoc, baseZ, _origin.direction }, _rideIndex, 0, _fromTrackDesign)) @@ -538,7 +538,7 @@ GameActions::Result::Ptr TrackPlaceAction::Execute() const { if (!(GetFlags() & GAME_COMMAND_FLAG_NO_SPEND)) { - entranceDirections = TrackSequenceProperties[_trackType][0]; + entranceDirections = teDescriptor.TrackSequenceProperties[0]; } } @@ -597,7 +597,7 @@ GameActions::Result::Ptr TrackPlaceAction::Execute() const } trackElement->SetColourScheme(_colour); - entranceDirections = TrackSequenceProperties[_trackType][0]; + entranceDirections = teDescriptor.TrackSequenceProperties[0]; if (entranceDirections & TRACK_SEQUENCE_FLAG_CONNECTS_TO_PATH) { uint8_t availableDirections = entranceDirections & 0x0F; diff --git a/src/openrct2/actions/TrackRemoveAction.cpp b/src/openrct2/actions/TrackRemoveAction.cpp index 5db867f52b..5e084b109d 100644 --- a/src/openrct2/actions/TrackRemoveAction.cpp +++ b/src/openrct2/actions/TrackRemoveAction.cpp @@ -203,7 +203,7 @@ GameActions::Result::Ptr TrackRemoveAction::Query() const return MakeResult(GameActions::Status::Unknown, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS); } - int32_t entranceDirections = TrackSequenceProperties[trackType][0]; + int32_t entranceDirections = teDescriptor.TrackSequenceProperties[0]; if (entranceDirections & TRACK_SEQUENCE_FLAG_ORIGIN && (tileElement->AsTrack()->GetSequenceIndex() == 0)) { if (!track_remove_station_element({ mapLoc, _origin.direction }, rideIndex, 0)) @@ -378,7 +378,7 @@ GameActions::Result::Ptr TrackRemoveAction::Execute() const return MakeResult(GameActions::Status::Unknown, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS); } - int32_t entranceDirections = TrackSequenceProperties[trackType][0]; + int32_t entranceDirections = teDescriptor.TrackSequenceProperties[0]; if (entranceDirections & TRACK_SEQUENCE_FLAG_ORIGIN && (tileElement->AsTrack()->GetSequenceIndex() == 0)) { if (!track_remove_station_element({ mapLoc, _origin.direction }, rideIndex, 0)) diff --git a/src/openrct2/actions/WallPlaceAction.cpp b/src/openrct2/actions/WallPlaceAction.cpp index ed78773c68..7aa2244383 100644 --- a/src/openrct2/actions/WallPlaceAction.cpp +++ b/src/openrct2/actions/WallPlaceAction.cpp @@ -441,7 +441,7 @@ bool WallPlaceAction::WallCheckObstructionWithTrack( int32_t z; if (sequence == 0) { - if (TrackSequenceProperties[trackType][0] & TRACK_SEQUENCE_FLAG_DISALLOW_DOORS) + if (teDescriptor.TrackSequenceProperties[0] & TRACK_SEQUENCE_FLAG_DISALLOW_DOORS) { return false; } diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index c6dd1930de..b55da43d9e 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -410,10 +410,11 @@ bool ride_try_get_origin_element(const Ride* ride, CoordsXYE* output) // Found a track piece for target ride // Check if it's not the station or ??? (but allow end piece of station) + const auto& teDescriptor = GetTrackElementDescriptor(it.element->AsTrack()->GetTrackType()); bool specialTrackPiece = (it.element->AsTrack()->GetTrackType() != TrackElemType::BeginStation && it.element->AsTrack()->GetTrackType() != TrackElemType::MiddleStation - && (TrackSequenceProperties[it.element->AsTrack()->GetTrackType()][0] & TRACK_SEQUENCE_FLAG_ORIGIN)); + && (teDescriptor.TrackSequenceProperties[0] & TRACK_SEQUENCE_FLAG_ORIGIN)); // Set result tile to this track piece if first found track or a ??? if (resultTileElement == nullptr || specialTrackPiece) @@ -2228,7 +2229,8 @@ static void ride_shop_connected(Ride* ride) return; } - uint8_t entrance_directions = TrackSequenceProperties[track_type][0] & 0xF; + const auto& teDescriptor = GetTrackElementDescriptor(track_type); + uint8_t entrance_directions = teDescriptor.TrackSequenceProperties[0] & 0xF; uint8_t tile_direction = trackElement->GetDirection(); entrance_directions = rol4(entrance_directions, tile_direction); @@ -2772,7 +2774,8 @@ static int32_t ride_check_station_length(CoordsXYE* input, CoordsXYE* output) do { - if (TrackSequenceProperties[output->element->AsTrack()->GetTrackType()][0] & TRACK_SEQUENCE_FLAG_ORIGIN) + const auto& teDescriptor = GetTrackElementDescriptor(output->element->AsTrack()->GetTrackType()); + if (teDescriptor.TrackSequenceProperties[0] & TRACK_SEQUENCE_FLAG_ORIGIN) { num_station_elements++; last_good_station = *output; @@ -2819,7 +2822,8 @@ static bool ride_check_start_and_end_is_station(CoordsXYE* input) // Check back of the track track_get_back(input, &trackBack); auto trackType = trackBack.element->AsTrack()->GetTrackType(); - if (!(TrackSequenceProperties[trackType][0] & TRACK_SEQUENCE_FLAG_ORIGIN)) + auto teDescriptor = GetTrackElementDescriptor(trackType); + if (!(teDescriptor.TrackSequenceProperties[0] & TRACK_SEQUENCE_FLAG_ORIGIN)) { return false; } @@ -2828,7 +2832,8 @@ static bool ride_check_start_and_end_is_station(CoordsXYE* input) // Check front of the track track_get_front(input, &trackFront); trackType = trackFront.element->AsTrack()->GetTrackType(); - if (!(TrackSequenceProperties[trackType][0] & TRACK_SEQUENCE_FLAG_ORIGIN)) + teDescriptor = GetTrackElementDescriptor(trackType); + if (!(teDescriptor.TrackSequenceProperties[0] & TRACK_SEQUENCE_FLAG_ORIGIN)) { return false; } @@ -3539,7 +3544,8 @@ static bool ride_initialise_cable_lift_track(Ride* ride, bool isApplying) if (tileElement->GetBaseZ() != location.z) continue; - if (!(TrackSequenceProperties[tileElement->AsTrack()->GetTrackType()][0] & TRACK_SEQUENCE_FLAG_ORIGIN)) + const auto& teDescriptor = GetTrackElementDescriptor(tileElement->AsTrack()->GetTrackType()); + if (!(teDescriptor.TrackSequenceProperties[0] & TRACK_SEQUENCE_FLAG_ORIGIN)) { continue; } @@ -3771,8 +3777,8 @@ TrackElement* Ride::GetOriginElement(StationIndex stationIndex) const continue; auto* trackElement = tileElement->AsTrack(); - - if (!(TrackSequenceProperties[trackElement->GetTrackType()][0] & TRACK_SEQUENCE_FLAG_ORIGIN)) + const auto& teDescriptor = GetTrackElementDescriptor(trackElement->GetTrackType()); + if (!(teDescriptor.TrackSequenceProperties[0] & TRACK_SEQUENCE_FLAG_ORIGIN)) continue; if (trackElement->GetRideIndex() == id) @@ -4878,7 +4884,8 @@ static int32_t ride_get_track_length(Ride* ride) continue; trackType = tileElement->AsTrack()->GetTrackType(); - if (!(TrackSequenceProperties[trackType][0] & TRACK_SEQUENCE_FLAG_ORIGIN)) + const auto& teDescriptor = GetTrackElementDescriptor(trackType); + if (!(teDescriptor.TrackSequenceProperties[0] & TRACK_SEQUENCE_FLAG_ORIGIN)) continue; if (tileElement->GetBaseZ() != trackStart.z) diff --git a/src/openrct2/ride/RideConstruction.cpp b/src/openrct2/ride/RideConstruction.cpp index 8f0a5975f5..5b3bb6a432 100644 --- a/src/openrct2/ride/RideConstruction.cpp +++ b/src/openrct2/ride/RideConstruction.cpp @@ -43,6 +43,7 @@ #include "TrainManager.h" #include "Vehicle.h" +using namespace OpenRCT2::TrackMetaData; bool gGotoStartPlacementMode = false; money16 gTotalRideValueForMoney; @@ -1253,7 +1254,8 @@ CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(const ScreenC { if (info.Element->AsTrack()->GetRideIndex() == gRideEntranceExitPlaceRideIndex) { - if (TrackSequenceProperties[info.Element->AsTrack()->GetTrackType()][0] & TRACK_SEQUENCE_FLAG_ORIGIN) + const auto& teDescriptor = GetTrackElementDescriptor(info.Element->AsTrack()->GetTrackType()); + if (teDescriptor.TrackSequenceProperties[0] & TRACK_SEQUENCE_FLAG_ORIGIN) { if (info.Element->AsTrack()->GetTrackType() == TrackElemType::Maze) { @@ -1343,9 +1345,8 @@ CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(const ScreenC int32_t eax = (entranceExitCoords.direction + 2 - tileElement->GetDirection()) & TILE_ELEMENT_DIRECTION_MASK; - if (TrackSequenceProperties[tileElement->AsTrack()->GetTrackType()] - [tileElement->AsTrack()->GetSequenceIndex()] - & (1 << eax)) + const auto& teDescriptor = GetTrackElementDescriptor(tileElement->AsTrack()->GetTrackType()); + if (teDescriptor.TrackSequenceProperties[tileElement->AsTrack()->GetSequenceIndex()] & (1 << eax)) { entranceExitCoords.direction = direction_reverse(entranceExitCoords.direction); gRideEntranceExitPlaceDirection = entranceExitCoords.direction; @@ -1438,6 +1439,7 @@ CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(const ScreenC */ void sub_6CB945(Ride* ride) { + TrackElementDescriptor teDescriptor; if (ride->type != RIDE_TYPE_MAZE) { for (StationIndex stationId = 0; stationId < MAX_STATIONS; ++stationId) @@ -1450,7 +1452,6 @@ void sub_6CB945(Ride* ride) bool specialTrack = false; TileElement* tileElement = nullptr; - while (true) { if (direction != INVALID_DIRECTION) @@ -1473,7 +1474,9 @@ void sub_6CB945(Ride* ride) continue; if (tileElement->AsTrack()->GetSequenceIndex() != 0) continue; - if (!(TrackSequenceProperties[tileElement->AsTrack()->GetTrackType()][0] & TRACK_SEQUENCE_FLAG_ORIGIN)) + + teDescriptor = GetTrackElementDescriptor(tileElement->AsTrack()->GetTrackType()); + if (!(teDescriptor.TrackSequenceProperties[0] & TRACK_SEQUENCE_FLAG_ORIGIN)) continue; trackFound = true; @@ -1500,7 +1503,7 @@ void sub_6CB945(Ride* ride) continue; } - const auto& teDescriptor = GetTrackElementDescriptor(tileElement->AsTrack()->GetTrackType()); + teDescriptor = GetTrackElementDescriptor(tileElement->AsTrack()->GetTrackType()); const rct_preview_track* trackBlock = teDescriptor.Block; while ((++trackBlock)->index != 0xFF) { @@ -1516,7 +1519,9 @@ void sub_6CB945(Ride* ride) continue; if (tileElement->GetType() != TILE_ELEMENT_TYPE_TRACK) continue; - if (!(TrackSequenceProperties[tileElement->AsTrack()->GetTrackType()][0] & TRACK_SEQUENCE_FLAG_ORIGIN)) + + teDescriptor = GetTrackElementDescriptor(tileElement->AsTrack()->GetTrackType()); + if (!(teDescriptor.TrackSequenceProperties[0] & TRACK_SEQUENCE_FLAG_ORIGIN)) continue; trackFound = true; @@ -1611,7 +1616,8 @@ void sub_6CB945(Ride* ride) Direction direction = (tileElement->GetDirection() - direction_reverse(trackElement->GetDirection())) & 3; - if (!(TrackSequenceProperties[trackType][trackSequence] & (1 << direction))) + teDescriptor = GetTrackElementDescriptor(trackType); + if (!(teDescriptor.TrackSequenceProperties[trackSequence] & (1 << direction))) { continue; } diff --git a/src/openrct2/ride/TrackData.cpp b/src/openrct2/ride/TrackData.cpp index 256db9beaa..0ab32b5984 100644 --- a/src/openrct2/ride/TrackData.cpp +++ b/src/openrct2/ride/TrackData.cpp @@ -287,7 +287,7 @@ const static rct_track_coordinates TrackCoordinates[TrackElemType::Count] = { }; /** rct2: 0x0099BA64 */ -const uint8_t TrackSequenceProperties[][MaxSequencesPerPiece] = { +const static uint8_t TrackSequenceProperties[][MaxSequencesPerPiece] = { { 0 }, /* TrackElemType::EndStation */ { TRACK_SEQUENCE_FLAG_DIRECTION_1 | TRACK_SEQUENCE_FLAG_DIRECTION_3 | TRACK_SEQUENCE_FLAG_ORIGIN | TRACK_SEQUENCE_FLAG_DISALLOW_DOORS, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* TrackElemType::BeginStation */ { TRACK_SEQUENCE_FLAG_DIRECTION_1 | TRACK_SEQUENCE_FLAG_DIRECTION_3 | TRACK_SEQUENCE_FLAG_ORIGIN | TRACK_SEQUENCE_FLAG_DISALLOW_DOORS, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, diff --git a/src/openrct2/ride/TrackData.h b/src/openrct2/ride/TrackData.h index f95adeb9e2..9e41660b5c 100644 --- a/src/openrct2/ride/TrackData.h +++ b/src/openrct2/ride/TrackData.h @@ -17,8 +17,6 @@ constexpr const uint8_t MaxSequencesPerPiece = 16; // 0x009968BB, 0x009968BC, 0x009968BD, 0x009968BF, 0x009968C1, 0x009968C3 -extern const uint8_t TrackSequenceProperties[TrackElemType::Count][MaxSequencesPerPiece]; - struct track_curve_chain { int32_t next; diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 6d50508bb5..e4258fe342 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -7933,7 +7933,8 @@ void Vehicle::Sub6DBF3E() } auto trackType = GetTrackType(); - if (!(TrackSequenceProperties[trackType][0] & TRACK_SEQUENCE_FLAG_ORIGIN)) + const auto& teDescriptor = GetTrackElementDescriptor(trackType); + if (!(teDescriptor.TrackSequenceProperties[0] & TRACK_SEQUENCE_FLAG_ORIGIN)) { return; } @@ -9208,7 +9209,8 @@ loc_6DCE02: } { auto trackType = GetTrackType(); - if (!(TrackSequenceProperties[trackType][0] & TRACK_SEQUENCE_FLAG_ORIGIN)) + const auto& teDescriptor = GetTrackElementDescriptor(trackType); + if (!(teDescriptor.TrackSequenceProperties[0] & TRACK_SEQUENCE_FLAG_ORIGIN)) { return; } diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index c155e3cc7d..33c520a3e6 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -38,6 +38,7 @@ #include #include +using namespace OpenRCT2::TrackMetaData; void footpath_update_queue_entrance_banner(const CoordsXY& footpathPos, TileElement* tileElement); ProvisionalFootpath gProvisionalFootpath; @@ -880,13 +881,15 @@ static void loc_6A6D7E( const auto trackType = tileElement->AsTrack()->GetTrackType(); const uint8_t trackSequence = tileElement->AsTrack()->GetSequenceIndex(); - if (!(TrackSequenceProperties[trackType][trackSequence] & TRACK_SEQUENCE_FLAG_CONNECTS_TO_PATH)) + const auto& teDescriptor = GetTrackElementDescriptor(trackType); + if (!(teDescriptor.TrackSequenceProperties[trackSequence] & TRACK_SEQUENCE_FLAG_CONNECTS_TO_PATH)) { return; } uint16_t dx = direction_reverse( (direction - tileElement->GetDirection()) & TILE_ELEMENT_DIRECTION_MASK); - if (!(TrackSequenceProperties[trackType][trackSequence] & (1 << dx))) + + if (!(teDescriptor.TrackSequenceProperties[trackSequence] & (1 << dx))) { return; } @@ -962,12 +965,13 @@ static void loc_6A6C85( const auto trackType = tileElementPos.element->AsTrack()->GetTrackType(); const uint8_t trackSequence = tileElementPos.element->AsTrack()->GetSequenceIndex(); - if (!(TrackSequenceProperties[trackType][trackSequence] & TRACK_SEQUENCE_FLAG_CONNECTS_TO_PATH)) + const auto& teDescriptor = GetTrackElementDescriptor(trackType); + if (!(teDescriptor.TrackSequenceProperties[trackSequence] & TRACK_SEQUENCE_FLAG_CONNECTS_TO_PATH)) { return; } uint16_t dx = (direction - tileElementPos.element->GetDirection()) & TILE_ELEMENT_DIRECTION_MASK; - if (!(TrackSequenceProperties[trackType][trackSequence] & (1 << dx))) + if (!(teDescriptor.TrackSequenceProperties[trackSequence] & (1 << dx))) { return; } @@ -2103,10 +2107,11 @@ bool tile_element_wants_path_connection_towards(const TileCoordsXYZD& coords, co const auto trackType = tileElement->AsTrack()->GetTrackType(); const uint8_t trackSequence = tileElement->AsTrack()->GetSequenceIndex(); - if (TrackSequenceProperties[trackType][trackSequence] & TRACK_SEQUENCE_FLAG_CONNECTS_TO_PATH) + const auto& teDescriptor = GetTrackElementDescriptor(trackType); + if (teDescriptor.TrackSequenceProperties[trackSequence] & TRACK_SEQUENCE_FLAG_CONNECTS_TO_PATH) { uint16_t dx = ((coords.direction - tileElement->GetDirection()) & TILE_ELEMENT_DIRECTION_MASK); - if (TrackSequenceProperties[trackType][trackSequence] & (1 << dx)) + if (teDescriptor.TrackSequenceProperties[trackSequence] & (1 << dx)) { // Track element has the flags required for the given direction return true;