Made circulators and TEGs work, updated Rowtree's station with a functional powergrid and TEG battery.

Signed-off-by: SkyMarshal <skymarshal1729@gmail.com>
This commit is contained in:
SkyMarshal
2013-04-24 15:58:39 -07:00
parent 2b2da60374
commit 3b41db4a18
3 changed files with 3025 additions and 2931 deletions
@@ -1,6 +1,14 @@
//node1, air1, network1 correspond to input
//node2, air2, network2 correspond to output
#define CIRCULATOR_MIN_PRESSURE 10 //KPA to move the mechanism
#define CIRCULATOR_VOLUME 100 //Litres
#define CIRCULATOR_EFFICIENCY 0.65 //Out of 1.
#define TURBINE_EFFICIENCY 0.1 //Uses more power than is generated.
#define TURBINE_PRESSURE_DIFFERENCE 20 //Simulates a 20KPa difference
#define GENRATE 800
/obj/machinery/atmospherics/binary/circulator
name = "circulator/heat exchanger"
desc = "A gas circulator pump and heat exchanger."
@@ -11,13 +19,19 @@
//var/side = 1 // 1=left 2=right
var/status = 0
var/datum/gas_mixture/gas_contents
var/last_pressure_delta = 0
var/turbine_pumping = 0 //For when there is not enough pressure difference and we need to induce one or something.
var/last_power_generation = 0
density = 1
/obj/machinery/atmospherics/binary/circulator/New()
..()
desc = initial(desc) + " Its outlet port is to the [dir2text(dir)]."
desc = initial(desc) + " Its outlet port is to the [dir2text(dir)]."
gas_contents = new
gas_contents.volume = CIRCULATOR_VOLUME
/obj/machinery/atmospherics/binary/circulator/proc/return_transfer_air()
if(!anchored)
@@ -25,40 +39,69 @@
var/output_starting_pressure = air2.return_pressure()
var/input_starting_pressure = air1.return_pressure()
var/internal_gas_pressure = gas_contents.return_pressure()
if(output_starting_pressure >= input_starting_pressure-10)
//Need at least 10 KPa difference to overcome friction in the mechanism
last_pressure_delta = 0
return null
var/intake_pressure_delta = input_starting_pressure - internal_gas_pressure
var/output_pressure_delta = internal_gas_pressure - output_starting_pressure
var/pressure_delta = max(intake_pressure_delta, output_pressure_delta, 0)
last_power_generation = 0
//If the turbine is running, we need to consider that.
if(turbine_pumping)
//Make it use powah
if(pressure_delta < TURBINE_PRESSURE_DIFFERENCE)
last_power_generation = (pressure_delta - TURBINE_PRESSURE_DIFFERENCE)*(1/TURBINE_EFFICIENCY)
pressure_delta = TURBINE_PRESSURE_DIFFERENCE
//If the force is already above what the turbine can do, shut it off and generate power instead!
else
turbine_pumping = 0
//Calculate necessary moles to transfer using PV = nRT
if(air1.temperature>0)
var/pressure_delta = (input_starting_pressure - output_starting_pressure)/2
if(air1.temperature > 0)
var/transfer_moles = pressure_delta*air2.volume/(air1.temperature * R_IDEAL_GAS_EQUATION)
var/transfer_moles = pressure_delta*gas_contents.volume/(air1.temperature * R_IDEAL_GAS_EQUATION)
last_pressure_delta = pressure_delta
//world << "pressure_delta = [pressure_delta]; transfer_moles = [transfer_moles];"
//Actually transfer the gas
var/datum/gas_mixture/removed = air1.remove(transfer_moles)
//Internal to output.
air2.merge(gas_contents.remove(transfer_moles))
//Intake to internal.
gas_contents.merge(air1.remove(transfer_moles))
//Update the gas networks.
if(network1)
network1.update = 1
if(network2)
network2.update = 1
return removed
else
last_pressure_delta = 0
//Needs at least 10 KPa difference to move the mechanism and make power
if(pressure_delta < CIRCULATOR_MIN_PRESSURE)
last_pressure_delta = 0
last_power_generation += pressure_delta*CIRCULATOR_EFFICIENCY
return gas_contents
//Used by the TEG to know how much power to use/produce.
/obj/machinery/atmospherics/binary/circulator/proc/ReturnPowerGeneration()
return GENRATE*last_power_generation
/obj/machinery/atmospherics/binary/circulator/process()
..()
update_icon()
/obj/machinery/atmospherics/binary/circulator/update_icon()
if(stat & (BROKEN|NOPOWER) || !anchored)
icon_state = "circ-p"
@@ -105,9 +148,9 @@
else
..()
/obj/machinery/atmospherics/binary/circulator/verb/rotate()
/obj/machinery/atmospherics/binary/circulator/verb/rotate_clockwise()
set category = "Object"
set name = "Rotate Circulator"
set name = "Rotate Circulator (Clockwise)"
set src in view(1)
if (usr.stat || usr.restrained() || anchored)
@@ -115,3 +158,15 @@
src.dir = turn(src.dir, 90)
desc = initial(desc) + " Its outlet port is to the [dir2text(dir)]."
/obj/machinery/atmospherics/binary/circulator/verb/rotate_anticlockwise()
set category = "Object"
set name = "Rotate Circulator (Counterclockwise)"
set src in view(1)
if (usr.stat || usr.restrained() || anchored)
return
src.dir = turn(src.dir, -90)
desc = initial(desc) + " Its outlet port is to the [dir2text(dir)]."