Files
Aurora.3/code/game/objects/structures/machinery/cable_layer.dm
T
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

124 lines
3.6 KiB
Plaintext

/obj/structure/machinery/cablelayer
name = "automatic cable layer"
icon = 'icons/obj/cable_layer.dmi'
icon_state = "cable_layer"
density = TRUE
var/obj/structure/cable/last_piece
var/obj/item/stack/cable_coil/cable
var/max_cable = 100
var/on = FALSE
/obj/structure/machinery/cablelayer/feedback_hints(mob/user, distance, is_adjacent)
. += ..()
. += SPAN_NOTICE("\The [src]'s cable reel has [cable.amount] length\s left.")
/obj/structure/machinery/cablelayer/Initialize()
. = ..()
cable = new(src)
cable.amount = max_cable
/obj/structure/machinery/cablelayer/Move(new_turf,M_Dir)
. = ..()
if(on)
layCable(new_turf,M_Dir)
/obj/structure/machinery/cablelayer/attack_hand(mob/user)
if(!cable && !on)
to_chat(user, SPAN_WARNING("\The [src] doesn't have any cable loaded."))
return
on = !on
user.visible_message("\The [user] [!on ? "de" : ""]activates \the [src].", SPAN_NOTICE("You switch \the [src] [on ? "on" : "off"]."))
return
/obj/structure/machinery/cablelayer/attackby(obj/item/attacking_item, mob/user)
if(attacking_item.tool_behaviour == TOOL_CABLECOIL)
var/result = load_cable(attacking_item)
if(!result)
to_chat(user, SPAN_WARNING("\The [src]'s cable reel is full."))
else
to_chat(user, SPAN_NOTICE("You load [result] lengths of cable into \the [src]."))
return TRUE
if(attacking_item.tool_behaviour == TOOL_WIRECUTTER)
if(cable && cable.amount)
var/m = round(input(usr,"Please specify the length of cable to cut.", "Cut Cable",min(cable.amount,30)) as num, 1)
m = min(m, cable.amount)
m = min(m, 30)
if(m)
playsound(loc, 'sound/items/Wirecutter.ogg', 50, 1)
var/cable_color = use_cable(m)
var/obj/item/stack/cable_coil/CC = new(get_turf(src), m, cable_color)
user.put_in_hands(CC)
else
to_chat(user, SPAN_WARNING("There's no more cable on the reel."))
return TRUE
if(attacking_item.tool_behaviour == TOOL_MULTITOOL)
if(!cable)
to_chat(user, SPAN_WARNING("\The [src] doesn't have any cable loaded!"))
return TRUE
return cable.attackby(attacking_item, user)
/obj/structure/machinery/cablelayer/proc/load_cable(var/obj/item/stack/cable_coil/CC)
if(istype(CC) && CC.amount)
var/cur_amount = cable? cable.amount : 0
var/to_load = max(max_cable - cur_amount,0)
if(to_load)
to_load = min(CC.amount, to_load)
if(!cable)
cable = new(src, 0, CC.color)
cable.amount = to_load
CC.use(to_load)
return to_load
else
return FALSE
/obj/structure/machinery/cablelayer/proc/use_cable(amount)
if(!cable || cable.amount < 1)
on = FALSE
reset()
playsound(loc, 'sound/machines/buzz-sigh.ogg', 50, TRUE)
visible_message(SPAN_WARNING("A red light flashes on \the [src]."))
return
var/cable_color = cable.color
cable.use(amount)
if(QDELETED(cable))
cable = null
return cable_color
/obj/structure/machinery/cablelayer/proc/reset()
last_piece = null
/obj/structure/machinery/cablelayer/proc/layCable(var/turf/new_turf,var/M_Dir)
if(!istype(new_turf))
return reset()
if(!new_turf.is_plating())
return reset()
var/fdirn = turn(M_Dir,180)
for(var/obj/structure/cable/LC in new_turf) // check to make sure there's not a cable there already
if(LC.d1 == fdirn || LC.d2 == fdirn)
return reset()
var/cable_color = use_cable(1)
if(!cable_color)
return reset()
var/obj/structure/cable/NC = new(new_turf)
NC.cableColor(cable_color)
NC.d1 = 0
NC.d2 = fdirn
NC.update_icon()
var/datum/powernet/PN
if(last_piece && last_piece.d2 != M_Dir)
last_piece.d1 = min(last_piece.d2, M_Dir)
last_piece.d2 = max(last_piece.d2, M_Dir)
last_piece.update_icon()
PN = last_piece.powernet
if(!PN)
PN = new()
PN.add_cable(NC)
NC.mergeConnectedNetworks(NC.d2)
last_piece = NC
return TRUE