/
_vending.dm
1883 lines (1650 loc) · 68.9 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
/*
* Vending machine types - Can be found under /code/modules/vending/
*/
/*
/obj/machinery/vending/[vendors name here] // --vending machine template :)
name = ""
desc = ""
icon = ''
icon_state = ""
products = list()
contraband = list()
premium = list()
*/
/// List of vending machines that players can restock, so only vending machines that are on station or don't have a unique condition.
GLOBAL_LIST_EMPTY(vending_machines_to_restock)
/// Maximum amount of items in a storage bag that we're transferring items to the vendor from.
#define MAX_VENDING_INPUT_AMOUNT 30
#define CREDITS_DUMP_THRESHOLD 50
/**
* # vending record datum
*
* A datum that represents a product that is vendable
*/
/datum/data/vending_product
name = "generic"
///Typepath of the product that is created when this record "sells"
var/product_path = null
///How many of this product we currently have
var/amount = 0
///How many we can store at maximum
var/max_amount = 0
///Does the item have a custom price override
var/custom_price
///Does the item have a custom premium price override
var/custom_premium_price
///Whether spessmen with an ID with an age below AGE_MINOR (20 by default) can buy this item
var/age_restricted = FALSE
///Whether the product can be recolored by the GAGS system
var/colorable
/// The category the product was in, if any.
/// Sourced directly from product_categories.
var/category
///List of items that have been returned to the vending machine.
var/list/returned_products
/**
* # vending machines
*
* Captalism in the year 2525, everything in a vending machine, even love
*/
/obj/machinery/vending
name = "\improper Vendomat"
desc = "A generic vending machine."
icon = 'icons/obj/machines/vending.dmi'
icon_state = "generic"
layer = BELOW_OBJ_LAYER
density = TRUE
verb_say = "beeps"
verb_ask = "beeps"
verb_exclaim = "beeps"
max_integrity = 300
integrity_failure = 0.33
armor_type = /datum/armor/machinery_vending
circuit = /obj/item/circuitboard/machine/vendor
payment_department = ACCOUNT_SRV
light_power = 0.7
light_range = MINIMUM_USEFUL_LIGHT_RANGE
voice_filter = "alimiter=0.9,acompressor=threshold=0.2:ratio=20:attack=10:release=50:makeup=2,highpass=f=1000"
/// Is the machine active (No sales pitches if off)!
var/active = 1
///Are we ready to vend?? Is it time??
var/vend_ready = TRUE
///Next world time to send a purchase message
var/purchase_message_cooldown
///The ref of the last mob to shop with us
var/last_shopper
///Whether the vendor is tilted or not
var/tilted = FALSE
/// If tilted, this variable should always be the rotation that was applied when we were tilted. Stored for the purposes of unapplying it.
var/tilted_rotation = 0
///Whether this vendor can be tilted over or not
var/tiltable = TRUE
///Damage this vendor does when tilting onto an atom
var/squish_damage = 75
/// The chance, in percent, of this vendor performing a critical hit on anything it crushes via [tilt].
var/crit_chance = 15
/// If set to a critical define in crushing.dm, anything this vendor crushes will always be hit with that effect.
var/forcecrit = null
///Number of glass shards the vendor creates and tries to embed into an atom it tilted onto
var/num_shards = 7
///List of mobs stuck under the vendor
var/list/pinned_mobs = list()
///Icon for the maintenance panel overlay
var/panel_type = "panel1"
/**
* List of products this machine sells
*
* form should be list(/type/path = amount, /type/path2 = amount2)
*/
var/list/products = list()
/**
* List of products this machine sells, categorized.
* Can only be used as an alternative to `products`, not alongside it.
*
* Form should be list(
* "name" = "Category Name",
* "icon" = "UI Icon (Font Awesome or tgfont)",
* "products" = list(/type/path = amount, ...),
* )
*/
var/list/product_categories = null
/**
* List of products this machine sells when you hack it
*
* form should be list(/type/path = amount, /type/path2 = amount2)
*/
var/list/contraband = list()
/**
* List of premium products this machine sells
*
* form should be list(/type/path = amount, /type/path2 = amount2)
*/
var/list/premium = list()
///String of slogans separated by semicolons, optional
var/product_slogans = ""
///String of small ad messages in the vending screen - random chance
var/product_ads = ""
///List of standard product records
var/list/product_records = list()
///List of contraband product records
var/list/hidden_records = list()
///List of premium product records
var/list/coin_records = list()
///List of slogans to scream at potential customers; built upon Iniitialize() of the vendor from product_slogans
var/list/slogan_list = list()
///Message sent post vend (Thank you for shopping!)
var/vend_reply
///Last world tick we sent a vent reply
var/last_reply = 0
///Last world tick we sent a slogan message out
var/last_slogan = 0
///How many ticks until we can send another
var/slogan_delay = 10 MINUTES
///Icon when vending an item to the user
var/icon_vend
///Icon to flash when user is denied a vend
var/icon_deny
///World ticks the machine is electified for
var/seconds_electrified = MACHINE_NOT_ELECTRIFIED
///When this is TRUE, we fire items at customers! We're broken!
var/shoot_inventory = FALSE
///How likely this is to happen (prob 100) per second
var/shoot_inventory_chance = 1
//Stop spouting those godawful pitches!
var/shut_up = FALSE
///can we access the hidden inventory?
var/extended_inventory = FALSE
///Are we checking the users ID
var/scan_id = TRUE
///Coins that we accept?
var/obj/item/coin/coin
///Bills we accept?
var/obj/item/stack/spacecash/bill
///Default price of items if not overridden
var/default_price = 25
///Default price of premium items if not overridden
var/extra_price = 50
///fontawesome icon name to use in to display the user's balance in the vendor UI
var/displayed_currency_icon = "coins"
///String of the used currency to display in the vendor UI
var/displayed_currency_name = " cr"
///Whether our age check is currently functional
var/age_restrictions = TRUE
/// How many credits does this vending machine have? 20% of all sales go to this pool, and are given freely when the machine is restocked, or successfully tilted. Lost on deconstruction.
var/credits_contained = 0
/**
* Is this item on station or not
*
* if it doesn't originate from off-station during mapload, everything is free
* if it's off-station during mapload, it's also safe from the brand intelligence event
*/
var/onstation = TRUE
/**
* A variable to change on a per instance basis on the map that allows the instance
* to ignore whether it's on the station or not.
* Useful to force cost and ID requirements. DO NOT APPLY THIS GLOBALLY.
*/
var/onstation_override = FALSE
///Items that the players have loaded into the vendor
var/list/vending_machine_input = list()
//The type of refill canisters used by this machine.
var/obj/item/vending_refill/refill_canister = null
/// how many items have been inserted in a vendor
var/loaded_items = 0
///Name of lighting mask for the vending machine
var/light_mask
/// used for narcing on underages
var/obj/item/radio/sec_radio
/datum/armor/machinery_vending
melee = 20
fire = 50
acid = 70
/**
* Initialize the vending machine
*
* Builds the vending machine inventory, sets up slogans and other such misc work
*
* This also sets the onstation var to:
* * FALSE - if the machine was maploaded on a zlevel that doesn't pass the is_station_level check
* * TRUE - all other cases
*/
/obj/machinery/vending/Initialize(mapload)
var/build_inv = FALSE
if(!refill_canister)
circuit = null
build_inv = TRUE
. = ..()
set_wires(new /datum/wires/vending(src))
if(SStts.tts_enabled)
var/static/vendor_voice_by_type = list()
if(!vendor_voice_by_type[type])
vendor_voice_by_type[type] = pick(SStts.available_speakers)
voice = vendor_voice_by_type[type]
if(build_inv) //non-constructable vending machine
///Non-constructible vending machines do not have a refill canister to populate its products list from,
///Which apparently is still needed in the case we use product categories instead.
if(product_categories)
for(var/list/category as anything in product_categories)
products |= category["products"]
build_inventories()
slogan_list = splittext(product_slogans, ";")
// So not all machines speak at the exact same time.
// The first time this machine says something will be at slogantime + this random value,
// so if slogantime is 10 minutes, it will say it at somewhere between 10 and 20 minutes after the machine is crated.
last_slogan = world.time + rand(0, slogan_delay)
power_change()
if(mapload) //check if it was initially created off station during mapload.
if(!is_station_level(z))
if(!onstation_override)
onstation = FALSE
if(circuit)
circuit.onstation = onstation //sync up the circuit so the pricing schema is carried over if it's reconstructed.
else if(HAS_TRAIT(SSstation, STATION_TRAIT_VENDING_SHORTAGE))
for (var/datum/data/vending_product/product_record as anything in product_records + coin_records + hidden_records)
/**
* in average, it should be 37.5% of the max amount, rounded up to the nearest int,
* tho the max boundary can be as low/high as 50%/100%
*/
var/max_amount = rand(CEILING(product_record.amount * 0.5, 1), product_record.amount)
product_record.amount = rand(0, max_amount)
credits_contained += rand(0, 1) //randomly add a few credits to the machine to make it look like it's been used, proportional to the amount missing.
if(tiltable && prob(6)) // 1 in 17 chance to start tilted (as an additional hint to the station trait behind it)
INVOKE_ASYNC(src, PROC_REF(tilt), loc)
credits_contained = 0 // If it's tilted, it's been looted, so no credits for you.
else if(circuit && (circuit.onstation != onstation)) //check if they're not the same to minimize the amount of edited values.
onstation = circuit.onstation //if it was constructed outside mapload, sync the vendor up with the circuit's var so you can't bypass price requirements by moving / reconstructing it off station.
if(onstation && !onstation_override)
AddComponent(/datum/component/payment, 0, SSeconomy.get_dep_account(payment_department), PAYMENT_VENDING)
GLOB.vending_machines_to_restock += src //We need to keep track of the final onstation vending machines so we can keep them restocked.
register_context()
/obj/machinery/vending/Destroy()
QDEL_NULL(wires)
QDEL_NULL(coin)
QDEL_NULL(bill)
QDEL_NULL(sec_radio)
GLOB.vending_machines_to_restock -= src
return ..()
/obj/machinery/vending/can_speak(allow_mimes)
return is_operational && !shut_up && ..()
/obj/machinery/vending/emp_act(severity)
. = ..()
var/datum/language_holder/vending_languages = get_language_holder()
var/datum/wires/vending/vending_wires = wires
// if the language wire got pulsed during an EMP, this will make sure the language_iterator is synched correctly
vending_languages.selected_language = vending_languages.spoken_languages[vending_wires.language_iterator]
//Better would be to make constructable child
/obj/machinery/vending/RefreshParts()
SHOULD_CALL_PARENT(FALSE)
if(!component_parts)
return
build_products_from_categories()
product_records = list()
hidden_records = list()
coin_records = list()
build_inventories(start_empty = TRUE)
for(var/obj/item/vending_refill/installed_refill in component_parts)
restock(installed_refill)
/obj/machinery/vending/on_deconstruction(disassembled)
if(refill_canister)
return ..()
new /obj/item/stack/sheet/iron(loc, 3)
/obj/machinery/vending/update_appearance(updates=ALL)
. = ..()
if(machine_stat & BROKEN)
set_light(0)
return
set_light(powered() ? MINIMUM_USEFUL_LIGHT_RANGE : 0)
/obj/machinery/vending/update_icon_state()
if(machine_stat & BROKEN)
icon_state = "[initial(icon_state)]-broken"
return ..()
icon_state = "[initial(icon_state)][powered() ? null : "-off"]"
return ..()
/obj/machinery/vending/update_overlays()
. = ..()
if(panel_open)
. += panel_type
if(light_mask && !(machine_stat & BROKEN) && powered())
. += emissive_appearance(icon, light_mask, src)
/obj/machinery/vending/examine(mob/user)
. = ..()
if(isnull(refill_canister))
return // you can add the comment here instead
if((total_loaded_stock() / total_max_stock()) < 1)
. += span_notice("\The [src] can be restocked with [span_boldnotice("\a [initial(refill_canister.machine_name)] [initial(refill_canister.name)]")] with the panel open.")
else
. += span_notice("\The [src] is fully stocked.")
if(credits_contained < CREDITS_DUMP_THRESHOLD && credits_contained > 0)
. += span_notice("It should have a handfull of credits stored based on the missing items.")
else if (credits_contained > PAYCHECK_CREW)
. += span_notice("It should have at least a full paycheck worth of credits inside!")
/**
* Intentionally leaving out a case for zero credits as it should be covered by the vending machine's stock being full,
* or covered by first case if items were returned.
*/
/obj/machinery/vending/atom_break(damage_flag)
. = ..()
if(!.)
return
var/dump_amount = 0
var/found_anything = TRUE
while (found_anything)
found_anything = FALSE
for(var/datum/data/vending_product/record as anything in shuffle(product_records))
//first dump any of the items that have been returned, in case they contain the nuke disk or something
for(var/obj/returned_obj_to_dump in record.returned_products)
LAZYREMOVE(record.returned_products, returned_obj_to_dump)
returned_obj_to_dump.forceMove(get_turf(src))
step(returned_obj_to_dump, pick(GLOB.alldirs))
record.amount--
if(record.amount <= 0) //Try to use a record that actually has something to dump.
continue
var/dump_path = record.product_path
if(!dump_path)
continue
record.amount--
// busting open a vendor will destroy some of the contents
if(found_anything && prob(80))
continue
var/obj/obj_to_dump = new dump_path(loc)
on_dispense(obj_to_dump)
step(obj_to_dump, pick(GLOB.alldirs))
found_anything = TRUE
dump_amount++
if (dump_amount >= 16)
return
/**
* Build the inventory of the vending machine from it's product and record lists
*
* This builds up a full set of /datum/data/vending_products from the product list of the vending machine type
* Arguments:
* * productlist - the list of products that need to be converted
* * recordlist - the list containing /datum/data/vending_product datums
* * categories - A list in the format of product_categories to source category from
* * startempty - should we set vending_product record amount from the product list (so it's prefilled at roundstart)
*/
/obj/machinery/vending/proc/build_inventory(list/productlist, list/recordlist, list/categories, start_empty = FALSE)
default_price = round(initial(default_price))
extra_price = round(initial(extra_price))
if(HAS_TRAIT(SSeconomy, TRAIT_MARKET_CRASHING))
default_price *= SSeconomy.inflation_value()
extra_price *= SSeconomy.inflation_value()
var/list/product_to_category = list()
for (var/list/category as anything in categories)
var/list/products = category["products"]
for (var/product_key in products)
product_to_category[product_key] = category
for(var/typepath in productlist)
var/amount = productlist[typepath]
if(isnull(amount))
amount = 0
var/obj/item/temp = typepath
var/datum/data/vending_product/new_record = new /datum/data/vending_product()
new_record.name = initial(temp.name)
new_record.product_path = typepath
if(!start_empty)
new_record.amount = amount
new_record.max_amount = amount
///Prices of vending machines are all increased uniformly.
new_record.custom_price = round(initial(temp.custom_price))
new_record.custom_premium_price = round(initial(temp.custom_premium_price))
if(HAS_TRAIT(SSeconomy, TRAIT_MARKET_CRASHING))
new_record.custom_price = round(initial(temp.custom_price) * SSeconomy.inflation_value())
new_record.custom_premium_price = round(initial(temp.custom_premium_price) * SSeconomy.inflation_value())
new_record.age_restricted = initial(temp.age_restricted)
new_record.colorable = !!(initial(temp.greyscale_config) && initial(temp.greyscale_colors) && (initial(temp.flags_1) & IS_PLAYER_COLORABLE_1))
new_record.category = product_to_category[typepath]
recordlist += new_record
/**Builds all available inventories for the vendor - standard, contraband and premium
* Arguments:
* start_empty - bool to pass into build_inventory that determines whether a product entry starts with available stock or not
*/
/obj/machinery/vending/proc/build_inventories(start_empty)
build_inventory(products, product_records, product_categories, start_empty)
build_inventory(contraband, hidden_records, create_categories_from("Contraband", "mask", contraband), start_empty)
build_inventory(premium, coin_records, create_categories_from("Premium", "coins", premium), start_empty)
/**
* Returns a list of data about the category
* Arguments:
* name - string for the name of the category
* icon - string for the fontawesome icon to use in the UI for the category
* products - list of products available in the category
*/
/obj/machinery/vending/proc/create_categories_from(name, icon, products)
return list(list(
"name" = name,
"icon" = icon,
"products" = products,
))
///Populates list of products with categorized products
/obj/machinery/vending/proc/build_products_from_categories()
if (isnull(product_categories))
return
products = list()
for (var/list/category in product_categories)
var/list/category_products = category["products"]
for (var/product_key in category_products)
products[product_key] += category_products[product_key]
/**
* Reassign the prices of the vending machine as a result of the inflation value, as provided by SSeconomy
*
* This rebuilds both /datum/data/vending_products lists for premium and standard products based on their most relevant pricing values.
* Arguments:
* * recordlist - the list of standard product datums in the vendor to refresh their prices.
* * premiumlist - the list of premium product datums in the vendor to refresh their prices.
*/
/obj/machinery/vending/proc/reset_prices(list/recordlist, list/premiumlist)
var/crash_status = HAS_TRAIT(SSeconomy, TRAIT_MARKET_CRASHING)
default_price = round(initial(default_price))
extra_price = round(initial(extra_price))
if(crash_status)
default_price *= SSeconomy.inflation_value()
extra_price *= SSeconomy.inflation_value()
for(var/datum/data/vending_product/record as anything in recordlist)
var/obj/item/potential_product = record.product_path
record.custom_price = round(initial(potential_product.custom_price))
if(crash_status)
record.custom_price = round(initial(potential_product.custom_price) * SSeconomy.inflation_value())
for(var/datum/data/vending_product/premium_record as anything in premiumlist)
var/obj/item/potential_product = premium_record.product_path
var/premium_sanity = round(initial(potential_product.custom_premium_price))
if(premium_sanity)
premium_record.custom_premium_price = round(premium_sanity)
if(crash_status)
premium_record.custom_premium_price = round(premium_sanity * SSeconomy.inflation_value())
continue
//For some ungodly reason, some premium only items only have a custom_price
premium_record.custom_premium_price = round(extra_price + (initial(potential_product.custom_price)))
if(crash_status)
premium_record.custom_premium_price = round(extra_price + (initial(potential_product.custom_price) * (SSeconomy.inflation_value() - 1)))
/**
* Refill a vending machine from a refill canister
*
* This takes the products from the refill canister and then fills the products, contraband and premium product categories
*
* Arguments:
* * canister - the vending canister we are refilling from
*/
/obj/machinery/vending/proc/restock(obj/item/vending_refill/canister)
if (!canister.products)
canister.products = products.Copy()
if (!canister.contraband)
canister.contraband = contraband.Copy()
if (!canister.premium)
canister.premium = premium.Copy()
. = 0
if (isnull(canister.product_categories) && !isnull(product_categories))
canister.product_categories = product_categories.Copy()
if (!isnull(canister.product_categories))
var/list/products_unwrapped = list()
for (var/list/category as anything in canister.product_categories)
var/list/products = category["products"]
for (var/product_key in products)
products_unwrapped[product_key] += products[product_key]
. += refill_inventory(products_unwrapped, product_records)
else
. += refill_inventory(canister.products, product_records)
. += refill_inventory(canister.contraband, hidden_records)
. += refill_inventory(canister.premium, coin_records)
return .
/**
* After-effects of refilling a vending machine from a refill canister
*
* This takes the amount of products restocked and gives the user our contained credits if needed,
* sending the user a fitting message.
*
* Arguments:
* * user - the user restocking us
* * restocked - the amount of items we've been refilled with
*/
/obj/machinery/vending/proc/post_restock(mob/living/user, restocked)
if(!restocked)
to_chat(user, span_warning("There's nothing to restock!"))
return
to_chat(user, span_notice("You loaded [restocked] items in [src][credits_contained > 0 ? ", and are rewarded [credits_contained] credits." : "."]"))
var/datum/bank_account/cargo_account = SSeconomy.get_dep_account(ACCOUNT_CAR)
cargo_account.adjust_money(round(credits_contained * 0.5), "Vending: Restock")
var/obj/item/holochip/payday = new(src, credits_contained)
try_put_in_hand(payday, user)
credits_contained = 0
/**
* Refill our inventory from the passed in product list into the record list
*
* Arguments:
* * productlist - list of types -> amount
* * recordlist - existing record datums
*/
/obj/machinery/vending/proc/refill_inventory(list/productlist, list/recordlist)
. = 0
for(var/datum/data/vending_product/record as anything in recordlist)
var/diff = min(record.max_amount - record.amount, productlist[record.product_path])
if (diff)
productlist[record.product_path] -= diff
record.amount += diff
. += diff
/**
* Set up a refill canister that matches this machine's products
*
* This is used when the machine is deconstructed, so the items aren't "lost"
*/
/obj/machinery/vending/proc/update_canister()
if (!component_parts)
return
var/obj/item/vending_refill/installed_refill = locate() in component_parts
if (!installed_refill)
CRASH("Constructible vending machine did not have a refill canister")
unbuild_inventory_into(product_records, installed_refill.products, installed_refill.product_categories)
installed_refill.contraband = unbuild_inventory(hidden_records)
installed_refill.premium = unbuild_inventory(coin_records)
/**
* Given a record list, go through and return a list of products in format of type -> amount
* Arguments:
* recordlist - list of records to unbuild products from
*/
/obj/machinery/vending/proc/unbuild_inventory(list/recordlist)
. = list()
for(var/datum/data/vending_product/record as anything in recordlist)
.[record.product_path] += record.amount
/**
* Unbuild product_records into categorized product lists to the machine's refill canister.
* Does not handle contraband/premium products, only standard stock and any other categories used by the vendor(see: ClothesMate).
* If a product has no category, puts it into standard stock category.
* Arguments:
* product_records - list of products of the vendor
* products - list of products of the refill canister
* product_categories - list of product categories of the refill canister
*/
/obj/machinery/vending/proc/unbuild_inventory_into(list/product_records, list/products, list/product_categories)
products?.Cut()
product_categories?.Cut()
var/others_have_category = null
var/list/categories_to_index = list()
for (var/datum/data/vending_product/record as anything in product_records)
var/list/category = record.category
var/has_category = !isnull(category)
//check if there're any uncategorized products
if (isnull(others_have_category))
others_have_category = has_category
else if (others_have_category != has_category)
if (has_category)
WARNING("[record.product_path] in [type] has a category, but other products don't")
else
WARNING("[record.product_path] in [type] does not have a category, but other products do")
continue
if (has_category)
var/index = categories_to_index.Find(category)
if (index) //if we've already established a category, add the product there
var/list/category_in_list = product_categories[index]
var/list/products_in_category = category_in_list["products"]
products_in_category[record.product_path] += record.amount
else //create a category that the product is supposed to have and put it there
categories_to_index += list(category)
index = categories_to_index.len
var/list/category_clone = category.Copy()
var/list/initial_product_list = list()
initial_product_list[record.product_path] = record.amount
category_clone["products"] = initial_product_list
product_categories += list(category_clone)
else //no category found - dump it into standard stock
products[record.product_path] = record.amount
/**
* Returns the total amount of items in the vending machine based on the product records and premium records, but not contraband
*/
/obj/machinery/vending/proc/total_loaded_stock()
var/total = 0
for(var/datum/data/vending_product/record as anything in product_records + coin_records)
total += record.amount
return total
/**
* Returns the total amount of items in the vending machine based on the product records and premium records, but not contraband
*/
/obj/machinery/vending/proc/total_max_stock()
var/total_max = 0
for(var/datum/data/vending_product/record as anything in product_records + coin_records)
total_max += record.max_amount
return total_max
/obj/machinery/vending/crowbar_act(mob/living/user, obj/item/attack_item)
if(!component_parts)
return FALSE
default_deconstruction_crowbar(attack_item)
return TRUE
/obj/machinery/vending/wrench_act(mob/living/user, obj/item/tool)
. = ..()
if(!panel_open)
return FALSE
if(default_unfasten_wrench(user, tool, time = 6 SECONDS))
unbuckle_all_mobs(TRUE)
return ITEM_INTERACT_SUCCESS
return FALSE
/obj/machinery/vending/screwdriver_act(mob/living/user, obj/item/attack_item)
if(..())
return TRUE
if(anchored)
default_deconstruction_screwdriver(user, icon_state, icon_state, attack_item)
update_appearance()
else
to_chat(user, span_warning("You must first secure [src]."))
return TRUE
/obj/machinery/vending/attackby(obj/item/attack_item, mob/living/user, params)
if(panel_open && is_wire_tool(attack_item))
wires.interact(user)
return
if(refill_canister && istype(attack_item, refill_canister))
if (!panel_open)
to_chat(user, span_warning("You should probably unscrew the service panel first!"))
else if (machine_stat & (BROKEN|NOPOWER))
to_chat(user, span_notice("[src] does not respond."))
else
//if the panel is open we attempt to refill the machine
var/obj/item/vending_refill/canister = attack_item
if(canister.get_part_rating() == 0)
to_chat(user, span_warning("[canister] is empty!"))
else
// instantiate canister if needed
var/restocked = restock(canister)
post_restock(user, restocked)
return
if(compartmentLoadAccessCheck(user) && !user.combat_mode)
if(canLoadItem(attack_item))
loadingAttempt(attack_item, user)
if(istype(attack_item, /obj/item/storage/bag)) //trays USUALLY
var/obj/item/storage/storage_item = attack_item
var/loaded = 0
var/denied_items = 0
for(var/obj/item/the_item in storage_item.contents)
if(contents.len >= MAX_VENDING_INPUT_AMOUNT) // no more than 30 item can fit inside, legacy from snack vending although not sure why it exists
to_chat(user, span_warning("[src]'s compartment is full."))
break
if(canLoadItem(the_item) && loadingAttempt(the_item, user))
storage_item.atom_storage?.attempt_remove(the_item, src)
loaded++
else
denied_items++
if(denied_items)
to_chat(user, span_warning("[src] refuses some items!"))
if(loaded)
to_chat(user, span_notice("You insert [loaded] dishes into [src]'s compartment."))
else
. = ..()
if(tiltable && !tilted && attack_item.force)
if(isclosedturf(get_turf(user))) //If the attacker is inside of a wall, immediately fall in the other direction, with no chance for goodies.
var/opposite_direction = REVERSE_DIR(get_dir(src, user))
var/target = get_step(src, opposite_direction)
tilt(get_turf(target))
return
switch(rand(1, 100))
if(1 to 5)
freebie(3)
if(6 to 15)
freebie(2)
if(16 to 25)
freebie(1)
if(26 to 75)
return
if(76 to 100)
tilt(user)
/**
* Dispenses free items from the standard stock.
* Arguments:
* freebies - number of free items to vend
*/
/obj/machinery/vending/proc/freebie(freebies)
visible_message(span_notice("[src] yields [freebies > 1 ? "several free goodies" : "a free goody"][credits_contained > 0 ? " and some credits" : ""]!"))
for(var/i in 1 to freebies)
playsound(src, 'sound/machines/machine_vend.ogg', 50, TRUE, extrarange = -3)
for(var/datum/data/vending_product/record in shuffle(product_records))
if(record.amount <= 0) //Try to use a record that actually has something to dump.
continue
var/dump_path = record.product_path
if(!dump_path)
continue
if(record.amount > LAZYLEN(record.returned_products)) //always give out new stuff that costs before free returned stuff, because of the risk getting gibbed involved
var/obj/item/free_stuff = new dump_path(get_turf(src))
on_dispense(free_stuff)
else
var/obj/returned_obj_to_dump = LAZYACCESS(record.returned_products, LAZYLEN(record.returned_products)) //first in, last out
LAZYREMOVE(record.returned_products, returned_obj_to_dump)
returned_obj_to_dump.forceMove(get_turf(src))
record.amount--
break
deploy_credits()
/**
* Tilts ontop of the atom supplied, if crit is true some extra shit can happen. See [fall_and_crush] for return values.
* Arguments:
* fatty - atom to tilt the vendor onto
* local_crit_chance - percent chance of a critical hit
* forced_crit - specific critical hit case to use, if any
*/
/obj/machinery/vending/proc/tilt(atom/fatty, local_crit_chance = crit_chance, forced_crit = forcecrit)
if(QDELETED(src) || !has_gravity(src))
return
. = NONE
var/picked_rotation = pick(90, 270)
if(Adjacent(fatty))
. = fall_and_crush(get_turf(fatty), squish_damage, local_crit_chance, forced_crit, 6 SECONDS, rotation = picked_rotation)
if (. & SUCCESSFULLY_FELL_OVER)
visible_message(span_danger("[src] tips over!"))
tilted = TRUE
tilted_rotation = picked_rotation
layer = ABOVE_MOB_LAYER
if(get_turf(fatty) != get_turf(src))
throw_at(get_turf(fatty), 1, 1, spin = FALSE, quickstart = FALSE)
/**
* Causes src to fall onto [target], crushing everything on it (including itself) with [damage]
* and a small chance to do a spectacular effect per entity (if a chance above 0 is provided).
*
* Args:
* * turf/target: The turf to fall onto. Cannot be null.
* * damage: The raw numerical damage to do by default.
* * chance_to_crit: The percent chance of a critical hit occuring. Default: 0
* * forced_crit_case: If given a value from crushing.dm, [target] and it's contents will always be hit with that specific critical hit. Default: null
* * paralyze_time: The time, in deciseconds, a given mob/living will be paralyzed for if crushed.
* * crush_dir: The direction the crush is coming from. Default: dir of src to [target].
* * damage_type: The type of damage to do. Default: BRUTE
* * damage_flag: The attack flag for armor purposes. Default: MELEE
* * rotation: The angle of which to rotate src's transform by on a successful tilt. Default: 90.
*
* Returns: A collection of bitflags defined in crushing.dm. Read that file's documentation for info.
*/
/atom/movable/proc/fall_and_crush(turf/target, damage, chance_to_crit = 0, forced_crit_case = null, paralyze_time, crush_dir = get_dir(get_turf(src), target), damage_type = BRUTE, damage_flag = MELEE, rotation = 90)
ASSERT(!isnull(target))
var/flags_to_return = NONE
if (!target.is_blocked_turf(TRUE, src, list(src)))
for(var/atom/atom_target in (target.contents) + target)
if (isarea(atom_target))
continue
if (SEND_SIGNAL(atom_target, COMSIG_PRE_TILT_AND_CRUSH, src) & COMPONENT_IMMUNE_TO_TILT_AND_CRUSH)
continue
var/crit_case = forced_crit_case
if (isnull(crit_case) && chance_to_crit > 0)
if (prob(chance_to_crit))
crit_case = pick_weight(get_crit_crush_chances())
var/crit_rebate_mult = 1 // lessen the normal damage we deal for some of the crits
if (!isnull(crit_case))
crit_rebate_mult = fall_and_crush_crit_rebate_table(crit_case)
apply_crit_crush(crit_case, atom_target)
var/adjusted_damage = damage * crit_rebate_mult
var/crushed
if (isliving(atom_target))
crushed = TRUE
var/mob/living/carbon/living_target = atom_target
var/was_alive = (living_target.stat != DEAD)
var/blocked = living_target.run_armor_check(attack_flag = damage_flag)
if (iscarbon(living_target))
var/mob/living/carbon/carbon_target = living_target
if(prob(30))
carbon_target.apply_damage(max(0, adjusted_damage), damage_type, blocked = blocked, forced = TRUE, spread_damage = TRUE, attack_direction = crush_dir) // the 30% chance to spread the damage means you escape breaking any bones
else
var/brute = (damage_type == BRUTE ? damage : 0) * 0.5
var/burn = (damage_type == BURN ? damage : 0) * 0.5
carbon_target.take_bodypart_damage(brute, burn, check_armor = TRUE, wound_bonus = 5) // otherwise, deal it to 2 random limbs (or the same one) which will likely shatter something
carbon_target.take_bodypart_damage(brute, burn, check_armor = TRUE, wound_bonus = 5)
carbon_target.AddElement(/datum/element/squish, 80 SECONDS)
else
living_target.apply_damage(adjusted_damage, damage_type, blocked = blocked, forced = TRUE, attack_direction = crush_dir)
living_target.Paralyze(paralyze_time)
living_target.emote("scream")
playsound(living_target, 'sound/effects/blobattack.ogg', 40, TRUE)
playsound(living_target, 'sound/effects/splat.ogg', 50, TRUE)
post_crush_living(living_target, was_alive)
flags_to_return |= (SUCCESSFULLY_CRUSHED_MOB|SUCCESSFULLY_CRUSHED_ATOM)
else if(check_atom_crushable(atom_target))
atom_target.take_damage(adjusted_damage, damage_type, damage_flag, FALSE, crush_dir)
crushed = TRUE
flags_to_return |= SUCCESSFULLY_CRUSHED_ATOM
if (crushed)
atom_target.visible_message(span_danger("[atom_target] is crushed by [src]!"), span_userdanger("You are crushed by [src]!"))
SEND_SIGNAL(atom_target, COMSIG_POST_TILT_AND_CRUSH, src)
var/matrix/to_turn = turn(transform, rotation)
animate(src, transform = to_turn, 0.2 SECONDS)
playsound(src, 'sound/effects/bang.ogg', 40)
visible_message(span_danger("[src] tips over, slamming hard onto [target]!"))
flags_to_return |= SUCCESSFULLY_FELL_OVER
post_tilt()
else
visible_message(span_danger("[src] rebounds comically as it fails to slam onto [target]!"))
Move(target, crush_dir) // we still TRY to move onto it for shit like teleporters
return flags_to_return
/**
* Exists for the purposes of custom behavior.
* Called directly after [crushed] is crushed.
*
* Args:
* * mob/living/crushed: The mob that was crushed.
* * was_alive: Boolean. True if the mob was alive before the crushing.
*/
/atom/movable/proc/post_crush_living(mob/living/crushed, was_alive)
return
/**
* Exists for the purposes of custom behavior.
* Called directly after src actually rotates and falls over.
*/
/atom/movable/proc/post_tilt()
return
/proc/check_atom_crushable(atom/atom_target)
/// Contains structures and items that vendors shouldn't crush when we land on them.
var/static/list/vendor_uncrushable_objects = list(
/obj/structure/chair,
/obj/machinery/conveyor,
) + GLOB.WALLITEMS_INTERIOR + GLOB.WALLITEMS_EXTERIOR
if(is_type_in_list(atom_target, vendor_uncrushable_objects)) //make sure its not in the list of "uncrushable" stuff
return FALSE
if (atom_target.uses_integrity && !(atom_target.invisibility > SEE_INVISIBLE_LIVING)) //check if it has integrity + allow ninjas, etc to be crushed in cloak
return TRUE //SMUSH IT
return FALSE
/obj/machinery/vending/post_crush_living(mob/living/crushed, was_alive)
if(was_alive && crushed.stat == DEAD && crushed.client)
crushed.client.give_award(/datum/award/achievement/misc/vendor_squish, crushed) // good job losing a fight with an inanimate object idiot
add_memory_in_range(crushed, 7, /datum/memory/witness_vendor_crush, protagonist = crushed, antagonist = src)
return ..()
/**
* Allows damage to be reduced on certain crit cases.
* Args:
* * crit_case: The critical case chosen.
*/
/atom/movable/proc/fall_and_crush_crit_rebate_table(crit_case)
ASSERT(!isnull(crit_case))
switch(crit_case)
if (CRUSH_CRIT_SHATTER_LEGS)
return 0.2
else
return 1
/obj/machinery/vending/fall_and_crush_crit_rebate_table(crit_case)
if (crit_case == VENDOR_CRUSH_CRIT_GLASSCANDY)
return 0.33
return ..()
/**
* Returns a assoc list of (critcase -> num), where critcase is a critical define in crushing.dm and num is a weight.
* Use with pickweight to acquire a random critcase.
*/
/atom/movable/proc/get_crit_crush_chances()
RETURN_TYPE(/list)
var/list/weighted_crits = list()
weighted_crits[CRUSH_CRIT_SHATTER_LEGS] = 100
weighted_crits[CRUSH_CRIT_PARAPALEGIC] = 80
weighted_crits[CRUSH_CRIT_HEADGIB] = 20
weighted_crits[CRUSH_CRIT_SQUISH_LIMB] = 100
return weighted_crits
/obj/machinery/vending/get_crit_crush_chances()
var/list/weighted_crits = ..()