Mat container related refactors & patches (#80164)

## About The Pull Request
**1. Mat container `user_insert()` tweaks**
- Mat container will now skip over an item & its contents if that item
cannot be processed (not suitable for redemption or not an allowed type)
this is not only realistic(if an item has an tough outer shell you can't
crush it to access its contents) but also saves us computation time as
we can skip over contents quickly
- Mat container now properly respects the `MATCONTAINER_SILENT` flag
- You can now hit machines like autolathe, protolathe etc with iron
sheets (or any other material item type those machines accept) when in
combat mode rather than inserting them because it makes sense
- Mat container now has much reduced chat spam as it will sum up all the
items inserted, and the material collected rather than displaying them
individually.
![Screenshot
(365)](https://github.com/tgstation/tgstation/assets/110812394/1ff444c6-cb0d-4a15-bfd6-71b9e8dcce5a)
Much improved readability and overall faster as we do much less
`to_chat()` calls

**2. ORM Tweaks** 
- Fixes https://github.com/Skyrat-SS13/Skyrat-tg/issues/25329 .

ORM now generates points correctly always, regardless of how the ore is
inserted be it
  
  - Via hand
  - Thrown at the ORM
  - Ore Box
  - Some other bag containing ore

Points will always be generated at a common proc so no more checking
every inlet on how the ore enters the machine. Once the silo receives
the material it will inform the ORM about it, so it does not have to
check itself therefore reducing code bloat.

## Changelog
🆑
fix: ORM will generate points regardless of how the ore enters it.
fix: Machines like autolathe, techfab etc can now be hit with iron
sheets (or any other material item type those machines accept) when in
combat mode rather than inserting them because it makes sense.
fix: Mat container won't display chats fully if the
`MATCONTAINER_SILENT` flag is passed.
refactor: Machines like autolathe, techfab etc now display summed up
material inserts to chats rather than each item individually. Also, will
skip items & its contents if it cannot be processed thus saving time
/🆑

---------

Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com>
This commit is contained in:
SyncIt21
2023-12-14 15:12:04 +01:00
committed by GitHub
co-authored by Ghom
parent 32fb42d19e
commit 27635e7640
4 changed files with 241 additions and 179 deletions
+29 -53
View File
@@ -58,6 +58,8 @@
mat_container_flags = BREAKDOWN_FLAGS_ORM \
)
RegisterSignal(src, COMSIG_MATCONTAINER_ITEM_CONSUMED, TYPE_PROC_REF(/obj/machinery/mineral/ore_redemption, redeem_points))
/obj/machinery/mineral/ore_redemption/Destroy()
stored_research = null
materials = null
@@ -68,34 +70,12 @@
if(panel_open)
. += span_notice("Alt-click to rotate the input and output direction.")
/// Turns ore into its refined type, and sends it to its material container
/obj/machinery/mineral/ore_redemption/proc/smelt_ore(obj/item/stack/ore/gathered_ore)
if(QDELETED(gathered_ore))
return
var/datum/component/material_container/mat_container = materials.mat_container
if (!mat_container)
return
if(gathered_ore.refined_type == null)
return
/obj/machinery/mineral/ore_redemption/proc/redeem_points(obj/machinery/mineral/ore_redemption/machine, container, obj/item/stack/ore/gathered_ore)
SIGNAL_HANDLER
var/material_amount = mat_container.get_item_material_amount(gathered_ore, BREAKDOWN_FLAGS_ORM)
if(!material_amount)
qdel(gathered_ore) //no materials, incinerate it
else if(!mat_container.has_space(material_amount * gathered_ore.amount)) //if there is no space, eject it
unload_mineral(gathered_ore)
else
var/ore_amount = gathered_ore.amount
var/ore_points= gathered_ore.points
var/refined_type = gathered_ore?.refined_type
if(mat_container.insert_item(gathered_ore, ore_multiplier, breakdown_flags = BREAKDOWN_FLAGS_ORM, context = src) > 0) //increase points only if insertion was successfull
if(refined_type)
points += ore_points * point_upgrade * ore_amount
SEND_SIGNAL(src, COMSIG_ORM_COLLECTED_ORE)
if(istype(gathered_ore) && gathered_ore.refined_type)
points += gathered_ore.points * point_upgrade * gathered_ore.amount
/// Returns the amount of a specific alloy design, based on the accessible materials
/obj/machinery/mineral/ore_redemption/proc/can_smelt_alloy(datum/design/D)
@@ -124,11 +104,6 @@
return build_amount
/// Smelts the passed ores one by one
/obj/machinery/mineral/ore_redemption/proc/process_ores(list/ores_to_process)
for(var/ore in ores_to_process)
smelt_ore(ore)
/// Sends a message to the request consoles that signed up for ore updates
/obj/machinery/mineral/ore_redemption/proc/send_console_message()
var/datum/component/material_container/mat_container = materials.mat_container
@@ -169,15 +144,27 @@
if(!materials.mat_container || panel_open || !powered())
return
//gethering the ore
var/list/obj/item/stack/ore/ore_list = list()
if(istype(target, /obj/structure/ore_box))
var/obj/structure/ore_box/box = target
process_ores(box.contents)
for(var/obj/item/stack/ore/ore_item in box.contents)
ore_list += ore_item
else if(istype(target, /obj/item/stack/ore))
var/obj/item/stack/ore/O = target
smelt_ore(O)
ore_list += target
else
return
//smelting the ore
for(var/obj/item/stack/ore/gathered_ore as anything in ore_list)
if(isnull(gathered_ore.refined_type))
continue
if(materials.mat_container.insert_item(gathered_ore, ore_multiplier, breakdown_flags = BREAKDOWN_FLAGS_ORM, context = src) <= 0)
unload_mineral(gathered_ore) //if rejected unload
SEND_SIGNAL(src, COMSIG_ORM_COLLECTED_ORE)
if(!console_notify_timer)
// gives 5 seconds for a load of ores to be sucked up by the ORM before it sends out request console notifications. This should be enough time for most deposits that people make
console_notify_timer = addtimer(CALLBACK(src, PROC_REF(send_console_message)), 5 SECONDS)
@@ -191,28 +178,17 @@
else
unregister_input_turf() // someone just un-wrenched us, unregister the turf
/obj/machinery/mineral/ore_redemption/wrench_act(mob/living/user, obj/item/tool)
. = ..()
default_unfasten_wrench(user, tool)
/obj/machinery/mineral/ore_redemption/screwdriver_act(mob/living/user, obj/item/tool)
default_deconstruction_screwdriver(user, "ore_redemption-open", "ore_redemption", tool)
return ITEM_INTERACT_SUCCESS
/obj/machinery/mineral/ore_redemption/attackby(obj/item/W, mob/user, params)
if(default_deconstruction_screwdriver(user, "ore_redemption-open", "ore_redemption", W))
return
if(default_deconstruction_crowbar(W))
return
/obj/machinery/mineral/ore_redemption/crowbar_act(mob/living/user, obj/item/tool)
default_deconstruction_crowbar(tool)
return ITEM_INTERACT_SUCCESS
if(!powered())
return ..()
var/obj/item/stack/ore/O = W
if(istype(O))
if(isnull(O.refined_type))
to_chat(user, span_warning("[O] has already been refined!"))
return
smelt_ore(O)
return TRUE
return ..()
/obj/machinery/mineral/ore_redemption/wrench_act(mob/living/user, obj/item/tool)
default_unfasten_wrench(user, tool)
return ITEM_INTERACT_SUCCESS
/obj/machinery/mineral/ore_redemption/AltClick(mob/living/user)
. = ..()
+4 -2
View File
@@ -39,7 +39,7 @@ GLOBAL_LIST_EMPTY(silo_access_logs)
materials_list, \
INFINITY, \
container_signals = list( \
COMSIG_MATCONTAINER_ITEM_CONSUMED = TYPE_PROC_REF(/obj/machinery/ore_silo, log_item_consumed), \
COMSIG_MATCONTAINER_ITEM_CONSUMED = TYPE_PROC_REF(/obj/machinery/ore_silo, on_item_consumed), \
COMSIG_MATCONTAINER_SHEETS_RETRIEVED = TYPE_PROC_REF(/obj/machinery/ore_silo, log_sheets_ejected), \
), \
allowed_items = /obj/item/stack \
@@ -59,11 +59,13 @@ GLOBAL_LIST_EMPTY(silo_access_logs)
return ..()
/obj/machinery/ore_silo/proc/log_item_consumed(datum/component/material_container/container, obj/item/item_inserted, last_inserted_id, mats_consumed, amount_inserted, atom/context)
/obj/machinery/ore_silo/proc/on_item_consumed(datum/component/material_container/container, obj/item/item_inserted, last_inserted_id, mats_consumed, amount_inserted, atom/context)
SIGNAL_HANDLER
silo_log(context, "deposited", amount_inserted, item_inserted.name, mats_consumed)
SEND_SIGNAL(context, COMSIG_MATCONTAINER_ITEM_CONSUMED, container, item_inserted, last_inserted_id, mats_consumed, amount_inserted)
/obj/machinery/ore_silo/proc/log_sheets_ejected(datum/component/material_container/container, obj/item/stack/sheet/sheets, atom/context)
SIGNAL_HANDLER