diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 97d9878335..cebf81ce34 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -3153,7 +3153,7 @@ static ChangeInfoResult SoundEffectChangeInfo(uint sid, int numinfo, int prop, B switch (prop) { case 0x08: // Relative volume - sound->volume = buf->ReadByte(); + sound->volume = Clamp(buf->ReadByte(), 0, SOUND_EFFECT_MAX_VOLUME); break; case 0x09: // Priority @@ -7857,7 +7857,7 @@ static void ImportGRFSound(SoundEntry *sound) *sound = *GetSound(file->sound_offset + sound_id); /* Reset volume and priority, which TTDPatch doesn't copy */ - sound->volume = 128; + sound->volume = SOUND_EFFECT_MAX_VOLUME; sound->priority = 0; } @@ -7869,7 +7869,7 @@ static void ImportGRFSound(SoundEntry *sound) static void LoadGRFSound(size_t offs, SoundEntry *sound) { /* Set default volume and priority */ - sound->volume = 0x80; + sound->volume = SOUND_EFFECT_MAX_VOLUME; sound->priority = 0; if (offs != SIZE_MAX) { diff --git a/src/sound_type.h b/src/sound_type.h index adc1438e6b..7113da9947 100644 --- a/src/sound_type.h +++ b/src/sound_type.h @@ -119,4 +119,6 @@ typedef uint16_t SoundID; static const SoundID INVALID_SOUND = 0xFFFF; +static const uint8_t SOUND_EFFECT_MAX_VOLUME = 128; + #endif /* SOUND_TYPE_H */