From 71ddf21925c8208d3c55ef1edce0a31a0beaf2b9 Mon Sep 17 00:00:00 2001 From: dearmochi Date: Sat, 10 Apr 2021 13:10:22 +0200 Subject: [PATCH] Adds volume channel for engine ambience (SM, Tesla) (#15845) --- code/__DEFINES/sound.dm | 5 ++++- code/__HELPERS/unsorted.dm | 2 ++ code/datums/looping_sounds/looping_sound.dm | 10 +++++++--- code/datums/looping_sounds/machinery_sounds.dm | 1 + code/modules/client/preference/preferences.dm | 1 + code/modules/power/supermatter/supermatter.dm | 8 ++++---- code/modules/power/tesla/energy_ball.dm | 4 ++-- 7 files changed, 21 insertions(+), 10 deletions(-) diff --git a/code/__DEFINES/sound.dm b/code/__DEFINES/sound.dm index 333efc90e0b..c3f7780b917 100644 --- a/code/__DEFINES/sound.dm +++ b/code/__DEFINES/sound.dm @@ -6,11 +6,14 @@ #define CHANNEL_HEARTBEAT 1020 //sound channel for heartbeats #define CHANNEL_BUZZ 1019 #define CHANNEL_AMBIENCE 1018 +#define CHANNEL_ENGINE 1017 // Engine ambient sounds + +#define USER_VOLUME(M, C) M?.client?.prefs.get_channel_volume(C) //THIS SHOULD ALWAYS BE THE LOWEST ONE! //KEEP IT UPDATED -#define CHANNEL_HIGHEST_AVAILABLE 1017 +#define CHANNEL_HIGHEST_AVAILABLE 1016 #define MAX_INSTRUMENT_CHANNELS (128 * 6) diff --git a/code/__HELPERS/unsorted.dm b/code/__HELPERS/unsorted.dm index 35388b7b824..3056485d755 100644 --- a/code/__HELPERS/unsorted.dm +++ b/code/__HELPERS/unsorted.dm @@ -2116,6 +2116,8 @@ GLOBAL_DATUM_INIT(dview_mob, /mob/dview, new) return "White Noise" if(CHANNEL_AMBIENCE) return "Ambience" + if(CHANNEL_ENGINE) + return "Engine Ambience" /proc/slot_bitfield_to_slot(input_slot_flags) // Kill off this garbage ASAP; slot flags and clothing flags should be IDENTICAL. GOSH DARN IT. Doesn't work with ears or pockets, either. switch(input_slot_flags) diff --git a/code/datums/looping_sounds/looping_sound.dm b/code/datums/looping_sounds/looping_sound.dm index 5e019439bc4..33fb5595c24 100644 --- a/code/datums/looping_sounds/looping_sound.dm +++ b/code/datums/looping_sounds/looping_sound.dm @@ -31,6 +31,8 @@ var/falloff_exponent var/muted = TRUE var/falloff_distance + /// Channel of the audio, random otherwise + var/channel /datum/looping_sound/New(list/_output_atoms = list(), start_immediately = FALSE, _direct = FALSE) if(!mid_sounds) @@ -75,14 +77,16 @@ var/list/atoms_cache = output_atoms var/sound/S = sound(soundfile) if(direct) - S.channel = SSsounds.random_available_channel() - S.volume = volume + S.channel = channel || SSsounds.random_available_channel() for(var/i in 1 to atoms_cache.len) var/atom/thing = atoms_cache[i] if(direct) + if(ismob(thing)) + var/mob/M = thing + S.volume = volume * (USER_VOLUME(M, channel) || 1) SEND_SOUND(thing, S) else - playsound(thing, S, volume, vary, extra_range, falloff_exponent = falloff_exponent, falloff_distance = falloff_distance) + playsound(thing, S, volume, vary, extra_range, falloff_exponent = falloff_exponent, falloff_distance = falloff_distance, channel = channel) /datum/looping_sound/proc/get_sound(looped, _mid_sounds) if(!_mid_sounds) diff --git a/code/datums/looping_sounds/machinery_sounds.dm b/code/datums/looping_sounds/machinery_sounds.dm index 280aa5fab60..432e2709335 100644 --- a/code/datums/looping_sounds/machinery_sounds.dm +++ b/code/datums/looping_sounds/machinery_sounds.dm @@ -16,3 +16,4 @@ falloff_exponent = 10 falloff_distance = 5 vary = TRUE + channel = CHANNEL_ENGINE diff --git a/code/modules/client/preference/preferences.dm b/code/modules/client/preference/preferences.dm index 7c45d7ce88a..5a838c3ac9a 100644 --- a/code/modules/client/preference/preferences.dm +++ b/code/modules/client/preference/preferences.dm @@ -192,6 +192,7 @@ GLOBAL_LIST_INIT(special_role_times, list( //minimum age (in days) for accounts "1020" = 100, // CHANNEL_HEARTBEAT "1019" = 100, // CHANNEL_BUZZ "1018" = 100, // CHANNEL_AMBIENCE + "1017" = 100, // CHANNEL_ENGINE ) /// The volume mixer save timer handle. Used to debounce the DB call to save, to avoid spamming. var/volume_mixer_saving = null diff --git a/code/modules/power/supermatter/supermatter.dm b/code/modules/power/supermatter/supermatter.dm index 5d505554c84..0cc682eae32 100644 --- a/code/modules/power/supermatter/supermatter.dm +++ b/code/modules/power/supermatter/supermatter.dm @@ -377,9 +377,9 @@ if(last_accent_sound < world.time && prob(20)) var/aggression = min(((damage / 800) * (power / 2500)), 1.0) * 100 if(damage >= 300) - playsound(src, "smdelam", max(50, aggression), FALSE, 40, 30, falloff_distance = 10) + playsound(src, "smdelam", max(50, aggression), FALSE, 40, 30, falloff_distance = 10, channel = CHANNEL_ENGINE) else - playsound(src, "smcalm", max(50, aggression), FALSE, 25, 25, falloff_distance = 10) + playsound(src, "smcalm", max(50, aggression), FALSE, 25, 25, falloff_distance = 10, channel = CHANNEL_ENGINE) var/next_sound = round((100 - aggression) * 5) last_accent_sound = world.time + max(SUPERMATTER_ACCENT_SOUND_MIN_COOLDOWN, next_sound) @@ -568,7 +568,7 @@ zap_count += 1 if(zap_count >= 1) - playsound(src.loc, 'sound/weapons/emitter2.ogg', 100, TRUE, extrarange = 10) + playsound(src.loc, 'sound/weapons/emitter2.ogg', 100, TRUE, extrarange = 10, channel = CHANNEL_ENGINE) for(var/i in 1 to zap_count) supermatter_zap(src, range, clamp(power*2, 4000, 20000), flags) @@ -807,7 +807,7 @@ icon_state = "darkmatter" /obj/machinery/power/supermatter_crystal/proc/supermatter_pull(turf/center, pull_range = 3) - playsound(center, 'sound/weapons/marauder.ogg', 100, TRUE, extrarange = pull_range - world.view) + playsound(center, 'sound/weapons/marauder.ogg', 100, TRUE, extrarange = pull_range - world.view, channel = CHANNEL_ENGINE) for(var/atom/movable/P in orange(pull_range,center)) if((P.anchored || P.move_resist >= MOVE_FORCE_EXTREMELY_STRONG)) //move resist memes. if(istype(P, /obj/structure/closet)) diff --git a/code/modules/power/tesla/energy_ball.dm b/code/modules/power/tesla/energy_ball.dm index a840c583128..02eaa84183e 100644 --- a/code/modules/power/tesla/energy_ball.dm +++ b/code/modules/power/tesla/energy_ball.dm @@ -65,7 +65,7 @@ move_the_basket_ball(4 + length(orbiting_balls) * 1.5) - playsound(loc, 'sound/magic/lightningbolt.ogg', 100, TRUE, extrarange = 30) + playsound(loc, 'sound/magic/lightningbolt.ogg', 100, TRUE, extrarange = 30, channel = CHANNEL_ENGINE) pixel_x = 0 pixel_y = 0 @@ -112,7 +112,7 @@ energy_to_lower = energy_to_raise - 20 energy_to_raise = energy_to_raise * 1.25 - playsound(src.loc, 'sound/magic/lightning_chargeup.ogg', 100, TRUE, extrarange = 30) + playsound(src.loc, 'sound/magic/lightning_chargeup.ogg', 100, TRUE, extrarange = 30, channel = CHANNEL_ENGINE) addtimer(CALLBACK(src, .proc/new_mini_ball), 100) else if(energy < energy_to_lower && length(orbiting_balls))