diff --git a/code/game/machinery/vending.dm b/code/game/machinery/vending.dm
index e0a0fef7569..63e28537abc 100644
--- a/code/game/machinery/vending.dm
+++ b/code/game/machinery/vending.dm
@@ -1,3 +1,7 @@
+#define CAT_NORMAL 0
+#define CAT_HIDDEN 1
+#define CAT_COIN 2
+
/datum/data/vending_product
var/product_name = "generic"
var/product_path = null
@@ -5,6 +9,7 @@
var/max_amount = 0
var/price = 0
var/display_color = "blue"
+ var/category = CAT_NORMAL
/obj/machinery/vending
@@ -114,10 +119,13 @@
R.price = price
R.display_color = pick("red","blue","green")
if(hidden)
+ R.category=CAT_HIDDEN
hidden_records += R
else if(req_coin)
+ R.category=CAT_COIN
coin_records += R
else
+ R.category=CAT_NORMAL
product_records += R
if(delay_product_spawn)
@@ -279,6 +287,31 @@
/obj/machinery/vending/attack_ai(mob/user as mob)
return attack_hand(user)
+/obj/machinery/vending/proc/GetProductIndex(var/datum/data/vending_product/P)
+ var/list/plist
+ switch(P.category)
+ if(CAT_NORMAL)
+ plist=product_records
+ if(CAT_HIDDEN)
+ plist=hidden_records
+ if(CAT_COIN)
+ plist=coin_records
+ else
+ warning("UNKNOWN CATEGORY [P.category] IN TYPE [P.product_path] INSIDE [type]!")
+ return plist.Find(P)
+
+/obj/machinery/vending/proc/GetProductByID(var/pid, var/category)
+ switch(category)
+ if(CAT_NORMAL)
+ return product_records[pid]
+ if(CAT_HIDDEN)
+ return hidden_records[pid]
+ if(CAT_COIN)
+ return coin_records[pid]
+ else
+ warning("UNKNOWN PRODUCT: PID: [pid], CAT: [category] INSIDE [type]!")
+ return null
+
/obj/machinery/vending/attack_hand(mob/user as mob)
if(stat & (BROKEN|NOPOWER))
return
@@ -313,12 +346,11 @@
dat += "No product loaded!"
else
var/list/display_records = src.product_records
+
if(src.extended_inventory)
- display_records = src.product_records + src.hidden_records
+ display_records += src.hidden_records
if(src.coin)
- display_records = src.product_records + src.coin_records
- if(src.coin && src.extended_inventory)
- display_records = src.product_records + src.hidden_records + src.coin_records
+ display_records += src.coin_records
for (var/datum/data/vending_product/R in display_records)
@@ -330,7 +362,8 @@
if(R.price)
dat += " (Price: [R.price])"
if (R.amount > 0)
- dat += " (Vend)"
+ var/idx=GetProductIndex(R)
+ dat += " (Vend)"
else
dat += " SOLD OUT"
dat += "
"
@@ -386,7 +419,10 @@
flick(src.icon_deny,src)
return
- var/datum/data/vending_product/R = locate(href_list["vend"])
+ var/idx=text2num(href_list["vend"])
+ var/cat=text2num(href_list["cat"])
+
+ var/datum/data/vending_product/R = GetProductByID(idx,cat)
if (!R || !istype(R) || !R.product_path || R.amount <= 0)
return