diff --git a/code/ATMOSPHERICS/components/binary_devices/circulator.dm b/code/ATMOSPHERICS/components/binary_devices/circulator.dm index 1425ed8d776..0ac8ab62997 100644 --- a/code/ATMOSPHERICS/components/binary_devices/circulator.dm +++ b/code/ATMOSPHERICS/components/binary_devices/circulator.dm @@ -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" diff --git a/code/modules/power/generator.dm b/code/modules/power/generator.dm index f37e62ac490..325f8917a3a 100644 --- a/code/modules/power/generator.dm +++ b/code/modules/power/generator.dm @@ -1,5 +1,4 @@ -//updated by cael_aislinn on 5/3/2013 to be rotateable, moveable and generally more flexible /obj/machinery/power/generator name = "thermoelectric generator" desc = "It's a high efficiency thermoelectric generator." @@ -57,39 +56,26 @@ if(lastgenlev != 0) overlays += image('icons/obj/power.dmi', "teg-op[lastgenlev]") - - /obj/machinery/power/generator/process() - - //world << "Generator process ran" - if(!circ1 || !circ2 || !anchored || stat & (BROKEN|NOPOWER)) return - //world << "circ1 and circ2 pass" + updateDialog() var/datum/gas_mixture/air1 = circ1.return_transfer_air() var/datum/gas_mixture/air2 = circ2.return_transfer_air() - lastgen = 0 - //world << "hot_air = [hot_air]; cold_air = [cold_air];" - if(air1 && air2) - - //world << "hot_air = [hot_air] temperature = [air2.temperature]; cold_air = [cold_air] temperature = [air2.temperature];" - - //world << "coldair and hotair pass" var/air1_heat_capacity = air1.heat_capacity() var/air2_heat_capacity = air2.heat_capacity() var/delta_temperature = abs(air2.temperature - air1.temperature) - //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) 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*0.05 if(air2.temperature > air1.temperature) air2.temperature = air2.temperature - energy_transfer/air2_heat_capacity @@ -98,20 +84,29 @@ air2.temperature = air2.temperature + heat/air2_heat_capacity air1.temperature = air1.temperature - energy_transfer/air1_heat_capacity - lastgen = circ1.ReturnPowerGeneration() + circ2.ReturnPowerGeneration() - if(lastgen > 0) - add_avail(lastgen) + //Transfer the air + circ1.air2.merge(air1) + circ2.air2.merge(air2) - else - add_load(-lastgen) + //Update the gas networks + if(circ1.network2) + circ1.network2.update = 1 + if(circ2.network2) + circ2.network2.update = 1 // update icon overlays and power usage only if displayed level has changed - var/genlev = max(0, min( round(11*lastgen / 100000), 11)) + if(lastgen > 250000 && prob(10)) + var/datum/effect/effect/system/spark_spread/s = new /datum/effect/effect/system/spark_spread + s.set_up(3, 1, src) + s.start() + lastgen *= 0.5 + var/genlev = max(0, min( round(11*lastgen / 250000), 11)) + if(lastgen > 100 && genlev == 0) + genlev = 1 if(genlev != lastgenlev) lastgenlev = genlev updateicon() - - updateDialog() + add_avail(lastgen) /obj/machinery/power/generator/attack_ai(mob/user) if(stat & (BROKEN|NOPOWER)) return @@ -145,19 +140,17 @@ if(circ1 && circ2) t += "Output : [round(lastgen)] W

" - t += "Primary Circulator (top/right)
" + t += "Primary Circulator (top or right)
" t += "Inlet Pressure: [round(circ1.air1.return_pressure(), 0.1)] kPa
" t += "Inlet Temperature: [round(circ1.air1.temperature, 0.1)] K
" t += "Outlet Pressure: [round(circ1.air2.return_pressure(), 0.1)] kPa
" t += "Outlet Temperature: [round(circ1.air2.temperature, 0.1)] K
" - t += "Turbine Status: [circ1.turbine_pumping ? "Pumping" : "Generating"]

" - t += "Secondary Circulator (bottom/left)
" + t += "Secondary Circulator (bottom or left)
" t += "Inlet Pressure: [round(circ2.air1.return_pressure(), 0.1)] kPa
" t += "Inlet Temperature: [round(circ2.air1.temperature, 0.1)] K
" t += "Outlet Pressure: [round(circ2.air2.return_pressure(), 0.1)] kPa
" t += "Outlet Temperature: [round(circ2.air2.temperature, 0.1)] K
" - t += "Turbine Status: [circ2.turbine_pumping ? "Pumping" : "Generating"]
" else t += "Unable to connect to circulators.
" @@ -179,14 +172,6 @@ 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