/
type2type.dm
397 lines (347 loc) · 9.97 KB
/
type2type.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
/*
* Holds procs designed to change one type of value, into another.
* Contains:
* file2list
* angle2dir
* angle2text
* worldtime2text
* text2dir_extended & dir2text_short
*/
//Splits the text of a file at seperator and returns them in a list.
//returns an empty list if the file doesn't exist
/world/proc/file2list(filename, seperator="\n", trim = TRUE)
if (trim)
return splittext(trim(file2text(filename)),seperator)
return splittext(file2text(filename),seperator)
//Turns a direction into text
/proc/dir2text(direction)
switch(direction)
if(NORTH)
return "north"
if(SOUTH)
return "south"
if(EAST)
return "east"
if(WEST)
return "west"
if(NORTHEAST)
return "northeast"
if(SOUTHEAST)
return "southeast"
if(NORTHWEST)
return "northwest"
if(SOUTHWEST)
return "southwest"
return NONE
//Turns text into proper directions
/proc/text2dir(direction)
switch(uppertext(direction))
if("NORTH")
return NORTH
if("SOUTH")
return SOUTH
if("EAST")
return EAST
if("WEST")
return WEST
if("NORTHEAST")
return NORTHEAST
if("NORTHWEST")
return NORTHWEST
if("SOUTHEAST")
return SOUTHEAST
if("SOUTHWEST")
return SOUTHWEST
return NONE
//Converts an angle (degrees) into a ss13 direction
GLOBAL_LIST_INIT(modulo_angle_to_dir, list(NORTH,NORTHEAST,EAST,SOUTHEAST,SOUTH,SOUTHWEST,WEST,NORTHWEST))
#define angle2dir(X) (GLOB.modulo_angle_to_dir[round((((X%360)+382.5)%360)/45)+1])
/proc/angle2dir_cardinal(degree)
degree = SIMPLIFY_DEGREES(degree)
switch(round(degree, 0.1))
if(315.5 to 360, 0 to 45.5)
return NORTH
if(45.6 to 135.5)
return EAST
if(135.6 to 225.5)
return SOUTH
if(225.6 to 315.5)
return WEST
//returns the north-zero clockwise angle in degrees, given a direction
/proc/dir2angle(D)
switch(D)
if(NORTH)
return 0
if(SOUTH)
return 180
if(EAST)
return 90
if(WEST)
return 270
if(NORTHEAST)
return 45
if(SOUTHEAST)
return 135
if(NORTHWEST)
return 315
if(SOUTHWEST)
return 225
else
return null
//Returns the angle in english
/proc/angle2text(degree)
return dir2text(angle2dir(degree))
/// Returns a list(x, y), being the change in position required to step in the passed in direction
/proc/dir2offset(dir)
switch(dir)
if(NORTH)
return list(0, 1)
if(SOUTH)
return list(0, -1)
if(EAST)
return list(1, 0)
if(WEST)
return list(-1, 0)
if(NORTHEAST)
return list(1, 1)
if(SOUTHEAST)
return list(1, -1)
if(NORTHWEST)
return list(-1, 1)
if(SOUTHWEST)
return list(-1, -1)
else
return list(0, 0)
//Converts a blend_mode constant to one acceptable to icon.Blend()
/proc/blendMode2iconMode(blend_mode)
switch(blend_mode)
if(BLEND_MULTIPLY)
return ICON_MULTIPLY
if(BLEND_ADD)
return ICON_ADD
if(BLEND_SUBTRACT)
return ICON_SUBTRACT
else
return ICON_OVERLAY
//Converts a rights bitfield into a string
/proc/rights2text(rights, seperator="", prefix = "+")
seperator += prefix
if(rights & R_BUILD)
. += "[seperator]BUILDMODE"
if(rights & R_ADMIN)
. += "[seperator]ADMIN"
if(rights & R_BAN)
. += "[seperator]BAN"
if(rights & R_FUN)
. += "[seperator]FUN"
if(rights & R_SERVER)
. += "[seperator]SERVER"
if(rights & R_DEBUG)
. += "[seperator]DEBUG"
if(rights & R_POSSESS)
. += "[seperator]POSSESS"
if(rights & R_PERMISSIONS)
. += "[seperator]PERMISSIONS"
if(rights & R_STEALTH)
. += "[seperator]STEALTH"
if(rights & R_POLL)
. += "[seperator]POLL"
if(rights & R_VAREDIT)
. += "[seperator]VAREDIT"
if(rights & R_SOUND)
. += "[seperator]SOUND"
if(rights & R_SPAWN)
. += "[seperator]SPAWN"
if(rights & R_AUTOADMIN)
. += "[seperator]AUTOLOGIN"
if(rights & R_DBRANKS)
. += "[seperator]DBRANKS"
if(!.)
. = "NONE"
return .
/// For finding out what body parts a body zone covers, the inverse of the below basically
/proc/body_zone2cover_flags(def_zone)
switch(def_zone)
if(BODY_ZONE_CHEST)
return CHEST|GROIN
if(BODY_ZONE_HEAD)
return HEAD
if(BODY_ZONE_L_ARM)
return ARM_LEFT|HAND_LEFT
if(BODY_ZONE_R_ARM)
return ARM_RIGHT|HAND_RIGHT
if(BODY_ZONE_L_LEG)
return LEG_LEFT|FOOT_LEFT
if(BODY_ZONE_R_LEG)
return LEG_RIGHT|FOOT_RIGHT
//Turns a Body_parts_covered bitfield into a list of organ/limb names.
//(I challenge you to find a use for this) -I found a use for it!! | So did I!.
/proc/cover_flags2body_zones(bpc)
var/list/covered_parts = list()
if(!bpc)
return 0
if(bpc == FULL_BODY)
covered_parts |= list(BODY_ZONE_L_ARM,BODY_ZONE_R_ARM,BODY_ZONE_HEAD,BODY_ZONE_CHEST,BODY_ZONE_L_LEG,BODY_ZONE_R_LEG)
else
if(bpc & HEAD)
covered_parts |= list(BODY_ZONE_HEAD)
if(bpc & CHEST)
covered_parts |= list(BODY_ZONE_CHEST)
if(bpc & GROIN)
covered_parts |= list(BODY_ZONE_CHEST)
if(bpc & ARMS)
covered_parts |= list(BODY_ZONE_L_ARM,BODY_ZONE_R_ARM)
else
if(bpc & ARM_LEFT)
covered_parts |= list(BODY_ZONE_L_ARM)
if(bpc & ARM_RIGHT)
covered_parts |= list(BODY_ZONE_R_ARM)
if(bpc & HANDS)
covered_parts |= list(BODY_ZONE_L_ARM,BODY_ZONE_R_ARM)
else
if(bpc & HAND_LEFT)
covered_parts |= list(BODY_ZONE_L_ARM)
if(bpc & HAND_RIGHT)
covered_parts |= list(BODY_ZONE_R_ARM)
if(bpc & LEGS)
covered_parts |= list(BODY_ZONE_L_LEG,BODY_ZONE_R_LEG)
else
if(bpc & LEG_LEFT)
covered_parts |= list(BODY_ZONE_L_LEG)
if(bpc & LEG_RIGHT)
covered_parts |= list(BODY_ZONE_R_LEG)
if(bpc & FEET)
covered_parts |= list(BODY_ZONE_L_LEG,BODY_ZONE_R_LEG)
else
if(bpc & FOOT_LEFT)
covered_parts |= list(BODY_ZONE_L_LEG)
if(bpc & FOOT_RIGHT)
covered_parts |= list(BODY_ZONE_R_LEG)
return covered_parts
/proc/slot2body_zone(slot)
switch(slot)
if(ITEM_SLOT_BACK, ITEM_SLOT_OCLOTHING, ITEM_SLOT_ICLOTHING, ITEM_SLOT_BELT, ITEM_SLOT_ID)
return BODY_ZONE_CHEST
if(ITEM_SLOT_GLOVES, ITEM_SLOT_HANDS, ITEM_SLOT_HANDCUFFED)
return pick(BODY_ZONE_PRECISE_L_HAND, BODY_ZONE_PRECISE_R_HAND)
if(ITEM_SLOT_HEAD, ITEM_SLOT_NECK, ITEM_SLOT_NECK, ITEM_SLOT_EARS)
return BODY_ZONE_HEAD
if(ITEM_SLOT_MASK)
return BODY_ZONE_PRECISE_MOUTH
if(ITEM_SLOT_EYES)
return BODY_ZONE_PRECISE_EYES
if(ITEM_SLOT_FEET)
return pick(BODY_ZONE_PRECISE_R_FOOT, BODY_ZONE_PRECISE_L_FOOT)
if(ITEM_SLOT_LEGCUFFED)
return pick(BODY_ZONE_L_LEG, BODY_ZONE_R_LEG)
//adapted from http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/
/proc/heat2colour(temp)
return rgb(heat2colour_r(temp), heat2colour_g(temp), heat2colour_b(temp))
/proc/heat2colour_r(temp)
temp /= 100
if(temp <= 66)
. = 255
else
. = max(0, min(255, 329.698727446 * (temp - 60) ** -0.1332047592))
/proc/heat2colour_g(temp)
temp /= 100
if(temp <= 66)
. = max(0, min(255, 99.4708025861 * log(temp) - 161.1195681661))
else
. = max(0, min(255, 288.1221685293 * ((temp - 60) ** -0.075148492)))
/proc/heat2colour_b(temp)
temp /= 100
if(temp >= 66)
. = 255
else
if(temp <= 16)
. = 0
else
. = max(0, min(255, 138.5177312231 * log(temp - 10) - 305.0447927307))
//This is a weird one:
//It returns a list of all var names found in the string
//These vars must be in the [var_name] format
//It's only a proc because it's used in more than one place
//Takes a string and a datum
//The string is well, obviously the string being checked
//The datum is used as a source for var names, to check validity
//Otherwise every single word could technically be a variable!
/proc/string2listofvars(t_string, datum/var_source)
if(!t_string || !var_source)
return list()
. = list()
var/var_found = findtext(t_string,"\[") //Not the actual variables, just a generic "should we even bother" check
if(var_found)
//Find var names
// "A dog said hi [name]!"
// splittext() --> list("A dog said hi ","name]!"
// jointext() --> "A dog said hi name]!"
// splittext() --> list("A","dog","said","hi","name]!")
t_string = replacetext(t_string,"\[","\[ ")//Necessary to resolve "word[var_name]" scenarios
var/list/list_value = splittext(t_string,"\[")
var/intermediate_stage = jointext(list_value, null)
list_value = splittext(intermediate_stage," ")
for(var/value in list_value)
if(findtext(value,"]"))
value = splittext(value,"]") //"name]!" --> list("name","!")
for(var/A in value)
if(var_source.vars.Find(A))
. += A
//word of warning: using a matrix like this as a color value will simplify it back to a string after being set
/proc/color_hex2color_matrix(string)
var/length = length(string)
if((length != 7 && length != 9) || length != length_char(string))
return COLOR_MATRIX_IDENTITY
// For runtime safety
. = COLOR_MATRIX_IDENTITY
var/list/color = rgb2num(string)
var/r = color[1] / 255
var/g = color[2] / 255
var/b = color[3] / 255
var/a = 1
if(length(color) == 4)
a = color[4] / 255
return list(r,0,0,0, 0,g,0,0, 0,0,b,0, 0,0,0,a, 0,0,0,0)
//will drop all values not on the diagonal
/proc/color_matrix2color_hex(list/the_matrix)
if(!istype(the_matrix) || the_matrix.len != 20)
return "#ffffffff"
return rgb(the_matrix[1]*255, the_matrix[6]*255, the_matrix[11]*255, the_matrix[16]*255)
/proc/type2parent(child)
var/string_type = "[child]"
var/last_slash = findlasttext(string_type, "/")
if(last_slash == 1)
switch(child)
if(/datum)
return null
if(/obj, /mob)
return /atom/movable
if(/area, /turf)
return /atom
else
return /datum
return text2path(copytext(string_type, 1, last_slash))
//returns a string the last bit of a type, without the preceeding '/'
/proc/type2top(the_type)
//handle the builtins manually
if(!ispath(the_type))
return
switch(the_type)
if(/datum)
return "datum"
if(/atom)
return "atom"
if(/obj)
return "obj"
if(/mob)
return "mob"
if(/area)
return "area"
if(/turf)
return "turf"
else //regex everything else (works for /proc too)
return LOWER_TEXT(replacetext("[the_type]", "[type2parent(the_type)]/", ""))
/// Return html to load a url.
/// for use inside of browse() calls to html assets that might be loaded on a cdn.
/proc/url2htmlloader(url)
return {"<html><head><meta http-equiv="refresh" content="0;URL='[url]'"/></head><body onLoad="parent.location='[url]'"></body></html>"}