From e50a028297ae4e1e19f01955e5ccf7d3b2e6e9df Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Mon, 3 May 2021 16:19:33 +0200 Subject: [PATCH] [MIRROR] RCD repairs grilles before adding windows to them (#5432) * RCD repairs grilles before adding windows to them (#58812) * RCD repairs grilles before adding windows to them - Grilles need to be clear of unanchored items for a window to fit on them - Attempting to build a window on a grille with unanchored items on it will automatically move 20 of them to your tile - If more than 20 items are on a tile, adding the window will fail (but you can just do it again to move 20 more) - Grilles no longer rely on a subtype to break * Uses text macro thing for simpler code * RCD repairs grilles before adding windows to them Co-authored-by: cacogen <25089914+cacogen@users.noreply.github.com> --- code/game/objects/structures/grille.dm | 62 ++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/code/game/objects/structures/grille.dm b/code/game/objects/structures/grille.dm index 09ae159ffd1..920a60e89f9 100644 --- a/code/game/objects/structures/grille.dm +++ b/code/game/objects/structures/grille.dm @@ -1,3 +1,6 @@ +/// Max number of unanchored items that will be moved from a tile when attempting to add a window to a grille. +#define CLEAR_TILE_MOVE_LIMIT 20 + /obj/structure/grille desc = "A flimsy framework of iron rods." name = "grille" @@ -15,8 +18,6 @@ var/rods_type = /obj/item/stack/rods var/rods_amount = 2 var/rods_broken = TRUE - var/grille_type = null - var/broken_type = /obj/structure/grille/broken /obj/structure/grille/Initialize(mapload) . = ..() @@ -77,6 +78,13 @@ if(!isturf(loc)) return FALSE var/turf/T = loc + + if(repair_grille()) + to_chat(user, "You rebuild the broken grille.") + + if(!clear_tile(user)) + return FALSE + if(!ispath(the_rcd.window_type, /obj/structure/window)) CRASH("Invalid window path type in RCD: [the_rcd.window_type]") var/obj/structure/window/window_path = the_rcd.window_type @@ -88,6 +96,29 @@ return TRUE return FALSE +/obj/structure/grille/proc/clear_tile(mob/user) + var/at_users_feet = get_turf(user) + + var/unanchored_items_on_tile + var/obj/item/last_item_moved + for(var/obj/item/item_to_move in loc.contents) + if(!item_to_move.anchored) + if(unanchored_items_on_tile <= CLEAR_TILE_MOVE_LIMIT) + item_to_move.forceMove(at_users_feet) + last_item_moved = item_to_move + unanchored_items_on_tile++ + + if(!unanchored_items_on_tile) + return TRUE + + to_chat(user, "You move [unanchored_items_on_tile == 1 ? "[last_item_moved]" : "some things"] out of the way.") + + if(unanchored_items_on_tile - CLEAR_TILE_MOVE_LIMIT > 0) + to_chat(user, "There's still too much stuff in the way!") + return FALSE + + return TRUE + /obj/structure/grille/Bumped(atom/movable/AM) if(!ismob(AM)) return @@ -159,9 +190,8 @@ if(!shock(user, 90)) user.visible_message("[user] rebuilds the broken grille.", \ "You rebuild the broken grille.") - new grille_type(src.loc) + repair_grille() R.use(1) - qdel(src) return //window placing begin @@ -178,12 +208,16 @@ for(var/obj/structure/window/WINDOW in loc) to_chat(user, "There is already a window there!") return + if(!clear_tile(user)) + return to_chat(user, "You start placing the window...") if(do_after(user,20, target = src)) if(!src.loc || !anchored) //Grille broken or unanchored while waiting return for(var/obj/structure/window/WINDOW in loc) //Another window already installed on grille return + if(!clear_tile(user)) + return var/obj/structure/window/WD if(istype(W, /obj/item/stack/sheet/plasmarglass)) WD = new/obj/structure/window/plasma/reinforced/fulltile(drop_location()) //reinforced plasma window @@ -232,11 +266,25 @@ /obj/structure/grille/obj_break() if(!broken && !(flags_1 & NODECONSTRUCT_1)) - new broken_type(src.loc) + icon_state = "brokengrille" + density = FALSE + obj_integrity = 20 + broken = TRUE + rods_amount = 1 + rods_broken = FALSE var/obj/R = new rods_type(drop_location(), rods_broken) transfer_fingerprints_to(R) - qdel(src) +/obj/structure/grille/proc/repair_grille() + if(broken) + icon_state = "grille" + density = TRUE + obj_integrity = max_integrity + broken = FALSE + rods_amount = 2 + rods_broken = TRUE + return TRUE + return FALSE // shock user with probability prb (if all connections & power are working) // returns 1 if shocked, 0 otherwise @@ -289,5 +337,3 @@ broken = TRUE rods_amount = 1 rods_broken = FALSE - grille_type = /obj/structure/grille - broken_type = null