mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-01-18 04:55:27 +00:00
## About The Pull Request When it comes to deconstructing an object we have `proc/deconstruct()` & `NO_DECONSTRUCT` Lets talk about the flag first. **Problems with `NO_DECONSTRUCTION`** I know what the comment says on what it should dob5593bc693/code/__DEFINES/obj_flags.dm (L18)But everywhere people have decided to give their own meaning/definition to this flag. Here are some examples on how this flag is used **1. Make the object just disappear(not drop anything) when deconstructed** This is by far the largest use case everywhere. If an object is deconstructed(either via tools or smashed apart) then if it has this flag it should not drop any of its contents but just disappear. You have seen this code pattern used everywhereb5593bc693/code/game/machinery/constructable_frame.dm (L26-L31)This behaviour is then leveraged by 2 important components. When an object is frozen, if it is deconstructed it should just disappear without leaving any traces behindb5593bc693/code/datums/elements/frozen.dm (L66-L67)By hologram objects. Obviously if you destroy an hologram nothing real should drop outb5593bc693/code/modules/holodeck/computer.dm (L301-L304)And there are other use cases as well but we won't go into them as they aren't as significant as these. **2. To stop an object from being wrenched ??** Yeah this one is weird. Like why? I understand in some instances (chair, table, rack etc) a wrench can be used to deconstruct a object so using the flag there to stop it from happening makes sense but why can't we even anchor an object just because of this flag?b5593bc693/code/game/objects/objs.dm (L368-L369)This is one of those instances where somebody just decided this behaviour for their own convenience just like the above example with no explanation as to why **3. To stop using tools to deconstruct the object** This was the original intent of the flag but it is enforced in few places far & between. One example is when deconstructing the a machine via crowbar.b5593bc693/code/game/machinery/_machinery.dm (L811)But machines are a special dual use case for this flag. Because if you look at its deconstruct proc the flag also prevents the machine from spawning a frame.b5593bc693/code/game/machinery/_machinery.dm (L820-L822)How can 1 flag serve 2 purposes within the same type? **4. Simply forget to check for this flag altogether** Yup if you find this flag not doing its job for some objects don't be surprised. People & sometimes even maintainers just forget that it even existsb5593bc693/code/game/objects/items/piggy_bank.dm (L66-L67)**Solution** These are the main examples i found. As you can see the same flag can perform 2 different functions within the same type and do something else in a different object & in some instances don't even work cause people just forget, etc. In order to bring consistency to this flag we need to move it to the atom level where it means the same thing everywhere. Where in the atom you may ask? .Well, I'll just post what MrMelbert said in https://github.com/tgstation/tgstation/pull/81656#discussion_r1503086862 > ...Ideally the .deconstruct call would handle NO_DECONSTRUCTION handling as it wants, Yup that's the ideal case now. This flag is checked directly in `deconstruct()`. Now like i said we want to give a universal definition to this flag and as you have seen from my examples it is used in 3 cases 1) Make an object disappear(doesn't dropping anything) when deconstructed 2) Stop it from being wrenched 3) Stop it from being deconstructed via tools We can't enforce points 2 & 3 inside `deconstruct()` which leaves us with only case 1) i.e. make the object disappear. And that's what i have done. Therefore after more than a decade or since this flag got introduced `NO_DECONSTRUCT` now has a new definition as of 2024 _"Make an object disappear(don't dropping anything) when deconstructed either via tools or forcefully smashed apart"_ Now i very well understand this will open up bugs in places where cases 2 & 3 are required but its worth it. In fact they could even be qol changes for all we know so who knows it might even benefit us but for now we need to give a universal definition to this flag to bring some consistency & that's what this PR does. **Problem with deconstruct()** This proc actually sends out a signal which is currently used by the material container but could be used by other objects later on.3e84c3e6da/code/game/objects/obj_defense.dm (L160)So objects that override this proc should call its parent. Sadly that isn't the case in many instances like such3e84c3e6da/code/game/machinery/deployable.dm (L20-L23)Instead of `return ..()` which would delete the object & send the signal it deletes the object directly thus the signal never gets sent. **Solution** Make this proc non overridable. For objects to add their own custom deconstruction behaviour a new proc has been introduced `atom_deconstruct()` Subtypes should now override this proc to handle object deconstruction. If objects have certain important stuff inside them (like mobs in machines for example) they want to drop by handling `NO_DECONSTRUCT` flag in a more carefully customized way they can do this by overriding `handle_deconstruct()` which by default delegates to `atom_deconstruct()` if the `NO_DECONSTRUCT` flag is absent. This proc will allow you to handle the flag in a more customized way if you ever need to. ## Why It's Good For The Game 1) I'm goanna post the full comment from MrMelbert https://github.com/tgstation/tgstation/pull/81656#discussion_r1503086862 > ...Ideally the .deconstruct call would handle NO_DECONSTRUCTION handling as it wants, but there's a shocking lack of consistency around NO_DECONSTRUCTION, where some objects treat it as "allow deconstruction, but make it drop no parts" and others simply "disallow deconstruction at all" This PR now makes `NO_DECONSTRUCTION` handled by `deconstruct()` & gives this flag the consistency it deserves. Not to mention as shown in case 4 there are objects that simply forgot to check for this flag. Now it applies for those missing instances as well. 2) No more copying pasting the most overused code pattern in this code base history `if(obj_flags & NO_DECONSTRUCTION)`. Just makes code cleaner everywhere 3) All objects now send the `COMSIG_OBJ_DECONSTRUCT` signal on object deconstruction which is now available for use should you need it ## Changelog 🆑 refactor: refactors how objects are deconstructed in relation to the `NO_DECONSTRUCTION` flag. Certain objects & machinery may display different tool interactions & behaviours when destroyed/deconstructed. Report these changes if you feel like they are bugs /🆑 --------- Co-authored-by: san7890 <the@san7890.com>
259 lines
8.5 KiB
Plaintext
259 lines
8.5 KiB
Plaintext
#define STAIR_TERMINATOR_AUTOMATIC 0
|
|
#define STAIR_TERMINATOR_NO 1
|
|
#define STAIR_TERMINATOR_YES 2
|
|
|
|
// dir determines the direction of travel to go upwards
|
|
// stairs require /turf/open/openspace as the tile above them to work, unless your stairs have 'force_open_above' set to TRUE
|
|
// multiple stair objects can be chained together; the Z level transition will happen on the final stair object in the chain
|
|
|
|
/obj/structure/stairs
|
|
name = "stairs"
|
|
icon = 'icons/obj/stairs.dmi'
|
|
icon_state = "stairs"
|
|
anchored = TRUE
|
|
move_resist = INFINITY
|
|
|
|
var/force_open_above = FALSE // replaces the turf above this stair obj with /turf/open/openspace
|
|
var/terminator_mode = STAIR_TERMINATOR_AUTOMATIC
|
|
var/turf/listeningTo
|
|
|
|
/obj/structure/stairs/north
|
|
dir = NORTH
|
|
|
|
/obj/structure/stairs/south
|
|
dir = SOUTH
|
|
|
|
/obj/structure/stairs/east
|
|
dir = EAST
|
|
|
|
/obj/structure/stairs/west
|
|
dir = WEST
|
|
|
|
/obj/structure/stairs/wood
|
|
icon_state = "stairs_wood"
|
|
|
|
/obj/structure/stairs/stone
|
|
icon_state = "stairs_stone"
|
|
|
|
/obj/structure/stairs/material
|
|
icon_state = "stairs_material"
|
|
material_flags = MATERIAL_EFFECTS | MATERIAL_ADD_PREFIX | MATERIAL_COLOR | MATERIAL_AFFECT_STATISTICS
|
|
|
|
/obj/structure/stairs/Initialize(mapload)
|
|
GLOB.stairs += src
|
|
if(force_open_above)
|
|
force_open_above()
|
|
build_signal_listener()
|
|
update_surrounding()
|
|
|
|
var/static/list/loc_connections = list(
|
|
COMSIG_ATOM_EXIT = PROC_REF(on_exit),
|
|
)
|
|
|
|
AddElement(/datum/element/connect_loc, loc_connections)
|
|
|
|
return ..()
|
|
|
|
/obj/structure/stairs/Destroy()
|
|
listeningTo = null
|
|
GLOB.stairs -= src
|
|
return ..()
|
|
|
|
/obj/structure/stairs/Move() //Look this should never happen but...
|
|
. = ..()
|
|
if(force_open_above)
|
|
build_signal_listener()
|
|
update_surrounding()
|
|
|
|
/obj/structure/stairs/proc/update_surrounding()
|
|
update_appearance()
|
|
for(var/i in GLOB.cardinals)
|
|
var/turf/T = get_step(get_turf(src), i)
|
|
var/obj/structure/stairs/S = locate() in T
|
|
if(S)
|
|
S.update_appearance()
|
|
|
|
/obj/structure/stairs/proc/on_exit(datum/source, atom/movable/leaving, direction)
|
|
SIGNAL_HANDLER
|
|
|
|
if(leaving == src)
|
|
return //Let's not block ourselves.
|
|
|
|
if(!isobserver(leaving) && isTerminator() && direction == dir)
|
|
leaving.set_currently_z_moving(CURRENTLY_Z_ASCENDING)
|
|
INVOKE_ASYNC(src, PROC_REF(stair_ascend), leaving)
|
|
leaving.Bump(src)
|
|
return COMPONENT_ATOM_BLOCK_EXIT
|
|
|
|
/obj/structure/stairs/Cross(atom/movable/AM)
|
|
if(isTerminator() && (get_dir(src, AM) == dir))
|
|
return FALSE
|
|
return ..()
|
|
|
|
/obj/structure/stairs/proc/stair_ascend(atom/movable/climber)
|
|
var/turf/checking = get_step_multiz(get_turf(src), UP)
|
|
if(!istype(checking))
|
|
return
|
|
// I'm only interested in if the pass is unobstructed, not if the mob will actually make it
|
|
if(!climber.can_z_move(UP, get_turf(src), checking, z_move_flags = ZMOVE_ALLOW_BUCKLED))
|
|
return
|
|
var/turf/target = get_step_multiz(get_turf(src), (dir|UP))
|
|
if(istype(target) && !climber.can_z_move(DOWN, target, z_move_flags = ZMOVE_FALL_FLAGS)) //Don't throw them into a tile that will just dump them back down.
|
|
climber.zMove(target = target, z_move_flags = ZMOVE_STAIRS_FLAGS)
|
|
/// Moves anything that's being dragged by src or anything buckled to it to the stairs turf.
|
|
climber.pulling?.move_from_pull(climber, loc, climber.glide_size)
|
|
for(var/mob/living/buckled as anything in climber.buckled_mobs)
|
|
buckled.pulling?.move_from_pull(buckled, loc, buckled.glide_size)
|
|
|
|
|
|
/obj/structure/stairs/vv_edit_var(var_name, var_value)
|
|
. = ..()
|
|
if(!.)
|
|
return
|
|
if(var_name != NAMEOF(src, force_open_above))
|
|
return
|
|
if(!var_value)
|
|
if(listeningTo)
|
|
UnregisterSignal(listeningTo, COMSIG_TURF_MULTIZ_NEW)
|
|
listeningTo = null
|
|
else
|
|
build_signal_listener()
|
|
force_open_above()
|
|
|
|
/obj/structure/stairs/proc/build_signal_listener()
|
|
if(listeningTo)
|
|
UnregisterSignal(listeningTo, COMSIG_TURF_MULTIZ_NEW)
|
|
var/turf/open/openspace/T = get_step_multiz(get_turf(src), UP)
|
|
RegisterSignal(T, COMSIG_TURF_MULTIZ_NEW, PROC_REF(on_multiz_new))
|
|
listeningTo = T
|
|
|
|
/obj/structure/stairs/proc/force_open_above()
|
|
var/turf/open/openspace/T = get_step_multiz(get_turf(src), UP)
|
|
if(T && !istype(T))
|
|
T.ChangeTurf(/turf/open/openspace, flags = CHANGETURF_INHERIT_AIR)
|
|
|
|
/obj/structure/stairs/proc/on_multiz_new(turf/source, dir)
|
|
SIGNAL_HANDLER
|
|
|
|
if(dir == UP)
|
|
var/turf/open/openspace/T = get_step_multiz(get_turf(src), UP)
|
|
if(T && !istype(T))
|
|
T.ChangeTurf(/turf/open/openspace, flags = CHANGETURF_INHERIT_AIR)
|
|
|
|
/obj/structure/stairs/intercept_zImpact(list/falling_movables, levels = 1)
|
|
. = ..()
|
|
if(levels == 1 && isTerminator()) // Stairs won't save you from a steep fall.
|
|
. |= FALL_INTERCEPTED | FALL_NO_MESSAGE | FALL_RETAIN_PULL
|
|
|
|
/obj/structure/stairs/proc/isTerminator() //If this is the last stair in a chain and should move mobs up
|
|
if(terminator_mode != STAIR_TERMINATOR_AUTOMATIC)
|
|
return (terminator_mode == STAIR_TERMINATOR_YES)
|
|
var/turf/T = get_turf(src)
|
|
if(!T)
|
|
return FALSE
|
|
var/turf/them = get_step(T, dir)
|
|
if(!them)
|
|
return FALSE
|
|
for(var/obj/structure/stairs/S in them)
|
|
if(S.dir == dir)
|
|
return FALSE
|
|
return TRUE
|
|
|
|
/obj/structure/stairs_frame
|
|
name = "stairs frame"
|
|
desc = "Everything you need to call something a staircase, aside from the stuff you actually step on."
|
|
icon = 'icons/obj/stairs.dmi'
|
|
icon_state = "stairs_frame"
|
|
density = FALSE
|
|
anchored = FALSE
|
|
/// What type of stack will this drop on deconstruction?
|
|
var/frame_stack = /obj/item/stack/rods
|
|
/// How much of frame_stack should this drop on deconstruction?
|
|
var/frame_stack_amount = 10
|
|
|
|
/obj/structure/stairs_frame/wood
|
|
name = "wooden stairs frame"
|
|
desc = "Everything you need to build a staircase, minus the actual stairs, this one is made of wood."
|
|
frame_stack = /obj/item/stack/sheet/mineral/wood
|
|
|
|
/obj/structure/stairs_frame/Initialize(mapload)
|
|
. = ..()
|
|
AddComponent(/datum/component/simple_rotation)
|
|
|
|
/obj/structure/stairs_frame/examine(mob/living/carbon/human/user)
|
|
. = ..()
|
|
if(anchored)
|
|
. += span_notice("The frame is anchored and can be made into proper stairs with 10 sheets of material.")
|
|
else
|
|
. += span_notice("The frame will need to be secured with a wrench before it can be completed.")
|
|
|
|
/obj/structure/stairs_frame/wrench_act(mob/living/user, obj/item/used_tool)
|
|
user.balloon_alert_to_viewers("securing stairs frame", "securing frame")
|
|
used_tool.play_tool_sound(src)
|
|
if(!used_tool.use_tool(src, user, 3 SECONDS))
|
|
return TRUE
|
|
if(anchored)
|
|
anchored = FALSE
|
|
playsound(loc, 'sound/items/deconstruct.ogg', 50, TRUE)
|
|
return TRUE
|
|
anchored = TRUE
|
|
playsound(loc, 'sound/items/deconstruct.ogg', 50, TRUE)
|
|
return TRUE
|
|
|
|
/obj/structure/stairs_frame/wrench_act_secondary(mob/living/user, obj/item/used_tool)
|
|
to_chat(user, span_notice("You start disassembling [src]..."))
|
|
used_tool.play_tool_sound(src)
|
|
if(!used_tool.use_tool(src, user, 3 SECONDS))
|
|
return TRUE
|
|
playsound(loc, 'sound/items/deconstruct.ogg', 50, TRUE)
|
|
deconstruct(TRUE)
|
|
return TRUE
|
|
|
|
/obj/structure/stairs_frame/atom_deconstruct(disassembled = TRUE)
|
|
new frame_stack(get_turf(src), frame_stack_amount)
|
|
|
|
/obj/structure/stairs_frame/attackby(obj/item/attacked_by, mob/user, params)
|
|
if(!isstack(attacked_by))
|
|
return ..()
|
|
if(!anchored)
|
|
user.balloon_alert(user, "secure frame first")
|
|
return TRUE
|
|
var/obj/item/stack/material = attacked_by
|
|
if(material.stairs_type)
|
|
if(material.get_amount() < 10)
|
|
to_chat(user, span_warning("You need ten [material.name] sheets to do this!"))
|
|
return
|
|
if(locate(/obj/structure/stairs) in loc)
|
|
to_chat(user, span_warning("There's already stairs built here!"))
|
|
return
|
|
to_chat(user, span_notice("You start adding [material] to [src]..."))
|
|
if(!do_after(user, 10 SECONDS, target = src) || !material.use(10) || (locate(/obj/structure/table) in loc))
|
|
return
|
|
make_new_stairs(material.stairs_type)
|
|
else if(istype(material, /obj/item/stack/sheet))
|
|
if(material.get_amount() < 10)
|
|
to_chat(user, span_warning("You need ten sheets to do this!"))
|
|
return
|
|
if(locate(/obj/structure/stairs) in loc)
|
|
to_chat(user, span_warning("There's already stairs built here!"))
|
|
return
|
|
to_chat(user, span_notice("You start adding [material] to [src]..."))
|
|
if(!do_after(user, 10 SECONDS, target = src) || !material.use(10) || (locate(/obj/structure/table) in loc))
|
|
return
|
|
var/list/material_list = list()
|
|
if(material.material_type)
|
|
material_list[material.material_type] = SHEET_MATERIAL_AMOUNT * 10
|
|
make_new_stairs(/obj/structure/stairs/material, material_list)
|
|
return TRUE
|
|
|
|
/obj/structure/stairs_frame/proc/make_new_stairs(stairs_type, custom_materials)
|
|
var/obj/structure/stairs/new_stairs = new stairs_type(loc)
|
|
new_stairs.setDir(dir)
|
|
if(custom_materials)
|
|
new_stairs.set_custom_materials(custom_materials)
|
|
qdel(src)
|
|
|
|
#undef STAIR_TERMINATOR_AUTOMATIC
|
|
#undef STAIR_TERMINATOR_NO
|
|
#undef STAIR_TERMINATOR_YES
|