diff --git a/code/datums/vending/stored_item.dm b/code/datums/vending/stored_item.dm
new file mode 100644
index 0000000000..4fed107d77
--- /dev/null
+++ b/code/datums/vending/stored_item.dm
@@ -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
\ No newline at end of file
diff --git a/code/datums/vending/vending.dm b/code/datums/vending/vending.dm
new file mode 100644
index 0000000000..329c8c1959
--- /dev/null
+++ b/code/datums/vending/vending.dm
@@ -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
\ No newline at end of file
diff --git a/code/game/machinery/kitchen/smartfridge.dm b/code/game/machinery/kitchen/smartfridge.dm
index a483232526..5dc2dba62b 100644
--- a/code/game/machinery/kitchen/smartfridge.dm
+++ b/code/game/machinery/kitchen/smartfridge.dm
@@ -1,63 +1,3 @@
-/*
-* Datum that holds the instances and information about the items in the smartfridge.
-*/
-/datum/data/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/fridge //The attatched fridge
-
-/datum/data/stored_item/New(var/fridge, 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.fridge = fridge
-
-/datum/data/stored_item/Destroy()
- fridge = null
- if(instances)
- for(var/product in instances)
- qdel(product)
- instances.Cut()
- . = ..()
-
-/datum/data/stored_item/proc/get_amount()
- return instances ? instances.len : amount
-
-/datum/data/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/data/stored_item/proc/add_product(var/atom/movable/product)
- if(product.type != item_path)
- return 0
- init_products()
- product.forceMove(fridge)
- instances += product
-
-/datum/data/stored_item/proc/init_products()
- if(instances)
- return
- instances = list()
- for(var/i = 1 to amount)
- var/new_product = new item_path(fridge)
- instances += new_product
-
-
/* SmartFridge. Much todo
*/
/obj/machinery/smartfridge
@@ -76,7 +16,7 @@
var/icon_off = "smartfridge-off"
var/icon_panel = "smartfridge-panel"
var/list/item_records = list()
- var/datum/data/stored_item/currently_vending = null //What we're putting out of the machine.
+ var/datum/stored_item/currently_vending = null //What we're putting out of the machine.
var/seconds_electrified = 0;
var/shoot_inventory = 0
var/locked = 0
@@ -96,6 +36,8 @@
/obj/machinery/smartfridge/Destroy()
qdel(wires)
+ for(var/A in item_records) //Get rid of item records.
+ qdel(A)
wires = null
return ..()
@@ -129,7 +71,7 @@
/obj/machinery/smartfridge/secure/extract/New()
..()
- var/datum/data/stored_item/I = new(src, /obj/item/xenoproduct/slime/core)
+ var/datum/stored_item/I = new(src, /obj/item/xenoproduct/slime/core)
item_records.Add(I)
for(var/i=1 to 5)
var/obj/item/xenoproduct/slime/core/C = new(src)
@@ -226,17 +168,17 @@
overlays += "drying_rack_drying"
/obj/machinery/smartfridge/drying_rack/proc/dry()
- for(var/datum/data/stored_item/I in item_records)
+ for(var/datum/stored_item/I in item_records)
for(var/obj/item/weapon/reagent_containers/food/snacks/S in I.instances)
if(S.dry) continue
if(S.dried_type == S.type)
S.dry = 1
S.name = "dried [S.name]"
S.color = "#AAAAAA"
- I.get_product(loc)
+ stock(S)
else
var/D = S.dried_type
- new D(loc)
+ new D(get_turf(src))
qdel(S)
return
return
@@ -286,46 +228,22 @@
if(accept_check(O))
user.remove_from_mob(O)
- var/hasRecord = FALSE //Check to see if this passes or not.
- for(var/datum/data/stored_item/I in item_records)
- if(istype(O, I.item_path))
- stock(O, I)
- qdel(O)
- return
- if(!hasRecord)
- var/datum/data/stored_item/item = new/datum/data/stored_item(src, O.type)
- stock(O, item)
- item_records.Add(item)
-
+ stock(O)
user.visible_message("[user] has added \the [O] to \the [src].", "You add \the [O] to \the [src].")
- nanomanager.update_uis(src)
else if(istype(O, /obj/item/weapon/storage/bag))
var/obj/item/weapon/storage/bag/P = O
var/plants_loaded = 0
for(var/obj/G in P.contents)
if(accept_check(G))
- plants_loaded++
- var/hasRecord = FALSE //Check to see if this passes or not.
- for(var/datum/data/stored_item/I in item_records)
- if(istype(G, I.item_path))
- if(G.name == I.item_name)
- stock(G, I)
- hasRecord = TRUE
- if(!hasRecord)
- var/datum/data/stored_item/item = new/datum/data/stored_item(src, G.type, G.name)
- stock(G, item)
- item_records.Add(item)
-
+ stock(G)
+ plants_loaded = 1
if(plants_loaded)
-
user.visible_message("[user] loads \the [src] with \the [P].", "You load \the [src] with \the [P].")
if(P.contents.len > 0)
user << "Some items are refused."
- nanomanager.update_uis(src)
-
else
user << "\The [src] smartly refuses [O]."
return 1
@@ -337,11 +255,20 @@
user << "You short out the product lock on [src]."
return 1
-/obj/machinery/smartfridge/proc/stock(obj/item/O, var/datum/data/stored_item/I)
- I.add_product(O)
+/obj/machinery/smartfridge/proc/stock(obj/item/O)
+ var/hasRecord = FALSE //Check to see if this passes or not.
+ for(var/datum/stored_item/I in item_records)
+ if((O.type == I.item_path) && (O.name == I.item_name))
+ I.add_product(O)
+ hasRecord = TRUE
+ break
+ if(!hasRecord)
+ var/datum/stored_item/item = new/datum/stored_item(src, O.type, O.name)
+ item.add_product(O)
+ item_records.Add(item)
nanomanager.update_uis(src)
-/obj/machinery/smartfridge/proc/vend(datum/data/stored_item/I)
+/obj/machinery/smartfridge/proc/vend(datum/stored_item/I)
I.get_product(get_turf(src))
nanomanager.update_uis(src)
@@ -370,7 +297,7 @@
var/list/items[0]
for (var/i=1 to length(item_records))
- var/datum/data/stored_item/I = item_records[i]
+ var/datum/stored_item/I = item_records[i]
var/count = I.get_amount()
if(count > 0)
items.Add(list(list("display_name" = html_encode(capitalize(I.item_name)), "vend" = i, "quantity" = count)))
@@ -400,7 +327,7 @@
if(href_list["vend"])
var/index = text2num(href_list["vend"])
var/amount = text2num(href_list["amount"])
- var/datum/data/stored_item/I = item_records[index]
+ var/datum/stored_item/I = item_records[index]
var/count = I.get_amount()
// Sanity check, there are probably ways to press the button when it shouldn't be possible.
@@ -419,8 +346,8 @@
if(!target)
return 0
- for(var/datum/data/stored_item/I in src.item_records)
- throw_item = I.get_product(loc)
+ for(var/datum/stored_item/I in item_records)
+ throw_item = I.get_product(get_turf(src))
if (!throw_item)
continue
break
diff --git a/code/game/machinery/vending.dm b/code/game/machinery/vending.dm
index f086a3e1dd..b947033526 100644
--- a/code/game/machinery/vending.dm
+++ b/code/game/machinery/vending.dm
@@ -1,69 +1,3 @@
-/**
- * Datum used to hold information about a product in a vending machine
- */
-/datum/data/vending_product
- var/product_name = "generic" // Display name for the product
- var/product_path = null
- var/amount = 0 // The original amount held in the vending machine
- var/list/instances
- 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
- var/vending_machine // The vending machine we belong to
-
-/datum/data/vending_product/New(var/vending_machine, var/path, var/name = null, var/amount = 1, var/price = 0, var/color = null, var/category = CAT_NORMAL)
- ..()
-
- src.product_path = path
-
- if(!name)
- var/atom/tmp = path
- src.product_name = initial(tmp.name)
- else
- src.product_name = name
-
- src.amount = amount
- src.price = price
- src.display_color = color
- src.category = category
- src.vending_machine = vending_machine
-
-/datum/data/vending_product/Destroy()
- vending_machine = null
- if(instances)
- for(var/product in instances)
- qdel(product)
- instances.Cut()
- . = ..()
-
-/datum/data/vending_product/proc/get_amount()
- return instances ? instances.len : amount
-
-/datum/data/vending_product/proc/add_product(var/atom/movable/product)
- if(product.type != product_path)
- return 0
- init_products()
- product.forceMove(vending_machine)
- instances += product
-
-/datum/data/vending_product/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)
- return product
-
-/datum/data/vending_product/proc/init_products()
- if(instances)
- return
- instances = list()
- for(var/i = 1 to amount)
- var/new_product = new product_path(vending_machine)
- instances += new_product
-
/**
* A vending machine
*/
@@ -89,7 +23,7 @@
var/vend_ready = 1 //Are we ready to vend?? Is it time??
var/vend_delay = 10 //How long does it take to vend?
var/categories = CAT_NORMAL // Bitmask of cats we're currently showing
- var/datum/data/vending_product/currently_vending = null // What we're requesting payment for right now
+ var/datum/stored_item/vending_product/currently_vending = null // What we're requesting payment for right now
var/status_message = "" // Status screen messages like "insufficient funds", displayed in NanoUI
var/status_error = 0 // Set to 1 if status_message is an error
@@ -169,7 +103,7 @@
var/category = current_list[2]
for(var/entry in current_list[1])
- var/datum/data/vending_product/product = new/datum/data/vending_product(src, entry)
+ var/datum/stored_item/vending_product/product = new/datum/stored_item/vending_product(src, entry)
product.price = (entry in src.prices) ? src.prices[entry] : 0
product.amount = (current_list[1][entry]) ? current_list[1][entry] : 1
@@ -182,7 +116,7 @@
wires = null
qdel(coin)
coin = null
- for(var/datum/data/vending_product/R in product_records)
+ for(var/datum/stored_item/vending_product/R in product_records)
qdel(R)
product_records = null
return ..()
@@ -276,10 +210,9 @@
return
else
- for(var/datum/data/vending_product/R in product_records)
- if(istype(W, R.product_path))
+ for(var/datum/stored_item/vending_product/R in product_records)
+ if(istype(W, R.item_path) && (W.name == R.item_name))
stock(W, R, user)
- qdel(W)
return
..()
@@ -374,7 +307,7 @@
// create entry in the purchaser's account log
var/datum/transaction/T = new()
T.target_name = "[vendor_account.owner_name] (via [src.name])"
- T.purpose = "Purchase of [currently_vending.product_name]"
+ T.purpose = "Purchase of [currently_vending.item_name]"
if(currently_vending.price > 0)
T.amount = "([currently_vending.price])"
else
@@ -400,7 +333,7 @@
var/datum/transaction/T = new()
T.target_name = target
- T.purpose = "Purchase of [currently_vending.product_name]"
+ T.purpose = "Purchase of [currently_vending.item_name]"
T.amount = "[currently_vending.price]"
T.source_terminal = src.name
T.date = current_date_string
@@ -432,7 +365,7 @@
var/list/data = list()
if(currently_vending)
data["mode"] = 1
- data["product"] = currently_vending.product_name
+ data["product"] = currently_vending.item_name
data["price"] = currently_vending.price
data["message_err"] = 0
data["message"] = src.status_message
@@ -442,14 +375,14 @@
var/list/listed_products = list()
for(var/key = 1 to src.product_records.len)
- var/datum/data/vending_product/I = src.product_records[key]
+ var/datum/stored_item/vending_product/I = src.product_records[key]
if(!(I.category & src.categories))
continue
listed_products.Add(list(list(
"key" = key,
- "name" = I.product_name,
+ "name" = I.item_name,
"price" = I.price,
"color" = I.display_color,
"amount" = I.get_amount())))
@@ -497,7 +430,7 @@
return
var/key = text2num(href_list["vend"])
- var/datum/data/vending_product/R = product_records[key]
+ var/datum/stored_item/vending_product/R = product_records[key]
// This should not happen unless the request from NanoUI was bad
if(!(R.category & src.categories))
@@ -526,7 +459,7 @@
src.add_fingerprint(usr)
nanomanager.update_uis(src)
-/obj/machinery/vending/proc/vend(datum/data/vending_product/R, mob/user)
+/obj/machinery/vending/proc/vend(datum/stored_item/vending_product/R, mob/user)
if((!allowed(usr)) && !emagged && scan_id) //For SECURE VENDING MACHINES YEAH
usr << "Access denied." //Unless emagged of course
flick(src.icon_deny,src)
@@ -581,7 +514,7 @@
* Checks if item is vendable in this machine should be performed before
* calling. W is the item being inserted, R is the associated vending_product entry.
*/
-/obj/machinery/vending/proc/stock(obj/item/weapon/W, var/datum/data/vending_product/R, var/mob/user)
+/obj/machinery/vending/proc/stock(obj/item/weapon/W, var/datum/stored_item/vending_product/R, var/mob/user)
if(!user.unEquip(W))
return
@@ -635,7 +568,7 @@
//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_records)
+ for(var/datum/stored_item/vending_product/R in src.product_records)
while(R.get_amount()>0)
R.get_product(loc)
break
@@ -651,7 +584,7 @@
if(!target)
return 0
- for(var/datum/data/vending_product/R in src.product_records)
+ for(var/datum/stored_item/vending_product/R in src.product_records)
throw_item = R.get_product(loc)
if (!throw_item)
continue
@@ -930,7 +863,7 @@
for(var/entry in current_list[1])
var/obj/item/seeds/S = new entry(src)
var/name = S.name
- var/datum/data/vending_product/product = new/datum/data/vending_product(src, entry, name)
+ var/datum/stored_item/vending_product/product = new/datum/stored_item/vending_product(src, entry, name)
product.price = (entry in src.prices) ? src.prices[entry] : 0
product.amount = (current_list[1][entry]) ? current_list[1][entry] : 1
diff --git a/polaris.dme b/polaris.dme
index 24805a5450..4bb3f09fda 100644
--- a/polaris.dme
+++ b/polaris.dme
@@ -215,6 +215,8 @@
#include "code\datums\uplink\uplink_categories.dm"
#include "code\datums\uplink\uplink_items.dm"
#include "code\datums\uplink\visible_weapons.dm"
+#include "code\datums\vending\stored_item.dm"
+#include "code\datums\vending\vending.dm"
#include "code\datums\wires\airlock.dm"
#include "code\datums\wires\alarm.dm"
#include "code\datums\wires\apc.dm"