diff --git a/code/modules/power/smes.dm b/code/modules/power/smes.dm
index 7ebc4f4471a..f5e7dcf25fc 100644
--- a/code/modules/power/smes.dm
+++ b/code/modules/power/smes.dm
@@ -158,9 +158,44 @@
to_chat(user, "You need more wires.")
return
- //build the terminal and link it to the network
- make_terminal(user)
- terminal.connect_to_network()
+ if(user.loc == loc)
+ to_chat(user, "You must not be on the same tile as the [src].")
+ return
+
+ //Direction the terminal will face to
+ var/tempDir = get_dir(user, src)
+ switch(tempDir)
+ if(NORTHEAST, SOUTHEAST)
+ tempDir = EAST
+ if(NORTHWEST, SOUTHWEST)
+ tempDir = WEST
+ var/turf/tempLoc = get_step(src, reverse_direction(tempDir))
+ if(istype(tempLoc, /turf/space))
+ to_chat(user, "You can't build a terminal on space.")
+ return
+ else if(istype(tempLoc))
+ if(tempLoc.intact)
+ to_chat(user, "You must remove the floor plating first.")
+ return
+
+ to_chat(user, "You start adding cable to the [src].")
+ playsound(src.loc, C.usesound, 50, 1)
+
+ if(do_after(user, 50, target = src))
+ if(!terminal && panel_open)
+ T = get_turf(user)
+ var/obj/structure/cable/N = T.get_cable_node() //get the connecting node cable, if there's one
+ if(prob(50) && electrocute_mob(usr, N, N, 1, TRUE)) //animate the electrocution if uncautious and unlucky
+ do_sparks(5, 1, src)
+ return
+
+ C.use(10) // make sure the cable gets used up
+ user.visible_message(\
+ "[user.name] adds the cables and connects the power terminal.",\
+ "You add the cables and connect the power terminal.")
+
+ make_terminal(user, tempDir, tempLoc)
+ terminal.connect_to_network()
return
//disassembling the terminal
@@ -174,18 +209,19 @@
playsound(src.loc, I.usesound, 50, 1)
if(do_after(user, 50 * I.toolspeed, target = src))
- if(prob(50) && electrocute_mob(usr, terminal.powernet, terminal, 1, TRUE)) //animate the electrocution if uncautious and unlucky
- do_sparks(5, 1, src)
- return
+ if(terminal && panel_open)
+ if(prob(50) && electrocute_mob(usr, terminal.powernet, terminal, 1, TRUE)) //animate the electrocution if uncautious and unlucky
+ do_sparks(5, 1, src)
+ return
- //give the wires back and delete the terminal
- new /obj/item/stack/cable_coil(T,10)
- user.visible_message(\
- "[user.name] cuts the cables and dismantles the power terminal.",\
- "You cut the cables and dismantle the power terminal.")
- inputting = 0 //stop inputting, since we have don't have a terminal anymore
- qdel(terminal)
- return
+ //give the wires back and delete the terminal
+ new /obj/item/stack/cable_coil(T,10)
+ user.visible_message(\
+ "[user.name] cuts the cables and dismantles the power terminal.",\
+ "You cut the cables and dismantle the power terminal.")
+ inputting = 0 //stop inputting, since we have don't have a terminal anymore
+ qdel(terminal)
+ return
//crowbarring it !
default_deconstruction_crowbar(I)
@@ -197,6 +233,13 @@
return 1
return 0
+/obj/machinery/power/smes/proc/make_terminal(user, tempDir, tempLoc)
+ // create a terminal object at the same position as original turf loc
+ // wires will attach to this
+ terminal = new /obj/machinery/power/terminal(tempLoc)
+ terminal.dir = tempDir
+ terminal.master = src
+
/obj/machinery/power/smes/Destroy()
if(SSticker && SSticker.current_state == GAME_STATE_PLAYING)
var/area/area = get_area(src)
@@ -299,45 +342,6 @@
update_icon()
return
-//Will return 1 on failure
-/obj/machinery/power/smes/proc/make_terminal(const/mob/user)
- if(user.loc == loc)
- to_chat(user, "You must not be on the same tile as the [src].")
- return 1
-
- //Direction the terminal will face to
- var/tempDir = get_dir(user, src)
- switch(tempDir)
- if(NORTHEAST, SOUTHEAST)
- tempDir = EAST
- if(NORTHWEST, SOUTHWEST)
- tempDir = WEST
- var/turf/tempLoc = get_step(src, reverse_direction(tempDir))
- if(istype(tempLoc, /turf/space))
- to_chat(user, "You can't build a terminal on space.")
- return 1
- else if(istype(tempLoc))
- if(tempLoc.intact)
- to_chat(user, "You must remove the floor plating first.")
- return 1
- to_chat(user, "You start adding cable to the [src].")
- if(do_after(user, 50, target = src))
- var/turf/T = get_turf(user)
- var/obj/structure/cable/N = T.get_cable_node() //get the connecting node cable, if there's one
- if(prob(50) && electrocute_mob(usr, N, N, 1, TRUE)) //animate the electrocution if uncautious and unlucky
- do_sparks(5, 1, src)
- return
-
- user.visible_message(\
- "[user.name] adds the cables and connects the power terminal.",\
- "You add the cables and connect the power terminal.")
-
- terminal = new /obj/machinery/power/terminal(tempLoc)
- terminal.dir = tempDir
- terminal.master = src
- return 0
- return 1
-
/obj/machinery/power/smes/attack_ai(mob/user)
add_hiddenprint(user)
ui_interact(user)