From ac561dbf4521d09bab039515b6a2f2fed1d7962f Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Wed, 10 Feb 2021 01:41:30 +0100 Subject: [PATCH] [MIRROR] Refactors ambience to a subsystem (#3245) * Refactors ambience to a subsystem (#56723) Ambience is now in a subsystem, and plays every now and then without you having to move to a new area for it to play * Refactors ambience to a subsystem Co-authored-by: Qustinnus --- code/__DEFINES/subsystems.dm | 1 + code/_globalvars/lists/ambience.dm | 2 +- code/controllers/subsystem/ambience.dm | 27 ++++++++++++++++++++++ code/game/area/areas.dm | 26 ++++++--------------- code/game/area/areas/mining.dm | 13 ++++++++++- code/game/area/space_station_13_areas.dm | 4 ++++ code/modules/client/client_defines.dm | 5 +--- code/modules/client/client_procs.dm | 10 ++++++++ code/modules/client/preferences_toggles.dm | 2 +- tgstation.dme | 1 + 10 files changed, 65 insertions(+), 26 deletions(-) create mode 100644 code/controllers/subsystem/ambience.dm diff --git a/code/__DEFINES/subsystems.dm b/code/__DEFINES/subsystems.dm index d5ca5eba8c6..b6d5cceac54 100644 --- a/code/__DEFINES/subsystems.dm +++ b/code/__DEFINES/subsystems.dm @@ -154,6 +154,7 @@ #define FIRE_PRIORITY_SERVER_MAINT 10 #define FIRE_PRIORITY_RESEARCH 10 #define FIRE_PRIORITY_VIS 10 +#define FIRE_PRIORITY_AMBIENCE 10 #define FIRE_PRIORITY_GARBAGE 15 #define FIRE_PRIORITY_WET_FLOORS 20 #define FIRE_PRIORITY_AIR 20 diff --git a/code/_globalvars/lists/ambience.dm b/code/_globalvars/lists/ambience.dm index 3573c380a3c..0bd581dea89 100644 --- a/code/_globalvars/lists/ambience.dm +++ b/code/_globalvars/lists/ambience.dm @@ -39,7 +39,7 @@ GLOBAL_LIST_INIT(mining_ambience,list( 'sound/ambience/ambiruin5.ogg', 'sound/ambience/ambiruin6.ogg', 'sound/ambience/ambiruin7.ogg', 'sound/ambience/ambidanger.ogg', 'sound/ambience/ambidanger2.ogg', 'sound/ambience/ambimaint1.ogg', - 'sound/ambience/ambilava1.ogg', 'sound/ambience/ambilava2.ogg', + 'sound/ambience/ambilava1.ogg', 'sound/ambience/ambilava2.ogg', 'sound/ambience/ambilava3.ogg')) GLOBAL_LIST_INIT(medical_ambience,list('sound/ambience/ambinice.ogg')) diff --git a/code/controllers/subsystem/ambience.dm b/code/controllers/subsystem/ambience.dm new file mode 100644 index 00000000000..6a1595d7204 --- /dev/null +++ b/code/controllers/subsystem/ambience.dm @@ -0,0 +1,27 @@ +/// 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() + +/datum/controller/subsystem/ambience/fire(resumed) + for(var/client/client_iterator as anything in ambience_listening_clients) + + if(isnull(client_iterator)) + ambience_listening_clients -= client_iterator + continue + + if(ambience_listening_clients[client_iterator] > world.time) + continue //Not ready for the next sound + + var/area/current_area = get_area(client_iterator.mob) + + var/sound = pick(current_area.ambientsounds) + + SEND_SOUND(client_iterator.mob, sound(sound, repeat = 0, wait = 0, volume = 25, channel = CHANNEL_AMBIENCE)) + + ambience_listening_clients[client_iterator] = world.time + rand(current_area.min_ambience_cooldown, current_area.max_ambience_cooldown) diff --git a/code/game/area/areas.dm b/code/game/area/areas.dm index 1bd90ff2f0f..3c3be6f3557 100644 --- a/code/game/area/areas.dm +++ b/code/game/area/areas.dm @@ -85,6 +85,11 @@ ///Used to decide what kind of reverb the area makes sound have var/sound_environment = SOUND_ENVIRONMENT_NONE + ///Used to decide what the minimum time between ambience is + var/min_ambience_cooldown = 30 SECONDS + ///Used to decide what the maximum time between ambience is + var/max_ambience_cooldown = 90 SECONDS + /** * A list of teleport locations * @@ -574,22 +579,10 @@ GLOBAL_LIST_EMPTY(teleportlocs) if(!L.ckey) return - // Ambience goes down here -- make sure to list each area separately for ease of adding things in later, thanks! Note: areas adjacent to each other should have the same sounds to prevent cutoff when possible.- LastyScratch - if(L.client && !L.client.ambience_playing && L.client.prefs.toggles & SOUND_SHIP_AMBIENCE) - L.client.ambience_playing = 1 + //Ship ambience just loops if turned on. + if(L.client?.prefs.toggles & SOUND_SHIP_AMBIENCE) SEND_SOUND(L, sound('sound/ambience/shipambience.ogg', repeat = 1, wait = 0, volume = 35, channel = CHANNEL_BUZZ)) - if(!(L.client && (L.client.prefs.toggles & SOUND_AMBIENCE))) - return //General ambience check is below the ship ambience so one can play without the other - - if(prob(35)) - var/sound = pick(ambientsounds) - - if(!L.client.played) - SEND_SOUND(L, sound(sound, repeat = 0, wait = 0, volume = 25, channel = CHANNEL_AMBIENCE)) - L.client.played = TRUE - addtimer(CALLBACK(L.client, /client/proc/ResetAmbiencePlayed), 600) - ///Divides total beauty in the room by roomsize to allow us to get an average beauty per tile. /area/proc/update_beauty() if(!areasize) @@ -610,11 +603,6 @@ GLOBAL_LIST_EMPTY(teleportlocs) SEND_SIGNAL(src, COMSIG_AREA_EXITED, M) SEND_SIGNAL(M, COMSIG_EXIT_AREA, src) //The atom that exits the area -/** - * Reset the played var to false on the client - */ -/client/proc/ResetAmbiencePlayed() - played = FALSE /** * Setup an area (with the given name) diff --git a/code/game/area/areas/mining.dm b/code/game/area/areas/mining.dm index 46fe5dac000..f4fd675b9b6 100644 --- a/code/game/area/areas/mining.dm +++ b/code/game/area/areas/mining.dm @@ -18,6 +18,8 @@ ambience_index = AMBIENCE_MINING area_flags = VALID_TERRITORY | UNIQUE_AREA | NO_ALERTS sound_environment = SOUND_AREA_STANDARD_STATION + min_ambience_cooldown = 70 SECONDS + max_ambience_cooldown = 220 SECONDS /area/mine/unexplored name = "Mine" @@ -31,6 +33,8 @@ flags_1 = NONE ambience_index = AMBIENCE_MINING area_flags = VALID_TERRITORY | UNIQUE_AREA | FLORA_ALLOWED | CAVES_ALLOWED | NO_ALERTS + min_ambience_cooldown = 70 SECONDS + max_ambience_cooldown = 220 SECONDS /area/mine/lobby name = "Mining Station" @@ -104,6 +108,8 @@ requires_power = TRUE ambience_index = AMBIENCE_MINING area_flags = VALID_TERRITORY | UNIQUE_AREA | FLORA_ALLOWED | NO_ALERTS + min_ambience_cooldown = 70 SECONDS + max_ambience_cooldown = 220 SECONDS /area/lavaland/underground name = "Lavaland Caves" @@ -115,7 +121,8 @@ power_light = FALSE ambience_index = AMBIENCE_MINING area_flags = VALID_TERRITORY | UNIQUE_AREA | FLORA_ALLOWED | NO_ALERTS - + min_ambience_cooldown = 70 SECONDS + max_ambience_cooldown = 220 SECONDS /area/lavaland/surface/outdoors name = "Lavaland Wastes" @@ -155,6 +162,8 @@ requires_power = TRUE ambience_index = AMBIENCE_MINING area_flags = UNIQUE_AREA | FLORA_ALLOWED | NO_ALERTS + min_ambience_cooldown = 70 SECONDS + max_ambience_cooldown = 220 SECONDS /area/icemoon/surface/outdoors // weather happens here name = "Icemoon Wastes" @@ -185,6 +194,8 @@ power_light = FALSE ambience_index = AMBIENCE_MINING area_flags = UNIQUE_AREA | FLORA_ALLOWED | NO_ALERTS + min_ambience_cooldown = 70 SECONDS + max_ambience_cooldown = 220 SECONDS /area/icemoon/underground/unexplored // mobs and megafauna and ruins spawn here name = "Icemoon Caves" diff --git a/code/game/area/space_station_13_areas.dm b/code/game/area/space_station_13_areas.dm index 237049c9aae..85bf35d996b 100644 --- a/code/game/area/space_station_13_areas.dm +++ b/code/game/area/space_station_13_areas.dm @@ -63,6 +63,8 @@ NOTE: there are two lists of areas in the end of this file: centcom and station ambience_index = AMBIENCE_MINING flags_1 = CAN_BE_DIRTY_1 sound_environment = SOUND_AREA_ASTEROID + min_ambience_cooldown = 70 SECONDS + max_ambience_cooldown = 220 SECONDS /area/asteroid/nearstation dynamic_lighting = DYNAMIC_LIGHTING_FORCED @@ -922,6 +924,8 @@ NOTE: there are two lists of areas in the end of this file: centcom and station ambience_index = AMBIENCE_MEDICAL airlock_wires = /datum/wires/airlock/medbay sound_environment = SOUND_AREA_STANDARD_STATION + min_ambience_cooldown = 90 SECONDS + max_ambience_cooldown = 180 SECONDS /area/medical/abandoned name = "Abandoned Medbay" diff --git a/code/modules/client/client_defines.dm b/code/modules/client/client_defines.dm index 9167476899b..58a2e519641 100644 --- a/code/modules/client/client_defines.dm +++ b/code/modules/client/client_defines.dm @@ -44,10 +44,7 @@ /////////////// //SOUND STUFF// /////////////// - ///Currently playing ambience sound - var/ambience_playing = null - ///Whether an ambience sound has been played and one shouldn't be played again, unset by a callback - var/played = FALSE + //////////// //SECURITY// //////////// diff --git a/code/modules/client/client_procs.dm b/code/modules/client/client_procs.dm index cd8473cba53..9d894b101c1 100644 --- a/code/modules/client/client_procs.dm +++ b/code/modules/client/client_procs.dm @@ -435,6 +435,7 @@ GLOBAL_LIST_INIT(blacklisted_builds, list( if(!winexists(src, "asset_cache_browser")) // The client is using a custom skin, tell them. to_chat(src, "Unable to access asset cache browser, if you are using a custom skin file, please allow DS to download the updated version, if you are not, then make a bug report. This is not a critical issue but can cause issues with resource downloading, as it is impossible to know when extra resources arrived to you.") + update_ambience_pref() //This is down here because of the browse() calls in tooltip/New() if(!tooltips) @@ -500,6 +501,7 @@ GLOBAL_LIST_INIT(blacklisted_builds, list( UNSETEMPTY(movingmob.client_mobs_in_contents) movingmob = null active_mousedown_item = null + SSambience.ambience_listening_clients -= src QDEL_NULL(view_size) QDEL_NULL(void) QDEL_NULL(tooltips) @@ -1129,3 +1131,11 @@ GLOBAL_LIST_INIT(blacklisted_builds, list( winset(src, "mapwindow.map", "right-click=false") winset(src, "default.Shift", "is-disabled=true") winset(src, "default.ShiftUp", "is-disabled=true") + +/client/proc/update_ambience_pref() + if(prefs.toggles & SOUND_AMBIENCE) + if(SSambience.ambience_listening_clients[src] > world.time) + return // If already properly set we don't want to reset the timer. + SSambience.ambience_listening_clients[src] = world.time + 10 SECONDS //Just wait 10 seconds before the next one aight mate? cheers. + else + SSambience.ambience_listening_clients -= src diff --git a/code/modules/client/preferences_toggles.dm b/code/modules/client/preferences_toggles.dm index 2a007e02e86..20f21ada743 100644 --- a/code/modules/client/preferences_toggles.dm +++ b/code/modules/client/preferences_toggles.dm @@ -239,6 +239,7 @@ TOGGLE_CHECKBOX(/datum/verbs/menu/settings/sound, Toggle_Soundscape)() to_chat(usr, "You will no longer hear ambient sounds.") usr.stop_sound_channel(CHANNEL_AMBIENCE) usr.stop_sound_channel(CHANNEL_BUZZ) + usr.client.update_ambience_pref() SSblackbox.record_feedback("nested tally", "preferences_verb", 1, list("Toggle Ambience", "[usr.client.prefs.toggles & SOUND_AMBIENCE ? "Enabled" : "Disabled"]")) //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc! /datum/verbs/menu/settings/sound/Toggle_Soundscape/Get_checked(client/C) return C.prefs.toggles & SOUND_AMBIENCE @@ -255,7 +256,6 @@ TOGGLE_CHECKBOX(/datum/verbs/menu/settings/sound, toggle_ship_ambience)() else to_chat(usr, "You will no longer hear ship ambience.") usr.stop_sound_channel(CHANNEL_BUZZ) - usr.client.ambience_playing = 0 SSblackbox.record_feedback("nested tally", "preferences_verb", 1, list("Toggle Ship Ambience", "[usr.client.prefs.toggles & SOUND_SHIP_AMBIENCE ? "Enabled" : "Disabled"]")) //If you are copy-pasting this, I bet you read this comment expecting to see the same thing :^) /datum/verbs/menu/settings/sound/toggle_ship_ambience/Get_checked(client/C) return C.prefs.toggles & SOUND_SHIP_AMBIENCE diff --git a/tgstation.dme b/tgstation.dme index 4aa334eeb18..daaa3caa092 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -302,6 +302,7 @@ #include "code\controllers\subsystem\achievements.dm" #include "code\controllers\subsystem\adjacent_air.dm" #include "code\controllers\subsystem\air.dm" +#include "code\controllers\subsystem\ambience.dm" #include "code\controllers\subsystem\assets.dm" #include "code\controllers\subsystem\atoms.dm" #include "code\controllers\subsystem\augury.dm"