mirror of
https://github.com/CHOMPstation/CHOMPstation.git
synced 2026-07-16 01:22:43 +01:00
Arithmetic Circuit Additions and Fixes
Subtraction, multiplication, and division should work properly. Added sign, round, and exponent circuits.
This commit is contained in:
@@ -11,6 +11,9 @@
|
||||
/obj/item/integrated_circuit/arithmetic/addition
|
||||
name = "addition circuit"
|
||||
desc = "This circuit can add numbers together."
|
||||
extended_desc = "The order that the calculation goes is;<br>\
|
||||
result = ((((A + B) + C) + D) ... ) and so on, until all pins have been added. \
|
||||
Null pins are ignored."
|
||||
icon_state = "addition"
|
||||
|
||||
/obj/item/integrated_circuit/arithmetic/addition/do_work()
|
||||
@@ -29,30 +32,47 @@
|
||||
/obj/item/integrated_circuit/arithmetic/subtraction
|
||||
name = "subtraction circuit"
|
||||
desc = "This circuit can subtract numbers."
|
||||
extended_desc = "The order that the calculation goes is;<br>\
|
||||
result = ((((A - B) - C) - D) ... ) and so on, until all pins have been subtracted. \
|
||||
Null pins are ignored. Pin A <b>must</b> be a number or the circuit will not function."
|
||||
icon_state = "subtraction"
|
||||
|
||||
/obj/item/integrated_circuit/arithmetic/subtraction/do_work()
|
||||
if(..())
|
||||
var/result = 0
|
||||
for(var/datum/integrated_io/input/I in inputs)
|
||||
I.pull_data()
|
||||
if(isnum(I.data))
|
||||
result = result - I.data
|
||||
var/datum/integrated_io/A = inputs[1]
|
||||
if(!isnum(A.data))
|
||||
return
|
||||
var/result = A.data
|
||||
|
||||
for(var/datum/integrated_io/output/O in outputs)
|
||||
O.data = result
|
||||
O.push_data()
|
||||
for(var/datum/integrated_io/input/I in inputs)
|
||||
if(I == A)
|
||||
continue
|
||||
I.pull_data()
|
||||
if(isnum(I.data))
|
||||
result = result - I.data
|
||||
|
||||
for(var/datum/integrated_io/output/O in outputs)
|
||||
O.data = result
|
||||
O.push_data()
|
||||
|
||||
// *Multiply* //
|
||||
|
||||
/obj/item/integrated_circuit/arithmetic/multiplication
|
||||
name = "multiplication circuit"
|
||||
desc = "This circuit can multiply numbers."
|
||||
extended_desc = "The order that the calculation goes is;<br>\
|
||||
result = ((((A * B) * C) * D) ... ) and so on, until all pins have been multiplied. \
|
||||
Null pins are ignored. Pin A <b>must</b> be a number or the circuit will not function."
|
||||
icon_state = "multiplication"
|
||||
|
||||
/obj/item/integrated_circuit/arithmetic/subtraction/do_work()
|
||||
var/result = 0
|
||||
|
||||
/obj/item/integrated_circuit/arithmetic/multiplication/do_work()
|
||||
var/datum/integrated_io/A = inputs[1]
|
||||
if(!isnum(A.data))
|
||||
return
|
||||
var/result = A.data
|
||||
for(var/datum/integrated_io/input/I in inputs)
|
||||
if(I == A)
|
||||
continue
|
||||
I.pull_data()
|
||||
if(isnum(I.data))
|
||||
result = result * I.data
|
||||
@@ -66,11 +86,20 @@
|
||||
/obj/item/integrated_circuit/arithmetic/division
|
||||
name = "division circuit"
|
||||
desc = "This circuit can divide numbers, just don't think about trying to divide by zero!"
|
||||
extended_desc = "The order that the calculation goes is;<br>\
|
||||
result = ((((A / B) / C) / D) ... ) and so on, until all pins have been divided. \
|
||||
Null pins, and pins containing 0, are ignored. Pin A <b>must</b> be a number or the circuit will not function."
|
||||
icon_state = "division"
|
||||
|
||||
/obj/item/integrated_circuit/arithmetic/division/do_work()
|
||||
var/result = 0
|
||||
var/datum/integrated_io/A = inputs[1]
|
||||
if(!isnum(A.data))
|
||||
return
|
||||
var/result = A.data
|
||||
|
||||
for(var/datum/integrated_io/input/I in inputs)
|
||||
if(I == A)
|
||||
continue
|
||||
I.pull_data()
|
||||
if(isnum(I.data) && I.data != 0) //No runtimes here.
|
||||
result = result / I.data
|
||||
@@ -79,6 +108,73 @@
|
||||
O.data = result
|
||||
O.push_data()
|
||||
|
||||
//^ Exponent ^//
|
||||
|
||||
/obj/item/integrated_circuit/arithmetic/exponent
|
||||
name = "exponent circuit"
|
||||
desc = "Outputs A to the power of B."
|
||||
icon_state = "exponent"
|
||||
inputs = list("A", "B")
|
||||
|
||||
/obj/item/integrated_circuit/arithmetic/exponent/do_work()
|
||||
var/result = 0
|
||||
var/datum/integrated_io/A = inputs[1]
|
||||
var/datum/integrated_io/B = inputs[2]
|
||||
if(isnum(A.data) && isnum(B.data))
|
||||
result = A.data ** B.data
|
||||
|
||||
for(var/datum/integrated_io/output/O in outputs)
|
||||
O.data = result
|
||||
O.push_data()
|
||||
|
||||
// +-Sign-+ //
|
||||
|
||||
/obj/item/integrated_circuit/arithmetic/sign
|
||||
name = "sign circuit"
|
||||
desc = "This will say if a number is positive, negative, or zero."
|
||||
extended_desc = "Will output 1, -1, or 0, depending on if A is a postive number, a negative number, or zero, respectively."
|
||||
icon_state = "sign"
|
||||
inputs = list("A")
|
||||
|
||||
/obj/item/integrated_circuit/arithmetic/sign/do_work()
|
||||
var/result = 0
|
||||
var/datum/integrated_io/A = inputs[1]
|
||||
if(isnum(A.data))
|
||||
if(A.data > 0)
|
||||
result = 1
|
||||
else if (A.data < 0)
|
||||
result = -1
|
||||
else
|
||||
result = 0
|
||||
|
||||
for(var/datum/integrated_io/output/O in outputs)
|
||||
O.data = result
|
||||
O.push_data()
|
||||
|
||||
// Round //
|
||||
|
||||
/obj/item/integrated_circuit/arithmetic/round
|
||||
name = "round circuit"
|
||||
desc = "Rounds A to the nearest B multiple of A."
|
||||
extended_desc = "If B is not given a number, it will output the floor of A instead."
|
||||
icon_state = "round"
|
||||
inputs = list("A", "B")
|
||||
|
||||
/obj/item/integrated_circuit/arithmetic/round/do_work()
|
||||
var/result = 0
|
||||
var/datum/integrated_io/A = inputs[1]
|
||||
var/datum/integrated_io/B = inputs[2]
|
||||
if(isnum(A.data))
|
||||
if(isnum(B.data) && B.data != 0)
|
||||
result = round(A.data, B.data)
|
||||
else
|
||||
result = round(A.data)
|
||||
|
||||
for(var/datum/integrated_io/output/O in outputs)
|
||||
O.data = result
|
||||
O.push_data()
|
||||
|
||||
|
||||
// Absolute //
|
||||
|
||||
/obj/item/integrated_circuit/arithmetic/absolute
|
||||
@@ -103,6 +199,7 @@
|
||||
/obj/item/integrated_circuit/arithmetic/average
|
||||
name = "average circuit"
|
||||
desc = "This circuit is of average quality, however it will compute the average for numbers you give it."
|
||||
extended_desc = "Note that null pins are ignored, where as a pin containing 0 is included in the averaging calculation."
|
||||
icon_state = "average"
|
||||
|
||||
/obj/item/integrated_circuit/arithmetic/average/do_work()
|
||||
@@ -137,6 +234,8 @@
|
||||
/obj/item/integrated_circuit/arithmetic/random
|
||||
name = "random number generator circuit"
|
||||
desc = "This gives a random (integer) number between values A and B inclusive."
|
||||
extended_desc = "'Inclusive' means that the upper bound is included in the range of numbers, e.g. L = 1 and H = 3 will allow \
|
||||
for outputs of 1, 2, or 3. L being the higher number is not <i>strictly</i> required."
|
||||
icon_state = "random"
|
||||
inputs = list("L","H")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user