TEG refactor

This commit is contained in:
Markolie
2016-10-11 22:49:51 +02:00
parent 8a2a9ee3b0
commit a577cd206c
10 changed files with 209 additions and 360 deletions
@@ -3,76 +3,68 @@
/obj/machinery/atmospherics/binary/circulator
name = "circulator/heat exchanger"
desc = "A gas circulator pump and heat exchanger."
icon = 'icons/obj/pipes.dmi'
icon_state = "circ-off"
anchored = 0
density = 1
icon = 'icons/obj/atmospherics/circulator.dmi'
icon_state = "circ1-off"
var/side = CIRC_LEFT
var/global/const/CIRC_LEFT = 1
var/global/const/CIRC_RIGHT = 2
var/recent_moles_transferred = 0
var/last_heat_capacity = 0
var/last_temperature = 0
var/last_pressure_delta = 0
var/last_worldtime_transfer = 0
anchored = 1
density = 1
can_unwrench = 1
/obj/machinery/atmospherics/binary/circulator/New()
initialize()
..()
desc = initial(desc) + " Its outlet port is to the [dir2text(dir)]."
/obj/machinery/atmospherics/binary/circulator/proc/return_transfer_air()
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 = air1.return_pressure()
var/input_starting_pressure = air2.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)
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
//Calculate necessary moles to transfer using PV = nRT
recent_moles_transferred = last_pressure_delta*air2.volume/(air1.temperature * R_IDEAL_GAS_EQUATION)
//Calculate necessary moles to transfer using PV = nRT
if(air2.temperature>0)
var/pressure_delta = (input_starting_pressure - output_starting_pressure)/2
//Actually transfer the gas
removed = air1.remove(recent_moles_transferred)
if(removed)
last_heat_capacity = removed.heat_capacity()
last_temperature = removed.temperature
var/transfer_moles = pressure_delta * air1.volume/(air2.temperature * R_IDEAL_GAS_EQUATION)
//Update the gas networks.
parent1.update = 1
last_pressure_delta = pressure_delta
last_worldtime_transfer = world.time
else
recent_moles_transferred = 0
//world << "pressure_delta = [pressure_delta]; transfer_moles = [transfer_moles];"
//Actually transfer the gas
var/datum/gas_mixture/removed = air2.remove(transfer_moles)
parent1.update = 1
parent2.update = 1
update_icon()
return removed
else
last_pressure_delta = 0
/obj/machinery/atmospherics/binary/circulator/process()
if(!..())
return 0
if(last_worldtime_transfer < world.time - 50)
recent_moles_transferred = 0
update_icon()
..()
update_icon()
/obj/machinery/atmospherics/binary/circulator/update_icon()
if(stat & (BROKEN|NOPOWER) || !anchored)
icon_state = "circ-p"
else if(last_pressure_delta > 0 && recent_moles_transferred > 0)
if(last_pressure_delta > 5*ONE_ATMOSPHERE)
icon_state = "circ-run"
if(stat & (BROKEN|NOPOWER))
icon_state = "circ[side]-p"
else if(last_pressure_delta > 0)
if(last_pressure_delta > ONE_ATMOSPHERE)
icon_state = "circ[side]-run"
else
icon_state = "circ-slow"
icon_state = "circ[side]-slow"
else
icon_state = "circ-off"
icon_state = "circ[side]-off"
return 1
/obj/machinery/atmospherics/binary/circulator/attackby(var/obj/item/W as obj, var/mob/user as mob, params)
if(istype(W, /obj/item/weapon/wrench))
var/turf/T = get_turf(src)
if(!istype(T, /turf/simulated))
return ..()
anchored = !anchored
to_chat(user, "You [(anchored) ? "fasten" : "loosen"] \the [src] to the floor")
playsound(loc, 'sound/items/Ratchet.ogg', 50, 1)
else return ..()
return 1