-
Notifications
You must be signed in to change notification settings - Fork 224
/
Copy pathautohiss.dm
57 lines (48 loc) · 2.03 KB
/
autohiss.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#define AUTOHISS_NUM 3
/mob/living/proc/handle_autohiss(message, decl/language/L)
return message // no autohiss at this level
/mob/living/human/handle_autohiss(message, decl/language/L)
if(!client || get_preference_value(/datum/client_preference/autohiss) == PREF_OFF) // no need to process if there's no client or they have autohiss off
return message
return species.handle_autohiss(message, L, get_preference_value(/datum/client_preference/autohiss))
/decl/species
var/list/autohiss_basic_map = null
var/list/autohiss_extra_map = null
var/list/autohiss_exempt = null
/decl/species/proc/get_autohiss_map(var/mode)
. = autohiss_basic_map?.Copy() || list()
if(mode == PREF_FULL && autohiss_extra_map)
. |= autohiss_extra_map
/decl/species/proc/handle_autohiss(message, decl/language/lang, mode)
if(!autohiss_basic_map)
return message
if(lang.flags & LANG_FLAG_NO_STUTTER) // Currently prevents EAL, Sign language, and emotes from autohissing
return message
if(autohiss_exempt && (lang.name in autohiss_exempt))
return message
var/map = get_autohiss_map(mode)
. = list()
while(length(message))
var/min_index = 10000 // if the message is longer than this, the autohiss is the least of your problems
var/min_char = null
for(var/char in map)
var/i = findtext_char(message, char)
if(!i) // no more of this character anywhere in the string, don't even bother searching next time
map -= char
else if(i < min_index)
min_index = i
min_char = char
if(!min_char) // we didn't find any of the mapping characters
. += message
break
. += copytext_char(message, 1, min_index)
if(copytext_char(message, min_index, min_index+1) == uppertext(min_char))
switch(text2ascii(message, min_index+1))
if(65 to 90) // A-Z, uppercase; uppercase R/S followed by another uppercase letter, uppercase the entire replacement string
. += uppertext(pick(map[min_char]))
else
. += capitalize(pick(map[min_char]))
else
. += pick(map[min_char])
message = copytext_char(message, min_index + 1)
return jointext(., null)