From ff52f85b9eaaf6781cee1c1e43138b6332e7b481 Mon Sep 17 00:00:00 2001 From: frosch Date: Sat, 2 Jul 2011 11:24:39 +0000 Subject: (svn r22614) -Fix [FS#4656]: If callback 33 returns a value out of range, no sound effect shall be played. --- src/newgrf_sound.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/newgrf_sound.cpp b/src/newgrf_sound.cpp index cbb6d512f..e5ab65d90 100644 --- a/src/newgrf_sound.cpp +++ b/src/newgrf_sound.cpp @@ -51,6 +51,12 @@ uint GetNumSounds() } +/** + * Checks whether a NewGRF wants to play a different vehicle sound effect. + * @param v Vehicle to play sound effect for. + * @param event Trigger for the sound effect. + * @return false if the default sound effect shall be played instead. + */ bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event) { const GRFFile *file = GetEngineGRF(v->engine_type); @@ -63,10 +69,15 @@ bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event) if (!HasBit(EngInfo(v->engine_type)->callback_mask, CBM_VEHICLE_SOUND_EFFECT)) return false; callback = GetVehicleCallback(CBID_VEHICLE_SOUND_EFFECT, event, 0, v->engine_type, v); + /* Play default sound if callback fails */ if (callback == CALLBACK_FAILED) return false; + if (callback >= ORIGINAL_SAMPLE_COUNT) { callback -= ORIGINAL_SAMPLE_COUNT; - if (callback > file->num_sounds) return false; + + /* Play no sound if result is out of range */ + if (callback > file->num_sounds) return true; + callback += file->sound_offset; } -- cgit v1.2.3-70-g09d2