From f875218284b235c9e61559f606523d55611e36f0 Mon Sep 17 00:00:00 2001 From: Sneakyrat6 Date: Sat, 6 Mar 2021 03:48:52 -0500 Subject: [PATCH 1/4] Fixes material component --- code/datums/components/material_container.dm | 54 +++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/code/datums/components/material_container.dm b/code/datums/components/material_container.dm index 7adc634621..e1886e2180 100644 --- a/code/datums/components/material_container.dm +++ b/code/datums/components/material_container.dm @@ -83,6 +83,8 @@ set waitfor = FALSE var/requested_amount var/active_held = user.get_active_held_item() // differs from I when using TK + + //handle stacks specially if(istype(I, /obj/item/stack) && precise_insertion) var/atom/current_parent = parent var/obj/item/stack/S = I @@ -91,10 +93,18 @@ return if(QDELETED(I) || QDELETED(user) || QDELETED(src) || parent != current_parent || user.physical_can_use_topic(current_parent) < UI_INTERACTIVE || user.get_active_held_item() != active_held) return + var/amt = insert_stack(S, requested_amount) + if(S.singular_name) + to_chat(user, "You insert [amt] [S.singular_name]\s into [parent].") + else + to_chat(user, "You insert [amt] into [parent].") + return + 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) + + var/inserted = insert_item(I) if(inserted) to_chat(user, "You insert a material total of [inserted] into [parent].") qdel(I) @@ -103,8 +113,46 @@ else if(I == active_held) user.put_in_active_hand(I) +//Inserts a number of sheets from a stack, returns the amount of sheets used. +/datum/component/material_container/proc/insert_stack(obj/item/stack/S, amt, multiplier = 1) + if(isnull(amt)) + amt = S.amount + + if(amt <= 0) + return FALSE + + if(amt > S.amount) + amt = S.amount + + var/material_amt = get_item_material_amount(S) + if(!material_amt) + return FALSE + + //get max number of sheets we have room to add + var/mat_per_sheet = material_amt/S.amount + amt = min(amt, round((max_amount - total_amount) / (mat_per_sheet))) + if(!amt) + return FALSE + + //add the mats + for(var/MAT in materials) + materials[MAT] += S.mats_per_unit[MAT] * amt * multiplier + total_amount += S.mats_per_unit[MAT] * amt * multiplier + + //update last_inserted_id with mat making up majority of the stack + var/primary_mat + var/max_mat_value = 0 + for(var/MAT in materials) + if(S.mats_per_unit[MAT] > max_mat_value) + max_mat_value = S.mats_per_unit[MAT] + primary_mat = MAT + last_inserted_id = primary_mat + + S.use(amt) + return amt + /// Proc specifically for inserting items, returns the amount of materials entered. -/datum/component/material_container/proc/insert_item(obj/item/I, var/multiplier = 1, stack_amt) +/datum/component/material_container/proc/insert_item(obj/item/I, var/multiplier = 1) if(QDELETED(I)) return FALSE @@ -124,6 +172,7 @@ materials[MAT] += I.custom_materials[MAT] * multiplier total_amount += I.custom_materials[MAT] * multiplier if(I.custom_materials[MAT] > max_mat_value) + max_mat_value = I.custom_materials[MAT] primary_mat = MAT return primary_mat @@ -135,6 +184,7 @@ var/total_amount_saved = total_amount if(mat) materials[mat] += amt + total_amount += amt else for(var/i in materials) materials[i] += amt From 703567e59157de0d3d556a520d07857a38c668dd Mon Sep 17 00:00:00 2001 From: Sneakyrat6 Date: Sun, 7 Mar 2021 04:09:36 -0500 Subject: [PATCH 2/4] other fixes --- code/datums/components/material_container.dm | 53 ++++++++++-------- code/datums/components/remote_materials.dm | 6 +- code/game/mecha/mech_fabricator.dm | 2 +- code/modules/mining/machine_silo.dm | 4 +- .../modules/research/machinery/_production.dm | 2 +- .../research/machinery/circuit_imprinter.dm | 3 + code/modules/research/rdmachines.dm | 12 ++-- icons/obj/machines/research.dmi | Bin 32997 -> 32998 bytes icons/obj/robotics.dmi | Bin 8887 -> 8886 bytes 9 files changed, 48 insertions(+), 34 deletions(-) diff --git a/code/datums/components/material_container.dm b/code/datums/components/material_container.dm index e1886e2180..9e9d060ca5 100644 --- a/code/datums/components/material_container.dm +++ b/code/datums/components/material_container.dm @@ -79,39 +79,46 @@ user_insert(I, user) /// Proc used for when player inserts materials -/datum/component/material_container/proc/user_insert(obj/item/I, mob/living/user) +/datum/component/material_container/proc/user_insert(obj/item/I, mob/living/user, datum/component/remote_materials/remote = null) set waitfor = FALSE - var/requested_amount var/active_held = user.get_active_held_item() // differs from I when using TK + var/inserted = 0 //handle stacks specially - if(istype(I, /obj/item/stack) && precise_insertion) - var/atom/current_parent = parent + if(istype(I, /obj/item/stack)) + var/atom/current_parent = remote ? remote.parent : parent //is the user using a remote materials component? var/obj/item/stack/S = I - requested_amount = input(user, "How much do you want to insert?", "Inserting [S.singular_name]s") as num|null + + //try to get ammount to use + var/requested_amount + if(precise_insertion) + requested_amount = input(user, "How much do you want to insert?", "Inserting [S.singular_name]s") as num|null + else + requested_amount= S.amount + if(isnull(requested_amount) || (requested_amount <= 0)) return - if(QDELETED(I) || QDELETED(user) || QDELETED(src) || parent != current_parent || user.physical_can_use_topic(current_parent) < UI_INTERACTIVE || user.get_active_held_item() != active_held) + if(QDELETED(I) || QDELETED(user) || QDELETED(src) || user.get_active_held_item() != active_held) return - var/amt = insert_stack(S, requested_amount) - if(S.singular_name) - to_chat(user, "You insert [amt] [S.singular_name]\s into [parent].") - else - to_chat(user, "You insert [amt] into [parent].") - return + //are we still in range after the user input? + if((remote ? remote.parent : parent) != current_parent || user.physical_can_use_topic(current_parent) < UI_INTERACTIVE) + return + inserted = insert_stack(S, requested_amount) + else + if(!user.temporarilyRemoveItemFromInventory(I)) + to_chat(user, "[I] is stuck to you and cannot be placed into [parent].") + return + inserted = insert_item(I) + qdel(I) - if(!user.temporarilyRemoveItemFromInventory(I)) - to_chat(user, "[I] is stuck to you and cannot be placed into [parent].") - return - - var/inserted = insert_item(I) if(inserted) to_chat(user, "You insert a material total of [inserted] into [parent].") - qdel(I) if(after_insert) after_insert.Invoke(I, last_inserted_id, inserted) - else if(I == active_held) - user.put_in_active_hand(I) + if(remote && remote.after_insert) + remote.after_insert.Invoke(I, last_inserted_id, inserted) + //else if(I == active_held) + // user.put_in_active_hand(I) //Inserts a number of sheets from a stack, returns the amount of sheets used. /datum/component/material_container/proc/insert_stack(obj/item/stack/S, amt, multiplier = 1) @@ -134,10 +141,12 @@ if(!amt) return FALSE - //add the mats + //add the mats and keep track of how much was added + var/starting_total = total_amount for(var/MAT in materials) materials[MAT] += S.mats_per_unit[MAT] * amt * multiplier total_amount += S.mats_per_unit[MAT] * amt * multiplier + var/total_added = total_amount - starting_total //update last_inserted_id with mat making up majority of the stack var/primary_mat @@ -149,7 +158,7 @@ last_inserted_id = primary_mat S.use(amt) - return amt + return total_added /// Proc specifically for inserting items, returns the amount of materials entered. /datum/component/material_container/proc/insert_item(obj/item/I, var/multiplier = 1) diff --git a/code/datums/components/remote_materials.dm b/code/datums/components/remote_materials.dm index 01038c11d3..896f09034b 100644 --- a/code/datums/components/remote_materials.dm +++ b/code/datums/components/remote_materials.dm @@ -15,13 +15,15 @@ handles linking back and forth. var/category var/allow_standalone var/local_size = INFINITY + var/datum/callback/after_insert -/datum/component/remote_materials/Initialize(category, mapload, allow_standalone = TRUE, force_connect = FALSE) +/datum/component/remote_materials/Initialize(category, mapload, allow_standalone = TRUE, force_connect = FALSE, _after_insert) if (!isatom(parent)) return COMPONENT_INCOMPATIBLE src.category = category src.allow_standalone = allow_standalone + after_insert = _after_insert RegisterSignal(parent, COMSIG_PARENT_ATTACKBY, .proc/OnAttackBy) @@ -103,7 +105,7 @@ handles linking back and forth. return COMPONENT_NO_AFTERATTACK else if(silo && istype(I, /obj/item/stack)) - if(silo.remote_attackby(parent, user, I)) + if(silo.remote_attackby(parent, user, I, src)) return COMPONENT_NO_AFTERATTACK /datum/component/remote_materials/proc/on_hold() diff --git a/code/game/mecha/mech_fabricator.dm b/code/game/mecha/mech_fabricator.dm index 002753c5d4..bf85253cbd 100644 --- a/code/game/mecha/mech_fabricator.dm +++ b/code/game/mecha/mech_fabricator.dm @@ -65,7 +65,7 @@ /obj/machinery/mecha_part_fabricator/Initialize(mapload) stored_research = new - rmat = AddComponent(/datum/component/remote_materials, "mechfab", mapload && link_on_init) + rmat = AddComponent(/datum/component/remote_materials, "mechfab", mapload && link_on_init, _after_insert=CALLBACK(src, .proc/AfterMaterialInsert)) RefreshParts() //Recalculating local material sizes if the fab isn't linked return ..() diff --git a/code/modules/mining/machine_silo.dm b/code/modules/mining/machine_silo.dm index b0055204f9..34b349b198 100644 --- a/code/modules/mining/machine_silo.dm +++ b/code/modules/mining/machine_silo.dm @@ -47,7 +47,7 @@ GLOBAL_LIST_EMPTY(silo_access_logs) return ..() -/obj/machinery/ore_silo/proc/remote_attackby(obj/machinery/M, mob/user, obj/item/stack/I) +/obj/machinery/ore_silo/proc/remote_attackby(obj/machinery/M, mob/user, obj/item/stack/I, remote = null) var/datum/component/material_container/materials = GetComponent(/datum/component/material_container) // stolen from /datum/component/material_container/proc/OnAttackBy if(user.a_intent != INTENT_HELP) @@ -63,7 +63,7 @@ GLOBAL_LIST_EMPTY(silo_access_logs) return // assumes unlimited space... var/amount = I.amount - materials.user_insert(I, user) + materials.user_insert(I, user, remote) silo_log(M, "deposited", amount, "sheets", item_mats) return TRUE diff --git a/code/modules/research/machinery/_production.dm b/code/modules/research/machinery/_production.dm index 5a50120833..346c3399f6 100644 --- a/code/modules/research/machinery/_production.dm +++ b/code/modules/research/machinery/_production.dm @@ -27,7 +27,7 @@ stored_research = new host_research = SSresearch.science_tech update_research() - materials = AddComponent(/datum/component/remote_materials, "lathe", mapload) + materials = AddComponent(/datum/component/remote_materials, "lathe", mapload, _after_insert=CALLBACK(src, .proc/AfterMaterialInsert)) RefreshParts() /obj/machinery/rnd/production/Destroy() diff --git a/code/modules/research/machinery/circuit_imprinter.dm b/code/modules/research/machinery/circuit_imprinter.dm index b80e96a1e9..7a5e08624b 100644 --- a/code/modules/research/machinery/circuit_imprinter.dm +++ b/code/modules/research/machinery/circuit_imprinter.dm @@ -31,3 +31,6 @@ /obj/machinery/rnd/production/circuit_imprinter/offstation offstation_security_levels = FALSE circuit = /obj/item/circuitboard/machine/circuit_imprinter/offstation + +/obj/machinery/rnd/production/circuit_imprinter/AfterMaterialInsert() //doesnt use have an animation like lathes do + return diff --git a/code/modules/research/rdmachines.dm b/code/modules/research/rdmachines.dm index 2237284a64..f39f5b1584 100644 --- a/code/modules/research/rdmachines.dm +++ b/code/modules/research/rdmachines.dm @@ -94,13 +94,13 @@ ..() /obj/machinery/rnd/proc/AfterMaterialInsert(item_inserted, id_inserted, amount_inserted) - var/stack_name + var/mat_name if(istype(item_inserted, /obj/item/stack/ore/bluespace_crystal)) - stack_name = "bluespace" + mat_name = "bluespace" use_power(MINERAL_MATERIAL_AMOUNT / 10) else - var/obj/item/stack/S = item_inserted - stack_name = S.name + var/datum/material/M = id_inserted + mat_name = M.name use_power(min(1000, (amount_inserted / 100))) - add_overlay("protolathe_[stack_name]") - addtimer(CALLBACK(src, /atom/proc/cut_overlay, "protolathe_[stack_name]"), 10) + add_overlay("protolathe_[mat_name]") + addtimer(CALLBACK(src, /atom/proc/cut_overlay, "protolathe_[mat_name]"), 10) diff --git a/icons/obj/machines/research.dmi b/icons/obj/machines/research.dmi index 7dcd4e6bcb3409b82745f7560b169bde68a03a85..8f9594c5dcbbd4378de0e23dd1ddc91a08648e78 100644 GIT binary patch delta 567 zcmV-70?7U4fdb}%0+1ws9C}n(bVOxyV{&P5bZKvH004NLy;i|)qc9LX!&g}C)kFc3 zEj@5qrCR0C9`*;2gPmZl@mRJ=w)^#a$f~#t4o;OI%P5iF_|1DW9(Y9GUw&-g(B^d; zADK2BBr4Hrv5cb=r?x>Q%Ck6X7(X=j{Kr^g87k33&2`;zTk%$ZX)Z0(4{=1fHmF2t z9PKq}+4;9WqOxCzA(D?rW$QSiOptd}qUEB%ciwR%0MzGfl?Drf*oI9C>!ATIIAG}k z=dSoQzH-NrW+yJGm-ZltG2_(FpKLF1;A51AYw!rXCCdQ>y+4cL;^?~-x8$Lmv>;~? zv=bdOiqxLwz9m(Er-|fUJ42B`aEg>5rX@2tNaReq2qi6%mdkq;i&jJu@&1SDN_d=0 zmpw^}2WxDAx~EP~#U6YGG+^2~V5OmEzQLD0xh6j2nRcJ3rJ$5xI)VLuQq>1|r{Nd# zOxgUuiVeg2xRq-~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 Mon Sep 17 00:00:00 2001 From: Sneakyrat6 Date: Sun, 7 Mar 2021 04:13:18 -0500 Subject: [PATCH 3/4] removes code i commented out --- code/datums/components/material_container.dm | 2 -- 1 file changed, 2 deletions(-) diff --git a/code/datums/components/material_container.dm b/code/datums/components/material_container.dm index 9e9d060ca5..8e1ed523d7 100644 --- a/code/datums/components/material_container.dm +++ b/code/datums/components/material_container.dm @@ -117,8 +117,6 @@ after_insert.Invoke(I, last_inserted_id, inserted) if(remote && remote.after_insert) remote.after_insert.Invoke(I, last_inserted_id, inserted) - //else if(I == active_held) - // user.put_in_active_hand(I) //Inserts a number of sheets from a stack, returns the amount of sheets used. /datum/component/material_container/proc/insert_stack(obj/item/stack/S, amt, multiplier = 1) From 0db08088c4cb23d997f4c921ac3e948ff3cc9c91 Mon Sep 17 00:00:00 2001 From: Sneakyrat6 Date: Sun, 7 Mar 2021 22:43:55 -0500 Subject: [PATCH 4/4] Fixes material insertion animations not working when there is no silo --- code/datums/components/remote_materials.dm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/datums/components/remote_materials.dm b/code/datums/components/remote_materials.dm index 896f09034b..b1d23ea3a8 100644 --- a/code/datums/components/remote_materials.dm +++ b/code/datums/components/remote_materials.dm @@ -69,7 +69,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) + mat_container = parent.AddComponent(/datum/component/material_container, allowed_mats, local_size, allowed_types=/obj/item/stack, _after_insert = after_insert) /datum/component/remote_materials/proc/set_local_size(size) local_size = size