Files
SyncIt21 3c5749f862 General maintenance for plumbing (#94427)
## About The Pull Request
The overall behaviour of everything should stay the same but the memory
& speed of these components has been slightly improved and when you
scale that across large plumbing factories you get a substantial
improvement. Here's a list of the most noticeable changes along with
many others that aren't worth mentioning

- Removed vars `use_overlays`, `turn_connects`,
`recipient_reagents_holder`
- `active` var is now replaced with a proc which simply returns is the
machine wrenched or not
- `turn_connects` has been removed because all machines have their pipes
rotate when the machine is rotated. This also removed all the static
icon states ending with `-s` from the `dmi` file thus reducing that file
size as well
- `extend_pipe_to_edge` var is directly integrated into `cut_overlays()`
because it's use cases were limited such for showers & sinks
- Simplified `Initialize()` a lot. Removed params `start`,
`turn_connects`, `custom_receiver`, `extend_pipe_to_edge`. We now only
pass `bolt_layer` making that proc faster & less convoluted
- Replaced `set_recipient_reagents_holder()` proc with
`recipient_reagents_holder()` which returns the reagent holder for
holding reagents instead of storing it in the component. This removes
the need to hook a qdel signal on the holder & we don't need to keep
track of it
- Merged a ton of procs to reduce overhead & reduce file size
- Plumbing ducts creating the network at mapload is faster without using
recursion and the timer subsystem
- Deconstructing plumbing ducts is faster in reconstructing the network
without using recursion and the timer subsystem

This makes managing plumbing code less convoluted & overall better for
the foreseeable future. See the lines of code removed vs added and still
preserves behaviour

## Changelog
🆑
qol: added examines & screentips for ducts & stack of ducts
qol: you can wrench a stack of ducts on the ground to create a pipe
refactor: plumbing code has been improved overall. Report bugs on github
sprite: removed unused static(does not rotate with machine) icon states
for plumbing connections
/🆑

---------

Co-authored-by: Time-Green <7501474+Time-Green@users.noreply.github.com>
2025-12-31 13:03:42 +01:00

61 lines
2.5 KiB
Plaintext

/// Special demand connector that consumes as normal, but redirects water into the magical water space.
/datum/component/plumbing/hydroponics
demand_connects = SOUTH
/// Alternate reagents container to buffer incoming water
var/datum/reagents/water_reagents
/// Decides if we receive either water or regular reagents
var/receive_water = FALSE
/datum/component/plumbing/hydroponics/Initialize(ducting_layer)
. = ..()
if(!istype(parent, /obj/machinery/hydroponics/constructable))
return COMPONENT_INCOMPATIBLE
var/obj/machinery/hydroponics/constructable/hydro_parent = parent
water_reagents = new(hydro_parent.maxwater)
water_reagents.my_atom = hydro_parent
/datum/component/plumbing/hydroponics/Destroy()
QDEL_NULL(water_reagents)
return ..()
/datum/component/plumbing/hydroponics/recipient_reagents_holder()
return receive_water ? water_reagents : reagents
/datum/component/plumbing/hydroponics/send_request(dir)
var/obj/machinery/hydroponics/constructable/hydro_parent = parent
var/initial_nutri_amount = reagents.total_volume
if(initial_nutri_amount < reagents.maximum_volume)
// Well boy howdy, we have no way to tell a supply to not mix the water with everything else,
// So we'll let it leak in, and move the water over.
receive_water = FALSE
process_request(dir = dir, round_robin = FALSE)
// Move the leaked water from nutrients to... water
var/leaking_water_amount = reagents.get_reagent_amount(/datum/reagent/water)
if(leaking_water_amount)
reagents.trans_to(water_reagents, leaking_water_amount, target_id = /datum/reagent/water)
// We should only take MACHINE_REAGENT_TRANSFER every tick; this is the remaining amount we can take
var/remaining_transfer_amount = max(MACHINE_REAGENT_TRANSFER - (reagents.total_volume - initial_nutri_amount), 0)
// How much extra water we should gather this tick to try to fill the water tray.
var/extra_water_to_gather = clamp(hydro_parent.maxwater - hydro_parent.waterlevel - water_reagents.total_volume, 0, remaining_transfer_amount)
if(extra_water_to_gather > 0)
receive_water = TRUE
process_request(
amount = extra_water_to_gather,
reagent = /datum/reagent/water,
dir = dir
)
// Now transfer all remaining water in that buffer and clear it out.
var/final_water_amount = water_reagents.total_volume
if(final_water_amount)
hydro_parent.adjust_waterlevel(round(final_water_amount))
// Using a pipe doesn't afford you extra water storage and the baseline behavior for trays is that excess water goes into the shadow realm.
water_reagents.clear_reagents()