-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathsm_monitor.dm
219 lines (196 loc) · 7.21 KB
/
sm_monitor.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/datum/computer_file/program/supermatter_monitor
filename = "smmonitor"
filedesc = "Supermatter Monitoring"
category = PROGRAM_CATEGORY_ENGINEERING
ui_header = "smmon_0.gif"
program_icon_state = "smmon_0"
extended_desc = "This program connects to specially calibrated supermatter sensors to provide information on the status of supermatter-based engines."
requires_ntnet = TRUE
transfer_access = ACCESS_ENGINEERING
network_destination = "supermatter monitoring system"
size = 5
tgui_id = "NtosSupermatterMonitor"
program_icon = "radiation"
alert_able = TRUE
var/last_status = SUPERMATTER_INACTIVE
var/list/supermatters
var/obj/machinery/power/supermatter_crystal/active // Currently selected supermatter crystal.
var/data_corrupted = FALSE //used for when supermatter corruptor is attached
/datum/computer_file/program/supermatter_monitor/Destroy()
clear_signals()
active = null
return ..()
/datum/computer_file/program/supermatter_monitor/process_tick()
..()
var/new_status = get_status()
if(last_status != new_status)
last_status = new_status
ui_header = "smmon_[last_status].gif"
program_icon_state = "smmon_[last_status]"
if(istype(computer))
computer.update_appearance(UPDATE_ICON)
/datum/computer_file/program/supermatter_monitor/run_program(mob/living/user)
. = ..(user)
if(!(active in GLOB.machines))
active = null
refresh()
/datum/computer_file/program/supermatter_monitor/kill_program(forced = FALSE)
supermatters = null
..()
// Refreshes list of active supermatter crystals
/datum/computer_file/program/supermatter_monitor/proc/refresh()
supermatters = list()
var/turf/T = get_turf(ui_host())
if(!T)
return
for(var/obj/machinery/power/supermatter_crystal/S in GLOB.machines)
// Delaminating, not within coverage, not on a tile.
if (!isturf(S.loc) || !(is_station_level(S.z) || is_mining_level(S.z) || S.z == T.z))
continue
supermatters.Add(S)
if(!(active in supermatters))
active = null
/datum/computer_file/program/supermatter_monitor/proc/get_status()
. = SUPERMATTER_INACTIVE
for(var/obj/machinery/power/supermatter_crystal/S in supermatters)
. = max(., S.get_status())
/**
* Sets up the signal listener for Supermatter delaminations.
*
* Unregisters any old listners for SM delams, and then registers one for the SM refered
* to in the `active` variable. This proc is also used with no active SM to simply clear
* the signal and exit.
*/
/datum/computer_file/program/supermatter_monitor/proc/set_signals()
if(active)
RegisterSignal(active, COMSIG_SUPERMATTER_DELAM_ALARM, PROC_REF(send_alert), override = TRUE)
RegisterSignal(active, COMSIG_SUPERMATTER_DELAM_START_ALARM, PROC_REF(send_start_alert), override = TRUE)
/**
* Removes the signal listener for Supermatter delaminations from the selected supermatter.
*
* Pretty much does what it says.
*/
/datum/computer_file/program/supermatter_monitor/proc/clear_signals()
if(active)
UnregisterSignal(active, COMSIG_SUPERMATTER_DELAM_ALARM)
UnregisterSignal(active, COMSIG_SUPERMATTER_DELAM_START_ALARM)
/**
* Sends an SM delam alert to the computer.
*
* Triggered by a signal from the selected supermatter, this proc sends a notification
* to the computer if the program is either closed or minimized. We do not send these
* notifications to the comptuer if we're the active program, because engineers fixing
* the supermatter probably don't need constant beeping to distract them.
*/
/datum/computer_file/program/supermatter_monitor/proc/send_alert()
if(!computer.get_ntnet_status())
return
if(computer.active_program != src)
computer.alert_call(src, "Crystal delamination in progress!")
alert_pending = TRUE
/**
* Sends an SM delam start alert to the computer.
*
* Triggered by a signal from the selected supermatter at the start of a delamination,
* this proc sends a notification to the computer if this program is the active one.
* We do this so that people carrying a tablet with NT CIMS open but with the NTOS window
* closed will still get one audio alert. This is not sent to computers with the program
* minimized or closed to avoid double-notifications.
*/
/datum/computer_file/program/supermatter_monitor/proc/send_start_alert()
if(!computer.get_ntnet_status())
return
if(computer.active_program == src)
computer.alert_call(src, "Crystal delamination in progress!")
/datum/computer_file/program/supermatter_monitor/ui_data()
var/list/data = get_header_data()
if(istype(active))
var/turf/T = get_turf(active)
if(!T)
active = null
refresh()
return
var/datum/gas_mixture/air = T.return_air()
if(!air)
active = null
return
data["active"] = TRUE
data["powerData"] = active.powerData
data["radsData"] = active.radsData
data["tempData"] = active.tempData
data["kpaData"] = active.kpaData
data["molesData"] = active.molesData
if(active.corruptor_attached) //yes it goes negative, that's even more funny
data["SM_integrity"] = active.get_fake_integrity()
data["SM_power"] = active.power + round((rand()-0.5)*12000,1)
data["SM_radiation"] = active.last_rads + round((rand()-0.5)*12000,1)
data["SM_ambienttemp"] = air.return_temperature() + round((rand()-0.5)*20000,1)
data["SM_ambientpressure"] = air.return_pressure() + round((rand()-0.5)*15000,1)
data["SM_moles"] = air.total_moles() + round((rand()-0.5)*1800,1)
else
data["SM_integrity"] = active.get_integrity()
data["SM_power"] = active.power
data["SM_radiation"] = active.last_rads
data["SM_ambienttemp"] = air.return_temperature()
data["SM_ambientpressure"] = air.return_pressure()
data["SM_moles"] = air.total_moles()
//data["SM_EPR"] = round((air.total_moles / air.group_multiplier) / 23.1, 0.01)
var/list/gasdata = list()
if(air.total_moles())
for(var/gasid in air.get_gases())
if(data_corrupted)
gasdata.Add(list(list(
"name"= GLOB.gas_data.names[gasid],
"amount" = round(rand()*100,0.01),
"ui_color" = GLOB.gas_data.ui_colors[gasid])))
else
gasdata.Add(list(list(
"name"= GLOB.gas_data.names[gasid],
"amount" = round(100*air.get_moles(gasid)/air.total_moles(),0.01),
"ui_color" = GLOB.gas_data.ui_colors[gasid])))
else
for(var/gasid in air.get_gases())
gasdata.Add(list(list(
"name"= GLOB.gas_data.names[gasid],
"amount" = 0,
"ui_color" = GLOB.gas_data.ui_colors[gasid])))
data["gases"] = gasdata
else
var/list/SMS = list()
for(var/obj/machinery/power/supermatter_crystal/S in supermatters)
var/area/A = get_area(S)
if(A)
if(S.corruptor_attached)
SMS.Add(list(list(
"area_name" = A.name,
"integrity" = S.get_fake_integrity(),
"uid" = S.uid
)))
else
SMS.Add(list(list(
"area_name" = A.name,
"integrity" = S.get_integrity(),
"uid" = S.uid
)))
data["active"] = FALSE
data["supermatters"] = SMS
return data
/datum/computer_file/program/supermatter_monitor/ui_act(action, params)
if(..())
return TRUE
computer.play_interact_sound()
switch(action)
if("PRG_clear")
clear_signals()
active = null
return TRUE
if("PRG_refresh")
refresh()
return TRUE
if("PRG_set")
var/newuid = text2num(params["target"])
for(var/obj/machinery/power/supermatter_crystal/S in supermatters)
if(S.uid == newuid)
active = S
set_signals()
return TRUE