diff --git a/src/s_advsound.cpp b/src/s_advsound.cpp index a381e91cd..cea8950ac 100644 --- a/src/s_advsound.cpp +++ b/src/s_advsound.cpp @@ -152,6 +152,7 @@ enum SICommands SI_Volume, SI_MusicAlias, SI_EDFOverride, + SI_Attenuation, }; // Blood was a cool game. If Monolith ever releases the source for it, @@ -247,6 +248,7 @@ static const char *SICommandStrings[] = "$volume", "$musicalias", "$edfoverride", + "$attenuation", NULL }; @@ -501,6 +503,7 @@ int S_AddSoundLump (const char *logicalname, int lump) newsfx.next = 0; newsfx.index = 0; newsfx.Volume = 1; + newsfx.Attenuation = 1; newsfx.PitchMask = CurrentPitchMask; newsfx.NearLimit = 2; newsfx.LimitRange = 256*256; @@ -1204,6 +1207,17 @@ static void S_AddSNDINFO (int lump) } break; + case SI_Attenuation: { + // $attenuation + int sfx; + + sc.MustGetString(); + sfx = S_FindSoundTentative(sc.String); + sc.MustGetFloat(); + S_sfx[sfx].Attenuation = (float)sc.Float; + } + break; + case SI_Rolloff: { // $rolloff *| [linear|log|custom] // Using * for the name makes it the default for sounds that don't specify otherwise. diff --git a/src/s_sound.cpp b/src/s_sound.cpp index 212658a13..c2e3b0f76 100644 --- a/src/s_sound.cpp +++ b/src/s_sound.cpp @@ -901,6 +901,8 @@ static FSoundChan *S_StartSound(AActor *actor, const sector_t *sec, const FPolyO } else if (sfx->bRandomHeader) { + // Random sounds attenuate based on the original (random) sound as well as the chosen one. + attenuation *= sfx->Attenuation; sound_id = FSoundID(S_PickReplacement (sound_id)); if (near_limit < 0) { @@ -928,6 +930,9 @@ static FSoundChan *S_StartSound(AActor *actor, const sector_t *sec, const FPolyO sfx = &S_sfx[sound_id]; } + // Attenuate the attenuation based on the sound. + attenuation *= sfx->Attenuation; + // The passed rolloff overrides any sound-specific rolloff. if (forcedrolloff != NULL && forcedrolloff->MinDistance != 0) { diff --git a/src/s_sound.h b/src/s_sound.h index d82e273ac..84881862c 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -41,7 +41,6 @@ struct sfxinfo_t int lumpnum; // lump number of sfx unsigned int next, index; // [RH] For hashing -// unsigned int frequency; // [RH] Preferred playback rate float Volume; BYTE PitchMask; @@ -65,6 +64,7 @@ struct sfxinfo_t enum { NO_LINK = 0xffffffff }; FRolloffInfo Rolloff; + float Attenuation; // Multiplies the attenuation passed to S_Sound. }; // Rolloff types