-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
vending.dm
2177 lines (1902 loc) · 93.2 KB
/
vending.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
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/datum/data/vending_product
var/product_name = "generic"
var/atom/product_path = null
var/product_cost
var/product_amount
var/product_hidden
var/logged_on_vend
var/static/list/product_name_cache = list(/obj/item/reagent_containers/mender/brute = "brute auto-mender", /obj/item/reagent_containers/mender/burn = "burn auto-mender")
New(productpath, amount=0, cost=0, hidden=0, logged_on_vend=FALSE)
..()
if (istext(productpath))
productpath = text2path(productpath)
if (!ispath(productpath))
qdel(src)
return
src.product_path = productpath
var/name_check = product_name_cache[productpath]
if (name_check)
src.product_name = name_check
else
//var/obj/temp = new src.product_path(src)
var/p_name = initial(product_path.name)
src.product_name = capitalize(p_name)
product_name_cache[productpath] = src.product_name
//qdel(temp)
src.product_amount = amount
src.product_cost = round(cost)
src.product_hidden = hidden
src.logged_on_vend = logged_on_vend
/obj/machinery/vending
name = "Vendomat"
desc = "A generic vending machine."
icon = 'icons/obj/vending.dmi'
icon_state = "generic"
anchored = 1
density = 1
mats = 20
layer = OBJ_LAYER - 0.1 // so items get spawned at 3, don't @ me
deconstruct_flags = DECON_SCREWDRIVER | DECON_WRENCH | DECON_MULTITOOL
object_flags = CAN_REPROGRAM_ACCESS
var/freestuff = 0
var/obj/item/card/id/scan = null
var/image/panel_image = null
var/active = 1 //No sales pitches if off!
var/vend_ready = 1 //Are we ready to vend?? Is it time??
var/vend_delay = 5 //How long does it take to vend?
//Keep track of lists
var/list/slogan_list = list()//new() //List of strings
var/list/product_list = new() //List of datum/data/vending_product
var/glitchy_slogans = 0 // do they come out aLL FunKY lIKe THIs?
//Replies when buying
var/vend_reply //Thank you for shopping!
var/last_reply = 0
//Slogans
var/last_slogan = 0 //When did we last pitch?
var/slogan_delay = 600 //How long until we can pitch again?
var/slogan_chance = 5
//Icons
var/icon_panel = "generic-panel"
var/icon_vend //Icon for vending
var/icon_deny //Icon when denying vend (wrong access)
var/icon_off // trying to cut down on some duplicated icons in vending.dmi so I'm adding more icon states wee
var/icon_broken // you only need to set these to something if you want these icons to be something other than "[initial(icon_state)]-off/-broken/-fallen"
var/icon_fallen // otherwise it'll just default to that behavior
var/emagged = 0 //Ignores if somebody doesn't have card access to that machine.
//Malfunctioning machine
var/seconds_electrified = 0 //Shock customers like an airlock.
var/shoot_inventory = 0 //Fire items at customers! We're broken!
var/shoot_inventory_chance = 5
var/ai_control_enabled = 1
var/extended_inventory = 0 //can we access the hidden inventory?
var/can_fall = 1 //Can this machine be knocked over?
var/panel_open = 0 //Hacking that vending machine. Gonna get a free candy bar.
var/wires = 15
// Paid vendor variables
var/pay = 0 // Does this vending machine require money?
var/acceptcard = 1 // does the machine accept ID swiping?
var/credit = 0 //How much money is currently in the machine?
var/profit = 0.90 // cogwerks: how much of a cut should the QMs get from the sale, expressed as a percent
var/HTML = null // guh
var/vending_HTML = null // buh
var/wire_HTML = null // duh
var/list/vendwires = list() // fuh
var/datum/data/vending_product/paying_for = null // zuh
var/datum/light/light
var/light_r =1
var/light_g = 1
var/light_b = 1
var/output_target = null
power_usage = 50
var/window_size = "400x475"
New()
src.create_products()
AddComponent(/datum/component/mechanics_holder)
SEND_SIGNAL(src,COMSIG_MECHCOMP_ADD_INPUT,"Vend Random", "vendinput")
SEND_SIGNAL(src,COMSIG_MECHCOMP_ADD_INPUT,"Vend by Name", "vendname")
light = new /datum/light/point
light.attach(src)
light.set_brightness(0.6)
light.set_height(1.5)
light.set_color(light_r, light_g, light_b)
..()
src.panel_image = image(src.icon, src.icon_panel)
var/lastvend = 0
proc/vendinput(var/datum/mechanicsMessage/inp)
if( world.time < lastvend ) return//aaaaaaa
lastvend = world.time + 2
var/datum/data/vending_product/R = throw_item()
if(R?.logged_on_vend)
logTheThing("station", usr, null, "randomly vended a logged product ([R.product_name]) using mechcomp from [src] at [log_loc(src)].")
proc/vendname(var/datum/mechanicsMessage/inp)
if( world.time < lastvend || !inp) return//aaaaaaa
if(!length(inp.signal)) return//aaaaaaa
lastvend = world.time + 5 //Make it slower to vend by name?
var/datum/data/vending_product/R = throw_item(inp.signal)
if(R?.logged_on_vend)
logTheThing("station", usr, null, "vended a logged product by name ([R.product_name]) using mechcomp from [src] at [log_loc(src)].")
// just making this proc so we don't have to override New() for every vending machine, which seems to lead to bad things
// because someone, somewhere, always forgets to use a ..()
proc/create_products()
return
MouseDrop(over_object, src_location, over_location)
if(!istype(usr,/mob/living/))
boutput(usr, "<span class='alert'>Only living mobs are able to set the output target for [src].</span>")
return
if(get_dist(over_object,src) > 1)
boutput(usr, "<span class='alert'>[src] is too far away from the target!</span>")
return
if(get_dist(over_object,usr) > 1)
boutput(usr, "<span class='alert'>You are too far away from the target!</span>")
return
if (istype(over_object,/obj/storage/crate/))
var/obj/storage/crate/C = over_object
if (C.locked || C.welded)
boutput(usr, "<span class='alert'>You can't use a currently unopenable crate as an output target.</span>")
else
src.output_target = over_object
boutput(usr, "<span class='notice'>You set [src] to output to [over_object]!</span>")
else if (istype(over_object,/obj/table/) || istype(over_object,/obj/rack/))
var/obj/O = over_object
src.output_target = O.loc
boutput(usr, "<span class='notice'>You set [src] to output on top of [O]!</span>")
else if (istype(over_object,/turf) && !over_object:density)
src.output_target = over_object
boutput(usr, "<span class='notice'>You set [src] to output to [over_object]!</span>")
else
boutput(usr, "<span class='alert'>You can't use that as an output target.</span>")
return
proc/get_output_location()
if (!src.output_target)
return src.loc
if (get_dist(src.output_target,src) > 1)
src.output_target = null
return src.loc
if (istype(src.output_target,/obj/storage/crate/))
var/obj/storage/crate/C = src.output_target
if (C.locked || C.welded)
src.output_target = null
return src.loc
else
if (C.open)
return C.loc
else
return C
else if (istype(src.output_target,/turf/simulated/floor/))
return src.output_target
else
return src.loc
#define WIRE_EXTEND 1
#define WIRE_SCANID 2
#define WIRE_SHOCK 3
#define WIRE_SHOOTINV 4
/obj/machinery/vending/ex_act(severity)
switch(severity)
if(1.0)
qdel(src)
return
if(2.0)
if (prob(50))
qdel(src)
return
if(3.0)
if (prob(25))
SPAWN_DBG(0)
src.malfunction()
return
return
else if (prob(25))
SPAWN_DBG(0)
src.fall()
return
else
return
/obj/machinery/vending/blob_act(var/power)
if (prob(power * 1.25))
SPAWN_DBG(0)
if (prob(power / 3) && can_fall == 2)
for (var/i = 0, i < rand(4,7), i++)
src.malfunction()
qdel(src)
if (prob(50) || can_fall == 2)
src.malfunction()
else
src.fall()
return
return
/obj/machinery/vending/emag_act(var/mob/user, var/obj/item/card/emag/E)
if (!src.emagged)
src.emagged = 1
if(user)
boutput(user, "You short out the product lock on [src]")
return 1
return 0
/obj/machinery/vending/demag(var/mob/user)
if (!src.emagged)
return 0
if (user)
user.show_text("You repair the product lock on [src].")
src.emagged = 0
return 1
/obj/machinery/vending/proc/scan_card(var/obj/item/card/id/card as obj, var/mob/user as mob)
if (!card || !user || !src.acceptcard)
return
boutput(user, "<span class='notice'>You swipe [card].</span>")
var/datum/data/record/account = null
account = FindBankAccountByName(card.registered)
if (account)
var/enterpin = input(user, "Please enter your PIN number.", "Enter PIN", 0) as null|num
if (enterpin == card.pin)
boutput(user, "<span class='notice'>Card authorized.</span>")
src.scan = card
else
boutput(user, "<span class='alert'>Pin number incorrect.</span>")
src.scan = null
else
boutput(user, "<span class='alert'>No bank account associated with this ID found.</span>")
src.scan = null
/obj/machinery/vending/proc/generate_HTML(var/update_vending = 0, var/update_wire = 0)
src.HTML = ""
if (!src.wire_HTML || update_wire)
src.generate_wire_HTML()
if (src.panel_open || isAI(usr))
src.HTML += src.wire_HTML
if (!src.vending_HTML || update_vending)
src.generate_vending_HTML()
src.HTML += src.vending_HTML
src.updateUsrDialog()
/obj/machinery/vending/proc/generate_vending_HTML()
var/list/html_parts = list()
html_parts += "<b>Welcome!</b><br>"
if (src.paying_for && (!istype(src.paying_for, /datum/data/vending_product) || !src.pay))
src.paying_for = null
if (src.pay && src.acceptcard)
if (src.paying_for && !src.scan)
html_parts += "<B>You have selected the following item:</b><br>"
html_parts += " <b>[src.paying_for.product_name]</b><br>"
html_parts += "Please swipe your card to authorize payment.<br>"
html_parts += "<B>Current ID:</B> None<BR>"
else if (src.scan)
if (src.paying_for)
html_parts += "<B>You have selected the following item for purchase:</b><br>"
html_parts += " [src.paying_for.product_name]<br>"
html_parts += "<B>Please swipe your card to authorize payment.</b><br>"
var/datum/data/record/account = null
account = FindBankAccountByName(src.scan.registered)
html_parts += "<B>Current ID:</B> <a href='byond://?src=\ref[src];logout=1'><u>([src.scan])</u></A><BR>"
html_parts += "<B>Credits on Account: [account.fields["current_money"]] Credits</B> <BR>"
else
html_parts += "<B>Current ID:</B> None<BR>"
if (src.product_list.len == 0)
html_parts += "<font color = 'red'>No product loaded!</font>"
else if (src.paying_for)
html_parts += "<a href='byond://?src=\ref[src];vend=\ref[src.paying_for]'><u><b>Continue</b></u></a>"
html_parts += " | <a href='byond://?src=\ref[src];cancel_payfor=1;logout=1'><u><b>Cancel</b></u></a>"
else
html_parts += "<table style='width: 100%; border: none; border-collapse: collapse;'><thead><tr><th>Product</th><th>Amt.</th><th>Price</th></tr></thead>"
for (var/datum/data/vending_product/R in src.product_list)
if (R.product_hidden && !src.extended_inventory)
continue
if (R.product_amount > 0)
html_parts += "<tr><td><a href='byond://?src=\ref[src];vend=\ref[R]'>[R.product_name]</a></td><td style='text-align: right;'>[R.product_amount]</td><td style='text-align: right;'> $[R.product_cost]</td></tr>"
else
html_parts += "<tr><td>[R.product_name]</a></td><td colspan='2' style='text-align: center;'><strong>SOLD OUT</strong></td></tr>"
html_parts += "</table>";
if (src.pay)
html_parts += "<BR><B>Available Credits:</B> $[src.credit] <a href='byond://?src=\ref[src];return_credits=1'>Return Credits</A>"
if (!src.acceptcard)
html_parts += "<BR>This machine only takes credit bills."
src.vending_HTML = jointext(html_parts, "")
/obj/machinery/vending/proc/generate_wire_HTML()
src.vendwires = list("Violet" = 1,\
"Orange" = 2,\
"Goldenrod" = 3,\
"Green" = 4)
var/list/html_parts = list()
html_parts = "<TT><B>The Access Panel is [src.panel_open ? "open" : "closed"]:</B><br>"
html_parts += "<table border=\"1\" style=\"width:100%\"><tbody><tr><td><small>"
for (var/wiredesc in vendwires)
var/is_uncut = src.wires & APCWireColorToFlag[vendwires[wiredesc]]
html_parts += "[wiredesc] wire: "
if (!is_uncut)
html_parts += "<a href='?src=\ref[src];cutwire=[vendwires[wiredesc]]'>Mend</a>"
else
html_parts += "<a href='?src=\ref[src];cutwire=[vendwires[wiredesc]]'>Cut</a> "
html_parts += "<a href='?src=\ref[src];pulsewire=[vendwires[wiredesc]]'>Pulse</a> "
html_parts += "<br>"
html_parts += "<br>"
html_parts += "The orange light is [(src.seconds_electrified == 0) ? "off" : "on"].<BR>"
html_parts += "The red light is [src.shoot_inventory ? "off" : "blinking"].<BR>"
html_parts += "The green light is [src.extended_inventory ? "on" : "off"].<BR>"
html_parts += "The [(src.wires & WIRE_SCANID) ? "purple" : "yellow"] light is on.<BR>"
html_parts += "The AI control indicator is [src.ai_control_enabled ? "lit" : "unlit"].<BR>"
html_parts += "</small></td></tr></tbody></table></TT><br>"
src.wire_HTML = jointext(html_parts, "")
/obj/machinery/vending/attackby(obj/item/W as obj, mob/user as mob)
if (istype(W, /obj/item/spacecash))
if (src.pay)
src.credit += W.amount
W.amount = 0
boutput(user, "<span class='notice'>You insert [W].</span>")
user.u_equip(W)
W.dropped()
pool( W )
src.generate_HTML(1)
return
else
boutput(user, "<span class='alert'>This machine does not accept cash.</span>")
return
if (istype(W, /obj/item/device/pda2) && W:ID_card)
W = W:ID_card
if (istype(W, /obj/item/card/id))
if (src.acceptcard)
src.scan_card(W, user)
src.generate_HTML(1)
return
/*var/amount = input(user, "How much money would you like to deposit?", "Deposit", 0) as null|num
if(amount <= 0)
return
if(amount > W:money)
boutput(user, "<span class='alert'>Insufficent funds. [W] only has [W:money] credits.</span>")
return
src.credit += amount
W:money -= amount
boutput(user, "<span class='notice'>You deposit [amount] credits. [W] now has [W:money] credits.</span>")
src.updateUsrDialog()
return()*/
else
boutput(user, "<span class='alert'>This machine does not accept ID cards.</span>")
return
else if (isscrewingtool(W))
src.panel_open = !src.panel_open
boutput(user, "You [src.panel_open ? "open" : "close"] the maintenance panel.")
src.UpdateOverlays(src.panel_open ? src.panel_image : null, "panel")
src.generate_HTML(0, 1)
return
else if (istype(W, /obj/item/device/t_scanner) || (istype(W, /obj/item/device/pda2) && istype(W:module, /obj/item/device/pda_module/tray)))
if (src.seconds_electrified != 0)
boutput(user, "<span class='alert'>[bicon(W)] <b>WARNING</b>: Abnormal electrical response received from access panel.</span>")
else
if (status & NOPOWER)
boutput(user, "<span class='alert'>[bicon(W)] No electrical response received from access panel.</span>")
else
boutput(user, "<span class='notice'>[bicon(W)] Regular electrical response received from access panel.</span>")
return
else if (ispulsingtool(W))
return src.attack_hand(user)
else if (ispryingtool(W))
if (src.status & BROKEN) //if the vendor is broken
//action bar is defined at the end of these procs
actions.start(new /datum/action/bar/icon/right_vendor(src), user)
return
if (istype(W, /obj/item/vending/restock_cartridge))
//check if cartridge type matches the vending machine
var/obj/item/vending/restock_cartridge/Q = W
if (istype(src, text2path("/obj/machinery/vending/[Q.vendingType]")))
// if (istype(src, text2path("/obj/machinery/vending/[W:vendingType]")))
//remove all producs, reinitialize array and then create the products like new
src.product_list = new()
src.create_products()
src.generate_HTML(1)
boutput(user, "<span class='notice'>You restocked the items in [src].</span>")
playsound(src.loc ,"sound/items/Deconstruct.ogg", 80, 0)
user.u_equip(W)
qdel(W)
return
else
boutput(user, "<span class='alert'>[W] is not compatible with [src].</span>")
else
user.lastattacked = src
hit_twitch(src)
attack_particle(user,src)
playsound(src,"sound/impact_sounds/Metal_Clang_2.ogg",50,1)
..()
if (W?.force >= 5 && prob(4 + (W.force - 5)))
src.fall(user)
/obj/machinery/vending/hitby(atom/movable/M, datum/thrown_thing/thr)
if (iscarbon(M) && M.throwing && prob(25))
src.fall(M)
return
..()
/obj/machinery/vending/attack_ai(mob/user as mob)
return attack_hand(user)
/obj/machinery/vending/attack_hand(mob/user as mob)
if (status & (BROKEN|NOPOWER))
return
src.add_dialog(user)
if (src.seconds_electrified != 0)
if (src.shock(user, 100))
return
if (!src.HTML)
src.generate_HTML()
else
if (src.HTML && !src.vending_HTML)
src.generate_HTML(1)
if (src.HTML && (src.panel_open || isAI(user)) && !src.wire_HTML)
src.generate_HTML(0, 1)
if (window_size)
user.Browse(src.HTML, "window=vending;size=[window_size]")
else
user.Browse(src.HTML, "window=vending")
onclose(user, "vending")
interact_particle(user,src)
return
/obj/machinery/vending/Topic(href, href_list)
if (status & (BROKEN|NOPOWER))
return
if (usr.stat || usr.restrained())
return
//ehh just let the AI operate vending machines. why not!!
if (isAI(usr) && !src.ai_control_enabled)
boutput(usr, "<span class='alert'>AI control for this vending machine has been disconnected!</span>")
return
if ((usr.contents.Find(src) || (in_interact_range(src, usr) && istype(src.loc, /turf))))
src.add_dialog(usr)
src.add_fingerprint(usr)
if ((href_list["vend"]) && (src.vend_ready))
if ((!src.allowed(usr)) && (!src.emagged) && (src.wires & WIRE_SCANID)) //For SECURE VENDING MACHINES YEAH
boutput(usr, "<span class='alert'>Access denied.</span>") //Unless emagged of course
flick(src.icon_deny,src)
return
src.vend_ready = 0 //One thing at a time!!
var/datum/data/vending_product/R = locate(href_list["vend"]) in src.product_list
if (!R || !istype(R))
src.vend_ready = 1
return
else if(R.product_hidden && !src.extended_inventory)
src.vend_ready = 1
return
var/product_path = R.product_path
if (istext(product_path))
product_path = text2path(product_path)
if (!product_path)
src.vend_ready = 1
return
if (R.product_amount <= 0)
src.vend_ready = 1
return
//Wire: Fix for href exploit allowing for vending of arbitrary items
if (!(R in src.product_list))
src.vend_ready = 1
trigger_anti_cheat(usr, "tried to href exploit [src] to spawn an invalid item.")
return
var/datum/data/record/account = null
if (src.pay)
if (src.acceptcard && src.scan)
account = FindBankAccountByName(src.scan.registered)
if (!account)
boutput(usr, "<span class='alert'>No bank account associated with ID found.</span>")
flick(src.icon_deny,src)
src.vend_ready = 1
src.paying_for = R
src.generate_HTML(1)
return
if (account.fields["current_money"] < R.product_cost)
boutput(usr, "<span class='alert'>Insufficient funds in account. To use machine credit, log out.</span>")
flick(src.icon_deny,src)
src.vend_ready = 1
src.paying_for = R
src.generate_HTML(1)
return
else
if (src.credit < R.product_cost)
boutput(usr, "<span class='alert'>Insufficient Credit.</span>")
flick(src.icon_deny,src)
src.vend_ready = 1
src.paying_for = R
src.generate_HTML(1)
return
if (((src.last_reply + (src.vend_delay + 200)) <= world.time) && src.vend_reply)
SPAWN_DBG(0)
src.speak(src.vend_reply)
src.last_reply = world.time
use_power(10)
if (src.icon_vend) //Show the vending animation if needed
flick(src.icon_vend,src)
src.prevend_effect()
if(!src.freestuff) R.product_amount--
if (src.pay)
if (src.acceptcard && account)
account.fields["current_money"] -= R.product_cost
else
src.credit -= R.product_cost
wagesystem.shipping_budget += round(R.product_cost * profit) // cogwerks - maybe money shouldn't just vanish into the aether idk
SPAWN_DBG(src.vend_delay)
src.vend_ready = 1 // doin this at the top here just in case something goes fucky and the proc crashes
if (ispath(product_path))
var/atom/movable/vended = new product_path(src.get_output_location()) // changed from obj, because it could be a mob, THANKS VALUCHIMP
vended.layer = src.layer + 0.1 //So things stop spawning under the fukin thing
if(isitem(vended))
usr.put_in_hand_or_eject(vended) // try to eject it into the users hand, if we can
// else, just let it spawn where it is
else if (isicon(R.product_path))
var/icon/welp = icon(R.product_path)
if (welp.Width() > 32 || welp.Height() > 32)
welp.Scale(32, 32)
R.product_path = welp // if scaling is required reset the product_path so it only happens the first time
var/obj/dummy = new /obj/item(src.get_output_location())
dummy.name = R.product_name
dummy.desc = "?!"
dummy.icon = welp
else if (isfile(R.product_path))
var/S = sound(R.product_path)
if (S)
playsound(src.loc, S, 50, 0)
src.postvend_effect()
SEND_SIGNAL(src,COMSIG_MECHCOMP_TRANSMIT_SIGNAL, "productDispensed=[R.product_name]")
if (src.paying_for)
src.paying_for = null
src.scan = null
src.generate_HTML(1)
if(R.logged_on_vend)
logTheThing("station", usr, null, "vended a logged product ([R.product_name]) from [src] at [log_loc(src)].")
if (href_list["logout"])
src.scan = null
src.generate_HTML(1)
if (href_list["cancel_payfor"])
src.paying_for = null
src.generate_HTML(1)
if (href_list["return_credits"])
SPAWN_DBG(src.vend_delay)
if (src.credit > 0)
var/obj/item/spacecash/returned = unpool(/obj/item/spacecash)
returned.setup(src.get_output_location(), src.credit)
usr.put_in_hand_or_eject(returned) // try to eject it into the users hand, if we can
src.credit = 0
boutput(usr, "<span class='notice'>You receive [returned].</span>")
src.generate_HTML(1)
if ((href_list["cutwire"]) && (src.panel_open))
var/twire = text2num(href_list["cutwire"])
if (!usr.find_tool_in_hand(TOOL_SNIPPING))
boutput(usr, "You need a snipping tool!")
return
else if (src.isWireColorCut(twire))
src.mend(twire)
else
src.cut(twire)
if ((href_list["pulsewire"]) && (src.panel_open || isAI(usr)))
var/twire = text2num(href_list["pulsewire"])
if (! (usr.find_tool_in_hand(TOOL_PULSING) || isAI(usr)) )
boutput(usr, "You need a multitool or similar!")
return
else if (src.isWireColorCut(twire))
boutput(usr, "You can't pulse a cut wire.")
return
else
src.pulse(twire)
else
usr.Browse(null, "window=vending")
return
return
/obj/machinery/vending/process()
if (status & BROKEN)
return
..()
if (status & NOPOWER)
return
if (!src.active)
return
if (src.seconds_electrified > 0)
src.seconds_electrified--
//Pitch to the people! Really sell it!
if (prob(src.slogan_chance) && ((src.last_slogan + src.slogan_delay) <= world.time) && (src.slogan_list.len > 0))
var/slogan = pick(src.slogan_list)
src.speak(slogan)
src.last_slogan = world.time
if ((prob(shoot_inventory_chance)) && (src.shoot_inventory))
src.throw_item()
return
/obj/machinery/vending/proc/speak(var/message)
if (status & NOPOWER)
return
if (!message)
return
for (var/mob/O in hearers(src, null))
if (src.glitchy_slogans)
O.show_message("<span class='game say'><span class='name'>[src]</span> beeps,</span> \"[voidSpeak(message)]\"", 2)
else
O.show_message("<span class='subtle'><span class='game say'><span class='name'>[src]</span> beeps, \"[message]\"</span></span>", 2)
return
/obj/machinery/vending/proc/prevend_effect()
playsound(src.loc, 'sound/machines/driveclick.ogg', 30, 1, 0.1)
return
/obj/machinery/vending/proc/postvend_effect()
playsound(src.loc, 'sound/machines/ping.ogg', 20, 1, 0.1)
return
/obj/machinery/vending/power_change()
if (can_fall == 2)
icon_state = icon_fallen ? icon_fallen : "[initial(icon_state)]-fallen"
light.disable()
return
if (status & BROKEN)
icon_state = icon_broken ? icon_broken : "[initial(icon_state)]-broken"
light.disable()
else
if ( powered() )
icon_state = initial(icon_state)
status &= ~NOPOWER
light.enable()
else
SPAWN_DBG(rand(0, 15))
src.icon_state = icon_off ? icon_off : "[initial(icon_state)]-off"
status |= NOPOWER
light.disable()
/obj/machinery/vending/proc/fall(mob/living/carbon/victim)
if (can_fall != 1)
return
can_fall = 2
status |= BROKEN
var/turf/vicTurf = get_turf(victim)
src.icon_state = "[initial(icon_state)]-fallen"
// SPAWN_DBG(0)
// src.icon_state = "[initial(icon_state)]-fall"
// SPAWN_DBG(2 SECONDS)
// src.icon_state = "[initial(icon_state)]-fallen"
if (istype(victim) && vicTurf && (get_dist(vicTurf, src) <= 1))
victim.changeStatus("weakened", 300)
src.visible_message("<b><font color=red>[src.name] tips over onto [victim]!</font></b>")
victim.lying = 1
victim.set_loc(vicTurf)
if (src.layer < victim.layer)
src.layer = victim.layer+1
src.set_loc(vicTurf)
random_brute_damage(victim, rand(30,50),1)
else
src.visible_message("<b><font color=red>[src.name] tips over!</font></b>")
src.power_change()
src.anchored = 0
return
//Oh no we're malfunctioning! Dump out some product and break.
/obj/machinery/vending/proc/malfunction()
for(var/datum/data/vending_product/R in src.product_list)
if (R.product_amount <= 0) //Try to use a record that actually has something to dump.
continue
var/dump_path = null
if (ispath(R.product_path))
dump_path = R.product_path
else if (istext(R.product_path))
dump_path = text2path(R.product_path)
if (isnull(dump_path))
continue
else
continue
while(R.product_amount>0)
new dump_path(src.loc)
R.product_amount--
break
status |= BROKEN
power_change()
return
//Somebody cut an important wire and now we're following a new definition of "pitch."
/obj/machinery/vending/proc/throw_item(var/item_name_to_throw = "")
var/mob/living/target = locate() in view(7,src)
if(!target)
return null
if(length(item_name_to_throw))
for(var/datum/data/vending_product/R in src.product_list)
if(item_name_to_throw == R.product_name_cache[R.product_path])
if(R.product_amount > 0)
throw_item_act(R, target)
return R
return
else
var/list/datum/data/vending_product/valid_products = list()
for(var/datum/data/vending_product/R in src.product_list)
if(R.product_amount <= 0) //Try to use a record that actually has something to dump.
continue
valid_products.Add(R)
if(length(valid_products))
var/datum/data/vending_product/vending_product = pick(valid_products)
throw_item_act(vending_product, target)
return vending_product
/obj/machinery/vending/proc/throw_item_act(var/datum/data/vending_product/R, var/mob/living/target)
var/obj/throw_item = null
//Big if/else trying to create the object properly
if (ispath(R.product_path))
var/dump_path = R.product_path
throw_item = new dump_path(src.loc)
else if (istext(R.product_path))
var/dump_path = text2path(R.product_path)
if (dump_path)
throw_item = new dump_path(src.loc)
else if (isicon(R.product_path))
var/icon/welp = icon(R.product_path)
if (welp.Width() > 32 || welp.Height() > 32)
welp.Scale(32, 32)
R.product_path = welp // if scaling is required reset the product_path so it only happens the first time
var/obj/dummy = new /obj/item(src.get_output_location())
dummy.name = R.product_name
dummy.desc = "?!"
dummy.icon = welp
throw_item = dummy
else if (isfile(R.product_path))
var/sound/S = sound(R.product_path)
if (S)
R.product_amount--
SPAWN_DBG(0)
playsound(src.loc, S, 50, 0)
src.visible_message("<span class='alert'><b>[src] launches [R.product_name] at [target.name]!</b></span>")
src.generate_HTML(1)
return 1
if (throw_item)
R.product_amount--
use_power(10)
if (src.icon_vend) //Show the vending animation if needed
flick(src.icon_vend,src)
SEND_SIGNAL(src,COMSIG_MECHCOMP_TRANSMIT_SIGNAL, "productDispensed=[R.product_name]")
src.generate_HTML(1)
throw_item.throw_at(target, 16, 3)
src.visible_message("<span class='alert'><b>[src] launches [throw_item.name] at [target.name]!</b></span>")
postvend_effect()
return 1
return 0
/obj/machinery/vending/proc/isWireColorCut(var/wireColor)
var/wireFlag = APCWireColorToFlag[wireColor]
return ((src.wires & wireFlag) == 0)
/obj/machinery/vending/proc/isWireCut(var/wireIndex)
var/wireFlag = APCIndexToFlag[wireIndex]
return ((src.wires & wireFlag) == 0)
/obj/machinery/vending/proc/cut(var/wireColor)
var/wireFlag = APCWireColorToFlag[wireColor]
var/wireIndex = APCWireColorToIndex[wireColor]
src.wires &= ~wireFlag
switch(wireIndex)
if(WIRE_EXTEND)
src.extended_inventory = 0
src.generate_HTML(1)
if(WIRE_SHOCK)
src.seconds_electrified = -1
if (WIRE_SHOOTINV)
if(!src.shoot_inventory)
src.shoot_inventory = 1
if (WIRE_SCANID) //yeah the scanID wire also controls the AI control FUCK YOU
if(src.ai_control_enabled)
src.ai_control_enabled = 0
src.generate_HTML(0, 1)
/obj/machinery/vending/proc/mend(var/wireColor)
var/wireFlag = APCWireColorToFlag[wireColor]
var/wireIndex = APCWireColorToIndex[wireColor] //not used in this function
src.wires |= wireFlag
switch(wireIndex)
if(WIRE_SCANID)
src.ai_control_enabled = 1
if(WIRE_SHOCK)
src.seconds_electrified = 0
if (WIRE_SHOOTINV)
src.shoot_inventory = 0
src.generate_HTML(0, 1)
/obj/machinery/vending/proc/pulse(var/wireColor)
var/wireIndex = APCWireColorToIndex[wireColor]
switch (wireIndex)
if (WIRE_EXTEND)
src.extended_inventory = !src.extended_inventory
src.generate_HTML(1)
if (WIRE_SCANID)
src.ai_control_enabled = !src.ai_control_enabled
if (WIRE_SHOCK)
src.seconds_electrified = 30
if (WIRE_SHOOTINV)
src.shoot_inventory = !src.shoot_inventory
src.generate_HTML(0, 1)
//"Borrowed" airlock shocking code.
/obj/machinery/vending/proc/shock(mob/user, prb)
if (!prob(prb))
return 0
if (status & (BROKEN|NOPOWER)) // unpowered, no shock
return 0
if (src.electrocute(user, 1))
return 1
else
return 0
/obj/machinery/vending/electrocute(mob/user, netnum)
if (!netnum) // unconnected cable is unpowered
return 0
var/datum/powernet/PN // find the powernet
if (powernets && powernets.len >= netnum)
PN = powernets[netnum]
elecflash(src)
if (!PN) //Wire note: Fix for Cannot read null.avail
return 0
if (user.shock(src, PN.avail, user.hand == 1 ? "l_arm" : "r_arm", 1, 0))
for (var/mob/M in AIviewers(src))
if (M == user) continue
M.show_message("<span class='alert'>[user.name] was shocked by the [src.name]!</span>", 3, "<span class='alert'>You hear a heavy electrical crack</span>", 2)
return 1
return 0
/datum/action/bar/icon/right_vendor //This is used when you try to remove someone elses handcuffs.
duration = 5 SECONDS
interrupt_flags = INTERRUPT_MOVE | INTERRUPT_ACT | INTERRUPT_STUNNED | INTERRUPT_ACTION
id = "right_vendor"
icon = 'icons/obj/items/tools/crowbar.dmi'
icon_state = "crowbar"
var/obj/machinery/vending/vendor = null
New(vending_machine, var/Owner)
src.vendor = vending_machine
src.owner = Owner
..()
onUpdate()
..()
if(!IN_RANGE(src.owner, src.vendor, 1) || src.vendor == null || src.owner == null)
interrupt(INTERRUPT_ALWAYS)
return
if(!(src.vendor.status & BROKEN)) //it somehow got fixed while making it go upright??
interrupt(INTERRUPT_ALWAYS)
return
onStart()
..()
if(!IN_RANGE(src.owner, src.vendor, 1) || src.vendor == null || src.owner == null)
interrupt(INTERRUPT_ALWAYS)
return
for(var/mob/M in AIviewers(src.owner))
M.show_message("<span class='notice'><B>[src.owner] starts trying to pry \the [src.vendor] back up...</B></span>", 1)
onEnd()
..()
if(src.owner && vendor && (src.vendor.status & BROKEN))
src.vendor.can_fall = 1
src.vendor.layer = initial(src.vendor.layer)
src.vendor.anchored = 1
src.vendor.status &= ~BROKEN
src.vendor.power_change()
for(var/mob/M in AIviewers(src.owner))
M.show_message("<span class='notice'><B>[src.owner] manages to stand \the [src.vendor] back upright!</B></span>", 1)
#undef WIRE_EXTEND
#undef WIRE_SCANID
#undef WIRE_SHOCK
#undef WIRE_SHOOTINV
/obj/machinery/vending/coffee
name = "coffee machine"