#define POWER_MONITOR_HIST_SIZE 15 // the power monitoring computer // for the moment, just report the status of all APCs in the same powernet /obj/machinery/computer/powermonitor name = "Power Monitoring Computer" desc = "It monitors power levels across the station." icon = 'icons/obj/computer.dmi' icon_state = "power" circuit = "/obj/item/weapon/circuitboard/powermonitor" use_auto_lights = 1 light_range_on = 2 light_power_on = 1 light_color = LIGHT_COLOR_YELLOW use_power = 1 idle_power_usage = 300 active_power_usage = 300 var/datum/html_interface/interface var/tmp/next_process = 0 var/datum/powernet/connected_powernet //Lists used for the charts. var/list/demand_hist[0] var/list/supply_hist[0] var/list/load_hist[0] /obj/machinery/computer/powermonitor/New() ..() for(var/i = 1 to POWER_MONITOR_HIST_SIZE) //The chart doesn't like lists with null. demand_hist.Add(list(0)) supply_hist.Add(list(0)) load_hist.Add(list(0)) var/head = {" "} interface = new/datum/html_interface/nanotrasen(src, "Power Monitoring", 420, 600, head) var/obj/machinery/power/apc/areaapc = get_area(src).areaapc if(areaapc) connected_powernet = areaapc.terminal.powernet var/obj/structure/cable/attached = null var/turf/T = loc if(isturf(T)) attached = locate() in T if(attached) connected_powernet = attached.get_powernet() html_machines += src init_ui() /obj/machinery/computer/powermonitor/proc/init_ui() var/dat = {"
Total power:X W
Total load:X W
Total demand:X W
AreaEqp.Lgt.Env.LoadCell
"} interface.updateContent("content", dat) /obj/machinery/computer/powermonitor/attack_ai(mob/user) . = attack_hand(user) /obj/machinery/computer/powermonitor/Destroy() ..() html_machines -= src qdel(interface) interface = null /obj/machinery/computer/powermonitor/attack_hand(mob/user) . = ..() if(.) interface.hide(user) return interact(user) //Needs to be overriden because else it will use the shitty set_machine(). /obj/machinery/computer/powermonitor/hiIsValidClient(datum/html_interface_client/hclient, datum/html_interface/hi) return hclient.client.mob.html_mob_check(type) /obj/machinery/computer/powermonitor/interact(mob/user) var/delay = 0 delay += send_asset(user.client, "Chart.js") delay += send_asset(user.client, "powerChart.js") spawn(delay) //To prevent Jscript issues with resource sending. interface.show(user) interface.executeJavaScript("makeChart()", user) //Making the chart in something like $("document").ready() won't work so I do it here for(var/i = 1 to POWER_MONITOR_HIST_SIZE) interface.callJavaScript("pushPowerData", list(demand_hist[i], supply_hist[i], load_hist[i]), user) /obj/machinery/computer/powermonitor/power_change() ..() var/obj/machinery/power/apc/areaapc = get_area(src).areaapc if(areaapc) connected_powernet = areaapc.terminal.powernet var/obj/structure/cable/attached = null var/turf/T = loc if(isturf(T)) attached = locate() in T if(attached) connected_powernet = attached.get_powernet() if(stat & BROKEN) icon_state = "broken" else if (stat & NOPOWER) spawn(rand(0, 15)) icon_state = "c_unpowered" else icon_state = initial(icon_state) /obj/machinery/computer/powermonitor/process() if(stat & (BROKEN|NOPOWER) || !connected_powernet) interface.executeJavaScript("setDisabled()") return else interface.executeJavaScript("setEnabled()") demand_hist += connected_powernet.load supply_hist += connected_powernet.avail load_hist += connected_powernet.viewload if(demand_hist.len > POWER_MONITOR_HIST_SIZE) //Should always be true but eh. demand_hist.Cut(1, 2) supply_hist.Cut(1, 2) load_hist.Cut(1,2) interface.callJavaScript("pushPowerData", list(connected_powernet.load, connected_powernet.avail, connected_powernet.viewload)) // next_process == 0 is in place to make it update the first time around, then wait until someone watches if ((!next_process || interface.isUsed()) && world.time >= next_process) next_process = world.time + 30 interface.updateContent("totPower", "[connected_powernet.avail] W") interface.updateContent("totLoad", "[num2text(connected_powernet.viewload,10)] W") interface.updateContent("totDemand", "[connected_powernet.load] W") var/tbl = list() var/list/S = list(" Off","AOff"," On", " AOn") var/list/chg = list(" N","C","F") for(var/obj/machinery/power/terminal/term in connected_powernet.nodes) if(istype(term.master, /obj/machinery/power/apc)) var/obj/machinery/power/apc/A = term.master var/area/APC_area = get_area(A) tbl += "" tbl += "["\The [APC_area]"]" tbl += "[S[A.equipment+1]][S[A.lighting+1]][S[A.environ+1]]" tbl += "[A.lastused_total]" if(A.cell) var/class = "good" switch(A.cell.percent()) if(49 to 15) class = "average" if(15 to -INFINITY) class = "bad" tbl += "[round(A.cell.percent())]%[chg[A.charging+1]]" else tbl += "N/C" tbl += "" tbl = jointext(tbl,"") interface.updateContent("APCTable", tbl) #undef POWER_MONITOR_HIST_SIZE