forked from Skyrat-SS13/Skyrat-tg
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathtts_sound_TEMPORARY.dm
77 lines (60 loc) · 3.25 KB
/
tts_sound_TEMPORARY.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// TODO: SS220-TTS Remove this file when upstream `/mob/proc/playsound_local` supports passing `wait` as parameter.
// Copypasted `/mob/proc/playsound_local` method with `wait` support.
/mob/playsound_local(turf/turf_source, soundin, vol as num, vary, frequency, falloff_exponent = SOUND_FALLOFF_EXPONENT, channel = 0, pressure_affected = TRUE, sound/sound_to_use, max_distance, falloff_distance = SOUND_DEFAULT_FALLOFF_DISTANCE, distance_multiplier = 1, use_reverb = TRUE, wait = FALSE)
if(!wait)
return ..()
if(!client || !can_hear())
return
if(!sound_to_use)
sound_to_use = sound(get_sfx(soundin))
sound_to_use.wait = wait
sound_to_use.channel = channel || SSsounds.random_available_channel()
sound_to_use.volume = vol
if(vary)
if(frequency)
sound_to_use.frequency = frequency
else
sound_to_use.frequency = get_rand_frequency()
if(isturf(turf_source))
var/turf/turf_loc = get_turf(src)
//sound volume falloff with distance
var/distance = get_dist(turf_loc, turf_source) * distance_multiplier
if(max_distance) //If theres no max_distance we're not a 3D sound, so no falloff.
sound_to_use.volume -= (max(distance - falloff_distance, 0) ** (1 / falloff_exponent)) / ((max(max_distance, distance) - falloff_distance) ** (1 / falloff_exponent)) * sound_to_use.volume
//https://www.desmos.com/calculator/sqdfl8ipgf
if(pressure_affected)
//Atmosphere affects sound
var/pressure_factor = 1
var/datum/gas_mixture/hearer_env = turf_loc.return_air()
var/datum/gas_mixture/source_env = turf_source.return_air()
if(hearer_env && source_env)
var/pressure = min(hearer_env.return_pressure(), source_env.return_pressure())
if(pressure < ONE_ATMOSPHERE)
pressure_factor = max((pressure - SOUND_MINIMUM_PRESSURE)/(ONE_ATMOSPHERE - SOUND_MINIMUM_PRESSURE), 0)
else //space
pressure_factor = 0
if(distance <= 1)
pressure_factor = max(pressure_factor, 0.15) //touching the source of the sound
sound_to_use.volume *= pressure_factor
//End Atmosphere affecting sound
if(sound_to_use.volume <= 0)
return //No sound
var/dx = turf_source.x - turf_loc.x // Hearing from the right/left
sound_to_use.x = dx * distance_multiplier
var/dz = turf_source.y - turf_loc.y // Hearing from infront/behind
sound_to_use.z = dz * distance_multiplier
var/dy = (turf_source.z - turf_loc.z) * 5 * distance_multiplier // Hearing from above / below, multiplied by 5 because we assume height is further along coords.
sound_to_use.y = dy
sound_to_use.falloff = max_distance || 1 //use max_distance, else just use 1 as we are a direct sound so falloff isnt relevant.
// Sounds can't have their own environment. A sound's environment will be:
// 1. the mob's
// 2. the area's (defaults to SOUND_ENVRIONMENT_NONE)
if(sound_environment_override != SOUND_ENVIRONMENT_NONE)
sound_to_use.environment = sound_environment_override
else
var/area/A = get_area(src)
sound_to_use.environment = A.sound_environment
if(use_reverb && sound_to_use.environment != SOUND_ENVIRONMENT_NONE) //We have reverb, reset our echo setting
sound_to_use.echo[3] = -1300 //Room setting, 0 means normal reverb //SKYRAT EDIT CHANGE
sound_to_use.echo[4] = -1300 //RoomHF setting, 0 means normal reverb. //SKYRAT EDIT CHANGE
SEND_SOUND(src, sound_to_use)