[MIRROR] More circuit components. Restructures the circuit components folder to be more organised. (#6142)

* More circuit components. Restructures the circuit components folder to be more organised.

* Mirror!

Co-authored-by: Watermelon914 <37270891+Watermelon914@users.noreply.github.com>
Co-authored-by: Funce <funce.973@gmail.com>
This commit is contained in:
SkyratBot
2021-06-05 17:15:43 +12:00
committed by GitHub
co-authored by Watermelon914 Funce
parent 6e52d05e2e
commit cc5cf407b0
42 changed files with 630 additions and 106 deletions
@@ -0,0 +1,66 @@
/**
* # Direction Component
*
* Return the direction of a mob relative to the component
*/
/obj/item/circuit_component/direction
display_name = "Get Direction"
/// The input port
var/datum/port/input/input_port
/// The result from the output
var/datum/port/output/output
// 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/Initialize()
. = ..()
input_port = add_input_port("Organism", PORT_TYPE_ATOM)
output = add_output_port("Direction", PORT_TYPE_STRING)
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/Destroy()
input_port = null
output = null
return ..()
/obj/item/circuit_component/direction/input_received(datum/port/input/port)
. = ..()
if(.)
return
var/atom/object = input_port.input_value
if(!object)
return
var/turf/location = get_turf(src)
if(object.z != location.z || get_dist(location, object) > 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)
@@ -0,0 +1,39 @@
/**
* # GPS Component
*
* Return the location of this
*/
/obj/item/circuit_component/gps
display_name = "Internal GPS"
/// The result from the output
var/datum/port/output/x_pos
var/datum/port/output/y_pos
var/datum/port/output/z_pos
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
/obj/item/circuit_component/gps/Initialize()
. = ..()
x_pos = add_output_port("X", PORT_TYPE_NUMBER)
y_pos = add_output_port("Y", PORT_TYPE_NUMBER)
z_pos = add_output_port("Z", PORT_TYPE_NUMBER)
/obj/item/circuit_component/gps/Destroy()
x_pos = null
y_pos = null
z_pos = null
return ..()
/obj/item/circuit_component/gps/input_received(datum/port/input/port)
. = ..()
if(.)
return
var/turf/location = get_turf(src)
x_pos.set_output(location?.x)
y_pos.set_output(location?.y)
z_pos.set_output(location?.z)
@@ -0,0 +1,66 @@
/**
* # Get Health Component
*
* Return the health of a mob
*/
/obj/item/circuit_component/health
display_name = "Get Health"
/// The input port
var/datum/port/input/input_port
/// Brute damage
var/datum/port/output/brute
/// Burn damage
var/datum/port/output/burn
/// Toxin damage
var/datum/port/output/toxin
/// Oxyloss damage
var/datum/port/output/oxy
/// Health
var/datum/port/output/health
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
var/max_range = 5
/obj/item/circuit_component/health/Initialize()
. = ..()
input_port = add_input_port("Organism", PORT_TYPE_ATOM)
brute = add_output_port("Brute Damage", PORT_TYPE_NUMBER)
burn = add_output_port("Burn Damage", PORT_TYPE_NUMBER)
toxin = add_output_port("Toxin Damage", PORT_TYPE_NUMBER)
oxy = add_output_port("Suffocation Damage", PORT_TYPE_NUMBER)
health = add_output_port("Health", PORT_TYPE_NUMBER)
/obj/item/circuit_component/health/Destroy()
input_port = null
brute = null
burn = null
toxin = null
oxy = null
health = null
return ..()
/obj/item/circuit_component/health/input_received(datum/port/input/port)
. = ..()
if(.)
return
var/mob/living/organism = input_port.input_value
var/turf/current_turf = get_turf(src)
if(!istype(organism) || get_dist(current_turf, organism) > max_range || current_turf.z != organism.z)
brute.set_output(null)
burn.set_output(null)
toxin.set_output(null)
oxy.set_output(null)
health.set_output(null)
return
brute.set_output(organism.getBruteLoss())
burn.set_output(organism.getFireLoss())
toxin.set_output(organism.getToxLoss())
oxy.set_output(organism.getOxyLoss())
health.set_output(organism.health)
@@ -0,0 +1,43 @@
/**
* # Hear Component
*
* Listens for messages. Requires a shell.
*/
/obj/item/circuit_component/hear
display_name = "Voice Activator"
flags_1 = HEAR_1
/// The message heard
var/datum/port/output/message_port
/// The language heard
var/datum/port/output/language_port
/// The speaker
var/datum/port/output/speaker_port
/// The trigger sent when this event occurs
var/datum/port/output/trigger_port
/obj/item/circuit_component/hear/Initialize()
. = ..()
message_port = add_output_port("Message", PORT_TYPE_STRING)
language_port = add_output_port("Language", PORT_TYPE_STRING)
speaker_port = add_output_port("Speaker", PORT_TYPE_ATOM)
trigger_port = add_output_port("Triggered", PORT_TYPE_SIGNAL)
/obj/item/circuit_component/hear/Destroy()
message_port = null
language_port = null
speaker_port = null
trigger_port = null
return ..()
/obj/item/circuit_component/hear/Hear(message, atom/movable/speaker, datum/language/message_language, raw_message, radio_freq, list/spans, list/message_mods)
if(speaker == parent?.shell)
return
message_port.set_output(raw_message)
if(message_language)
language_port.set_output(initial(message_language.name))
speaker_port.set_output(speaker)
trigger_port.set_output(COMPONENT_SIGNAL)
@@ -0,0 +1,24 @@
/**
* # Self Component
*
* Return the current shell.
*/
/obj/item/circuit_component/self
display_name = "Self"
/// The shell this component is attached to.
var/datum/port/output/output
/obj/item/circuit_component/self/Initialize()
. = ..()
output = add_output_port("Self", PORT_TYPE_ATOM)
/obj/item/circuit_component/self/Destroy()
output = null
return ..()
/obj/item/circuit_component/self/register_shell(atom/movable/shell)
output.set_output(shell)
/obj/item/circuit_component/self/unregister_shell(atom/movable/shell)
output.set_output(null)
@@ -0,0 +1,39 @@
/**
* # Get Species Component
*
* Return the species of a mob
*/
/obj/item/circuit_component/species
display_name = "Get Species"
/// The input port
var/datum/port/input/input_port
/// The result from the output
var/datum/port/output/output
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
/obj/item/circuit_component/species/Initialize()
. = ..()
input_port = add_input_port("Organism", PORT_TYPE_ATOM)
output = add_output_port("Species", PORT_TYPE_STRING)
/obj/item/circuit_component/species/Destroy()
input_port = null
output = null
return ..()
/obj/item/circuit_component/species/input_received(datum/port/input/port)
. = ..()
if(.)
return
var/mob/living/carbon/human/human = input_port.input_value
if(!istype(human) || !human.has_dna())
output.set_output(null)
return
output.set_output(human.dna.species.name)