/
camera.dm
331 lines (288 loc) · 10.6 KB
/
camera.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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/var/camera_cache_id = 1
/proc/invalidateCameraCache()
camera_cache_id = (++camera_cache_id % 999999)
/obj/machinery/computer/security
name = "Camera Monitor"
desc = "Used to access the various cameras networks on the station."
icon_keyboard = "security_key"
icon_screen = "cameras"
circuit = /obj/item/weapon/circuitboard/camera
var/obj/machinery/camera/current = null
var/list/network = list("")
var/last_pic = 1.0
light_color = LIGHT_COLOR_RED
var/mapping = 0
var/cache_id = 0
var/list/networks[0]
var/list/tempnets[0]
var/list/data[0]
var/list/access[0]
var/camera_cache = null
/obj/machinery/computer/security/New() // Lists existing networks and their required access. Format: networks[<name>] = list(<access>)
networks["SS13"] = list(access_hos,access_captain)
networks["Telecomms"] = list(access_hos,access_captain)
networks["Research Outpost"] = list(access_rd,access_hos,access_captain)
networks["Mining Outpost"] = list(access_qm,access_hop,access_hos,access_captain)
networks["Research"] = list(access_rd,access_hos,access_captain)
networks["Prison"] = list(access_hos,access_captain)
networks["Labor"] = list(access_hos,access_captain)
networks["Interrogation"] = list(access_hos,access_captain)
networks["Atmosphere Alarms"] = list(access_ce,access_hos,access_captain)
networks["Fire Alarms"] = list(access_ce,access_hos,access_captain)
networks["Power Alarms"] = list(access_ce,access_hos,access_captain)
networks["Supermatter"] = list(access_ce,access_hos,access_captain)
networks["MiniSat"] = list(access_rd,access_hos,access_captain)
networks["Singularity"] = list(access_ce,access_hos,access_captain)
networks["Anomaly Isolation"] = list(access_rd,access_hos,access_captain)
networks["Toxins"] = list(access_rd,access_hos,access_captain)
networks["Telepad"] = list(access_rd,access_hos,access_captain)
networks["TestChamber"] = list(access_rd,access_hos,access_captain)
networks["ERT"] = list(access_cent_specops_commander,access_cent_commander)
networks["CentCom"] = list(access_cent_security,access_cent_commander)
networks["Thunderdome"] = list(access_cent_thunder,access_cent_commander)
..()
/obj/machinery/computer/security/attack_ai(var/mob/user as mob)
return attack_hand(user)
/obj/machinery/computer/security/check_eye(var/mob/user as mob)
if ((get_dist(user, src) > 1 || !( user.canmove ) || user.blinded || !( current ) || !( current.status )) && (!istype(user, /mob/living/silicon)))
return null
user.reset_view(current)
return 1
// Network configuration
/obj/machinery/computer/security/attackby(I as obj, user as mob, params)
access = list()
if(istype(I,/obj/item/weapon/card/id)) // If hit by a regular ID card.
var/obj/item/weapon/card/id/E = I
access = E.access
ui_interact(user)
else
..()
/obj/machinery/computer/security/emag_act(user as mob)
if(!emagged)
emagged = 1
user << "\blue You have authorized full network access!"
ui_interact(user)
else
ui_interact(user)
/obj/machinery/computer/security/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1)
if(src.z > 6) return
if(stat & (NOPOWER|BROKEN)) return
if(user.stat) return
var/data[0]
data["current"] = null
if(camera_cache_id != cache_id)
cache_id = camera_cache_id
cameranet.process_sort()
var/cameras[0]
for(var/obj/machinery/camera/C in cameranet.cameras)
if(!can_access_camera(C))
continue
var/cam = C.nano_structure()
cameras[++cameras.len] = cam
camera_cache=list2json(cameras)
tempnets.Cut()
if(emagged)
access = list(access_captain) // Assume captain level access when emagged
data["emagged"] = 1
if(isAI(user) || isrobot(user))
access = list(access_captain) // Assume captain level access when AI
// Loop through the ID's permission, and check which networks the ID has access to.
for(var/l in networks) // Loop through networks.
for(var/m in networks[l]) // Loop through access levels of the networks.
if(m in access)
if(l in network) // Checks if the network is currently active.
tempnets.Add(list(list("name" = l, "active" = 1)))
else
tempnets.Add(list(list("name" = l, "active" = 0)))
break
if(tempnets.len)
data["networks"] = tempnets
if(current)
data["current"] = current.nano_structure()
data["cameras"] = list("__json_cache" = camera_cache)
ui = nanomanager.try_update_ui(user, src, ui_key, ui, data, force_open)
if (!ui)
ui = new(user, src, ui_key, "sec_camera.tmpl", "Camera Console", 900, 800)
// adding a template with the key "mapContent" enables the map ui functionality
ui.add_template("mapContent", "sec_camera_map_content.tmpl")
// adding a template with the key "mapHeader" replaces the map header content
ui.add_template("mapHeader", "sec_camera_map_header.tmpl")
ui.set_initial_data(data)
ui.open()
ui.set_auto_update(1)
/obj/machinery/computer/security/Topic(href, href_list)
if(href_list["switchTo"])
if(src.z>6 || stat&(NOPOWER|BROKEN)) return
if(usr.stat || ((get_dist(usr, src) > 1 || !( usr.canmove ) || usr.blinded) && !istype(usr, /mob/living/silicon))) return
var/obj/machinery/camera/C = locate(href_list["switchTo"]) in cameranet.cameras
if(!C) return
switch_to_camera(usr, C)
return 1
else if(href_list["reset"])
if(src.z>6 || stat&(NOPOWER|BROKEN)) return
if(usr.stat || ((get_dist(usr, src) > 1 || !( usr.canmove ) || usr.blinded) && !istype(usr, /mob/living/silicon))) return
reset_current()
usr.check_eye(current)
return 1
else if(href_list["activate"]) // Activate: enable or disable networks
var/net = href_list["activate"] // Network to be enabled or disabled.
var/active = href_list["active"] // Is the network currently active.
for(var/a in networks[net])
if(a in access) // Re-check for authorization.
if(text2num(active) == 1)
src.network -= net
break
else
src.network += net
break
invalidateCameraCache()
nanomanager.update_uis(src)
else
. = ..()
/obj/machinery/computer/security/attack_hand(var/mob/user as mob)
access = list()
if (src.z > 6)
user << "\red <b>Unable to establish a connection</b>: \black You're too far away from the station!"
return
if(stat & (NOPOWER|BROKEN)) return
if(!isAI(user))
user.set_machine(src)
if(ishuman(user))
var/mob/living/carbon/human/H = user
if(H.wear_id)
var/obj/item/weapon/card/id/gold/C = H.wear_id
access = C.access
ui_interact(user)
// Check if camera is accessible when jumping
/obj/machinery/computer/security/proc/can_access_camera(var/obj/machinery/camera/C)
var/list/shared_networks = src.network & C.network
if(shared_networks.len)
return 1
return 0
// Switching to cameras
/obj/machinery/computer/security/proc/switch_to_camera(var/mob/user, var/obj/machinery/camera/C)
if ((get_dist(user, src) > 1 || user.machine != src || user.blinded || !( user.canmove ) || !( C.can_use() )) && (!istype(user, /mob/living/silicon/ai)))
if(!C.can_use() && !isAI(user))
src.current = null
return 0
else
if(isAI(user))
var/mob/living/silicon/ai/A = user
// Only allow non-carded AIs to view because the interaction with the eye gets all wonky otherwise.
if(!A.is_in_chassis())
return 0
A.eyeobj.setLoc(get_turf(C))
A.client.eye = A.eyeobj
else
set_current(C)
use_power(50)
return 1
/obj/machinery/computer/security/proc/set_current(var/obj/machinery/camera/C)
if(current == C)
return
if(current)
reset_current()
src.current = C
if(current)
use_power = 2
var/mob/living/L = current.loc
if(istype(L))
L.tracking_initiated()
/obj/machinery/computer/security/proc/reset_current()
if(current)
var/mob/living/L = current.loc
if(istype(L))
L.tracking_cancelled()
current = null
use_power = 1
//Camera control: moving.
/obj/machinery/computer/security/proc/jump_on_click(var/mob/user,var/A)
if(user.machine != src)
return
var/obj/machinery/camera/jump_to
if(istype(A,/obj/machinery/camera))
jump_to = A
else if(ismob(A))
if(ishuman(A))
jump_to = locate() in A:head
else if(isrobot(A))
jump_to = A:camera
else if(isobj(A))
jump_to = locate() in A
else if(isturf(A))
var/best_dist = INFINITY
for(var/obj/machinery/camera/camera in get_area(A))
if(!camera.can_use())
continue
if(!can_access_camera(camera))
continue
var/dist = get_dist(camera,A)
if(dist < best_dist)
best_dist = dist
jump_to = camera
if(isnull(jump_to))
return
if(can_access_camera(jump_to))
switch_to_camera(user,jump_to)
// Camera control: mouse.
/atom/DblClick()
..()
if(istype(usr.machine,/obj/machinery/computer/security))
var/obj/machinery/computer/security/console = usr.machine
console.jump_on_click(usr,src)
// Camera control: arrow keys.
/mob/Move(n,direct)
if(istype(machine,/obj/machinery/computer/security))
var/obj/machinery/computer/security/console = machine
var/turf/T = get_turf(console.current)
for(var/i;i<10;i++)
T = get_step(T,direct)
console.jump_on_click(src,T)
return
return ..(n,direct)
// Other computer monitors.
/obj/machinery/computer/security/telescreen
name = "\improper Telescreen"
desc = "Used for watching camera networks."
icon = 'icons/obj/stationobjs.dmi'
icon_state = "telescreen"
light_range_on = 0
network = list("SS13")
density = 0
/obj/machinery/computer/security/telescreen/update_icon()
icon_state = initial(icon_state)
if(stat & BROKEN)
icon_state += "b"
return
/obj/machinery/computer/security/telescreen/entertainment
name = "entertainment monitor"
desc = "Damn, they better have Paradise TV on these things."
icon = 'icons/obj/status_display.dmi'
icon_state = "entertainment"
light_color = "#FFEEDB"
light_range_on = 0
network = list("news")
luminosity = 0
/obj/machinery/computer/security/wooden_tv
name = "security camera monitor"
desc = "An old TV hooked into the stations camera network."
icon_state = "television"
icon_keyboard = null
icon_screen = "detective_tv"
light_color = "#3848B3"
light_power_on = 0.5
network = list("SS13")
/obj/machinery/computer/security/mining
name = "outpost camera monitor"
desc = "Used to access the various cameras on the outpost."
icon_keyboard = "mining_key"
icon_screen = "mining"
light_color = "#F9BBFC"
network = list("Mining Outpost")
/obj/machinery/computer/security/engineering
name = "engineering camera monitor"
desc = "Used to monitor fires and breaches."
icon_keyboard = "power_key"
icon_screen = "engie_cams"
light_color = "#FAC54B"
network = list("Power Alarms","Atmosphere Alarms","Fire Alarms")