From 49150c542f4f0395e3c2921d9cd81321580270a1 Mon Sep 17 00:00:00 2001 From: vuonojenmustaturska Date: Wed, 2 May 2018 09:32:00 +0300 Subject: [PATCH 1/2] Splits APC attackbys into tool acts, removes some old parts that do nothing and allows crowbars to remove the cell too (#37035) * APC crap * moar define * honk * cover defines --- code/modules/power/apc.dm | 327 ++++++++++++++++++++------------------ 1 file changed, 174 insertions(+), 153 deletions(-) diff --git a/code/modules/power/apc.dm b/code/modules/power/apc.dm index 0d07b3dbf9..d17513ddf9 100644 --- a/code/modules/power/apc.dm +++ b/code/modules/power/apc.dm @@ -26,6 +26,13 @@ #define APC_UPOVERLAY_LOCKED (1<<12) #define APC_UPOVERLAY_OPERATING (1<<13) +#define APC_ELECTRONICS_MISSING 0 // None +#define APC_ELECTRONICS_INSTALLED 1 // Installed but not secured +#define APC_ELECTRONICS_SECURED 2 // Installed and secured + +#define APC_COVER_CLOSED 0 +#define APC_COVER_OPENED 1 +#define APC_COVER_REMOVED 2 // the Area Power Controller (APC), formerly Power Distribution Unit (PDU) // one per area, needs wire connection to power network through a terminal @@ -34,10 +41,6 @@ // may be opened to change power cell // three different channels (lighting/equipment/environ) - may each be set to on, off, or auto - -//NOTE: STUFF STOLEN FROM AIRLOCK.DM thx - - /obj/machinery/power/apc name = "area power controller" desc = "A control terminal for the area's electrical systems." @@ -57,7 +60,7 @@ var/obj/item/stock_parts/cell/cell var/start_charge = 90 // initial cell charge % var/cell_type = /obj/item/stock_parts/cell/upgraded //Base cell has 2500 capacity. Enter the path of a different cell you want to use. cell determines charge rates, max capacity, ect. These can also be changed with other APC vars, but isn't recommended to minimize the risk of accidental usage of dirty editted APCs - var/opened = 0 //0=closed, 1=opened, 2=cover removed + var/opened = APC_COVER_CLOSED var/shorted = 0 var/lighting = 3 var/equipment = 3 @@ -79,7 +82,7 @@ powernet = 0 // set so that APCs aren't found as powernet nodes //Hackish, Horrible, was like this before I changed it :( var/malfhack = 0 //New var for my changes to AI malf. --NeoFite var/mob/living/silicon/ai/malfai = null //See above --NeoFite - var/has_electronics = 0 // 0 - none, 1 - plugged in, 2 - secured by screwdriver + var/has_electronics = APC_ELECTRONICS_MISSING // 0 - none, 1 - plugged in, 2 - secured by screwdriver var/overload = 1 //used for the Blackout malf module var/beenhit = 0 // used for counting how many times it has been hit, used for Aliens at the moment var/mob/living/silicon/ai/occupier = null @@ -147,7 +150,7 @@ pixel_x = -25 if (building) area = get_area(src) - opened = 1 + opened = APC_COVER_OPENED operating = FALSE name = "[area.name] APC" stat |= MAINT @@ -190,7 +193,7 @@ . = ..() if(!mapload) return - has_electronics = 2 //installed and secured + has_electronics = APC_ELECTRONICS_SECURED // is starting with a power cell installed, create it and set its charge level if(cell_type) cell = new cell_type @@ -218,7 +221,7 @@ return if(opened) if(has_electronics && terminal) - to_chat(user, "The cover is [opened==2?"removed":"open"] and the power cell is [ cell ? "installed" : "missing"].") + to_chat(user, "The cover is [opened==APC_COVER_REMOVED?"removed":"open"] and the power cell is [ cell ? "installed" : "missing"].") else to_chat(user, "It's [ !terminal ? "not" : "" ] wired up.") to_chat(user, "The electronics are[!has_electronics?"n't":""] installed.") @@ -316,9 +319,9 @@ if(stat & MAINT) update_state |= UPSTATE_MAINT if(opened) - if(opened==1) + if(opened==APC_COVER_OPENED) update_state |= UPSTATE_OPENED1 - if(opened==2) + if(opened==APC_COVER_REMOVED) update_state |= UPSTATE_OPENED2 else if((obj_flags & EMAGGED) || malfai) update_state |= UPSTATE_BLUESCREEN @@ -378,75 +381,142 @@ //attack with an item - open/close cover, insert cell, or (un)lock interface +/obj/machinery/power/apc/crowbar_act(mob/user, obj/item/W) + . = TRUE + if (opened) + if(cell) + user.visible_message("[user] removes \the [cell] from [src]!","You remove \the [cell].") + var/turf/T = get_turf(user) + cell.forceMove(T) + cell.update_icon() + cell = null + charging = 0 + update_icon() + return + if (has_electronics == APC_ELECTRONICS_INSTALLED) + if (terminal) + to_chat(user, "Disconnect the wires first!") + return + W.play_tool_sound(src) + to_chat(user, "You attempt to remove the power control board..." ) + if(W.use_tool(src, user, 50)) + if (has_electronics == APC_ELECTRONICS_INSTALLED) + has_electronics = APC_ELECTRONICS_MISSING + if (stat & BROKEN) + user.visible_message(\ + "[user.name] has broken the power control board inside [src.name]!",\ + "You break the charred power control board and remove the remains.", + "You hear a crack.") + return + else if (obj_flags & EMAGGED) + obj_flags &= ~EMAGGED + user.visible_message(\ + "[user.name] has discarded an emagged power control board from [src.name]!",\ + "You discard the emagged power control board.") + return + else if (malfhack) + user.visible_message(\ + "[user.name] has discarded a strangely programmed power control board from [src.name]!",\ + "You discard the strangely programmed board.") + malfai = null + malfhack = 0 + return + else + user.visible_message(\ + "[user.name] has removed the power control board from [src.name]!",\ + "You remove the power control board.") + new /obj/item/electronics/apc(loc) + return + else if(integration_cog) + user.visible_message("[user] starts prying [integration_cog] from [src]...", \ + "You painstakingly start tearing [integration_cog] out of [src]'s guts...") + W.play_tool_sound(src) + if(W.use_tool(src, user, 100)) + user.visible_message("[user] destroys [integration_cog] in [src]!", \ + "[integration_cog] comes free with a clank and snaps in two as the machinery returns to normal!") + playsound(src, 'sound/items/deconstruct.ogg', 50, TRUE) + QDEL_NULL(integration_cog) + return + else if (opened!=APC_COVER_REMOVED) + opened = APC_COVER_CLOSED + coverlocked = TRUE //closing cover relocks it + update_icon() + return + else if (!(stat & BROKEN)) + if(coverlocked && !(stat & MAINT)) // locked... + to_chat(user, "The cover is locked and cannot be opened!") + return + else if (panel_open) + to_chat(user, "Exposed wires prevents you from opening it!") + return + else + opened = APC_COVER_OPENED + update_icon() + return + +/obj/machinery/power/apc/screwdriver_act(mob/living/user, obj/item/W) + . = TRUE + if(opened) + if (cell) + to_chat(user, "Close the APC first!") + return + else + switch (has_electronics) + if (APC_ELECTRONICS_INSTALLED) + has_electronics = APC_ELECTRONICS_SECURED + stat &= ~MAINT + W.play_tool_sound(src) + to_chat(user, "You screw the circuit electronics into place.") + if (APC_ELECTRONICS_SECURED) + has_electronics = APC_ELECTRONICS_INSTALLED + stat |= MAINT + W.play_tool_sound(src) + to_chat(user, "You unfasten the electronics.") + else + to_chat(user, "There is nothing to secure!") + return + update_icon() + else if(obj_flags & EMAGGED) + to_chat(user, "The interface is broken!") + return + else + panel_open = !panel_open + to_chat(user, "The wires have been [panel_open ? "exposed" : "unexposed"]") + update_icon() + +/obj/machinery/power/apc/wirecutter_act(mob/living/user, obj/item/W) + if (terminal && opened) + terminal.dismantle(user, W) + return TRUE + + +/obj/machinery/power/apc/welder_act(mob/living/user, obj/item/W) + if (opened && !has_electronics && !terminal) + if(!W.tool_start_check(user, amount=3)) + return + user.visible_message("[user.name] welds [src].", \ + "You start welding the APC frame...", \ + "You hear welding.") + if(W.use_tool(src, user, 50, volume=50, amount=3)) + if ((stat & BROKEN) || opened==APC_COVER_REMOVED) + new /obj/item/stack/sheet/metal(loc) + user.visible_message(\ + "[user.name] has cut [src] apart with [W].",\ + "You disassembled the broken APC frame.") + else + new /obj/item/wallframe/apc(loc) + user.visible_message(\ + "[user.name] has cut [src] from the wall with [W].",\ + "You cut the APC frame from the wall.") + qdel(src) + return TRUE + /obj/machinery/power/apc/attackby(obj/item/W, mob/living/user, params) if(issilicon(user) && get_dist(src,user)>1) return attack_hand(user) - if (istype(W, /obj/item/crowbar)) //Using crowbar - if (opened) // a) on open apc - if (has_electronics==1) - if (terminal) - to_chat(user, "Disconnect the wires first!") - return - W.play_tool_sound(src) - to_chat(user, "You are trying to remove the power control board..." ) - if(W.use_tool(src, user, 50)) - if (has_electronics==1) - has_electronics = 0 - if (stat & BROKEN) - user.visible_message(\ - "[user.name] has broken the power control board inside [src.name]!",\ - "You break the charred power control board and remove the remains.", - "You hear a crack.") - return - //SSticker.mode:apcs-- //XSI said no and I agreed. -rastaf0 - else if (obj_flags & EMAGGED) // We emag board, not APC's frame - obj_flags &= ~EMAGGED - user.visible_message(\ - "[user.name] has discarded emaged power control board from [src.name]!",\ - "You discarded shorten board.") - return - else if (malfhack) // AI hacks board, not APC's frame - user.visible_message(\ - "[user.name] has discarded strangely programmed power control board from [src.name]!",\ - "You discarded strangely programmed board.") - malfai = null - malfhack = 0 - return - else - user.visible_message(\ - "[user.name] has removed the power control board from [src.name]!",\ - "You remove the power control board.") - new /obj/item/electronics/apc(loc) - return - else if(integration_cog) - user.visible_message("[user] starts prying [integration_cog] from [src]...", \ - "You painstakingly start tearing [integration_cog] out of [src]'s guts...") - W.play_tool_sound(src) - if(W.use_tool(src, user, 100)) - user.visible_message("[user] destroys [integration_cog] in [src]!", \ - "[integration_cog] comes free with a clank and snaps in two as the machinery returns to normal!") - playsound(src, 'sound/items/deconstruct.ogg', 50, TRUE) - QDEL_NULL(integration_cog) - return - else if (opened!=2) //cover isn't removed - opened = 0 - coverlocked = TRUE //closing cover relocks it - update_icon() - return - else if (!(stat & BROKEN)) // b) on closed and not broken APC - if(coverlocked && !(stat & MAINT)) // locked... - to_chat(user, "The cover is locked and cannot be opened!") - return - else if (panel_open) // wires are exposed - to_chat(user, "Exposed wires prevents you from opening it!") - return - else - opened = 1 - update_icon() - return - else if (istype(W, /obj/item/stock_parts/cell) && opened) // trying to put a cell inside + if (istype(W, /obj/item/stock_parts/cell) && opened) if(cell) to_chat(user, "There is a power cell already installed!") return @@ -462,39 +532,8 @@ "You insert the power cell.") chargecount = 0 update_icon() - - else if (istype(W, /obj/item/screwdriver)) // haxing - if(opened) - if (cell) - to_chat(user, "Close the APC first!") //Less hints more mystery! - return - else - if (has_electronics==1) - has_electronics = 2 - stat &= ~MAINT - W.play_tool_sound(src) - to_chat(user, "You screw the circuit electronics into place.") - else if (has_electronics==2) - has_electronics = 1 - stat |= MAINT - W.play_tool_sound(src) - to_chat(user, "You unfasten the electronics.") - else /* has_electronics==0 */ - to_chat(user, "There is nothing to secure!") - return - update_icon() - else if(obj_flags & EMAGGED) - to_chat(user, "The interface is broken!") - else if((stat & MAINT) && !opened) - ..() //its an empty closed frame... theres no wires to expose! - else - panel_open = !panel_open - to_chat(user, "The wires have been [panel_open ? "exposed" : "unexposed"]") - update_icon() - - else if (W.GetID()) // trying to unlock the interface with an ID card + else if (W.GetID()) togglelock(user) - else if (istype(W, /obj/item/stack/cable_coil) && opened) var/turf/host_turf = get_turf(src) if(!host_turf) @@ -503,10 +542,10 @@ if (host_turf.intact) to_chat(user, "You must remove the floor plating in front of the APC first!") return - else if (terminal) // it already have terminal + else if (terminal) to_chat(user, "This APC is already wired!") return - else if (has_electronics == 0) + else if (!has_electronics) to_chat(user, "There is nothing to wire!") return @@ -520,7 +559,7 @@ if(do_after(user, 20, target = src)) if (C.get_amount() < 10 || !C) return - if (C.get_amount() >= 10 && !terminal && opened && has_electronics > 0) + if (C.get_amount() >= 10 && !terminal && opened && has_electronics) var/turf/T = get_turf(src) var/obj/structure/cable/N = T.get_cable_node() if (prob(50) && electrocute_mob(usr, N, N, 1, TRUE)) @@ -530,13 +569,9 @@ to_chat(user, "You add cables to the APC frame.") make_terminal() terminal.connect_to_network() - - else if (istype(W, /obj/item/wirecutters) && terminal && opened) - terminal.dismantle(user, W) - else if (istype(W, /obj/item/electronics/apc) && opened) - if (has_electronics!=0) // there are already electronicks inside - to_chat(user, "You cannot put the board inside, there already is one!") + if (has_electronics) + to_chat(user, "There is already a board inside the [src]!") return else if (stat & BROKEN) to_chat(user, "You cannot put the board inside, the frame is damaged!") @@ -546,12 +581,11 @@ "You start to insert the power control board into the frame...") playsound(src.loc, 'sound/items/deconstruct.ogg', 50, 1) if(do_after(user, 10, target = src)) - if(has_electronics==0) - has_electronics = 1 + if(!has_electronics) + has_electronics = APC_ELECTRONICS_INSTALLED locked = FALSE to_chat(user, "You place the power control board inside the frame.") qdel(W) - else if(istype(W, /obj/item/electroadaptive_pseudocircuit) && opened) var/obj/item/electroadaptive_pseudocircuit/P = W if(!has_electronics) @@ -562,7 +596,7 @@ return user.visible_message("[user] fabricates a circuit and places it into [src].", \ "You adapt a power control board and click it into place in [src]'s guts.") - has_electronics = TRUE + has_electronics = APC_ELECTRONICS_INSTALLED locked = FALSE else if(!cell) if(stat & MAINT) @@ -580,38 +614,17 @@ else to_chat(user, "[src] has both electronics and a cell.") return - - else if (istype(W, /obj/item/weldingtool) && opened && has_electronics==0 && !terminal) - if(!W.tool_start_check(user, amount=3)) - return - user.visible_message("[user.name] welds [src].", \ - "You start welding the APC frame...", \ - "You hear welding.") - if(W.use_tool(src, user, 50, volume=50, amount=3)) - if ((stat & BROKEN) || opened==2) - new /obj/item/stack/sheet/metal(loc) - user.visible_message(\ - "[user.name] has cut [src] apart with [W].",\ - "You disassembled the broken APC frame.") - else - new /obj/item/wallframe/apc(loc) - user.visible_message(\ - "[user.name] has cut [src] from the wall with [W].",\ - "You cut the APC frame from the wall.") - qdel(src) - return - else if (istype(W, /obj/item/wallframe/apc) && opened) - if (!(stat & BROKEN || opened==2 || obj_integrity < max_integrity)) // There is nothing to repair + if (!(stat & BROKEN || opened==APC_COVER_REMOVED || obj_integrity < max_integrity)) // There is nothing to repair to_chat(user, "You found no reason for repairing this APC") return - if (!(stat & BROKEN) && opened==2) // Cover is the only thing broken, we do not need to remove elctronicks to replace cover + if (!(stat & BROKEN) && opened==APC_COVER_REMOVED) // Cover is the only thing broken, we do not need to remove elctronicks to replace cover user.visible_message("[user.name] replaces missing APC's cover.",\ "You begin to replace APC's cover...") if(do_after(user, 20, target = src)) // replacing cover is quicker than replacing whole frame to_chat(user, "You replace missing APC's cover.") qdel(W) - opened = 1 + opened = APC_COVER_OPENED update_icon() return if (has_electronics) @@ -624,8 +637,8 @@ qdel(W) stat &= ~BROKEN obj_integrity = max_integrity - if (opened==2) - opened = 1 + if (opened==APC_COVER_REMOVED) + opened = APC_COVER_OPENED update_icon() else if(istype(W, /obj/item/clockwork/integration_cog) && is_servant_of_ratvar(user)) if(integration_cog) @@ -634,7 +647,7 @@ if(!opened) user.visible_message("[user] slices [src]'s cover lock, and it swings wide open!", \ "You slice [src]'s cover lock apart with [W], and the cover swings open.") - opened = TRUE + opened = APC_COVER_OPENED update_icon() else user.visible_message("[user] presses [W] into [src]!", \ @@ -650,7 +663,7 @@ integration_cog = W START_PROCESSING(SSfastprocess, W) playsound(src, 'sound/machines/clockcult/steam_whoosh.ogg', 50, FALSE) - opened = FALSE + opened = APC_COVER_CLOSED locked = FALSE update_icon() return @@ -697,8 +710,9 @@ if(!(flags_1 & NODECONSTRUCT_1)) if(!(stat & BROKEN)) set_broken() - if(opened != 2) - opened = 2 + if(opened != APC_COVER_REMOVED) + opened = APC_COVER_REMOVED + coverlocked = FALSE visible_message("The APC cover is knocked down!") update_icon() @@ -718,15 +732,14 @@ to_chat(user, "You emag the APC interface.") update_icon() + // attack with hand - remove cell (if cover open) or interact with the APC /obj/machinery/power/apc/attack_hand(mob/user) . = ..() if(.) return - if(!user) - return - if(usr == user && opened && (!issilicon(user))) + if(opened && (!issilicon(user))) if(cell) user.visible_message("[user] removes \the [cell] from [src]!","You remove \the [cell].") user.put_in_hands(cell) @@ -1337,6 +1350,14 @@ #undef APC_RESET_EMP +#undef APC_ELECTRONICS_MISSING +#undef APC_ELECTRONICS_INSTALLED +#undef APC_ELECTRONICS_SECURED + +#undef APC_COVER_CLOSED +#undef APC_COVER_OPENED +#undef APC_COVER_REMOVED + //update_overlay #undef APC_UPOVERLAY_CHARGEING0 #undef APC_UPOVERLAY_CHARGEING1