From 150f6f432871aff29ae7f97f9c305538e7436a92 Mon Sep 17 00:00:00 2001
From: LetterN <24603524+LetterN@users.noreply.github.com>
Date: Fri, 19 Mar 2021 20:11:26 +0800
Subject: [PATCH] cbt
---
code/game/machinery/constructable_frame.dm | 104 +++++++++++-------
.../circuitboards/computer_circuitboards.dm | 3 +
2 files changed, 65 insertions(+), 42 deletions(-)
diff --git a/code/game/machinery/constructable_frame.dm b/code/game/machinery/constructable_frame.dm
index d5bbcb0adc..bdf7a80c96 100644
--- a/code/game/machinery/constructable_frame.dm
+++ b/code/game/machinery/constructable_frame.dm
@@ -36,7 +36,7 @@
/obj/structure/frame/machine/examine(user)
. = ..()
if(state == 3 && req_components && req_component_names)
- var/hasContent = 0
+ var/hasContent = FALSE
var/requires = "It requires"
for(var/i = 1 to req_components.len)
@@ -46,10 +46,10 @@
continue
var/use_and = i == req_components.len
requires += "[(hasContent ? (use_and ? ", and" : ",") : "")] [amt] [amt == 1 ? req_component_names[tname] : "[req_component_names[tname]]\s"]"
- hasContent = 1
+ hasContent = TRUE
if(hasContent)
- . += requires + "."
+ . += "[requires]."
else
. += "It does not require any more components."
@@ -76,7 +76,7 @@
amt += req_components[path]
return amt
-/obj/structure/frame/machine/attackby(obj/item/P, mob/user, params)
+/obj/structure/frame/machine/attackby(obj/item/P, mob/living/user, params)
switch(state)
if(1)
if(istype(P, /obj/item/circuitboard/machine))
@@ -88,6 +88,7 @@
if(istype(P, /obj/item/stack/cable_coil))
if(!P.tool_start_check(user, amount=5))
return
+
to_chat(user, "You start to add cables to the frame...")
if(P.use_tool(src, user, 20, volume=50, amount=5, extra_checks = CALLBACK(src, .proc/check_state, 1)))
to_chat(user, "You add cables to the frame.")
@@ -97,39 +98,41 @@
return
if(P.tool_behaviour == TOOL_SCREWDRIVER && !anchored)
user.visible_message("[user] disassembles the frame.", \
- "You start to disassemble the frame...", "You hear banging and clanking.")
+ "You start to disassemble the frame...", "You hear banging and clanking.")
if(P.use_tool(src, user, 40, volume=50, extra_checks = CALLBACK(src, .proc/check_state, 1)))
- to_chat(user, "You disassemble the frame.")
- var/obj/item/stack/sheet/metal/M = new (loc, 5)
- M.add_fingerprint(user)
- qdel(src)
+ if(state == 1)
+ to_chat(user, "You disassemble the frame.")
+ var/obj/item/stack/sheet/metal/M = new (loc, 5)
+ M.add_fingerprint(user)
+ qdel(src)
return
if(P.tool_behaviour == TOOL_WRENCH)
- to_chat(user, "You start [anchored ? "un" : ""]securing [name]...")
+ to_chat(user, "You start [anchored ? "un" : ""]securing [src]...")
if(P.use_tool(src, user, 40, volume=75, extra_checks = CALLBACK(src, .proc/check_state, 1)))
- to_chat(user, "You [anchored ? "un" : ""]secure [name].")
- setAnchored(!anchored)
+ if(state == 1)
+ to_chat(user, "You [anchored ? "un" : ""]secure [src].")
+ set_anchored(!anchored)
return
if(2)
if(P.tool_behaviour == TOOL_WRENCH)
- to_chat(user, "You start [anchored ? "un" : ""]securing [name]...")
+ to_chat(user, "You start [anchored ? "un" : ""]securing [src]...")
if(P.use_tool(src, user, 40, volume=75, extra_checks = CALLBACK(src, .proc/check_state, 2)))
- to_chat(user, "You [anchored ? "un" : ""]secure [name].")
- setAnchored(!anchored)
+ to_chat(user, "You [anchored ? "un" : ""]secure [src].")
+ set_anchored(!anchored)
return
if(istype(P, /obj/item/circuitboard/machine))
var/obj/item/circuitboard/machine/B = P
if(!B.build_path)
- to_chat(user, "This circuitboard seems to be broken.")
+ to_chat(user, "This circuitboard seems to be broken.")
return
if(!anchored && B.needs_anchored)
to_chat(user, "The frame needs to be secured first!")
return
if(!user.transferItemToLoc(B, src))
return
- playsound(src.loc, 'sound/items/deconstruct.ogg', 50, 1)
+ playsound(src.loc, 'sound/items/deconstruct.ogg', 50, TRUE)
to_chat(user, "You add the circuit board to the frame.")
circuit = B
icon_state = "box_2"
@@ -171,34 +174,49 @@
return
if(P.tool_behaviour == TOOL_WRENCH && !circuit.needs_anchored)
- to_chat(user, "You start [anchored ? "un" : ""]securing [name]...")
+ to_chat(user, "You start [anchored ? "un" : ""]securing [src]...")
if(P.use_tool(src, user, 40, volume=75, extra_checks = CALLBACK(src, .proc/check_state, 3)))
- to_chat(user, "You [anchored ? "un" : ""]secure [name].")
- setAnchored(!anchored)
+ to_chat(user, "You [anchored ? "un" : ""]secure [src].")
+ set_anchored(!anchored)
return
if(P.tool_behaviour == TOOL_SCREWDRIVER)
- var/component_check = 1
+ var/component_check = TRUE
for(var/R in req_components)
if(req_components[R] > 0)
- component_check = 0
+ component_check = FALSE
break
if(component_check)
P.play_tool_sound(src)
var/obj/machinery/new_machine = new circuit.build_path(loc)
- if(new_machine.circuit)
- QDEL_NULL(new_machine.circuit)
- new_machine.circuit = circuit
- new_machine.setAnchored(anchored)
- new_machine.on_construction()
- for(var/obj/O in new_machine.component_parts)
- qdel(O)
- new_machine.component_parts = list()
- for(var/obj/O in src)
- O.moveToNullspace()
- new_machine.component_parts += O
- circuit.moveToNullspace()
- new_machine.RefreshParts()
+ if(istype(new_machine))
+ // Machines will init with a set of default components. Move to nullspace so we don't trigger handle_atom_del, then qdel.
+ // Finally, replace with this frame's parts.
+ if(new_machine.circuit)
+ // Move to nullspace and delete.
+ new_machine.circuit.moveToNullspace()
+ QDEL_NULL(new_machine.circuit)
+ for(var/obj/old_part in new_machine.component_parts)
+ // Move to nullspace and delete.
+ old_part.moveToNullspace()
+ qdel(old_part)
+
+ // Set anchor state and move the frame's parts over to the new machine.
+ // Then refresh parts and call on_construction().
+
+ new_machine.set_anchored(anchored)
+ new_machine.component_parts = list()
+
+ circuit.forceMove(new_machine)
+ new_machine.component_parts += circuit
+ new_machine.circuit = circuit
+
+ for(var/obj/new_part in src)
+ new_part.forceMove(new_machine)
+ new_machine.component_parts += new_part
+ new_machine.RefreshParts()
+
+ new_machine.on_construction()
qdel(src)
return
@@ -232,12 +250,15 @@
for(var/obj/item/part in added_components)
if(istype(part,/obj/item/stack))
- var/obj/item/stack/S = part
- var/obj/item/stack/NS = locate(S.merge_type) in components //find a stack to merge with
- if(NS)
- S.merge(NS)
+ var/obj/item/stack/incoming_stack = part
+ for(var/obj/item/stack/merge_stack in components)
+ if(incoming_stack.can_merge(merge_stack))
+ incoming_stack.merge(merge_stack)
+ if(QDELETED(incoming_stack))
+ break
if(!QDELETED(part)) //If we're a stack and we merged we might not exist anymore
components += part
+ part.forceMove(src)
to_chat(user, "[part.name] applied.")
if(added_components.len)
replacer.play_rped_sound()
@@ -267,9 +288,9 @@
to_chat(user, "You add [P] to [src].")
components += P
req_components[I]--
- return 1
+ return TRUE
to_chat(user, "You cannot add that to the machine!")
- return 0
+ return FALSE
if(user.a_intent == INTENT_HARM)
return ..()
@@ -280,5 +301,4 @@
for(var/X in components)
var/obj/item/I = X
I.forceMove(loc)
-
..()
diff --git a/code/game/objects/items/circuitboards/computer_circuitboards.dm b/code/game/objects/items/circuitboards/computer_circuitboards.dm
index 01bed631fa..afab49ac76 100644
--- a/code/game/objects/items/circuitboards/computer_circuitboards.dm
+++ b/code/game/objects/items/circuitboards/computer_circuitboards.dm
@@ -549,6 +549,7 @@
contraband = TRUE
obj_flags |= EMAGGED
to_chat(user, "You adjust [src]'s routing and receiver spectrum, unlocking special supplies and contraband.")
+ return TRUE
/obj/item/circuitboard/computer/cargo/configure_machine(obj/machinery/computer/cargo/machine)
if(!istype(machine))
@@ -565,10 +566,12 @@
build_path = /obj/machinery/computer/cargo/express
/obj/item/circuitboard/computer/cargo/express/emag_act(mob/living/user)
+ . = ..()
if(!(obj_flags & EMAGGED))
contraband = TRUE
obj_flags |= EMAGGED
to_chat(user, "You change the routing protocols, allowing the Drop Pod to land anywhere on the station.")
+ return TRUE
/obj/item/circuitboard/computer/cargo/express/multitool_act(mob/living/user)
if (!(obj_flags & EMAGGED))