Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ private void ApplySfxEvents(AnimationTrackInstance trackInstance)

var clip = _audioService.GetRandomSoundClip(sfx.Name);
PrefabProps.NpcSound.clip = clip;
PrefabProps.NpcSound.maxDistance = sfx.Range.ToMeter();
PrefabProps.NpcSound.maxDistance = _audioService.GetSfxRangeMeters(sfx.Name, sfx.Range.ToMeter());
PrefabProps.NpcSound.Play();
}
}
Expand Down
22 changes: 22 additions & 0 deletions Assets/Gothic-Core/Scripts/Services/Audio/AudioService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Gothic.Core.Domain.Audio;
using Gothic.Core.Logging;
Expand Down Expand Up @@ -40,6 +41,13 @@ public class AudioService

private readonly SoundDomain _soundDomain = new SoundDomain().Inject();

// Animation sounds that carry further than their *eventSFX range (R:). Finite list, all others keep theirs.
private static readonly Dictionary<string, float> _sfxRangeOverridesMeters =
new(StringComparer.OrdinalIgnoreCase)
{
{ "HAMMER", 24f }
};

private AudioSource _scriptSoundSource;

public SoundEffectInstance InvOpen => _vmCacheService.TryGetSfxData("INV_OPEN").GetFirstSound();
Expand Down Expand Up @@ -169,6 +177,20 @@ public void SetScriptSoundSource(AudioSource audioSource)
_scriptSoundSource = audioSource;
}

/// <summary>
/// Range (m) in which an animation sound (*eventSFX) is audible: the override of the few sounds that carry
/// further than Gothic's range, else Gothic's own.
/// Chosen in play: Fellan's hammering (R:1000 = 10 m) must reach Alwin's sheep pen ~18 m away (his quest asks
/// whether you hear it); 60 m was heard across the harbour, 24 m reaches the pen. Unity's linear rolloff is
/// quiet long before Gothic's range is felt; a general rolloff change is a follow-up.
/// </summary>
public float GetSfxRangeMeters(string sfxName, float gothicRangeMeters)
{
return _sfxRangeOverridesMeters.TryGetValue(sfxName, out var overrideMeters)
? overrideMeters
: gothicRangeMeters;
}

/// <summary>
/// Non-positional sound, e.g. Daedalus Snd_Play("LogEntry").
/// </summary>
Expand Down