From b68b48e37e9730664a7604713fed55a683d82607 Mon Sep 17 00:00:00 2001 From: Contrabang <91113370+Contrabang@users.noreply.github.com> Date: Tue, 26 Mar 2024 06:55:10 -0400 Subject: [PATCH] Makes stuttering actually legible (#24324) * stutter but better * good whitespace * downstream support --- .../mob/living/carbon/human/human_say.dm | 2 +- .../living/carbon/human/species/_species.dm | 3 - .../living/carbon/human/species/plasmaman.dm | 5 -- code/modules/mob/living/living_say.dm | 5 +- code/modules/mob/mob_misc_procs.dm | 70 ++++++++----------- 5 files changed, 30 insertions(+), 55 deletions(-) diff --git a/code/modules/mob/living/carbon/human/human_say.dm b/code/modules/mob/living/carbon/human/human_say.dm index c6e66e1b38e..1c9e0db7f61 100644 --- a/code/modules/mob/living/carbon/human/human_say.dm +++ b/code/modules/mob/living/carbon/human/human_say.dm @@ -159,7 +159,7 @@ GLOBAL_LIST_INIT(soapy_words, list( var/braindam = getBrainLoss() if(braindam >= 60) if(prob(braindam / 4)) - S.message = stutter(S.message) + S.message = stutter(S.message, getStaminaLoss(), ismachineperson(src)) verb = "gibbers" else if(prob(braindam / 2)) S.message = uppertext(S.message) diff --git a/code/modules/mob/living/carbon/human/species/_species.dm b/code/modules/mob/living/carbon/human/species/_species.dm index 850c430cec5..1d6d67f995d 100644 --- a/code/modules/mob/living/carbon/human/species/_species.dm +++ b/code/modules/mob/living/carbon/human/species/_species.dm @@ -694,9 +694,6 @@ if(INTENT_DISARM) disarm(M, H, attacker_style) -/datum/species/proc/say_filter(mob/M, message, datum/language/speaking) - return message - /datum/species/proc/before_equip_job(datum/job/J, mob/living/carbon/human/H, visualsOnly = FALSE) return diff --git a/code/modules/mob/living/carbon/human/species/plasmaman.dm b/code/modules/mob/living/carbon/human/species/plasmaman.dm index a9a24b1ef32..2e1a6c0e66e 100644 --- a/code/modules/mob/living/carbon/human/species/plasmaman.dm +++ b/code/modules/mob/living/carbon/human/species/plasmaman.dm @@ -48,11 +48,6 @@ speciesbox = /obj/item/storage/box/survival_plasmaman flesh_color = "#8b3fba" -/datum/species/plasmaman/say_filter(mob/M, message, datum/language/speaking) - if(copytext(message, 1, 2) != "*") - message = replacetext(message, "s", stutter("ss")) - return message - /datum/species/plasmaman/before_equip_job(datum/job/J, mob/living/carbon/human/H, visualsOnly = FALSE) var/current_job = J.title var/datum/outfit/plasmaman/O = new /datum/outfit/plasmaman diff --git a/code/modules/mob/living/living_say.dm b/code/modules/mob/living/living_say.dm index 56f4efbf770..917bd1a9460 100644 --- a/code/modules/mob/living/living_say.dm +++ b/code/modules/mob/living/living_say.dm @@ -79,10 +79,7 @@ GLOBAL_LIST_EMPTY(channel_to_radio_key) verb = "slurs" if(AmountStuttering()) - if(robot) - S.message = robostutter(S.message) - else - S.message = stutter(S.message) + S.message = stutter(S.message, getStaminaLoss(), robot) verb = "stammers" if(AmountCultSlurring()) diff --git a/code/modules/mob/mob_misc_procs.dm b/code/modules/mob/mob_misc_procs.dm index 5229d3f14cb..7aa785514dc 100644 --- a/code/modules/mob/mob_misc_procs.dm +++ b/code/modules/mob/mob_misc_procs.dm @@ -273,50 +273,36 @@ counter-=1 return newphrase -/proc/stutter(n) - var/te = html_decode(n) - var/t = "" //placed before the message. Not really sure what it's for. - n = length_char(n) //length of the entire word - var/p = null - p = 1 //1 is the start of any word - while(p <= n) //while P, which starts at 1 is less or equal to N which is the length. - var/n_letter = copytext_char(te, p, p + 1)//copies text from a certain distance. In this case, only one letter at a time. - if(prob(80) && (lowertext(n_letter) in list("b","c","d","f","g","h","j","k","l","m","n","p","q","r","s","t","v","w","x","y","z"))) - if(prob(5)) - n_letter = text("[n_letter]-[n_letter]-[n_letter]") //replaces the current letter with this instead. - else - if(prob(5)) - n_letter = null - else - n_letter = text("[n_letter]-[n_letter]") - t = text("[t][n_letter]") //since the above is ran through for each letter, the text just adds up back to the original word. - p++ //for each letter p is increased to find where the next letter will be. - return sanitize(copytext_char(t, 1, MAX_MESSAGE_LEN)) +/proc/stutter(phrase, stamina_loss = 0, robotic = FALSE) + phrase = html_decode(phrase) + var/list/split_phrase = splittext_char(phrase, " ") //Split it up into words. -/proc/robostutter(n) //for robutts - var/te = html_decode(n) - var/t = ""//placed before the message. Not really sure what it's for. - n = length_char(n)//length of the entire word - var/p = null - p = 1//1 is the start of any word - while(p <= n)//while P, which starts at 1 is less or equal to N which is the length. - var/robotletter = pick("@", "!", "#", "$", "%", "&", "?") //for beep boop - var/n_letter = copytext_char(te, p, p + 1)//copies text from a certain distance. In this case, only one letter at a time. - if(prob(80) && (lowertext(n_letter) in list("b","c","d","f","g","h","j","k","l","m","n","p","q","r","s","t","v","w","x","y","z"))) - if(prob(10)) - n_letter = text("[n_letter]-[robotletter]-[n_letter]-[n_letter]")//replaces the current letter with this instead. - else - if(prob(20)) - n_letter = text("[n_letter]-[robotletter]-[n_letter]") - else - if(prob(5)) - n_letter = robotletter - else - n_letter = text("[n_letter]-[n_letter]") - t = text("[t][n_letter]")//since the above is ran through for each letter, the text just adds up back to the original word. - p++//for each letter p is increased to find where the next letter will be. - return sanitize(copytext_char(t, 1, MAX_MESSAGE_LEN)) + var/phrase_length = length_char(split_phrase) + var/stutter_chance = clamp(max(rand(25, 50), stamina_loss), 0, 100) + for(var/index in 1 to phrase_length) + if(!prob(stutter_chance)) + continue + var/word = split_phrase[index] // Get the word at the index + var/first_letter = copytext_char(word, 1, 2) + //Search for dipthongs (two letters that make one sound.) + var/first_sound = copytext_char(word, 1, 3) + if(lowertext(first_sound) in list("ch", "th", "sh")) + first_letter = first_sound + + var/second_repeat = first_letter + if(robotic && prob(50)) + first_letter = pick("@", "!", "#", "$", "%", "&", "?") + if(prob(25)) + second_repeat = pick("@", "!", "#", "$", "%", "&", "?") + //Repeat the first letter to create a stutter. + if(rand(1, 3) == 1) // more accurate than prob(33.333333) + word = "[first_letter]-[second_repeat]-[word]" + else + word = "[first_letter]-[word]" + split_phrase[index] = word // replace it + + return sanitize(jointext(split_phrase, " ")) /proc/Gibberish(t, p, replace_rate = 50)//t is the inputted message, and any value higher than 70 for p will cause letters to be replaced instead of added. replace_rate is the chance a letter is corrupted. /* Turn text into complete gibberish! */