From b643391e5abcf50bfcbcc6fa7f5d8511cb7cb430 Mon Sep 17 00:00:00 2001 From: The Sharkening <95130227+StrangeWeirdKitten@users.noreply.github.com> Date: Mon, 1 Jul 2024 02:52:23 -0600 Subject: [PATCH] Ambience Buzz Handling Changes + Ambience buzz requires enviorment power (#84479) ## About The Pull Request Partial port of https://github.com/DaedalusDock/daedalusdock/pull/996 - Fixes ambience prefrence inconsistancy issues with Observers unable to turn off the ambience buzz. - Ambience buzz requires a working, existing, charged APC with power to the enviorment. - Moves ``update_ambience_area()`` and ``refresh_looping_ambience()`` into ``code\controllers\subsystem\ambience.dm`` for better organization. ## Why It's Good For The Game Mostly to tackle a prefrence bug where ghosts are unable to turn off ambience buzz. But this also includes ambience buzz requiring a powered area. Makes the station feel more dead when there's no enviorment power. There should also be no buzzing inside space. ## Changelog :cl: Kapu (ported by StrangeWeirdKitten) fix: Ambience buzz will now respect ship ambience prefrences for observers. sound: Ambience buzz requires APC enviorment power to function /:cl: --------- Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com> --- code/controllers/subsystem/ambience.dm | 49 ++++++++++++++++++++++ code/game/area/areas.dm | 36 ++-------------- code/modules/mob/dead/observer/observer.dm | 6 +++ code/modules/mob/login.dm | 3 +- code/modules/mob/logout.dm | 1 + code/modules/mob/mob_defines.dm | 3 ++ 6 files changed, 64 insertions(+), 34 deletions(-) diff --git a/code/controllers/subsystem/ambience.dm b/code/controllers/subsystem/ambience.dm index 712a8cd80f5..cae5d85246d 100644 --- a/code/controllers/subsystem/ambience.dm +++ b/code/controllers/subsystem/ambience.dm @@ -86,3 +86,52 @@ SUBSYSTEM_DEF(ambience) if(!M.has_light_nearby() && prob(0.5)) return ..(M, pick(minecraft_cave_noises)) return ..() + +/** + * Ambience buzz handling called by either area/Enter() or refresh_looping_ambience() + */ + +/mob/proc/update_ambience_area(area/new_area) + + var/old_tracked_area = ambience_tracked_area + if(old_tracked_area) + UnregisterSignal(old_tracked_area, COMSIG_AREA_POWER_CHANGE) + ambience_tracked_area = null + if(!client) + return + if(new_area) + ambience_tracked_area = new_area + RegisterSignal(ambience_tracked_area, COMSIG_AREA_POWER_CHANGE, PROC_REF(refresh_looping_ambience), TRUE) + + refresh_looping_ambience() + +/mob/proc/refresh_looping_ambience() + SIGNAL_HANDLER + + 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(!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 + + if(!can_hear()) // Can the mob hear? + SEND_SOUND(src, sound(null, repeat = 0, wait = 0, channel = CHANNEL_BUZZ)) + client.current_ambient_sound = null + return + + //Station ambience is dependant on a functioning and charged APC with enviorment power enabled. + if(!is_mining_level(my_area.z) && ((!my_area.apc || !my_area.apc.operating || !my_area.apc.cell?.charge && my_area.requires_power || !my_area.power_environ))) + SEND_SOUND(src, sound(null, repeat = 0, wait = 0, channel = CHANNEL_BUZZ)) + client.current_ambient_sound = null + return + else + if(sound_to_use == client.current_ambient_sound) // Don't reset current loops + return + + client.current_ambient_sound = sound_to_use + SEND_SOUND(src, sound(my_area.ambient_buzz, repeat = 1, wait = 0, volume = my_area.ambient_buzz_vol, channel = CHANNEL_BUZZ)) diff --git a/code/game/area/areas.dm b/code/game/area/areas.dm index 51d660af045..36ce8c5a24f 100644 --- a/code/game/area/areas.dm +++ b/code/game/area/areas.dm @@ -540,39 +540,9 @@ GLOBAL_LIST_EMPTY(teleportlocs) for(var/atom/movable/recipient as anything in arrived.important_recursive_contents[RECURSIVE_CONTENTS_AREA_SENSITIVE]) SEND_SIGNAL(recipient, COMSIG_ENTER_AREA, src) - if(!isliving(arrived)) - return - - var/mob/living/L = arrived - if(!L.ckey) - return - - if(ambient_buzz != old_area.ambient_buzz) - L.refresh_looping_ambience() - -///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(!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 - - 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)) - + if(ismob(arrived)) + var/mob/mob = arrived + mob.update_ambience_area(src) /** * Called when an atom exits an area diff --git a/code/modules/mob/dead/observer/observer.dm b/code/modules/mob/dead/observer/observer.dm index 1a7b362ec2e..c1a81b9d338 100644 --- a/code/modules/mob/dead/observer/observer.dm +++ b/code/modules/mob/dead/observer/observer.dm @@ -359,6 +359,12 @@ This is the proc mobs get to turn into a ghost. Forked from ghostize due to comp abstract_move(destination) // move like the wind return TRUE +/mob/dead/observer/Moved(atom/old_loc, movement_dir, forced, list/old_locs, momentum_change) + . = ..() + var/area/new_area = get_area(src) + if(new_area != ambience_tracked_area) + update_ambience_area(new_area) + /mob/dead/observer/verb/reenter_corpse() set category = "Ghost" set name = "Re-enter Corpse" diff --git a/code/modules/mob/login.dm b/code/modules/mob/login.dm index 81a9fa7c624..a4964add6c8 100644 --- a/code/modules/mob/login.dm +++ b/code/modules/mob/login.dm @@ -99,7 +99,8 @@ update_client_colour() update_mouse_pointer() - refresh_looping_ambience() + update_ambience_area(get_area(src)) + if(!can_hear()) stop_sound_channel(CHANNEL_AMBIENCE) diff --git a/code/modules/mob/logout.dm b/code/modules/mob/logout.dm index cf937e42bb7..09d50c8436c 100644 --- a/code/modules/mob/logout.dm +++ b/code/modules/mob/logout.dm @@ -3,6 +3,7 @@ log_message("[key_name(src)] is no longer owning mob [src]([src.type])", LOG_OWNERSHIP) SStgui.on_logout(src) remove_from_player_list() + update_ambience_area(null) // Unset ambience vars so it plays again on login ..() if(loc) diff --git a/code/modules/mob/mob_defines.dm b/code/modules/mob/mob_defines.dm index a0658c3a02b..2206efd0e13 100644 --- a/code/modules/mob/mob_defines.dm +++ b/code/modules/mob/mob_defines.dm @@ -191,3 +191,6 @@ var/active_typing_indicator ///the icon currently used for the thinking indicator's bubble var/active_thinking_indicator + + /// A ref of the area we're taking our ambient loop from. + var/area/ambience_tracked_area