From 92f2365bc2e0e42aa503a4d61c177af777e866aa Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Sat, 29 Jun 2024 07:19:05 +0200 Subject: [PATCH] [MIRROR] Fixes deaf mobs hearing ship/area ambience (#28461) * Fixes deaf mobs hearing ship/area ambience (#84207) Fixes #65618 :cl: ShizCalev fix: Deafened mobs will no longer hear the station's ambient sounds. fix: Fixed ambient sounds resetting their loop when entering different bodies (ie admin ghosting, being moved to other mobs, ect.) /:cl: * Fixes deaf mobs hearing ship/area ambience --------- Co-authored-by: Afevis --- code/controllers/subsystem/ambience.dm | 3 +++ code/game/area/areas.dm | 17 +++++++++++++++-- code/modules/client/client_defines.dm | 3 +++ code/modules/mob/living/init_signals.dm | 14 ++++++++++++++ code/modules/mob/living/living.dm | 4 ++++ code/modules/mob/login.dm | 2 ++ 6 files changed, 41 insertions(+), 2 deletions(-) diff --git a/code/controllers/subsystem/ambience.dm b/code/controllers/subsystem/ambience.dm index e138c2d6048c5..712a8cd80f5de 100644 --- a/code/controllers/subsystem/ambience.dm +++ b/code/controllers/subsystem/ambience.dm @@ -27,6 +27,9 @@ SUBSYSTEM_DEF(ambience) client_old_areas -= client_iterator continue + if(!client_mob.can_hear()) //WHAT? I CAN'T HEAR YOU + continue + //Check to see if the client-mob is in a valid area var/area/current_area = get_area(client_mob) if(!current_area) //Something's gone horribly wrong diff --git a/code/game/area/areas.dm b/code/game/area/areas.dm index 8d8977a6451ed..a2b5711691da1 100644 --- a/code/game/area/areas.dm +++ b/code/game/area/areas.dm @@ -552,13 +552,26 @@ GLOBAL_LIST_EMPTY(teleportlocs) ///Tries to play looping ambience to the mobs. /mob/proc/refresh_looping_ambience() + if(!client) //if a tree falls in the woods... + return var/area/my_area = get_area(src) + var/sound_to_use = my_area.ambient_buzz - if(!(client?.prefs.read_preference(/datum/preference/toggle/sound_ship_ambience)) || !my_area.ambient_buzz) + if(!sound_to_use || !(client.prefs.read_preference(/datum/preference/toggle/sound_ship_ambience))) SEND_SOUND(src, sound(null, repeat = 0, wait = 0, channel = CHANNEL_BUZZ)) + client.current_ambient_sound = null return - SEND_SOUND(src, sound(my_area.ambient_buzz, repeat = 1, wait = 0, volume = my_area.ambient_buzz_vol, channel = CHANNEL_BUZZ)) + if(!can_hear()) + SEND_SOUND(src, sound(null, repeat = 0, wait = 0, channel = CHANNEL_BUZZ)) + client.current_ambient_sound = null + return + + if(sound_to_use == client.current_ambient_sound) + return //don't reset current loops. + + client.current_ambient_sound = sound_to_use + SEND_SOUND(src, sound(sound_to_use, repeat = 1, wait = 0, volume = my_area.ambient_buzz_vol, channel = CHANNEL_BUZZ)) /** * Called when an atom exits an area diff --git a/code/modules/client/client_defines.dm b/code/modules/client/client_defines.dm index 97924643604c5..2b60b3bdbb2e4 100644 --- a/code/modules/client/client_defines.dm +++ b/code/modules/client/client_defines.dm @@ -268,3 +268,6 @@ /// Loot panel for the client var/datum/lootpanel/loot_panel + + ///Which ambient sound this client is currently being provided. + var/current_ambient_sound diff --git a/code/modules/mob/living/init_signals.dm b/code/modules/mob/living/init_signals.dm index 064a0573353eb..4bf0407c4670a 100644 --- a/code/modules/mob/living/init_signals.dm +++ b/code/modules/mob/living/init_signals.dm @@ -38,6 +38,9 @@ RegisterSignal(src, SIGNAL_ADDTRAIT(TRAIT_RESTRAINED), PROC_REF(on_restrained_trait_gain)) RegisterSignal(src, SIGNAL_REMOVETRAIT(TRAIT_RESTRAINED), PROC_REF(on_restrained_trait_loss)) + RegisterSignal(src, SIGNAL_ADDTRAIT(TRAIT_DEAF), PROC_REF(on_hearing_loss)) + RegisterSignal(src, SIGNAL_REMOVETRAIT(TRAIT_DEAF), PROC_REF(on_hearing_regain)) + RegisterSignals(src, list( SIGNAL_ADDTRAIT(TRAIT_CRITICAL_CONDITION), SIGNAL_REMOVETRAIT(TRAIT_CRITICAL_CONDITION), @@ -272,3 +275,14 @@ /mob/living/proc/undense_changed(datum/source) SIGNAL_HANDLER update_density() + +///Called when [TRAIT_DEAF] is added to the mob. +/mob/living/proc/on_hearing_loss() + SIGNAL_HANDLER + refresh_looping_ambience() + stop_sound_channel(CHANNEL_AMBIENCE) + +///Called when [TRAIT_DEAF] is added to the mob. +/mob/living/proc/on_hearing_regain() + SIGNAL_HANDLER + refresh_looping_ambience() diff --git a/code/modules/mob/living/living.dm b/code/modules/mob/living/living.dm index d5a12934bf22e..2dce366733a5a 100644 --- a/code/modules/mob/living/living.dm +++ b/code/modules/mob/living/living.dm @@ -2355,6 +2355,10 @@ GLOBAL_LIST_EMPTY(fire_appearances) REMOVE_TRAIT(src, TRAIT_CRITICAL_CONDITION, STAT_TRAIT) remove_from_alive_mob_list() add_to_dead_mob_list() + if(!can_hear()) + stop_sound_channel(CHANNEL_AMBIENCE) + refresh_looping_ambience() + ///Reports the event of the change in value of the buckled variable. diff --git a/code/modules/mob/login.dm b/code/modules/mob/login.dm index 2f013f855b855..81a9fa7c62447 100644 --- a/code/modules/mob/login.dm +++ b/code/modules/mob/login.dm @@ -100,6 +100,8 @@ update_client_colour() update_mouse_pointer() refresh_looping_ambience() + if(!can_hear()) + stop_sound_channel(CHANNEL_AMBIENCE) if(client) if(client.view_size)