Add some 'lossy' smartfridges and options

This commit is contained in:
Aronai Sieyes
2021-05-13 18:39:32 -04:00
parent f0ddc3b8b8
commit 7ff1861528
6 changed files with 58 additions and 10 deletions
@@ -25,6 +25,13 @@
store_per_type = TRUE
target_type = /obj/machinery/smartfridge/sheets
var/stacks_go_missing = FALSE // Variable rate depletion of stacks inter-round
/datum/persistent/storage/smartfridge/sheet_storage/lossy
name = "sheet_storage_lossy"
max_storage = 250
stacks_go_missing = TRUE
/datum/persistent/storage/smartfridge/sheet_storage/generate_items(var/list/L)
. = list()
for(var/obj/item/stack/material/S as anything in L)
@@ -32,13 +39,34 @@
log_debug("Warning: Sheet_storage persistent datum tried to create [S]")
continue
var/count = L[S]
while(count > 0)
S = new S
S.amount = min(count, S.get_max_amount())
count -= S.get_amount()
. += S
// Skip entire stack if we hit the chance
if(prob(go_missing_chance))
continue
var/count = L[S]
var/obj/item/stack/material/inst = S
var/max_amount = initial(inst.max_amount)
// Delete some stacks if we want
if(stacks_go_missing)
var/fuzzy = rand(-5,5)
switch(count / max_amount)
if(0 to 1)
count -= 10+fuzzy // 1 stack or less, lose 10
if(1 to 10)
count -= max_amount+fuzzy // 1 to 10 stacks, lose a stack
if(10 to INFINITY)
count -= max_amount*3+fuzzy // 10+ stacks, lose 3 stacks
if(count <= 0)
qdel(inst)
continue
while(count > 0)
inst = new S
inst.amount = min(count, max_amount)
count -= inst.get_amount()
. += inst
/datum/persistent/storage/smartfridge/produce
@@ -47,6 +75,10 @@
store_per_type = FALSE
target_type = /obj/machinery/smartfridge/produce
/datum/persistent/storage/smartfridge/produce/lossy
name = "fruit_storage_lossy"
go_missing_chance = 12.5 // 10% loss between rounds
/datum/persistent/storage/smartfridge/produce/assemble_token(var/T)
var/list/subtok = splittext(T, " ")
if(subtok.len != 2)
@@ -74,6 +106,8 @@
. = list()
for(var/datum/stored_item/I in entry.item_records)
if(prob(go_missing_chance))
continue
if(LAZYLEN(I.instances))
var/obj/item/weapon/reagent_containers/food/snacks/grown/G = I.instances[1]
if(!istype(G))
+10 -2
View File
@@ -1,13 +1,19 @@
/datum/persistent/storage
entries_expire_at = 1
// Don't use these for storage persistence. If someone takes some sheets out and puts them back in mixed in with
// new sheets, how do you know the age of the stack? If you want sheets to 'decay', see go_missing_chance
entries_decay_at = 0
entry_decay_weight = 0
// // // //
tokens_per_line = PERSISTENCE_VARIABLE_TOKEN_LENGTH
var/max_storage = 0
var/store_per_type = FALSE // If true, will store up to max_storage for each type stored
var/target_type = null // Path of the thing that this expects to put stuff into
var/go_missing_chance = 0 // Chance an item will fail to be spawned in from persistence and need to be restocked
/datum/persistent/storage/SetFilename()
if(name)
filename = "data/persistent/storage/[lowertext(using_map.name)]-[lowertext(name)].txt"
@@ -26,7 +32,7 @@
return null
subtok[1] = text2path(subtok[1])
subtok[2] = text2num( subtok[2])
subtok[2] = text2num(subtok[2])
// Ensure we've found a token describing the quantity of a path
if(subtok.len != 2 || \
@@ -73,6 +79,8 @@
. = list()
for(var/path in L)
for(var/i in 1 to L[path])
if(prob(go_missing_chance))
continue
var/atom/A = create_item(path)
if(!QDELETED(A))
. += A