diff --git a/code/ATMOSPHERICS/components/binary_devices/circulator.dm b/code/ATMOSPHERICS/components/binary_devices/circulator.dm index 4144fbb66d5..26dc82033ad 100644 --- a/code/ATMOSPHERICS/components/binary_devices/circulator.dm +++ b/code/ATMOSPHERICS/components/binary_devices/circulator.dm @@ -5,62 +5,113 @@ name = "circulator/heat exchanger" desc = "A gas circulator pump and heat exchanger." icon = 'icons/obj/pipes.dmi' - icon_state = "circ1-off" + icon_state = "circ-off" + anchored = 0 - var/side = 1 // 1=left 2=right + //var/side = 1 // 1=left 2=right var/status = 0 var/last_pressure_delta = 0 - anchored = 1.0 density = 1 - proc/return_transfer_air() - var/output_starting_pressure = air2.return_pressure() - var/input_starting_pressure = air1.return_pressure() +/obj/machinery/atmospherics/binary/circulator/New() + ..() + desc = initial(desc) + " Its outlet port is to the [dir2text(dir)]." - 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 +/obj/machinery/atmospherics/binary/circulator/proc/return_transfer_air() + if(!anchored) + return null - //Calculate necessary moles to transfer using PV = nRT - if(air1.temperature>0) - var/pressure_delta = (input_starting_pressure - output_starting_pressure)/2 + var/output_starting_pressure = air2.return_pressure() + var/input_starting_pressure = air1.return_pressure() - var/transfer_moles = pressure_delta*air2.volume/(air1.temperature * R_IDEAL_GAS_EQUATION) + 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 - last_pressure_delta = pressure_delta + //Calculate necessary moles to transfer using PV = nRT + if(air1.temperature>0) + var/pressure_delta = (input_starting_pressure - output_starting_pressure)/2 - //world << "pressure_delta = [pressure_delta]; transfer_moles = [transfer_moles];" + var/transfer_moles = pressure_delta*air2.volume/(air1.temperature * R_IDEAL_GAS_EQUATION) - //Actually transfer the gas - var/datum/gas_mixture/removed = air1.remove(transfer_moles) + last_pressure_delta = pressure_delta - if(network1) - network1.update = 1 + //world << "pressure_delta = [pressure_delta]; transfer_moles = [transfer_moles];" - if(network2) - network2.update = 1 + //Actually transfer the gas + var/datum/gas_mixture/removed = air1.remove(transfer_moles) - return removed + if(network1) + network1.update = 1 - else - last_pressure_delta = 0 + if(network2) + network2.update = 1 - process() - ..() - update_icon() + return removed + else + last_pressure_delta = 0 + +/obj/machinery/atmospherics/binary/circulator/process() + ..() update_icon() - 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[side]-slow" - else - icon_state = "circ[side]-off" - return 1 \ No newline at end of file +/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) + icon_state = "circ-run" + else + icon_state = "circ-slow" + else + icon_state = "circ-off" + + return 1 + +/obj/machinery/atmospherics/binary/circulator/attackby(obj/item/weapon/W as obj, mob/user as mob) + if(istype(W, /obj/item/weapon/wrench)) + anchored = !anchored + user << "\blue You [anchored ? "secure" : "unsecure"] the bolts holding [src] to the floor." + + if(anchored) + if(dir & (NORTH|SOUTH)) + initialize_directions = NORTH|SOUTH + else if(dir & (EAST|WEST)) + initialize_directions = EAST|WEST + + initialize() + build_network() + if (node1) + node1.initialize() + node1.build_network() + if (node2) + node2.initialize() + node2.build_network() + else + if(node1) + node1.disconnect(src) + del(network1) + if(node2) + node2.disconnect(src) + del(network2) + + node1 = null + node2 = null + + else + ..() + +/obj/machinery/atmospherics/binary/circulator/verb/rotate() + set category = "Object" + set name = "Rotate Circulator" + 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)]." diff --git a/code/modules/power/generator.dm b/code/modules/power/generator.dm index e7e1f1e657d..7eaf4d1b018 100644 --- a/code/modules/power/generator.dm +++ b/code/modules/power/generator.dm @@ -1,18 +1,14 @@ -// dummy generator object for testing -/*/obj/machinery/power/generator/verb/set_amount(var/g as num) - set src in view(1) - - gen_amount = g - -*/ +//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." icon_state = "teg" - anchored = 1 density = 1 use_power = 0 + anchored = 0 + idle_power_usage = 50 + active_power_usage = 1000 var/obj/machinery/atmospherics/binary/circulator/circ1 var/obj/machinery/atmospherics/binary/circulator/circ2 @@ -20,28 +16,39 @@ var/lastgen = 0 var/lastgenlev = -1 - /obj/machinery/power/generator/New() ..() - spawn(5) - circ1 = locate(/obj/machinery/atmospherics/binary/circulator) in get_step(src,WEST) - circ2 = locate(/obj/machinery/atmospherics/binary/circulator) in get_step(src,EAST) + spawn(1) + reconnect() - if(circ1) - circ1.side = 1 - circ1.update_icon() - if(circ2) - circ2.side = 2 - circ2.update_icon() +//generators connect in dir and reverse_dir(dir) directions +//mnemonic to determine circulator/generator directions: the cirulators orbit clockwise around the generator +//so a circulator to the NORTH of the generator connects first to the EAST, then to the WEST +//and a circulator to the WEST of the generator connects first to the NORTH, then to the SOUTH +//note that the circulator's outlet dir is it's always facing dir, and it's inlet is always the reverse +/obj/machinery/power/generator/proc/reconnect() + circ1 = null + circ2 = null + if(src.loc && anchored) + if(src.dir & (EAST|WEST)) + circ1 = locate(/obj/machinery/atmospherics/binary/circulator) in get_step(src,EAST) + circ2 = locate(/obj/machinery/atmospherics/binary/circulator) in get_step(src,WEST) - if(!circ1 || !circ2) - stat |= BROKEN + if(circ1 && circ2) + if(circ1.dir != SOUTH || circ2.dir != NORTH) + circ1 = null + circ2 = null - updateicon() + else if(src.dir & (NORTH|SOUTH)) + circ1 = locate(/obj/machinery/atmospherics/binary/circulator) in get_step(src,NORTH) + circ2 = locate(/obj/machinery/atmospherics/binary/circulator) in get_step(src,SOUTH) + + if(circ1 && circ2 && (circ1.dir != EAST || circ2.dir != WEST)) + circ1 = null + circ2 = null /obj/machinery/power/generator/proc/updateicon() - if(stat & (NOPOWER|BROKEN)) overlays.Cut() else @@ -56,57 +63,64 @@ //world << "Generator process ran" - if(!circ1 || !circ2) + if(!circ1 || !circ2 || !anchored || stat & (BROKEN|NOPOWER)) return //world << "circ1 and circ2 pass" - var/datum/gas_mixture/cold_air = circ1.return_transfer_air() - var/datum/gas_mixture/hot_air = circ2.return_transfer_air() + 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(cold_air && hot_air) + if(air1 && air2) - //world << "hot_air = [hot_air] temperature = [hot_air.temperature]; cold_air = [cold_air] temperature = [hot_air.temperature];" + //world << "hot_air = [hot_air] temperature = [air2.temperature]; cold_air = [cold_air] temperature = [air2.temperature];" //world << "coldair and hotair pass" - var/cold_air_heat_capacity = cold_air.heat_capacity() - var/hot_air_heat_capacity = hot_air.heat_capacity() + var/air1_heat_capacity = air1.heat_capacity() + var/air2_heat_capacity = air2.heat_capacity() + var/delta_temperature = abs(air2.temperature - air1.temperature) - var/delta_temperature = hot_air.temperature - cold_air.temperature + //world << "delta_temperature = [delta_temperature]; air1_heat_capacity = [air1_heat_capacity]; air2_heat_capacity = [air2_heat_capacity]" - //world << "delta_temperature = [delta_temperature]; cold_air_heat_capacity = [cold_air_heat_capacity]; hot_air_heat_capacity = [hot_air_heat_capacity]" - - if(delta_temperature > 0 && cold_air_heat_capacity > 0 && hot_air_heat_capacity > 0) + if(delta_temperature > 0 && air1_heat_capacity > 0 && air2_heat_capacity > 0) + use_power = 2 var/efficiency = 0.65 - - var/energy_transfer = delta_temperature*hot_air_heat_capacity*cold_air_heat_capacity/(hot_air_heat_capacity+cold_air_heat_capacity) - + 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]; hot_air_heat_capacity = [hot_air_heat_capacity]; cold_air_heat_capacity = [cold_air_heat_capacity];" + //world << "lastgen = [lastgen]; heat = [heat]; delta_temperature = [delta_temperature]; air2_heat_capacity = [air2_heat_capacity]; air1_heat_capacity = [air1_heat_capacity];" - hot_air.temperature = hot_air.temperature - energy_transfer/hot_air_heat_capacity - cold_air.temperature = cold_air.temperature + heat/cold_air_heat_capacity + if(air2.temperature > air1.temperature) + air2.temperature = air2.temperature - energy_transfer/air2_heat_capacity + air1.temperature = air1.temperature + heat/air1_heat_capacity + else + 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 [cold_air_heat_capacity], [hot_air_heat_capacity]" + //world << "POWER: [lastgen] W generated at [efficiency*100]% efficiency and sinks sizes [air1_heat_capacity], [air2_heat_capacity]" add_avail(lastgen) - // update icon overlays only if displayed level has changed - if(hot_air) - circ2.air2.merge(hot_air) + if(air1) + circ1.air2.merge(air1) - if(cold_air) - circ1.air2.merge(cold_air) + if(air2) + circ2.air2.merge(air2) + // 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() @@ -115,10 +129,18 @@ if(stat & (BROKEN|NOPOWER)) return interact(user) +/obj/machinery/power/generator/attackby(obj/item/weapon/W as obj, mob/user as mob) + if(istype(W, /obj/item/weapon/wrench)) + anchored = !anchored + user << "\blue You [anchored ? "secure" : "unsecure"] the bolts holding [src] to the floor." + use_power = anchored + reconnect() + else + ..() /obj/machinery/power/generator/attack_hand(mob/user) add_fingerprint(user) - if(stat & (BROKEN|NOPOWER)) return + if(stat & (BROKEN|NOPOWER) || !anchored) return interact(user) @@ -132,19 +154,28 @@ var/t = "
Thermo-Electric Generator" user << browse(t, "window=teg;size=460x300") onclose(user, "teg") return 1 @@ -156,6 +187,7 @@ usr << browse(null, "window=teg") usr.unset_machine() return 0 + updateDialog() return 1 @@ -163,3 +195,13 @@ ..() updateicon() + +/obj/machinery/power/generator/verb/rotate() + set category = "Object" + set name = "Rotate Generator" + set src in view(1) + + if (usr.stat || usr.restrained() || anchored) + return + + src.dir = turn(src.dir, 90) diff --git a/icons/obj/pipes.dmi b/icons/obj/pipes.dmi index eace98cda47..7a99757c0dd 100644 Binary files a/icons/obj/pipes.dmi and b/icons/obj/pipes.dmi differ diff --git a/icons/obj/power.dmi b/icons/obj/power.dmi index b9cdd3aec60..b0130821d4d 100644 Binary files a/icons/obj/power.dmi and b/icons/obj/power.dmi differ
" - t += "Output : [round(lastgen)] W
" + if(circ1 && circ2) + t += "Output : [round(lastgen)] W
" - t += "Cold loop
" - t += "Temperature Inlet: [round(circ1.air1.temperature, 0.1)] K Outlet: [round(circ1.air2.temperature, 0.1)] K
" - t += "Pressure Inlet: [round(circ1.air1.return_pressure(), 0.1)] kPa Outlet: [round(circ1.air2.return_pressure(), 0.1)] kPa
" + t += "Primary Circulator (top/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 += "Hot loop
" - t += "Temperature Inlet: [round(circ2.air1.temperature, 0.1)] K Outlet: [round(circ2.air2.temperature, 0.1)] K
" - t += "Pressure Inlet: [round(circ2.air1.return_pressure(), 0.1)] kPa Outlet: [round(circ2.air2.return_pressure(), 0.1)] kPa
" + t += "Secondary Circulator (bottom/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
" + else + t += "Unable to connect to circulators.
" + t += "Ensure both are in position and wrenched into place." - t += "
Close" + t += "
" + t += "
" + t += "Refresh Close" - t += "