Files
Bubberstation/code/controllers/subsystem/weather.dm
SkyratBot cab78dcf78 [MIRROR] Changes how weather sends sound to players, reduces sound loop overtime (#6627)
* Changes how weather sends sound to players, reduces sound loop overtime (#59284)

* Converts looping sounds from a list of play locations to just the one

* Updates all uses of looping sounds to match the new arg

* Adds an area based sound manager that hooks into looping sounds to drive the actual audio. I'll be using this to redo how weather effects handle sound

* Some structrual stuff to make everything else smoother
Timers now properly return the time left for client based timers
Weather sends global signals when it starts/stops
Looping sounds now use their timerid var for all their sound related timers, not just the main loop

* This is the painful part
Adds an area sound manager component, it handles the logic of moving into new areas potentially creating new
sound loops. We do some extra work to prevent stacking sound loops.
Adds an ash storm listener element that adds a tailored area sound manager to clients on the lavaland z level.
It's removed on logout.
Adds the ash_storm_sounds assoc list, a reference to this is passed into area sound managers, and it's modified
in a manner that doesn't break the reference in ash_storm (This is what I hate)

* Hooks ash storm listener into cliented mobs and possessed objects

* Documents the odd ref stuff, adds an ignore start var to looping sounds, fixes some errors and lint issues

* Applies kyler's review

banging

Co-authored-by: Kylerace <kylerlumpkin1@ gmail.com>

* Cleans up some var names, reduces the amount of looping we do in some areas

* Makes the code compile, redoes the movement listener to be more general

* fuck

* We don't need to detach on del if we're just removing signals on detach

* Should? work

* if(direct) memes

Co-authored-by: Kylerace <kylerlumpkin1@ gmail.com>

* Changes how weather sends sound to players, reduces sound loop overtime

Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com>
Co-authored-by: Kylerace <kylerlumpkin1@ gmail.com>
2021-07-01 02:18:04 +01:00

80 lines
2.8 KiB
Plaintext

#define STARTUP_STAGE 1
#define MAIN_STAGE 2
#define WIND_DOWN_STAGE 3
#define END_STAGE 4
//Used for all kinds of weather, ex. lavaland ash storms.
SUBSYSTEM_DEF(weather)
name = "Weather"
flags = SS_BACKGROUND
wait = 10
runlevels = RUNLEVEL_GAME
var/list/processing = list()
var/list/eligible_zlevels = list()
var/list/next_hit_by_zlevel = list() //Used by barometers to know when the next storm is coming
/datum/controller/subsystem/weather/fire()
// process active weather
for(var/V in processing)
var/datum/weather/our_event = V
if(our_event.aesthetic || our_event.stage != MAIN_STAGE)
continue
for(var/mob/act_on as anything in GLOB.mob_living_list)
if(our_event.can_weather_act(act_on))
our_event.weather_act(act_on)
// start random weather on relevant levels
for(var/z in eligible_zlevels)
var/possible_weather = eligible_zlevels[z]
var/datum/weather/our_event = pickweight(possible_weather)
run_weather(our_event, list(text2num(z)))
eligible_zlevels -= z
var/randTime = rand(3000, 6000)
next_hit_by_zlevel["[z]"] = addtimer(CALLBACK(src, .proc/make_eligible, z, possible_weather), randTime + initial(our_event.weather_duration_upper), TIMER_UNIQUE|TIMER_STOPPABLE) //Around 5-10 minutes between weathers
/datum/controller/subsystem/weather/Initialize(start_timeofday)
for(var/V in subtypesof(/datum/weather))
var/datum/weather/W = V
var/probability = initial(W.probability)
var/target_trait = initial(W.target_trait)
// any weather with a probability set may occur at random
if (probability)
for(var/z in SSmapping.levels_by_trait(target_trait))
LAZYINITLIST(eligible_zlevels["[z]"])
eligible_zlevels["[z]"][W] = probability
return ..()
/datum/controller/subsystem/weather/proc/run_weather(datum/weather/weather_datum_type, z_levels)
if (istext(weather_datum_type))
for (var/V in subtypesof(/datum/weather))
var/datum/weather/W = V
if (initial(W.name) == weather_datum_type)
weather_datum_type = V
break
if (!ispath(weather_datum_type, /datum/weather))
CRASH("run_weather called with invalid weather_datum_type: [weather_datum_type || "null"]")
if (isnull(z_levels))
z_levels = SSmapping.levels_by_trait(initial(weather_datum_type.target_trait))
else if (isnum(z_levels))
z_levels = list(z_levels)
else if (!islist(z_levels))
CRASH("run_weather called with invalid z_levels: [z_levels || "null"]")
var/datum/weather/W = new weather_datum_type(z_levels)
W.telegraph()
/datum/controller/subsystem/weather/proc/make_eligible(z, possible_weather)
eligible_zlevels[z] = possible_weather
next_hit_by_zlevel["[z]"] = null
/datum/controller/subsystem/weather/proc/get_weather(z, area/active_area)
var/datum/weather/A
for(var/V in processing)
var/datum/weather/W = V
if((z in W.impacted_z_levels) && W.area_type == active_area.type)
A = W
break
return A