Material Scanner circuit component (#62677)

* Material Scanner circuit component

* get_turf(src) to get_location()
This commit is contained in:
Ghom
2021-11-09 23:08:55 -05:00
committed by GitHub
parent eba4c36db7
commit 45e7aeda84
4 changed files with 51 additions and 0 deletions
@@ -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"
@@ -221,6 +221,7 @@
"comp_light",
"comp_list_literal",
"comp_logic",
"comp_matscanner",
"comp_mmi",
"comp_module",
"comp_multiplexer",
@@ -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)
+1
View File
@@ -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"