From 45e7aeda847dacbfebd22b103ab42a68b66f9567 Mon Sep 17 00:00:00 2001 From: Ghom <42542238+Ghommie@users.noreply.github.com> Date: Wed, 10 Nov 2021 05:08:55 +0100 Subject: [PATCH] Material Scanner circuit component (#62677) * Material Scanner circuit component * get_turf(src) to get_location() --- .../research/designs/wiremod_designs.dm | 5 +++ code/modules/research/techweb/all_nodes.dm | 1 + .../wiremod/components/atom/matscanner.dm | 44 +++++++++++++++++++ tgstation.dme | 1 + 4 files changed, 51 insertions(+) create mode 100644 code/modules/wiremod/components/atom/matscanner.dm diff --git a/code/modules/research/designs/wiremod_designs.dm b/code/modules/research/designs/wiremod_designs.dm index 35aa401eda1..aa141f03249 100644 --- a/code/modules/research/designs/wiremod_designs.dm +++ b/code/modules/research/designs/wiremod_designs.dm @@ -188,6 +188,11 @@ id = "comp_health" build_path = /obj/item/circuit_component/health +/datum/design/component/matscanner + name = "Material Scanner" + id = "comp_matscanner" + build_path = /obj/item/circuit_component/matscanner + /datum/design/component/split name = "Split Component" id = "comp_split" diff --git a/code/modules/research/techweb/all_nodes.dm b/code/modules/research/techweb/all_nodes.dm index 076e7656425..7146b5d8d6a 100644 --- a/code/modules/research/techweb/all_nodes.dm +++ b/code/modules/research/techweb/all_nodes.dm @@ -221,6 +221,7 @@ "comp_light", "comp_list_literal", "comp_logic", + "comp_matscanner", "comp_mmi", "comp_module", "comp_multiplexer", diff --git a/code/modules/wiremod/components/atom/matscanner.dm b/code/modules/wiremod/components/atom/matscanner.dm new file mode 100644 index 00000000000..bbc36bb9789 --- /dev/null +++ b/code/modules/wiremod/components/atom/matscanner.dm @@ -0,0 +1,44 @@ +/** + * # Material Scanner + * + * Returns the materials of an atom + */ +/obj/item/circuit_component/matscanner + display_name = "Material Scanner" + desc = "Outputs the material composition of the inputted entity." + category = "Entity" + + circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL + + // The entity to scan + var/datum/port/input/input_port + /// Whether we consider the materials alloys are made when scanning. + var/datum/port/input/break_down_alloys + /// The result from the output + var/datum/port/output/result + + var/max_range = 5 + +/obj/item/circuit_component/matscanner/get_ui_notices() + . = ..() + . += create_ui_notice("Maximum Range: [max_range] tiles", "orange", "info") + +/obj/item/circuit_component/matscanner/populate_ports() + input_port = add_input_port("Entity", PORT_TYPE_ATOM) + break_down_alloys = add_input_port("Break Down Alloys", PORT_TYPE_NUMBER) + result = add_output_port("Materials", PORT_TYPE_ASSOC_LIST(PORT_TYPE_STRING, PORT_TYPE_NUMBER)) + +/obj/item/circuit_component/matscanner/input_received(datum/port/input/port) + var/atom/entity = input_port.value + var/turf/location = get_location() + if(!istype(entity) || !IN_GIVEN_RANGE(location, entity, max_range)) + result.set_output(null) + return + var/breakdown_flags = BREAKDOWN_INCLUDE_ALCHEMY + if(break_down_alloys.value) + breakdown_flags |= BREAKDOWN_ALLOYS + var/list/composition = entity.get_material_composition(breakdown_flags) + var/list/composition_but_with_string_keys = list() + for(var/datum/material/material as anything in composition) + composition_but_with_string_keys[material.name] = composition[material] + result.set_output(composition_but_with_string_keys) diff --git a/tgstation.dme b/tgstation.dme index c79bc15bc5f..6a2acb9d6bf 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -3903,6 +3903,7 @@ #include "code\modules\wiremod\components\atom\gps.dm" #include "code\modules\wiremod\components\atom\health.dm" #include "code\modules\wiremod\components\atom\hear.dm" +#include "code\modules\wiremod\components\atom\matscanner.dm" #include "code\modules\wiremod\components\atom\pinpointer.dm" #include "code\modules\wiremod\components\atom\self.dm" #include "code\modules\wiremod\components\atom\species.dm"