diff --git a/code/modules/power/smes.dm b/code/modules/power/smes.dm
index 78c01b24636..2f0e57e313d 100644
--- a/code/modules/power/smes.dm
+++ b/code/modules/power/smes.dm
@@ -68,10 +68,12 @@
capacity = C / (15000) * 1e6
/obj/machinery/power/smes/attackby(obj/item/I, mob/user)
+ //opening using screwdriver
if(default_deconstruction_screwdriver(user, "[initial(icon_state)]-o", initial(icon_state), I))
update_icon()
return
+ //changing direction using wrench
if(default_change_direction_wrench(user, I))
terminal = null
var/turf/T = get_step(src, dir)
@@ -81,12 +83,6 @@
terminal.master = src
user << "Terminal found."
break
- if(!terminal)
- for(var/obj/structure/cable/C in T)
- if(C.d1 == turn(dir, 180) || C.d2 == turn(dir, 180))
- terminal = C
- user << "Cable found."
- break
if(!terminal)
user << "No power source found."
return
@@ -94,9 +90,83 @@
update_icon()
return
+ //exchanging parts using the RPE
if(exchange_parts(user, I))
return
+ //building and linking a terminal
+ if(istype(I, /obj/item/stack/cable_coil))
+ var/dir = get_dir(user,src)
+ if(dir & (dir-1))//we don't want diagonal click
+ return
+
+ if(terminal) //is there already a terminal ?
+ user << "This SMES already have a power terminal!"
+ return
+
+ if(!panel_open) //is the panel open ?
+ user << "You must open the maintenance panel first!"
+ return
+
+ var/turf/T = get_turf(user)
+ if (T.intact) //is the floor plating removed ?
+ user << "You must first remove the floor plating!"
+ return
+
+
+ var/obj/item/stack/cable_coil/C = I
+ if(C.amount < 10)
+ user << "You need more wires."
+ return
+
+ user << "You start building the power terminal..."
+ playsound(src.loc, 'sound/items/Deconstruct.ogg', 50, 1)
+
+ if(do_after(user, 20) && C.amount >= 10)
+ 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)) //animate the electrocution if uncautious and unlucky
+ var/datum/effect/effect/system/spark_spread/s = new /datum/effect/effect/system/spark_spread
+ s.set_up(5, 1, src)
+ s.start()
+ return
+
+ C.use(10)
+ user.visible_message(\
+ "[user.name] has build a power terminal!",\
+ "You build the power terminal.")
+
+ //build the terminal and link it to the network
+ make_terminal(T)
+ terminal.connect_to_network()
+ return
+
+ //disassembling the terminal
+ if(istype(I, /obj/item/weapon/wirecutters) && terminal && panel_open)
+ var/turf/T = get_turf(terminal)
+ if (T.intact) //is the floor plating removed ?
+ user << "You must first expose the power terminal!"
+ return
+
+ user << "You begin to dismantle the power terminal..."
+ playsound(src.loc, 'sound/items/Deconstruct.ogg', 50, 1)
+
+ if(do_after(user, 50))
+ if (prob(50) && electrocute_mob(usr, terminal.powernet, terminal)) //animate the electrocution if uncautious and unlucky
+ var/datum/effect/effect/system/spark_spread/s = new /datum/effect/effect/system/spark_spread
+ s.set_up(5, 1, src)
+ s.start()
+ 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)
/obj/machinery/power/smes/Destroy()
@@ -109,6 +179,13 @@
disconnect_terminal()
..()
+// create a terminal object pointing towards the SMES
+// wires will attach to this
+/obj/machinery/power/smes/proc/make_terminal(var/turf/T)
+ terminal = new/obj/machinery/power/terminal(T)
+ terminal.dir = get_dir(T,src)
+ terminal.master = src
+
/obj/machinery/power/smes/disconnect_terminal()
if(terminal)
terminal.master = null