Gas filters and mixers can be connected and wrenched around like any other pipe machinery, and new ones can be extruded from the pipe dispenser.

git-svn-id: http://tgstation13.googlecode.com/svn/trunk@2338 316c924e-a436-60f5-8080-3fe189b3f50e
This commit is contained in:
bbusse@gmail.com
2011-10-09 20:57:36 +00:00
parent df24bd1cbf
commit 90e0297389
10 changed files with 732 additions and 812 deletions
-389
View File
@@ -1,389 +0,0 @@
obj/machinery/atmospherics/filter
icon = 'filter.dmi'
icon_state = "intact_off"
density = 1
name = "Gas filter"
dir = SOUTH
initialize_directions = SOUTH|NORTH|WEST
req_access = list(access_atmospherics)
var/on = 0
var/temp = null // -- TLE
var/datum/gas_mixture/air_in
var/datum/gas_mixture/air_out1
var/datum/gas_mixture/air_out2
var/obj/machinery/atmospherics/node_in
var/obj/machinery/atmospherics/node_out1
var/obj/machinery/atmospherics/node_out2
var/datum/pipe_network/network_in
var/datum/pipe_network/network_out1
var/datum/pipe_network/network_out2
var/target_pressure = ONE_ATMOSPHERE
var/filter_type = 0
/*
Filter types:
-1: Nothing
0: Carbon Molecules: Plasma Toxin, Oxygen Agent B
1: Oxygen: Oxygen ONLY
2: Nitrogen: Nitrogen ONLY
3: Carbon Dioxide: Carbon Dioxide ONLY
4: Sleeping Agent (N2O)
*/
var/frequency = 0
var/datum/radio_frequency/radio_connection
proc
set_frequency(new_frequency)
radio_controller.remove_object(src, frequency)
frequency = new_frequency
if(frequency)
radio_connection = radio_controller.add_object(src, frequency, RADIO_ATMOSIA)
New()
..()
switch(dir)
if(NORTH)
initialize_directions = NORTH|EAST|SOUTH
if(SOUTH)
initialize_directions = NORTH|SOUTH|WEST
if(EAST)
initialize_directions = EAST|WEST|SOUTH
if(WEST)
initialize_directions = NORTH|EAST|WEST
if(radio_controller)
initialize()
update_icon()
if(node_out1&&node_out2&&node_in)
icon_state = "intact_[on?("on"):("off")]"
else
var/node_out1_direction = get_dir(src, node_out1)
var/node_out2_direction = get_dir(src, node_out2)
var/node_in_bit = (node_in)?(1):(0)
icon_state = "exposed_[node_out1_direction|node_out2_direction]_[node_in_bit]_off"
on = 0
return
New()
..()
air_in = new
air_out1 = new
air_out2 = new
air_in.volume = 200
air_out1.volume = 200
air_out2.volume = 200
process()
..()
if(!on)
return 0
var/output_starting_pressure = air_out2.return_pressure()
if(output_starting_pressure >= target_pressure)
//No need to mix if target is already full!
return 1
//Calculate necessary moles to transfer using PV=nRT
var/pressure_delta = target_pressure - output_starting_pressure
var/transfer_moles
if(air_in.temperature > 0)
transfer_moles = pressure_delta*air_out2.volume/(air_in.temperature * R_IDEAL_GAS_EQUATION)
//Actually transfer the gas
if(transfer_moles > 0)
var/datum/gas_mixture/removed = air_in.remove(transfer_moles)
if(!removed)
return
var/datum/gas_mixture/filtered_out = new
filtered_out.temperature = removed.temperature
switch(filter_type)
if(0) //removing hydrocarbons
filtered_out.toxins = removed.toxins
removed.toxins = 0
if(removed.trace_gases.len>0)
for(var/datum/gas/trace_gas in removed.trace_gases)
if(istype(trace_gas, /datum/gas/oxygen_agent_b))
removed.trace_gases -= trace_gas
filtered_out.trace_gases += trace_gas
if(1) //removing O2
filtered_out.oxygen = removed.oxygen
removed.oxygen = 0
if(2) //removing N2
filtered_out.nitrogen = removed.nitrogen
removed.nitrogen = 0
if(3) //removing CO2
filtered_out.carbon_dioxide = removed.carbon_dioxide
removed.carbon_dioxide = 0
if(4)//removing N2O
if(removed.trace_gases.len>0)
for(var/datum/gas/trace_gas in removed.trace_gases)
if(istype(trace_gas, /datum/gas/sleeping_agent))
removed.trace_gases -= trace_gas
filtered_out.trace_gases += trace_gas
else
filtered_out = null
air_out1.merge(filtered_out)
air_out2.merge(removed)
if(network_out1)
network_out1.update = 1
if(network_out2)
network_out2.update = 1
if(network_in)
network_in.update = 1
return 1
// Housekeeping and pipe network stuff below
network_expand(datum/pipe_network/new_network, obj/machinery/atmospherics/pipe/reference)
if(reference == node_out1)
network_out1 = new_network
else if(reference == node_out2)
network_out2 = new_network
else if(reference == node_in)
network_in = new_network
if(new_network.normal_members.Find(src))
return 0
new_network.normal_members += src
return null
Del()
loc = null
if(node_out1)
node_out1.disconnect(src)
del(network_out1)
if(node_out2)
node_out2.disconnect(src)
del(network_out2)
if(node_in)
node_in.disconnect(src)
del(network_in)
node_out1 = null
node_out2 = null
node_in = null
..()
initialize()
if(node_out1 && node_in) return
var/node_in_connect = turn(dir, -180)
var/node_out1_connect = turn(dir, -90)
var/node_out2_connect = dir
for(var/obj/machinery/atmospherics/target in get_step(src,node_out1_connect))
if(target.initialize_directions & get_dir(target,src))
node_out1 = target
break
for(var/obj/machinery/atmospherics/target in get_step(src,node_out2_connect))
if(target.initialize_directions & get_dir(target,src))
node_out2 = target
break
for(var/obj/machinery/atmospherics/target in get_step(src,node_in_connect))
if(target.initialize_directions & get_dir(target,src))
node_in = target
break
update_icon()
set_frequency(frequency)
build_network()
if(!network_out1 && node_out1)
network_out1 = new /datum/pipe_network()
network_out1.normal_members += src
network_out1.build_network(node_out1, src)
if(!network_out2 && node_out2)
network_out2 = new /datum/pipe_network()
network_out2.normal_members += src
network_out2.build_network(node_out2, src)
if(!network_in && node_in)
network_in = new /datum/pipe_network()
network_in.normal_members += src
network_in.build_network(node_in, src)
return_network(obj/machinery/atmospherics/reference)
build_network()
if(reference==node_out1)
return network_out1
if(reference==node_out2)
return network_out2
if(reference==node_in)
return network_in
return null
reassign_network(datum/pipe_network/old_network, datum/pipe_network/new_network)
if(network_out1 == old_network)
network_out1 = new_network
if(network_out2 == old_network)
network_out2 = new_network
if(network_in == old_network)
network_in = new_network
return 1
return_network_air(datum/pipe_network/reference)
var/list/results = list()
if(network_out1 == reference)
results += air_out1
if(network_out2 == reference)
results += air_out2
if(network_in == reference)
results += air_in
return results
disconnect(obj/machinery/atmospherics/reference)
if(reference==node_out1)
del(network_out1)
node_out1 = null
else if(reference==node_out2)
del(network_out2)
node_out2 = null
else if(reference==node_in)
del(network_in)
node_in = null
return null
obj/machinery/atmospherics/filter/attack_hand(user as mob) // -- TLE
if(..())
return
if(!src.allowed(user))
user << "\red Access denied."
return
/*
dat += "Autolathe Wires:<BR>"
var/wire
for(wire in src.wires)
dat += text("[wire] Wire: <A href='?src=\ref[src];wire=[wire];act=wire'>[src.wires[wire] ? "Mend" : "Cut"]</A> <A href='?src=\ref[src];wire=[wire];act=pulse'>Pulse</A><BR>")
dat += text("The red light is [src.disabled ? "off" : "on"].<BR>")
dat += text("The green light is [src.shocked ? "off" : "on"].<BR>")
dat += text("The blue light is [src.hacked ? "off" : "on"].<BR>")
*/
var/dat
var/current_filter_type
switch(filter_type)
if(0)
current_filter_type = "Carbon Molecules"
if(1)
current_filter_type = "Oxygen"
if(2)
current_filter_type = "Nitrogen"
if(3)
current_filter_type = "Carbon Dioxide"
if(4)
current_filter_type = "Nitrous Oxide"
if(-1)
current_filter_type = "Nothing"
else
current_filter_type = "ERROR - Report this bug to the admin, please!"
dat += {"
<b>Power: </b><a href='?src=\ref[src];power=1'>[on?"On":"Off"]</a><br>
<b>Filtering: </b>[current_filter_type]<br><HR>
<h4>Set Filter Type:</h4>
<A href='?src=\ref[src];filterset=0'>Carbon Molecules</A><BR>
<A href='?src=\ref[src];filterset=1'>Oxygen</A><BR>
<A href='?src=\ref[src];filterset=2'>Nitrogen</A><BR>
<A href='?src=\ref[src];filterset=3'>Carbon Dioxide</A><BR>
<A href='?src=\ref[src];filterset=4'>Nitrous Oxide</A><BR>
<A href='?src=\ref[src];filterset=-1'>Nothing</A><BR>
<HR><B>Desirable output pressure:</B>
[src.target_pressure] | <a href='?src=\ref[src];set_press=1'>Change</a>
"}
/*
user << browse("<HEAD><TITLE>[src.name] control</TITLE></HEAD>[dat]","window=atmo_filter")
onclose(user, "atmo_filter")
return
if (src.temp)
dat = text("<TT>[]</TT><BR><BR><A href='?src=\ref[];temp=1'>Clear Screen</A>", src.temp, src)
//else
// src.on != src.on
*/
user << browse("<HEAD><TITLE>[src.name] control</TITLE></HEAD><TT>[dat]</TT>", "window=atmo_filter")
onclose(user, "atmo_filter")
return
obj/machinery/atmospherics/filter/Topic(href, href_list) // -- TLE
if(..())
return
usr.machine = src
src.add_fingerprint(usr)
if(href_list["filterset"])
src.filter_type = text2num(href_list["filterset"])
if (href_list["temp"])
src.temp = null
if(href_list["set_press"])
var/new_pressure = input(usr,"Enter new output pressure (0-4500kPa)","Pressure control",src.target_pressure) as num
src.target_pressure = max(0, min(4500, new_pressure))
if(href_list["power"])
on=!on
src.update_icon()
src.updateUsrDialog()
/*
for(var/mob/M in viewers(1, src))
if ((M.client && M.machine == src))
src.attack_hand(M)
*/
return
-301
View File
@@ -1,301 +0,0 @@
obj/machinery/atmospherics/mixer
icon = 'mixer.dmi'
icon_state = "intact_off"
density = 1
name = "Gas mixer"
dir = SOUTH
initialize_directions = SOUTH|NORTH|WEST
req_access = list(access_atmospherics)
var/on = 0
var/datum/gas_mixture/air_in1
var/datum/gas_mixture/air_in2
var/datum/gas_mixture/air_out
var/obj/machinery/atmospherics/node_in1
var/obj/machinery/atmospherics/node_in2
var/obj/machinery/atmospherics/node_out
var/datum/pipe_network/network_in1
var/datum/pipe_network/network_in2
var/datum/pipe_network/network_out
var/target_pressure = ONE_ATMOSPHERE
var/node1_concentration = 0.5
var/node2_concentration = 0.5
update_icon()
if(node_in1&&node_in2&&node_out)
icon_state = "intact_[on?("on"):("off")]"
else
var/node_in1_direction = get_dir(src, node_in1)
var/node_in2_direction = get_dir(src, node_in2)
var/node_out_bit = (node_out)?(1):(0)
icon_state = "exposed_[node_in1_direction|node_in2_direction]_[node_out_bit]_off"
on = 0
return
New()
..()
switch(dir)
if(NORTH)
initialize_directions = NORTH|EAST|SOUTH
if(EAST)
initialize_directions = EAST|SOUTH|WEST
if(SOUTH)
initialize_directions = SOUTH|WEST|NORTH
if(WEST)
initialize_directions = WEST|NORTH|EAST
air_in1 = new
air_in2 = new
air_out = new
air_in1.volume = 200
air_in2.volume = 200
air_out.volume = 300
process()
..()
if(!on)
return 0
var/output_starting_pressure = air_out.return_pressure()
if(output_starting_pressure >= target_pressure)
//No need to mix if target is already full!
return 1
//Calculate necessary moles to transfer using PV=nRT
var/pressure_delta = target_pressure - output_starting_pressure
var/transfer_moles1 = 0
var/transfer_moles2 = 0
if(air_in1.temperature > 0)
transfer_moles1 = (node1_concentration*pressure_delta)*air_out.volume/(air_in1.temperature * R_IDEAL_GAS_EQUATION)
if(air_in2.temperature > 0)
transfer_moles2 = (node2_concentration*pressure_delta)*air_out.volume/(air_in2.temperature * R_IDEAL_GAS_EQUATION)
var/air_in1_moles = air_in1.total_moles()
var/air_in2_moles = air_in2.total_moles()
if((air_in1_moles < transfer_moles1) || (air_in2_moles < transfer_moles2))
if(!transfer_moles1 || !transfer_moles2) return
var/ratio = min(air_in1_moles/transfer_moles1, air_in2_moles/transfer_moles2)
transfer_moles1 *= ratio
transfer_moles2 *= ratio
//Actually transfer the gas
if(transfer_moles1 > 0)
var/datum/gas_mixture/removed1 = air_in1.remove(transfer_moles1)
air_out.merge(removed1)
if(transfer_moles2 > 0)
var/datum/gas_mixture/removed2 = air_in2.remove(transfer_moles2)
air_out.merge(removed2)
if(network_in1 && transfer_moles1)
network_in1.update = 1
if(network_in2 && transfer_moles2)
network_in2.update = 1
if(network_out)
network_out.update = 1
return 1
// Housekeeping and pipe network stuff below
network_expand(datum/pipe_network/new_network, obj/machinery/atmospherics/pipe/reference)
if(reference == node_in1)
network_in1 = new_network
else if(reference == node_in2)
network_in2 = new_network
else if(reference == node_out)
network_out = new_network
if(new_network.normal_members.Find(src))
return 0
new_network.normal_members += src
return null
Del()
loc = null
if(node_in1)
node_in1.disconnect(src)
del(network_in1)
if(node_in2)
node_in2.disconnect(src)
del(network_in2)
if(node_out)
node_out.disconnect(src)
del(network_out)
node_in1 = null
node_in2 = null
node_out = null
..()
initialize()
if(node_in1 && node_out) return
var/node_out_connect = dir
var/node_in1_connect = turn(dir, -90)
var/node_in2_connect = turn(dir, -180)
for(var/obj/machinery/atmospherics/target in get_step(src,node_in1_connect))
if(target.initialize_directions & get_dir(target,src))
node_in1 = target
break
for(var/obj/machinery/atmospherics/target in get_step(src,node_in2_connect))
if(target.initialize_directions & get_dir(target,src))
node_in2 = target
break
for(var/obj/machinery/atmospherics/target in get_step(src,node_out_connect))
if(target.initialize_directions & get_dir(target,src))
node_out = target
break
update_icon()
build_network()
if(!network_in1 && node_in1)
network_in1 = new /datum/pipe_network()
network_in1.normal_members += src
network_in1.build_network(node_in1, src)
if(!network_in2 && node_in2)
network_in2 = new /datum/pipe_network()
network_in2.normal_members += src
network_in2.build_network(node_in2, src)
if(!network_out && node_out)
network_out = new /datum/pipe_network()
network_out.normal_members += src
network_out.build_network(node_out, src)
return_network(obj/machinery/atmospherics/reference)
build_network()
if(reference==node_in1)
return network_in1
if(reference==node_in2)
return network_in2
if(reference==node_out)
return network_out
return null
reassign_network(datum/pipe_network/old_network, datum/pipe_network/new_network)
if(network_in1 == old_network)
network_in1 = new_network
if(network_in2 == old_network)
network_in2 = new_network
if(network_out == old_network)
network_out = new_network
return 1
return_network_air(datum/pipe_network/reference)
var/list/results = list()
if(network_in1 == reference)
results += air_in1
if(network_in2 == reference)
results += air_in2
if(network_out == reference)
results += air_out
return results
disconnect(obj/machinery/atmospherics/reference)
if(reference==node_in1)
del(network_in1)
node_in1 = null
else if(reference==node_in2)
del(network_in2)
node_in2 = null
else if(reference==node_out)
del(network_out)
node_out = null
return null
attack_hand(user as mob)
if(..())
return
src.add_fingerprint(usr)
if(!src.allowed(user))
user << "\red Access denied."
return
usr.machine = src
var/dat = {"<b>Power: </b><a href='?src=\ref[src];power=1'>[on?"On":"Off"]</a><br>
<b>Desirable output pressure: </b>
[target_pressure]kPa | <a href='?src=\ref[src];set_press=1'>Change</a>
<br>
<b>Node 1 Concentration:</b>
<a href='?src=\ref[src];node1_c=-0.1'><b>-</b></a>
<a href='?src=\ref[src];node1_c=-0.01'>-</a>
[node1_concentration]([node1_concentration*100]%)
<a href='?src=\ref[src];node1_c=0.01'><b>+</b></a>
<a href='?src=\ref[src];node1_c=0.1'>+</a>
<br>
<b>Node 2 Concentration:</b>
<a href='?src=\ref[src];node2_c=-0.1'><b>-</b></a>
<a href='?src=\ref[src];node2_c=-0.01'>-</a>
[node2_concentration]([node2_concentration*100]%)
<a href='?src=\ref[src];node2_c=0.01'><b>+</b></a>
<a href='?src=\ref[src];node2_c=0.1'>+</a>
"}
user << browse("<HEAD><TITLE>[src.name] control</TITLE></HEAD><TT>[dat]</TT>", "window=atmo_mixer")
onclose(user, "atmo_mixer")
return
Topic(href,href_list)
if(href_list["power"])
on = !on
if(href_list["set_press"])
var/new_pressure = input(usr,"Enter new output pressure (0-4500kPa)","Pressure control",src.target_pressure) as num
src.target_pressure = max(0, min(4500, new_pressure))
if(href_list["node1_c"])
var/value = text2num(href_list["node1_c"])
src.node1_concentration = max(0, min(1, src.node1_concentration + value))
src.node2_concentration = max(0, min(1, src.node2_concentration - value))
if(href_list["node2_c"])
var/value = text2num(href_list["node2_c"])
src.node2_concentration = max(0, min(1, src.node2_concentration + value))
src.node1_concentration = max(0, min(1, src.node1_concentration - value))
src.update_icon()
src.updateUsrDialog()
return
@@ -0,0 +1,234 @@
obj/machinery/atmospherics/trinary/filter
icon = 'filter.dmi'
icon_state = "intact_off"
density = 1
name = "Gas filter"
req_access = list(access_atmospherics)
var/on = 0
var/temp = null // -- TLE
var/target_pressure = ONE_ATMOSPHERE
var/filter_type = 0
/*
Filter types:
-1: Nothing
0: Carbon Molecules: Plasma Toxin, Oxygen Agent B
1: Oxygen: Oxygen ONLY
2: Nitrogen: Nitrogen ONLY
3: Carbon Dioxide: Carbon Dioxide ONLY
4: Sleeping Agent (N2O)
*/
var/frequency = 0
var/datum/radio_frequency/radio_connection
proc
set_frequency(new_frequency)
radio_controller.remove_object(src, frequency)
frequency = new_frequency
if(frequency)
radio_connection = radio_controller.add_object(src, frequency, RADIO_ATMOSIA)
New()
if(radio_controller)
initialize()
..()
update_icon()
if(node2 && node3 && node1)
icon_state = "intact_[on?("on"):("off")]"
else
icon_state = "hintact_off"
on = 0
return
New()
..()
process()
..()
if(!on)
return 0
var/output_starting_pressure = air3.return_pressure()
if(output_starting_pressure >= target_pressure)
//No need to mix if target is already full!
return 1
//Calculate necessary moles to transfer using PV=nRT
var/pressure_delta = target_pressure - output_starting_pressure
var/transfer_moles
if(air1.temperature > 0)
transfer_moles = pressure_delta*air3.volume/(air1.temperature * R_IDEAL_GAS_EQUATION)
//Actually transfer the gas
if(transfer_moles > 0)
var/datum/gas_mixture/removed = air1.remove(transfer_moles)
if(!removed)
return
var/datum/gas_mixture/filtered_out = new
filtered_out.temperature = removed.temperature
switch(filter_type)
if(0) //removing hydrocarbons
filtered_out.toxins = removed.toxins
removed.toxins = 0
if(removed.trace_gases.len>0)
for(var/datum/gas/trace_gas in removed.trace_gases)
if(istype(trace_gas, /datum/gas/oxygen_agent_b))
removed.trace_gases -= trace_gas
filtered_out.trace_gases += trace_gas
if(1) //removing O2
filtered_out.oxygen = removed.oxygen
removed.oxygen = 0
if(2) //removing N2
filtered_out.nitrogen = removed.nitrogen
removed.nitrogen = 0
if(3) //removing CO2
filtered_out.carbon_dioxide = removed.carbon_dioxide
removed.carbon_dioxide = 0
if(4)//removing N2O
if(removed.trace_gases.len>0)
for(var/datum/gas/trace_gas in removed.trace_gases)
if(istype(trace_gas, /datum/gas/sleeping_agent))
removed.trace_gases -= trace_gas
filtered_out.trace_gases += trace_gas
else
filtered_out = null
air2.merge(filtered_out)
air3.merge(removed)
if(network2)
network2.update = 1
if(network3)
network3.update = 1
if(network1)
network1.update = 1
return 1
initialize()
set_frequency(frequency)
..()
attackby(var/obj/item/weapon/W as obj, var/mob/user as mob)
if (!istype(W, /obj/item/weapon/wrench))
return ..()
var/turf/T = src.loc
if (level==1 && isturf(T) && T.intact)
user << "\red You must remove the plating first."
return 1
var/datum/gas_mixture/int_air = return_air()
var/datum/gas_mixture/env_air = loc.return_air()
if ((int_air.return_pressure()-env_air.return_pressure()) > 2*ONE_ATMOSPHERE)
user << "\red You cannot unwrench this [src], it too exerted due to internal pressure."
add_fingerprint(user)
return 1
playsound(src.loc, 'Ratchet.ogg', 50, 1)
user << "\blue You begin to unfasten \the [src]..."
if (do_after(user, 40))
user.visible_message( \
"[user] unfastens \the [src].", \
"\blue You have unfastened \the [src].", \
"You hear ratchet.")
new /obj/item/pipe(loc, make_from=src)
del(src)
obj/machinery/atmospherics/trinary/filter/attack_hand(user as mob) // -- TLE
if(..())
return
if(!src.allowed(user))
user << "\red Access denied."
return
var/dat
var/current_filter_type
switch(filter_type)
if(0)
current_filter_type = "Carbon Molecules"
if(1)
current_filter_type = "Oxygen"
if(2)
current_filter_type = "Nitrogen"
if(3)
current_filter_type = "Carbon Dioxide"
if(4)
current_filter_type = "Nitrous Oxide"
if(-1)
current_filter_type = "Nothing"
else
current_filter_type = "ERROR - Report this bug to the admin, please!"
dat += {"
<b>Power: </b><a href='?src=\ref[src];power=1'>[on?"On":"Off"]</a><br>
<b>Filtering: </b>[current_filter_type]<br><HR>
<h4>Set Filter Type:</h4>
<A href='?src=\ref[src];filterset=0'>Carbon Molecules</A><BR>
<A href='?src=\ref[src];filterset=1'>Oxygen</A><BR>
<A href='?src=\ref[src];filterset=2'>Nitrogen</A><BR>
<A href='?src=\ref[src];filterset=3'>Carbon Dioxide</A><BR>
<A href='?src=\ref[src];filterset=4'>Nitrous Oxide</A><BR>
<A href='?src=\ref[src];filterset=-1'>Nothing</A><BR>
<HR><B>Desirable output pressure:</B>
[src.target_pressure] | <a href='?src=\ref[src];set_press=1'>Change</a>
"}
/*
user << browse("<HEAD><TITLE>[src.name] control</TITLE></HEAD>[dat]","window=atmo_filter")
onclose(user, "atmo_filter")
return
if (src.temp)
dat = text("<TT>[]</TT><BR><BR><A href='?src=\ref[];temp=1'>Clear Screen</A>", src.temp, src)
//else
// src.on != src.on
*/
user << browse("<HEAD><TITLE>[src.name] control</TITLE></HEAD><TT>[dat]</TT>", "window=atmo_filter")
onclose(user, "atmo_filter")
return
obj/machinery/atmospherics/trinary/filter/Topic(href, href_list) // -- TLE
if(..())
return
usr.machine = src
src.add_fingerprint(usr)
if(href_list["filterset"])
src.filter_type = text2num(href_list["filterset"])
if (href_list["temp"])
src.temp = null
if(href_list["set_press"])
var/new_pressure = input(usr,"Enter new output pressure (0-4500kPa)","Pressure control",src.target_pressure) as num
src.target_pressure = max(0, min(4500, new_pressure))
if(href_list["power"])
on=!on
src.update_icon()
src.updateUsrDialog()
/*
for(var/mob/M in viewers(1, src))
if ((M.client && M.machine == src))
src.attack_hand(M)
*/
return
@@ -0,0 +1,155 @@
obj/machinery/atmospherics/trinary/mixer
icon = 'mixer.dmi'
icon_state = "intact_off"
density = 1
name = "Gas mixer"
req_access = list(access_atmospherics)
var/on = 0
var/target_pressure = ONE_ATMOSPHERE
var/node1_concentration = 0.5
var/node2_concentration = 0.5
//node 3 is the outlet, nodes 1 & 2 are intakes
update_icon()
if(node2 && node3 && node1)
icon_state = "intact_[on?("on"):("off")]"
else
icon_state = "intact_off"
on = 0
return
New()
..()
air3.volume = 300
process()
..()
if(!on)
return 0
var/output_starting_pressure = air3.return_pressure()
if(output_starting_pressure >= target_pressure)
//No need to mix if target is already full!
return 1
//Calculate necessary moles to transfer using PV=nRT
var/pressure_delta = target_pressure - output_starting_pressure
var/transfer_moles1 = 0
var/transfer_moles2 = 0
if(air1.temperature > 0)
transfer_moles1 = (node1_concentration*pressure_delta)*air3.volume/(air1.temperature * R_IDEAL_GAS_EQUATION)
if(air2.temperature > 0)
transfer_moles2 = (node2_concentration*pressure_delta)*air3.volume/(air2.temperature * R_IDEAL_GAS_EQUATION)
var/air1_moles = air1.total_moles()
var/air2_moles = air2.total_moles()
if((air1_moles < transfer_moles1) || (air2_moles < transfer_moles2))
if(!transfer_moles1 || !transfer_moles2) return
var/ratio = min(air1_moles/transfer_moles1, air2_moles/transfer_moles2)
transfer_moles1 *= ratio
transfer_moles2 *= ratio
//Actually transfer the gas
if(transfer_moles1 > 0)
var/datum/gas_mixture/removed1 = air1.remove(transfer_moles1)
air3.merge(removed1)
if(transfer_moles2 > 0)
var/datum/gas_mixture/removed2 = air2.remove(transfer_moles2)
air3.merge(removed2)
if(network1 && transfer_moles1)
network1.update = 1
if(network2 && transfer_moles2)
network2.update = 1
if(network3)
network3.update = 1
return 1
attackby(var/obj/item/weapon/W as obj, var/mob/user as mob)
if (!istype(W, /obj/item/weapon/wrench))
return ..()
var/turf/T = src.loc
if (level==1 && isturf(T) && T.intact)
user << "\red You must remove the plating first."
return 1
var/datum/gas_mixture/int_air = return_air()
var/datum/gas_mixture/env_air = loc.return_air()
if ((int_air.return_pressure()-env_air.return_pressure()) > 2*ONE_ATMOSPHERE)
user << "\red You cannot unwrench this [src], it too exerted due to internal pressure."
add_fingerprint(user)
return 1
playsound(src.loc, 'Ratchet.ogg', 50, 1)
user << "\blue You begin to unfasten \the [src]..."
if (do_after(user, 40))
user.visible_message( \
"[user] unfastens \the [src].", \
"\blue You have unfastened \the [src].", \
"You hear ratchet.")
new /obj/item/pipe(loc, make_from=src)
del(src)
attack_hand(user as mob)
if(..())
return
src.add_fingerprint(usr)
if(!src.allowed(user))
user << "\red Access denied."
return
usr.machine = src
var/dat = {"<b>Power: </b><a href='?src=\ref[src];power=1'>[on?"On":"Off"]</a><br>
<b>Desirable output pressure: </b>
[target_pressure]kPa | <a href='?src=\ref[src];set_press=1'>Change</a>
<br>
<b>Node 1 Concentration:</b>
<a href='?src=\ref[src];node1_c=-0.1'><b>-</b></a>
<a href='?src=\ref[src];node1_c=-0.01'>-</a>
[node1_concentration]([node1_concentration*100]%)
<a href='?src=\ref[src];node1_c=0.01'><b>+</b></a>
<a href='?src=\ref[src];node1_c=0.1'>+</a>
<br>
<b>Node 2 Concentration:</b>
<a href='?src=\ref[src];node2_c=-0.1'><b>-</b></a>
<a href='?src=\ref[src];node2_c=-0.01'>-</a>
[node2_concentration]([node2_concentration*100]%)
<a href='?src=\ref[src];node2_c=0.01'><b>+</b></a>
<a href='?src=\ref[src];node2_c=0.1'>+</a>
"}
user << browse("<HEAD><TITLE>[src.name] control</TITLE></HEAD><TT>[dat]</TT>", "window=atmo_mixer")
onclose(user, "atmo_mixer")
return
Topic(href,href_list)
if(href_list["power"])
on = !on
if(href_list["set_press"])
var/new_pressure = input(usr,"Enter new output pressure (0-4500kPa)","Pressure control",src.target_pressure) as num
src.target_pressure = max(0, min(4500, new_pressure))
if(href_list["node1_c"])
var/value = text2num(href_list["node1_c"])
src.node1_concentration = max(0, min(1, src.node1_concentration + value))
src.node2_concentration = max(0, min(1, src.node2_concentration - value))
if(href_list["node2_c"])
var/value = text2num(href_list["node2_c"])
src.node2_concentration = max(0, min(1, src.node2_concentration + value))
src.node1_concentration = max(0, min(1, src.node1_concentration - value))
src.update_icon()
src.updateUsrDialog()
return
@@ -0,0 +1,163 @@
obj/machinery/atmospherics/trinary
dir = SOUTH
initialize_directions = SOUTH|NORTH|WEST
var/datum/gas_mixture/air1
var/datum/gas_mixture/air2
var/datum/gas_mixture/air3
var/obj/machinery/atmospherics/node1
var/obj/machinery/atmospherics/node2
var/obj/machinery/atmospherics/node3
var/datum/pipe_network/network1
var/datum/pipe_network/network2
var/datum/pipe_network/network3
New()
..()
switch(dir)
if(NORTH)
initialize_directions = EAST|NORTH|SOUTH
if(SOUTH)
initialize_directions = SOUTH|WEST|NORTH
if(EAST)
initialize_directions = EAST|WEST|SOUTH
if(WEST)
initialize_directions = WEST|NORTH|EAST
air1 = new
air2 = new
air3 = new
air1.volume = 200
air2.volume = 200
air3.volume = 200
// Housekeeping and pipe network stuff below
network_expand(datum/pipe_network/new_network, obj/machinery/atmospherics/pipe/reference)
if(reference == node1)
network1 = new_network
else if(reference == node2)
network2 = new_network
else if (reference == node3)
network3 = new_network
if(new_network.normal_members.Find(src))
return 0
new_network.normal_members += src
return null
Del()
loc = null
if(node1)
node1.disconnect(src)
del(network1)
if(node2)
node2.disconnect(src)
del(network2)
if(node3)
node3.disconnect(src)
del(network3)
node1 = null
node2 = null
node3 = null
..()
initialize()
if(node1 && node2 && node3) return
var/node1_connect = turn(dir, -180)
var/node2_connect = turn(dir, -90)
var/node3_connect = dir
for(var/obj/machinery/atmospherics/target in get_step(src,node1_connect))
if(target.initialize_directions & get_dir(target,src))
node1 = target
break
for(var/obj/machinery/atmospherics/target in get_step(src,node2_connect))
if(target.initialize_directions & get_dir(target,src))
node2 = target
break
for(var/obj/machinery/atmospherics/target in get_step(src,node3_connect))
if(target.initialize_directions & get_dir(target,src))
node3 = target
break
update_icon()
build_network()
if(!network1 && node1)
network1 = new /datum/pipe_network()
network1.normal_members += src
network1.build_network(node1, src)
if(!network2 && node2)
network2 = new /datum/pipe_network()
network2.normal_members += src
network2.build_network(node2, src)
if(!network3 && node3)
network3 = new /datum/pipe_network()
network3.normal_members += src
network3.build_network(node3, src)
return_network(obj/machinery/atmospherics/reference)
build_network()
if(reference==node1)
return network1
if(reference==node2)
return network2
if(reference==node3)
return network3
return null
reassign_network(datum/pipe_network/old_network, datum/pipe_network/new_network)
if(network1 == old_network)
network1 = new_network
if(network2 == old_network)
network2 = new_network
if(network3 == old_network)
network3 = new_network
return 1
return_network_air(datum/pipe_network/reference)
var/list/results = list()
if(network1 == reference)
results += air1
if(network2 == reference)
results += air2
if(network3 == reference)
results += air3
return results
disconnect(obj/machinery/atmospherics/reference)
if(reference==node1)
del(network1)
node1 = null
else if(reference==node2)
del(network2)
node2 = null
else if(reference==node3)
del(network3)
node3 = null
return null