Files
CHOMPStation2/code/modules/power/grid_checker.dm
Neerti 337ef499a1 Cleans Up WIP Event System + New Grid Check For It
Separates the 'count and assess everything' stuff to it's own datum, called the metric datum, which I plan to add on to in the future to make counting and metrics easier.
Makes decision process a bit more weight-based, will probably continue tweaking later.
Makes the admin debug UI have links to change settings easily.
Adds replacement for grid check event, which works similar to the old one, but is now based on a physical machine in the game world, that Engineering can hack to make the event end faster, if so desired.  Note that the machine is not mapped in, and won't be mapped in until the event system is ready for launch.
Adds grid_check variables to SMESes and APCs to make them stop doing work without draining the battery.
Grid checks in the new system are caused by a "power spike" which originates from the engine and will cause bad things, should no grid checker machine be connected to the power-net.  These power spikes occur when the GM decides that a grid check is a good event to have.
The grid checker can be built and deconstructed using the standard machine construction methods.
2016-10-05 21:40:07 -04:00

125 lines
4.0 KiB
Plaintext

/obj/machinery/power/grid_checker
name = "grid checker"
desc = "A machine that reacts to unstable conditions in the powernet, by safely shutting everything down. Probably better \
than the alternative."
icon_state = "gridchecker_on"
circuit = /obj/item/weapon/circuitboard/grid_checker
var/power_failing = FALSE // Turns to TRUE when the grid check event is fired by the Game Master, or perhaps a cheeky antag.
// Wire stuff below.
var/datum/wires/grid_checker/wires
var/wire_locked_out = FALSE
var/wire_allow_manual_1 = FALSE
var/wire_allow_manual_2 = FALSE
var/wire_allow_manual_3 = FALSE
var/opened = FALSE
/obj/machinery/power/grid_checker/New()
..()
connect_to_network()
update_icon()
wires = new(src)
component_parts = list()
component_parts += new /obj/item/weapon/stock_parts/capacitor(src)
component_parts += new /obj/item/weapon/stock_parts/capacitor(src)
component_parts += new /obj/item/weapon/stock_parts/capacitor(src)
component_parts += new /obj/item/stack/cable_coil(src, 10)
RefreshParts()
/obj/machinery/power/grid_checker/Destroy()
qdel(wires)
wires = null
..()
/obj/machinery/power/grid_checker/update_icon()
if(power_failing)
icon_state = "gridchecker_off"
set_light(2, 2, "#F86060")
else
icon_state = "gridchecker_on"
set_light(2, 2, "#A8B0F8")
/obj/machinery/power/grid_checker/attackby(obj/item/W, mob/user)
if(!user)
return
if(istype(W, /obj/item/weapon/screwdriver))
default_deconstruction_screwdriver(user, W)
opened = !opened
else if(istype(W, /obj/item/weapon/crowbar))
default_deconstruction_crowbar(user, W)
else if(istype(W, /obj/item/device/multitool) || istype(W, /obj/item/weapon/wirecutters) )
attack_hand(user)
/obj/machinery/power/grid_checker/attack_hand(mob/user)
if(!user)
return
add_fingerprint(user)
interact(user)
/obj/machinery/power/grid_checker/interact(mob/user)
if(!user)
return
if(opened)
wires.Interact(user)
return ui_interact(user)
/obj/machinery/power/grid_checker/proc/power_failure(var/announce = TRUE)
if(announce)
command_announcement.Announce("Abnormal activity detected in [station_name()]'s powernet. As a precautionary measure, \
the colony's power will be shut off for an indeterminate duration while the powernet monitor restarts automatically, or \
when Engineering can manually resolve the issue.",
"Critical Power Failure",
new_sound = 'sound/AI/poweroff.ogg')
power_failing = TRUE
if(powernet)
for(var/obj/machinery/power/terminal/T in powernet.nodes) // SMESes that are "downstream" of the powernet.
if(istype(T.master, /obj/machinery/power/apc))
var/obj/machinery/power/apc/A = T.master
if(A.is_critical)
continue
A.grid_check = TRUE
for(var/obj/machinery/power/smes/smes in powernet.nodes) // These are "upstream"
smes.grid_check = TRUE
/*
smes.last_charge = smes.charge
smes.last_output_attempt = smes.output_attempt
smes.last_input_attempt = smes.input_attempt
smes.charge = 0
smes.inputting(FALSE)
smes.outputting(FALSE)
smes.update_icon()
smes.power_change()
*/
update_icon()
spawn(rand(4 MINUTES, 10 MINUTES) )
if(power_failing) // Check to see if engineering didn't beat us to it.
end_power_failure(TRUE)
/obj/machinery/power/grid_checker/proc/end_power_failure(var/announce = TRUE)
if(announce)
command_announcement.Announce("Power has been restored to [station_name()]. We apologize for the inconvenience.",
"Power Systems Nominal",
new_sound = 'sound/AI/poweron.ogg')
power_failing = FALSE
update_icon()
for(var/obj/machinery/power/terminal/T in powernet.nodes)
if(istype(T.master, /obj/machinery/power/apc))
var/obj/machinery/power/apc/A = T.master
if(A.is_critical)
continue
A.grid_check = FALSE
for(var/obj/machinery/power/smes/smes in powernet.nodes) // These are "upstream"
smes.grid_check = FALSE
/*
smes.charge = smes.last_charge
smes.output_attempt = smes.last_output_attempt
smes.input_attempt = smes.last_input_attempt
smes.update_icon()
smes.power_change()
*/