Reworks and Cleans Up Ambience Code (#14652)

* Reworks and Cleans Up Ambience Code

* Removes Unused Defines; Minor Code Comments

* Cleans Up Code Comments

* Changelog

* Changelog Update
This commit is contained in:
SleepyGemmy
2022-08-21 21:25:24 +02:00
committed by GitHub
parent 1f536c64ac
commit 14d7cc6a4d
12 changed files with 171 additions and 182 deletions

View File

@@ -31,16 +31,12 @@
// Some arbitrary defines to be used by self-pruning global lists. (see master_controller)
#define PROCESS_KILL 26 // Used to trigger removal from a processing list.
// Age limits on a character.
#define AGE_MIN 17
#define AGE_MAX 85
#define MAX_GEAR_COST 15 // Used in chargen for accessory loadout limit.
// Preference toggles.
#define SOUND_ADMINHELP 0x1
#define SOUND_MIDI 0x2
#define SOUND_AMBIENCE 0x4
// 0x4 is free.
#define SOUND_LOBBY 0x8
#define CHAT_OOC 0x10
#define CHAT_DEAD 0x20
@@ -56,7 +52,8 @@
#define CHAT_NOICONS 0x8000
#define CHAT_GHOSTLOOC 0x10000
//Note that 0x1 and 0x2 are free. Use those!
// 0x1 is free.
// 0x2 is free.
#define PROGRESS_BARS 0x4
#define PARALLAX_IS_STATIC 0x8
#define FLOATING_MESSAGES 0x10
@@ -64,7 +61,7 @@
#define FULLSCREEN_MODE 0x40
#define ACCENT_TAG_TEXT 0x80
#define TOGGLES_DEFAULT (SOUND_ADMINHELP|SOUND_MIDI|SOUND_AMBIENCE|SOUND_LOBBY|CHAT_OOC|CHAT_DEAD|CHAT_GHOSTEARS|CHAT_GHOSTSIGHT|CHAT_PRAYER|CHAT_RADIO|CHAT_ATTACKLOGS|CHAT_LOOC|CHAT_GHOSTLOOC)
#define TOGGLES_DEFAULT (SOUND_ADMINHELP | SOUND_MIDI | SOUND_LOBBY | CHAT_OOC | CHAT_DEAD | CHAT_GHOSTEARS | CHAT_GHOSTSIGHT | CHAT_PRAYER | CHAT_RADIO | CHAT_ATTACKLOGS | CHAT_LOOC | CHAT_GHOSTLOOC)
//Sound effects toggles
#define ASFX_AMBIENCE 1
@@ -75,8 +72,9 @@
#define ASFX_ARCADE 32
#define ASFX_RADIO 64
#define ASFX_INSTRUMENT 128
#define ASFX_HUM 256
#define ASFX_DEFAULT (ASFX_AMBIENCE|ASFX_FOOTSTEPS|ASFX_VOTE|ASFX_VOX|ASFX_DROPSOUND|ASFX_ARCADE|ASFX_RADIO|ASFX_INSTRUMENT)
#define ASFX_DEFAULT (ASFX_AMBIENCE | ASFX_FOOTSTEPS | ASFX_VOTE | ASFX_VOX | ASFX_DROPSOUND | ASFX_ARCADE | ASFX_RADIO | ASFX_INSTRUMENT | ASFX_HUM)
// For secHUDs and medHUDs and variants. The number is the location of the image on the list hud_list of humans.
#define HEALTH_HUD 1 // A simple line reading the pulse.

View File

@@ -1,8 +1,7 @@
// Areas.dm
//
// Areas
//
// ===
/area
var/global/global_uid = 0
var/uid
@@ -46,7 +45,6 @@
var/air_doors_activated = 0
var/list/ambience = list()
var/list/forced_ambience = null
var/loop_ambience = TRUE
var/sound_env = STANDARD_STATION
var/turf/base_turf //The base turf type of the area, which can be used to override the z-level's base turf
var/no_light_control = 0 // if 1, lights in area cannot be toggled with light controller
@@ -272,41 +270,50 @@ var/list/mob/living/forced_ambiance_list = new
L.lastarea = get_area(L.loc)
var/area/newarea = get_area(L.loc)
var/area/oldarea = L.lastarea
if((oldarea.has_gravity() == 0) && (newarea.has_gravity() == 1) && (L.m_intent == M_RUN)) // Being ready when you change areas gives you a chance to avoid falling all together.
if((oldarea.has_gravity() == FALSE) && (newarea.has_gravity() == TRUE) && (L.m_intent == M_RUN)) // Being ready when you change areas gives you a chance to avoid falling all together.
thunk(L)
L.update_floating(L.Check_Dense_Object())
L.lastarea = newarea
// Ambience goes down here -- make sure to list each area seperately 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 && L.client && (L.client.prefs.asfx_togs & ASFX_AMBIENCE))) return
// Start playing ambience.
if(L && L.client && (L.client.prefs.asfx_togs & ASFX_AMBIENCE) && !L.ear_deaf)
play_ambience(L)
else
stop_ambience(L)
// The dreaded ship ambience hum.
// Explanation for the "if" clause: If the mob exists, has a client, the client has the hum ASFX toggled on, the area the mob is in is a station area,
// the mob isn't deaf, and the client doesn't already have the ambient hum playing, then start playing the ambient hum.
if(L && L.client && (L.client.prefs.asfx_togs & ASFX_HUM) && newarea.station_area && !L.ear_deaf)
if(!L.client.ambient_hum_playing)
L.client.ambient_hum_playing = TRUE
L << sound('sound/ambience/shipambience.ogg', repeat = 1, volume = 35, channel = 2)
// Otherwise, stop playing the ambient hum.
else
L << sound(null, channel = 2)
L.client.ambient_hum_playing = FALSE
/area/proc/play_ambience(var/mob/living/L)
// Ambience goes down here -- make sure to list each area seperately 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 && L.client && (L.client.prefs.toggles & SOUND_AMBIENCE))) return
// If we previously were in an area with force-played ambiance, stop it.
// If we previously were in an area with force played ambience, stop it.
if(L in forced_ambiance_list)
L << sound(null, channel = 1)
forced_ambiance_list -= L
if(!L.client.ambience_playing)
L.client.ambience_playing = 1
L << sound('sound/ambience/shipambience.ogg', repeat = loop_ambience, wait = 0, volume = 35, channel = 2)
if(forced_ambience)
if(forced_ambience.len)
forced_ambiance_list |= L
L << sound(pick(forced_ambience), repeat = loop_ambience, wait = 0, volume = 25, channel = 1)
L << sound(pick(forced_ambience), repeat = 1, volume = 30, channel = 1)
else
L << sound(null, channel = 1)
else if(src.ambience.len && prob(35))
if((world.time >= L.client.played + 600))
else if(src.ambience.len)
if((world.time >= L.client.ambience_last_played_time + 30 SECONDS))
var/sound = pick(ambience)
L << sound(sound, repeat = 0, wait = 0, volume = 25, channel = 1)
L.client.played = world.time
L << sound(sound, volume = 30, channel = 1)
L.client.ambience_last_played_time = world.time
/area/proc/stop_ambience(var/mob/living/L)
L << sound(null, channel = 1)
/area/proc/gravitychange(var/gravitystate = 0)
has_gravity = gravitystate
@@ -333,7 +340,7 @@ var/list/mob/living/forced_ambiance_list = new
else
H.AdjustStunned(1)
H.AdjustWeakened(1)
to_chat(mob, "<span class='notice'>The sudden appearance of gravity makes you fall to the floor!</span>")
to_chat(mob, SPAN_WARNING("The sudden appearance of gravity makes you fall to the floor!"))
/area/proc/prison_break()
for(var/obj/machinery/power/apc/temp_apc in src)

View File

@@ -235,7 +235,7 @@
var/area/area = get_area(src)
for(var/obj/machinery/firealarm/FA in area)
fire_alarm.triggerAlarm(loc, FA, duration)
playsound(FA.loc, 'sound/ambience/firealarm.ogg', 75, 0)
playsound(get_turf(FA), 'sound/ambience/firealarm.ogg', 75, FALSE)
update_icon()
return

View File

@@ -1,44 +1,26 @@
//
// Client Defines
//
/client
parent_type = /datum
////////////////
//ADMIN THINGS//
////////////////
// Admin
var/datum/admins/holder = null
var/datum/admins/deadmin_holder = null
var/buildmode = 0
///////////////////
//SPAM PROTECTION//
///////////////////
// Spam Protection
var/last_message = "" // Contains the last message sent by this client - used to protect against copy-paste spamming.
var/last_message_count = 0 //contins a number of how many times a message identical to last_message was sent.
var/last_message_count = 0 // Contains a number of how many times a message identical to last_message was sent.
var/last_message_time
var/spam_alert = 0
/////////
//OTHER//
/////////
var/datum/preferences/prefs
var/datum/tooltip/tooltips
var/move_delay = 1
var/moving = null
var/adminobs = null
var/area = null
var/time_died_as_rat = 0
var/list/autofire_aiming_at[2]
// Sounds
var/ambient_hum_playing = null // Is the ambient hum playing?
var/ambience_last_played_time = null // "world.time".
var/adminhelped = NOT_ADMINHELPED
///////////////
//SOUND STUFF//
///////////////
var/ambience_playing= null
var/played = 0
////////////
//SECURITY//
////////////
// Security
var/info_sent = 0
// comment out the line below when debugging locally to enable the options & messages menu
//control_freak = 1
@@ -48,10 +30,7 @@
var/discord_admin //IRC- no more IRC, K? Discord admin that spoke with them last.
var/mute_discord = 0
////////////////////////////////////
//things that require the database//
////////////////////////////////////
// Database
var/player_age = "Requires database" // So admins know why it isn't working - Used to determine how old the account is - in days.
var/related_accounts_ip = "Requires database" //So admins know why it isn't working - Used to determine what other accounts previously logged in from this ip
var/related_accounts_cid = "Requires database" //So admins know why it isn't working - Used to determine what other accounts previously logged in from this computer id
@@ -67,5 +46,17 @@
var/is_initialized = FALSE // Used to track whether the client has been initialized with InitClient.
///goonchat chatoutput of the client
// Goonchat chat output of the client.
var/datum/chatOutput/chatOutput
// Other
var/datum/preferences/prefs
var/datum/tooltip/tooltips
var/move_delay = 1
var/moving = null
var/adminobs = null
var/area = null
var/time_died_as_rat = 0
var/list/autofire_aiming_at[2]
var/adminhelped = NOT_ADMINHELPED

View File

@@ -1,115 +1,119 @@
// ASFX Toggles List
/var/global/asfx_togs = list(
// /client/proc/Toggle_asfx,
// /client/proc/Toggle_footsteps,
/client/proc/Toggle_asfx_vote,
/client/proc/Toggle_messagesounds,
/client/proc/Toggle_dropsounds,
/client/proc/Toggle_arcadesounds,
/client/proc/Toggle_radiosounds,
/client/proc/Toggle_instrumentsounds
/client/proc/toggle_footsteps,
/client/proc/toggle_asfx_vote,
/client/proc/toggle_messagesounds,
/client/proc/toggle_dropsounds,
/client/proc/toggle_arcadesounds,
/client/proc/toggle_radiosounds,
/client/proc/toggle_instrumentsounds
)
/client/verb/asf_toggle()
set name = "Open ASFX Tab"
// ASFX Tab Toggle
/client/verb/toggle_asfx_tab()
set name = "Toggle SFX Preferences Tab"
set category = "Preferences"
set desc = "Open the ambience sound effects toggle tab"
set desc = "Toggle the SFX preferences tab"
verbs ^= asfx_togs
return
/client/verb/Toggle_asfx() //Allgnew ambience should be added here so it works with this verb until someone better at things comes up with a fix that isn't awful
set name = "Hear/Silence Ambience"
// set category = "SoundFx Prefs"
//
// ASFX Toggles
//
/client/verb/toggle_asfx()
set name = "Toggle Ambience SFX"
set category = "Preferences"
set desc = "Toggles hearing ambient sound effects"
prefs.asfx_togs ^= ASFX_AMBIENCE
prefs.save_preferences()
if(prefs.asfx_togs & ASFX_AMBIENCE)
to_chat(src, "You will now hear ambient sounds.")
to_chat(src, SPAN_INFO("You will now hear ambient sounds."))
else
to_chat(src, "<span class='warning'>You will no longer hear ambient sounds.</span>")
src << sound(null, repeat = 0, wait = 0, volume = 0, channel = 1)
src << sound(null, repeat = 0, wait = 0, volume = 0, channel = 2)
feedback_add_details("admin_verb","TSFXAmbi") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc!
to_chat(src, SPAN_INFO("You will no longer hear ambient sounds."))
src << sound(null, repeat = 0, wait = 0, volume = 0, channel = 1) // Ambience plays on channel 1.
feedback_add_details("admin_verb", "TSFXAmbi") // If you are copy pasting this, ensure the 2nd parameter is unique to the new proc.
/client/proc/Toggle_footsteps()
set name = "Hear/Silence Footsteps"
set category = "SoundFx Prefs"
/client/verb/toggle_asfx_hum(var/mob/living/L)
set name = "Toggle Ambient Hum SFX"
set category = "Preferences"
set desc = "Toggles hearing the ambient hum sound effect"
prefs.asfx_togs ^= ASFX_HUM
prefs.save_preferences()
if(prefs.asfx_togs & ASFX_HUM)
to_chat(src, SPAN_INFO("You will now hear the ambient hum sound."))
else
to_chat(src, SPAN_INFO("You will no longer hear the ambient hum sound."))
src << sound(null, repeat = 0, wait = 0, volume = 0, channel = 2) // Ambient hum plays on channel 2.
L.client.ambient_hum_playing = FALSE
feedback_add_details("admin_verb", "TSFXHum")
//
// SFX Toggles
//
/client/proc/toggle_footsteps()
set name = "Toggle Footsteps SFX"
set category = "SFX Preferences"
set desc = "Toggles hearing footstep sound effects"
prefs.asfx_togs ^= ASFX_FOOTSTEPS
prefs.save_preferences()
if(prefs.asfx_togs & ASFX_FOOTSTEPS)
to_chat(src, "You will now hear footstep sounds.")
else
to_chat(src, "<span class='warning'>You will no longer hear footstep sounds.</span>")
feedback_add_details("admin_verb","TSFXFS") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc!
to_chat(src, SPAN_INFO("You will [(prefs.asfx_togs & ASFX_FOOTSTEPS) ? "now" : "no longer"] hear footstep sounds."))
/client/proc/Toggle_asfx_vote()
set name = "Hear/Silence Vote Alarm"
set category = "SoundFx Prefs"
/client/proc/toggle_asfx_vote()
set name = "Toggle Vote Alarm SFX"
set category = "SFX Preferences"
set desc = "Toggles hearing of the vote alarm"
prefs.asfx_togs ^= ASFX_VOTE
prefs.save_preferences()
if(prefs.asfx_togs & ASFX_VOTE)
to_chat(src, "You will now hear the vote alarm.")
else
to_chat(src, "<span class='warning'>You will no longer hear the vote alarm.</span>")
feedback_add_details("admin_verb","TSFXFV") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc!
to_chat(src, SPAN_INFO("You will [(prefs.asfx_togs & ASFX_VOTE) ? "now" : "no longer"] hear the vote alarm."))
/client/proc/Toggle_messagesounds()
/client/proc/toggle_messagesounds()
set name = "Toggle Message SFX"
set category = "SoundFx Prefs"
set desc = "Toggles the message sounds."
set category = "SFX Preferences"
set desc = "Toggles the message sounds"
prefs.asfx_togs ^= ASFX_VOX
prefs.save_preferences()
to_chat(src, "You will [(prefs.asfx_togs & ASFX_VOX) ? "now" : "no longer"] hear chat voices.")
to_chat(src, SPAN_INFO("You will [(prefs.asfx_togs & ASFX_VOX) ? "now" : "no longer"] hear chat voices."))
/client/proc/Toggle_dropsounds()
set name = "Hear/Silence Drop Sounds"
set category = "SoundFx Prefs"
/client/proc/toggle_dropsounds()
set name = "Toggle Item Dropping SFX"
set category = "SFX Preferences"
set desc = "Toggles hearing dropping and throwing sound effects"
prefs.asfx_togs ^= ASFX_DROPSOUND
prefs.save_preferences()
if(prefs.asfx_togs & ASFX_DROPSOUND)
to_chat(src, "You will now hear dropping and throwing sounds.")
else
to_chat(src, "<span class='warning'>You will no longer hear dropping and throwing sounds.</span>")
to_chat(src, SPAN_INFO("You will [(prefs.asfx_togs & ASFX_DROPSOUND) ? "now" : "no longer"] hear dropping and throwing sounds."))
/client/proc/Toggle_arcadesounds()
/client/proc/toggle_arcadesounds()
set name = "Toggle Arcade SFX"
set category = "SoundFx Prefs"
set desc = "Toggles hearing noises made by arcades."
set category = "SFX Preferences"
set desc = "Toggles hearing noises made by arcades"
prefs.asfx_togs ^= ASFX_ARCADE
prefs.save_preferences()
if(prefs.asfx_togs & ASFX_ARCADE)
to_chat(src, "You will now hear arcade sounds.")
else
to_chat(src, "<span class='warning'>You will no longer hear arcade sounds.</span>")
to_chat(src, SPAN_INFO("You will [(prefs.asfx_togs & ASFX_ARCADE) ? "now" : "no longer"] hear arcade sounds."))
/client/proc/Toggle_radiosounds()
/client/proc/toggle_radiosounds()
set name = "Toggle Radio SFX"
set category = "SoundFx Prefs"
set desc = "Toggles hearing noises made by radios."
set category = "SFX Preferences"
set desc = "Toggles hearing noises made by radios"
prefs.asfx_togs ^= ASFX_RADIO
prefs.save_preferences()
if(prefs.asfx_togs & ASFX_RADIO)
to_chat(src, "You will now hear radio sounds.")
else
to_chat(src, "<span class='warning'>You will no longer hear radio sounds.</span>")
to_chat(src, SPAN_INFO("You will [(prefs.asfx_togs & ASFX_RADIO) ? "now" : "no longer"] hear radio sounds."))
/client/proc/Toggle_instrumentsounds()
/client/proc/toggle_instrumentsounds()
set name = "Toggle Instrument SFX"
set category = "SoundFx Prefs"
set desc = "Toggles hearing noises made by instruments."
set category = "SFX Preferences"
set desc = "Toggles hearing noises made by instruments"
prefs.asfx_togs ^= ASFX_INSTRUMENT
prefs.save_preferences()
if(prefs.asfx_togs & ASFX_INSTRUMENT)
to_chat(src, "You will now hear instrument sounds.")
else
to_chat(src, "<span class='warning'>You will no longer hear instrument sounds.</span>")
to_chat(src, SPAN_INFO("You will [(prefs.asfx_togs & ASFX_INSTRUMENT) ? "now" : "no longer"] hear instrument sounds."))

View File

@@ -110,7 +110,6 @@
to_chat(src, "You will [(prefs.toggles & CHAT_OOC) ? "now" : "no longer"] see messages on the OOC channel.")
feedback_add_details("admin_verb","TOOC") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc!
/client/verb/listen_looc()
set name = "Show/Hide LOOC (All)"
set category = "Preferences"
@@ -145,21 +144,6 @@
to_chat(src, "You will [!(prefs.toggles & CHAT_NOICONS) ? "now" : "no longer"] see chat tag icons.")
feedback_add_details("admin_verb","TCTAG") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc!
/client/verb/Toggle_Soundscape() //All new ambience should be added here so it works with this verb until someone better at things comes up with a fix that isn't awful
set name = "Hear/Silence Ambience"
set category = "Preferences"
set desc = "Toggles hearing ambient sound effects"
prefs.toggles ^= SOUND_AMBIENCE
prefs.save_preferences()
if(prefs.toggles & SOUND_AMBIENCE)
to_chat(src, "You will now hear ambient sounds.")
else
to_chat(src, "You will no longer hear ambient sounds.")
src << sound(null, repeat = 0, wait = 0, volume = 0, channel = 1)
src << sound(null, repeat = 0, wait = 0, volume = 0, channel = 2)
feedback_add_details("admin_verb","TAmbi") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc!
/client/verb/toggle_progress()
set name = "Show/Hide Progress Bars"
set category = "Preferences"

View File

@@ -1,9 +1,7 @@
/datum/holodeck_program
var/target
var/list/ambience = null
var/loop_ambience = TRUE
/datum/holodeck_program/New(var/target, var/list/ambience = null, var/loop_ambience = TRUE)
/datum/holodeck_program/New(var/target, var/list/ambience = null)
src.target = target
src.ambience = ambience
src.loop_ambience = loop_ambience

View File

@@ -45,9 +45,8 @@
/area/exoplanet/grass/play_ambience(var/mob/living/L)
..()
if(!L.ear_deaf && L.client && !L.client.ambience_playing)
L.client.ambience_playing = 1
L.playsound_to(get_turf(L),sound('sound/ambience/jungle.ogg', repeat = 1, wait = 0, volume = 25))
if(L && L.client && (L.client.prefs.asfx_togs & ASFX_AMBIENCE) && !L.ear_deaf)
L.playsound_to(get_turf(L),sound('sound/ambience/jungle.ogg', repeat = 1, wait = 0, volume = 25, channel = 1))
/datum/random_map/noise/exoplanet/grass
descriptor = "grass exoplanet"

View File

@@ -46,9 +46,9 @@
working = hard_drive && processor_unit && damage < broken_damage && computer_use_power()
check_update_ui_need()
if(working && enabled && world.time > ambience_last_played + 30 SECONDS && prob(3))
playsound(get_turf(src), /decl/sound_category/computerbeep_sound, 30, 1, 10, required_preferences = SOUND_AMBIENCE)
ambience_last_played = world.time
if(!is_portable && working && enabled && world.time > ambience_last_played_time + 30 SECONDS && prob(3))
playsound(get_turf(src), /decl/sound_category/computerbeep_sound, 30, 1, 10, required_preferences = ASFX_AMBIENCE)
ambience_last_played_time = world.time
/obj/item/modular_computer/proc/get_preset_programs(preset_type)
for(var/datum/modular_computer_app_presets/prs in ntnet_global.available_software_presets)

View File

@@ -21,7 +21,7 @@
var/base_idle_power_usage = 5 // Power usage when the computer is idle and screen is off (currently only applies to laptops)
var/enrolled = 0 // Weather the computer is enrolled in the company device management or not. 0 - unconfigured 1 - enrolled (work device) 2 - unenrolled (private device)
var/_app_preset_type // Used for specifying the software preset of the console
var/ambience_last_played // Last time sound was played
var/ambience_last_played_time // Last time sound was played
var/pAI_lock = FALSE // Toggles whether pAI can interact with the modular computer while installed in it
var/obj/item/card/id/registered_id = null // ID used for chat client registering
var/scan_mode = null // Mode used for health/reagent scanners
@@ -29,6 +29,7 @@
var/doorcode = "smindicate"
var/hidden = FALSE
var/initial_name
var/is_portable = FALSE // Used to prevent the ambient beeps from playing.
// Modular computers can run on various devices. Each DEVICE (Laptop, Console, Tablet,..)
// must have it's own DMI file. Icon states must be called exactly the same in all files, but may look differently

View File

@@ -13,6 +13,7 @@
hardware_flag = PROGRAM_TABLET
max_hardware_size = 1
w_class = ITEMSIZE_SMALL
is_portable = TRUE
/obj/item/modular_computer/handheld/Initialize()
. = ..()

View File

@@ -0,0 +1,6 @@
author: SleepyGemmy
delete-after: True
changes:
- tweak: "Reworks and cleans up the ambience code. Seperates the ambience and ambient hum and makes the ambient hum its own SFX toggle."