water pipes base + pda support

This commit is contained in:
Tastyfish
2012-01-24 15:45:51 -05:00
parent d6de48663e
commit a591aef35c
29 changed files with 4210 additions and 8 deletions
@@ -0,0 +1,147 @@
obj/machinery/water/binary
dir = SOUTH
initialize_directions = SOUTH|NORTH
var/datum/reagents/r1
var/datum/reagents/r2
var/obj/machinery/water/node1
var/obj/machinery/water/node2
var/datum/water/pipe_network/network1
var/datum/water/pipe_network/network2
var/max_volume = 400
var/max_pressure = 3 * ONE_ATMOSPHERE
New()
..()
switch(dir)
if(NORTH)
initialize_directions = NORTH|SOUTH
if(SOUTH)
initialize_directions = NORTH|SOUTH
if(EAST)
initialize_directions = EAST|WEST
if(WEST)
initialize_directions = EAST|WEST
r1 = new(max_volume)
r1.my_atom = src
r2 = new(max_volume)
r2.my_atom = src
// Housekeeping and pipe network stuff below
network_expand(datum/water/pipe_network/new_network, obj/machinery/water/pipe/reference)
if(reference == node1)
network1 = new_network
else if(reference == node2)
network2 = 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)
node1 = null
node2 = null
..()
initialize()
if(node1 && node2) return
var/node2_connect = dir
var/node1_connect = turn(dir, 180)
for(var/obj/machinery/water/target in get_step(src,node1_connect))
if(target.initialize_directions & get_dir(target,src))
node1 = target
break
for(var/obj/machinery/water/target in get_step(src,node2_connect))
if(target.initialize_directions & get_dir(target,src))
node2 = target
break
update_icon()
build_network()
if(!network1 && node1)
network1 = new /datum/water/pipe_network()
network1.normal_members += src
network1.build_network(node1, src)
if(!network2 && node2)
network2 = new /datum/water/pipe_network()
network2.normal_members += src
network2.build_network(node2, src)
return_network(obj/machinery/water/reference)
build_network()
if(reference==node1)
return network1
if(reference==node2)
return network2
return null
reassign_network(datum/water/pipe_network/old_network, datum/water/pipe_network/new_network)
if(network1 == old_network)
network1 = new_network
if(network2 == old_network)
network2 = new_network
return 1
return_network_reagents(datum/water/pipe_network/reference)
var/list/results = list()
if(network1 == reference)
results += r1
if(network2 == reference)
results += r2
return results
disconnect(obj/machinery/water/reference)
if(reference==node1)
del(network1)
node1 = null
else if(reference==node2)
del(network2)
node2 = null
return null
proc/return_pressure1()
return r1.total_volume / r1.maximum_volume * max_pressure
proc/return_pressure2()
return r2.total_volume / r2.maximum_volume * max_pressure
proc/mingle_dc1_with_turf()
mingle_outflow_with_turf(get_turf(src), r1.total_volume,
turn(dir, 180),
reagents = r1, pressure = return_pressure1())
proc/mingle_dc2_with_turf()
mingle_outflow_with_turf(get_turf(src), r2.total_volume,
dir,
reagents = r2, pressure = return_pressure2())
@@ -0,0 +1,77 @@
/obj/machinery/water/binary/fixture
name = "water fixture connection"
icon = 'water_fixtures.dmi'
icon_state = "fixture"
level = 1
layer = 2.9
var/obj/parent
hide(var/i)
if(level == 1 && istype(loc, /turf/simulated))
invisibility = i ? 101 : 0
update_icon()
initialize()
..()
var/turf/T = src.loc // hide if turf is not intact
hide(T.intact)
update_icon()
process()
..()
// handle leaks
if(!network1 && r1.total_volume > 0)
mingle_dc1_with_turf()
if(!network2 && r2.total_volume > 0)
mingle_dc2_with_turf()
proc/fill(amount)
if(!parent || !parent.reagents || amount <= 0) return
amount = min(amount, parent.reagents.maximum_volume-parent.reagents.total_volume)
var/parent_pressure = parent.reagents.total_volume / parent.reagents.maximum_volume
if(return_pressure1() > parent_pressure)
r1.trans_to(parent, amount)
if(network1)
network1.update = 1
return amount
else
return 0
proc/drain(amount)
if(!parent || !parent.reagents || amount <= 0) return
amount = min(amount, r2.maximum_volume-r2.total_volume)
var/parent_pressure = parent.reagents.total_volume / parent.reagents.maximum_volume
if(return_pressure2() < parent_pressure)
parent.reagents.trans_to(r2, amount)
if(network2)
network2.update = 1
return amount
else
return 0
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/env_air = loc.return_air()
if ((return_pressure1()-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/water_pipe(loc, make_from=src)
del(src)
@@ -0,0 +1,198 @@
/*
Every cycle, the pump uses the reagents in reagents_in to try and make reagents_out the perfect pressure.
node1, r1, network1 correspond to input
node2, r2, network2 correspond to output
Thus, the two variables affect pump operation are set in New():
r1.total_volume
This is the volume of gas available to the pump that may be transfered to the output
r2.total_volume
Higher quantities of this cause more air to be perfected later
but overall network volume is also increased as this increases...
*/
obj/machinery/water/binary/pump
icon = 'pump.dmi'
icon_state = "intact_off"
name = "Water pump"
desc = "A pump"
var/on = 0
var/target_pressure = ONE_ATMOSPHERE
var/frequency = 0
var/id = null
var/datum/radio_frequency/radio_connection
/*
attack_hand(mob/user)
on = !on
update_icon()
*/
update_icon()
if(node1&&node2)
icon_state = "intact_[on?("on"):("off")]"
else
if(node1)
icon_state = "exposed_1_off"
else if(node2)
icon_state = "exposed_2_off"
else
icon_state = "exposed_3_off"
return
process()
// ..()
if(stat & (NOPOWER|BROKEN))
return
if(!on)
return 0
var/output_starting_pressure = return_pressure2()
if( (target_pressure - output_starting_pressure) < 0.01)
//No need to pump liquid if target is already reached!
return 1
//Calculate necessary moles to transfer using PV=nRT
if(r1.total_volume > 0)
var/pressure_delta = target_pressure - output_starting_pressure
var/transfer_vol = pressure_delta * r2.maximum_volume / max_pressure
//Actually transfer the reagents
r1.trans_to(r2, transfer_vol)
if(network1)
network1.update = 1
if(network2)
network2.update = 1
else if(r2.total_volume > 0) // leak out 1->2
mingle_dc2_with_turf()
return 1
//Radio remote control
proc
set_frequency(new_frequency)
radio_controller.remove_object(src, frequency)
frequency = new_frequency
if(frequency)
radio_connection = radio_controller.add_object(src, frequency, filter = RADIO_ATMOSIA)
broadcast_status()
if(!radio_connection)
return 0
var/datum/signal/signal = new
signal.transmission_method = 1 //radio signal
signal.source = src
signal.data = list(
"tag" = id,
"device" = "AGP",
"power" = on,
"target_output" = target_pressure,
"sigtype" = "status"
)
radio_connection.post_signal(src, signal, filter = RADIO_ATMOSIA)
return 1
interact(mob/user as mob)
var/dat = {"<b>Power: </b><a href='?src=\ref[src];power=1'>[on?"On":"Off"]</a><br>
<b>Desirable output pressure: </b>
[round(target_pressure,0.1)]kPa | <a href='?src=\ref[src];set_press=1'>Change</a>
"}
user << browse("<HEAD><TITLE>[src.name] control</TITLE></HEAD><TT>[dat]</TT>", "window=atmo_pump")
onclose(user, "atmo_pump")
initialize()
..()
if(frequency)
set_frequency(frequency)
receive_signal(datum/signal/signal)
if(!signal.data["tag"] || (signal.data["tag"] != id) || (signal.data["sigtype"]!="command"))
return 0
if("power" in signal.data)
on = text2num(signal.data["power"])
if("power_toggle" in signal.data)
on = !on
if("set_output_pressure" in signal.data)
target_pressure = between(
0,
text2num(signal.data["set_output_pressure"]),
ONE_ATMOSPHERE*50
)
if("status" in signal.data)
spawn(2)
broadcast_status()
return //do not update_icon
spawn(2)
broadcast_status()
update_icon()
return
attack_hand(user as mob)
if(..())
return
src.add_fingerprint(usr)
if(!src.allowed(user))
user << "\red Access denied."
return
usr.machine = src
interact(user)
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))
usr.machine = src
src.update_icon()
src.updateUsrDialog()
return
power_change()
..()
update_icon()
attackby(var/obj/item/weapon/W as obj, var/mob/user as mob)
if (!istype(W, /obj/item/weapon/wrench))
return ..()
if (!(stat & NOPOWER) && on)
user << "\red You cannot unwrench this [src], turn it off first."
return 1
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/env_air = loc.return_air()
if ((return_pressure1()-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/water_pipe(loc, make_from=src)
del(src)