//---------- shield capacitor
//pulls energy out of a power net and charges an adjacent generator
/obj/machinery/shield_capacitor
name = "shield capacitor"
desc = "Machine that charges a shield generator."
icon = 'icons/obj/machines/shielding.dmi'
icon_state = "capacitor"
obj_flags = OBJ_FLAG_ROTATABLE
var/active = FALSE
density = TRUE
var/stored_charge = 0 //not to be confused with power cell charge, this is in Joules
var/last_stored_charge = 0
var/time_since_fail = 100
var/max_charge = 8e6 //8 MJ
var/max_charge_rate = 400000 //400 kW
var/locked = FALSE
use_power = FALSE //doesn't use APC power
var/charge_rate = 100000 //100 kW
var/obj/machinery/shield_gen/owned_gen
req_one_access = list(access_captain, access_security, access_engine)
/obj/machinery/shield_capacitor/Initialize()
..()
return INITIALIZE_HINT_LATELOAD
/obj/machinery/shield_capacitor/LateInitialize()
for(var/obj/machinery/shield_gen/possible_gen in range(1, src))
if(get_dir(src, possible_gen) == dir)
possible_gen.owned_capacitor = src
break
/obj/machinery/shield_capacitor/emag_act(var/remaining_charges, var/mob/user)
if(prob(75))
locked = !locked
to_chat(user, "Controls are now [locked ? "locked." : "unlocked."]")
. = TRUE
updateDialog()
spark(src, 5, alldirs)
/obj/machinery/shield_capacitor/attackby(obj/item/W, mob/user)
if(istype(W, /obj/item/card/id))
if(allowed(user))
locked = !locked
to_chat(user, "Controls are now [locked ? "locked." : "unlocked."]")
updateDialog()
else
to_chat(user, SPAN_ALERT("Access denied."))
else if(W.iswrench())
anchored = !anchored
visible_message(SPAN_NOTICE("\The [src] has been [anchored ? "bolted to the floor" : "unbolted from the floor"] by \the [user]."))
if(anchored)
for(var/obj/machinery/shield_gen/gen in range(1, src))
if(get_dir(src, gen) == src.dir && !gen.owned_capacitor)
owned_gen = gen
owned_gen.owned_capacitor = src
owned_gen.updateDialog()
else
if(owned_gen && owned_gen.owned_capacitor == src)
owned_gen.owned_capacitor = null
owned_gen = null
else
..()
/obj/machinery/shield_capacitor/attack_hand(mob/user)
if(stat & (BROKEN))
return
interact(user)
/obj/machinery/shield_capacitor/interact(mob/user)
if ( !in_range(src, user) || (stat & (BROKEN)) )
if (!issilicon(user))
user.unset_machine()
user << browse(null, "window=shield_capacitor")
return
var/t = "Shield Capacitor Control Console
"
if(locked)
t += "Swipe your ID card to begin."
else
t += "This capacitor is: [active ? "Online" : "Offline" ] [active ? "\[Deactivate\]" : "\[Activate\]"]
"
t += "Capacitor Status: [time_since_fail > 2 ? "OK." : "Discharging!"]
"
t += "Stored Energy: [round(stored_charge/1000, 0.1)] kJ ([100 * round(stored_charge/max_charge, 0.1)]%)
"
t += "Charge Rate: \
\[----\] \
\[---\] \
\[--\] \
\[-\][charge_rate] W \
\[+\] \
\[++\] \
\[+++\] \
\[+++\]
"
t += "