From 8b99bc27b2657b4b193a5196efb0caf1fb37bd9d Mon Sep 17 00:00:00 2001 From: Julian56 <117036822+Huffie56@users.noreply.github.com> Date: Wed, 21 Feb 2024 14:05:34 +0100 Subject: [PATCH] refactor barricades files to hopfully have a more constant interaction when trying to fix them with welder. (#5609) # About the pull request fixes: https://github.com/cmss13-devs/cmss13/issues/5229 1-replace a bunch of single letter variable and in the same movement standardize it for all the parent/child object... 2-create a proc that is a group of check to see if you can start fixing a barricade with a welder. 3-implement this proc on metal,plasteel and deployable to have all the check be the same as we want them to all react the same way... # Explain why it's good for the game # Testing Photographs and Procedure i tested welding different different cades at the same time seem to work i had some weirdness but it's working.
Screenshots & Videos Put screenshots and videos here with an empty line between the screenshots and the `
` tags.
# Changelog :cl: refactor: refactored files with the aim of making fixing barricade with a welder more constant. fix: being unable to repair more than one metal barricade at the time. /:cl: --------- Co-authored-by: Julien Co-authored-by: Birdtalon --- .../objects/structures/barricade/barricade.dm | 43 +++++++++++++--- .../structures/barricade/deployable.dm | 14 ++---- .../objects/structures/barricade/handrail.dm | 18 +++---- .../objects/structures/barricade/metal.dm | 22 +++------ .../objects/structures/barricade/plasteel.dm | 49 ++++++++----------- 5 files changed, 77 insertions(+), 69 deletions(-) diff --git a/code/game/objects/structures/barricade/barricade.dm b/code/game/objects/structures/barricade/barricade.dm index 0a37e4bcec59..37975d4a8960 100644 --- a/code/game/objects/structures/barricade/barricade.dm +++ b/code/game/objects/structures/barricade/barricade.dm @@ -5,21 +5,28 @@ climbable = TRUE anchored = TRUE density = TRUE - throwpass = TRUE //You can throw objects over this, despite its density. + /// You can throw objects over this, despite its density. + throwpass = TRUE layer = BELOW_OBJ_LAYER flags_atom = ON_BORDER - var/stack_type //The type of stack the barricade dropped when disassembled if any. - var/stack_amount = 5 //The amount of stack dropped when disassembled at full health - var/destroyed_stack_amount //to specify a non-zero amount of stack to drop when destroyed + /// The type of stack the barricade dropped when disassembled if any. + var/stack_type + /// The amount of stack dropped when disassembled at full health + var/stack_amount = 5 + /// to specify a non-zero amount of stack to drop when destroyed + var/destroyed_stack_amount health = 100 //Pretty tough. Changes sprites at 300 and 150 - var/maxhealth = 100 //Basic code functions + var/maxhealth = 100 /// Used for calculating some stuff related to maxhealth as it constantly changes due to e.g. barbed wire. set to 100 to avoid possible divisions by zero var/starting_maxhealth = 100 - var/crusher_resistant = TRUE //Whether a crusher can ram through it. - var/force_level_absorption = 5 //How much force an item needs to even damage it at all. + /// Whether a crusher can ram through it. + var/crusher_resistant = TRUE + /// How much force an item needs to even damage it at all. + var/force_level_absorption = 5 var/barricade_hitsound var/barricade_type = "barricade" //"metal", "plasteel", etc. - var/wire_icon = 'icons/obj/structures/barricades.dmi' //! Icon file used for the wiring + /// ! Icon file used for the wiring + var/wire_icon = 'icons/obj/structures/barricades.dmi' var/can_change_dmg_state = TRUE var/damage_state = BARRICADE_DMG_NONE var/closed = FALSE @@ -35,6 +42,8 @@ var/burn_flame_multiplier = 1 var/repair_materials = list() var/metallic = TRUE + /// Lower limit of damage beyond which the barricade cannot be fixed by welder. Compared to damage_state. If null it can be repaired at any damage_state. + var/welder_lower_damage_limit = null /obj/structure/barricade/Initialize(mapload, mob/user) . = ..() @@ -466,3 +475,21 @@ nailgun.in_chamber = null nailgun.load_into_chamber() return TRUE + +// This proc is to check a bunch of condition to cancel the action that a welder user is trying to do while giving +// a explanation on why... + +/obj/structure/barricade/proc/attackby_welder(obj/item/item, mob/user) + if(!HAS_TRAIT(item, TRAIT_TOOL_BLOWTORCH)) + to_chat(user, SPAN_WARNING("You need a stronger blowtorch!")) + return FALSE + + if(health == maxhealth) + to_chat(user, SPAN_WARNING("[src] doesn't need repairs.")) + return FALSE + + if(!(isnull(damage_state)) && !(isnull(welder_lower_damage_limit)) && damage_state >= welder_lower_damage_limit) + to_chat(user, SPAN_WARNING("[src] has sustained too much structural damage to be repaired.")) + return FALSE + + return TRUE diff --git a/code/game/objects/structures/barricade/deployable.dm b/code/game/objects/structures/barricade/deployable.dm index 0d5275f98a3d..3de5ba1928a2 100644 --- a/code/game/objects/structures/barricade/deployable.dm +++ b/code/game/objects/structures/barricade/deployable.dm @@ -26,17 +26,11 @@ /obj/structure/barricade/deployable/attackby(obj/item/item, mob/user) if(iswelder(item)) - if(!HAS_TRAIT(item, TRAIT_TOOL_BLOWTORCH)) - to_chat(user, SPAN_WARNING("You need a stronger blowtorch!")) - return - if(user.action_busy) - return - var/obj/item/tool/weldingtool/welder = item - if(health == maxhealth) - to_chat(user, SPAN_WARNING("[src] doesn't need repairs.")) - return + if(!attackby_welder(item, user)) + return FALSE + - weld_cade(welder, user) + weld_cade(item, user) return else if(HAS_TRAIT(item, TRAIT_TOOL_CROWBAR)) diff --git a/code/game/objects/structures/barricade/handrail.dm b/code/game/objects/structures/barricade/handrail.dm index ae166dbbf985..1d641479c3d9 100644 --- a/code/game/objects/structures/barricade/handrail.dm +++ b/code/game/objects/structures/barricade/handrail.dm @@ -67,7 +67,7 @@ reinforced = !reinforced update_icon() -/obj/structure/barricade/handrail/attackby(obj/item/W, mob/user) +/obj/structure/barricade/handrail/attackby(obj/item/item, mob/user) for(var/obj/effect/xenomorph/acid/A in src.loc) if(A.acid_t == src) to_chat(user, "You can't get near that, it's melting!") @@ -75,7 +75,7 @@ switch(build_state) if(BARRICADE_BSTATE_SECURED) //Non-reinforced. Wrench to unsecure. Screwdriver to disassemble into metal. 1 metal to reinforce. - if(HAS_TRAIT(W, TRAIT_TOOL_WRENCH)) // Make unsecure + if(HAS_TRAIT(item, TRAIT_TOOL_WRENCH)) // Make unsecure if(user.action_busy) return if(!skillcheck(user, SKILL_CONSTRUCTION, SKILL_CONSTRUCTION_TRAINED)) @@ -89,7 +89,7 @@ build_state = BARRICADE_BSTATE_UNSECURED update_icon() return - if(istype(W, /obj/item/stack/sheet/metal)) // Start reinforcing + if(istype(item, /obj/item/stack/sheet/metal)) // Start reinforcing if(!can_be_reinforced) return if(user.action_busy) @@ -97,7 +97,7 @@ if(!skillcheck(user, SKILL_CONSTRUCTION, SKILL_CONSTRUCTION_TRAINED)) to_chat(user, SPAN_WARNING("You are not trained to reinforce [src]...")) return - var/obj/item/stack/sheet/metal/M = W + var/obj/item/stack/sheet/metal/M = item playsound(src.loc, 'sound/items/Screwdriver2.ogg', 25, 1) if(M.amount >= 1 && do_after(user, 30, INTERRUPT_ALL|BEHAVIOR_IMMOBILE, BUSY_ICON_BUILD)) //Shouldnt be possible, but doesnt hurt to check if(!M.use(1)) @@ -109,7 +109,7 @@ return if(BARRICADE_BSTATE_UNSECURED) - if(HAS_TRAIT(W, TRAIT_TOOL_WRENCH)) // Secure again + if(HAS_TRAIT(item, TRAIT_TOOL_WRENCH)) // Secure again if(user.action_busy) return if(!skillcheck(user, SKILL_CONSTRUCTION, SKILL_CONSTRUCTION_TRAINED)) @@ -123,7 +123,7 @@ build_state = BARRICADE_BSTATE_SECURED update_icon() return - if(HAS_TRAIT(W, TRAIT_TOOL_SCREWDRIVER)) // Disassemble into metal + if(HAS_TRAIT(item, TRAIT_TOOL_SCREWDRIVER)) // Disassemble into metal if(user.action_busy) return if(!skillcheck(user, SKILL_CONSTRUCTION, SKILL_CONSTRUCTION_TRAINED)) @@ -141,7 +141,7 @@ if(BARRICADE_BSTATE_FORTIFIED) if(reinforced) - if(HAS_TRAIT(W, TRAIT_TOOL_CROWBAR)) // Un-reinforce + if(HAS_TRAIT(item, TRAIT_TOOL_CROWBAR)) // Un-reinforce if(user.action_busy) return if(!skillcheck(user, SKILL_CONSTRUCTION, SKILL_CONSTRUCTION_TRAINED)) @@ -155,8 +155,8 @@ reinforce() return else - if(iswelder(W)) // Finish reinforcing - if(!HAS_TRAIT(W, TRAIT_TOOL_BLOWTORCH)) + if(iswelder(item)) // Finish reinforcing + if(!HAS_TRAIT(item, TRAIT_TOOL_BLOWTORCH)) to_chat(user, SPAN_WARNING("You need a stronger blowtorch!")) return if(user.action_busy) diff --git a/code/game/objects/structures/barricade/metal.dm b/code/game/objects/structures/barricade/metal.dm index 4f250eed50e9..59f4ad314878 100644 --- a/code/game/objects/structures/barricade/metal.dm +++ b/code/game/objects/structures/barricade/metal.dm @@ -19,6 +19,8 @@ var/build_state = BARRICADE_BSTATE_SECURED //Look at __game.dm for barricade defines var/upgrade = null + welder_lower_damage_limit = BARRICADE_DMG_HEAVY + /obj/structure/barricade/metal/update_icon() . = ..() if(dir > 2) @@ -44,24 +46,16 @@ /obj/structure/barricade/metal/attackby(obj/item/item, mob/user) if(iswelder(item)) - if(!HAS_TRAIT(item, TRAIT_TOOL_BLOWTORCH)) - to_chat(user, SPAN_WARNING("You need a stronger blowtorch!")) - return - if(user.action_busy) - return + if(!attackby_welder(item, user)) + return FALSE + + if(!skillcheck(user, SKILL_ENGINEER, SKILL_ENGINEER_TRAINED)) to_chat(user, SPAN_WARNING("You're not trained to repair [src]...")) - return - var/obj/item/tool/weldingtool/welder = item - if(damage_state == BARRICADE_DMG_HEAVY) - to_chat(user, SPAN_WARNING("[src] has sustained too much structural damage to be repaired.")) - return + return FALSE - if(health == maxhealth) - to_chat(user, SPAN_WARNING("[src] doesn't need repairs.")) - return + weld_cade(item, user) - weld_cade(welder, user) return if(try_nailgun_usage(item, user)) diff --git a/code/game/objects/structures/barricade/plasteel.dm b/code/game/objects/structures/barricade/plasteel.dm index dd95aa3f1baf..bba07832f790 100644 --- a/code/game/objects/structures/barricade/plasteel.dm +++ b/code/game/objects/structures/barricade/plasteel.dm @@ -20,12 +20,15 @@ repair_materials = list("plasteel" = 0.3) var/build_state = BARRICADE_BSTATE_SECURED //Look at __game.dm for barricade defines - var/tool_cooldown = 0 //Delay to apply tools to prevent spamming - var/busy = FALSE //Standard busy check + /// Delay to apply tools to prevent spamming + var/tool_cooldown = 0 + /// Standard busy check + var/busy = FALSE var/linked = 0 var/recentlyflipped = FALSE var/hasconnectionoverlay = TRUE var/linkable = TRUE + welder_lower_damage_limit = BARRICADE_DMG_HEAVY /obj/structure/barricade/plasteel/update_icon() ..() @@ -57,35 +60,25 @@ if(BARRICADE_BSTATE_MOVABLE) . += SPAN_INFO("The protection panel has been removed and the anchor bolts loosened. It's ready to be taken apart.") -/obj/structure/barricade/plasteel/weld_cade(obj/item/W, mob/user) +/obj/structure/barricade/plasteel/weld_cade(obj/item/item, mob/user) busy = TRUE ..() busy = FALSE -/obj/structure/barricade/plasteel/attackby(obj/item/W, mob/user) - if(iswelder(W)) - if(!HAS_TRAIT(W, TRAIT_TOOL_BLOWTORCH)) - to_chat(user, SPAN_WARNING("You need a stronger blowtorch!")) - return - if(busy || tool_cooldown > world.time) - return - tool_cooldown = world.time + 10 +/obj/structure/barricade/plasteel/attackby(obj/item/item, mob/user) + if(iswelder(item)) + if(!attackby_welder(item, user)) + return FALSE + + if(!skillcheck(user, SKILL_ENGINEER, SKILL_ENGINEER_TRAINED)) to_chat(user, SPAN_WARNING("You're not trained to repair [src]...")) - return - var/obj/item/tool/weldingtool/WT = W - if(damage_state == BARRICADE_DMG_HEAVY) - to_chat(user, SPAN_WARNING("[src] has sustained too much structural damage to be repaired.")) - return - - if(health == maxhealth) - to_chat(user, SPAN_WARNING("[src] doesn't need repairs.")) - return + return FALSE - weld_cade(WT, user) + weld_cade(item, user) return - if(try_nailgun_usage(W, user)) + if(try_nailgun_usage(item, user)) return for(var/obj/effect/xenomorph/acid/A in src.loc) @@ -95,7 +88,7 @@ switch(build_state) if(2) //Fully constructed step. Use screwdriver to remove the protection panels to reveal the bolts - if(HAS_TRAIT(W, TRAIT_TOOL_SCREWDRIVER)) + if(HAS_TRAIT(item, TRAIT_TOOL_SCREWDRIVER)) if(busy || tool_cooldown > world.time) return tool_cooldown = world.time + 10 @@ -113,7 +106,7 @@ playsound(src.loc, 'sound/items/Screwdriver.ogg', 25, 1) build_state = BARRICADE_BSTATE_UNSECURED return - if(HAS_TRAIT(W, TRAIT_TOOL_CROWBAR)) + if(HAS_TRAIT(item, TRAIT_TOOL_CROWBAR)) if(!skillcheck(user, SKILL_ENGINEER, SKILL_ENGINEER_ENGI)) to_chat(user, SPAN_WARNING("You are not trained to modify [src]...")) return @@ -133,7 +126,7 @@ cade.update_icon() update_icon() if(1) //Protection panel removed step. Screwdriver to put the panel back, wrench to unsecure the anchor bolts - if(HAS_TRAIT(W, TRAIT_TOOL_SCREWDRIVER)) + if(HAS_TRAIT(item, TRAIT_TOOL_SCREWDRIVER)) if(busy || tool_cooldown > world.time) return tool_cooldown = world.time + 10 @@ -146,7 +139,7 @@ playsound(src.loc, 'sound/items/Screwdriver.ogg', 25, 1) build_state = BARRICADE_BSTATE_SECURED return - if(HAS_TRAIT(W, TRAIT_TOOL_WRENCH)) + if(HAS_TRAIT(item, TRAIT_TOOL_WRENCH)) if(busy || tool_cooldown > world.time) return tool_cooldown = world.time + 10 @@ -163,7 +156,7 @@ return if(0) //Anchor bolts loosened step. Apply crowbar to unseat the panel and take apart the whole thing. Apply wrench to rescure anchor bolts - if(HAS_TRAIT(W, TRAIT_TOOL_WRENCH)) + if(HAS_TRAIT(item, TRAIT_TOOL_WRENCH)) if(busy || tool_cooldown > world.time) return tool_cooldown = world.time + 10 @@ -182,7 +175,7 @@ build_state = BARRICADE_BSTATE_UNSECURED update_icon() //unanchored changes layer return - if(HAS_TRAIT(W, TRAIT_TOOL_CROWBAR)) + if(HAS_TRAIT(item, TRAIT_TOOL_CROWBAR)) if(busy || tool_cooldown > world.time) return tool_cooldown = world.time + 10