mirror of
https://github.com/VOREStation/VOREStation.git
synced 2026-07-13 08:04:22 +01:00
Brings vending machine datums under a subtype of smartfridge datums.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Datum that holds the instances and information about the items stored. Currently used in SmartFridges and Vending Machines.
|
||||
*/
|
||||
/datum/stored_item
|
||||
var/item_name = "name" //Name of the item(s) displayed
|
||||
var/item_path = null
|
||||
var/amount = 0
|
||||
var/list/instances //What items are actually stored
|
||||
var/stored //The thing holding it is
|
||||
|
||||
/datum/stored_item/New(var/stored, var/path, var/name = null, var/amount = 0)
|
||||
src.item_path = path
|
||||
|
||||
if(!name)
|
||||
var/atom/tmp = path
|
||||
src.item_name = initial(tmp.name)
|
||||
else
|
||||
src.item_name = name
|
||||
|
||||
src.amount = amount
|
||||
src.stored = stored
|
||||
|
||||
..()
|
||||
|
||||
/datum/stored_item/Destroy()
|
||||
stored = null
|
||||
if(instances)
|
||||
for(var/product in instances)
|
||||
qdel(product)
|
||||
instances.Cut()
|
||||
. = ..()
|
||||
|
||||
/datum/stored_item/proc/get_amount()
|
||||
return instances ? instances.len : amount
|
||||
|
||||
/datum/stored_item/proc/get_product(var/product_location)
|
||||
if(!get_amount() || !product_location)
|
||||
return
|
||||
init_products()
|
||||
|
||||
var/atom/movable/product = instances[instances.len] // Remove the last added product
|
||||
instances -= product
|
||||
product.forceMove(product_location)
|
||||
|
||||
/datum/stored_item/proc/add_product(var/atom/movable/product)
|
||||
if(product.type != item_path)
|
||||
return 0
|
||||
init_products()
|
||||
product.forceMove(stored)
|
||||
instances += product
|
||||
|
||||
/datum/stored_item/proc/init_products()
|
||||
if(instances)
|
||||
return
|
||||
instances = list()
|
||||
for(var/i = 1 to amount)
|
||||
var/new_product = new item_path(stored)
|
||||
instances += new_product
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Datum used to hold further information about a product in a vending machine
|
||||
*/
|
||||
/datum/stored_item/vending_product
|
||||
var/price = 0 // Price to buy one
|
||||
var/display_color = null // Display color for vending machine listing
|
||||
var/category = CAT_NORMAL // CAT_HIDDEN for contraband, CAT_COIN for premium
|
||||
|
||||
/datum/stored_item/vending_product/New(var/stored, var/path, var/name = null, var/amount = 1, var/price = 0, var/color = null, var/category = CAT_NORMAL)
|
||||
..(stored, path, name, amount)
|
||||
src.price = price
|
||||
src.display_color = color
|
||||
src.category = category
|
||||
Reference in New Issue
Block a user