diff --git a/code/__DEFINES/materials.dm b/code/__DEFINES/materials.dm index 4b678431e6a..ef6a35a9abc 100644 --- a/code/__DEFINES/materials.dm +++ b/code/__DEFINES/materials.dm @@ -10,9 +10,18 @@ /// Used to make a material initialize at roundstart. #define MATERIAL_INIT_MAPLOAD (1<<0) -// Breakdown flags used when decomposing alloys. Should be expanded upon and diversified once someone gets around to reworking recycling. +//Material Container Flags. +///If the container shows the amount of contained materials on examine. +#define MATCONTAINER_EXAMINE (1<<0) +///If the container cannot have materials inserted through attackby(). +#define MATCONTAINER_NO_INSERT (1<<1) +///if the user can insert mats into the container despite the intent. +#define MATCONTAINER_ANY_INTENT (1<<2) +///if the user won't receive a warning when attacking the container with an unallowed item. +#define MATCONTAINER_SILENT (1<<3) +// The following flags are for decomposing alloys. Should be expanded upon and diversified once someone gets around to reworking recycling. /// Can reduce an alloy into its component materials. -#define BREAKDOWN_ALLOYS (1<<0) +#define BREAKDOWN_ALLOYS (1<<4) /// Breakdown flags used by techfabs and circuit printers. #define BREAKDOWN_FLAGS_LATHE (BREAKDOWN_ALLOYS) /// Breakdown flags used by the ORM. diff --git a/code/_globalvars/bitfields.dm b/code/_globalvars/bitfields.dm index 6be57f7c127..f291e07e75f 100644 --- a/code/_globalvars/bitfields.dm +++ b/code/_globalvars/bitfields.dm @@ -167,6 +167,14 @@ DEFINE_BITFIELD(machine_stat, list( "NOPOWER" = NOPOWER, )) +DEFINE_BITFIELD(mat_container_flags, list( + "MATCONTAINER_EXAMINE" = MATCONTAINER_EXAMINE, + "MATCONTAINER_NO_INSERT" = MATCONTAINER_NO_INSERT, + "MATCONTAINER_ANY_INTENT" = MATCONTAINER_ANY_INTENT, + "MATCONTAINER_SILENT" = MATCONTAINER_SILENT, + "BREAKDOWN_ALLOYS" = BREAKDOWN_ALLOYS, +)) + DEFINE_BITFIELD(internal_damage, list( "MECHA_INT_FIRE" = MECHA_INT_FIRE, "MECHA_INT_TEMP_CONTROL" = MECHA_INT_TEMP_CONTROL, diff --git a/code/datums/components/material_container.dm b/code/datums/components/material_container.dm index 312c675bfca..010500d4adf 100644 --- a/code/datums/components/material_container.dm +++ b/code/datums/components/material_container.dm @@ -14,22 +14,20 @@ var/max_amount var/sheet_type var/list/materials //Map of key = material ref | Value = amount - var/show_on_examine var/disable_attackby var/list/allowed_typecache var/last_inserted_id var/precise_insertion = FALSE var/datum/callback/precondition var/datum/callback/after_insert - ///The material breakdown flags used when inserting items into this container. Used to reduce alloys to their components. - var/breakdown_flags + ///The material container flags. See __DEFINES/materials.dm. + var/mat_container_flags /// Sets up the proper signals and fills the list of materials with the appropriate references. -/datum/component/material_container/Initialize(list/mat_list, max_amt = 0, _show_on_examine = FALSE, list/allowed_types, datum/callback/_precondition, datum/callback/_after_insert, _disable_attackby, _breakdown_flags=NONE) +/datum/component/material_container/Initialize(list/mat_list, max_amt = 0, _mat_container_flags=NONE, list/allowed_types, datum/callback/_precondition, datum/callback/_after_insert) materials = list() max_amount = max(0, max_amt) - show_on_examine = _show_on_examine - disable_attackby = _disable_attackby + mat_container_flags = _mat_container_flags if(allowed_types) if(ispath(allowed_types) && allowed_types == /obj/item/stack) @@ -39,54 +37,68 @@ precondition = _precondition after_insert = _after_insert - breakdown_flags = _breakdown_flags - RegisterSignal(parent, COMSIG_PARENT_ATTACKBY, .proc/OnAttackBy) - RegisterSignal(parent, COMSIG_PARENT_EXAMINE, .proc/OnExamine) + if(!(mat_container_flags & MATCONTAINER_NO_INSERT)) + RegisterSignal(parent, COMSIG_PARENT_ATTACKBY, .proc/on_attackby) + if(mat_container_flags & MATCONTAINER_EXAMINE) + RegisterSignal(parent, COMSIG_PARENT_EXAMINE, .proc/on_examine) for(var/mat in mat_list) //Make the assoc list ref | amount var/datum/material/M = SSmaterials.GetMaterialRef(mat) materials[M] = 0 -/datum/component/material_container/proc/OnExamine(datum/source, mob/user) +/datum/component/material_container/vv_edit_var(var_name, var_value) + var/old_flags = mat_container_flags + . = ..() + if(var_name == NAMEOF(src, mat_container_flags) && parent) + if(!(old_flags & MATCONTAINER_EXAMINE) && mat_container_flags & MATCONTAINER_EXAMINE) + RegisterSignal(parent, COMSIG_PARENT_EXAMINE, .proc/on_examine) + else if(old_flags & MATCONTAINER_EXAMINE && !(mat_container_flags & MATCONTAINER_EXAMINE)) + UnregisterSignal(parent, COMSIG_PARENT_EXAMINE) + + if(old_flags & MATCONTAINER_NO_INSERT && !(mat_container_flags & MATCONTAINER_NO_INSERT)) + RegisterSignal(parent, COMSIG_PARENT_ATTACKBY, .proc/on_attackby) + else if(!(old_flags & MATCONTAINER_NO_INSERT) && mat_container_flags & MATCONTAINER_NO_INSERT) + UnregisterSignal(parent, COMSIG_PARENT_ATTACKBY) + + +/datum/component/material_container/proc/on_examine(datum/source, mob/user, list/examine_texts) SIGNAL_HANDLER - if(show_on_examine) - for(var/I in materials) - var/datum/material/M = I - var/amt = materials[I] - if(amt) - to_chat(user, "It has [amt] units of [lowertext(M.name)] stored.") + for(var/I in materials) + var/datum/material/M = I + var/amt = materials[I] + if(amt) + examine_texts += "It has [amt] units of [lowertext(M.name)] stored." /// Proc that allows players to fill the parent with mats -/datum/component/material_container/proc/OnAttackBy(datum/source, obj/item/I, mob/living/user) +/datum/component/material_container/proc/on_attackby(datum/source, obj/item/I, mob/living/user) SIGNAL_HANDLER var/list/tc = allowed_typecache - if(disable_attackby) - return - if(user.a_intent != INTENT_HELP) + if(!(mat_container_flags & MATCONTAINER_ANY_INTENT) && user.a_intent != INTENT_HELP) return if(I.item_flags & ABSTRACT) return if((I.flags_1 & HOLOGRAM_1) || (I.item_flags & NO_MAT_REDEMPTION) || (tc && !is_type_in_typecache(I, tc))) - to_chat(user, "[parent] won't accept [I]!") + if(!(mat_container_flags & MATCONTAINER_SILENT)) + to_chat(user, "[parent] won't accept [I]!") return . = COMPONENT_NO_AFTERATTACK var/datum/callback/pc = precondition if(pc && !pc.Invoke(user)) return - var/material_amount = get_item_material_amount(I, breakdown_flags) + var/material_amount = get_item_material_amount(I, mat_container_flags) if(!material_amount) to_chat(user, "[I] does not contain sufficient materials to be accepted by [parent].") return if(!has_space(material_amount)) to_chat(user, "[parent] is full. Please remove materials from [parent] in order to insert more.") return - user_insert(I, user, breakdown_flags) + user_insert(I, user, mat_container_flags) /// Proc used for when player inserts materials -/datum/component/material_container/proc/user_insert(obj/item/I, mob/living/user, breakdown_flags=src.breakdown_flags) +/datum/component/material_container/proc/user_insert(obj/item/I, mob/living/user, breakdown_flags = mat_container_flags) set waitfor = FALSE var/requested_amount var/active_held = user.get_active_held_item() // differs from I when using TK @@ -101,7 +113,7 @@ if(!user.temporarilyRemoveItemFromInventory(I)) to_chat(user, "[I] is stuck to you and cannot be placed into [parent].") return - var/inserted = insert_item(I, stack_amt = requested_amount, breakdown_flags=breakdown_flags) + var/inserted = insert_item(I, stack_amt = requested_amount, breakdown_flags= mat_container_flags) if(inserted) to_chat(user, "You insert a material total of [inserted] into [parent].") qdel(I) @@ -111,7 +123,7 @@ user.put_in_active_hand(I) /// Proc specifically for inserting items, returns the amount of materials entered. -/datum/component/material_container/proc/insert_item(obj/item/I, multiplier = 1, stack_amt, breakdown_flags=src.breakdown_flags) +/datum/component/material_container/proc/insert_item(obj/item/I, multiplier = 1, stack_amt, breakdown_flags = mat_container_flags) if(QDELETED(I)) return FALSE @@ -124,7 +136,7 @@ last_inserted_id = insert_item_materials(I, multiplier, breakdown_flags) return material_amount -/datum/component/material_container/proc/insert_item_materials(obj/item/I, multiplier = 1, breakdown_flags=src.breakdown_flags) +/datum/component/material_container/proc/insert_item_materials(obj/item/I, multiplier = 1, breakdown_flags = mat_container_flags) var/primary_mat var/max_mat_value = 0 var/list/item_materials = I.get_material_composition(breakdown_flags) @@ -314,7 +326,7 @@ ///returns the amount of material relevant to this container; if this container does not support glass, any glass in 'I' will not be taken into account -/datum/component/material_container/proc/get_item_material_amount(obj/item/I, breakdown_flags=src.breakdown_flags) +/datum/component/material_container/proc/get_item_material_amount(obj/item/I, breakdown_flags = mat_container_flags) if(!istype(I) || !I.custom_materials) return 0 var/material_amount = 0 diff --git a/code/datums/components/remote_materials.dm b/code/datums/components/remote_materials.dm index c2b9f13887d..f8ee6a830e9 100644 --- a/code/datums/components/remote_materials.dm +++ b/code/datums/components/remote_materials.dm @@ -16,15 +16,15 @@ handles linking back and forth. var/allow_standalone var/local_size = INFINITY ///Flags used when converting inserted materials into their component materials. - var/breakdown_flags = NONE + var/mat_container_flags = NONE -/datum/component/remote_materials/Initialize(category, mapload, allow_standalone = TRUE, force_connect = FALSE, breakdown_flags=NONE) +/datum/component/remote_materials/Initialize(category, mapload, allow_standalone = TRUE, force_connect = FALSE, mat_container_flags=NONE) if (!isatom(parent)) return COMPONENT_INCOMPATIBLE src.category = category src.allow_standalone = allow_standalone - src.breakdown_flags = breakdown_flags + src.mat_container_flags = mat_container_flags RegisterSignal(parent, COMSIG_PARENT_ATTACKBY, .proc/OnAttackBy) RegisterSignal(parent, COMSIG_ATOM_TOOL_ACT(TOOL_MULTITOOL), .proc/OnMultitool) @@ -72,7 +72,7 @@ handles linking back and forth. /datum/material/plastic, ) - mat_container = parent.AddComponent(/datum/component/material_container, allowed_mats, local_size, allowed_types=/obj/item/stack, _breakdown_flags=breakdown_flags) + mat_container = parent.AddComponent(/datum/component/material_container, allowed_mats, local_size, mat_container_flags, /obj/item/stack) /datum/component/remote_materials/proc/set_local_size(size) local_size = size @@ -92,7 +92,7 @@ handles linking back and forth. SIGNAL_HANDLER if (silo && istype(I, /obj/item/stack)) - if (silo.remote_attackby(parent, user, I, breakdown_flags)) + if (silo.remote_attackby(parent, user, I, mat_container_flags)) return COMPONENT_NO_AFTERATTACK /datum/component/remote_materials/proc/OnMultitool(datum/source, mob/user, obj/item/I) diff --git a/code/game/machinery/autolathe.dm b/code/game/machinery/autolathe.dm index b1eed4cbaf7..fa3b8c4dd9c 100644 --- a/code/game/machinery/autolathe.dm +++ b/code/game/machinery/autolathe.dm @@ -48,7 +48,7 @@ ) /obj/machinery/autolathe/Initialize() - AddComponent(/datum/component/material_container, SSmaterials.materialtypes_by_category[MAT_CATEGORY_RIGID], 0, TRUE, null, null, CALLBACK(src, .proc/AfterMaterialInsert)) + AddComponent(/datum/component/material_container, SSmaterials.materialtypes_by_category[MAT_CATEGORY_RIGID], 0, MATCONTAINER_EXAMINE, null, null, CALLBACK(src, .proc/AfterMaterialInsert)) . = ..() wires = new /datum/wires/autolathe(src) diff --git a/code/game/machinery/droneDispenser.dm b/code/game/machinery/droneDispenser.dm index 37ce6a51b15..4345c76a800 100644 --- a/code/game/machinery/droneDispenser.dm +++ b/code/game/machinery/droneDispenser.dm @@ -50,7 +50,7 @@ /obj/machinery/drone_dispenser/Initialize() . = ..() - var/datum/component/material_container/materials = AddComponent(/datum/component/material_container, list(/datum/material/iron, /datum/material/glass), MINERAL_MATERIAL_AMOUNT * MAX_STACK_SIZE * 2, TRUE, /obj/item/stack, _breakdown_flags=BREAKDOWN_FLAGS_DRONE_DISPENSER) + var/datum/component/material_container/materials = AddComponent(/datum/component/material_container, list(/datum/material/iron, /datum/material/glass), MINERAL_MATERIAL_AMOUNT * MAX_STACK_SIZE * 2, MATCONTAINER_EXAMINE|BREAKDOWN_FLAGS_DRONE_DISPENSER, /obj/item/stack) materials.insert_amount_mat(starting_amount) materials.precise_insertion = TRUE using_materials = list(/datum/material/iron = metal_cost, /datum/material/glass = glass_cost) diff --git a/code/game/machinery/recycler.dm b/code/game/machinery/recycler.dm index 6c755d98dc0..f94ea180053 100644 --- a/code/game/machinery/recycler.dm +++ b/code/game/machinery/recycler.dm @@ -19,7 +19,19 @@ /obj/machinery/recycler/Initialize() AddComponent(/datum/component/butchering/recycler, 1, amount_produced,amount_produced/5) - AddComponent(/datum/component/material_container, list(/datum/material/iron, /datum/material/glass, /datum/material/silver, /datum/material/plasma, /datum/material/gold, /datum/material/diamond, /datum/material/plastic, /datum/material/uranium, /datum/material/bananium, /datum/material/titanium, /datum/material/bluespace), INFINITY, FALSE, null, null, null, TRUE, _breakdown_flags=BREAKDOWN_FLAGS_RECYCLER) + var/list/allowed_materials = list(/datum/material/iron, + /datum/material/glass, + /datum/material/silver, + /datum/material/plasma, + /datum/material/gold, + /datum/material/diamond, + /datum/material/plastic, + /datum/material/uranium, + /datum/material/bananium, + /datum/material/titanium, + /datum/material/bluespace + ) + AddComponent(/datum/component/material_container, allowed_materials, INFINITY, MATCONTAINER_NO_INSERT|BREAKDOWN_FLAGS_RECYCLER) . = ..() update_icon() req_one_access = get_all_accesses() + get_all_centcom_access() diff --git a/code/game/machinery/sheetifier.dm b/code/game/machinery/sheetifier.dm index a5592bbc0c1..d388564aaae 100644 --- a/code/game/machinery/sheetifier.dm +++ b/code/game/machinery/sheetifier.dm @@ -13,7 +13,7 @@ /obj/machinery/sheetifier/Initialize() . = ..() - AddComponent(/datum/component/material_container, list(/datum/material/meat), MINERAL_MATERIAL_AMOUNT * MAX_STACK_SIZE * 2, TRUE, /obj/item/food/meat/slab, CALLBACK(src, .proc/CanInsertMaterials), CALLBACK(src, .proc/AfterInsertMaterials), _breakdown_flags=BREAKDOWN_FLAGS_SHEETIFIER) + AddComponent(/datum/component/material_container, list(/datum/material/meat), MINERAL_MATERIAL_AMOUNT * MAX_STACK_SIZE * 2, MATCONTAINER_EXAMINE|BREAKDOWN_FLAGS_SHEETIFIER, /obj/item/food/meat/slab, CALLBACK(src, .proc/CanInsertMaterials), CALLBACK(src, .proc/AfterInsertMaterials)) /obj/machinery/sheetifier/update_overlays() . = ..() diff --git a/code/modules/clothing/shoes/bananashoes.dm b/code/modules/clothing/shoes/bananashoes.dm index 28bbd8b969d..0d34acf075b 100644 --- a/code/modules/clothing/shoes/bananashoes.dm +++ b/code/modules/clothing/shoes/bananashoes.dm @@ -16,7 +16,7 @@ /obj/item/clothing/shoes/clown_shoes/banana_shoes/ComponentInitialize() . = ..() AddElement(/datum/element/update_icon_updates_onmob) - AddComponent(/datum/component/material_container, list(/datum/material/bananium), 200000, TRUE, /obj/item/stack) + AddComponent(/datum/component/material_container, list(/datum/material/bananium), 200000, MATCONTAINER_EXAMINE|MATCONTAINER_ANY_INTENT|MATCONTAINER_SILENT, /obj/item/stack) AddComponent(/datum/component/squeak, list('sound/items/bikehorn.ogg'=1), 75, falloff_exponent = 20) /obj/item/clothing/shoes/clown_shoes/banana_shoes/step_action() diff --git a/code/modules/mining/machine_processing.dm b/code/modules/mining/machine_processing.dm index 627626725b4..b484deb5a30 100644 --- a/code/modules/mining/machine_processing.dm +++ b/code/modules/mining/machine_processing.dm @@ -133,7 +133,18 @@ /obj/machinery/mineral/processing_unit/Initialize() . = ..() proximity_monitor = new(src, 1) - AddComponent(/datum/component/material_container, list(/datum/material/iron, /datum/material/glass, /datum/material/silver, /datum/material/gold, /datum/material/diamond, /datum/material/plasma, /datum/material/uranium, /datum/material/bananium, /datum/material/titanium, /datum/material/bluespace), INFINITY, TRUE, /obj/item/stack, _breakdown_flags=BREAKDOWN_FLAGS_ORE_PROCESSOR) + var/list/allowed_materials = list(/datum/material/iron, + /datum/material/glass, + /datum/material/silver, + /datum/material/gold, + /datum/material/diamond, + /datum/material/plasma, + /datum/material/uranium, + /datum/material/bananium, + /datum/material/titanium, + /datum/material/bluespace + ) + AddComponent(/datum/component/material_container, allowed_materials, INFINITY, MATCONTAINER_EXAMINE|BREAKDOWN_FLAGS_ORE_PROCESSOR, /obj/item/stack) stored_research = new /datum/techweb/specialized/autounlocking/smelter selected_material = SSmaterials.GetMaterialRef(/datum/material/iron) diff --git a/code/modules/mining/machine_redemption.dm b/code/modules/mining/machine_redemption.dm index a560bcc6481..50226f53552 100644 --- a/code/modules/mining/machine_redemption.dm +++ b/code/modules/mining/machine_redemption.dm @@ -28,7 +28,7 @@ /obj/machinery/mineral/ore_redemption/Initialize(mapload) . = ..() stored_research = new /datum/techweb/specialized/autounlocking/smelter - materials = AddComponent(/datum/component/remote_materials, "orm", mapload, breakdown_flags=BREAKDOWN_FLAGS_ORM) + materials = AddComponent(/datum/component/remote_materials, "orm", mapload, mat_container_flags=BREAKDOWN_FLAGS_ORM) /obj/machinery/mineral/ore_redemption/Destroy() QDEL_NULL(stored_research) diff --git a/code/modules/mining/machine_silo.dm b/code/modules/mining/machine_silo.dm index 20f8938f002..e1e9544fb7b 100644 --- a/code/modules/mining/machine_silo.dm +++ b/code/modules/mining/machine_silo.dm @@ -28,7 +28,7 @@ GLOBAL_LIST_EMPTY(silo_access_logs) /datum/material/bluespace, /datum/material/plastic, ) - AddComponent(/datum/component/material_container, materials_list, INFINITY, allowed_types=/obj/item/stack, _disable_attackby=TRUE) + AddComponent(/datum/component/material_container, materials_list, INFINITY, MATCONTAINER_NO_INSERT, /obj/item/stack) if (!GLOB.ore_silo_default && mapload && is_station_level(z)) GLOB.ore_silo_default = src diff --git a/code/modules/research/machinery/_production.dm b/code/modules/research/machinery/_production.dm index 495ee9e6d0c..a79f539b2df 100644 --- a/code/modules/research/machinery/_production.dm +++ b/code/modules/research/machinery/_production.dm @@ -21,7 +21,7 @@ matching_designs = list() cached_designs = list() update_designs() - materials = AddComponent(/datum/component/remote_materials, "lathe", mapload, breakdown_flags=BREAKDOWN_FLAGS_LATHE) + materials = AddComponent(/datum/component/remote_materials, "lathe", mapload, mat_container_flags=BREAKDOWN_FLAGS_LATHE) RefreshParts() /obj/machinery/rnd/production/Destroy() diff --git a/code/modules/vehicles/mecha/mech_fabricator.dm b/code/modules/vehicles/mecha/mech_fabricator.dm index d571d6861d3..a8ead6cba59 100644 --- a/code/modules/vehicles/mecha/mech_fabricator.dm +++ b/code/modules/vehicles/mecha/mech_fabricator.dm @@ -64,7 +64,7 @@ /obj/machinery/mecha_part_fabricator/Initialize(mapload) stored_research = SSresearch.science_tech - rmat = AddComponent(/datum/component/remote_materials, "mechfab", mapload && link_on_init, breakdown_flags=BREAKDOWN_FLAGS_LATHE) + rmat = AddComponent(/datum/component/remote_materials, "mechfab", mapload && link_on_init, mat_container_flags=BREAKDOWN_FLAGS_LATHE) RefreshParts() //Recalculating local material sizes if the fab isn't linked return ..()