From 9aed3b6a8f34fbc48cdb3ed0835b7b1247a3d35d Mon Sep 17 00:00:00 2001 From: SyncIt21 <110812394+SyncIt21@users.noreply.github.com> Date: Tue, 22 Aug 2023 03:53:01 +0530 Subject: [PATCH] General code maintenance for Mat container related stuff (#77671) 1. Removes `/obj/machinery/ore_silo/proc/remote_attackby()`. This proc calls `datum/component/material_container/user_insert()` anyway which performs all the checks necessary for inserting stuff into the ore silo and `/obj/machinery/ore_silo/proc/remote_attackby()` was just repeating its code & checks. So now inserting into the ore silo is directly handled by the mat container without this proxy proc making the operation slightly faster 2. Removed silo `attackby` code. Same operations can be done via `screwdriver_act` & `crowbar_act` procs much cleaner 3. The ore silo now hooks onto signals `COMSIG_MATCONTAINER_ITEM_CONSUMED` and `COMSIG_MATCONTAINER_SHEETS_RETRIVED` and logs into silo when they are triggered. This means when you insert/eject sheets from the silo the connected machine performing the operation no longer has to do the logging manually thus the proc `silo_log` has been removed from a lot of places ,reducing overall code size 4. A lot of stuff that use materials from the ore silo follow this pattern. i.e. They first use the materials from the silo and then log it via `silo_log` proc. This code pattern is repeated in a lot of places so let's just merge these 2 lines with some extra sanity checks into a single proc inside `remote_materials` itself. That's what was done and the number of places where you log manually into the silo has been removed further reducing code size everywhere. 5. Added auto doc & cleaned up some procs Since logging is now done by the ore silo directly, we need a way to pass the machine that is inserting items into the silo to the signal handlers of the ore silo [via the `context` var]. So other code changes elsewhere is because of this var --- .../dcs/signals/signals_material_container.dm | 4 +- .../components/material/material_container.dm | 73 ++++---- .../components/material/remote_materials.dm | 156 +++++++++++------- code/game/machinery/autolathe.dm | 2 +- code/game/machinery/sheetifier.dm | 4 +- code/game/objects/items/rcd/RHD.dm | 5 +- code/modules/mining/machine_redemption.dm | 16 +- code/modules/mining/machine_silo.dm | 51 ++---- code/modules/mining/machine_stacking.dm | 3 +- .../mob/living/silicon/robot/robot_model.dm | 3 +- code/modules/mod/modules/modules_general.dm | 2 +- .../modules/research/machinery/_production.dm | 3 +- .../modules/vehicles/mecha/mech_fabricator.dm | 6 +- .../modules/wiremod/core/component_printer.dm | 12 +- 14 files changed, 178 insertions(+), 162 deletions(-) diff --git a/code/__DEFINES/dcs/signals/signals_material_container.dm b/code/__DEFINES/dcs/signals/signals_material_container.dm index 3f9ab395175..c089ed4f67f 100644 --- a/code/__DEFINES/dcs/signals/signals_material_container.dm +++ b/code/__DEFINES/dcs/signals/signals_material_container.dm @@ -5,7 +5,7 @@ /// Called from datum/component/material_container/proc/user_insert() : (held_item, user) #define COMSIG_MATCONTAINER_PRE_USER_INSERT "matcontainer_pre_user_insert" #define MATCONTAINER_BLOCK_INSERT (1<<1) -/// Called from datum/component/material_container/proc/insert_item() : (target, last_inserted_id, material_amount, container) +/// Called from datum/component/material_container/proc/insert_item() : (target, last_inserted_id, mats_consumed, material_amount, context) #define COMSIG_MATCONTAINER_ITEM_CONSUMED "matcontainer_item_consumed" -/// Called from datum/component/material_container/proc/retrieve_sheets() : (sheets) +/// Called from datum/component/material_container/proc/retrieve_sheets() : (sheets, context) #define COMSIG_MATCONTAINER_SHEETS_RETRIVED "matcontainer_sheets_retrived" diff --git a/code/datums/components/material/material_container.dm b/code/datums/components/material/material_container.dm index 99769ce7996..6829a308553 100644 --- a/code/datums/components/material/material_container.dm +++ b/code/datums/components/material/material_container.dm @@ -131,19 +131,27 @@ * - [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 */ -/datum/component/material_container/proc/insert_item_materials(obj/item/source, multiplier = 1, breakdown_flags = mat_container_flags) +/datum/component/material_container/proc/insert_item_materials(obj/item/source, multiplier = 1, breakdown_flags = mat_container_flags, 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/mats_consumed = list() for(var/MAT in item_materials) if(!can_hold_material(MAT)) continue - materials[MAT] += OPTIMAL_COST(item_materials[MAT] * multiplier) + var/mat_amount = OPTIMAL_COST(item_materials[MAT] * multiplier) + materials[MAT] += mat_amount if(item_materials[MAT] > max_mat_value) max_mat_value = item_materials[MAT] primary_mat = MAT + mats_consumed[MAT] = mat_amount + material_amount += mat_amount + if(length(mats_consumed)) + SEND_SIGNAL(src, COMSIG_MATCONTAINER_ITEM_CONSUMED, source, primary_mat, mats_consumed, material_amount, context) return primary_mat //=================================================================================== @@ -188,15 +196,16 @@ * - [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) +/datum/component/material_container/proc/insert_item(obj/item/weapon, multiplier = 1, breakdown_flags = mat_container_flags, 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 = get_item_material_amount(target, breakdown_flags) * multiplier + var/material_amount = OPTIMAL_COST(get_item_material_amount(target, breakdown_flags) * multiplier) if(!material_amount) return MATERIAL_INSERT_ITEM_NO_MATS var/obj/item/stack/item_stack @@ -218,9 +227,8 @@ return MATERIAL_INSERT_ITEM_NO_SPACE //do the insert - var/last_inserted_id = insert_item_materials(target, multiplier, breakdown_flags) + var/last_inserted_id = insert_item_materials(target, multiplier, breakdown_flags, context) if(!isnull(last_inserted_id)) - SEND_SIGNAL(src, COMSIG_MATCONTAINER_ITEM_CONSUMED, target, last_inserted_id, material_amount, src) qdel(target) //item gone return material_amount else if(!isnull(item_stack) && item_stack != target) //insertion failed, merge the split stack back into the original @@ -242,8 +250,9 @@ * * 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) +/datum/component/material_container/proc/user_insert(obj/item/held_item, mob/living/user, breakdown_flags = mat_container_flags, atom/context = parent) set waitfor = FALSE . = 0 @@ -327,7 +336,7 @@ //insert the item var/item_name = target.name - var/inserted = insert_item(target, breakdown_flags = mat_container_flags) + var/inserted = insert_item(target, 1, mat_container_flags, context) if(inserted > 0) . += inserted inserted /= SHEET_MATERIAL_AMOUNT // display units inserted as sheets for improved readability @@ -564,44 +573,52 @@ * sheet_amt: number of sheets to extract * [material][datum/material]: type of sheets present in this container to extract * [target][atom]: drop location + * [atom][context]: context - the atom performing the operation, this is the last argument sent in COMSIG_MATCONTAINER_SHEETS_RETRIVED and is used mostly for silo logging */ -/datum/component/material_container/proc/retrieve_sheets(sheet_amt, datum/material/material, atom/target = null) +/datum/component/material_container/proc/retrieve_sheets(sheet_amt, datum/material/material, atom/target = null, atom/context = parent) + //do we support sheets of this material if(!material.sheet_type) return 0 //Add greyscale sheet handling here later - if(sheet_amt <= 0) + if(!can_hold_material(material)) return 0 + //requested amount greater than available amount or just an invalid value + sheet_amt = min(round(materials[material] / SHEET_MATERIAL_AMOUNT), sheet_amt) + if(sheet_amt <= 0) + return 0 + //auto drop location if(!target) var/atom/parent_atom = parent target = parent_atom.drop_location() - if(materials[material] < (sheet_amt * SHEET_MATERIAL_AMOUNT)) - sheet_amt = round(materials[material] / SHEET_MATERIAL_AMOUNT) - var/count = 0 - while(sheet_amt > MAX_STACK_SIZE) - var/obj/item/stack/sheet/new_sheets = new material.sheet_type(target, MAX_STACK_SIZE, null, list((material) = SHEET_MATERIAL_AMOUNT)) - count += MAX_STACK_SIZE - use_amount_mat(sheet_amt * SHEET_MATERIAL_AMOUNT, material) - sheet_amt -= MAX_STACK_SIZE - SEND_SIGNAL(src, COMSIG_MATCONTAINER_SHEETS_RETRIVED, new_sheets) - if(sheet_amt >= 1) - var/obj/item/stack/sheet/new_sheets = new material.sheet_type(target, sheet_amt, null, list((material) = SHEET_MATERIAL_AMOUNT)) - count += sheet_amt - use_amount_mat(sheet_amt * SHEET_MATERIAL_AMOUNT, material) - SEND_SIGNAL(src, COMSIG_MATCONTAINER_SHEETS_RETRIVED, new_sheets) - return count + if(!target) + return 0 + //eject sheets based on available amount after each iteration + var/count = 0 + while(sheet_amt > 0) + //create sheets in null space so it doesn't merge & delete itself + var/obj/item/stack/sheet/new_sheets = new material.sheet_type(null, min(sheet_amt, MAX_STACK_SIZE), null, list((material) = SHEET_MATERIAL_AMOUNT)) + count += new_sheets.amount + //use material & deduct work needed + use_amount_mat(new_sheets.amount * SHEET_MATERIAL_AMOUNT, material) + sheet_amt -= new_sheets.amount + //send signal + SEND_SIGNAL(src, COMSIG_MATCONTAINER_SHEETS_RETRIVED, new_sheets, context) + //now move to target so it gets merged + new_sheets.forceMove(target) + return count /** * Proc to get all the materials and dump them as sheets * * Arguments: * - target: drop location of the sheets + * - context: the atom which is ejecting the sheets. Used mostly in silo logging */ -/datum/component/material_container/proc/retrieve_all(target = null) +/datum/component/material_container/proc/retrieve_all(target = null, atom/context = parent) var/result = 0 for(var/MAT in materials) - var/amount = materials[MAT] - result += retrieve_sheets(amount2sheet(amount), MAT, target) + result += retrieve_sheets(amount2sheet(materials[MAT]), MAT, target, context) return result //============================================================================================ diff --git a/code/datums/components/material/remote_materials.dm b/code/datums/components/material/remote_materials.dm index 8d91ba7a75c..c9677ecec44 100644 --- a/code/datums/components/material/remote_materials.dm +++ b/code/datums/components/material/remote_materials.dm @@ -22,13 +22,6 @@ handles linking back and forth. ///Flags used when converting inserted materials into their component materials. var/mat_container_flags = NONE - //Internal vars - - ///Prepare storage when component is registered to parent. This allows local material container(if created) to be first in the component list so it gets GC'd properly - var/_prepare_on_register = FALSE - ///Are we trying to to connect to remote ore silo or not - var/_connect_to_silo = FALSE - /datum/component/remote_materials/Initialize(mapload, allow_standalone = TRUE, force_connect = FALSE, mat_container_flags = NONE) if (!isatom(parent)) return COMPONENT_INCOMPATIBLE @@ -36,23 +29,26 @@ handles linking back and forth. src.allow_standalone = allow_standalone src.mat_container_flags = mat_container_flags - RegisterSignal(parent, COMSIG_ATOM_ATTACKBY, PROC_REF(OnAttackBy)) RegisterSignal(parent, COMSIG_ATOM_TOOL_ACT(TOOL_MULTITOOL), PROC_REF(OnMultitool)) var/turf/T = get_turf(parent) - _connect_to_silo = FALSE + var/connect_to_silo = FALSE if(force_connect || (mapload && is_station_level(T.z))) - _connect_to_silo = TRUE + connect_to_silo = TRUE + 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)) + addtimer(CALLBACK(src, PROC_REF(_PrepareStorage), connect_to_silo)) else //directly register in round - _prepare_on_register = TRUE - -/datum/component/remote_materials/RegisterWithParent() - if(_prepare_on_register) - _PrepareStorage(_connect_to_silo) + _PrepareStorage(connect_to_silo) +/** + * Internal proc. prepares local storage if onnect_to_silo = FALSE + * + * Arguments + * connect_to_silo- if true connect to global silo. If not successfull then go to local storage + * only if allow_standalone = TRUE, else you a null mat_container + */ /datum/component/remote_materials/proc/_PrepareStorage(connect_to_silo) if (connect_to_silo) silo = GLOB.ore_silo_default @@ -112,7 +108,12 @@ handles linking back and forth. if (!silo && mat_container) mat_container.max_amount = size -// called if disconnected by ore silo UI or destruction +/** + * Disconnect this component from the remote silo + * + * Arguments + * old_silo- The silo we are trying to disconnect from + */ /datum/component/remote_materials/proc/disconnect_from(obj/machinery/ore_silo/old_silo) if (!old_silo || silo != old_silo) return @@ -122,12 +123,14 @@ handles linking back and forth. if (allow_standalone) _MakeLocal() -/datum/component/remote_materials/proc/OnAttackBy(datum/source, obj/item/I, mob/user) +///Insert mats into silo +/datum/component/remote_materials/proc/SiloAttackBy(datum/source, obj/item/target, mob/user) SIGNAL_HANDLER - if (silo && isstack(I)) - if (silo.remote_attackby(parent, user, I, mat_container_flags)) - return COMPONENT_NO_AFTERATTACK + if(silo) + mat_container.user_insert(target, user, mat_container_flags, parent) + + return COMPONENT_NO_AFTERATTACK /datum/component/remote_materials/proc/OnMultitool(datum/source, mob/user, obj/item/I) SIGNAL_HANDLER @@ -152,52 +155,87 @@ handles linking back and forth. silo.ore_connected_machines += src silo.updateUsrDialog() mat_container = silo.GetComponent(/datum/component/material_container) + 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 COMPONENT_BLOCK_TOOL_ATTACK -/datum/component/remote_materials/proc/check_z_level(obj/silo_to_check) - SIGNAL_HANDLER - if(!silo_to_check) - if(isnull(silo)) - return FALSE - silo_to_check = silo +/** + * Checks if the param silo is in the same level as this components parent i.e. connected machine, rcd, etc + * + * Arguments + * silo_to_check- Is this components parent in the same Z level as this param silo. If null + * then check this components connected silo + * + * Returns true if both are on the station or same z level + */ +/datum/component/remote_materials/proc/check_z_level(obj/silo_to_check = silo) + if(isnull(silo_to_check)) + return FALSE - var/turf/current_turf = get_turf(parent) - var/turf/silo_turf = get_turf(silo_to_check) - if(!is_valid_z_level(silo_turf, current_turf)) + return is_valid_z_level(get_turf(silo_to_check), get_turf(parent)) + +/// returns TRUE if this connection put on hold by the silo +/datum/component/remote_materials/proc/on_hold() + return check_z_level() ? silo.holds[src] : FALSE + +/** + * Internal proc to check if this connection can use any materials from the silo + * Returns true only if + * - The parent is of type movable atom + * - A mat container is actually present + * - The silo in not on hold + */ +/datum/component/remote_materials/proc/_can_use_resource() + 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 + movable_parent.say("Mineral access is on hold, please contact the quartermaster.") return FALSE return TRUE -/datum/component/remote_materials/proc/on_hold() - if(!check_z_level()) - return FALSE - return silo.holds[src] +/** + * Use materials from either the silo(if connected) or from the local storage. If silo then this action + * is logged else not e.g. action="build" & name="matter bin" means you are trying to build an matter bin + * + * Arguments + * [mats][list]- list of materials to use + * coefficient- each mat unit is scaled by this value then rounded. This value if usually your machine efficiency e.g. upgraded protolathe has reduced costs + * multiplier- each mat unit is scaled by this value then rounded after it is scaled by coefficient. This value is your print quatity e.g. printing multiple items + * action- For logging only. e.g. build, create, i.e. the action you are trying to perform + * name- For logging only. the design you are trying to build e.g. matter bin, etc. + */ +/datum/component/remote_materials/proc/use_materials(list/mats, coefficient = 1, multiplier = 1, action = "build", name = "design") + if(!_can_use_resource()) + return 0 -/datum/component/remote_materials/proc/silo_log(obj/machinery/M, action, amount, noun, list/mats) - if (silo) - silo.silo_log(M || parent, action, amount, noun, mats) + var/amount_consumed = mat_container.use_materials(mats, coefficient, multiplier) + + if (silo)//log only if silo is linked + var/list/scaled_mats = list() + for(var/i in mats) + scaled_mats[i] = OPTIMAL_COST(OPTIMAL_COST(mats[i] * coefficient) * multiplier) + silo.silo_log(parent, action, -multiplier, name, scaled_mats) + + return amount_consumed + +/** + * Ejects the given material ref and logs it + * + * Arguments + * [material_ref][datum/material]- The material type you are trying to eject + * eject_amount- how many sheets to eject + * [drop_target][atom]- optional where to drop the sheets. null means it is dropped at this components parent location + */ +/datum/component/remote_materials/proc/eject_sheets(datum/material/material_ref, eject_amount, atom/drop_target = null) + if(!_can_use_resource()) + return 0 -/// Ejects the given material ref and logs it, or says out loud the problem. -/datum/component/remote_materials/proc/eject_sheets(datum/material/material_ref, eject_amount) var/atom/movable/movable_parent = parent - if (!istype(movable_parent)) - return 0 + if(isnull(drop_target)) + drop_target = movable_parent.drop_location() - if (!mat_container) //no silolink & local storage not supported - movable_parent.say("No access to material storage, please contact the quartermaster.") - return 0 - if(!mat_container.can_hold_material(material_ref)) //material not supported by container - movable_parent.say("Invalid material requested.") - return 0 - if(eject_amount <= 0) //invalid amount - movable_parent.say("Invalid amount requested.") - return 0 - if(on_hold()) //silo on hold - movable_parent.say("Mineral access is on hold, please contact the quartermaster.") - return 0 - - var/count = mat_container.retrieve_sheets(eject_amount, material_ref, movable_parent.drop_location()) - var/list/matlist = list() - matlist[material_ref] = eject_amount - silo_log(parent, "ejected", -count, "sheets", matlist) - return count + return mat_container.retrieve_sheets(eject_amount, material_ref, target = drop_target, context = parent) diff --git a/code/game/machinery/autolathe.dm b/code/game/machinery/autolathe.dm index 6ad97655c4c..cf99119cf80 100644 --- a/code/game/machinery/autolathe.dm +++ b/code/game/machinery/autolathe.dm @@ -279,7 +279,7 @@ return SECONDARY_ATTACK_CALL_NORMAL -/obj/machinery/autolathe/proc/AfterMaterialInsert(obj/machinery/machine, obj/item/item_inserted, last_inserted_id, amount_inserted, container) +/obj/machinery/autolathe/proc/AfterMaterialInsert(container, obj/item/item_inserted, last_inserted_id, mats_consumed, amount_inserted, atom/context) SIGNAL_HANDLER if(ispath(item_inserted, /obj/item/stack/ore/bluespace_crystal)) diff --git a/code/game/machinery/sheetifier.dm b/code/game/machinery/sheetifier.dm index 57decf63ae4..30ce4860074 100644 --- a/code/game/machinery/sheetifier.dm +++ b/code/game/machinery/sheetifier.dm @@ -38,12 +38,12 @@ icon_state = "base_machine[busy_processing ? "_processing" : ""]" return ..() -/obj/machinery/sheetifier/proc/CanInsertMaterials(obj/machinery/machine, held_item, user) +/obj/machinery/sheetifier/proc/CanInsertMaterials(container, held_item, user) SIGNAL_HANDLER return busy_processing ? MATCONTAINER_BLOCK_INSERT : TRUE -/obj/machinery/sheetifier/proc/AfterInsertMaterials(obj/machinery/machine, item_inserted, id_inserted, amount_inserted, container) +/obj/machinery/sheetifier/proc/AfterInsertMaterials(container, item_inserted, id_inserted, mats_consumed, amount_inserted, atom/context) busy_processing = TRUE update_appearance() var/datum/material/last_inserted_material = id_inserted diff --git a/code/game/objects/items/rcd/RHD.dm b/code/game/objects/items/rcd/RHD.dm index c8a36d45953..92a6ab77641 100644 --- a/code/game/objects/items/rcd/RHD.dm +++ b/code/game/objects/items/rcd/RHD.dm @@ -181,10 +181,7 @@ if(user) balloon_alert(user, "not enough silo material!") return FALSE - - silo_mats.mat_container.use_amount_mat(amount * SILO_USE_AMOUNT, /datum/material/iron) - var/static/list/mats = list(GET_MATERIAL_REF(/datum/material/iron) = SILO_USE_AMOUNT) - silo_mats.silo_log(src, "consume", -amount, "build", mats) + silo_mats.use_materials(list(/datum/material/iron = SILO_USE_AMOUNT), multiplier = amount, action = "build", name = "consume") return TRUE ///shared data for rcd,rld & plumbing diff --git a/code/modules/mining/machine_redemption.dm b/code/modules/mining/machine_redemption.dm index c125671bcbf..4c0ca13dcd2 100644 --- a/code/modules/mining/machine_redemption.dm +++ b/code/modules/mining/machine_redemption.dm @@ -88,16 +88,12 @@ unload_mineral(gathered_ore) else - var/list/stack_mats = gathered_ore.get_material_composition(BREAKDOWN_FLAGS_ORM) - var/mats = stack_mats & mat_container.materials var/ore_amount = gathered_ore.amount var/ore_points= gathered_ore.points - var/ore_name = gathered_ore.name var/refined_type = gathered_ore?.refined_type - if(mat_container.insert_item(gathered_ore, ore_multiplier, breakdown_flags = BREAKDOWN_FLAGS_ORM) > 0) //increase points only if insertion was successfull + 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 - materials.silo_log(src, "smelted", ore_amount, ore_name, mats) SEND_SIGNAL(src, COMSIG_ORM_COLLECTED_ORE) @@ -356,12 +352,7 @@ var/desired = text2num(params["sheets"]) var/sheets_to_remove = round(min(desired, 50, stored_amount)) - - var/count = mat_container.retrieve_sheets(sheets_to_remove, mat, get_step(src, output_dir)) - var/list/mats = list() - mats[mat] = SHEET_MATERIAL_AMOUNT - materials.silo_log(src, "released", -count, "sheets", mats) - //Logging deleted for quick coding + materials.eject_sheets(mat, sheets_to_remove, get_step(src, output_dir)) return TRUE if("Smelt") if(!mat_container) @@ -379,8 +370,7 @@ var/amount = round(min(text2num(params["sheets"]), 50, can_smelt_alloy(alloy))) if(amount < 1) //no negative mats return - mat_container.use_materials(alloy.materials, multiplier = amount) - materials.silo_log(src, "released", -amount, "sheets", alloy.materials) + materials.use_materials(alloy.materials, action = "released", name = "sheets") var/output if(ispath(alloy.build_path, /obj/item/stack/sheet)) output = new alloy.build_path(src, amount) diff --git a/code/modules/mining/machine_silo.dm b/code/modules/mining/machine_silo.dm index 07b4c714915..04f0ca2706f 100644 --- a/code/modules/mining/machine_silo.dm +++ b/code/modules/mining/machine_silo.dm @@ -37,7 +37,10 @@ GLOBAL_LIST_EMPTY(silo_access_logs) /datum/component/material_container, \ materials_list, \ INFINITY, \ - MATCONTAINER_NO_INSERT, \ + container_signals = list( \ + COMSIG_MATCONTAINER_ITEM_CONSUMED = TYPE_PROC_REF(/obj/machinery/ore_silo, log_item_consumed), \ + COMSIG_MATCONTAINER_SHEETS_RETRIVED = TYPE_PROC_REF(/obj/machinery/ore_silo, log_sheets_ejected), \ + ), \ allowed_items = /obj/item/stack \ ) if (!GLOB.ore_silo_default && mapload && is_station_level(z)) @@ -55,39 +58,21 @@ GLOBAL_LIST_EMPTY(silo_access_logs) return ..() -/obj/machinery/ore_silo/proc/remote_attackby(obj/machinery/M, mob/living/user, obj/item/stack/I, breakdown_flags=NONE) - if(user.combat_mode) - return - if(I.item_flags & ABSTRACT) - return - if(!istype(I) || (I.flags_1 & HOLOGRAM_1) || (I.item_flags & NO_MAT_REDEMPTION)) - to_chat(user, span_warning("[M] won't accept [I]!")) - return - var/item_mats = materials.get_item_material_amount(I, breakdown_flags) - if(!item_mats) - to_chat(user, span_warning("[I] does not contain sufficient materials to be accepted by [M].")) - return - // assumes unlimited space... - var/amount = I.amount - materials.user_insert(I, user, breakdown_flags) - var/list/matlist = I.get_material_composition(breakdown_flags) - silo_log(M, "deposited", amount, I.name, matlist) - return TRUE +/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) + SIGNAL_HANDLER -/obj/machinery/ore_silo/attackby(obj/item/W, mob/user, params) - if(default_deconstruction_screwdriver(user, icon_state, icon_state, W)) - updateUsrDialog() - return - if(default_deconstruction_crowbar(W)) - return + silo_log(context, "deposited", amount_inserted, item_inserted.name, mats_consumed) - if(!powered()) - return ..() +/obj/machinery/ore_silo/proc/log_sheets_ejected(datum/component/material_container/container, obj/item/stack/sheet/sheets, atom/context) + SIGNAL_HANDLER - if (isstack(W)) - return remote_attackby(src, user, W) + silo_log(context, "ejected", -sheets.amount, "[sheets.singular_name]", sheets.custom_materials) - return ..() +/obj/machinery/ore_silo/screwdriver_act(mob/living/user, obj/item/tool) + return default_deconstruction_screwdriver(user, icon_state, icon_state, tool) + +/obj/machinery/ore_silo/crowbar_act(mob/living/user, obj/item/tool) + return default_deconstruction_crowbar(tool) /obj/machinery/ore_silo/ui_interact(mob/user) user.set_machine(src) @@ -169,10 +154,8 @@ GLOBAL_LIST_EMPTY(silo_access_logs) return TRUE else if(href_list["ejectsheet"]) var/datum/material/eject_sheet = locate(href_list["ejectsheet"]) - var/count = materials.retrieve_sheets(text2num(href_list["eject_amt"]), eject_sheet, drop_location()) - var/list/matlist = list() - matlist[eject_sheet] = SHEET_MATERIAL_AMOUNT * count - silo_log(src, "ejected", -count, "sheets", matlist) + var/amount = text2num(href_list["eject_amt"]) + materials.retrieve_sheets(amount, eject_sheet, drop_location()) return TRUE else if(href_list["page"]) log_page = text2num(href_list["page"]) || 1 diff --git a/code/modules/mining/machine_stacking.dm b/code/modules/mining/machine_stacking.dm index 537f6cab99d..d7381d48e66 100644 --- a/code/modules/mining/machine_stacking.dm +++ b/code/modules/mining/machine_stacking.dm @@ -145,8 +145,7 @@ 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) + materials.mat_container.insert_item(inp, context = src) return // No silo attached process to internal storage diff --git a/code/modules/mob/living/silicon/robot/robot_model.dm b/code/modules/mob/living/silicon/robot/robot_model.dm index 033d52a9622..29e82433500 100644 --- a/code/modules/mob/living/silicon/robot/robot_model.dm +++ b/code/modules/mob/living/silicon/robot/robot_model.dm @@ -188,9 +188,8 @@ if(!to_stock) //Nothing for us in the silo continue - storage_datum.energy += mat_container.use_amount_mat(to_stock, storage_datum.mat_type) + storage_datum.energy += charger.materials.use_materials(list(GET_MATERIAL_REF(storage_datum.mat_type) = to_stock), action = "resupplied", name = "units") charger.balloon_alert(robot, "+ [to_stock]u [initial(storage_datum.mat_type.name)]") - charger.materials.silo_log(charger, "resupplied", -1, "units", list(GET_MATERIAL_REF(storage_datum.mat_type) = to_stock)) playsound(charger, 'sound/weapons/gun/general/mag_bullet_insert.ogg', 50, vary = FALSE) return charger.balloon_alert(robot, "restock process complete") diff --git a/code/modules/mod/modules/modules_general.dm b/code/modules/mod/modules/modules_general.dm index 133bf25b833..757d952974e 100644 --- a/code/modules/mod/modules/modules_general.dm +++ b/code/modules/mod/modules/modules_general.dm @@ -835,7 +835,7 @@ balloon_alert(mod.wearer, "not enough material") playsound(src, 'sound/machines/buzz-sigh.ogg', 50, TRUE) -/obj/item/mod/module/recycler/proc/InsertSheets(obj/item/recycler, obj/item/stack/sheets) +/obj/item/mod/module/recycler/proc/InsertSheets(obj/item/recycler, obj/item/stack/sheets, atom/context) SIGNAL_HANDLER attempt_insert_storage(sheets) diff --git a/code/modules/research/machinery/_production.dm b/code/modules/research/machinery/_production.dm index 65cddf68c73..d607a5573a0 100644 --- a/code/modules/research/machinery/_production.dm +++ b/code/modules/research/machinery/_production.dm @@ -304,8 +304,7 @@ borg.cell.use(SILICON_LATHE_TAX) //consume materials - materials.mat_container.use_materials(design.materials, coefficient, print_quantity) - materials.silo_log(src, "built", -print_quantity, "[design.name]", design.materials) + materials.use_materials(design.materials, coefficient, print_quantity, "built", "[design.name]") for(var/reagent in design.reagents_list) reagents.remove_reagent(reagent, design.reagents_list[reagent] * print_quantity * coefficient) //produce item diff --git a/code/modules/vehicles/mecha/mech_fabricator.dm b/code/modules/vehicles/mecha/mech_fabricator.dm index 033378d496b..618ad33d1db 100644 --- a/code/modules/vehicles/mecha/mech_fabricator.dm +++ b/code/modules/vehicles/mecha/mech_fabricator.dm @@ -28,9 +28,6 @@ /// The job ID of the part currently being processed. This is used for ordering list items for the client UI. var/top_job_id = 0 - /// Reference to all materials used in the creation of the item being_built. - var/list/build_materials - /// Part currently stored in the Exofab. var/obj/item/stored_part @@ -221,12 +218,11 @@ say("Not enough resources. Processing stopped.") return FALSE - materials.use_materials(D.materials, component_coeff) + rmat.use_materials(D.materials, component_coeff, 1, "built", "[D.name]") being_built = D build_finish = world.time + get_construction_time_w_coeff(initial(D.construction_time)) build_start = world.time desc = "It's building \a [D.name]." - rmat.silo_log(src, "built", -1, "[D.name]", build_materials) return TRUE diff --git a/code/modules/wiremod/core/component_printer.dm b/code/modules/wiremod/core/component_printer.dm index 0671d347e58..cf791ffdad6 100644 --- a/code/modules/wiremod/core/component_printer.dm +++ b/code/modules/wiremod/core/component_printer.dm @@ -112,8 +112,7 @@ if (!materials.mat_container.has_materials(design.materials, efficiency_coeff)) return - materials.mat_container.use_materials(design.materials, efficiency_coeff) - materials.silo_log(src, "printed", -1, design.name, design.materials) + materials.use_materials(design.materials, efficiency_coeff, 1, "printed", "[design.name]") return new design.build_path(drop_location()) /obj/machinery/component_printer/ui_act(action, list/params) @@ -140,8 +139,8 @@ return TRUE balloon_alert_to_viewers("printed [design.name]") - materials.mat_container.use_materials(design.materials, efficiency_coeff) - materials.silo_log(src, "printed", -1, design.name, design.materials) + + materials.use_materials(design.materials, efficiency_coeff, 1, "printed", "[design.name]") var/atom/printed_design = new design.build_path(drop_location()) printed_design.pixel_x = printed_design.base_pixel_x + rand(-5, 5) printed_design.pixel_y = printed_design.base_pixel_y + rand(-5, 5) @@ -381,10 +380,9 @@ say("Not enough materials.") return TRUE - balloon_alert_to_viewers("printed [design["name"]]") - materials.mat_container.use_materials(design["materials"], efficiency_coeff) - materials.silo_log(src, "printed", -1, design["name"], design["materials"]) + materials.use_materials(design["materials"], efficiency_coeff, 1, design["name"], design["materials"]) print_module(design) + balloon_alert_to_viewers("printed [design["name"]]") if ("remove_mat") var/datum/material/material = locate(params["ref"]) var/amount = text2num(params["amount"])