mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-01-04 14:01:22 +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>
213 lines
6.8 KiB
Plaintext
213 lines
6.8 KiB
Plaintext
#define BOOKCASE_UNANCHORED 0
|
|
#define BOOKCASE_ANCHORED 1
|
|
#define BOOKCASE_FINISHED 2
|
|
|
|
/obj/structure/bookcase
|
|
name = "bookcase"
|
|
icon = 'icons/obj/service/library.dmi'
|
|
icon_state = "bookempty"
|
|
desc = "A great place for storing knowledge."
|
|
anchored = FALSE
|
|
density = TRUE
|
|
opacity = FALSE
|
|
resistance_flags = FLAMMABLE
|
|
max_integrity = 200
|
|
armor_type = /datum/armor/structure_bookcase
|
|
var/state = BOOKCASE_UNANCHORED
|
|
/// When enabled, books_to_load number of random books will be generated for this bookcase
|
|
var/load_random_books = FALSE
|
|
/// The category of books to pick from when populating random books.
|
|
var/random_category = null
|
|
/// How many random books to generate.
|
|
var/books_to_load = 0
|
|
|
|
/datum/armor/structure_bookcase
|
|
fire = 50
|
|
|
|
/obj/structure/bookcase/Initialize(mapload)
|
|
. = ..()
|
|
if(!mapload || QDELETED(src))
|
|
return
|
|
// Only mapload from here on
|
|
set_anchored(TRUE)
|
|
state = BOOKCASE_FINISHED
|
|
for(var/obj/item/I in loc)
|
|
if(!isbook(I))
|
|
continue
|
|
I.forceMove(src)
|
|
update_appearance()
|
|
|
|
if(SSlibrary.initialized)
|
|
INVOKE_ASYNC(src, PROC_REF(load_shelf))
|
|
else
|
|
SSlibrary.shelves_to_load += src
|
|
|
|
///proc for doing things after a bookcase is randomly populated
|
|
/obj/structure/bookcase/proc/after_random_load()
|
|
return
|
|
|
|
///Loads the shelf, both by allowing it to generate random items, and by adding its contents to a list used by library machines
|
|
/obj/structure/bookcase/proc/load_shelf()
|
|
//Loads a random selection of books in from the db, adds a copy of their info to a global list
|
|
//To send to library consoles as a starting inventory
|
|
if(load_random_books)
|
|
create_random_books(books_to_load, src, FALSE, random_category)
|
|
after_random_load()
|
|
update_appearance() //Make sure you look proper
|
|
|
|
var/area/our_area = get_area(src)
|
|
var/area_type = our_area.type //Save me from the dark
|
|
|
|
if(!SSlibrary.books_by_area[area_type])
|
|
SSlibrary.books_by_area[area_type] = list()
|
|
|
|
//Time to populate that list
|
|
var/list/books_in_area = SSlibrary.books_by_area[area_type]
|
|
for(var/obj/item/book/book in contents)
|
|
var/datum/book_info/info = book.book_data
|
|
books_in_area += info.return_copy()
|
|
|
|
/obj/structure/bookcase/examine(mob/user)
|
|
. = ..()
|
|
if(!anchored)
|
|
. += span_notice("The <i>bolts</i> on the bottom are unsecured.")
|
|
else
|
|
. += span_notice("It's secured in place with <b>bolts</b>.")
|
|
switch(state)
|
|
if(BOOKCASE_UNANCHORED)
|
|
. += span_notice("There's a <b>small crack</b> visible on the back panel.")
|
|
if(BOOKCASE_ANCHORED)
|
|
. += span_notice("There's space inside for a <i>wooden</i> shelf.")
|
|
if(BOOKCASE_FINISHED)
|
|
. += span_notice("There's a <b>small crack</b> visible on the shelf.")
|
|
|
|
/obj/structure/bookcase/set_anchored(anchorvalue)
|
|
. = ..()
|
|
if(isnull(.))
|
|
return
|
|
state = anchorvalue
|
|
if(!anchorvalue) //in case we were vareditted or uprooted by a hostile mob, ensure we drop all our books instead of having them disappear till we're rebuild.
|
|
var/atom/Tsec = drop_location()
|
|
for(var/obj/I in contents)
|
|
if(!isbook(I))
|
|
continue
|
|
I.forceMove(Tsec)
|
|
update_appearance()
|
|
|
|
/obj/structure/bookcase/attackby(obj/item/I, mob/user, params)
|
|
switch(state)
|
|
if(BOOKCASE_UNANCHORED)
|
|
if(I.tool_behaviour == TOOL_WRENCH)
|
|
if(I.use_tool(src, user, 20, volume=50))
|
|
to_chat(user, span_notice("You wrench the frame into place."))
|
|
set_anchored(TRUE)
|
|
else if(I.tool_behaviour == TOOL_CROWBAR)
|
|
if(I.use_tool(src, user, 20, volume=50))
|
|
to_chat(user, span_notice("You pry the frame apart."))
|
|
deconstruct(TRUE)
|
|
|
|
if(BOOKCASE_ANCHORED)
|
|
if(istype(I, /obj/item/stack/sheet/mineral/wood))
|
|
var/obj/item/stack/sheet/mineral/wood/W = I
|
|
if(W.get_amount() >= 2)
|
|
W.use(2)
|
|
to_chat(user, span_notice("You add a shelf."))
|
|
state = BOOKCASE_FINISHED
|
|
update_appearance()
|
|
else if(I.tool_behaviour == TOOL_WRENCH)
|
|
I.play_tool_sound(src, 100)
|
|
to_chat(user, span_notice("You unwrench the frame."))
|
|
set_anchored(FALSE)
|
|
|
|
if(BOOKCASE_FINISHED)
|
|
if(isbook(I))
|
|
if(!user.transferItemToLoc(I, src))
|
|
return
|
|
update_appearance()
|
|
else if(atom_storage)
|
|
for(var/obj/item/T in I.contents)
|
|
if(istype(T, /obj/item/book) || istype(T, /obj/item/spellbook))
|
|
atom_storage.attempt_remove(T, src)
|
|
to_chat(user, span_notice("You empty \the [I] into \the [src]."))
|
|
update_appearance()
|
|
else if(istype(I, /obj/item/pen))
|
|
if(!user.can_perform_action(src) || !user.can_write(I))
|
|
return
|
|
var/newname = tgui_input_text(user, "What would you like to title this bookshelf?", "Bookshelf Renaming", max_length = MAX_NAME_LEN)
|
|
if(!user.can_perform_action(src) || !user.can_write(I))
|
|
return
|
|
if(!newname)
|
|
return
|
|
else
|
|
name = "bookcase ([sanitize(newname)])"
|
|
else if(I.tool_behaviour == TOOL_CROWBAR)
|
|
if(length(contents))
|
|
to_chat(user, span_warning("You need to remove the books first!"))
|
|
else
|
|
I.play_tool_sound(src, 100)
|
|
to_chat(user, span_notice("You pry the shelf out."))
|
|
new /obj/item/stack/sheet/mineral/wood(drop_location(), 2)
|
|
state = BOOKCASE_ANCHORED
|
|
update_appearance()
|
|
else
|
|
return ..()
|
|
|
|
/obj/structure/bookcase/attack_hand(mob/living/user, list/modifiers)
|
|
. = ..()
|
|
if(.)
|
|
return
|
|
if(!istype(user))
|
|
return
|
|
if(!length(contents))
|
|
return
|
|
var/obj/item/book/choice = tgui_input_list(user, "Book to remove from the shelf", "Remove Book", sort_names(contents.Copy()))
|
|
if(isnull(choice))
|
|
return
|
|
if(!(user.mobility_flags & MOBILITY_USE) || user.stat != CONSCIOUS || HAS_TRAIT(user, TRAIT_HANDS_BLOCKED) || !in_range(loc, user))
|
|
return
|
|
if(ishuman(user))
|
|
if(!user.get_active_held_item())
|
|
user.put_in_hands(choice)
|
|
else
|
|
choice.forceMove(drop_location())
|
|
update_appearance()
|
|
|
|
/obj/structure/bookcase/atom_deconstruct(disassembled = TRUE)
|
|
var/atom/Tsec = drop_location()
|
|
new /obj/item/stack/sheet/mineral/wood(Tsec, 4)
|
|
for(var/obj/item/I in contents)
|
|
if(!isbook(I)) //Wake me up inside
|
|
continue
|
|
I.forceMove(Tsec)
|
|
|
|
/obj/structure/bookcase/update_icon_state()
|
|
if(state == BOOKCASE_UNANCHORED || state == BOOKCASE_ANCHORED)
|
|
icon_state = "bookempty"
|
|
return ..()
|
|
var/amount = length(contents)
|
|
icon_state = "book-[clamp(amount, 0, 5)]"
|
|
return ..()
|
|
|
|
/obj/structure/bookcase/manuals/engineering
|
|
name = "engineering manuals bookcase"
|
|
|
|
/obj/structure/bookcase/manuals/engineering/Initialize(mapload)
|
|
. = ..()
|
|
new /obj/item/book/manual/wiki/engineering_construction(src)
|
|
new /obj/item/book/manual/wiki/engineering_hacking(src)
|
|
new /obj/item/book/manual/wiki/engineering_guide(src)
|
|
new /obj/item/book/manual/wiki/robotics_cyborgs(src)
|
|
update_appearance()
|
|
|
|
/obj/structure/bookcase/manuals/research_and_development
|
|
name = "\improper R&D manuals bookcase"
|
|
|
|
/obj/structure/bookcase/manuals/research_and_development/Initialize(mapload)
|
|
. = ..()
|
|
new /obj/item/book/manual/wiki/research_and_development(src)
|
|
update_appearance()
|
|
|
|
#undef BOOKCASE_UNANCHORED
|
|
#undef BOOKCASE_ANCHORED
|
|
#undef BOOKCASE_FINISHED
|