minor material_container args/vars refactor and Mk-honk shoes peeve. (#54863)

My original intention was just fixing an issue with the Mk-honk banana shoes but, considering I didn't want to add two new variables to a component with already lot of args and lengthy AddComponent() calls in term of text, I had to merge some TRUE/FALSE variable/args into the breakdown_flags bitfield (now named mat_container_flags) in the process.
This commit is contained in:
Ghom
2020-11-21 04:37:07 -03:00
committed by GitHub
parent bc55c332c8
commit 27d0e32b47
14 changed files with 97 additions and 45 deletions
+11 -2
View File
@@ -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.
+8
View File
@@ -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,
+40 -28
View File
@@ -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, "<span class='notice'>It has [amt] units of [lowertext(M.name)] stored.</span>")
for(var/I in materials)
var/datum/material/M = I
var/amt = materials[I]
if(amt)
examine_texts += "<span class='notice'>It has [amt] units of [lowertext(M.name)] stored.</span>"
/// 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, "<span class='warning'>[parent] won't accept [I]!</span>")
if(!(mat_container_flags & MATCONTAINER_SILENT))
to_chat(user, "<span class='warning'>[parent] won't accept [I]!</span>")
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, "<span class='warning'>[I] does not contain sufficient materials to be accepted by [parent].</span>")
return
if(!has_space(material_amount))
to_chat(user, "<span class='warning'>[parent] is full. Please remove materials from [parent] in order to insert more.</span>")
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, "<span class='warning'>[I] is stuck to you and cannot be placed into [parent].</span>")
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, "<span class='notice'>You insert a material total of [inserted] into [parent].</span>")
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
+5 -5
View File
@@ -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)
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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)
+13 -1
View File
@@ -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()
+1 -1
View File
@@ -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()
. = ..()
+1 -1
View File
@@ -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()
+12 -1
View File
@@ -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)
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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
@@ -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()
@@ -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 ..()