Files
Bubberstation/code/modules/wiremod/components/math/random.dm
SkyratBot 9e74cd4a03 [MIRROR] Input ports now connect to multiple output ports. Remove combiner. (#7505)
* Input ports now connect to multiple output ports. Remove combiner. (#60494)

* tgui bsod

* debug disconnections

* prelim

* recomment

* set_value -> put ._.

* DAMN IT

* reinsert subsystem

* prepare

* unditch signals

* remove combiner

* remove combiner some more

* how did router.dm get here? deleting.

* These two COMSIGS should be one.

* critical typo

* inline cast

* have your signals

* Have your set_input & set_output.

* make compile

* upgrade save/load to n-to-n-wires

* have your documentation

* have your unsafe proc

* pay no attention to the compile errors

* unlist the ref

* paste my for block back in ._.

* fix manual input

* oops pushed too soon

* Have your !port.connected_to?.length

Co-authored-by: Watermelon914 <37270891+Watermelon914@ users.noreply.github.com>

Co-authored-by: Watermelon914 <37270891+Watermelon914@ users.noreply.github.com>

* Input ports now connect to multiple output ports. Remove combiner.

Co-authored-by: Gurkenglas <gurkenglas@hotmail.de>
Co-authored-by: Watermelon914 <37270891+Watermelon914@ users.noreply.github.com>
2021-08-11 20:27:29 +01:00

41 lines
1005 B
Plaintext

/**
* # Random Component
*
* Generates a random number between specific values
*/
/obj/item/circuit_component/random
display_name = "Random"
desc = "A component that returns random values."
/// The minimum value that the random number can be
var/datum/port/input/minimum
/// The maximum value that the random number can be
var/datum/port/input/maximum
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
/// The result from the output
var/datum/port/output/output
/obj/item/circuit_component/random/Initialize()
. = ..()
minimum = add_input_port("Minimum", PORT_TYPE_NUMBER, FALSE)
maximum = add_input_port("Maximum", PORT_TYPE_NUMBER, FALSE)
output = add_output_port("Output", PORT_TYPE_NUMBER)
/obj/item/circuit_component/random/input_received(datum/port/input/port)
. = ..()
if(.)
return
var/min_val = minimum.value || 0
var/max_val = maximum.value || 0
if(max_val < min_val)
output.set_output(0)
return
output.set_output(rand(min_val, max_val))