Files
Bubberstation/code/controllers/subsystem/ambience.dm
The Sharkening b643391e5a 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>
2024-07-01 10:52:23 +02:00

138 lines
4.9 KiB
Plaintext

/// The subsystem used to play ambience to users every now and then, makes them real excited.
SUBSYSTEM_DEF(ambience)
name = "Ambience"
flags = SS_BACKGROUND|SS_NO_INIT
priority = FIRE_PRIORITY_AMBIENCE
runlevels = RUNLEVEL_GAME | RUNLEVEL_POSTGAME
wait = 1 SECONDS
///Assoc list of listening client - next ambience time
var/list/ambience_listening_clients = list()
var/list/client_old_areas = list()
///Cache for sanic speed :D
var/list/currentrun = list()
/datum/controller/subsystem/ambience/fire(resumed)
if(!resumed)
currentrun = ambience_listening_clients.Copy()
var/list/cached_clients = currentrun
while(cached_clients.len)
var/client/client_iterator = cached_clients[cached_clients.len]
cached_clients.len--
//Check to see if the client exists and isn't held by a new player
var/mob/client_mob = client_iterator?.mob
if(isnull(client_iterator) || !client_mob || isnewplayer(client_mob))
ambience_listening_clients -= client_iterator
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
stack_trace("[key_name(client_mob)] has somehow ended up in nullspace. WTF did you do")
ambience_listening_clients -= client_iterator
continue
if(ambience_listening_clients[client_iterator] > world.time)
if(!(current_area.forced_ambience && (client_old_areas?[client_iterator] != current_area) && prob(5)))
continue
//Run play_ambience() on the client-mob and set a cooldown
ambience_listening_clients[client_iterator] = world.time + current_area.play_ambience(client_mob)
//We REALLY don't want runtimes in SSambience
if(client_iterator)
client_old_areas[client_iterator] = current_area
if(MC_TICK_CHECK)
return
///Attempts to play an ambient sound to a mob, returning the cooldown in deciseconds
/area/proc/play_ambience(mob/M, sound/override_sound, volume = 27)
var/sound/new_sound = override_sound || pick(ambientsounds)
new_sound = sound(new_sound, repeat = 0, wait = 0, volume = volume, channel = CHANNEL_AMBIENCE)
SEND_SOUND(M, new_sound)
return rand(min_ambience_cooldown, max_ambience_cooldown)
/datum/controller/subsystem/ambience/proc/remove_ambience_client(client/to_remove)
ambience_listening_clients -= to_remove
client_old_areas -= to_remove
currentrun -= to_remove
/area/station/maintenance
min_ambience_cooldown = 20 SECONDS
max_ambience_cooldown = 35 SECONDS
///A list of rare sound effects to fuck with players. No, it does not contain actual minecraft sounds anymore.
var/static/list/minecraft_cave_noises = list(
'sound/machines/airlock.ogg',
'sound/effects/snap.ogg',
'sound/effects/footstep/clownstep1.ogg',
'sound/effects/footstep/clownstep2.ogg',
'sound/items/welder.ogg',
'sound/items/welder2.ogg',
'sound/items/crowbar.ogg',
'sound/items/deconstruct.ogg',
'sound/ambience/source_holehit3.ogg',
'sound/ambience/cavesound3.ogg',
)
/area/station/maintenance/play_ambience(mob/M, sound/override_sound, volume)
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))