Files
Batrachophreno 4ecb0bc21c Repath obj/machinery to obj/structure/machinery [MDB Ignore] (#22500)
Repaths obj/machinery to obj/structure/machinery. **Note for
reviewers:** the only meaningful changed code exists within
**code/game/objects/structures.dm** and
**code/game/objects/structures/_machinery.dm**, largely concerning
damage procs. With the exception of moving airlock defines to their own
file, ALL OTHER CHANGES ARE STRICTLY PATH CHANGES.

Objects, _categorically_, are largely divided between those you can hold
in your hand/inventory and those you can't. Machinery objects are
already subtypes of Structures behaviorally, this PR just makes their
pathing reflect that, and allows for future work (tool actions, more
health/destruction functionality) to be developed without unnecessary
code duplication.

I have tested this PR by loading up the Horizon and dismantling various
machines and structures with tools, shooting guns of various types
throughout the ship, and detonating a bunch of explosions throughout the
ship.
2026-05-26 19:35:48 +00:00

149 lines
4.8 KiB
Plaintext

// Updated version of old powerswitch by Atlantis
// Has better texture, and is now considered electronic device
// AI has ability to toggle it in 5 seconds
// Humans need 30 seconds (AI is faster when it comes to complex electronics)
// Used for advanced grid control (read: Substations)
/obj/structure/machinery/power/breakerbox
name = "breaker box"
desc = "A large machine with heavy duty switching circuits used for advanced grid control."
icon = 'icons/obj/power.dmi'
icon_state = "bbox_off"
//directwired = 0
density = 1
anchored = 1
var/on = 0
var/busy = 0
var/directions = list(1,2,4,8,5,6,9,10)
var/RCon_tag = "NO_TAG"
var/update_locked = 0
/obj/structure/machinery/power/breakerbox/mechanics_hints(mob/user, distance, is_adjacent)
. += ..()
. += "A breaker brox functions as an electrical passthrough; if enabled, power will flow freely around it. In substations, this means that the PSU/SMES will be bypassed."
. += "Toggling the breaker box has a sixty-second cooldown time."
. += "A multitool can be used to update or clear the breaker's RCON tag."
/obj/structure/machinery/power/breakerbox/feedback_hints(mob/user, distance, is_adjacent)
. += ..()
if(on)
. += "It seems to be online."
else
. += "It seems to be offline."
/obj/structure/machinery/power/breakerbox/Initialize()
LAZYADD(SSmachinery.breaker_boxes, src)
return ..()
/obj/structure/machinery/power/breakerbox/update_icon()
icon_state = "bbox_[on ? "on" : "off"]"
/obj/structure/machinery/power/breakerbox/Destroy()
LAZYREMOVE(SSmachinery.breaker_boxes, src)
return ..()
/obj/structure/machinery/power/breakerbox/activated
icon_state = "bbox_on"
// Enabled on server startup. Used in substations to keep them in bypass mode.
/obj/structure/machinery/power/breakerbox/activated/Initialize()
..()
return INITIALIZE_HINT_LATELOAD
/obj/structure/machinery/power/breakerbox/activated/LateInitialize()
. = ..()
set_state(1)
/obj/structure/machinery/power/breakerbox/attack_ai(mob/user)
if(!ai_can_interact(user))
return
if(update_locked)
to_chat(user, SPAN_BAD("System locked. Please try again later."))
return
if(busy)
to_chat(user, SPAN_BAD("System is busy. Please wait until current operation is finished before changing power settings."))
return
busy = 1
to_chat(user, SPAN_GOOD("Updating power settings..."))
if(do_after(user, 50))
set_state(!on)
to_chat(user, SPAN_GOOD("Update Completed. New setting:[on ? "on": "off"]"))
update_locked = 1
addtimer(CALLBACK(src, PROC_REF(reset_locked)), 600)
busy = 0
/obj/structure/machinery/power/breakerbox/proc/reset_locked()
update_locked = 0
/obj/structure/machinery/power/breakerbox/attack_hand(mob/user)
if(update_locked)
to_chat(user, SPAN_BAD("System locked. Please try again later."))
return
if(busy)
to_chat(user, SPAN_BAD("System is busy. Please wait until current operation is finished before changing power settings."))
return
busy = 1
for(var/mob/O in viewers(user))
O.show_message(SPAN_WARNING("[user] started reprogramming [src]!"), 1)
if(do_after(user, 50))
set_state(!on)
user.visible_message(SPAN_NOTICE("[user.name] [on ? "enabled" : "disabled"] the breaker box!"), \
SPAN_NOTICE("You [on ? "enabled" : "disabled"] the breaker box!"))
update_locked = 1
addtimer(CALLBACK(src, PROC_REF(reset_locked)), 600)
busy = 0
/obj/structure/machinery/power/breakerbox/attackby(obj/item/attacking_item, mob/user)
if(attacking_item.tool_behaviour == TOOL_MULTITOOL)
var/newtag = input(user, "Enter new RCON tag. Use \"NO_TAG\" to disable RCON or leave empty to cancel.", "SMES RCON system") as text
if(newtag)
RCon_tag = newtag
to_chat(user, SPAN_NOTICE("You changed the RCON tag to: [newtag]"))
/obj/structure/machinery/power/breakerbox/proc/set_state(var/state)
on = state
update_icon()
if(on)
var/list/connection_dirs = list()
for(var/direction in directions)
for(var/obj/structure/cable/C in get_step(src,direction))
if(C.d1 == turn(direction, 180) || C.d2 == turn(direction, 180))
connection_dirs += direction
break
for(var/direction in connection_dirs)
var/obj/structure/cable/C = new/obj/structure/cable(src.loc)
C.d1 = 0
C.d2 = direction
C.icon_state = "[C.d1]-[C.d2]"
C.breaker_box = src
var/datum/powernet/PN = new()
PN.add_cable(C)
C.mergeConnectedNetworks(C.d2)
C.mergeConnectedNetworksOnTurf()
if(C.d2 & (C.d2 - 1))// if the cable is layed diagonally, check the others 2 possible directions
C.mergeDiagonalsNetworks(C.d2)
else
for(var/obj/structure/cable/C in src.loc)
qdel(C)
// Used by RCON to toggle the breaker box.
/obj/structure/machinery/power/breakerbox/proc/auto_toggle()
if(!update_locked)
set_state(!on)
update_locked = 1
addtimer(CALLBACK(src, PROC_REF(reset_locked)), 600)
/obj/structure/machinery/power/breakerbox/activated
icon_state = "bbox_on"