-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
power.dm
99 lines (85 loc) · 2.99 KB
/
power.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/obj/machinery/computer/monitor
name = "power monitoring console"
desc = "Used to monitor power levels across the station."
icon_screen = "power"
icon_keyboard = "power_key"
use_power = ACTIVE_POWER_USE
idle_power_usage = 20
active_power_usage = 80
light_color = LIGHT_COLOR_ORANGE
circuit = /obj/item/circuitboard/powermonitor
var/datum/powernet/powernet = null
var/datum/ui_module/power_monitor/power_monitor
/// Will this monitor be hidden from viewers?
var/is_secret_monitor = FALSE
/// How many records to keep of supply and demand
var/record_size = 60
/// Interval between power snapshots
var/record_interval = 5 SECONDS
/// Time to next record power
var/next_record = 0
/// The history list itself of the power
var/list/history = list()
/obj/machinery/computer/monitor/secret //Hides the power monitor (such as ones on ruins & CentCom) from PDA's to prevent metagaming.
name = "outdated power monitoring console"
desc = "It monitors power levels across the local powernet."
circuit = /obj/item/circuitboard/powermonitor/secret
is_secret_monitor = TRUE
/obj/machinery/computer/monitor/Initialize(mapload)
. = ..()
GLOB.power_monitors += src
GLOB.power_monitors = sortAtom(GLOB.power_monitors)
power_monitor = new(src)
GLOB.powermonitor_repository.update_cache()
powernet = find_powernet()
history["supply"] = list()
history["demand"] = list()
/obj/machinery/computer/monitor/Destroy()
GLOB.power_monitors -= src
GLOB.powermonitor_repository.update_cache()
QDEL_NULL(power_monitor)
return ..()
/obj/machinery/computer/monitor/power_change()
..()
GLOB.powermonitor_repository.update_cache()
/obj/machinery/computer/monitor/proc/find_powernet()
var/obj/structure/cable/attached = null
var/turf/T = loc
if(isturf(T))
attached = locate() in T
if(attached)
return attached.powernet
/obj/machinery/computer/monitor/attack_ai(mob/user)
attack_hand(user)
/obj/machinery/computer/monitor/attack_hand(mob/user)
add_fingerprint(user)
if(stat & (BROKEN|NOPOWER))
return
// Update the powernet
powernet = find_powernet()
ui_interact(user)
/obj/machinery/computer/monitor/ui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = FALSE, datum/tgui/master_ui = null, datum/ui_state/state = GLOB.default_state)
power_monitor.ui_interact(user, ui_key, ui, force_open)
/obj/machinery/computer/monitor/interact(mob/user)
power_monitor.ui_interact(user)
/obj/machinery/computer/monitor/process()
record()
/**
* Power snapshot recording proc
*
* This proc handles recording powernet history for the graph on the TGUI
* It is called every process(), but only logs every 5 seconds
*/
/obj/machinery/computer/monitor/proc/record()
if(world.time >= next_record)
next_record = world.time + record_interval
if(!powernet)
return
var/list/supply = history["supply"]
supply += powernet.viewavail
if(length(supply) > record_size)
supply.Cut(1, 2)
var/list/demand = history["demand"]
demand += powernet.viewload
if(length(demand) > record_size)
demand.Cut(1, 2)