diff --git a/code/__DEFINES/dcs/signals.dm b/code/__DEFINES/dcs/signals.dm index 0853e650da..dbf5490985 100644 --- a/code/__DEFINES/dcs/signals.dm +++ b/code/__DEFINES/dcs/signals.dm @@ -25,6 +25,12 @@ /// Do not allow this random event to continue. #define CANCEL_PRE_RANDOM_EVENT (1<<0) +/// a weather event of some kind occured +#define COMSIG_WEATHER_TELEGRAPH(event_type) "!weather_telegraph [event_type]" +#define COMSIG_WEATHER_START(event_type) "!weather_start [event_type]" +#define COMSIG_WEATHER_WINDDOWN(event_type) "!weather_winddown [event_type]" +#define COMSIG_WEATHER_END(event_type) "!weather_end [event_type]" + // signals from globally accessible objects /// from SSsun when the sun changes position : (primary_sun, suns) #define COMSIG_SUN_MOVED "sun_moved" diff --git a/code/datums/components/area_sound_manager.dm b/code/datums/components/area_sound_manager.dm new file mode 100644 index 0000000000..50bb77772f --- /dev/null +++ b/code/datums/components/area_sound_manager.dm @@ -0,0 +1,77 @@ +///Allows you to set a theme for a set of areas without tying them to looping sounds explicitly +/datum/component/area_sound_manager + ///area -> looping sound type + var/list/area_to_looping_type = list() + ///Current sound loop + var/datum/looping_sound/our_loop + ///A list of "acceptable" z levels to be on. If you leave this, we're gonna delete ourselves + var/list/accepted_zs + ///The timer id of our current start delay, if it exists + var/timerid + +/datum/component/area_sound_manager/Initialize(area_loop_pairs, change_on, remove_on, acceptable_zs) + if(!ismovable(parent)) + return + area_to_looping_type = area_loop_pairs + accepted_zs = acceptable_zs + change_the_track() + + RegisterSignal(parent, COMSIG_MOVABLE_MOVED, .proc/react_to_move) + RegisterSignal(parent, COMSIG_MOVABLE_Z_CHANGED, .proc/react_to_z_move) + RegisterSignal(parent, change_on, .proc/handle_change) + RegisterSignal(parent, remove_on, .proc/handle_removal) + +/datum/component/area_sound_manager/Destroy(force, silent) + QDEL_NULL(our_loop) + . = ..() + +/datum/component/area_sound_manager/proc/react_to_move(datum/source, atom/oldloc, dir, forced) + SIGNAL_HANDLER + var/list/loop_lookup = area_to_looping_type + if(loop_lookup[get_area(oldloc)] == loop_lookup[get_area(parent)]) + return + change_the_track(TRUE) + +/datum/component/area_sound_manager/proc/react_to_z_move(datum/source, old_z, new_z) + SIGNAL_HANDLER + if(!length(accepted_zs) || (new_z in accepted_zs)) + return + qdel(src) + +/datum/component/area_sound_manager/proc/handle_removal(datum/source) + SIGNAL_HANDLER + qdel(src) + +/datum/component/area_sound_manager/proc/handle_change(datum/source) + SIGNAL_HANDLER + change_the_track() + +/datum/component/area_sound_manager/proc/change_the_track(skip_start = FALSE) + var/time_remaining = 0 + + if(our_loop) + var/our_id = our_loop.timerid || timerid + if(our_id) + time_remaining = timeleft(our_id, SSsound_loops) || 0 + //Time left will sometimes return negative values, just ignore them and start a new sound loop now + time_remaining = max(time_remaining, 0) + QDEL_NULL(our_loop) + + var/area/our_area = get_area(parent) + var/new_loop_type = area_to_looping_type[our_area] + if(!new_loop_type) + return + + our_loop = new new_loop_type(parent, FALSE, TRUE, skip_start) + + //If we're still playing, wait a bit before changing the sound so we don't double up + if(time_remaining) + timerid = addtimer(CALLBACK(src, .proc/start_looping_sound), time_remaining, TIMER_UNIQUE | TIMER_CLIENT_TIME | TIMER_STOPPABLE | TIMER_NO_HASH_WAIT | TIMER_DELETE_ME, SSsound_loops) + return + timerid = null + our_loop.start() + +/datum/component/area_sound_manager/proc/start_looping_sound() + timerid = null + if(our_loop) + our_loop.start() diff --git a/code/datums/elements/weather_listener.dm b/code/datums/elements/weather_listener.dm new file mode 100644 index 0000000000..7cea61b640 --- /dev/null +++ b/code/datums/elements/weather_listener.dm @@ -0,0 +1,44 @@ +///This element just handles creating and destroying an area sound manager that's hooked into weather stuff +/datum/element/weather_listener + element_flags = ELEMENT_BESPOKE + id_arg_index = 2 + var/weather_type + //What events to change the track on + var/list/sound_change_signals + //The weather type we're working with + var/weather_trait + //The playlist of sounds to draw from. Pass by ref + var/list/playlist + + +/datum/element/weather_listener/Attach(datum/target, w_type, trait, weather_playlist) + . = ..() + if(!weather_type) + weather_type = w_type + sound_change_signals = list( + COMSIG_WEATHER_TELEGRAPH(weather_type), + COMSIG_WEATHER_START(weather_type), + COMSIG_WEATHER_WINDDOWN(weather_type), + COMSIG_WEATHER_END(weather_type) + ) + weather_trait = trait + playlist = weather_playlist + + RegisterSignal(target, COMSIG_MOVABLE_Z_CHANGED, .proc/handle_z_level_change, override = TRUE) + RegisterSignal(target, COMSIG_MOB_CLIENT_LOGOUT, .proc/handle_logout, override = TRUE) + +/datum/element/weather_listener/Detach(datum/source) + . = ..() + UnregisterSignal(source, COMSIG_MOVABLE_Z_CHANGED, COMSIG_MOB_CLIENT_LOGOUT) + +/datum/element/weather_listener/proc/handle_z_level_change(datum/source, old_z, new_z) + SIGNAL_HANDLER + var/list/fitting_z_levels = SSmapping.levels_by_trait(weather_trait) + if(!(new_z in fitting_z_levels)) + return + var/datum/component/our_comp = source.AddComponent(/datum/component/area_sound_manager, playlist, list(), COMSIG_MOB_CLIENT_LOGOUT, fitting_z_levels) + our_comp.RegisterSignal(SSdcs, sound_change_signals, /datum/component/area_sound_manager/proc/handle_change) + +/datum/element/weather_listener/proc/handle_logout(datum/source, client/this_is_a_null_ref) + SIGNAL_HANDLER + source.RemoveElement(/datum/element/weather_listener, weather_type, weather_trait, playlist) diff --git a/code/modules/client/client_procs.dm b/code/modules/client/client_procs.dm index 36d2ed2750..ccca7c93cb 100644 --- a/code/modules/client/client_procs.dm +++ b/code/modules/client/client_procs.dm @@ -1118,11 +1118,6 @@ GLOBAL_LIST_INIT(blacklisted_builds, list( return to_chat(src, span_userdanger("Statpanel failed to load, click here to reload the panel ")) -/client/proc/check_panel_loaded() - if(statbrowser_ready) - return - to_chat(src, span_userdanger("Statpanel failed to load, click here to reload the panel ")) - //increment progress for an unlockable loadout item /client/proc/increment_progress(key, amount) if(prefs) diff --git a/code/modules/mob/login.dm b/code/modules/mob/login.dm index 8f74d3b45f..7d2daac326 100644 --- a/code/modules/mob/login.dm +++ b/code/modules/mob/login.dm @@ -1,4 +1,31 @@ +/** + * Run when a client is put in this mob or reconnets to byond and their client was on this mob + * + * Things it does: + * * Adds player to player_list + * * sets lastKnownIP + * * sets computer_id + * * logs the login + * * tells the world to update it's status (for player count) + * * create mob huds for the mob if needed + * * reset next_move to 1 + * * parent call + * * if the client exists set the perspective to the mob loc + * * call on_log on the loc (sigh) + * * reload the huds for the mob + * * reload all full screen huds attached to this mob + * * load any global alternate apperances + * * sync the mind datum via sync_mind() + * * call any client login callbacks that exist + * * grant any actions the mob has to the client + * * calls [auto_deadmin_on_login](mob.html#proc/auto_deadmin_on_login) + * * send signal COMSIG_MOB_CLIENT_LOGIN + * * attaches the ash listener element so clients can hear weather + * client can be deleted mid-execution of this proc, chiefly on parent calls, with lag + */ /mob/Login() + if(!client) + return FALSE add_to_player_list() lastKnownIP = client.address computer_id = client.computer_id @@ -15,6 +42,14 @@ . = ..() + if(!client) + return FALSE + + // SEND_SIGNAL(src, COMSIG_MOB_LOGIN) + + if (key != client.key) + key = client.key + reset_perspective(loc) if(loc) @@ -53,6 +88,12 @@ log_message("Client [key_name(src)] has taken ownership of mob [src]([src.type])", LOG_OWNERSHIP) SEND_SIGNAL(src, COMSIG_MOB_CLIENT_LOGIN, client) + client.init_verbs() if(has_field_of_vision && CONFIG_GET(flag/use_field_of_vision)) LoadComponent(/datum/component/field_of_vision, field_of_vision_type) + + AddElement(/datum/element/weather_listener, /datum/weather/ash_storm, ZTRAIT_ASHSTORM, GLOB.ash_storm_sounds) + + // optimized area sound effects. Enable during events (compile flag when 😳) + // AddElement(/datum/element/weather_listener, /datum/weather/long_rain, ZTRAIT_STATION, GLOB.rain_sounds) diff --git a/code/modules/mob/logout.dm b/code/modules/mob/logout.dm index 2e2eeeb4fb..d26d562a46 100644 --- a/code/modules/mob/logout.dm +++ b/code/modules/mob/logout.dm @@ -4,7 +4,6 @@ SStgui.on_logout(src) unset_machine() remove_from_player_list() - ..() if(loc) diff --git a/modular_citadel/code/modules/eventmaps/Spookystation/JTGSZwork.dm b/modular_citadel/code/modules/eventmaps/Spookystation/JTGSZwork.dm index 98ca2005dc..2e3e4d5c69 100644 --- a/modular_citadel/code/modules/eventmaps/Spookystation/JTGSZwork.dm +++ b/modular_citadel/code/modules/eventmaps/Spookystation/JTGSZwork.dm @@ -463,6 +463,11 @@ name = "grass baseturf helper" //Basically just changes the baseturf into grass baseturf = /turf/open/floor/spooktime/spooktimegrass //Wherever it is at. +//A reference to this list is passed into area sound managers, and it's modified in a manner that preserves that reference in ash_storm.dm +GLOBAL_LIST_EMPTY(rain_sounds) + +// HEY!! IF THIS DOES NOT WORK CHECK LOGIN.DM !!!!! + /* HERE COMES THE MOTHERFUCKING RAIN */ @@ -487,45 +492,46 @@ barometer_predictable = TRUE - var/datum/looping_sound/active_outside_longrain/sound_ao = new(list(), FALSE, TRUE) //Outside - var/datum/looping_sound/active_inside_longrain/sound_ai = new(list(), FALSE, TRUE) //Inside - var/datum/looping_sound/active_mountain_longrain/sound_am = new(list(), FALSE, TRUE) //Mountain + var/list/outside_longrain = list() + var/list/inside_longrain = list() + var/list/mountain_longrain = list() + // var/datum/looping_sound/active_outside_longrain/sound_ao = new(list(), FALSE, TRUE) //Outside + // var/datum/looping_sound/active_inside_longrain/sound_ai = new(list(), FALSE, TRUE) //Inside + // var/datum/looping_sound/active_mountain_longrain/sound_am = new(list(), FALSE, TRUE) //Mountain /datum/weather/long_rain/telegraph() //Yeah, I'm sorry but I just stole ash storm sound loops . = ..() - var/list/inside_areas = list() //It already handled inside and outside areas lol. - var/list/outside_areas = list() //Now this is what I call, some real disgusting lazy list abuse - var/list/mountain_areas = list() var/list/eligible_areas = list() for(var/z in impacted_z_levels) //We check the Z level eligible_areas += SSmapping.areas_in_z["[z]"] //And append them to eligible areas list - for(var/i in 1 to eligible_areas.len) //We check the list - var/area/place = eligible_areas[i] //Place is the list + + + for(var/i in 1 to eligible_areas.len) + var/area/place = eligible_areas[i] if(istype(place, /area/eventmap/outside)) //If the place is this path - outside_areas += place //Outside areas is the place + outside_longrain[place] = /datum/looping_sound/active_outside_longrain //Outside areas is the place if(istype(place, /area/eventmap/inside)) - inside_areas += place + inside_longrain[place] = /datum/looping_sound/active_inside_longrain if(istype(place, /area/eventmap/mountain)) - mountain_areas += place - CHECK_TICK //We check the tick this all occurs on. + mountain_longrain[place] = /datum/looping_sound/active_mountain_longrain - sound_ao.output_atoms = outside_areas //The output atom is now set to the areas - sound_ai.output_atoms = inside_areas - sound_am.output_atoms = mountain_areas + CHECK_TICK - sound_ao.start() //Outside - We can hear it begin + //We modify this list instead of setting it to weak/stron sounds in order to preserve things that hold a reference to it + //It's essentially a playlist for a bunch of components that chose what sound to loop based on the area a player is in + GLOB.rain_sounds += outside_longrain + return ..() /datum/weather/long_rain/start() - . = ..() - sound_am.start() //Mountain - We only hear after it begins - sound_ai.start() //Inside - Ditto + GLOB.ash_storm_sounds += mountain_longrain + GLOB.ash_storm_sounds += inside_longrain + return ..() /datum/weather/long_rain/end() - . = ..() - sound_am.stop() //Mountain - - sound_ao.stop() //Outside - And then we stop it all, but only people outside hear the entire segment - sound_ai.stop() //Inside + GLOB.ash_storm_sounds -= outside_longrain + GLOB.ash_storm_sounds -= inside_longrain + GLOB.ash_storm_sounds -= mountain_longrain + return ..() /datum/looping_sound/active_outside_longrain mid_sounds = list('modular_citadel/code/modules/eventmaps/Spookystation/outsideloop1.ogg'=1, diff --git a/tgstation.dme b/tgstation.dme index 3c282d10e8..5e4b91394b 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -484,6 +484,7 @@ #include "code\datums\components\acid.dm" #include "code\datums\components\activity.dm" #include "code\datums\components\anti_magic.dm" +#include "code\datums\components\area_sound_manager.dm" #include "code\datums\components\armor_plate.dm" #include "code\datums\components\bane.dm" #include "code\datums\components\bouncy.dm" @@ -667,6 +668,7 @@ #include "code\datums\elements\update_icon_blocker.dm" #include "code\datums\elements\update_icon_updates_onmob.dm" #include "code\datums\elements\ventcrawling.dm" +#include "code\datums\elements\weather_listener.dm" #include "code\datums\elements\wuv.dm" #include "code\datums\helper_datums\events.dm" #include "code\datums\helper_datums\getrev.dm"