diff --git a/distribution/changelog.txt b/distribution/changelog.txt index dbe17103cc..39fa549daa 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -30,8 +30,9 @@ - Fix: [#15255] Tile Inspector shows banner information on walls that do not contain one. - Fix: [#15257] Chat icon shows in scenario/track editor. Other icons don't disable when deactivated in options menu. - Fix: [#15289] Unexpected behavior with duplicated banners which also caused desyncs in multiplayer. -- Fix: [#15451] Guest list name filter remains after group selection. +- Fix: [#15322] Circus music doesn't play. - Fix: [#15377] Entrance/exit ghost doesn't work on different stations without touching them first. +- Fix: [#15451] Guest list name filter remains after group selection. - Fix: [#15476] Crash when placing/clearing small scenery. - Fix: [#15487] Map animations do not work correctly when loading an exported SV6 file in vanilla RCT2. - Fix: [#15490] Tile inspector needlessly updates clearance height when changing surface slopes. diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 602d9a417c..9e62de1cd6 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -1753,35 +1753,30 @@ Staff* ride_get_assigned_mechanic(Ride* ride) /** * - * rct2: 0x006ABE85 + * Calculates the sample rate for ride music. */ -static void ride_music_update(Ride* ride) +static int32_t RideMusicSampleRate(Ride* ride) { - // The circus does not have music in the normal sense - its “music” is a sound effect. - if (ride->type == RIDE_TYPE_CIRCUS) - { - Vehicle* vehicle = GetEntity(ride->vehicles[0]); - if (vehicle == nullptr || vehicle->status != Vehicle::Status::DoingCircusShow) - { - ride->music_tune_id = 255; - return; - } - } - else - { - const auto& rtd = ride->GetRideTypeDescriptor(); - if (!rtd.HasFlag(RIDE_TYPE_FLAG_MUSIC_ON_DEFAULT) && !rtd.HasFlag(RIDE_TYPE_FLAG_ALLOW_MUSIC)) - { - return; - } + int32_t sampleRate = 22050; - if (ride->status != RideStatus::Open || !(ride->lifecycle_flags & RIDE_LIFECYCLE_MUSIC)) - { - ride->music_tune_id = 255; - return; - } + // Alter sample rate for a power cut effect + if (ride->lifecycle_flags & (RIDE_LIFECYCLE_BREAKDOWN_PENDING | RIDE_LIFECYCLE_BROKEN_DOWN)) + { + sampleRate = ride->breakdown_sound_modifier * 70; + if (ride->breakdown_reason_pending != BREAKDOWN_CONTROL_FAILURE) + sampleRate *= -1; + sampleRate += 22050; } + return sampleRate; +} + +/** + * + * Ride music slows down upon breaking. If it's completely broken, no music should play. + */ +static bool RideMusicBreakdownEffect(Ride* ride) +{ // Oscillate parameters for a power cut effect when breaking down if (ride->lifecycle_flags & (RIDE_LIFECYCLE_BREAKDOWN_PENDING | RIDE_LIFECYCLE_BROKEN_DOWN)) { @@ -1804,10 +1799,67 @@ static void ride_music_update(Ride* ride) if (ride->breakdown_sound_modifier == 255) { ride->music_tune_id = 255; - return; + return true; } } } + return false; +} + +/** + * + * Circus music is a sound effect, rather than music. Needs separate processing. + */ +static void CircusMusicUpdate(Ride* ride) +{ + Vehicle* vehicle = GetEntity(ride->vehicles[0]); + if (vehicle == nullptr || vehicle->status != Vehicle::Status::DoingCircusShow) + { + ride->music_position = 0; + ride->music_tune_id = 255; + return; + } + + if (RideMusicBreakdownEffect(ride)) + { + return; + } + + CoordsXYZ rideCoords = ride->stations[0].GetStart().ToTileCentre(); + + const auto sampleRate = RideMusicSampleRate(ride); + + OpenRCT2::RideAudio::UpdateMusicInstance(*ride, rideCoords, sampleRate); +} + +/** + * + * rct2: 0x006ABE85 + */ +static void ride_music_update(Ride* ride) +{ + if (ride->type == RIDE_TYPE_CIRCUS) + { + CircusMusicUpdate(ride); + return; + } + + const auto& rtd = ride->GetRideTypeDescriptor(); + if (!rtd.HasFlag(RIDE_TYPE_FLAG_MUSIC_ON_DEFAULT) && !rtd.HasFlag(RIDE_TYPE_FLAG_ALLOW_MUSIC)) + { + return; + } + + if (ride->status != RideStatus::Open || !(ride->lifecycle_flags & RIDE_LIFECYCLE_MUSIC)) + { + ride->music_tune_id = 255; + return; + } + + if (RideMusicBreakdownEffect(ride)) + { + return; + } // Select random tune from available tunes for a music style (of course only merry-go-rounds have more than one tune) if (ride->music_tune_id == 255) @@ -1825,16 +1877,7 @@ static void ride_music_update(Ride* ride) CoordsXYZ rideCoords = ride->stations[0].GetStart().ToTileCentre(); - int32_t sampleRate = 22050; - - // Alter sample rate for a power cut effect - if (ride->lifecycle_flags & (RIDE_LIFECYCLE_BREAKDOWN_PENDING | RIDE_LIFECYCLE_BROKEN_DOWN)) - { - sampleRate = ride->breakdown_sound_modifier * 70; - if (ride->breakdown_reason_pending != BREAKDOWN_CONTROL_FAILURE) - sampleRate *= -1; - sampleRate += 22050; - } + int32_t sampleRate = RideMusicSampleRate(ride); OpenRCT2::RideAudio::UpdateMusicInstance(*ride, rideCoords, sampleRate); }