Files
Bubberstation/code/game/objects/structures/shower.dm
LemonInTheDark 23bfdec8f4 Multiz Rework: Human Suffering Edition (Contains PLANE CUBE) (#69115)
About The Pull Request

I've reworked multiz. This was done because our current implementation of multiz flattens planes down into just the openspace plane. This breaks any effects we attach to plane masters (including lighting), but it also totally kills the SIDE_MAP map format, which we NEED for wallening (A major 3/4ths resprite of all wall and wall adjacent things, making them more then one tile high. Without sidemap we would be unable to display things both in from of and behind objects on map. Stupid.)

This required MASSIVE changes. Both to all uses of the plane var for reasons I'll discuss later, and to a ton of different systems that interact with rendering.

I'll do my best to keep this compact, but there's only so much I can do. Sorry brother.
Core idea

OK: first thing.
vis_contents as it works now squishes the planes of everything inside it down into the plane of the vis_loc.
This is bad. But how to do better?

It's trivially easy to make copies of our existing plane masters but offset, and relay them to the bottom of the plane above. Not a problem. The issue is how to get the actual atoms on the map to "land" on them properly.

We could use FLOAT_PLANE to offset planes based off how they're being seen, in theory this would allow us to create lens for how objects are viewed.
But that's not a stable thing to do, because properly "landing" a plane on a desired plane master would require taking into account every bit of how it's being seen, would inherently break this effect.

Ok so we need to manually edit planes based off "z layer" (IE: what layer of a z stack are you on).

That's the key conceit of this pr. Implementing the plane cube, and ensuring planes are always offset properly.
Everything else is just gravy.
About the Plane Cube

Each plane master (except ones that opt out) is copied down by some constant value equal to the max absolute change between the first and the last plane.
We do this based off the max z stack size detected by SSmapping. This is also where updates come from, and where all our updating logic will live.

As mentioned, plane masters can choose to opt out of being mirrored down. In this case, anything that interacts with them assuming that they'll be offset will instead just get back the valid plane value. This works for render targets too, since I had to work them into the system as well.

Plane masters can also be temporarily hidden from the client's screen. This is done as an attempt at optimization, and applies to anything used in niche cases, or planes only used if there's a z layer below you.
About Plane Master Groups

BYOND supports having different "maps" on screen at once (IE: groups of items/turfs/etc)
Plane masters cannot cover 2 maps at once, since their location is determined by their screen_loc.
So we need to maintain a mirror of each plane for every map we have open.

This was quite messy, so I've refactored it (and maps too) to be a bit more modular.

Rather then storing a list of plane masters, we store a list of plane master group datums.
Each datum is in charge of the plane masters for its particular map, both creating them, and managing them.

Like I mentioned, I also refactored map views. Adding a new mapview is now as simple as newing a /atom/movable/screen/map_view, calling generate_view with the appropriate map id, setting things you want to display in its vis_contents, and then calling display_to on it, passing in the mob to show ourselves to.

Much better then the hardcoded pattern we used to use. So much duplicated code man.

Oh and plane master controllers, that system we have that allows for applying filters to sets of plane masters? I've made it use lookups on plane master groups now, rather then hanging references to all impacted planes. This makes logic easier, and prevents the need to manage references and update the controllers.

image

In addition, I've added a debug ui for plane masters.
It allows you to view all of your own plane masters and short descriptions of what they do, alongside tools for editing them and their relays.

It ALSO supports editing someone elses plane masters, AND it supports (in a very fragile and incomplete manner) viewing literally through someone else's eyes, including their plane masters. This is very useful, because it means you can debug "hey my X is yorked" issues yourself, on live.

In order to accomplish this I have needed to add setters for an ungodly amount of visual impacting vars. Sight flags, eye, see_invis, see_in_dark, etc.

It also comes with an info dump about the ui, and plane masters/relays in general.

Sort of on that note. I've documented everything I know that's niche/useful about our visual effects and rendering system. My hope is this will serve to bring people up to speed on what can be done more quickly, alongside making my sin here less horrible.
See https://github.com/LemonInTheDark/tgstation/blob/multiz-hell/.github/guides/VISUALS.md.
"Landing" planes

Ok so I've explained the backend, but how do we actually land planes properly?
Most of the time this is really simple. When a plane var is set, we need to provide some spokesperson for the appearance's z level. We can use this to derive their z layer, and thus what offset to use.

This is just a lot of gruntwork, but it's occasionally more complex.
Sometimes we need to cache a list of z layer -> effect, and then use that.
Also a LOT of updating on z move. So much z move shit.

Oh. and in order to make byond darkness work properly, I needed to add SEE_BLACKNESS to all sight flags.
This draws darkness to plane 0, which means I'm able to relay it around and draw it on different z layers as is possible. fun darkness ripple effects incoming someday

I also need to update mob overlays on move.
I do this by realiizing their appearances, mutating their plane, and then readding the overlay in the correct order.

The cost of this is currently 3N. I'm convinced this could be improved, but I've not got to it yet.
It can also occasionally cause overlays to corrupt. This is fixed by laying a protective ward of overlays.Copy in the sand, but that spell makes the compiler confused, so I'll have to bully lummy about fixing it at some point.
Behavior changes

We've had to give up on the already broken gateway "see through" effect. Won't work without managing gateway plane masters or something stupid. Not worth it.
So instead we display the other side as a ui element. It's worse, but not that bad.

Because vis_contents no longer flattens planes (most of the time), some uses of it now have interesting behavior.
The main thing that comes to mind is alert popups that display mobs. They can impact the lighting plane.
I don't really care, but it should be fixable, I think, given elbow grease.

Ah and I've cleaned up layers and plane defines to make them a bit easier to read/reason about, at least I think.
Why It's Good For The Game
<visual candy>

Fixes #65800
Fixes #68461
Changelog

cl
refactor: Refactored... well a lot really. Map views, anything to do with planes, multiz, a shit ton of rendering stuff. Basically if you see anything off visually report it
admin: VV a mob, and hit View/Edit Planes in the dropdown to steal their view, and modify it as you like. You can do the same to yourself using the Edit/Debug Planes verb
/cl
2022-09-27 20:11:04 +13:00

399 lines
13 KiB
Plaintext

#define SHOWER_FREEZING "freezing"
#define SHOWER_FREEZING_TEMP 100
#define SHOWER_NORMAL "normal"
#define SHOWER_NORMAL_TEMP 300
#define SHOWER_BOILING "boiling"
#define SHOWER_BOILING_TEMP 400
/// The volume of it's internal reagents the shower applies to everything it sprays.
#define SHOWER_SPRAY_VOLUME 5
/// How much the volume of the shower's spay reagents are amplified by when it sprays something.
#define SHOWER_EXPOSURE_MULTIPLIER 2 // Showers effectively double exposed reagents
/// How long we run in TIMED mode
#define SHOWER_TIMED_LENGTH (15 SECONDS)
/// Run the shower until we run out of reagents.
#define SHOWER_MODE_UNTIL_EMPTY 0
/// Run the shower for SHOWER_TIMED_LENGTH time, or until we run out of reagents.
#define SHOWER_MODE_TIMED 1
/// Run the shower forever, pausing when we run out of liquid, and then resuming later.
#define SHOWER_MODE_FOREVER 2
/// Number of modes to cycle through
#define SHOWER_MODE_COUNT 3
GLOBAL_LIST_INIT(shower_mode_descriptions, list(
"[SHOWER_MODE_UNTIL_EMPTY]" = "run until empty",
"[SHOWER_MODE_TIMED]" = "run for 15 seconds or until empty",
"[SHOWER_MODE_FOREVER]" = "keep running forever and auto turn back on",
))
/obj/machinery/shower
name = "shower"
desc = "The HS-452. Installed in the 2550s by the Nanotrasen Hygiene Division, now with 2560 lead compliance! Passively replenishes itself with water when not in use."
icon = 'icons/obj/watercloset.dmi'
icon_state = "shower"
density = FALSE
layer = ABOVE_WINDOW_LAYER
use_power = NO_POWER_USE
subsystem_type = /datum/controller/subsystem/processing/plumbing
///Does the user want the shower on or off?
var/intended_on = FALSE
///Is the shower actually spitting out water currently
var/actually_on = FALSE
///What temperature the shower reagents are set to.
var/current_temperature = SHOWER_NORMAL
///What sound will be played on loop when the shower is on and pouring water.
var/datum/looping_sound/showering/soundloop
///What reagent should the shower be filled with when initially built.
var/reagent_id = /datum/reagent/water
///How much reagent capacity should the shower begin with when built.
var/reagent_capacity = 200
///How many units the shower refills every second.
var/refill_rate = 0.5
///Does the shower have a water recycler to recollect it's water supply?
var/has_water_reclaimer = TRUE
///Which mode the shower is operating in.
var/mode = SHOWER_MODE_UNTIL_EMPTY
///The cooldown for SHOWER_MODE_TIMED mode.
COOLDOWN_DECLARE(timed_cooldown)
///How far to shift the sprite when placing.
var/pixel_shift = 16
MAPPING_DIRECTIONAL_HELPERS(/obj/machinery/shower, (-16))
/obj/machinery/shower/Initialize(mapload, ndir = 0, has_water_reclaimer = null)
. = ..()
if(ndir)
dir = ndir
if(has_water_reclaimer != null)
src.has_water_reclaimer = has_water_reclaimer
switch(dir)
if(NORTH)
pixel_x = 0
pixel_y = -pixel_shift
if(SOUTH)
pixel_x = 0
pixel_y = pixel_shift
if(EAST)
pixel_x = -pixel_shift
pixel_y = 0
if(WEST)
pixel_x = pixel_shift
pixel_y = 0
create_reagents(reagent_capacity)
if(src.has_water_reclaimer)
reagents.add_reagent(reagent_id, reagent_capacity)
soundloop = new(src, FALSE)
AddComponent(/datum/component/plumbing/simple_demand, extend_pipe_to_edge = TRUE)
var/static/list/loc_connections = list(
COMSIG_ATOM_ENTERED = .proc/on_entered,
)
AddElement(/datum/element/connect_loc, loc_connections)
/obj/machinery/shower/examine(mob/user)
. = ..()
. += span_notice("It looks like the thermostat has an adjustment screw.")
if(has_water_reclaimer)
. += span_notice("A water recycler is installed. It looks like you could pry it out.")
. += span_notice("The auto shut-off is programmed to [GLOB.shower_mode_descriptions["[mode]"]].")
. += span_notice("[reagents.total_volume]/[reagents.maximum_volume] liquids remaining.")
/obj/machinery/shower/Destroy()
QDEL_NULL(soundloop)
QDEL_NULL(reagents)
return ..()
/obj/machinery/shower/interact(mob/user)
. = ..()
if(.)
return
intended_on = !intended_on
if(!update_actually_on(intended_on))
balloon_alert(user, "[src] is dry!")
return FALSE
balloon_alert(user, "turned [intended_on ? "on" : "off"]")
return TRUE
/obj/machinery/shower/analyzer_act(mob/living/user, obj/item/tool)
. = ..()
tool.play_tool_sound(src)
to_chat(user, span_notice("The water temperature seems to be [current_temperature]."))
return TRUE
/obj/machinery/shower/attackby(obj/item/tool, mob/user, params)
if(istype(tool, /obj/item/stock_parts/water_recycler))
if(has_water_reclaimer)
to_chat(user, span_warning("There is already has a water recycler installed."))
return
playsound(src, 'sound/machines/click.ogg', 20, TRUE)
qdel(tool)
has_water_reclaimer = TRUE
begin_processing()
return ..()
/obj/machinery/shower/multitool_act(mob/living/user, obj/item/tool)
. = ..()
if(.)
return
tool.play_tool_sound(src)
mode = (mode + 1) % SHOWER_MODE_COUNT
begin_processing()
to_chat(user, span_notice("You change the shower's auto shut-off mode to [GLOB.shower_mode_descriptions["[mode]"]]."))
return TRUE
/obj/machinery/shower/crowbar_act(mob/living/user, obj/item/tool)
. = ..()
if(.)
return
if(!has_water_reclaimer)
to_chat(user, span_warning("There isn't a water recycler to remove."))
return
tool.play_tool_sound(src)
has_water_reclaimer = FALSE
new/obj/item/stock_parts/water_recycler(get_turf(loc))
to_chat(user, span_notice("You remove the water reclaimer from [src]"))
return TRUE
/obj/machinery/shower/screwdriver_act(mob/living/user, obj/item/I)
..()
to_chat(user, span_notice("You begin to adjust the temperature valve with \the [I]..."))
if(I.use_tool(src, user, 50))
switch(current_temperature)
if(SHOWER_NORMAL)
current_temperature = SHOWER_FREEZING
if(SHOWER_FREEZING)
current_temperature = SHOWER_BOILING
if(SHOWER_BOILING)
current_temperature = SHOWER_NORMAL
user.visible_message(span_notice("[user] adjusts the shower with \the [I]."), span_notice("You adjust the shower with \the [I] to [current_temperature] temperature."))
user.log_message("has wrenched a shower to [current_temperature].", LOG_ATTACK)
add_hiddenprint(user)
handle_mist()
return TRUE
/obj/machinery/shower/wrench_act(mob/living/user, obj/item/I)
. = ..()
if(flags_1 & NODECONSTRUCT_1)
return
I.play_tool_sound(src)
deconstruct()
return TRUE
/obj/machinery/shower/update_overlays()
. = ..()
if(!actually_on)
return
var/mutable_appearance/water_falling = mutable_appearance('icons/obj/watercloset.dmi', "water", ABOVE_MOB_LAYER)
water_falling.color = mix_color_from_reagents(reagents.reagent_list)
SET_PLANE_EXPLICIT(water_falling, GAME_PLANE_UPPER, src)
switch(dir)
if(NORTH)
water_falling.pixel_y += pixel_shift
if(SOUTH)
water_falling.pixel_y -= pixel_shift
if(EAST)
water_falling.pixel_x += pixel_shift
if(WEST)
water_falling.pixel_x -= pixel_shift
. += water_falling
/obj/machinery/shower/on_changed_z_level(turf/old_turf, turf/new_turf, same_z_layer, notify_contents)
if(same_z_layer)
return ..()
update_appearance()
return ..()
/obj/machinery/shower/proc/handle_mist()
// If there is no mist, and the shower was turned on (on a non-freezing temp): make mist in 5 seconds
// If there was already mist, and the shower was turned off (or made cold): remove the existing mist in 25 sec
var/obj/effect/mist/mist = locate() in loc
if(!mist && actually_on && current_temperature != SHOWER_FREEZING)
addtimer(CALLBACK(src, .proc/make_mist), 5 SECONDS)
if(mist && !(actually_on && current_temperature != SHOWER_FREEZING))
addtimer(CALLBACK(src, .proc/clear_mist), 25 SECONDS)
/obj/machinery/shower/proc/make_mist()
var/obj/effect/mist/mist = locate() in loc
if(!mist && actually_on && current_temperature != SHOWER_FREEZING)
var/obj/effect/mist/new_mist = new /obj/effect/mist(loc)
new_mist.color = mix_color_from_reagents(reagents.reagent_list)
/obj/machinery/shower/proc/clear_mist()
var/obj/effect/mist/mist = locate() in loc
if(mist && !(actually_on && current_temperature != SHOWER_FREEZING))
qdel(mist)
/obj/machinery/shower/proc/on_entered(datum/source, atom/movable/AM)
SIGNAL_HANDLER
if(actually_on && reagents.total_volume)
wash_atom(AM)
/obj/machinery/shower/proc/wash_atom(atom/target)
target.wash(CLEAN_RAD | CLEAN_WASH)
reagents.expose(target, (TOUCH), SHOWER_EXPOSURE_MULTIPLIER * SHOWER_SPRAY_VOLUME / max(reagents.total_volume, SHOWER_SPRAY_VOLUME))
if(isliving(target))
var/mob/living/living_target = target
check_heat(living_target)
living_target.add_mood_event("shower", /datum/mood_event/nice_shower)
/**
* Toggle whether shower is actually on and outputting water.
* May not match what user asked to happen by clicking.
* Returns TRUE if the state was changed.
*
* Arguments:
* * new_on_state - new state
*/
/obj/machinery/shower/proc/update_actually_on(new_on_state)
if(new_on_state == actually_on)
return FALSE
// Check if we have enough reagents to actually turn on.
if(new_on_state && reagents.total_volume < SHOWER_SPRAY_VOLUME)
return FALSE
actually_on = new_on_state
update_appearance()
handle_mist()
if(new_on_state)
begin_processing()
soundloop.start()
COOLDOWN_START(src, timed_cooldown, SHOWER_TIMED_LENGTH)
else
soundloop.stop()
if(isopenturf(loc))
var/turf/open/tile = loc
tile.MakeSlippery(TURF_WET_WATER, min_wet_time = 5 SECONDS, wet_time_to_add = 1 SECONDS)
return TRUE
/obj/machinery/shower/process(delta_time)
// the TIMED mode cutoff feature. User has to manually reactivate.
if(intended_on && mode == SHOWER_MODE_TIMED && COOLDOWN_FINISHED(src, timed_cooldown))
// the TIMED mode cutoff feature. User has to manually reactivate.
intended_on = FALSE
// Out of water.
if(actually_on && reagents.total_volume < SHOWER_SPRAY_VOLUME)
update_actually_on(FALSE)
// Don't turn back on.
if(mode != SHOWER_MODE_FOREVER)
intended_on = FALSE
else
// Cycle: update_actually_on() will only change state if appropriate.
update_actually_on(intended_on)
// Reclaim water
if(!actually_on)
if(has_water_reclaimer && reagents.total_volume < reagents.maximum_volume)
reagents.add_reagent(reagent_id, refill_rate * delta_time)
return 0
// FOREVER mode stays processing so it can cycle back on.
return mode == SHOWER_MODE_FOREVER ? 0 : PROCESS_KILL
// Wash up.
wash_atom(loc)
for(var/atom/movable/movable_content as anything in loc)
if(!ismopable(movable_content)) // Mopables will be cleaned anyways by the turf wash above
wash_atom(movable_content) // Reagent exposure is handled in wash_atom
reagents.remove_any(SHOWER_SPRAY_VOLUME)
/obj/machinery/shower/deconstruct(disassembled = TRUE)
new /obj/item/stack/sheet/iron(drop_location(), 2)
if(has_water_reclaimer)
new /obj/item/stock_parts/water_recycler(drop_location())
qdel(src)
/obj/machinery/shower/proc/check_heat(mob/living/L)
var/mob/living/carbon/C = L
if(current_temperature == SHOWER_FREEZING)
if(iscarbon(L))
C.adjust_bodytemperature(-80, 80)
to_chat(L, span_warning("[src] is freezing!"))
else if(current_temperature == SHOWER_BOILING)
if(iscarbon(L))
C.adjust_bodytemperature(35, 0, 500)
L.adjustFireLoss(5)
to_chat(L, span_danger("[src] is searing!"))
/obj/structure/showerframe
name = "shower frame"
icon = 'icons/obj/watercloset.dmi'
icon_state = "shower_frame"
desc = "A shower frame, that needs a water recycler to finish construction."
anchored = FALSE
/obj/structure/showerframe/Initialize(mapload)
. = ..()
AddComponent(/datum/component/simple_rotation)
/obj/structure/showerframe/attackby(obj/item/tool, mob/living/user, params)
if(istype(tool, /obj/item/stock_parts/water_recycler))
qdel(tool)
var/obj/machinery/shower/shower = new(loc, REVERSE_DIR(dir), TRUE)
qdel(src)
playsound(shower, 'sound/machines/click.ogg', 20, TRUE)
return
return ..()
/obj/structure/showerframe/wrench_act(mob/living/user, obj/item/tool)
. = ..()
tool.play_tool_sound(src)
new/obj/machinery/shower(loc, REVERSE_DIR(dir), FALSE)
qdel(src)
return TRUE
/obj/structure/sinkframe/wrench_act_secondary(mob/living/user, obj/item/tool)
. = ..()
tool.play_tool_sound(src)
deconstruct()
return TRUE
/obj/structure/showerframe/AltClick(mob/user)
return ..() // This hotkey is BLACKLISTED since it's used by /datum/component/simple_rotation
/obj/effect/mist
name = "mist"
icon = 'icons/obj/watercloset.dmi'
icon_state = "mist"
layer = FLY_LAYER
plane = ABOVE_GAME_PLANE
anchored = TRUE
mouse_opacity = MOUSE_OPACITY_TRANSPARENT
#undef SHOWER_MODE_UNTIL_EMPTY
#undef SHOWER_MODE_TIMED
#undef SHOWER_MODE_FOREVER
#undef SHOWER_MODE_COUNT
#undef SHOWER_TIMED_LENGTH
#undef SHOWER_SPRAY_VOLUME
#undef SHOWER_EXPOSURE_MULTIPLIER
#undef SHOWER_BOILING_TEMP
#undef SHOWER_BOILING
#undef SHOWER_NORMAL_TEMP
#undef SHOWER_NORMAL
#undef SHOWER_FREEZING_TEMP
#undef SHOWER_FREEZING