From 111176c7c2f406fbd2a07e1c316134cbe2a02084 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Sat, 16 Jan 2021 00:49:46 +0100 Subject: [PATCH] [MIRROR] Wooden tables now obey The Law of Conservation of Mass (#2720) * Wooden tables now obey The Law of Conservation of Mass (#56156) ## About The Pull Request Fixes Issue https://github.com/tgstation/tgstation/issues/56152 making wood tables deconstruct at they should be. Bug vivisection: Okay, see here? This is the proc for creating a table, we can introduce three arguments. One of them is _buildstack. _buildstack overrides Buildstack on initialize, a variable used for storing the type of raw "ore" that the table is supposed to drop in deconstruction. Here is supposed to be null unless we want to override the buildstack with another ore. ```DM /obj/structure/table_frame/proc/make_new_table(table_type, custom_materials, _buildstack) var/obj/structure/table/T = new table_type(loc, _buildstack) T.frame = type T.framestack = framestack T.framestackamount = framestackamount if(custom_materials) T.set_custom_materials(custom_materials) qdel(src) ``` What happened? The proc for building a wood table from a wooden frame, shown below, passed the "type" variable, used for storing the type of table_frame, as a _buildstack argument to the make_new_table proc. This overrides the buildstack variable of the final wooden table, causing it to drop a wooden frame as it was an ore on deconstruction. ```DM /obj/structure/table_frame/wood/attackby(obj/item/I, mob/user, params) [...] if (toConstruct) if(material.get_amount() < 1) to_chat(user, "You need one [material.name] sheet to do this!") return to_chat(user, "You start adding [material] to [src]...") if(do_after(user, 20, target = src) && material.use(1)) make_new_table(toConstruct, null, type) ``` This is funnier (not very much, to be honest) when we consider that deconstructing with a screwdriver would drop a frame normally, causing it to drop two frames. We could repeat this ad nauseam, essentially cloning wood frames in place as we pleased. So TL;DR: this is another of those simple but hard to hunt bugs that would be prevented with testing and a null on its right place. * Wooden tables now obey The Law of Conservation of Mass Co-authored-by: Manybones --- code/game/objects/structures/table_frames.dm | 11 +++++++---- code/game/objects/structures/tables_racks.dm | 5 ----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/code/game/objects/structures/table_frames.dm b/code/game/objects/structures/table_frames.dm index 52f3f6bcab6..28954150e97 100644 --- a/code/game/objects/structures/table_frames.dm +++ b/code/game/objects/structures/table_frames.dm @@ -64,11 +64,13 @@ return ..() -/obj/structure/table_frame/proc/make_new_table(table_type, custom_materials, _buildstack) //makes sure the new table made retains what we had as a frame - var/obj/structure/table/T = new table_type(loc, _buildstack) +/obj/structure/table_frame/proc/make_new_table(table_type, custom_materials, carpet_type) //makes sure the new table made retains what we had as a frame + var/obj/structure/table/T = new table_type(loc) T.frame = type T.framestack = framestack T.framestackamount = framestackamount + if (carpet_type) + T.buildstack = carpet_type if(custom_materials) T.set_custom_materials(custom_materials) qdel(src) @@ -97,17 +99,18 @@ if (istype(I, /obj/item/stack)) var/obj/item/stack/material = I var/toConstruct // stores the table variant + var/carpet_type // stores the carpet type used for construction in case of poker tables if(istype(I, /obj/item/stack/sheet/mineral/wood)) toConstruct = /obj/structure/table/wood else if(istype(I, /obj/item/stack/tile/carpet)) toConstruct = /obj/structure/table/wood/poker - + carpet_type = I.type if (toConstruct) if(material.get_amount() < 1) to_chat(user, "You need one [material.name] sheet to do this!") return to_chat(user, "You start adding [material] to [src]...") if(do_after(user, 20, target = src) && material.use(1)) - make_new_table(toConstruct, null, type) + make_new_table(toConstruct, null, carpet_type) else return ..() diff --git a/code/game/objects/structures/tables_racks.dm b/code/game/objects/structures/tables_racks.dm index adbfe4dfe40..eebb4176397 100644 --- a/code/game/objects/structures/tables_racks.dm +++ b/code/game/objects/structures/tables_racks.dm @@ -37,11 +37,6 @@ smoothing_groups = list(SMOOTH_GROUP_TABLES) canSmoothWith = list(SMOOTH_GROUP_TABLES) -/obj/structure/table/Initialize(mapload, _buildstack) - . = ..() - if(_buildstack) - buildstack = _buildstack - /obj/structure/table/examine(mob/user) . = ..() . += deconstruction_hints(user)