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

🆑 Kapu (ported by StrangeWeirdKitten)
fix: Ambience buzz will now respect ship ambience prefrences for
observers.
sound: Ambience buzz requires APC enviorment power to function
/🆑

---------

Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com>
This commit is contained in:
The Sharkening
2024-07-01 10:52:23 +02:00
committed by GitHub
co-authored by Ghom
parent 8c605d151d
commit b643391e5a
6 changed files with 64 additions and 34 deletions
+49
View File
@@ -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))