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

View File

@@ -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)]."

View File

@@ -5,10 +5,10 @@
desc = "It's a high efficiency thermoelectric generator."
icon_state = "teg"
density = 1
use_power = 0
anchored = 0
idle_power_usage = 50
active_power_usage = 1000
use_power = 1
idle_power_usage = 100 //Watts, I hope. Just enough to do the computer and display things.
var/obj/machinery/atmospherics/binary/circulator/circ1
var/obj/machinery/atmospherics/binary/circulator/circ2
@@ -57,7 +57,7 @@
if(lastgenlev != 0)
overlays += image('icons/obj/power.dmi', "teg-op[lastgenlev]")
#define GENRATE 800 // generator output coefficient from Q
/obj/machinery/power/generator/process()
@@ -87,13 +87,9 @@
//world << "delta_temperature = [delta_temperature]; air1_heat_capacity = [air1_heat_capacity]; air2_heat_capacity = [air2_heat_capacity]"
if(delta_temperature > 0 && air1_heat_capacity > 0 && air2_heat_capacity > 0)
use_power = 2
var/efficiency = 0.65
var/energy_transfer = delta_temperature*air2_heat_capacity*air1_heat_capacity/(air2_heat_capacity+air1_heat_capacity)
var/heat = energy_transfer*(1-efficiency)
lastgen = energy_transfer*efficiency
//world << "lastgen = [lastgen]; heat = [heat]; delta_temperature = [delta_temperature]; air2_heat_capacity = [air2_heat_capacity]; air1_heat_capacity = [air1_heat_capacity];"
if(air2.temperature > air1.temperature)
air2.temperature = air2.temperature - energy_transfer/air2_heat_capacity
@@ -102,28 +98,20 @@
air2.temperature = air2.temperature + heat/air2_heat_capacity
air1.temperature = air1.temperature - energy_transfer/air1_heat_capacity
//world << "POWER: [lastgen] W generated at [efficiency*100]% efficiency and sinks sizes [air1_heat_capacity], [air2_heat_capacity]"
lastgen = circ1.ReturnPowerGeneration() + circ2.ReturnPowerGeneration()
if(lastgen > 0)
add_avail(lastgen)
add_avail(lastgen)
if(air1)
circ1.air2.merge(air1)
if(air2)
circ2.air2.merge(air2)
else
add_load(-lastgen)
// update icon overlays and power usage only if displayed level has changed
var/genlev = max(0, min( round(11*lastgen / 100000), 11))
if(genlev != lastgenlev)
lastgenlev = genlev
active_power_usage = lastgenlev * 1000
if(lastgenlev > 0)
use_power = 2
else
use_power = 1
updateicon()
src.updateDialog()
updateDialog()
/obj/machinery/power/generator/attack_ai(mob/user)
if(stat & (BROKEN|NOPOWER)) return
@@ -162,12 +150,15 @@
t += "Inlet Temperature: [round(circ1.air1.temperature, 0.1)] K<BR>"
t += "Outlet Pressure: [round(circ1.air2.return_pressure(), 0.1)] kPa<BR>"
t += "Outlet Temperature: [round(circ1.air2.temperature, 0.1)] K<BR>"
t += "Turbine Status: <A href='?src=\ref[src];turbine1=1'>[circ1.turbine_pumping ? "Pumping" : "Generating"]</a><br><br>"
t += "<B>Secondary Circulator (bottom/left)</B><BR>"
t += "Inlet Pressure: [round(circ2.air1.return_pressure(), 0.1)] kPa<BR>"
t += "Inlet Temperature: [round(circ2.air1.temperature, 0.1)] K<BR>"
t += "Outlet Pressure: [round(circ2.air2.return_pressure(), 0.1)] kPa<BR>"
t += "Outlet Temperature: [round(circ2.air2.temperature, 0.1)] K<BR>"
t += "Turbine Status: <A href='?src=\ref[src];turbine2=1'>[circ2.turbine_pumping ? "Pumping" : "Generating"]</a><br>"
else
t += "Unable to connect to circulators.<br>"
t += "Ensure both are in position and wrenched into place."
@@ -187,6 +178,15 @@
usr << browse(null, "window=teg")
usr.unset_machine()
return 0
if( href_list["turbine2"] )
if(circ2)
circ2.turbine_pumping = !circ2.turbine_pumping
if( href_list["turbine1"] )
if(circ1)
circ1.turbine_pumping = !circ1.turbine_pumping
updateDialog()
return 1
@@ -196,12 +196,22 @@
updateicon()
/obj/machinery/power/generator/verb/rotate()
/obj/machinery/power/generator/verb/rotate_clock()
set category = "Object"
set name = "Rotate Generator"
set name = "Rotate Generator (Clockwise)"
set src in view(1)
if (usr.stat || usr.restrained() || anchored)
return
src.dir = turn(src.dir, 90)
/obj/machinery/power/generator/verb/rotate_anticlock()
set category = "Object"
set name = "Rotate Generator (Counterclockwise)"
set src in view(1)
if (usr.stat || usr.restrained() || anchored)
return
src.dir = turn(src.dir, -90)

File diff suppressed because it is too large Load Diff