made TEG generate power from heat transferred again, restructed TEG and circulator code to be smaller and cleaner, added an "overload" to TEGs where they spark + power output drops if power output exceeds 250k

Signed-off-by: Cael_Aislinn <cael_aislinn@yahoo.com.au>
This commit is contained in:
Cael_Aislinn
2013-05-19 18:50:15 +10:00
parent 7c6e7d4727
commit 1d9fe082d7
2 changed files with 51 additions and 111 deletions
@@ -1,14 +1,6 @@
//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."
@@ -16,97 +8,60 @@
icon_state = "circ-off"
anchored = 0
//var/side = 1 // 1=left 2=right
var/status = 0
var/datum/gas_mixture/gas_contents
var/recent_moles_transferred = 0
var/last_heat_capacity = 0
var/last_temperature = 0
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
var/last_worldtime_transfer = 0
density = 1
/obj/machinery/atmospherics/binary/circulator/New()
..()
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)
return null
var/datum/gas_mixture/removed
if(anchored && !(stat&BROKEN) )
var/input_starting_pressure = air1.return_pressure()
var/output_starting_pressure = air2.return_pressure()
last_pressure_delta = max(input_starting_pressure - output_starting_pressure + 10, 0)
var/output_starting_pressure = air2.return_pressure()
var/input_starting_pressure = air1.return_pressure()
var/internal_gas_pressure = gas_contents.return_pressure()
//only circulate air if there is a pressure difference (plus 10 kPa to represent friction in the machine)
if(air1.temperature > 0 && last_pressure_delta > 0)
var/intake_pressure_delta = input_starting_pressure - internal_gas_pressure
var/output_pressure_delta = internal_gas_pressure - output_starting_pressure
//Calculate necessary moles to transfer using PV = nRT
recent_moles_transferred = last_pressure_delta*air2.volume/(air1.temperature * R_IDEAL_GAS_EQUATION)
var/pressure_delta = max(intake_pressure_delta, output_pressure_delta, 0)
//Actually transfer the gas
removed = air1.remove(recent_moles_transferred)
if(removed)
last_heat_capacity = removed.heat_capacity()
last_temperature = removed.temperature
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
//Update the gas networks.
if(network1)
network1.update = 1
//If the force is already above what the turbine can do, shut it off and generate power instead!
last_worldtime_transfer = world.time
else
turbine_pumping = 0
//Calculate necessary moles to transfer using PV = nRT
if(air1.temperature > 0)
var/transfer_moles = pressure_delta*gas_contents.volume/(air1.temperature * R_IDEAL_GAS_EQUATION)
last_pressure_delta = pressure_delta
//Actually transfer the gas
//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
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
recent_moles_transferred = 0
update_icon()
return removed
/obj/machinery/atmospherics/binary/circulator/process()
..()
update_icon()
if(last_worldtime_transfer < world.time - 50)
recent_moles_transferred = 0
update_icon()
/obj/machinery/atmospherics/binary/circulator/update_icon()
if(stat & (BROKEN|NOPOWER) || !anchored)
icon_state = "circ-p"
else if(last_pressure_delta > 0)
if(last_pressure_delta > ONE_ATMOSPHERE)
else if(last_pressure_delta > 0 && recent_moles_transferred > 0)
if(last_pressure_delta > 5*ONE_ATMOSPHERE)
icon_state = "circ-run"
else
icon_state = "circ-slow"