-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathdance_machine.dm
477 lines (444 loc) · 15.6 KB
/
dance_machine.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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
/obj/machinery/jukebox
name = "jukebox"
desc = "A classic music player."
icon = 'icons/obj/stationobjs.dmi'
icon_state = "jukebox"
verb_say = "states"
density = TRUE
req_access = null
var/active = FALSE
var/list/rangers = list()
var/stop = 0
var/list/songs = list()
var/datum/track/selection = null
/// Volume of the songs played
var/volume = 100
/obj/machinery/jukebox/disco
name = "radiant dance machine mark IV"
desc = "The first three prototypes were discontinued after mass casualty incidents."
icon_state = "disco"
req_access = null
anchored = FALSE
var/list/spotlights = list()
var/list/sparkles = list()
/obj/machinery/jukebox/disco/indestructible
name = "radiant dance machine mark V"
desc = "Now redesigned with data gathered from the extensive disco and plasma research."
anchored = TRUE
resistance_flags = INDESTRUCTIBLE | LAVA_PROOF | FIRE_PROOF | UNACIDABLE | ACID_PROOF
flags_1 = NODECONSTRUCT_1
/obj/machinery/jukebox/disco/bar
req_access = list(ACCESS_BAR)
/datum/track
var/song_name = "generic"
var/song_path = null
var/song_length = 0
var/song_beat = 0
/datum/track/New(name, path, length, beat)
song_name = name
song_path = path
song_length = length
song_beat = beat
/obj/machinery/jukebox/Initialize(mapload)
. = ..()
var/list/tracks = flist("[global.config.directory]/jukebox_music/sounds/")
for(var/S in tracks)
var/datum/track/T = new()
T.song_path = file("[global.config.directory]/jukebox_music/sounds/[S]")
var/list/L = splittext(S,"+")
if(L.len != 3)
continue
T.song_name = L[1]
T.song_length = text2num(L[2])
T.song_beat = text2num(L[3])
songs |= T
if(songs.len)
selection = pick(songs)
/obj/machinery/jukebox/Destroy()
dance_over()
return ..()
/obj/machinery/jukebox/attackby(obj/item/O, mob/user, params)
if(!active && !(flags_1 & NODECONSTRUCT_1))
if(O.tool_behaviour == TOOL_WRENCH)
if(!anchored && !isinspace())
to_chat(user,span_notice("You secure [src] to the floor."))
setAnchored(TRUE)
else if(anchored)
to_chat(user,span_notice("You unsecure and disconnect [src]."))
setAnchored(FALSE)
playsound(src, 'sound/items/deconstruct.ogg', 50, TRUE)
return
return ..()
/obj/machinery/jukebox/update_icon_state()
. = ..()
if(active)
icon_state = "[initial(icon_state)]-active"
else
icon_state = "[initial(icon_state)]"
/obj/machinery/jukebox/ui_status(mob/user)
if(!anchored)
to_chat(user,span_warning("This device must be anchored by a wrench!"))
return UI_CLOSE
if(!allowed(user) && !isobserver(user))
to_chat(user,span_warning("Error: Access Denied."))
user.playsound_local(src, 'sound/misc/compiler-failure.ogg', 25, TRUE)
return UI_CLOSE
if(!songs.len && !isobserver(user))
to_chat(user,span_warning("Error: No music tracks have been authorized for your station. Petition Central Command to resolve this issue."))
playsound(src, 'sound/misc/compiler-failure.ogg', 25, TRUE)
return UI_CLOSE
return ..()
/obj/machinery/jukebox/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "Jukebox", name)
ui.open()
/obj/machinery/jukebox/ui_data(mob/user)
var/list/data = list()
data["active"] = active
data["songs"] = list()
for(var/datum/track/S in songs)
var/list/track_data = list(
name = S.song_name
)
data["songs"] += list(track_data)
data["track_selected"] = null
data["track_length"] = null
data["track_beat"] = null
if(selection)
data["track_selected"] = selection.song_name
data["track_length"] = DisplayTimeText(selection.song_length)
data["track_beat"] = selection.song_beat
data["volume"] = volume
return data
/obj/machinery/jukebox/ui_act(action, list/params)
. = ..()
if(.)
return
switch(action)
if("toggle")
if(QDELETED(src))
return
if(!active)
if(stop > world.time)
to_chat(usr, span_warning("Error: The device is still resetting from the last activation, it will be ready again in [DisplayTimeText(stop-world.time)]."))
playsound(src, 'sound/misc/compiler-failure.ogg', 50, TRUE)
return
activate_music()
START_PROCESSING(SSobj, src)
return TRUE
else
stop = 0
return TRUE
if("select_track")
if(active)
to_chat(usr, span_warning("Error: You cannot change the song until the current one is over."))
return
var/list/available = list()
for(var/datum/track/S in songs)
available[S.song_name] = S
var/selected = params["track"]
if(QDELETED(src) || !selected || !istype(available[selected], /datum/track))
return
selection = available[selected]
return TRUE
if("set_volume")
var/new_volume = params["volume"]
if(new_volume == "reset")
volume = initial(volume)
return TRUE
else if(new_volume == "min")
volume = 0
return TRUE
else if(new_volume == "max")
volume = 100
return TRUE
else if(text2num(new_volume) != null)
volume = text2num(new_volume)
return TRUE
/obj/machinery/jukebox/proc/activate_music()
active = TRUE
update_appearance(UPDATE_ICON)
START_PROCESSING(SSobj, src)
var/sound/song_played = sound(selection.song_path)
var/list/close = range(10,src)
for(var/mob/L in GLOB.player_list)
if(!L || !L.client)
continue
// it doesn't send at 0 volume so you get 0.001 volume on init
L.playsound_local(get_turf(L), null, 0.001, channel = CHANNEL_JUKEBOX, S = song_played)
if(L in close && L.client.prefs.toggles & SOUND_JUKEBOX)
L.set_sound_channel_volume(CHANNEL_JUKEBOX, volume) // TURN THAT SHIT UP!!!!
else
L.set_sound_channel_volume(CHANNEL_JUKEBOX, 0)
stop = world.time + selection.song_length
/obj/machinery/jukebox/disco/activate_music()
..()
dance_setup()
lights_spin()
/obj/machinery/jukebox/disco/proc/dance_setup()
var/turf/cen = get_turf(src)
var/turf/t
FOR_DVIEW(t, 3, get_turf(src),INVISIBILITY_LIGHTING)
if(t.x == cen.x && t.y > cen.y)
spotlights += new /obj/item/flashlight/spotlight(t, 1 + get_dist(src, t), 30 - (get_dist(src, t) * 8), LIGHT_COLOR_RED)
continue
if(t.x == cen.x && t.y < cen.y)
spotlights += new /obj/item/flashlight/spotlight(t, 1 + get_dist(src, t), 30 - (get_dist(src, t) * 8), LIGHT_COLOR_PURPLE)
continue
if(t.x > cen.x && t.y == cen.y)
spotlights += new /obj/item/flashlight/spotlight(t, 1 + get_dist(src, t), 30 - (get_dist(src, t) * 8), LIGHT_COLOR_YELLOW)
continue
if(t.x < cen.x && t.y == cen.y)
spotlights += new /obj/item/flashlight/spotlight(t, 1 + get_dist(src, t), 30 - (get_dist(src, t) * 8), LIGHT_COLOR_GREEN)
continue
if((t.x+1 == cen.x && t.y+1 == cen.y) || (t.x+2==cen.x && t.y+2 == cen.y))
spotlights += new /obj/item/flashlight/spotlight(t, 1.4 + get_dist(src, t), 30 - (get_dist(src, t) * 8), LIGHT_COLOR_ORANGE)
continue
if((t.x-1 == cen.x && t.y-1 == cen.y) || (t.x-2==cen.x && t.y-2 == cen.y))
spotlights += new /obj/item/flashlight/spotlight(t, 1.4 + get_dist(src, t), 30 - (get_dist(src, t) * 8), LIGHT_COLOR_CYAN)
continue
if((t.x-1 == cen.x && t.y+1 == cen.y) || (t.x-2==cen.x && t.y+2 == cen.y))
spotlights += new /obj/item/flashlight/spotlight(t, 1.4 + get_dist(src, t), 30 - (get_dist(src, t) * 8), LIGHT_COLOR_BLUEGREEN)
continue
if((t.x+1 == cen.x && t.y-1 == cen.y) || (t.x+2==cen.x && t.y-2 == cen.y))
spotlights += new /obj/item/flashlight/spotlight(t, 1.4 + get_dist(src, t), 30 - (get_dist(src, t) * 8), LIGHT_COLOR_BLUE)
continue
continue
FOR_DVIEW_END
/obj/machinery/jukebox/disco/proc/hierofunk()
for(var/i in 1 to 10)
spawn_atom_to_turf(/obj/effect/temp_visual/hierophant/telegraph/edge, src, 1, FALSE)
sleep(0.5 SECONDS)
#define DISCO_INFENO_RANGE (rand(85, 115)*0.01)
/obj/machinery/jukebox/disco/proc/lights_spin()
for(var/i in 1 to 25)
if(QDELETED(src) || !active)
return
var/obj/effect/overlay/sparkles/S = new /obj/effect/overlay/sparkles(src)
S.alpha = 0
sparkles += S
switch(i)
if(1 to 8)
S.orbit(src, 30, TRUE, 60, 36, TRUE)
if(9 to 16)
S.orbit(src, 62, TRUE, 60, 36, TRUE)
if(17 to 24)
S.orbit(src, 95, TRUE, 60, 36, TRUE)
if(25)
S.pixel_y = 7
S.forceMove(get_turf(src))
sleep(0.7 SECONDS)
if(selection.song_name == "Engineering's Ultimate High-Energy Hustle")
sleep(28 SECONDS)
for(var/s in sparkles)
var/obj/effect/overlay/sparkles/reveal = s
reveal.alpha = 255
while(active)
for(var/g in spotlights) // The multiples reflects custom adjustments to each colors after dozens of tests
var/obj/item/flashlight/spotlight/glow = g
if(QDELETED(glow))
stack_trace("[glow?.gc_destroyed ? "Qdeleting glow" : "null entry"] found in [src].[gc_destroyed ? " Source qdeleting at the time." : ""]")
return
switch(glow.light_color)
if(LIGHT_COLOR_RED)
if(glow.even_cycle)
glow.set_light_on(FALSE)
glow.set_light_color(LIGHT_COLOR_BLUE)
else
glow.set_light_range_power_color(glow.base_light_range * DISCO_INFENO_RANGE, glow.light_power * 1.48, LIGHT_COLOR_BLUE)
glow.set_light_on(TRUE)
if(LIGHT_COLOR_BLUE)
if(glow.even_cycle)
glow.set_light_range_power_color(glow.base_light_range * DISCO_INFENO_RANGE, glow.light_power * 2, LIGHT_COLOR_GREEN)
glow.set_light_on(TRUE)
else
glow.set_light_on(FALSE)
glow.set_light_color(LIGHT_COLOR_GREEN)
if(LIGHT_COLOR_GREEN)
if(glow.even_cycle)
glow.set_light_on(FALSE)
glow.set_light_color(LIGHT_COLOR_ORANGE)
else
glow.set_light_range_power_color(glow.base_light_range * DISCO_INFENO_RANGE, glow.light_power * 0.5, LIGHT_COLOR_ORANGE)
glow.set_light_on(TRUE)
if(LIGHT_COLOR_ORANGE)
if(glow.even_cycle)
glow.set_light_range_power_color(glow.base_light_range * DISCO_INFENO_RANGE, glow.light_power * 2.27, LIGHT_COLOR_PURPLE)
glow.set_light_on(TRUE)
else
glow.set_light_on(FALSE)
glow.set_light_color(LIGHT_COLOR_PURPLE)
if(LIGHT_COLOR_PURPLE)
if(glow.even_cycle)
glow.set_light_on(FALSE)
glow.set_light_color(LIGHT_COLOR_BLUEGREEN)
else
glow.set_light_range_power_color(glow.base_light_range * DISCO_INFENO_RANGE, glow.light_power * 0.44, LIGHT_COLOR_BLUEGREEN)
glow.set_light_on(TRUE)
if(LIGHT_COLOR_BLUEGREEN)
if(glow.even_cycle)
glow.set_light_range(glow.base_light_range * DISCO_INFENO_RANGE)
glow.set_light_color(LIGHT_COLOR_YELLOW)
glow.set_light_on(TRUE)
else
glow.set_light_on(FALSE)
glow.set_light_color(LIGHT_COLOR_YELLOW)
if(LIGHT_COLOR_YELLOW)
if(glow.even_cycle)
glow.set_light_on(FALSE)
glow.set_light_color(LIGHT_COLOR_CYAN)
else
glow.set_light_range(glow.base_light_range * DISCO_INFENO_RANGE)
glow.set_light_color(LIGHT_COLOR_CYAN)
glow.set_light_on(TRUE)
if(LIGHT_COLOR_CYAN)
if(glow.even_cycle)
glow.set_light_range_power_color(glow.base_light_range * DISCO_INFENO_RANGE, glow.light_power * 0.68, LIGHT_COLOR_RED)
glow.set_light_on(TRUE)
else
glow.set_light_on(FALSE)
glow.set_light_color(LIGHT_COLOR_RED)
glow.even_cycle = !glow.even_cycle
if(prob(2)) // Unique effects for the dance floor that show up randomly to mix things up
INVOKE_ASYNC(src, PROC_REF(hierofunk))
sleep(selection.song_beat)
if(QDELETED(src))
return
#undef DISCO_INFENO_RANGE
/obj/machinery/jukebox/disco/proc/dance(mob/living/M) //Show your moves
set waitfor = FALSE
switch(rand(0,6))
if(0 to 1)
dance2(M)
if(2 to 3)
dance3(M)
if(4 to 6)
dance4(M)
/obj/machinery/jukebox/disco/proc/dance2(mob/living/M)
for(var/i in 0 to 9)
dance_rotate(M, CALLBACK(M, TYPE_PROC_REF(/mob, dance_flip)))
sleep(2 SECONDS)
/mob/proc/dance_flip()
if(dir == WEST)
emote("flip")
/obj/machinery/jukebox/disco/proc/dance3(mob/living/M)
var/matrix/initial_matrix = matrix(M.transform)
for (var/i in 1 to 75)
if (!M)
return
switch(i)
if (1 to 15)
initial_matrix = matrix(M.transform)
initial_matrix.Translate(0,1)
animate(M, transform = initial_matrix, time = 0.1 SECONDS, loop = 0)
if (16 to 30)
initial_matrix = matrix(M.transform)
initial_matrix.Translate(1,-1)
animate(M, transform = initial_matrix, time = 0.1 SECONDS, loop = 0)
if (31 to 45)
initial_matrix = matrix(M.transform)
initial_matrix.Translate(-1,-1)
animate(M, transform = initial_matrix, time = 0.1 SECONDS, loop = 0)
if (46 to 60)
initial_matrix = matrix(M.transform)
initial_matrix.Translate(-1,1)
animate(M, transform = initial_matrix, time = 0.1 SECONDS, loop = 0)
if (61 to 75)
initial_matrix = matrix(M.transform)
initial_matrix.Translate(1,0)
animate(M, transform = initial_matrix, time = 0.1 SECONDS, loop = 0)
M.setDir(turn(M.dir, 90))
switch (M.dir)
if (NORTH)
initial_matrix = matrix(M.transform)
initial_matrix.Translate(0,3)
animate(M, transform = initial_matrix, time = 0.1 SECONDS, loop = 0)
if (SOUTH)
initial_matrix = matrix(M.transform)
initial_matrix.Translate(0,-3)
animate(M, transform = initial_matrix, time = 0.1 SECONDS, loop = 0)
if (EAST)
initial_matrix = matrix(M.transform)
initial_matrix.Translate(3,0)
animate(M, transform = initial_matrix, time = 0.1 SECONDS, loop = 0)
if (WEST)
initial_matrix = matrix(M.transform)
initial_matrix.Translate(-3,0)
animate(M, transform = initial_matrix, time = 0.1 SECONDS, loop = 0)
sleep(0.1 SECONDS)
M.lying_fix()
/obj/machinery/jukebox/disco/proc/dance4(mob/living/M)
animate(M, transform = matrix(180, MATRIX_ROTATE), time = 0.1 SECONDS, loop = 0)
var/matrix/initial_matrix = matrix(M.transform)
for (var/i in 1 to 60)
if (!M)
return
if (i<31)
initial_matrix = matrix(M.transform)
initial_matrix.Translate(0,1)
animate(M, transform = initial_matrix, time = 0.1 SECONDS, loop = 0)
if (i>30)
initial_matrix = matrix(M.transform)
initial_matrix.Translate(0,-1)
animate(M, transform = initial_matrix, time = 0.1 SECONDS, loop = 0)
M.setDir(turn(M.dir, 90))
switch (M.dir)
if (NORTH)
initial_matrix = matrix(M.transform)
initial_matrix.Translate(0,3)
animate(M, transform = initial_matrix, time = 0.1 SECONDS, loop = 0)
if (SOUTH)
initial_matrix = matrix(M.transform)
initial_matrix.Translate(0,-3)
animate(M, transform = initial_matrix, time = 0.1 SECONDS, loop = 0)
if (EAST)
initial_matrix = matrix(M.transform)
initial_matrix.Translate(3,0)
animate(M, transform = initial_matrix, time = 0.1 SECONDS, loop = 0)
if (WEST)
initial_matrix = matrix(M.transform)
initial_matrix.Translate(-3,0)
animate(M, transform = initial_matrix, time = 0.1 SECONDS, loop = 0)
sleep(0.1 SECONDS)
M.lying_fix()
/mob/living/proc/lying_fix()
animate(src, transform = null, time = 0.1 SECONDS, loop = 0)
lying_prev = 0
/obj/machinery/jukebox/proc/dance_over()
for(var/mob/L in GLOB.player_list)
if(!L || !L.client)
continue
L.stop_sound_channel(CHANNEL_JUKEBOX)
rangers = list()
/obj/machinery/jukebox/disco/dance_over()
..()
QDEL_LIST(spotlights)
QDEL_LIST(sparkles)
/obj/machinery/jukebox/process()
if(world.time < stop && active)
for(var/mob/M in range(10,src))
if(!M.client || !(M.client.prefs.toggles & SOUND_JUKEBOX))
continue
if(!(M in rangers))
rangers[M] = TRUE
M.set_sound_channel_volume(CHANNEL_JUKEBOX, volume) // We want volume updated without having to walk away!!
for(var/mob/L in rangers)
if(get_dist(src,L) > 10)
rangers -= L
if(!L || !L.client)
continue
L.set_sound_channel_volume(CHANNEL_JUKEBOX, 0)
else if(active)
active = FALSE
STOP_PROCESSING(SSobj, src)
dance_over()
playsound(src,'sound/machines/terminal_off.ogg',50,TRUE)
update_appearance(UPDATE_ICON)
stop = world.time + 100
/obj/machinery/jukebox/disco/process()
. = ..()
if(active)
for(var/mob/living/M in rangers)
if(prob(5+(allowed(M)*4)) && (M.mobility_flags & MOBILITY_MOVE))
dance(M)