Files
Bubberstation/code/modules/wiremod/components/atom/direction.dm
Joshua Kidder 3690bd3d8a Add distance output to direction circuit component, resizes several shells (#86577)
## About The Pull Request

The direction component outputs the direction of an entity if it's
within 7 tiles of the circuit. Since it already checks the distance, I
added distance as one of its outputs.

Besides that, I did a pass over the generics and shells and resized many
of them. Most I resized to be small or tiny, except for the airlock
shell, which I set to be bulky because it's a whole ass door. The shells
I didn't touch remain at 'normal' size.

1) All handheld shells set to small, compact remote set to tiny 
2) all components and the generic of the circuit set to tiny
3) drone shell set to small
4) airlock shell set to bulky
## Why It's Good For The Game

Returning the distance spares any would be circuiteers from having to do
a labyrinthine set of calculations to determine distance themselves.

Making most circuits more portable makes them more attractive for people
to tote around.
## Changelog
🆑 Bisar
qol: The 'direction' circuit component now also returns the distance of
its target.
balance: Most circuit shells and the generic component and generic
circuit have had their size reduced.
balance: The airlock circuit shell has had its size increased.
/🆑

---------

Co-authored-by: Metekillot <ubuntu@ip-172-26-7-23.us-east-2.compute.internal>
Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com>
2024-09-14 22:54:07 +00:00

70 lines
1.9 KiB
Plaintext

/**
* # Direction Component
*
* Return the direction of a mob relative to the component
*/
/obj/item/circuit_component/direction
display_name = "Get Direction"
desc = "A component that returns the direction of itself and an entity."
category = "Entity"
/// The input port
var/datum/port/input/input_port
/// The result from the output
var/datum/port/output/output
var/datum/port/output/distance
// Directions outputs
var/datum/port/output/north
var/datum/port/output/south
var/datum/port/output/east
var/datum/port/output/west
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
/// Maximum range for a valid direction to be returned
var/max_range = 7
/obj/item/circuit_component/direction/get_ui_notices()
. = ..()
. += create_ui_notice("Maximum Range: [max_range] tiles", "orange", "info")
/obj/item/circuit_component/direction/populate_ports()
input_port = add_input_port("Targeted Entity", PORT_TYPE_ATOM)
output = add_output_port("Direction", PORT_TYPE_STRING)
distance = add_output_port("Distance", PORT_TYPE_NUMBER)
north = add_output_port("North", PORT_TYPE_SIGNAL)
east = add_output_port("East", PORT_TYPE_SIGNAL)
south = add_output_port("South", PORT_TYPE_SIGNAL)
west = add_output_port("West", PORT_TYPE_SIGNAL)
/obj/item/circuit_component/direction/input_received(datum/port/input/port)
var/atom/object = input_port.value
if(!object)
return
var/turf/location = get_location()
var/measured_distance = get_dist(location, object)
if(object.z != location.z || measured_distance > max_range)
output.set_output(null)
return
var/direction = get_dir(location, get_turf(object))
output.set_output(dir2text(direction))
if(direction & NORTH)
north.set_output(COMPONENT_SIGNAL)
if(direction & SOUTH)
south.set_output(COMPONENT_SIGNAL)
if(direction & EAST)
east.set_output(COMPONENT_SIGNAL)
if(direction & WEST)
west.set_output(COMPONENT_SIGNAL)
distance.set_output(measured_distance)