Simplifies hearing into handle_hearing() (#9443)

Currently, hearing related stuff is handled in at least three places throughout Life(), and whether a mob is deaf or not is complicated - Handled by an sdisabilities flag, has_hearing_aid() and ear_deaf.

This change consolidates everything into handle_hearing(); whether a mob is deaf or not can be determined just by the value of ear_deaf using isdeaf()

Fixes #9310
Fixes #8490
This commit is contained in:
mikomyazaki
2020-07-24 13:04:08 +01:00
committed by GitHub
parent 074cbfc9b1
commit 3ac9bd5849
13 changed files with 63 additions and 61 deletions

View File

@@ -314,6 +314,10 @@
#define TASTE_DULL 0.5 //anything below 30% #define TASTE_DULL 0.5 //anything below 30%
#define TASTE_NUMB 0.1 //anything below 150% #define TASTE_NUMB 0.1 //anything below 150%
//ear healing limit - past this ear_damage your ear will not recover its hearing over time
#define HEARING_DAMAGE_LIMIT 100
#define HEARING_DAMAGE_SLOW_HEAL 25
//Used by emotes //Used by emotes
#define VISIBLE_MESSAGE 1 #define VISIBLE_MESSAGE 1
#define AUDIBLE_MESSAGE 2 #define AUDIBLE_MESSAGE 2

View File

@@ -341,7 +341,7 @@ var/datum/controller/subsystem/explosives/SSexplosives
continue continue
var/dist = get_dist(M, epicenter) || 1 var/dist = get_dist(M, epicenter) || 1
if ((reception & EXPLFX_SOUND) && M.ear_deaf <= 0) if ((reception & EXPLFX_SOUND) && !isdeaf(M))
if (dist <= close_dist) if (dist <= close_dist)
M.playsound_simple(epicenter, explosion_sound, min(100, volume), use_random_freq = TRUE, falloff = 5) M.playsound_simple(epicenter, explosion_sound, min(100, volume), use_random_freq = TRUE, falloff = 5)
//You hear a far explosion if you're outside the blast radius. Small bombs shouldn't be heard all over the station. //You hear a far explosion if you're outside the blast radius. Small bombs shouldn't be heard all over the station.

View File

@@ -57,73 +57,69 @@
activation_message="Your mind says 'Hello'." activation_message="Your mind says 'Hello'."
mutation=mHallucination mutation=mHallucination
New() /datum/dna/gene/disability/hallucinate/New()
block=HALLUCINATIONBLOCK block=HALLUCINATIONBLOCK
/datum/dna/gene/disability/epilepsy /datum/dna/gene/disability/epilepsy
name="Epilepsy" name="Epilepsy"
activation_message="You get a headache." activation_message="You get a headache."
disability=EPILEPSY disability=EPILEPSY
New() /datum/dna/gene/disability/epilepsy/New()
block=HEADACHEBLOCK block=HEADACHEBLOCK
/datum/dna/gene/disability/cough /datum/dna/gene/disability/cough
name="Coughing" name="Coughing"
activation_message="You start coughing." activation_message="You start coughing."
disability=COUGHING disability=COUGHING
New() /datum/dna/gene/disability/cough/New()
block=COUGHBLOCK block=COUGHBLOCK
/datum/dna/gene/disability/clumsy /datum/dna/gene/disability/clumsy
name="Clumsiness" name="Clumsiness"
activation_message="You feel lightheaded." activation_message="You feel lightheaded."
mutation=CLUMSY mutation=CLUMSY
New() /datum/dna/gene/disability/clumsy/New()
block=CLUMSYBLOCK block=CLUMSYBLOCK
/datum/dna/gene/disability/tourettes /datum/dna/gene/disability/tourettes
name="Tourettes" name="Tourettes"
activation_message="You twitch." activation_message="You twitch."
disability=TOURETTES disability=TOURETTES
New() /datum/dna/gene/disability/tourettes/New()
block=TWITCHBLOCK block=TWITCHBLOCK
/datum/dna/gene/disability/stutter /datum/dna/gene/disability/stutter
name="Stuttering" name="Stuttering"
activation_message="You feel like forming words becomes increasingly difficult." activation_message="You feel like forming words becomes increasingly difficult."
disability=STUTTERING disability=STUTTERING
New() /datum/dna/gene/disability/stutter/New()
block=STUTTERBLOCK block=STUTTERBLOCK
/datum/dna/gene/disability/blindness /datum/dna/gene/disability/blindness
name="Blindness" name="Blindness"
activation_message="You can't seem to see anything." activation_message="You can't seem to see anything."
sdisability=BLIND sdisability=BLIND
New() /datum/dna/gene/disability/blindness/New()
block=BLINDBLOCK block=BLINDBLOCK
/datum/dna/gene/disability/deaf /datum/dna/gene/disability/deaf
name="Deafness" name="Deafness"
activation_message="It's kinda quiet." activation_message="It's kinda quiet."
sdisability=DEAF sdisability=DEAF
New() /datum/dna/gene/disability/deaf/New()
block=DEAFBLOCK block=DEAFBLOCK
activate(var/mob/M, var/connected, var/flags)
..(M,connected,flags)
M.ear_deaf = 1
/datum/dna/gene/disability/nearsighted /datum/dna/gene/disability/nearsighted
name="Nearsightedness" name="Nearsightedness"
activation_message="Your eyes feel weird..." activation_message="Your eyes feel weird..."
disability=NEARSIGHTED disability=NEARSIGHTED
New() /datum/dna/gene/disability/nearsighted/New()
block=GLASSESBLOCK block=GLASSESBLOCK

View File

@@ -328,6 +328,6 @@
var/mob/M = A var/mob/M = A
var/turf/mobloc = get_turf(M) var/turf/mobloc = get_turf(M)
if(mobloc && mobloc.z == T.z) if(mobloc && mobloc.z == T.z)
if(M.ear_deaf <= 0 || !M.ear_deaf) if(!isdeaf(M))
M.playsound_simple(T, 'sound/effects/meteorimpact.ogg', range, use_random_freq = TRUE, use_pressure = FALSE) M.playsound_simple(T, 'sound/effects/meteorimpact.ogg', range, use_random_freq = TRUE, use_pressure = FALSE)

View File

@@ -31,15 +31,10 @@
//This is a central proc that all emotes are run through. This handles sending the messages to living mobs //This is a central proc that all emotes are run through. This handles sending the messages to living mobs
/mob/proc/send_emote(var/message, var/type) /mob/proc/send_emote(var/message, var/type)
var/list/messageturfs = list()//List of turfs we broadcast to. var/list/messageturfs = list()//List of turfs we broadcast to.
var/list/messagemobs = list() var/list/messagemobs = list()
var/list/ghosts = list() var/list/ghosts = list()
var/list/ghosts_nearby = list() var/list/ghosts_nearby = list()
var/hearing_aid = FALSE
if(type == 2 && ishuman(src))
var/mob/living/carbon/human/H = src
hearing_aid = H.has_hearing_aid()
for (var/turf in view(world.view, get_turf(src))) for (var/turf in view(world.view, get_turf(src)))
messageturfs += turf messageturfs += turf
@@ -50,7 +45,7 @@
if (isobserver(M)) if (isobserver(M))
ghosts_nearby += M ghosts_nearby += M
continue continue
else if (isliving(M) && !(type == 2 && ((sdisabilities & DEAF) && !hearing_aid) || ear_deaf > 1)) else if (isliving(M) && !(type == 2 && isdeaf(M)))
messagemobs += M messagemobs += M
else if(src.client) else if(src.client)
if (M.stat == DEAD && (M.client.prefs.toggles & CHAT_GHOSTSIGHT)) if (M.stat == DEAD && (M.client.prefs.toggles & CHAT_GHOSTSIGHT))
@@ -62,6 +57,6 @@
for(var/mob/O in ghosts) for(var/mob/O in ghosts)
O.show_message("[ghost_follow_link(src, O)] [message]", type) O.show_message("[ghost_follow_link(src, O)] [message]", type)
for(var/mob/GN in ghosts_nearby) for(var/mob/GN in ghosts_nearby)
GN.show_message("[ghost_follow_link(src, GN)] <b>[message]</b>", type) GN.show_message("[ghost_follow_link(src, GN)] <b>[message]</b>", type)

View File

@@ -63,12 +63,7 @@
if((client.prefs.toggles & CHAT_GHOSTEARS) && (speaker in view(src))) if((client.prefs.toggles & CHAT_GHOSTEARS) && (speaker in view(src)))
message = "<b>[message]</b>" message = "<b>[message]</b>"
var/hearing_aid = FALSE if(isdeaf(src))
if(ishuman(src))
var/mob/living/carbon/human/H = src
hearing_aid = H.has_hearing_aid()
if(((sdisabilities & DEAF) && !hearing_aid) || ear_deaf > 1)
if(!language || !(language.flags & INNATE)) // INNATE is the flag for audible-emote-language, so we don't want to show an "x talks but you cannot hear them" message if it's set if(!language || !(language.flags & INNATE)) // INNATE is the flag for audible-emote-language, so we don't want to show an "x talks but you cannot hear them" message if it's set
if(speaker == src) if(speaker == src)
to_chat(src, "<span class='warning'>You cannot hear yourself speak!</span>") to_chat(src, "<span class='warning'>You cannot hear yourself speak!</span>")
@@ -205,7 +200,7 @@
formatted = language.format_message_radio(message, verb) formatted = language.format_message_radio(message, verb)
else else
formatted = "[verb], <span class=\"body\">\"[message]\"</span>" formatted = "[verb], <span class=\"body\">\"[message]\"</span>"
if(sdisabilities & DEAF || ear_deaf) if(isdeaf(src))
if(prob(20)) if(prob(20))
to_chat(src, "<span class='warning'>You feel your headset vibrate but can hear nothing from it!</span>") to_chat(src, "<span class='warning'>You feel your headset vibrate but can hear nothing from it!</span>")
else else

View File

@@ -773,17 +773,6 @@
if(!embedded_needs_process()) if(!embedded_needs_process())
embedded_flag = 0 embedded_flag = 0
//Ears
if(sdisabilities & DEAF) //disabled-deaf, doesn't get better on its own
ear_deaf = max(ear_deaf, 1)
else if(ear_deaf) //deafness, heals slowly over time
ear_deaf = max(ear_deaf-1, 0)
else if(istype(l_ear, /obj/item/clothing/ears/earmuffs) || istype(r_ear, /obj/item/clothing/ears/earmuffs)) //resting your ears with earmuffs heals ear damage faster
ear_damage = max(ear_damage-0.15, 0)
ear_deaf = max(ear_deaf, 1)
else if(ear_damage < 25) //ear damage heals slowly under this threshold. otherwise you'll need earmuffs
ear_damage = max(ear_damage-0.05, 0)
//Resting //Resting
if(resting) if(resting)
dizziness = max(0, dizziness - 15) dizziness = max(0, dizziness - 15)
@@ -1294,6 +1283,20 @@
update_equipment_vision() update_equipment_vision()
species.handle_vision(src) species.handle_vision(src)
/mob/living/carbon/human/handle_hearing()
..()
if(ear_damage < HEARING_DAMAGE_LIMIT)
//Hearing aids allow our ear_deaf to reach zero, if we have a hearing disability
if(ear_deaf <= 1 && (sdisabilities & DEAF) && has_hearing_aid())
setEarDamage(-1, max(ear_deaf-1, 0))
if(istype(l_ear, /obj/item/clothing/ears/earmuffs) || istype(r_ear, /obj/item/clothing/ears/earmuffs)) //resting your ears with earmuffs heals ear damage faster
adjustEarDamage(-0.15, 0)
setEarDamage(-1, max(ear_deaf, 1))
else if(ear_damage < HEARING_DAMAGE_SLOW_HEAL) //ear damage heals slowly under this threshold. otherwise you'll need earmuffs
adjustEarDamage(-0.05, 0)
/mob/living/carbon/human/update_sight() /mob/living/carbon/human/update_sight()
..() ..()
if(stat == DEAD) if(stat == DEAD)

View File

@@ -121,12 +121,8 @@
eye_blurry = max(eye_blurry-1, 0) eye_blurry = max(eye_blurry-1, 0)
//Ears //Ears
if(sdisabilities & DEAF) //disabled-deaf, doesn't get better on its own handle_hearing()
setEarDamage(-1, max(ear_deaf, 1))
else
// deafness heals slowly over time, unless ear_damage is over 100
if(ear_damage < 100)
adjustEarDamage(-0.05,-1)
if((is_pacified()) && a_intent == I_HURT) if((is_pacified()) && a_intent == I_HURT)
to_chat(src, "<span class='notice'>You don't feel like harming anybody.</span>") to_chat(src, "<span class='notice'>You don't feel like harming anybody.</span>")
a_intent_change(I_HELP) a_intent_change(I_HELP)
@@ -175,6 +171,13 @@
else if(!client.adminobs) else if(!client.adminobs)
reset_view(null) reset_view(null)
/mob/living/proc/handle_hearing()
// deafness heals slowly over time, unless ear_damage is over HEARING_DAMAGE_LIMIT
if(ear_damage < HEARING_DAMAGE_LIMIT)
adjustEarDamage(-0.05, -1)
if(sdisabilities & DEAF) //disabled-deaf, doesn't get better on its own
setEarDamage(-1, max(ear_deaf, 1))
/mob/living/proc/update_sight() /mob/living/proc/update_sight()
if(stat == DEAD || eyeobj) if(stat == DEAD || eyeobj)
update_dead_sight() update_dead_sight()

View File

@@ -390,7 +390,7 @@ var/controlling
M.show_message("<B>[host]</B> whispers something incoherent.",2) // 2 stands for hearable message M.show_message("<B>[host]</B> whispers something incoherent.",2) // 2 stands for hearable message
// Find out whether the target can hear // Find out whether the target can hear
if(target.disabilities & 32 || target.ear_deaf) if(target.disabilities & 32 || isdeaf(target))
to_chat(src, "<span class='warning'>Your target doesn't seem to hear you.</span>") to_chat(src, "<span class='warning'>Your target doesn't seem to hear you.</span>")
return return
@@ -434,7 +434,7 @@ var/controlling
M.show_message("<B>[host]</B> screams something incoherent!",2) // 2 stands for hearable message M.show_message("<B>[host]</B> screams something incoherent!",2) // 2 stands for hearable message
// Find out whether the target can hear // Find out whether the target can hear
if(target.disabilities & 32 || target.ear_deaf) if(target.disabilities & 32 || isdeaf(target))
to_chat(src, "<span class='warning'>Your target doesn't seem to hear you.</span>") to_chat(src, "<span class='warning'>Your target doesn't seem to hear you.</span>")
return return

View File

@@ -89,7 +89,7 @@
else else
msg = alt msg = alt
type = alt_type type = alt_type
if (type & 2 && (sdisabilities & DEAF || ear_deaf))//Hearing related if (type & 2 && isdeaf(src))//Hearing related
if (!( alt )) if (!( alt ))
return return
else else

View File

@@ -155,7 +155,7 @@
proc/isdeaf(A) proc/isdeaf(A)
if(istype(A, /mob)) if(istype(A, /mob))
var/mob/M = A var/mob/M = A
return (M.sdisabilities & DEAF) || M.ear_deaf return M.ear_deaf
return 0 return 0
proc/iscuffed(A) proc/iscuffed(A)

View File

@@ -25,7 +25,7 @@
for(var/obj/item/device/radio/radio in listening_objects) for(var/obj/item/device/radio/radio in listening_objects)
if(radio.on) if(radio.on)
for(var/mob/living/victim in range(radio.canhear_range, radio.loc)) for(var/mob/living/victim in range(radio.canhear_range, radio.loc))
if(isnull(victims[victim]) && victim.stat == CONSCIOUS && !victim.ear_deaf) if(isnull(victims[victim]) && victim.stat == CONSCIOUS && !isdeaf(victim))
victims[victim] = radio victims[victim] = radio
for(var/thing in victims) for(var/thing in victims)
var/mob/living/victim = thing var/mob/living/victim = thing

View File

@@ -0,0 +1,6 @@
author: mikomyazaki
delete-after: True
changes:
- bugfix: "Hearing aids should now allow deaf characters to hear holocomms, radios, etc."