Files
Bubberstation/code/datums/outputs.dm
Militaires cecf676684 [Ready] Outputs datum (#41535)
Idea and instructions by @Razharas, many thanks.

This PR only implements the framework required to catalog as well as play the sounds. Their to_chat text, and icons (if any) are not included, are to be pushed in a separate PR.

This PR does not remove the old playsound_local system, it is kept for the sake of not necessitating a direct changeover of every single playsound in the code, which will surely cause a lot of merge conflicts. It does however, replace bike horns' and toy nukes' means of playback to this datum, purely as proof of concept.

Playsound_local may remain in the code to support playback of admin-uploaded sounds that do not have an inherent datum. Playsound will likely be renamed to something else in the next PR to reflect its new, more universal function. We will see.

New process for adding sounds:

    Create a new datum/outputs subtype.
    If you wish, write down some supporting text; this gives further meaning to the sound.
    Add multiple sounds to the sounds list, and weight them as you wish. (New)
    Add a sound icon if you wish, it defaults to a generic sound circle anyways though.
    playsound(/datum/outputs/new_subtype, receiver), and it will deliver, icon, sound, and text to the receiver.

Maintaining implication is that from now on playsound should only be processing datum/outputs

This pr intends to gut to_chats that are added alongside playsounds in the code.
This pr eliminates the need to initialize sounds in a list so that you can weight them or have the game play them randomly from the list.

Sound Rings
Currently, only mobs with the audiolocation var may view them. Sound icons have an alpha that depends on the volume of the sound, louder sounds create a more opaque image

Sound rings are completely modular and may be changed to any image.

In addition to renaming playsound to reflect its new function. I intend to give blind people sound icons at the cost of their small view, but that is for another PR.

cl Basilman
refactor: refactored how sounds are stored and played
add: Added sound rings and supporting text
/cl
2019-02-04 10:25:48 +13:00

110 lines
3.5 KiB
Plaintext

//NOTE: When adding new sounds here, check to make sure they haven't been added already via CTRL + F.
/datum/outputs
var/text = ""
var/list/sounds = 'sound/items/airhorn.ogg' //can be either a sound path or a WEIGHTED list, put multiple for random selection between sounds
var/mutable_appearance/vfx = list('icons/sound_icon.dmi',"circle", HUD_LAYER) //syntax: icon, icon_state, layer
/datum/outputs/New()
vfx = mutable_appearance(vfx[1],vfx[2],vfx[3])
/datum/outputs/proc/send_info(mob/receiver, turf/turf_source, vol as num, vary, frequency, falloff, channel = 0, pressure_affected = TRUE)
var/sound/sound_output
//Pick sound
if(islist(sounds))
if(sounds.len)
var/soundin = pickweight(sounds)
sound_output = sound(get_sfx(soundin))
else
sound_output = sound(get_sfx(sounds))
//Process sound
if(sound_output)
sound_output.wait = 0 //No queue
sound_output.channel = channel || open_sound_channel()
sound_output.volume = vol
if(vary)
if(frequency)
sound_output.frequency = frequency
else
sound_output.frequency = get_rand_frequency()
if(isturf(turf_source))
var/turf/T = get_turf(receiver)
//sound volume falloff with distance
var/distance = get_dist(T, turf_source)
sound_output.volume -= max(distance - world.view, 0) * 2 //multiplicative falloff to add on top of natural audio falloff.
if(pressure_affected)
//Atmosphere affects sound
var/pressure_factor = 1
var/datum/gas_mixture/hearer_env = T.return_air()
var/datum/gas_mixture/source_env = turf_source.return_air()
if(hearer_env && source_env)
var/pressure = min(hearer_env.return_pressure(), source_env.return_pressure())
if(pressure < ONE_ATMOSPHERE)
pressure_factor = max((pressure - SOUND_MINIMUM_PRESSURE)/(ONE_ATMOSPHERE - SOUND_MINIMUM_PRESSURE), 0)
else //space
pressure_factor = 0
if(distance <= 1)
pressure_factor = max(pressure_factor, 0.15) //touching the source of the sound
sound_output.volume *= pressure_factor
//End Atmosphere affecting sound
if(sound_output.volume <= 0)
return //No sound
var/dx = turf_source.x - T.x // Hearing from the right/left
sound_output.x = dx
var/dz = turf_source.y - T.y // Hearing from infront/behind
sound_output.z = dz
// The y value is for above your head, but there is no ceiling in 2d spessmens.
sound_output.y = 1
sound_output.falloff = (falloff ? falloff : FALLOFF_SOUNDS)
receiver.display_output(sound_output, vfx, text, turf_source, vol, vary, frequency, falloff, channel, pressure_affected)
/datum/outputs/bikehorn
text = "You hear a HONK."
sounds = 'sound/items/bikehorn.ogg'
/datum/outputs/airhorn
text = "You hear the violent blaring of an airhorn."
sounds = 'sound/items/airhorn2.ogg'
/datum/outputs/alarm
text = "You hear a blaring alarm."
sounds = 'sound/machines/alarm.ogg'
/datum/outputs/squeak
text = "You hear a squeak."
sounds = 'sound/effects/mousesqueek.ogg'
/datum/outputs/clownstep
sounds = list('sound/effects/clownstep1.ogg' = 1,'sound/effects/clownstep2.ogg' = 1)
/datum/outputs/bite
text = "You hear ravenous biting."
sounds = 'sound/weapons/bite.ogg'
/datum/outputs/demonattack
text = "You hear a terrifying, unholy noise."
sounds = 'sound/magic/demon_attack1.ogg'
/datum/outputs/slash
text = "You hear a slashing noise."
sounds = 'sound/weapons/slash.ogg'
/datum/outputs/punch
text = "You hear a punch."
sounds = 'sound/effects/hit_punch.ogg'
/datum/outputs/squelch
text = "You hear a horrendous squelching sound."
sounds = 'sound/effects/blobattack.ogg'