This repository has been archived by the owner on Jan 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
turntable.dm
375 lines (332 loc) · 8.98 KB
/
turntable.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
#define TURNTABLE_CHANNEL 10
/*
/mob/var/datum/hear_music/hear_music
#define NONE_MUSIC 0
#define UPLOADING 1
#define PLAYING 2
/datum/hear_music
var/mob/target = null
//var/sound/sound
var/status = NONE_MUSIC
var/stop = 0
proc/play(sound/S)
status = NONE_MUSIC
if(!target)
return
if(!S)
return
status = UPLOADING
target << browse_rsc(S)
//sound = S
if(target.hear_music != src)
qdel(src)
if(!stop)
target << S
status = PLAYING
else
qdel(src)
proc/stop()
if(!target)
return
if(status == PLAYING)
var/sound/S = sound(null)
S.channel = 10
S.wait = 1
target << S
qdel(src)
else if(status == UPLOADING)
stop = 1
target.hear_music = null
*/
/mob/var/sound/music
/datum/turntable_soundtrack
var/f_name
var/name
var/path
/obj/machinery/party/turntable
name = "Jukebox"
desc = "A jukebox is a partially automated music-playing device, usually a coin-operated machine, that will play a patron's selection from self-contained media."
icon = 'icons/effects/lasers2.dmi'
icon_state = "Jukebox7"
var/obj/item/weapon/disk/music/disk
var/playing = 0
var/datum/turntable_soundtrack/track = null
var/volume = 100
var/list/turntable_soundtracks = list()
anchored = 1
density = 1
/obj/machinery/party/turntable/New()
..()
for(var/obj/machinery/party/turntable/TT) // NO WAY
if(TT != src)
qdel(src)
turntable_soundtracks = list()
for(var/i in typesof(/datum/turntable_soundtrack) - /datum/turntable_soundtrack)
var/datum/turntable_soundtrack/D = new i()
if(D.path)
turntable_soundtracks.Add(D)
/obj/machinery/party/turntable/attackby(obj/O, mob/user)
if(istype(O, /obj/item/weapon/disk/music) && !disk)
user.drop_item()
O.loc = src
disk = O
attack_hand(user)
/obj/machinery/party/turntable/attack_paw(user as mob)
return src.attack_hand(user)
/obj/machinery/party/turntable/attack_hand(mob/living/user as mob)
if (..())
return
usr.set_machine(src)
src.add_fingerprint(usr)
var/t = "<body background='turntable_back.jpg'><br><br><br><div align='center'><table border='0'><B><font color='maroon' size='6'>J</font><font size='5' color='purple'>uke Box</font> <font size='5' color='green'>Interface</font></B><br><br><br><br>"
t += "<A href='?src=\ref[src];on=1'>On</A><br>"
if(disk)
t += "<A href='?src=\ref[src];eject=1'>Eject disk</A><br>"
t += "<tr><td height='50' weight='50'></td><td height='50' weight='50'><A href='?src=\ref[src];off=1'><font color='maroon'>T</font><font color='lightgreen'>urn</font> <font color='red'>Off</font></A></td><td height='50' weight='50'></td></tr>"
t += "<tr>"
var/lastcolor = "green"
for(var/i = 10; i <= 100; i += 10)
t += "<A href='?src=\ref[src];set_volume=[i]'><font color='[lastcolor]'>[i]</font></A> "
if(lastcolor == "green")
lastcolor = "purple"
else
lastcolor = "green"
var/i = 0
for(var/datum/turntable_soundtrack/D in turntable_soundtracks)
t += "<td height='50' weight='50'><A href='?src=\ref[src];on=\ref[D]'><font color='maroon'>[D.f_name]</font><font color='[lastcolor]'>[D.name]</font></A></td>"
i++
if(i == 1)
lastcolor = pick("lightgreen", "purple")
else
lastcolor = pick("green", "purple")
if(i == 3)
i = 0
t += "</tr><tr>"
if(disk)
if(disk.data)
t += "<td height='50' weight='50'><A href='?src=\ref[src];on=\ref[disk.data]'><font color='maroon'>[disk.data.f_name]</font><font color='[lastcolor]'>[disk.data.name]</font></A></td>"
else
t += "<td height='50' weight='50'><font color='maroon'>D</font><font color='[lastcolor]'>isk empty</font></td>"
t += "</table></div></body>"
user << browse(t, "window=turntable;size=450x700;can_resize=0")
onclose(user, "turntable")
return
/obj/machinery/party/turntable/power_change()
turn_off()
/obj/machinery/party/turntable/Topic(href, href_list)
if(..())
return
if(href_list["on"])
turn_on(locate(href_list["on"]))
else if(href_list["off"])
turn_off()
else if(href_list["set_volume"])
set_volume(text2num(href_list["set_volume"]))
else if(href_list["eject"])
if(disk)
disk.loc = src.loc
if(disk.data && track == disk.data)
turn_off()
track = null
disk = null
/obj/machinery/party/turntable/process()
if(playing)
update_sound()
/obj/machinery/party/turntable/proc/turn_on(var/datum/turntable_soundtrack/selected)
if(playing)
turn_off()
if(selected)
track = selected
if(!track)
return
for(var/mob/M)
create_sound(M)
update_sound()
var/area/A = get_area(src)
for(var/area/RA in A.related)
for(var/obj/machinery/party/lasermachine/L in RA)
L.turnon(L.dir)
playing = 1
process()
/obj/machinery/party/turntable/proc/turn_off()
if(!playing)
return
for(var/mob/M)
M.music = null
M << sound(null, channel = TURNTABLE_CHANNEL, wait = 0)
playing = 0
var/area/A = get_area(src)
for(var/area/RA in A.related)
for(var/obj/machinery/party/lasermachine/L in RA)
L.turnoff()
/obj/machinery/party/turntable/proc/set_volume(var/new_volume)
volume = max(0, min(100, new_volume))
if(playing)
update_sound(1)
/obj/machinery/party/turntable/proc/update_sound(update = 0)
var/area/A = get_area(src)
for(var/mob/M)
var/inRange = (get_area(M) in A.related)
if(A == "Bar") // kostuli kostulnie
var/area/crew_quarters/theatre/T
var/area/crew_quarters/kitchen/K
inRange+=(get_area(M) in K.related)
inRange+=(get_area(M) in T.related)
if(!M.music)
create_sound(M)
continue
if(inRange && (M.music.volume != volume || update))
//world << "In range. Volume: [M.music.volume]. Update: [update]"
M.music.status = SOUND_UPDATE//|SOUND_STREAM
M.music.volume = volume
M << M.music
else if(!inRange && M.music.volume != 0)
//world << "!In range. Volume: [M.music.volume]."
M.music.status = SOUND_UPDATE//|SOUND_STREAM
M.music.volume = 0
M << M.music
/obj/machinery/party/turntable/proc/create_sound(mob/M)
//var/area/A = get_area(src)
//var/inRange = (get_area(M) in A.related)
var/sound/S = sound(track.path)
S.repeat = 1
S.channel = TURNTABLE_CHANNEL
S.falloff = 2
S.wait = 0
S.volume = 0
S.status = 0 //SOUND_STREAM
M.music = S
M << S
/obj/machinery/party/mixer
name = "mixer"
desc = "A mixing board for mixing music"
icon = 'icons/effects/lasers2.dmi'
icon_state = "mixer"
density = 0
anchored = 1
/obj/machinery/party/lasermachine
name = "laser machine"
desc = "A laser machine that shoots lasers."
icon = 'icons/effects/lasers2.dmi'
icon_state = "lasermachine"
dir = 4
anchored = 1
var/mirrored = 0
/obj/effect/laser2
name = "laser"
desc = "A laser..."
icon = 'icons/effects/lasers2.dmi'
icon_state = "laserred1"
anchored = 1
layer = 4
/obj/machinery/party/lasermachine/proc/turnon(laser_dir)
var/wall = 0
var/cycle = 1
var/area/A = get_area(src)
var/X = 1
var/Y = 0
if(mirrored == 0)
while(wall == 0)
if(cycle == 1)
var/obj/effect/laser2/F = new/obj/effect/laser2(src)
F.x = src.x+X
F.y = src.y+Y
F.z = src.z
F.dir = laser_dir
F.icon_state = "laserred1"
var/area/AA = get_area(F)
var/turf/T = get_turf(F)
if(T.density == 1 || AA.name != A.name)
qdel(F)
return
cycle++
if(cycle > 3)
cycle = 1
X++
if(cycle == 2)
var/obj/effect/laser2/F = new/obj/effect/laser2(src)
F.x = src.x+X
F.y = src.y+Y
F.z = src.z
F.dir = laser_dir
F.icon_state = "laserred2"
var/area/AA = get_area(F)
var/turf/T = get_turf(F)
if(T.density == 1 || AA.name != A.name)
qdel(F)
return
cycle++
if(cycle > 3)
cycle = 1
Y++
if(cycle == 3)
var/obj/effect/laser2/F = new/obj/effect/laser2(src)
F.x = src.x+X
F.y = src.y+Y
F.z = src.z
F.dir = laser_dir
F.icon_state = "laserred3"
var/area/AA = get_area(F)
var/turf/T = get_turf(F)
if(T.density == 1 || AA.name != A.name)
qdel(F)
return
cycle++
if(cycle > 3)
cycle = 1
X++
if(mirrored == 1)
while(wall == 0)
if(cycle == 1)
var/obj/effect/laser2/F = new/obj/effect/laser2(src)
F.x = src.x+X
F.y = src.y-Y
F.z = src.z
F.icon_state = "laserred1m"
var/area/AA = get_area(F)
var/turf/T = get_turf(F)
if(T.density == 1 || AA.name != A.name)
qdel(F)
return
cycle++
if(cycle > 3)
cycle = 1
Y++
if(cycle == 2)
var/obj/effect/laser2/F = new/obj/effect/laser2(src)
F.x = src.x+X
F.y = src.y-Y
F.z = src.z
F.icon_state = "laserred2m"
var/area/AA = get_area(F)
var/turf/T = get_turf(F)
if(T.density == 1 || AA.name != A.name)
qdel(F)
return
cycle++
if(cycle > 3)
cycle = 1
X++
if(cycle == 3)
var/obj/effect/laser2/F = new/obj/effect/laser2(src)
F.x = src.x+X
F.y = src.y-Y
F.z = src.z
F.icon_state = "laserred3m"
var/area/AA = get_area(F)
var/turf/T = get_turf(F)
if(T.density == 1 || AA.name != A.name)
qdel(F)
return
cycle++
if(cycle > 3)
cycle = 1
X++
/obj/machinery/party/lasermachine/proc/turnoff()
var/area/A = src.loc.loc
for(var/area/RA in A.related)
for(var/obj/effect/laser2/F in RA)
qdel(F)
/obj/machinery/party/lasermachine/Move()
..()
turnon(src.dir)