diff --git a/code/__DEFINES/cooldowns.dm b/code/__DEFINES/cooldowns.dm index bd13dcedf32..11c65df87f0 100644 --- a/code/__DEFINES/cooldowns.dm +++ b/code/__DEFINES/cooldowns.dm @@ -53,6 +53,7 @@ #define COOLDOWN_CIRCUIT_PATHFIND_SAME "circuit_pathfind_same" #define COOLDOWN_CIRCUIT_PATHFIND_DIF "circuit_pathfind_different" #define COOLDOWN_CIRCUIT_TARGET_INTERCEPT "circuit_target_intercept" +#define COOLDOWN_CIRCUIT_VIEW_SENSOR "circuit_view_sensor" // mob cooldowns #define COOLDOWN_YAWN_PROPAGATION "yawn_propagation_cooldown" diff --git a/code/modules/research/designs/wiremod_designs.dm b/code/modules/research/designs/wiremod_designs.dm index d88053acb34..98f4bc9a4d4 100644 --- a/code/modules/research/designs/wiremod_designs.dm +++ b/code/modules/research/designs/wiremod_designs.dm @@ -396,6 +396,11 @@ id = "comp_set_variable_trigger" build_path = /obj/item/circuit_component/variable/setter/trigger +/datum/design/component/view_sensor + name = "View Sensor Component" + id = "comp_view_sensor" + build_path = /obj/item/circuit_component/view_sensor + /datum/design/component/access_checker name = "Access Checker Component" id = "comp_access_checker" diff --git a/code/modules/research/techweb/all_nodes.dm b/code/modules/research/techweb/all_nodes.dm index c8ab320ba31..b4fb1e57744 100644 --- a/code/modules/research/techweb/all_nodes.dm +++ b/code/modules/research/techweb/all_nodes.dm @@ -304,6 +304,7 @@ "comp_trigonometry", "comp_typecast", "comp_typecheck", + "comp_view_sensor", "compact_remote_shell", "component_printer", "integrated_circuit", @@ -543,7 +544,7 @@ "stack_machine", "tesla_coil", "thermomachine", - "w-recycler", + "w-recycler", "emitter", "welding_goggles", "anomaly_refinery", diff --git a/code/modules/wiremod/components/sensors/view_sensor.dm b/code/modules/wiremod/components/sensors/view_sensor.dm new file mode 100644 index 00000000000..565f9fca325 --- /dev/null +++ b/code/modules/wiremod/components/sensors/view_sensor.dm @@ -0,0 +1,64 @@ +/** + * # View Sensor + * + * Returns all movable objects in view. + */ + +#define VIEW_SENSOR_RANGE 5 + +/obj/item/circuit_component/view_sensor + display_name = "View Sensor" + desc = "Outputs a list with all movable objects in it's view. Requires a shell." + category = "Sensor" + + circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL + + power_usage_per_input = 10 //Normal components have 1 + + /// The result from the output + var/datum/port/output/result + var/datum/port/output/cooldown + + var/see_invisible = SEE_INVISIBLE_LIVING + var/view_cooldown = 1 SECONDS + +/obj/item/circuit_component/view_sensor/populate_ports() + result = add_output_port("Result", PORT_TYPE_LIST(PORT_TYPE_ATOM)) + cooldown = add_output_port("Scan On Cooldown", PORT_TYPE_SIGNAL) + +/obj/item/circuit_component/view_sensor/get_ui_notices() + . = ..() + . += create_ui_notice("Scan Cooldown: [DisplayTimeText(view_cooldown)]", "orange", "stopwatch") + +/obj/item/circuit_component/view_sensor/input_received(datum/port/input/port) + if(TIMER_COOLDOWN_CHECK(parent, COOLDOWN_CIRCUIT_VIEW_SENSOR)) + result.set_output(null) + cooldown.set_output(COMPONENT_SIGNAL) + return + + if(!parent || !parent.shell) + result.set_output(null) + return + + if(!isturf(parent.shell.loc)) + if(isliving(parent.shell.loc)) + var/mob/living/owner = parent.shell.loc + if(parent.shell != owner.get_active_held_item() && parent.shell != owner.get_inactive_held_item()) + result.set_output(null) + return + else + result.set_output(null) + return + + var/object_list = list() + + for(var/atom/movable/target in view(5, get_turf(parent.shell))) + if(target.invisibility > see_invisible) + continue + + object_list += target + + result.set_output(object_list) + TIMER_COOLDOWN_START(parent, COOLDOWN_CIRCUIT_VIEW_SENSOR, view_cooldown) + +#undef VIEW_SENSOR_RANGE diff --git a/tgstation.dme b/tgstation.dme index 29c198d423b..0e3a4f58fb9 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -4337,6 +4337,7 @@ #include "code\modules\wiremod\components\ntnet\ntnet_send.dm" #include "code\modules\wiremod\components\sensors\pressuresensor.dm" #include "code\modules\wiremod\components\sensors\tempsensor.dm" +#include "code\modules\wiremod\components\sensors\view_sensor.dm" #include "code\modules\wiremod\components\string\concat.dm" #include "code\modules\wiremod\components\string\contains.dm" #include "code\modules\wiremod\components\string\textcase.dm"