diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index e3907ac39a..720b948782 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -1062,10 +1062,9 @@ void Ride::Update() } // Ride specific updates - if (type == RIDE_TYPE_CHAIRLIFT) - UpdateChairlift(); - else if (type == RIDE_TYPE_SPIRAL_SLIDE) - UpdateSpiralSlide(); + const auto& rtd = GetRideTypeDescriptor(); + if (rtd.RideUpdate != nullptr) + rtd.RideUpdate(*this); ride_breakdown_update(this); @@ -1104,23 +1103,23 @@ void Ride::Update() * * rct2: 0x006AC489 */ -void Ride::UpdateChairlift() +void UpdateChairlift(Ride& ride) { - if (!(lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK)) + if (!(ride.lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK)) return; - if ((lifecycle_flags & (RIDE_LIFECYCLE_BREAKDOWN_PENDING | RIDE_LIFECYCLE_BROKEN_DOWN | RIDE_LIFECYCLE_CRASHED)) - && breakdown_reason_pending == 0) + if ((ride.lifecycle_flags & (RIDE_LIFECYCLE_BREAKDOWN_PENDING | RIDE_LIFECYCLE_BROKEN_DOWN | RIDE_LIFECYCLE_CRASHED)) + && ride.breakdown_reason_pending == 0) return; - uint16_t old_chairlift_bullwheel_rotation = chairlift_bullwheel_rotation >> 14; - chairlift_bullwheel_rotation += speed * 2048; - if (old_chairlift_bullwheel_rotation == speed / 8) + uint16_t old_chairlift_bullwheel_rotation = ride.chairlift_bullwheel_rotation >> 14; + ride.chairlift_bullwheel_rotation += ride.speed * 2048; + if (old_chairlift_bullwheel_rotation == ride.speed / 8) return; - auto bullwheelLoc = ChairliftBullwheelLocation[0].ToCoordsXYZ(); + auto bullwheelLoc = ride.ChairliftBullwheelLocation[0].ToCoordsXYZ(); map_invalidate_tile_zoom1({ bullwheelLoc, bullwheelLoc.z, bullwheelLoc.z + (4 * COORDS_Z_STEP) }); - bullwheelLoc = ChairliftBullwheelLocation[1].ToCoordsXYZ(); + bullwheelLoc = ride.ChairliftBullwheelLocation[1].ToCoordsXYZ(); map_invalidate_tile_zoom1({ bullwheelLoc, bullwheelLoc.z, bullwheelLoc.z + (4 * COORDS_Z_STEP) }); } @@ -1196,19 +1195,20 @@ static constexpr const CoordsXY ride_spiral_slide_main_tile_offset[][4] = { * * rct2: 0x006AC545 */ -void Ride::UpdateSpiralSlide() + +void UpdateSpiralSlide(Ride& ride) { if (gCurrentTicks & 3) return; - if (slide_in_use == 0) + if (ride.slide_in_use == 0) return; - spiral_slide_progress++; - if (spiral_slide_progress >= 48) + ride.spiral_slide_progress++; + if (ride.spiral_slide_progress >= 48) { - slide_in_use--; + ride.slide_in_use--; - auto* peep = GetEntity(slide_peep); + auto* peep = GetEntity(ride.slide_peep); if (peep != nullptr) { auto destination = peep->GetDestination(); @@ -1221,12 +1221,12 @@ void Ride::UpdateSpiralSlide() // Invalidate something related to station start for (int32_t i = 0; i < OpenRCT2::Limits::MaxStationsPerRide; i++) { - if (stations[i].Start.IsNull()) + if (ride.stations[i].Start.IsNull()) continue; - auto startLoc = stations[i].Start; + auto startLoc = ride.stations[i].Start; - TileElement* tileElement = ride_get_station_start_track_element(this, StationIndex::FromUnderlying(i)); + TileElement* tileElement = ride_get_station_start_track_element(&ride, StationIndex::FromUnderlying(i)); if (tileElement == nullptr) continue; diff --git a/src/openrct2/ride/Ride.h b/src/openrct2/ride/Ride.h index 5238d45d59..ef8e95c6ce 100644 --- a/src/openrct2/ride/Ride.h +++ b/src/openrct2/ride/Ride.h @@ -279,6 +279,10 @@ struct Ride uint8_t current_issues; uint32_t last_issue_time; + // TO-DO: those friend functions are temporary, find a way to not access the private fields + friend void UpdateSpiralSlide(Ride& ride); + friend void UpdateChairlift(Ride& ride); + private: std::array stations; @@ -298,8 +302,6 @@ public: private: void Update(); - void UpdateChairlift(); - void UpdateSpiralSlide(); void UpdateQueueLength(StationIndex stationIndex); ResultWithMessage CreateVehicles(const CoordsXYE& element, bool isApplying); void MoveTrainsToBlockBrakes(TrackElement* firstBlock); @@ -396,6 +398,8 @@ public: bool HasRecolourableShopItems() const; bool HasStation() const; }; +void UpdateSpiralSlide(Ride& ride); +void UpdateChairlift(Ride& ride); #pragma pack(push, 1) diff --git a/src/openrct2/ride/RideData.h b/src/openrct2/ride/RideData.h index fce70de999..b3ab7cd368 100644 --- a/src/openrct2/ride/RideData.h +++ b/src/openrct2/ride/RideData.h @@ -160,6 +160,7 @@ using RideMusicUpdateFunction = void (*)(Ride*); using PeepUpdateRideLeaveEntranceFunc = void (*)(Guest*, Ride*, CoordsXYZD&); using StartRideMusicFunction = void (*)(const OpenRCT2::RideAudio::ViewportRideMusicInstance&); using LightFXAddLightsMagicVehicleFunction = void (*)(const Vehicle* vehicle); +using RideUpdateFunction = void (*)(Ride& ride); using RideUpdateMeasurementsSpecialElementsFunc = void (*)(Ride* ride, const track_type_t trackType); using MusicTrackOffsetLengthFunc = std::pair (*)(const Ride& ride); @@ -228,6 +229,7 @@ struct RideTypeDescriptor PeepUpdateRideLeaveEntranceFunc UpdateLeaveEntrance = PeepUpdateRideLeaveEntranceDefault; RideConstructionWindowContext ConstructionWindowContext = RideConstructionWindowContext::Default; + RideUpdateFunction RideUpdate = nullptr; RideUpdateMeasurementsSpecialElementsFunc UpdateMeasurementsSpecialElements = RideUpdateMeasurementsSpecialElements_Default; diff --git a/src/openrct2/ride/coaster/meta/WaterCoaster.h b/src/openrct2/ride/coaster/meta/WaterCoaster.h index 24ef469c92..c5d14ec2a0 100644 --- a/src/openrct2/ride/coaster/meta/WaterCoaster.h +++ b/src/openrct2/ride/coaster/meta/WaterCoaster.h @@ -61,6 +61,7 @@ constexpr const RideTypeDescriptor WaterCoasterRTD = SET_FIELD(Classification, RideClassification::Ride), SET_FIELD(UpdateLeaveEntrance, PeepUpdateRideLeaveEntranceDefault), SET_FIELD(ConstructionWindowContext, RideConstructionWindowContext::Default), + SET_FIELD(RideUpdate, nullptr), SET_FIELD(UpdateMeasurementsSpecialElements, RideUpdateMeasurementsSpecialElements_WaterCoaster), }; // clang-format on diff --git a/src/openrct2/ride/gentle/meta/Circus.h b/src/openrct2/ride/gentle/meta/Circus.h index e84de20e72..496d55f55d 100644 --- a/src/openrct2/ride/gentle/meta/Circus.h +++ b/src/openrct2/ride/gentle/meta/Circus.h @@ -57,6 +57,7 @@ constexpr const RideTypeDescriptor CircusRTD = SET_FIELD(Classification,RideClassification::Ride), SET_FIELD(UpdateLeaveEntrance,PeepUpdateRideLeaveEntranceDefault), SET_FIELD(ConstructionWindowContext, RideConstructionWindowContext::Default), + SET_FIELD(RideUpdate, nullptr), SET_FIELD(UpdateMeasurementsSpecialElements, RideUpdateMeasurementsSpecialElements_Default), SET_FIELD(MusicTrackOffsetLength, OpenRCT2::RideAudio::RideMusicGetTrackOffsetLength_Circus), }; diff --git a/src/openrct2/ride/gentle/meta/MiniGolf.h b/src/openrct2/ride/gentle/meta/MiniGolf.h index 07dbfccc60..69ac375822 100644 --- a/src/openrct2/ride/gentle/meta/MiniGolf.h +++ b/src/openrct2/ride/gentle/meta/MiniGolf.h @@ -59,6 +59,7 @@ constexpr const RideTypeDescriptor MiniGolfRTD = SET_FIELD(Classification, RideClassification::Ride), SET_FIELD(UpdateLeaveEntrance, PeepUpdateRideLeaveEntranceDefault), SET_FIELD(ConstructionWindowContext, RideConstructionWindowContext::Default), + SET_FIELD(RideUpdate, nullptr), SET_FIELD(UpdateMeasurementsSpecialElements, RideUpdateMeasurementsSpecialElements_MiniGolf), }; // clang-format on diff --git a/src/openrct2/ride/gentle/meta/SpiralSlide.h b/src/openrct2/ride/gentle/meta/SpiralSlide.h index 28bb9513aa..ad613f3f73 100644 --- a/src/openrct2/ride/gentle/meta/SpiralSlide.h +++ b/src/openrct2/ride/gentle/meta/SpiralSlide.h @@ -59,5 +59,7 @@ constexpr const RideTypeDescriptor SpiralSlideRTD = SET_FIELD(MusicUpdateFunction, DefaultMusicUpdate), SET_FIELD(Classification, RideClassification::Ride), SET_FIELD(UpdateLeaveEntrance, PeepUpdateRideLeaveEntranceSpiralSlide), + SET_FIELD(ConstructionWindowContext, RideConstructionWindowContext::Default), + SET_FIELD(RideUpdate, UpdateSpiralSlide), }; // clang-format on diff --git a/src/openrct2/ride/transport/meta/Chairlift.h b/src/openrct2/ride/transport/meta/Chairlift.h index 88c2ea7294..d2a94b9c68 100644 --- a/src/openrct2/ride/transport/meta/Chairlift.h +++ b/src/openrct2/ride/transport/meta/Chairlift.h @@ -57,5 +57,12 @@ constexpr const RideTypeDescriptor ChairliftRTD = SET_FIELD(ColourKey, RideColourKey::Ride), SET_FIELD(Name, "chairlift"), SET_FIELD(LightFXAddLightsMagicVehicle, LightFxAddLightsMagicVehicle_ChairLift), + SET_FIELD(StartRideMusic, OpenRCT2::RideAudio::DefaultStartRideMusicChannel), + SET_FIELD(DesignCreateMode, TrackDesignCreateMode::Default), + SET_FIELD(MusicUpdateFunction, DefaultMusicUpdate), + SET_FIELD(Classification, RideClassification::Ride), + SET_FIELD(UpdateLeaveEntrance, PeepUpdateRideLeaveEntranceDefault), + SET_FIELD(ConstructionWindowContext, RideConstructionWindowContext::Default), + SET_FIELD(RideUpdate, UpdateChairlift), }; // clang-format on