From be43595093bd00ee2d30aefbbcd500f6a1c2df96 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Sun, 17 Oct 2021 02:32:27 +0200 Subject: [PATCH] [MIRROR] Trigonometry circuit component [MDB IGNORE] (#8863) * Trigonometry circuit component (#61885) Adds a trigonometry circuit component to the game. * Trigonometry circuit component Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com> --- .../research/designs/wiremod_designs.dm | 5 ++ code/modules/research/techweb/all_nodes.dm | 1 + .../wiremod/components/math/trigonometry.dm | 69 +++++++++++++++++++ tgstation.dme | 1 + 4 files changed, 76 insertions(+) create mode 100644 code/modules/wiremod/components/math/trigonometry.dm diff --git a/code/modules/research/designs/wiremod_designs.dm b/code/modules/research/designs/wiremod_designs.dm index 99c75416452..346d9aaafe0 100644 --- a/code/modules/research/designs/wiremod_designs.dm +++ b/code/modules/research/designs/wiremod_designs.dm @@ -48,6 +48,11 @@ id = "comp_arithmetic" build_path = /obj/item/circuit_component/arithmetic +/datum/design/component/trigonometry + name = "Trigonometry Component" + id = "comp_trigonometry" + build_path = /obj/item/circuit_component/trigonometry + /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 24b84f5440e..ceb988fabb2 100644 --- a/code/modules/research/techweb/all_nodes.dm +++ b/code/modules/research/techweb/all_nodes.dm @@ -259,6 +259,7 @@ "comp_timepiece", "comp_tonumber", "comp_tostring", + "comp_trigonometry", "comp_typecast", "comp_typecheck", "compact_remote_shell", diff --git a/code/modules/wiremod/components/math/trigonometry.dm b/code/modules/wiremod/components/math/trigonometry.dm new file mode 100644 index 00000000000..d27978f22f6 --- /dev/null +++ b/code/modules/wiremod/components/math/trigonometry.dm @@ -0,0 +1,69 @@ +#define COMP_TRIGONOMETRY_SINE "Sine" +#define COMP_TRIGONOMETRY_COSINE "Cosine" +#define COMP_TRIGONOMETRY_TANGENT "Tangent" +#define COMP_TRIGONOMETRY_ARCSINE "Arcsine" +#define COMP_TRIGONOMETRY_ARCCOSINE "Arccosine" +#define COMP_TRIGONOMETRY_ARCTANGENT "Arctangent" + + +/** + * # Trigonometric Component + * + * General trigonometric unit with sine, cosine, tangent and their inverse functions. + * This one only works with numbers. + */ +/obj/item/circuit_component/trigonometry + display_name = "Trigonometry" + desc = "General trigonometry component with main and inverse trigonometry functions." + + var/datum/port/input/option/trigonometric_function + + /// 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/trigonometry/populate_options() + var/static/component_functions = list( + COMP_TRIGONOMETRY_SINE, + COMP_TRIGONOMETRY_COSINE, + COMP_TRIGONOMETRY_TANGENT, + COMP_TRIGONOMETRY_ARCSINE, + COMP_TRIGONOMETRY_ARCCOSINE, + COMP_TRIGONOMETRY_ARCTANGENT, + ) + trigonometric_function = add_option_port("Trigonometric Function", component_functions) + +/obj/item/circuit_component/trigonometry/populate_ports() + input_port = add_input_port("Input", PORT_TYPE_NUMBER) + output = add_output_port("Output", PORT_TYPE_NUMBER) + +/obj/item/circuit_component/trigonometry/input_received(datum/port/input/port) + + var/result = input_port.value + + switch(trigonometric_function.value) + if(COMP_TRIGONOMETRY_SINE) + result = sin(result) + if(COMP_TRIGONOMETRY_COSINE) + result = cos(result) + if(COMP_TRIGONOMETRY_TANGENT) + result = tan(result) + if(COMP_TRIGONOMETRY_ARCSINE) + result = arcsin(result) + if(COMP_TRIGONOMETRY_ARCCOSINE) + result = arccos(result) + if(COMP_TRIGONOMETRY_ARCTANGENT) + result = arctan(result) + + output.set_output(result) + +#undef COMP_TRIGONOMETRY_SINE +#undef COMP_TRIGONOMETRY_COSINE +#undef COMP_TRIGONOMETRY_TANGENT +#undef COMP_TRIGONOMETRY_ARCSINE +#undef COMP_TRIGONOMETRY_ARCCOSINE +#undef COMP_TRIGONOMETRY_ARCTANGENT diff --git a/tgstation.dme b/tgstation.dme index 8ca4ef84f95..f29651e1fd7 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -3949,6 +3949,7 @@ #include "code\modules\wiremod\components\math\logic.dm" #include "code\modules\wiremod\components\math\not.dm" #include "code\modules\wiremod\components\math\random.dm" +#include "code\modules\wiremod\components\math\trigonometry.dm" #include "code\modules\wiremod\components\ntnet\ntnet_receive.dm" #include "code\modules\wiremod\components\ntnet\ntnet_send.dm" #include "code\modules\wiremod\components\sensors\pressuresensor.dm"