Removes material breakdown flags, traits & miscellaneous fixes. (#80389)

## About The Pull Request
1. Removes material breakdown flags i.e. all flags with the format
`BREAKDOWN_XXX`. These flags do nothing, there are no special checks to
transform materials based on these flags, they are passed around just
because certain procs require them for syntax purposes only.

Apparently there were plans to make these flags do something special
from the comment

https://github.com/tgstation/tgstation/blob/302247c0d1e980478f59d9c497169290ee259887/code/__DEFINES/construction/material.dm#L43
But nobody got any ideas for years now. The only special thing we can do
with them now is remove them and reduce code clutter, so let's do that
    
The only flag that ever did something was the
`BREAKDOWN_INCLUDE_ALCHEMY` flag. This only worked when coupled together
with `TRAIT_MAT_TRANSMUTED` trait(which is only used by the reagent
metalgen) and when both this trait & flag are combined together... they
still do nothing

https://github.com/tgstation/tgstation/blob/302247c0d1e980478f59d9c497169290ee259887/code/game/atom/atom_materials.dm#L41-L42
Yup they cancel out each other to prevent returning an empty list, the
traits only job was to prevent materials from being recycled (like why?
what's the benefit of that? nothing) and the flag was meant to bypass
this restriction so both the trait & the flag cancel out each other
therefore doing nothing meaningful. Best remove them both and call it a
day.

2. Fixes an error in displaying number of sheets inserted into a mat
container when that sheet is made up of alloy materials. it would count
as 2 or more because it would take the sum of total material amount
inserted and not the actual sheets. That's fixed now.

3. Remote materials now properly respect the `MATCONTAINER_NO_INSERT`
flag

4. Adds helper proc to insert materials via the remote material
component with proper context

## Changelog
🆑
fix: mat container displays correct number of sheets inserted for alloy
materials.
fix: remote materials now properly respect the `MATCONTAINER_NO_INSERT`
flag.
code: removes material breakdown flags and related traits.
code: adds helper proc to insert materials via the remote material
component with proper context.
/🆑
This commit is contained in:
SyncIt21
2023-12-25 06:59:26 +05:30
committed by GitHub
parent 33780514d9
commit d36a5af64f
22 changed files with 92 additions and 120 deletions
@@ -30,13 +30,13 @@
/// Sets up the proper signals and fills the list of materials with the appropriate references.
/datum/component/material_container/Initialize(
list/init_mats,
max_amt = 0,
_mat_container_flags = NONE,
list/allowed_mats = init_mats,
list/allowed_items,
list/container_signals
)
list/init_mats,
max_amt = 0,
_mat_container_flags = NONE,
list/allowed_mats = init_mats,
list/allowed_items,
list/container_signals
)
if(!isatom(parent))
return COMPONENT_INCOMPATIBLE
@@ -133,17 +133,16 @@
* Arguments:
* - [source][/obj/item]: The source of the materials we are inserting.
* - multiplier: The multiplier for the materials extract from this item being inserted.
* - breakdown_flags: The breakdown bitflags that will be used to retrieve the materials from the source
* - context: the atom performing the operation, this is the last argument sent in COMSIG_MATCONTAINER_ITEM_CONSUMED
* and is used mostly for silo logging, the silo resends this signal on the context to give it a
* chance to process the item
*/
/datum/component/material_container/proc/insert_item_materials(obj/item/source, multiplier = 1, breakdown_flags = mat_container_flags, atom/context = parent)
/datum/component/material_container/proc/insert_item_materials(obj/item/source, multiplier = 1, atom/context = parent)
var/primary_mat
var/max_mat_value = 0
var/material_amount = 0
var/list/item_materials = source.get_material_composition(breakdown_flags)
var/list/item_materials = source.get_material_composition()
var/list/mats_consumed = list()
for(var/MAT in item_materials)
if(!can_hold_material(MAT))
@@ -200,17 +199,16 @@
* Arguments:
* - [weapon][obj/item]: the item you are trying to insert
* - multiplier: The multiplier for the materials being inserted
* - breakdown_flags: The breakdown bitflags that will be used to retrieve the materials from the source
* - context: the atom performing the operation, this is the last argument sent in COMSIG_MATCONTAINER_ITEM_CONSUMED and is used mostly for silo logging
*/
/datum/component/material_container/proc/insert_item(obj/item/weapon, multiplier = 1, breakdown_flags = mat_container_flags, atom/context = parent)
/datum/component/material_container/proc/insert_item(obj/item/weapon, multiplier = 1, atom/context = parent)
if(QDELETED(weapon))
return MATERIAL_INSERT_ITEM_NO_MATS
multiplier = CEILING(multiplier, 0.01)
var/obj/item/target = weapon
var/material_amount = OPTIMAL_COST(get_item_material_amount(target, breakdown_flags) * multiplier)
var/material_amount = OPTIMAL_COST(get_item_material_amount(target) * multiplier)
if(!material_amount)
return MATERIAL_INSERT_ITEM_NO_MATS
var/obj/item/stack/item_stack
@@ -224,7 +222,7 @@
if(!sheets_to_insert)
return MATERIAL_INSERT_ITEM_NO_SPACE
target = fast_split_stack(item_stack, sheets_to_insert)
material_amount = get_item_material_amount(target, breakdown_flags) * multiplier
material_amount = get_item_material_amount(target) * multiplier
material_amount = OPTIMAL_COST(material_amount)
//not enough space, time to bail
@@ -232,7 +230,7 @@
return MATERIAL_INSERT_ITEM_NO_SPACE
//do the insert
var/last_inserted_id = insert_item_materials(target, multiplier, breakdown_flags, context)
var/last_inserted_id = insert_item_materials(target, multiplier, context)
if(!isnull(last_inserted_id))
qdel(target) //item gone
return material_amount
@@ -254,10 +252,9 @@
* Arguments:
* * held_item - the item to insert
* * user - the mob inserting this item
* * breakdown_flags - how this item and all it's contents inside are broken down during insertion. This is unique to the machine doing the insertion
* * context - the atom performing the operation, this is the last argument sent in COMSIG_MATCONTAINER_ITEM_CONSUMED and is used mostly for silo logging
*/
/datum/component/material_container/proc/user_insert(obj/item/held_item, mob/living/user, breakdown_flags = mat_container_flags, atom/context = parent)
/datum/component/material_container/proc/user_insert(obj/item/held_item, mob/living/user, atom/context = parent)
set waitfor = FALSE
. = 0
@@ -342,7 +339,7 @@
if(!isstack(target_item) && !is_type_in_list(target_item, storage_items))
var/total_amount = 0
for(var/obj/item/weapon as anything in target_item.get_all_contents_type(/obj/item))
total_amount += get_item_material_amount(weapon, breakdown_flags)
total_amount += get_item_material_amount(weapon)
if(!has_space(total_amount))
if(!(mat_container_flags & MATCONTAINER_SILENT))
to_chat(user, span_warning("[parent] does not have enough space for [target_item]!"))
@@ -397,7 +394,7 @@
item_name = the_stack.singular_name
item_count = the_stack.amount
is_stack = TRUE
inserted = insert_item(target_item, 1, mat_container_flags, context)
inserted = insert_item(target_item, 1, context)
if(inserted > 0)
. += inserted
inserted /= SHEET_MATERIAL_AMOUNT // display units inserted as sheets for improved readability
@@ -418,11 +415,9 @@
//collect all messages to print later
var/list/status_data = chat_msgs["[MATERIAL_INSERT_ITEM_SUCCESS]"] || list()
var/list/item_data = status_data[item_name] || list()
item_data["count"] += item_count
item_data["amount"] += inserted
if(!is_stack) //count will match with amount so its not required
item_data["count"] += item_count
else
item_data["stack"] = TRUE
item_data["stack"] = is_stack
status_data[item_name] = item_data
chat_msgs["[MATERIAL_INSERT_ITEM_SUCCESS]"] = status_data
@@ -463,7 +458,8 @@
switch(text2num(status))
if(MATERIAL_INSERT_ITEM_SUCCESS) //no problems full item was consumed
if(chat_data["stack"])
to_chat(user, span_notice("[amount > 1 ? amount : ""] [item_name][amount > 1 ? "'s" : ""] was consumed by [parent]"))
var/sheets = min(count, amount) //minimum between sheets inserted vs sheets consumed(values differ for alloys)
to_chat(user, span_notice("[sheets > 1 ? sheets : ""] [item_name][sheets > 1 ? "'s" : ""] was consumed by [parent]"))
else
to_chat(user, span_notice("[count > 1 ? count : ""] [item_name][count > 1 ? "'s" : ""] worth [amount] sheets of material was consumed by [parent]"))
if(MATERIAL_INSERT_ITEM_NO_SPACE) //no space
@@ -539,13 +535,12 @@
*
* Arguments:
* - [I][obj/item]: the item whos materials must be retrieved
* - breakdown_flags: how this item must be broken down to retrieve its materials
*/
/datum/component/material_container/proc/get_item_material_amount(obj/item/I, breakdown_flags = mat_container_flags)
/datum/component/material_container/proc/get_item_material_amount(obj/item/I)
if(!istype(I) || !I.custom_materials)
return 0
var/material_amount = 0
var/list/item_materials = I.get_material_composition(breakdown_flags)
var/list/item_materials = I.get_material_composition()
for(var/MAT in item_materials)
if(!can_hold_material(MAT))
continue
@@ -750,7 +745,7 @@
return NONE
if((held_item.flags_1 & HOLOGRAM_1) || (held_item.item_flags & NO_MAT_REDEMPTION) || (allowed_item_typecache && !is_type_in_typecache(held_item, allowed_item_typecache)))
return NONE
var/list/item_materials = held_item.get_material_composition(mat_container_flags)
var/list/item_materials = held_item.get_material_composition()
if(!length(item_materials))
return NONE
for(var/material in item_materials)
@@ -35,7 +35,8 @@ handles linking back and forth.
var/connect_to_silo = FALSE
if(force_connect || (mapload && is_station_level(T.z)))
connect_to_silo = TRUE
RegisterSignal(parent, COMSIG_ATOM_ATTACKBY, TYPE_PROC_REF(/datum/component/remote_materials, SiloAttackBy))
if(!(mat_container_flags & MATCONTAINER_NO_INSERT))
RegisterSignal(parent, COMSIG_ATOM_ATTACKBY, TYPE_PROC_REF(/datum/component/remote_materials, SiloAttackBy))
if(mapload) // wait for silo to initialize during mapload
addtimer(CALLBACK(src, PROC_REF(_PrepareStorage), connect_to_silo))
@@ -132,7 +133,7 @@ handles linking back and forth.
return
if(silo)
mat_container.user_insert(target, user, mat_container_flags, parent)
mat_container.user_insert(target, user, parent)
return COMPONENT_NO_AFTERATTACK
@@ -170,7 +171,8 @@ handles linking back and forth.
silo.ore_connected_machines += src
silo.updateUsrDialog()
mat_container = new_container
RegisterSignal(parent, COMSIG_ATOM_ATTACKBY, TYPE_PROC_REF(/datum/component/remote_materials, SiloAttackBy))
if(!(mat_container_flags & MATCONTAINER_NO_INSERT))
RegisterSignal(parent, COMSIG_ATOM_ATTACKBY, TYPE_PROC_REF(/datum/component/remote_materials, SiloAttackBy))
to_chat(user, span_notice("You connect [parent] to [silo] from the multitool's buffer."))
return ITEM_INTERACT_BLOCKING
@@ -199,15 +201,19 @@ handles linking back and forth.
* - The parent is of type movable atom
* - A mat container is actually present
* - The silo in not on hold
* Arguments
* * check_hold - should we check if the silo is on hold
*/
/datum/component/remote_materials/proc/_can_use_resource()
/datum/component/remote_materials/proc/_can_use_resource(check_hold = TRUE)
PRIVATE_PROC(TRUE)
var/atom/movable/movable_parent = parent
if (!istype(movable_parent))
return FALSE
if (!mat_container) //no silolink & local storage not supported
movable_parent.say("No access to material storage, please contact the quartermaster.")
return FALSE
if(on_hold()) //silo on hold
if(check_hold && on_hold()) //silo on hold
movable_parent.say("Mineral access is on hold, please contact the quartermaster.")
return FALSE
return TRUE
@@ -254,3 +260,16 @@ handles linking back and forth.
drop_target = movable_parent.drop_location()
return mat_container.retrieve_sheets(eject_amount, material_ref, target = drop_target, context = parent)
/**
* Insert an item into the mat container, helper proc to insert items with the correct context
*
* Arguments
* * obj/item/weapon - the item you are trying to insert
* * multiplier - the multiplier applied on the materials consumed
*/
/datum/component/remote_materials/proc/insert_item(obj/item/weapon, multiplier)
if(!_can_use_resource(FALSE))
return MATERIAL_INSERT_ITEM_FAILURE
return mat_container.insert_item(weapon, multiplier, parent)