Fixes + expands vending machine returned purchases (#64314)

Fixes vending machine returns, also makes it so you can return anything to (nearly) any vending machine. New stuff vends first. Secondhand stuff last.
This commit is contained in:
cacogen
2022-01-23 21:35:34 -05:00
committed by GitHub
parent 1fbd523806
commit 0ebcce8de2
4 changed files with 44 additions and 17 deletions
+44 -8
View File
@@ -36,6 +36,8 @@
var/age_restricted = FALSE
///Whether the product can be recolored by the GAGS system
var/colorable
///List of items that have been returned to the vending machine.
var/list/returned_products
/**
* # vending machines
@@ -278,6 +280,14 @@
found_anything = FALSE
for(var/record in shuffle(product_records))
var/datum/data/vending_product/R = record
//first dump any of the items that have been returned, in case they contain the nuke disk or something
for(var/obj/returned_obj_to_dump in R.returned_products)
LAZYREMOVE(R.returned_products, returned_obj_to_dump)
returned_obj_to_dump.forceMove(get_turf(src))
step(returned_obj_to_dump, pick(GLOB.alldirs))
R.amount--
if(R.amount <= 0) //Try to use a record that actually has something to dump.
continue
var/dump_path = R.product_path
@@ -288,8 +298,8 @@
if(found_anything && prob(80))
continue
var/obj/O = new dump_path(loc)
step(O, pick(GLOB.alldirs))
var/obj/obj_to_dump = new dump_path(loc)
step(obj_to_dump, pick(GLOB.alldirs))
found_anything = TRUE
dump_amount++
if (dump_amount >= 16)
@@ -511,9 +521,13 @@ GLOBAL_LIST_EMPTY(vending_products)
var/dump_path = R.product_path
if(!dump_path)
continue
if(R.amount > LAZYLEN(R.returned_products)) //always give out new stuff that costs before free returned stuff, because of the risk getting gibbed involved
new dump_path(get_turf(src))
else
var/obj/returned_obj_to_dump = LAZYACCESS(R.returned_products, LAZYLEN(R.returned_products)) //first in, last out
LAZYREMOVE(R.returned_products, returned_obj_to_dump)
returned_obj_to_dump.forceMove(get_turf(src))
R.amount--
new dump_path(get_turf(src))
break
///Tilts ontop of the atom supplied, if crit is true some extra shit can happen. Returns TRUE if it dealt damage to something.
@@ -646,11 +660,18 @@ GLOBAL_LIST_EMPTY(vending_products)
. = TRUE
if(!user.transferItemToLoc(I, src))
return FALSE
to_chat(user, span_notice("You insert [I] into [src]'s input compartment."))
for(var/datum/data/vending_product/product_datum in product_records + coin_records + hidden_records)
if(ispath(I.type, product_datum.product_path))
product_datum.amount++
LAZYADD(product_datum.returned_products, I)
return
if(vending_machine_input[format_text(I.name)])
vending_machine_input[format_text(I.name)]++
else
vending_machine_input[format_text(I.name)] = 1
to_chat(user, span_notice("You insert [I] into [src]'s input compartment."))
loaded_items++
/obj/machinery/vending/unbuckle_mob(mob/living/buckled_mob, force = FALSE, can_fall = TRUE)
@@ -926,6 +947,8 @@ GLOBAL_LIST_EMPTY(vending_products)
price_to_use = max(round(price_to_use * VENDING_DISCOUNT), 1) //No longer free, but signifigantly cheaper.
if(coin_records.Find(R) || hidden_records.Find(R))
price_to_use = R.custom_premium_price ? R.custom_premium_price : extra_price
if(LAZYLEN(R.returned_products))
price_to_use = 0 //returned items are free
if(price_to_use && !account.adjust_money(-price_to_use))
say("You do not possess the funds to purchase [R.name].")
flick(icon_deny,src)
@@ -945,7 +968,13 @@ GLOBAL_LIST_EMPTY(vending_products)
if(icon_vend) //Show the vending animation if needed
flick(icon_vend,src)
playsound(src, 'sound/machines/machine_vend.ogg', 50, TRUE, extrarange = -3)
var/obj/item/vended_item = new R.product_path(get_turf(src))
var/obj/item/vended_item
if(!LAZYLEN(R.returned_products)) //always give out free returned stuff first, e.g. to avoid walling a traitor objective in a bag behind paid items
vended_item = new R.product_path(get_turf(src))
else
vended_item = LAZYACCESS(R.returned_products, LAZYLEN(R.returned_products)) //first in, last out
LAZYREMOVE(R.returned_products, vended_item)
vended_item.forceMove(get_turf(src))
if(greyscale_colors)
vended_item.set_greyscale(colors=greyscale_colors)
R.amount--
@@ -1013,9 +1042,13 @@ GLOBAL_LIST_EMPTY(vending_products)
var/dump_path = R.product_path
if(!dump_path)
continue
if(R.amount > LAZYLEN(R.returned_products)) //always throw new stuff that costs before free returned stuff, because of the hacking effort and time between throws involved
throw_item = new dump_path(loc)
else
throw_item = LAZYACCESS(R.returned_products, LAZYLEN(R.returned_products)) //first in, last out
throw_item.forceMove(loc)
LAZYREMOVE(R.returned_products, throw_item)
R.amount--
throw_item = new dump_path(loc)
break
if(!throw_item)
return FALSE
@@ -1064,6 +1097,9 @@ GLOBAL_LIST_EMPTY(vending_products)
* * user - the user doing the loading
*/
/obj/machinery/vending/proc/canLoadItem(obj/item/I, mob/user)
if((I.type in products) || (I.type in premium) || (I.type in contraband))
return TRUE
to_chat(user, span_warning("[src] does not accept [I]!"))
return FALSE
/obj/machinery/vending/hitby(atom/movable/AM, skipcatch, hitpush, blocked, datum/thrownthing/throwingdatum)
-3
View File
@@ -165,9 +165,6 @@
payment_department = ACCOUNT_SRV
light_mask="theater-light-mask"
/obj/machinery/vending/autodrobe/canLoadItem(obj/item/I,mob/user)
return (I.type in products)
/obj/machinery/vending/autodrobe/all_access
desc = "A vending machine for costumes. This model appears to have no access restrictions."
req_access = null
-3
View File
@@ -208,9 +208,6 @@
light_mask = "wardrobe-light-mask"
light_color = LIGHT_COLOR_ELECTRIC_GREEN
/obj/machinery/vending/clothing/canLoadItem(obj/item/I,mob/user)
return (I.type in products)
/obj/item/vending_refill/clothing
machine_name = "ClothesMate"
icon_state = "refill_clothes"
-3
View File
@@ -9,9 +9,6 @@
panel_type = "panel19"
light_mask = "wardrobe-light-mask"
/obj/machinery/vending/wardrobe/canLoadItem(obj/item/I,mob/user)
return (I.type in products)
/obj/machinery/vending/wardrobe/sec_wardrobe
name = "\improper SecDrobe"
desc = "A vending machine for security and security-related clothing!"