Files
Bubberstation/code/modules/vending/sustenance.dm
SyncIt21 0b6101a37e General maintenance for vending machines (#91987)
## About The Pull Request
**1. Code Improvements**
- Removed unused vars `coin`, `bill` & other stuff
- Removed duplicate definition of `on_deconstruction()`
- Autodoc for a lot of procs
- Merged smaller procs into larger ones to avoid scrolling in the code
editor & reduced overhead
- Split the vending machine file into several smaller files for easy
code management

**2. Qol**
- Implemented vending machine ads. They now display random stuff on the
UI


https://github.com/user-attachments/assets/9720ea60-f268-4ca2-940d-243e3d0ac75f
- More error messages for custom & normal vendors as to why an item
could not be loaded
- Custom vending machines can be deconstructed safely via crowbar
without any explosion only after unlinking your account from the machine
else you get the same explosion. Upon deconstruction all loaded items
are moved into its restock canister meaning the machine can be safely
moved with all its products just like a regular vending machine to a new
location

**3. Fixes**
- Fixes #81917. Any returned items in the vending machine now show up as
free in the UI & won't cost credits to buy them
- Fixes #87416. Custom & normal vendors now keep track of products
removed via `Exited()` so the UI gets always updated
- Fixes #83151. Items with different names & custom prices now show up
in unique rows
- Fixes #92170 Custom vendors now show the correct icon for inserted
items
- Closes #80010. From the above fix this situation is impossible so it's
safe to close this as a duplicate
- Closes #78016 same problem as above with `Exited()` duplicate
- Custom vendors can now actually be used by players who are not the
owner instead of locking down the UI
- Vending machines keep track of `max_amount` of stocked items by hand
as well & not just RPED

**4. Refactor**
- Separates custom vending machine code from normal vending machine
code. This prime Marely focus on the `vending_machine_input` list which
now only exists inside the custom vending machine
- Compressed the UI code for vending machine so both custom & normal
vending machines can send the same data instead of separating the 2.
Overall less code
- Moved attack chain from `attackby()` to `item_interaction()` for
loading items

## Changelog
🆑
code: cleaned up vending machine code
qol: vending machines now have more product slogans you never heard
before
qol: custom & normal vending machines now have more feedback on why an
item could not be loaded
qol: vending machines now display random ads on the UI
qol: custom vending machines can be deconstructed via crowbar safely
only after unlinking your account from the machine.
qol: upon deconstructing a custom vendor all its products are moved into
its refill canister & it will be restored when reconstructing the
machine elsewhere
fix: Returned items to the vending machine now show up as free in the UI
and won't be greyed out if you don't have credits to get them back
fix: items that leave the vending machine by any means will update the
UI in all cases
fix: loading items by hand to the vending machine now respects the
max_amount for that category
fix: custom vendors can now actually be used by players who are not the
owner thus enabling them to transfer credits to the owner during
purchases & basically they do their job again
fix: custom vendors now show the correct icon for inserted items
fix: Items with different names & custom prices now show up in unique
rows in custom vendors
refactor: separated custom & normal vending machine code. Reduced UI
code & improved attack chain
/🆑

---------

Co-authored-by: MrMelbert <51863163+MrMelbert@users.noreply.github.com>
2025-08-11 14:37:13 +02:00

76 lines
3.1 KiB
Plaintext

/obj/machinery/vending/sustenance
name = "\improper Sustenance Vendor"
desc = "A vending machine which vends food, as required by section 47-C of the NT's Prisoner Ethical Treatment Agreement."
product_slogans = "Enjoy your meal.;Enough calories to support strenuous labor."
product_ads = "Sufficiently healthy.;Efficiently produced tofu!;Mmm! So good!;Have a meal.;You need food to live!;Even prisoners deserve their daily bread!;Have some more candy corn!;Try our new ice cups!"
light_mask = "snack-light-mask"
icon_state = "sustenance"
panel_type = "panel2"
products = list(
/obj/item/food/tofu/prison = 24,
/obj/item/food/breadslice/moldy = 15,
/obj/item/reagent_containers/cup/glass/ice/prison = 12,
/obj/item/food/candy_corn/prison = 6,
/obj/item/kitchen/spoon/plastic = 6,
)
contraband = list(
/obj/item/knife = 6,
/obj/item/kitchen/spoon = 6,
/obj/item/reagent_containers/cup/glass/coffee = 12,
/obj/item/tank/internals/emergency_oxygen = 6,
/obj/item/clothing/mask/breath = 6,
)
refill_canister = /obj/item/vending_refill/sustenance
default_price = PAYCHECK_LOWER
extra_price = PAYCHECK_LOWER * 0.6
payment_department = NO_FREEBIES
allow_custom = TRUE
/obj/machinery/vending/sustenance/interact(mob/living/living_user)
if(!isliving(living_user))
return
if(!istype(living_user.get_idcard(TRUE), /obj/item/card/id/advanced/prisoner))
if(!req_access)
speak("No valid prisoner account found. Vending is not permitted.")
return
if(!allowed(living_user))
speak("No valid permissions. Vending is not permitted.")
return
return ..()
/obj/item/vending_refill/sustenance
machine_name = "Sustenance Vendor"
icon_state = "refill_snack"
//Labor camp subtype that uses labor points obtained from mining and processing ore
/obj/machinery/vending/sustenance/labor_camp
name = "\improper Labor Camp Sustenance Vendor"
desc = "A vending machine which vends food, as required by section 47-C of the NT's Prisoner Ethical Treatment Agreement. \
This one, however, processes labor points for its products if the user is incarcerated."
icon_state = "sustenance_labor"
all_products_free = FALSE
displayed_currency_icon = "digging"
displayed_currency_name = " LP"
allow_custom = FALSE
/obj/machinery/vending/sustenance/labor_camp/proceed_payment(obj/item/card/id/advanced/prisoner/paying_scum_id, mob/living/mob_paying, datum/data/vending_product/product_to_vend, price_to_use)
if(!istype(paying_scum_id))
speak("I don't take bribes! Pay with labor points!")
return FALSE
if(LAZYLEN(product_to_vend.returned_products))
price_to_use = 0 //returned items are free
if(price_to_use && !(paying_scum_id.points >= price_to_use)) //not enough good prisoner points
speak("You do not possess enough points to purchase [product_to_vend.name].")
flick(icon_deny, src)
return FALSE
paying_scum_id.points -= price_to_use
return TRUE
/obj/machinery/vending/sustenance/labor_camp/fetch_balance_to_use(obj/item/card/id/passed_id)
if(!istype(passed_id, /obj/item/card/id/advanced/prisoner))
return null //no points balance - no balance at all
var/obj/item/card/id/advanced/prisoner/paying_scum_id = passed_id
return paying_scum_id.points