diff --git a/code/game/machinery/computer/buildandrepair.dm b/code/game/machinery/computer/buildandrepair.dm
index 00ba621550..47343ea58f 100644
--- a/code/game/machinery/computer/buildandrepair.dm
+++ b/code/game/machinery/computer/buildandrepair.dm
@@ -3,7 +3,7 @@
icon_state = "0"
state = 0
-/obj/structure/frame/computer/attackby(obj/item/P, mob/user, params)
+/obj/structure/frame/computer/attackby(obj/item/P, mob/living/user, params)
add_fingerprint(user)
switch(state)
if(0)
@@ -11,7 +11,7 @@
to_chat(user, "You start wrenching the frame into place...")
if(P.use_tool(src, user, 20, volume=50))
to_chat(user, "You wrench the frame into place.")
- setAnchored(TRUE)
+ set_anchored(TRUE)
state = 1
return
if(P.tool_behaviour == TOOL_WELDER)
@@ -19,7 +19,7 @@
return
to_chat(user, "You start deconstructing the frame...")
- if(P.use_tool(src, user, 20, volume=50) && state == 0)
+ if(P.use_tool(src, user, 20, volume=50))
to_chat(user, "You deconstruct the frame.")
var/obj/item/stack/sheet/metal/M = new (drop_location(), 5)
M.add_fingerprint(user)
@@ -28,15 +28,15 @@
if(1)
if(P.tool_behaviour == TOOL_WRENCH)
to_chat(user, "You start to unfasten the frame...")
- if(P.use_tool(src, user, 20, volume=50) && state == 1)
+ if(P.use_tool(src, user, 20, volume=50))
to_chat(user, "You unfasten the frame.")
- setAnchored(FALSE)
+ set_anchored(FALSE)
state = 0
return
if(istype(P, /obj/item/circuitboard/computer) && !circuit)
if(!user.transferItemToLoc(P, src))
return
- playsound(src, 'sound/items/deconstruct.ogg', 50, 1)
+ playsound(src, 'sound/items/deconstruct.ogg', 50, TRUE)
to_chat(user, "You place [P] inside the frame.")
icon_state = "1"
circuit = P
@@ -71,8 +71,10 @@
if(istype(P, /obj/item/stack/cable_coil))
if(!P.tool_start_check(user, amount=5))
return
+ if(state != 2)
+ return
to_chat(user, "You start adding cables to the frame...")
- if(P.use_tool(src, user, 20, 5, 50, CALLBACK(src, .proc/check_state, 2)))
+ if(P.use_tool(src, user, 20, volume=50, amount=5))
to_chat(user, "You add cables to the frame.")
state = 3
icon_state = "3"
@@ -90,9 +92,11 @@
if(istype(P, /obj/item/stack/sheet/glass))
if(!P.tool_start_check(user, amount=2))
return
- playsound(src, 'sound/items/deconstruct.ogg', 50, 1)
+ if(state != 3)
+ return
+ playsound(src, 'sound/items/deconstruct.ogg', 50, TRUE)
to_chat(user, "You start to put in the glass panel...")
- if(P.use_tool(src, user, 20, 2, 0, CALLBACK(src, .proc/check_state, 3)))
+ if(P.use_tool(src, user, 20, amount=2))
to_chat(user, "You put in the glass panel.")
state = 4
src.icon_state = "4"
@@ -109,14 +113,51 @@
if(P.tool_behaviour == TOOL_SCREWDRIVER)
P.play_tool_sound(src)
to_chat(user, "You connect the monitor.")
- var/obj/B = new circuit.build_path (loc, circuit)
- B.setDir(dir)
- transfer_fingerprints_to(B)
+
+ var/obj/machinery/new_machine = new circuit.build_path(loc)
+ new_machine.setDir(dir)
+ transfer_fingerprints_to(new_machine)
+
+ if(istype(new_machine, /obj/machinery/computer))
+ var/obj/machinery/computer/new_computer = new_machine
+
+ // Machines will init with a set of default components.
+ // Triggering handle_atom_del will make the machine realise it has lost a component_parts and then deconstruct.
+ // Move to nullspace so we don't trigger handle_atom_del, then qdel.
+ // Finally, replace new machine's parts with this frame's parts.
+ if(new_computer.circuit)
+ // Move to nullspace and delete.
+ new_computer.circuit.moveToNullspace()
+ QDEL_NULL(new_computer.circuit)
+ for(var/old_part in new_computer.component_parts)
+ var/atom/movable/movable_part = old_part
+ // Move to nullspace and delete.
+ movable_part.moveToNullspace()
+ qdel(movable_part)
+
+ // Set anchor state and move the frame's parts over to the new machine.
+ // Then refresh parts and call on_construction().
+ new_computer.set_anchored(anchored)
+ new_computer.component_parts = list()
+
+ circuit.forceMove(new_computer)
+ new_computer.component_parts += circuit
+ new_computer.circuit = circuit
+
+ for(var/new_part in src)
+ var/atom/movable/movable_part = new_part
+ movable_part.forceMove(new_computer)
+ new_computer.component_parts += movable_part
+
+ new_computer.RefreshParts()
+ new_computer.on_construction()
+
qdel(src)
return
if(user.a_intent == INTENT_HARM)
return ..()
+
/obj/structure/frame/computer/deconstruct(disassembled = TRUE)
if(!(flags_1 & NODECONSTRUCT_1))
if(state == 4)
@@ -127,13 +168,12 @@
..()
/obj/structure/frame/computer/AltClick(mob/user)
- . = ..()
- if(!isliving(user) || !user.canUseTopic(src, BE_CLOSE, ismonkey(user)))
+ ..()
+ if(!user.canUseTopic(src, BE_CLOSE, TRUE, FALSE))
return
if(anchored)
to_chat(usr, "You must unwrench [src] before rotating it!")
- return TRUE
+ return
setDir(turn(dir, -90))
- return TRUE
diff --git a/code/game/machinery/constructable_frame.dm b/code/game/machinery/constructable_frame.dm
index bdf7a80c96..c2855b4a46 100644
--- a/code/game/machinery/constructable_frame.dm
+++ b/code/game/machinery/constructable_frame.dm
@@ -208,6 +208,8 @@
new_machine.component_parts = list()
circuit.forceMove(new_machine)
+ // TODO: make sleepers not shit out parts PROPERLY THIS TIME.
+ new_machine.circuit.moveToNullspace()
new_machine.component_parts += circuit
new_machine.circuit = circuit