From 9d6e70171ab3b2a1a3785c8124c517c621d8758d Mon Sep 17 00:00:00 2001 From: Time-Green <7501474+Time-Green@users.noreply.github.com> Date: Fri, 24 Nov 2023 21:04:49 +0100 Subject: [PATCH] Adds arctangent 2 component to circuits (#79892) ## About The Pull Request Adds an arctangent 2 component (atan2) ## Why It's Good For The Game It's made to convert offsets into angles, something thats pretty useful in a coordinate based game ## Changelog :cl: add: Adds an arctangent2 component to circuitry! /:cl: --- .../research/designs/wiremod_designs.dm | 5 ++++ code/modules/research/techweb/all_nodes.dm | 1 + .../wiremod/components/math/arctan2.dm | 26 +++++++++++++++++++ tgstation.dme | 1 + 4 files changed, 33 insertions(+) create mode 100644 code/modules/wiremod/components/math/arctan2.dm diff --git a/code/modules/research/designs/wiremod_designs.dm b/code/modules/research/designs/wiremod_designs.dm index a3b4a9a8866..5783ee36082 100644 --- a/code/modules/research/designs/wiremod_designs.dm +++ b/code/modules/research/designs/wiremod_designs.dm @@ -61,6 +61,11 @@ id = "comp_trigonometry" build_path = /obj/item/circuit_component/trigonometry +/datum/design/component/arctan2 + name = "Arctangent 2 Component" + id = "comp_arctan2" + build_path = /obj/item/circuit_component/arctan2 + /datum/design/component/clock name = "Clock Component" id = "comp_clock" diff --git a/code/modules/research/techweb/all_nodes.dm b/code/modules/research/techweb/all_nodes.dm index 50d01dbd670..4bd39be308a 100644 --- a/code/modules/research/techweb/all_nodes.dm +++ b/code/modules/research/techweb/all_nodes.dm @@ -319,6 +319,7 @@ design_ids = list( "circuit_multitool", "comp_access_checker", + "comp_arctan2", "comp_arithmetic", "comp_assoc_list_pick", "comp_assoc_list_remove", diff --git a/code/modules/wiremod/components/math/arctan2.dm b/code/modules/wiremod/components/math/arctan2.dm new file mode 100644 index 00000000000..cce03df1d83 --- /dev/null +++ b/code/modules/wiremod/components/math/arctan2.dm @@ -0,0 +1,26 @@ +/** + * # Arctangent 2 function + * A variant of arctan. When given a deltaX and deltaY, returns the angle. I will blow you out of the sky + */ +/obj/item/circuit_component/arctan2 + display_name = "Arctangent 2 Component" + desc = "A two parameter arctan2 component, for calculating any angle you want." + category = "Math" + + /// The input port for the x-offset + var/datum/port/input/input_port_x + /// The input port for the y-offset + var/datum/port/input/input_port_y + + /// The result from the output + var/datum/port/output/output + + circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL + +/obj/item/circuit_component/arctan2/populate_ports() + input_port_x = add_input_port("Delta X", PORT_TYPE_NUMBER) + input_port_y = add_input_port("Delta Y", PORT_TYPE_NUMBER) + output = add_output_port("Angle", PORT_TYPE_NUMBER) + +/obj/item/circuit_component/arctan2/input_received(datum/port/input/port) + output.set_output(arctan(input_port_x.value, input_port_y.value)) diff --git a/tgstation.dme b/tgstation.dme index 593b6669ae9..2553b026ce6 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -5907,6 +5907,7 @@ #include "code\modules\wiremod\components\list\list_pick.dm" #include "code\modules\wiremod\components\list\list_remove.dm" #include "code\modules\wiremod\components\list\split.dm" +#include "code\modules\wiremod\components\math\arctan2.dm" #include "code\modules\wiremod\components\math\arithmetic.dm" #include "code\modules\wiremod\components\math\binary_conversion.dm" #include "code\modules\wiremod\components\math\comparison.dm"