Files
Bubberstation/code/modules/holodeck/items.dm
SyncIt21 6dc40ca522 Standardizes object deconstruction throughout the codebase. (#82280)
## 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 do

b5593bc693/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 everywhere

b5593bc693/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 behind

b5593bc693/code/datums/elements/frozen.dm (L66-L67)

By hologram objects. Obviously if you destroy an hologram nothing real
should drop out

b5593bc693/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
exists

b5593bc693/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 such

3e84c3e6da/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>
2024-04-04 18:55:51 -06:00

170 lines
4.9 KiB
Plaintext

/*
Items, Structures, Machines
*/
//
// Items
//
/obj/item/melee/energy/sword/holographic
name = "holographic energy sword"
desc = "May the force be with you. Sorta."
damtype = STAMINA
throw_speed = 2
block_chance = 0
throwforce = 0
embedding = null
sword_color_icon = null
active_throwforce = 0
active_sharpness = NONE
active_heat = 0
/obj/item/melee/energy/sword/holographic/Initialize(mapload)
. = ..()
if(!sword_color_icon)
sword_color_icon = pick("red", "blue", "green", "purple")
/obj/item/melee/energy/sword/holographic/green
sword_color_icon = "green"
/obj/item/melee/energy/sword/holographic/red
sword_color_icon = "red"
/obj/item/toy/cards/deck/syndicate/holographic
desc = "A deck of holographic playing cards."
/obj/item/toy/cards/deck/syndicate/holographic/Initialize(mapload, obj/machinery/computer/holodeck/holodeck)
src.holodeck = holodeck
RegisterSignal(src, COMSIG_QDELETING, PROC_REF(handle_card_delete))
. = ..()
/obj/item/toy/cards/deck/syndicate/holographic/proc/handle_card_delete(datum/source)
SIGNAL_HANDLER
//if any REAL cards have been inserted into the deck they are moved outside before destroying it
for(var/obj/item/toy/singlecard/card in card_atoms)
if(card.flags_1 & HOLOGRAM_1)
continue
card_atoms -= card
card.forceMove(drop_location())
/obj/item/toy/dodgeball
name = "dodgeball"
icon = 'icons/obj/toys/balls.dmi'
icon_state = "dodgeball"
inhand_icon_state = "dodgeball"
desc = "Used for playing the most violent and degrading of childhood games."
w_class = WEIGHT_CLASS_BULKY //Stops people from hiding it in their bags/pockets
/obj/item/toy/dodgeball/throw_impact(atom/hit_atom, datum/thrownthing/throwingdatum)
..()
if((ishuman(hit_atom)))
var/mob/living/carbon/M = hit_atom
playsound(src, 'sound/items/dodgeball.ogg', 50, TRUE)
M.apply_damage(10, STAMINA)
if(prob(5))
M.Paralyze(60)
visible_message(span_danger("[M] is knocked right off [M.p_their()] feet!"))
//
// Machines
//
/obj/machinery/readybutton
name = "ready declaration device"
desc = "This device is used to declare ready. If all devices in an area are ready, the event will begin!"
icon = 'icons/obj/machines/wallmounts.dmi'
icon_state = "auth_off"
var/ready = 0
var/area/currentarea = null
var/eventstarted = FALSE
idle_power_usage = BASE_MACHINE_IDLE_CONSUMPTION * 0.02
active_power_usage = BASE_MACHINE_ACTIVE_CONSUMPTION * 0.006
power_channel = AREA_USAGE_ENVIRON
/obj/machinery/readybutton/attack_ai(mob/user)
to_chat(user, span_warning("The station AI is not to interact with these devices!"))
return
/obj/machinery/readybutton/attack_paw(mob/user, list/modifiers)
to_chat(user, span_warning("You are too primitive to use this device!"))
return
/obj/machinery/readybutton/attackby(obj/item/W, mob/user, params)
to_chat(user, span_warning("The device is a solid button, there's nothing you can do with it!"))
/obj/machinery/readybutton/attack_hand(mob/user, list/modifiers)
. = ..()
if(.)
return
if(machine_stat & (NOPOWER|BROKEN))
to_chat(user, span_warning("This device is not powered!"))
return
currentarea = get_area(src)
if(isnull(currentarea))
qdel(src)
return
if(eventstarted)
to_chat(usr, span_warning("The event has already begun!"))
return
ready = !ready
update_appearance()
var/numbuttons = 0
var/numready = 0
for (var/list/zlevel_turfs as anything in currentarea.get_zlevel_turf_lists())
for (var/turf/area_turf as anything in zlevel_turfs)
for(var/obj/machinery/readybutton/button in area_turf)
numbuttons++
if(button.ready)
numready++
if(numbuttons == numready)
begin_event()
/obj/machinery/readybutton/update_icon_state()
icon_state = "auth_[ready ? "on" : "off"]"
return ..()
/obj/machinery/readybutton/proc/begin_event()
eventstarted = TRUE
for (var/list/zlevel_turfs as anything in currentarea.get_zlevel_turf_lists())
for(var/turf/area_turf as anything in zlevel_turfs)
for(var/obj/structure/window/barrier in area_turf)
if(barrier.flags_1 & HOLOGRAM_1)// Just in case: only holo-windows
qdel(barrier)
for(var/mob/contestant in area_turf)
to_chat(contestant, span_userdanger("FIGHT!"))
/obj/machinery/conveyor/holodeck
/obj/machinery/conveyor/holodeck/attackby(obj/item/I, mob/user, params)
if(!user.transferItemToLoc(I, drop_location()))
return ..()
/obj/item/paper/fluff/holodeck/trek_diploma
name = "paper - Starfleet Academy Diploma"
default_raw_text = {"<h2>Starfleet Academy</h2></br><p>Official Diploma</p></br>"}
/obj/item/paper/fluff/holodeck/disclaimer
name = "Holodeck Disclaimer"
default_raw_text = "Bruises sustained in the holodeck can be healed simply by sleeping."
/obj/vehicle/ridden/scooter/skateboard/pro/holodeck
name = "holographic skateboard"
desc = "A holographic copy of the EightO brand professional skateboard."
instability = 6
/obj/vehicle/ridden/scooter/skateboard/pro/holodeck/pick_up_board() //picking up normal skateboards spawned in the holodeck gets rid of the holo flag, now you cant pick them up.
return