diff options
author | frosch <frosch@openttd.org> | 2011-07-02 11:24:39 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2011-07-02 11:24:39 +0000 |
commit | ff52f85b9eaaf6781cee1c1e43138b6332e7b481 (patch) | |
tree | d6e7016aa4817b102890c6a6c354ffc10e5d8c39 /src | |
parent | 22378a2164fcab223fa3cde09e02726148f17a7a (diff) | |
download | openttd-ff52f85b9eaaf6781cee1c1e43138b6332e7b481.tar.xz |
(svn r22614) -Fix [FS#4656]: If callback 33 returns a value out of range, no sound effect shall be played.
Diffstat (limited to 'src')
-rw-r--r-- | src/newgrf_sound.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
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; } |