mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-11 18:53:06 +00:00
- Unified pipe *unwrenching* by creating a standard proc along with the `construction_type` var.
- Eliminated the pipe fitting name & icon_state lookup tables by adding `pipe_state` var on atmos machinery and referencing that.
- Each pipe which can be made from a fitting object should override `pipe_state` with the icon state to be used on the pipe fitting object.
- Eliminated the giant switch statement of doom in pipe construction by delegating that work to `on_construction` proc.
- To make this work, every pipe must implement `get_neighbor_nodes_for_init` which returns a list of nodes which should be re-initialized on that pipe's construction.
- Combined the SCRUBBERS, SUPPLY and REGULAR pipe fitting classes together by storing the `piping_layer` variable and using the `setPipingLayer` procs
- Standardized the code for searching for node neighbors into the `can_be_node` proc.
- This proc is also improved in that is a mutual check, `check_connectable` is called on BOTH objects, so they have to mutually agree to connect as nodes. Eliminates lots of special edge case logic.
- Updated all the `amos_init` procs to use `can_be_node`. In the most common cases, even that boilerplate code is consolidated into the `STANDARD_ATMOS_CHOOSE_NODE` macro.
- Implemented `pipe_flags` which lets pipes declare (or override) certain requirements.
- Adds a "pipe_recipe" datum to help out things that construct pipes. By taking it out of the dispenser, we open the road for multiple dispenser types. No, no RPD yet. Soon.
- Enhances the pipe dispenser to operate on pipe recipe datums instead of hard coded lists of pipes it can construct. These datums are also (partially) initialized from the pipe machine types themselves, reducing having to define stuff in multiple places.
- Switched pipe dispenser UI to use browse(). Not a NanoUI, but makes it a bit prettier with low effort.
- Changed pipe dispenser to use a button selector to switch between Regular/Scrubbers/Supply instead of having separate list items.
- Added icon states to HE pipes to support the "connected on neither side" state.
290 lines
6.8 KiB
Plaintext
290 lines
6.8 KiB
Plaintext
#define ADIABATIC_EXPONENT 0.667 //Actually adiabatic exponent - 1.
|
|
|
|
/obj/machinery/atmospherics/pipeturbine
|
|
name = "turbine"
|
|
desc = "A gas turbine. Converting pressure into energy since 1884."
|
|
icon = 'icons/obj/pipeturbine.dmi'
|
|
icon_state = "turbine"
|
|
anchored = 0
|
|
density = 1
|
|
|
|
var/efficiency = 0.4
|
|
var/kin_energy = 0
|
|
var/datum/gas_mixture/air_in = new
|
|
var/datum/gas_mixture/air_out = new
|
|
var/volume_ratio = 0.2
|
|
var/kin_loss = 0.001
|
|
|
|
var/dP = 0
|
|
|
|
var/datum/pipe_network/network1
|
|
var/datum/pipe_network/network2
|
|
|
|
New()
|
|
..()
|
|
air_in.volume = 200
|
|
air_out.volume = 800
|
|
volume_ratio = air_in.volume / (air_in.volume + air_out.volume)
|
|
switch(dir)
|
|
if(NORTH)
|
|
initialize_directions = EAST|WEST
|
|
if(SOUTH)
|
|
initialize_directions = EAST|WEST
|
|
if(EAST)
|
|
initialize_directions = NORTH|SOUTH
|
|
if(WEST)
|
|
initialize_directions = NORTH|SOUTH
|
|
|
|
Destroy()
|
|
. = ..()
|
|
|
|
if(node1)
|
|
node1.disconnect(src)
|
|
qdel(network1)
|
|
if(node2)
|
|
node2.disconnect(src)
|
|
qdel(network2)
|
|
|
|
node1 = null
|
|
node2 = null
|
|
|
|
process()
|
|
..()
|
|
if(anchored && !(stat&BROKEN))
|
|
kin_energy *= 1 - kin_loss
|
|
dP = max(air_in.return_pressure() - air_out.return_pressure(), 0)
|
|
if(dP > 10)
|
|
kin_energy += 1/ADIABATIC_EXPONENT * dP * air_in.volume * (1 - volume_ratio**ADIABATIC_EXPONENT) * efficiency
|
|
air_in.temperature *= volume_ratio**ADIABATIC_EXPONENT
|
|
|
|
var/datum/gas_mixture/air_all = new
|
|
air_all.volume = air_in.volume + air_out.volume
|
|
air_all.merge(air_in.remove_ratio(1))
|
|
air_all.merge(air_out.remove_ratio(1))
|
|
|
|
air_in.merge(air_all.remove(volume_ratio))
|
|
air_out.merge(air_all)
|
|
|
|
update_icon()
|
|
|
|
if (network1)
|
|
network1.update = 1
|
|
if (network2)
|
|
network2.update = 1
|
|
|
|
update_icon()
|
|
overlays.Cut()
|
|
if (dP > 10)
|
|
overlays += image('icons/obj/pipeturbine.dmi', "moto-turb")
|
|
if (kin_energy > 100000)
|
|
overlays += image('icons/obj/pipeturbine.dmi', "low-turb")
|
|
if (kin_energy > 500000)
|
|
overlays += image('icons/obj/pipeturbine.dmi', "med-turb")
|
|
if (kin_energy > 1000000)
|
|
overlays += image('icons/obj/pipeturbine.dmi', "hi-turb")
|
|
|
|
attackby(obj/item/weapon/W as obj, mob/user as mob)
|
|
if(istype(W, /obj/item/weapon/wrench))
|
|
anchored = !anchored
|
|
playsound(src, W.usesound, 50, 1)
|
|
to_chat(user, "<span class='notice'>You [anchored ? "secure" : "unsecure"] the bolts holding \the [src] to the floor.</span>")
|
|
|
|
if(anchored)
|
|
if(dir & (NORTH|SOUTH))
|
|
initialize_directions = EAST|WEST
|
|
else if(dir & (EAST|WEST))
|
|
initialize_directions = NORTH|SOUTH
|
|
|
|
atmos_init()
|
|
build_network()
|
|
if (node1)
|
|
node1.atmos_init()
|
|
node1.build_network()
|
|
if (node2)
|
|
node2.atmos_init()
|
|
node2.build_network()
|
|
else
|
|
if(node1)
|
|
node1.disconnect(src)
|
|
qdel(network1)
|
|
if(node2)
|
|
node2.disconnect(src)
|
|
qdel(network2)
|
|
|
|
node1 = null
|
|
node2 = null
|
|
|
|
else
|
|
..()
|
|
|
|
verb/rotate_clockwise()
|
|
set category = "Object"
|
|
set name = "Rotate Circulator (Clockwise)"
|
|
set src in view(1)
|
|
|
|
if (usr.stat || usr.restrained() || anchored)
|
|
return
|
|
|
|
src.set_dir(turn(src.dir, -90))
|
|
|
|
|
|
verb/rotate_anticlockwise()
|
|
set category = "Object"
|
|
set name = "Rotate Circulator (Counterclockwise)"
|
|
set src in view(1)
|
|
|
|
if (usr.stat || usr.restrained() || anchored)
|
|
return
|
|
|
|
src.set_dir(turn(src.dir, 90))
|
|
|
|
//Goddamn copypaste from binary base class because atmospherics machinery API is not damn flexible
|
|
get_neighbor_nodes_for_init()
|
|
return list(node1, node2)
|
|
|
|
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
|
|
|
|
if(new_network.normal_members.Find(src))
|
|
return 0
|
|
|
|
new_network.normal_members += src
|
|
|
|
return null
|
|
|
|
atmos_init()
|
|
if(node1 && node2) return
|
|
|
|
var/node2_connect = turn(dir, -90)
|
|
var/node1_connect = turn(dir, 90)
|
|
|
|
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
|
|
|
|
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)
|
|
|
|
|
|
return_network(obj/machinery/atmospherics/reference)
|
|
build_network()
|
|
|
|
if(reference==node1)
|
|
return network1
|
|
|
|
if(reference==node2)
|
|
return network2
|
|
|
|
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
|
|
|
|
return 1
|
|
|
|
return_network_air(datum/pipe_network/reference)
|
|
var/list/results = list()
|
|
|
|
if(network1 == reference)
|
|
results += air_in
|
|
if(network2 == reference)
|
|
results += air_out
|
|
|
|
return results
|
|
|
|
disconnect(obj/machinery/atmospherics/reference)
|
|
if(reference==node1)
|
|
qdel(network1)
|
|
node1 = null
|
|
|
|
else if(reference==node2)
|
|
qdel(network2)
|
|
node2 = null
|
|
|
|
return null
|
|
|
|
|
|
/obj/machinery/power/turbinemotor
|
|
name = "motor"
|
|
desc = "Electrogenerator. Converts rotation into power."
|
|
icon = 'icons/obj/pipeturbine.dmi'
|
|
icon_state = "motor"
|
|
anchored = 0
|
|
density = 1
|
|
|
|
var/kin_to_el_ratio = 0.1 //How much kinetic energy will be taken from turbine and converted into electricity
|
|
var/obj/machinery/atmospherics/pipeturbine/turbine
|
|
|
|
New()
|
|
..()
|
|
spawn(1)
|
|
updateConnection()
|
|
|
|
proc/updateConnection()
|
|
turbine = null
|
|
if(src.loc && anchored)
|
|
turbine = locate(/obj/machinery/atmospherics/pipeturbine) in get_step(src,dir)
|
|
if (turbine.stat & (BROKEN) || !turbine.anchored || turn(turbine.dir,180) != dir)
|
|
turbine = null
|
|
|
|
process()
|
|
updateConnection()
|
|
if(!turbine || !anchored || stat & (BROKEN))
|
|
return
|
|
|
|
var/power_generated = kin_to_el_ratio * turbine.kin_energy
|
|
turbine.kin_energy -= power_generated
|
|
add_avail(power_generated)
|
|
|
|
|
|
attackby(obj/item/weapon/W as obj, mob/user as mob)
|
|
if(istype(W, /obj/item/weapon/wrench))
|
|
anchored = !anchored
|
|
playsound(src, W.usesound, 50, 1)
|
|
turbine = null
|
|
to_chat(user, "<span class='notice'>You [anchored ? "secure" : "unsecure"] the bolts holding \the [src] to the floor.</span>")
|
|
updateConnection()
|
|
else
|
|
..()
|
|
|
|
verb/rotate_clock()
|
|
set category = "Object"
|
|
set name = "Rotate Motor Clockwise"
|
|
set src in view(1)
|
|
|
|
if (usr.stat || usr.restrained() || anchored)
|
|
return
|
|
|
|
src.set_dir(turn(src.dir, -90))
|
|
|
|
verb/rotate_anticlock()
|
|
set category = "Object"
|
|
set name = "Rotate Motor Counterclockwise"
|
|
set src in view(1)
|
|
|
|
if (usr.stat || usr.restrained() || anchored)
|
|
return
|
|
|
|
src.set_dir(turn(src.dir, 90))
|