Files
Bubberstation/code/game/objects/structures/door_assembly.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

363 lines
14 KiB
Plaintext

/obj/structure/door_assembly
name = "airlock assembly"
icon = 'icons/obj/doors/airlocks/station/public.dmi'
icon_state = "construction"
var/overlays_file = 'icons/obj/doors/airlocks/station/overlays.dmi'
anchored = FALSE
density = TRUE
max_integrity = 200
var/state = AIRLOCK_ASSEMBLY_NEEDS_WIRES
var/base_name = "Airlock"
var/mineral = null
var/obj/item/electronics/airlock/electronics = null
var/airlock_type = /obj/machinery/door/airlock //the type path of the airlock once completed
var/glass_type = /obj/machinery/door/airlock/glass
var/glass = 0 // 0 = glass can be installed. 1 = glass is already installed.
var/created_name = null
var/heat_proof_finished = 0 //whether to heat-proof the finished airlock
var/previous_assembly = /obj/structure/door_assembly
var/noglass = FALSE //airlocks with no glass version, also cannot be modified with sheets
var/nomineral = FALSE //airlock with glass version, but cannot be modified with sheets
var/material_type = /obj/item/stack/sheet/iron
var/material_amt = 4
/obj/structure/door_assembly/Initialize(mapload)
. = ..()
update_appearance()
update_name()
/obj/structure/door_assembly/examine(mob/user)
. = ..()
var/doorname = ""
if(created_name)
doorname = ", written on it is '[created_name]'"
switch(state)
if(AIRLOCK_ASSEMBLY_NEEDS_WIRES)
if(anchored)
. += span_notice("The anchoring bolts are <b>wrenched</b> in place, but the maintenance panel lacks <i>wiring</i>.")
else
. += span_notice("The assembly is <b>welded together</b>, but the anchoring bolts are <i>unwrenched</i>.")
if(AIRLOCK_ASSEMBLY_NEEDS_ELECTRONICS)
. += span_notice("The maintenance panel is <b>wired</b>, but the circuit slot is <i>empty</i>.")
if(AIRLOCK_ASSEMBLY_NEEDS_SCREWDRIVER)
. += span_notice("The circuit is <b>connected loosely</b> to its slot, but the maintenance panel is <i>unscrewed and open</i>.")
if(!mineral && !nomineral && !glass && !noglass)
. += span_notice("There are <i>empty</i> slots for glass windows and mineral covers.")
else if(!mineral && !nomineral && glass && !noglass)
. += span_notice("There are <i>empty</i> slots for mineral covers.")
else if(!glass && !noglass)
. += span_notice("There are <i>empty</i> slots for glass windows.")
if(doorname)
. += span_notice("There is a small <i>paper</i> placard on the assembly labelled \"[doorname]\".")
/obj/structure/door_assembly/attackby(obj/item/W, mob/living/user, params)
if(istype(W, /obj/item/pen) && !user.combat_mode)
var/t = tgui_input_text(user, "Enter the name for the door", "Airlock Renaming", created_name, MAX_NAME_LEN)
if(!t)
return
if(!in_range(src, usr) && loc != usr)
return
created_name = t
else if((W.tool_behaviour == TOOL_WELDER) && (mineral || glass || !anchored ))
if(!W.tool_start_check(user, amount=0))
return
if(mineral)
var/obj/item/stack/sheet/mineral/mineral_path = text2path("/obj/item/stack/sheet/mineral/[mineral]")
user.visible_message(span_notice("[user] welds the [mineral] plating off the airlock assembly."), span_notice("You start to weld the [mineral] plating off the airlock assembly..."))
if(W.use_tool(src, user, 40, volume=50))
to_chat(user, span_notice("You weld the [mineral] plating off."))
new mineral_path(loc, 2)
var/obj/structure/door_assembly/PA = new previous_assembly(loc)
transfer_assembly_vars(src, PA)
else if(glass)
user.visible_message(span_notice("[user] welds the glass panel out of the airlock assembly."), span_notice("You start to weld the glass panel out of the airlock assembly..."))
if(W.use_tool(src, user, 40, volume=50))
to_chat(user, span_notice("You weld the glass panel out."))
if(heat_proof_finished)
new /obj/item/stack/sheet/rglass(get_turf(src))
heat_proof_finished = 0
else
new /obj/item/stack/sheet/glass(get_turf(src))
glass = 0
else if(!anchored)
user.visible_message(span_warning("[user] disassembles the airlock assembly."), \
span_notice("You start to disassemble the airlock assembly..."))
if(W.use_tool(src, user, 40, volume=50))
to_chat(user, span_notice("You disassemble the airlock assembly."))
deconstruct(TRUE)
else if(W.tool_behaviour == TOOL_WRENCH)
if(!anchored )
var/door_check = 1
for(var/obj/machinery/door/D in loc)
if(!D.sub_door)
door_check = 0
break
if(door_check)
user.visible_message(span_notice("[user] secures the airlock assembly to the floor."), \
span_notice("You start to secure the airlock assembly to the floor..."), \
span_hear("You hear wrenching."))
if(W.use_tool(src, user, 40, volume=100))
if(anchored)
return
to_chat(user, span_notice("You secure the airlock assembly."))
name = "secured airlock assembly"
set_anchored(TRUE)
else
to_chat(user, "There is another door here!")
else
user.visible_message(span_notice("[user] unsecures the airlock assembly from the floor."), \
span_notice("You start to unsecure the airlock assembly from the floor..."), \
span_hear("You hear wrenching."))
if(W.use_tool(src, user, 40, volume=100))
if(!anchored)
return
to_chat(user, span_notice("You unsecure the airlock assembly."))
name = "airlock assembly"
set_anchored(FALSE)
else if(istype(W, /obj/item/stack/cable_coil) && state == AIRLOCK_ASSEMBLY_NEEDS_WIRES && anchored )
if(!W.tool_start_check(user, amount=1))
return
user.visible_message(span_notice("[user] wires the airlock assembly."), \
span_notice("You start to wire the airlock assembly..."))
if(W.use_tool(src, user, 40, amount=1))
if(state != AIRLOCK_ASSEMBLY_NEEDS_WIRES)
return
state = AIRLOCK_ASSEMBLY_NEEDS_ELECTRONICS
to_chat(user, span_notice("You wire the airlock assembly."))
name = "wired airlock assembly"
else if((W.tool_behaviour == TOOL_WIRECUTTER) && state == AIRLOCK_ASSEMBLY_NEEDS_ELECTRONICS )
user.visible_message(span_notice("[user] cuts the wires from the airlock assembly."), \
span_notice("You start to cut the wires from the airlock assembly..."))
if(W.use_tool(src, user, 40, volume=100))
if(state != AIRLOCK_ASSEMBLY_NEEDS_ELECTRONICS)
return
to_chat(user, span_notice("You cut the wires from the airlock assembly."))
new/obj/item/stack/cable_coil(get_turf(user), 1)
state = AIRLOCK_ASSEMBLY_NEEDS_WIRES
name = "secured airlock assembly"
else if(istype(W, /obj/item/electronics/airlock) && state == AIRLOCK_ASSEMBLY_NEEDS_ELECTRONICS )
W.play_tool_sound(src, 100)
user.visible_message(span_notice("[user] installs the electronics into the airlock assembly."), \
span_notice("You start to install electronics into the airlock assembly..."))
if(do_after(user, 40, target = src))
if( state != AIRLOCK_ASSEMBLY_NEEDS_ELECTRONICS )
return
if(!user.transferItemToLoc(W, src))
return
to_chat(user, span_notice("You install the airlock electronics."))
state = AIRLOCK_ASSEMBLY_NEEDS_SCREWDRIVER
name = "near finished airlock assembly"
electronics = W
else if((W.tool_behaviour == TOOL_CROWBAR) && state == AIRLOCK_ASSEMBLY_NEEDS_SCREWDRIVER )
user.visible_message(span_notice("[user] removes the electronics from the airlock assembly."), \
span_notice("You start to remove electronics from the airlock assembly..."))
if(W.use_tool(src, user, 40, volume=100))
if(state != AIRLOCK_ASSEMBLY_NEEDS_SCREWDRIVER)
return
to_chat(user, span_notice("You remove the airlock electronics."))
state = AIRLOCK_ASSEMBLY_NEEDS_ELECTRONICS
name = "wired airlock assembly"
var/obj/item/electronics/airlock/ae
if (!electronics)
ae = new/obj/item/electronics/airlock( loc )
else
ae = electronics
electronics = null
ae.forceMove(src.loc)
else if(istype(W, /obj/item/stack/sheet) && (!glass || !mineral))
var/obj/item/stack/sheet/G = W
if(G)
if(G.get_amount() >= 1)
if(!noglass)
if(!glass)
if(istype(G, /obj/item/stack/sheet/rglass) || istype(G, /obj/item/stack/sheet/glass))
playsound(src, 'sound/items/crowbar.ogg', 100, TRUE)
user.visible_message(span_notice("[user] adds [G.name] to the airlock assembly."), \
span_notice("You start to install [G.name] into the airlock assembly..."))
if(do_after(user, 40, target = src))
if(G.get_amount() < 1 || glass)
return
if(G.type == /obj/item/stack/sheet/rglass)
to_chat(user, span_notice("You install [G.name] windows into the airlock assembly."))
heat_proof_finished = 1 //reinforced glass makes the airlock heat-proof
name = "near finished heat-proofed window airlock assembly"
else
to_chat(user, span_notice("You install regular glass windows into the airlock assembly."))
name = "near finished window airlock assembly"
G.use(1)
glass = TRUE
if(!nomineral && !mineral)
if(istype(G, /obj/item/stack/sheet/mineral) && G.sheettype)
var/M = G.sheettype
var/mineralassembly = text2path("/obj/structure/door_assembly/door_assembly_[M]")
if(!ispath(mineralassembly))
to_chat(user, span_warning("You cannot add [G] to [src]!"))
return
if(G.get_amount() >= 2)
playsound(src, 'sound/items/crowbar.ogg', 100, TRUE)
user.visible_message(span_notice("[user] adds [G.name] to the airlock assembly."), \
span_notice("You start to install [G.name] into the airlock assembly..."))
if(do_after(user, 40, target = src))
if(G.get_amount() < 2 || mineral)
return
to_chat(user, span_notice("You install [M] plating into the airlock assembly."))
G.use(2)
var/obj/structure/door_assembly/MA = new mineralassembly(loc)
if(MA.noglass && glass) //in case the new door doesn't support glass. prevents the new one from reverting to a normal airlock after being constructed.
var/obj/item/stack/sheet/dropped_glass
if(heat_proof_finished)
dropped_glass = new /obj/item/stack/sheet/rglass(drop_location())
heat_proof_finished = FALSE
else
dropped_glass = new /obj/item/stack/sheet/glass(drop_location())
glass = FALSE
to_chat(user, span_notice("As you finish, a [dropped_glass.singular_name] falls out of [MA]'s frame."))
transfer_assembly_vars(src, MA, TRUE)
else
to_chat(user, span_warning("You need at least two sheets add a mineral cover!"))
else
to_chat(user, span_warning("You cannot add [G] to [src]!"))
else
to_chat(user, span_warning("You cannot add [G] to [src]!"))
else if((W.tool_behaviour == TOOL_SCREWDRIVER) && state == AIRLOCK_ASSEMBLY_NEEDS_SCREWDRIVER )
user.visible_message(span_notice("[user] finishes the airlock."), \
span_notice("You start finishing the airlock..."))
if(W.use_tool(src, user, 40, volume=100))
if(loc && state == AIRLOCK_ASSEMBLY_NEEDS_SCREWDRIVER)
to_chat(user, span_notice("You finish the airlock."))
finish_door()
else
return ..()
update_name()
update_appearance()
/obj/structure/door_assembly/proc/finish_door()
var/obj/machinery/door/airlock/door
if(glass)
door = new glass_type( loc )
else
door = new airlock_type( loc )
door.setDir(dir)
door.unres_sides = electronics.unres_sides
//door.req_access = req_access
door.electronics = electronics
door.heat_proof = heat_proof_finished
door.security_level = 0
if(electronics.shell)
door.AddComponent( \
/datum/component/shell, \
unremovable_circuit_components = list(new /obj/item/circuit_component/airlock, new /obj/item/circuit_component/airlock_access_event), \
capacity = SHELL_CAPACITY_LARGE, \
shell_flags = SHELL_FLAG_ALLOW_FAILURE_ACTION|SHELL_FLAG_REQUIRE_ANCHOR \
)
if(electronics.one_access)
door.req_one_access = electronics.accesses
else
door.req_access = electronics.accesses
if(created_name)
door.name = created_name
else if(electronics.passed_name)
door.name = sanitize(electronics.passed_name)
else
door.name = base_name
if(electronics.passed_cycle_id)
door.closeOtherId = electronics.passed_cycle_id
door.update_other_id()
if(door.unres_sides)
door.unres_sensor = TRUE
door.previous_airlock = previous_assembly
electronics.forceMove(door)
door.update_appearance()
qdel(src)
return door
/obj/structure/door_assembly/update_overlays()
. = ..()
if(!glass)
. += get_airlock_overlay("fill_construction", icon, src, TRUE)
else
. += get_airlock_overlay("glass_construction", overlays_file, src, TRUE)
. += get_airlock_overlay("panel_c[state+1]", overlays_file, src, TRUE)
/obj/structure/door_assembly/update_name()
name = ""
switch(state)
if(AIRLOCK_ASSEMBLY_NEEDS_WIRES)
if(anchored)
name = "secured "
if(AIRLOCK_ASSEMBLY_NEEDS_ELECTRONICS)
name = "wired "
if(AIRLOCK_ASSEMBLY_NEEDS_SCREWDRIVER)
name = "near finished "
name += "[heat_proof_finished ? "heat-proofed " : ""][glass ? "window " : ""][base_name] assembly"
return ..()
/obj/structure/door_assembly/proc/transfer_assembly_vars(obj/structure/door_assembly/source, obj/structure/door_assembly/target, previous = FALSE)
target.glass = source.glass
target.heat_proof_finished = source.heat_proof_finished
target.created_name = source.created_name
target.state = source.state
target.set_anchored(source.anchored)
if(previous)
target.previous_assembly = source.type
if(electronics)
target.electronics = source.electronics
source.electronics.forceMove(target)
target.update_appearance()
target.update_name()
qdel(source)
/obj/structure/door_assembly/deconstruct(disassembled = TRUE)
if(!(flags_1 & NODECONSTRUCT_1))
var/turf/T = get_turf(src)
if(!disassembled)
material_amt = rand(2,4)
new material_type(T, material_amt)
if(glass)
if(disassembled)
if(heat_proof_finished)
new /obj/item/stack/sheet/rglass(T)
else
new /obj/item/stack/sheet/glass(T)
else
new /obj/item/shard(T)
if(mineral)
var/obj/item/stack/sheet/mineral/mineral_path = text2path("/obj/item/stack/sheet/mineral/[mineral]")
new mineral_path(T, 2)
qdel(src)
/obj/structure/door_assembly/rcd_vals(mob/user, obj/item/construction/rcd/the_rcd)
if(the_rcd.mode == RCD_DECONSTRUCT)
return list("mode" = RCD_DECONSTRUCT, "delay" = 50, "cost" = 16)
return FALSE
/obj/structure/door_assembly/rcd_act(mob/user, obj/item/construction/rcd/the_rcd, passed_mode)
switch(passed_mode)
if(RCD_DECONSTRUCT)
to_chat(user, span_notice("You deconstruct [src]."))
qdel(src)
return TRUE
return FALSE