Adds temperature and pressure sensors to circuits (#59993)

Co-authored-by: Watermelon914 <37270891+Watermelon914@users.noreply.github.com>
This commit is contained in:
obsol
2021-07-04 19:47:32 -04:00
committed by GitHub
parent 6948ca330f
commit 9c46c01439
5 changed files with 94 additions and 0 deletions
@@ -0,0 +1,40 @@
/**
* # Pressure Sensor
*
* Returns the pressure of the tile
*/
/obj/item/circuit_component/pressuresensor
display_name = "Pressure Sensor"
display_desc = "Outputs the current pressure of the tile"
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
/// The result from the output
var/datum/port/output/result
/obj/item/circuit_component/pressuresensor/Initialize()
. = ..()
result = add_output_port("Result", PORT_TYPE_NUMBER)
/obj/item/circuit_component/tempsensor/Destroy()
result = null
return ..()
/obj/item/circuit_component/pressuresensor/input_received(datum/port/input/port)
. = ..()
if(.)
return
//Get current turf
var/turf/location = get_turf(src)
if(!location)
result.set_output(null)
return
//Get environment info
var/datum/gas_mixture/environment = location.return_air()
var/total_moles = environment.total_moles()
var/pressure = environment.return_pressure()
if(total_moles)
//If there's atmos, return pressure
result.set_output(round(pressure,1))
else
result.set_output(0)
@@ -0,0 +1,40 @@
/**
* # Temperature Sensor
*
* Returns the temperature of the tile
*/
/obj/item/circuit_component/tempsensor
display_name = "Temperature Sensor"
display_desc = "Outputs the current temperature of the tile"
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
/// The result from the output
var/datum/port/output/result
/obj/item/circuit_component/tempsensor/Initialize()
. = ..()
result = add_output_port("Result", PORT_TYPE_NUMBER)
/obj/item/circuit_component/tempsensor/Destroy()
result = null
return ..()
/obj/item/circuit_component/tempsensor/input_received(datum/port/input/port)
. = ..()
if(.)
return
//Get current turf
var/turf/location = get_turf(src)
if(!location)
result.set_output(null)
return
//Get environment info
var/datum/gas_mixture/environment = location.return_air()
var/total_moles = environment.total_moles()
if(total_moles)
//If there's atmos, return temperature
result.set_output(round(environment.temperature,1))
else
result.set_output(0)