Files
RoxyandGitHub 436f766c3b Modular vending machine code cleanup (#4791)
## About The Pull Request

This is a general clean up of some of our modular vending machine code,
highlights are:
- Merges the skyrat `modular_vending` folder into our own
- Eliminates the `skyrat_products`, `skyrat_product_categories`,
`skyrat_contraband`, and `skyrat_premium` vars, merge their stuff into
the bubber equivalents
- Changes the handling for modular autodrobe additions to just add them
to the global list because the autodrobe uses global lists for some
reason, this fixes #4758
- Change a `+=` to `|=` to prevent duplicate entries in vending machines
causing both to appear out of stock
- Fix a duplicate recolor button in the vending machine TGUI

## Why It's Good For The Game

Less duplicate code and bugs, the autodrobe one in particular was funny
because what was happening is the category lists of items were global
lists, and the modular code for adding our own stuff to categories just
`+=` adds it, and that runs every time an autodrobe is created on the
map, so each time the same stuff was being added to the same list and
bloating it to several hundred

## Proof Of Testing
<details>
<summary>Screenshots/Videos</summary>

<img width="425" height="559" alt="image"
src="https://github.com/user-attachments/assets/e9ab16ed-3c7c-4061-90d5-dc27a7d8a40e"
/>

</details>

## Changelog
🆑
fix: fixed the autodrobe being mostly out of stock and broken
fix: fixed certain vending machines having duplicate items that broke
fix: fixed a bug with the recolor button in vending machines appearing
twice
code: merged modular skyrat vending machine code into our folder
/🆑
2025-10-08 14:28:49 -04:00

95 lines
3.7 KiB
Plaintext

#define MINIMUM_CLOTHING_STOCK 5
/obj/machinery/vending
/// List of products to exclude when building the vending machine's inventory
var/list/excluded_products
/// Additions to the `products` list of the vending machine, modularly. Will become null after Initialize, to free up memory.
var/list/zubbers_products
/// Additions to the `product_categories` list of the vending machine, modularly. Will become null after Initialize, to free up memory.
var/list/zubbers_product_categories
/// Additions to the `premium` list of the vending machine, modularly. Will become null after Initialize, to free up memory.
var/list/zubbers_premium
/// Additions to the `contraband` list of the vending machine, modularly. Will become null after Initialize, to free up memory.
var/list/zubbers_contraband
/obj/machinery/vending/Initialize(mapload)
if(zubbers_products)
// We need this, because duplicates screw up the spritesheet!
for(var/item_to_add in zubbers_products)
products[item_to_add] = zubbers_products[item_to_add]
if(zubbers_product_categories)
for(var/category in zubbers_product_categories)
var/already_exists = FALSE
for(var/existing_category in product_categories)
if(existing_category["name"] == category["name"])
existing_category["products"] |= category["products"]
already_exists = TRUE
break
if(!already_exists)
product_categories += category
if(zubbers_premium)
// We need this, because duplicates screw up the spritesheet!
for(var/item_to_add in zubbers_premium)
premium[item_to_add] = zubbers_premium[item_to_add]
if(zubbers_contraband)
// We need this, because duplicates screw up the spritesheet!
for(var/item_to_add in zubbers_contraband)
contraband[item_to_add] = zubbers_contraband[item_to_add]
// Time to make clothes amounts consistent!
for (var/obj/item/clothing/item in products)
if(products[item] < MINIMUM_CLOTHING_STOCK && allow_increase(item))
products[item] = MINIMUM_CLOTHING_STOCK
for (var/category in product_categories)
for(var/obj/item/clothing/item in category["products"])
if(category["products"][item] < MINIMUM_CLOTHING_STOCK && allow_increase(item))
category["products"][item] = MINIMUM_CLOTHING_STOCK
for (var/obj/item/clothing/item in premium)
if(premium[item] < MINIMUM_CLOTHING_STOCK && allow_increase(item))
premium[item] = MINIMUM_CLOTHING_STOCK
remove_products(excluded_products)
zubbers_products = null
zubbers_product_categories = null
zubbers_premium = null
zubbers_contraband = null
return ..()
/// This proc checks for forbidden traits cause it'd be pretty bad to have 5 insuls available to assistants roundstart at the vendor!
/obj/machinery/vending/proc/allow_increase(obj/item/clothing/clothing_path)
var/obj/item/clothing/clothing = new clothing_path()
// Ignore earmuffs!
if(TRAIT_DEAF in clothing.clothing_traits)
return FALSE
// Don't touch sunglasses or welding helmets!
if(clothing.flash_protect == FLASH_PROTECTION_WELDER)
return FALSE
// Don't touch bodyarmour!
if(ispath(clothing, /obj/item/clothing/suit/armor))
return FALSE
// Don't touch protective helmets, like riot helmets!
if(ispath(clothing, /obj/item/clothing/head/helmet))
return FALSE
// Ignore all gloves, because it's almost impossible to check what they do...
if(ispath(clothing, /obj/item/clothing/gloves))
return FALSE
return TRUE
/// Removes given list of products. Must be called before build_inventory() to actually prevent the records from being created.
/obj/machinery/vending/proc/remove_products(list/paths_to_remove)
if(!length(paths_to_remove))
return
for(var/typepath in products)
for(var/to_remove in paths_to_remove)
if(ispath(typepath, to_remove))
products.Remove(typepath)
#undef MINIMUM_CLOTHING_STOCK