diff --git a/code/game/objects/items/RPD.dm b/code/game/objects/items/RPD.dm
index 98beede2fb8..f584886a30c 100644
--- a/code/game/objects/items/RPD.dm
+++ b/code/game/objects/items/RPD.dm
@@ -378,35 +378,39 @@ GLOBAL_LIST_INIT(transit_tube_recipes, list(
if(!user.IsAdvancedToolUser() || istype(A, /turf/open/space/transit))
return ..()
+ var/atom/attack_target = A
+
//So that changing the menu settings doesn't affect the pipes already being built.
var/queued_p_type = recipe.id
var/queued_p_dir = p_dir
var/queued_p_flipped = p_flipped
- //Unwrench pipe before we build one over/paint it.
- if((mode & DESTROY_MODE) && (upgrade_flags & RPD_UPGRADE_UNWRENCH) && istype(A, /obj/machinery/atmospherics))
- A = A.wrench_act(user, src)
+ //Unwrench pipe before we build one over/paint it, but only if we're not already running a do_after on it already to prevent a potential runtime.
+ if((mode & DESTROY_MODE) && (upgrade_flags & RPD_UPGRADE_UNWRENCH) && istype(attack_target, /obj/machinery/atmospherics) && !(attack_target in user.do_afters))
+ attack_target = attack_target.wrench_act(user, src)
+ if(!isatom(attack_target))
+ CRASH("When attempting to call [A.type].wrench_act(), received the following non-atom return value: [attack_target]")
//make sure what we're clicking is valid for the current category
var/static/list/make_pipe_whitelist
if(!make_pipe_whitelist)
make_pipe_whitelist = typecacheof(list(/obj/structure/lattice, /obj/structure/girder, /obj/item/pipe, /obj/structure/window, /obj/structure/grille))
- if(istype(A, /obj/machinery/atmospherics) && (mode & BUILD_MODE && !(mode & PAINT_MODE))) //Reduces pixelhunt when coloring is off.
- A = get_turf(A)
- var/can_make_pipe = (isturf(A) || is_type_in_typecache(A, make_pipe_whitelist))
+ if(istype(attack_target, /obj/machinery/atmospherics) && (mode & BUILD_MODE && !(mode & PAINT_MODE))) //Reduces pixelhunt when coloring is off.
+ attack_target = get_turf(attack_target)
+ var/can_make_pipe = (isturf(attack_target) || is_type_in_typecache(attack_target, make_pipe_whitelist))
. = TRUE
- if((mode & DESTROY_MODE) && istype(A, /obj/item/pipe) || istype(A, /obj/structure/disposalconstruct) || istype(A, /obj/structure/c_transit_tube) || istype(A, /obj/structure/c_transit_tube_pod) || istype(A, /obj/item/pipe_meter))
+ if((mode & DESTROY_MODE) && istype(attack_target, /obj/item/pipe) || istype(attack_target, /obj/structure/disposalconstruct) || istype(attack_target, /obj/structure/c_transit_tube) || istype(attack_target, /obj/structure/c_transit_tube_pod) || istype(attack_target, /obj/item/pipe_meter))
to_chat(user, "You start destroying a pipe...")
playsound(get_turf(src), 'sound/machines/click.ogg', 50, TRUE)
- if(do_after(user, destroy_speed, target = A))
+ if(do_after(user, destroy_speed, target = attack_target))
activate()
- qdel(A)
+ qdel(attack_target)
return
if((mode & PAINT_MODE))
- var/obj/machinery/atmospherics/M = A
+ var/obj/machinery/atmospherics/M = attack_target
if(istype(M) && M.paintable)
to_chat(user, "You start painting \the [M] [paint_color]...")
playsound(get_turf(src), 'sound/machines/click.ogg', 50, TRUE)
@@ -414,7 +418,7 @@ GLOBAL_LIST_INIT(transit_tube_recipes, list(
M.paint(GLOB.pipe_paint_colors[paint_color]) //paint the pipe
user.visible_message("[user] paints \the [M] [paint_color].","You paint \the [M] [paint_color].")
return
- var/obj/item/pipe/I = A
+ var/obj/item/pipe/I = attack_target
if(istype(I) && I.paintable)
to_chat(user, "You start painting \the [I] [paint_color]...")
playsound(get_turf(src), 'sound/machines/click.ogg', 50, TRUE)
@@ -431,9 +435,9 @@ GLOBAL_LIST_INIT(transit_tube_recipes, list(
playsound(get_turf(src), 'sound/machines/click.ogg', 50, TRUE)
if (recipe.type == /datum/pipe_info/meter)
to_chat(user, "You start building a meter...")
- if(do_after(user, atmos_build_speed, target = A))
+ if(do_after(user, atmos_build_speed, target = attack_target))
activate()
- var/obj/item/pipe_meter/PM = new /obj/item/pipe_meter(get_turf(A))
+ var/obj/item/pipe_meter/PM = new /obj/item/pipe_meter(get_turf(attack_target))
PM.setAttachLayer(piping_layer)
if(mode & WRENCH_MODE)
PM.wrench_act(user, src)
@@ -442,14 +446,14 @@ GLOBAL_LIST_INIT(transit_tube_recipes, list(
to_chat(user, "You can't build this object on the layer...")
return ..()
to_chat(user, "You start building a pipe...")
- if(do_after(user, atmos_build_speed, target = A))
+ if(do_after(user, atmos_build_speed, target = attack_target))
if(recipe.all_layers == FALSE && (piping_layer == 1 || piping_layer == 5))//double check to stop cheaters (and to not waste time waiting for something that can't be placed)
to_chat(user, "You can't build this object on the layer...")
return ..()
activate()
var/obj/machinery/atmospherics/path = queued_p_type
var/pipe_item_type = initial(path.construction_type) || /obj/item/pipe
- var/obj/item/pipe/P = new pipe_item_type(get_turf(A), queued_p_type, queued_p_dir)
+ var/obj/item/pipe/P = new pipe_item_type(get_turf(attack_target), queued_p_type, queued_p_dir)
if(queued_p_flipped && istype(P, /obj/item/pipe/trinary/flippable))
var/obj/item/pipe/trinary/flippable/F = P
@@ -466,14 +470,14 @@ GLOBAL_LIST_INIT(transit_tube_recipes, list(
if(DISPOSALS_CATEGORY) //Making disposals pipes
if(!can_make_pipe)
return ..()
- A = get_turf(A)
- if(isclosedturf(A))
+ attack_target = get_turf(attack_target)
+ if(isclosedturf(attack_target))
to_chat(user, "[src]'s error light flickers; there's something in the way!")
return
to_chat(user, "You start building a disposals pipe...")
playsound(get_turf(src), 'sound/machines/click.ogg', 50, TRUE)
- if(do_after(user, disposal_build_speed, target = A))
- var/obj/structure/disposalconstruct/C = new (A, queued_p_type, queued_p_dir, queued_p_flipped)
+ if(do_after(user, disposal_build_speed, target = attack_target))
+ var/obj/structure/disposalconstruct/C = new (attack_target, queued_p_type, queued_p_dir, queued_p_flipped)
if(!C.can_place())
to_chat(user, "There's not enough room to build that here!")
@@ -491,22 +495,22 @@ GLOBAL_LIST_INIT(transit_tube_recipes, list(
if(TRANSIT_CATEGORY) //Making transit tubes
if(!can_make_pipe)
return ..()
- A = get_turf(A)
- if(isclosedturf(A))
+ attack_target = get_turf(attack_target)
+ if(isclosedturf(attack_target))
to_chat(user, "[src]'s error light flickers; there's something in the way!")
return
to_chat(user, "You start building a transit tube...")
playsound(get_turf(src), 'sound/machines/click.ogg', 50, TRUE)
- if(do_after(user, transit_build_speed, target = A))
+ if(do_after(user, transit_build_speed, target = attack_target))
activate()
if(queued_p_type == /obj/structure/c_transit_tube_pod)
- var/obj/structure/c_transit_tube_pod/pod = new /obj/structure/c_transit_tube_pod(A)
+ var/obj/structure/c_transit_tube_pod/pod = new /obj/structure/c_transit_tube_pod(attack_target)
pod.add_fingerprint(usr)
if(mode & WRENCH_MODE)
pod.wrench_act(user, src)
else
- var/obj/structure/c_transit_tube/tube = new queued_p_type(A)
+ var/obj/structure/c_transit_tube/tube = new queued_p_type(attack_target)
tube.setDir(queued_p_dir)
if(queued_p_flipped)