Files
Bubberstation/code/modules/flufftext/Dreaming.dm
Watermelon914 375a20e49b Refactors most spans into span procs (#59645)
Converts most spans into span procs. Mostly used regex for this and sorted out any compile time errors afterwards so there could be some bugs.
Was initially going to do defines, but ninja said to make it into a proc, and if there's any overhead, they can easily be changed to defines.

Makes it easier to control the formatting and prevents typos when creating spans as it'll runtime if you misspell instead of silently failing.
Reduces the code you need to write when writing spans, as you don't need to close the span as that's automatically handled by the proc.

(Note from Lemon: This should be converted to defines once we update the minimum version to 514. Didn't do it now because byond pain and such)
2021-06-14 13:03:53 -07:00

70 lines
1.8 KiB
Plaintext

/mob/living/carbon/proc/handle_dreams()
if(prob(10) && !dreaming)
dream()
/mob/living/carbon/proc/dream()
set waitfor = FALSE
var/list/dream_fragments = list()
var/list/custom_dream_nouns = list()
var/fragment = ""
for(var/obj/item/bedsheet/sheet in loc)
custom_dream_nouns += sheet.dream_messages
dream_fragments += "you see"
//Subject
if(custom_dream_nouns.len && prob(90))
fragment += pick(custom_dream_nouns)
else
fragment += pick(GLOB.dream_strings)
if(prob(50))
fragment = replacetext(fragment, "%ADJECTIVE%", pick(GLOB.adjectives))
else
fragment = replacetext(fragment, "%ADJECTIVE% ", "")
if(findtext(fragment, "%A% "))
fragment = "\a [replacetext(fragment, "%A% ", "")]"
dream_fragments += fragment
//Verb
fragment = ""
if(prob(50))
if(prob(35))
fragment += "[pick(GLOB.adverbs)] "
fragment += pick(GLOB.ing_verbs)
else
fragment += "will "
fragment += pick(GLOB.verbs)
dream_fragments += fragment
if(prob(25))
dream_sequence(dream_fragments)
return
//Object
fragment = ""
fragment += pick(GLOB.dream_strings)
if(prob(50))
fragment = replacetext(fragment, "%ADJECTIVE%", pick(GLOB.adjectives))
else
fragment = replacetext(fragment, "%ADJECTIVE% ", "")
if(findtext(fragment, "%A% "))
fragment = "\a [replacetext(fragment, "%A% ", "")]"
dream_fragments += fragment
dreaming = TRUE
dream_sequence(dream_fragments)
/mob/living/carbon/proc/dream_sequence(list/dream_fragments)
if(stat != UNCONSCIOUS || HAS_TRAIT(src, TRAIT_CRITICAL_CONDITION))
dreaming = FALSE
return
var/next_message = dream_fragments[1]
dream_fragments.Cut(1,2)
to_chat(src, span_notice("<i>... [next_message] ...</i>"))
if(LAZYLEN(dream_fragments))
addtimer(CALLBACK(src, .proc/dream_sequence, dream_fragments), rand(10,30))
else
dreaming = FALSE