mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-05-13 02:31:46 +01:00
2922d36500
**1. Material Container Refactors** a. `/datum/component/material_container/proc/insert_item()` - Will now do stack spliting i.e. it will consume as many sheets from a stack as possible and leave out the rest, It was moved from a player interaction feature in `user_insert()` to this low level allowing many things to take advantage of it - Will now delete the item for you if it could salvage any materials from it, you don't have to do it explicitly anymore if insertion was successfull (i.e. this proc returns an non zero value) If you inserted a stack and not all of it's sheets were inserted from the above point then you still have to check it explicitly - Will now invoke `after_insert` if any materials were salvaged b. `datum/component/material_container/proc/user_insert() ` - Will now split the stack by the requested amount making precise insertion work again & Fixes #72288 - will now consume all contents inside of the object reccursively, this means items like ammo boxes will no longer have to adjust their custom materials based on how much ammo they contain because `user_insert()` will loop through all its contents and salvage the metal of every bullet inside the box contents so this means https://github.com/tgstation/tgstation/blob/9686971c76fb6300939c9c191c635d2a852a143c/code/modules/projectiles/boxes_magazines/_box_magazine.dm#L206 has been removed. **The Problem with this proc** take `/obj/item/ammo_box/foambox/riot` for example. it has 40 darts each having 1125 worth of iron, this proc will add the total iron of all the bullets to the box custom material so the box custom materials would become `5000(base iron of box. see the definition of /obj/item/ammo_box/foambox/riot) + 45000(40 bullets each having 1125 worth of iron) = 50000 iron` What happens when you throw this ammo box in an recycler? The recycler will recycle this box(Now 50000 worth of iron) AND the iron of each of it's 40 bullets thus yielding `50000(iron from box because of update_custom_materials()) + 45000(40 bullets each having 1125 worth of iron) = 95000 iron` ` because of this single proc we got `95000 - 50000 = 45000 extra iron` from thin air **The Solution?** Remove this proc and set a constant custom material value for the ammo box(it's now 5000 computed see code) AND allow the material container to loop through every bullet in the box and salvage iron from them. This would yield `5000(base iron of box. see the definition of /obj/item/ammo_box/foambox/riot) + 45000(40 bullets each having 1125 worth of iron) = 50000 iron` From both box & bullets combined and not just from the box alone Fixes #43570 Fixes #57548 This also allows you to do cool stuff like fill your bag with iron, glass, whatever and dump them in the autolathe/ore silo by attacking the machine with your bag rather than pulling out & inserting each item individually so hey convinience **2. Recycler patches** - Recycler will stop consuming items when it runs out of power mid recycling(which can happen if it recycles a large amount of items). It used to previously run through the list of items without breaking so even when power was lost, it still did it's job - Recycler will now Properly recycle all the contents inside an atom. **The Problem** Say we have 2 Items - Backpack - Glass sheet inside Backpack If we process the items in the following order while deleting each item that is processed first "Backpack" then "Glass Sheet" then when "Backpack" is fully recycled and "Deleted" since the "Glass Sheet" is inside the "Backpack" it get's deleted as well, so when we actually try to recycle the "Glass Sheet" next, nothing happens because it was deleted when we deleted the "Backpack". **The Solution** Recycle the items in the reverse order first recycle the "Glass Sheet" delete it & then the "Back Pack" so we don't deal with deleted items. So you should see more materials come out when you put stuff inside storage mediums & throw them in the recycler - Recycler will consume only half the power when it's deleting items that can't be recycled(no material was salvaged). just for convinience
159 lines
5.3 KiB
Plaintext
159 lines
5.3 KiB
Plaintext
/**********************Mineral stacking unit console**************************/
|
|
|
|
/obj/machinery/mineral/stacking_unit_console
|
|
name = "stacking machine console"
|
|
icon = 'icons/obj/machines/mining_machines.dmi'
|
|
icon_state = "console"
|
|
desc = "Controls a stacking machine... in theory."
|
|
density = FALSE
|
|
circuit = /obj/item/circuitboard/machine/stacking_unit_console
|
|
/// Connected stacking machine
|
|
var/obj/machinery/mineral/stacking_machine/machine
|
|
|
|
/obj/machinery/mineral/stacking_unit_console/Initialize(mapload)
|
|
. = ..()
|
|
machine = locate(/obj/machinery/mineral/stacking_machine) in view(2, src)
|
|
if (machine)
|
|
machine.console = src
|
|
|
|
/obj/machinery/mineral/stacking_unit_console/Destroy()
|
|
if(machine)
|
|
machine.console = null
|
|
machine = null
|
|
return ..()
|
|
|
|
/obj/machinery/mineral/stacking_unit_console/multitool_act(mob/living/user, obj/item/I)
|
|
if(!multitool_check_buffer(user, I))
|
|
return
|
|
var/obj/item/multitool/M = I
|
|
M.buffer = src
|
|
to_chat(user, span_notice("You store linkage information in [I]'s buffer."))
|
|
return TRUE
|
|
|
|
/obj/machinery/mineral/stacking_unit_console/ui_interact(mob/user, datum/tgui/ui)
|
|
ui = SStgui.try_update_ui(user, src, ui)
|
|
if(!ui)
|
|
ui = new(user, src, "StackingConsole", name)
|
|
ui.open()
|
|
|
|
/obj/machinery/mineral/stacking_unit_console/ui_data(mob/user)
|
|
var/list/data = list()
|
|
data["machine"] = machine ? TRUE : FALSE
|
|
data["stacking_amount"] = null
|
|
data["contents"] = list()
|
|
if(machine)
|
|
data["stacking_amount"] = machine.stack_amt
|
|
data["input_direction"] = dir2text(machine.input_dir)
|
|
data["output_direction"] = dir2text(machine.output_dir)
|
|
for(var/stack_type in machine.stack_list)
|
|
var/obj/item/stack/sheet/stored_sheet = machine.stack_list[stack_type]
|
|
if(stored_sheet.amount <= 0)
|
|
continue
|
|
data["contents"] += list(list(
|
|
"type" = stored_sheet.type,
|
|
"name" = capitalize(stored_sheet.name),
|
|
"amount" = stored_sheet.amount,
|
|
))
|
|
return data
|
|
|
|
/obj/machinery/mineral/stacking_unit_console/ui_act(action, list/params)
|
|
. = ..()
|
|
if(.)
|
|
return
|
|
|
|
switch(action)
|
|
if("release")
|
|
var/obj/item/stack/sheet/released_type = text2path(params["type"])
|
|
if(!released_type || !(initial(released_type.merge_type) in machine.stack_list))
|
|
return //someone tried to spawn materials by spoofing hrefs
|
|
var/obj/item/stack/sheet/inp = machine.stack_list[initial(released_type.merge_type)]
|
|
var/obj/item/stack/sheet/out = new inp.type(null, inp.amount)
|
|
inp.amount = 0
|
|
machine.unload_mineral(out)
|
|
return TRUE
|
|
if("rotate")
|
|
var/input = text2num(params["input"])
|
|
machine.rotate(input)
|
|
return TRUE
|
|
|
|
/**********************Mineral stacking unit**************************/
|
|
|
|
|
|
/obj/machinery/mineral/stacking_machine
|
|
name = "stacking machine"
|
|
icon = 'icons/obj/machines/mining_machines.dmi'
|
|
icon_state = "stacker"
|
|
desc = "A machine that automatically stacks acquired materials. Controlled by a nearby console."
|
|
density = TRUE
|
|
circuit = /obj/item/circuitboard/machine/stacking_machine
|
|
input_dir = EAST
|
|
output_dir = WEST
|
|
var/obj/machinery/mineral/stacking_unit_console/console
|
|
var/stk_types = list()
|
|
var/stk_amt = list()
|
|
var/stack_list[0] //Key: Type. Value: Instance of type.
|
|
var/stack_amt = 50 //amount to stack before releassing
|
|
var/datum/component/remote_materials/materials
|
|
var/force_connect = FALSE
|
|
///Proximity monitor associated with this atom, needed for proximity checks.
|
|
var/datum/proximity_monitor/proximity_monitor
|
|
|
|
/obj/machinery/mineral/stacking_machine/Initialize(mapload)
|
|
. = ..()
|
|
proximity_monitor = new(src, 1)
|
|
materials = AddComponent(/datum/component/remote_materials, "stacking", mapload, FALSE, (mapload && force_connect))
|
|
|
|
/obj/machinery/mineral/stacking_machine/Destroy()
|
|
if(console)
|
|
console.machine = null
|
|
console = null
|
|
materials = null
|
|
return ..()
|
|
|
|
/obj/machinery/mineral/stacking_machine/HasProximity(atom/movable/AM)
|
|
if(QDELETED(AM))
|
|
return
|
|
if(istype(AM, /obj/item/stack/sheet) && AM.loc == get_step(src, input_dir))
|
|
process_sheet(AM)
|
|
|
|
/obj/machinery/mineral/stacking_machine/multitool_act(mob/living/user, obj/item/multitool/M)
|
|
if(istype(M))
|
|
if(istype(M.buffer, /obj/machinery/mineral/stacking_unit_console))
|
|
console = M.buffer
|
|
console.machine = src
|
|
to_chat(user, span_notice("You link [src] to the console in [M]'s buffer."))
|
|
return TRUE
|
|
|
|
/obj/machinery/mineral/stacking_machine/proc/rotate(input)
|
|
if (input)
|
|
input_dir = turn(input_dir, 90)
|
|
else
|
|
output_dir = turn(output_dir, 90)
|
|
if (input_dir == output_dir)
|
|
rotate(input)
|
|
|
|
/obj/machinery/mineral/stacking_machine/proc/process_sheet(obj/item/stack/sheet/inp)
|
|
if(QDELETED(inp))
|
|
return
|
|
|
|
// Dump the sheets to the silo if attached
|
|
if(materials.silo && !materials.on_hold())
|
|
var/matlist = inp.custom_materials & materials.mat_container.materials
|
|
if (length(matlist))
|
|
var/inserted = materials.mat_container.insert_item(inp)
|
|
materials.silo_log(src, "collected", inserted, "sheets", matlist)
|
|
return
|
|
|
|
// No silo attached process to internal storage
|
|
var/key = inp.merge_type
|
|
var/obj/item/stack/sheet/storage = stack_list[key]
|
|
if(!storage) //It's the first of this sheet added
|
|
stack_list[key] = storage = new inp.type(src, 0)
|
|
storage.amount += inp.amount //Stack the sheets
|
|
qdel(inp)
|
|
|
|
while(storage.amount >= stack_amt) //Get rid of excessive stackage
|
|
var/obj/item/stack/sheet/out = new inp.type(null, stack_amt)
|
|
unload_mineral(out)
|
|
storage.amount -= stack_amt
|