forked from tgstation/tgstation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fax.dm
547 lines (501 loc) · 19.2 KB
/
fax.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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
/obj/machinery/fax
name = "Fax Machine"
desc = "Bluespace technologies on the application of bureaucracy."
icon = 'icons/obj/fax.dmi'
icon_state = "fax"
density = TRUE
power_channel = AREA_USAGE_EQUIP
max_integrity = 100
pass_flags = PASSTABLE
circuit = /obj/item/circuitboard/machine/fax
/// The unique ID by which the fax will build a list of existing faxes.
var/fax_id
/// The name of the fax displayed in the list. Not necessarily unique to some EMAG jokes.
var/fax_name
/// A weak reference to an inserted object.
var/datum/weakref/loaded_item_ref
/// World ticks the machine is electified for.
var/seconds_electrified = MACHINE_NOT_ELECTRIFIED
/// If true, the fax machine is jammed and needs cleaning
var/jammed = FALSE
/// Determines the possibility of sending papers to the additional faxes.
var/access_additional_faxes = FALSE
/// Defines a list of accesses whose owners can open a connection with the additional faxes.
var/static/access_additional_faxes_required = list(ACCESS_CAPTAIN)
/// Necessary to hide syndicate faxes from the general list. Doesn't mean he's EMAGGED!
var/syndicate_network = FALSE
/// True if the fax machine should be visible to other fax machines in general.
var/visible_to_network = TRUE
/// If true we will eject faxes at speed rather than sedately place them into a tray.
var/hurl_contents = FALSE
/// If true you can fax things which strictly speaking are not paper.
var/allow_exotic_faxes = FALSE
/// This is where the dispatch and reception history for each fax is stored.
var/list/fax_history = list()
/// List of types which should always be allowed to be faxed
var/static/list/allowed_types = list(
/obj/item/paper,
/obj/item/photo,
/obj/item/tcgcard
)
/// List of types which should be allowed to be faxed if hacked
var/static/list/exotic_types = list(
/obj/item/food/pizzaslice,
/obj/item/food/root_flatbread,
/obj/item/food/salami,
/obj/item/throwing_star,
/obj/item/stack/spacecash,
/obj/item/holochip,
/obj/item/card
)
/obj/machinery/fax/Initialize(mapload)
. = ..()
if (!fax_id)
fax_id = SSnetworks.assign_random_name()
if (!fax_name)
fax_name = "Unregistered fax " + fax_id
wires = new /datum/wires/fax(src)
register_context()
/obj/machinery/fax/Destroy()
QDEL_NULL(loaded_item_ref)
QDEL_NULL(wires)
return ..()
/obj/machinery/fax/update_overlays()
. = ..()
if (panel_open)
. += "fax_panel"
var/obj/item/loaded = loaded_item_ref?.resolve()
if (loaded)
. += mutable_appearance(icon, find_overlay_state(loaded, "contain"))
/obj/machinery/fax/examine()
. = ..()
if(jammed)
. += span_notice("Its output port is jammed and needs cleaning.")
/obj/machinery/fax/on_set_is_operational(old_value)
if (old_value == FALSE)
START_PROCESSING(SSmachines, src)
return
STOP_PROCESSING(SSmachines, src)
/obj/machinery/fax/process(delta_time)
if(seconds_electrified > MACHINE_NOT_ELECTRIFIED)
seconds_electrified -= delta_time
/obj/machinery/fax/attack_hand(mob/user, list/modifiers)
if(seconds_electrified && !(machine_stat & NOPOWER))
if(shock(user, 100))
return
return ..()
/***
* Emag the device if the panel is open.
* Emag does not bring you into the syndicate network, but makes it visible to you.
*/
/obj/machinery/fax/emag_act(mob/user)
if (!panel_open && !allow_exotic_faxes)
balloon_alert(user, "open panel first!")
return
if (!(obj_flags & EMAGGED))
obj_flags |= EMAGGED
playsound(src, 'sound/creatures/dog/growl2.ogg', 50, FALSE)
to_chat(user, span_warning("An image appears on [src] screen for a moment with Ian in the cap of a Syndicate officer."))
/obj/machinery/fax/wrench_act(mob/living/user, obj/item/tool)
. = ..()
default_unfasten_wrench(user, tool)
return TOOL_ACT_TOOLTYPE_SUCCESS
/**
* Open and close the wire panel.
*/
/obj/machinery/fax/screwdriver_act(mob/living/user, obj/item/screwdriver)
. = ..()
default_deconstruction_screwdriver(user, icon_state, icon_state, screwdriver)
update_appearance()
return TRUE
/**
* Using the multi-tool with the panel closed causes the fax network name to be renamed.
*/
/obj/machinery/fax/multitool_act(mob/living/user, obj/item/I)
if (panel_open)
return
var/new_fax_name = tgui_input_text(user, "Enter a new name for the fax machine.", "New Fax Name", , 128)
if (!new_fax_name)
return TOOL_ACT_TOOLTYPE_SUCCESS
if (new_fax_name != fax_name)
if (fax_name_exist(new_fax_name))
// Being able to set the same name as another fax machine will give a lot of gimmicks for the traitor.
if (syndicate_network != TRUE && obj_flags != EMAGGED)
to_chat(user, span_warning("There is already a fax machine with this name on the network."))
return TOOL_ACT_TOOLTYPE_SUCCESS
user.log_message("renamed [fax_name] (fax machine) to [new_fax_name].", LOG_GAME)
fax_name = new_fax_name
return TOOL_ACT_TOOLTYPE_SUCCESS
/obj/machinery/fax/attackby(obj/item/item, mob/user, params)
if (jammed && clear_jam(item, user))
return
if (panel_open)
if (is_wire_tool(item))
wires.interact(user)
return
if (can_load_item(item))
if (!loaded_item_ref?.resolve())
loaded_item_ref = WEAKREF(item)
item.forceMove(src)
update_appearance()
return
return ..()
// Checks if the card has access to switch "legal" faxes of administrators.
/obj/machinery/fax/proc/access_additional_faxes_check(mob/living/user)
if(isAdminGhostAI(user))
return TRUE
var/obj/item/card/id/used_id = user.get_idcard(TRUE)
// We check if it makes sense to check access at all.
if(!access_additional_faxes_required || !used_id.access)
return FALSE
for(var/requested_access in access_additional_faxes_required)
if(requested_access in used_id.access)
return TRUE
return FALSE
// Switches access to the "legal" administrator's fax list. Access to the "illegal" is switched by hacking.
/obj/machinery/fax/proc/access_additional_faxes_toggle()
access_additional_faxes = !access_additional_faxes
say("The channel of communication with CentCom is [access_additional_faxes ? "open" : "close"].")
/**
* Attempts to clean out a jammed machine using a passed item.
* Returns true if successful.
*/
/obj/machinery/fax/proc/clear_jam(obj/item/item, mob/user)
if (istype(item, /obj/item/reagent_containers/spray))
var/obj/item/reagent_containers/spray/clean_spray = item
if(!clean_spray.reagents.has_reagent(/datum/reagent/space_cleaner, clean_spray.amount_per_transfer_from_this))
return FALSE
clean_spray.reagents.remove_reagent(/datum/reagent/space_cleaner, clean_spray.amount_per_transfer_from_this, 1)
playsound(loc, 'sound/effects/spray3.ogg', 50, TRUE, MEDIUM_RANGE_SOUND_EXTRARANGE)
user.visible_message(span_notice("[user] cleans \the [src]."), span_notice("You clean \the [src]."))
jammed = FALSE
return TRUE
if (istype(item, /obj/item/soap) || istype(item, /obj/item/reagent_containers/cup/rag))
var/cleanspeed = 50
if (istype(item, /obj/item/soap))
var/obj/item/soap/used_soap = item
cleanspeed = used_soap.cleanspeed
user.visible_message(span_notice("[user] starts to clean \the [src]."), span_notice("You start to clean \the [src]..."))
if (do_after(user, cleanspeed, target = src))
user.visible_message(span_notice("[user] cleans \the [src]."), span_notice("You clean \the [src]."))
jammed = FALSE
return TRUE
return FALSE
/**
* Returns true if an item can be loaded into the fax machine.
*/
/obj/machinery/fax/proc/can_load_item(obj/item/item)
if(!is_allowed_type(item))
return FALSE
if (!istype(item, /obj/item/stack))
return TRUE
var/obj/item/stack/stack_item = item
return stack_item.amount == 1
/**
* Returns true if an item is of a type which can currently be loaded into this fax machine.
* This list expands if you snip a particular wire.
*/
/obj/machinery/fax/proc/is_allowed_type(obj/item/item)
if (is_type_in_list(item, allowed_types))
return TRUE
if (!allow_exotic_faxes)
return FALSE
return is_type_in_list(item, exotic_types)
/obj/machinery/fax/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "Fax")
ui.open()
/obj/machinery/fax/ui_static_data(mob/user)
var/list/data = list()
data["additional_faxes_list"] = GLOB.additional_faxes_list
data["syndicate_faxes_list"] = GLOB.syndicate_faxes_list
return data
/obj/machinery/fax/ui_data(mob/user)
var/list/data = list()
//Record a list of all existing faxes.
for(var/obj/machinery/fax/FAX in GLOB.machines)
if(FAX.fax_id == fax_id) //skip yourself
continue
var/list/fax_data = list()
fax_data["fax_name"] = FAX.fax_name
fax_data["fax_id"] = FAX.fax_id
fax_data["visible"] = FAX.visible_to_network
fax_data["has_paper"] = !!FAX.loaded_item_ref?.resolve()
// Hacked doesn't mean on the syndicate network.
fax_data["syndicate_network"] = FAX.syndicate_network
data["faxes"] += list(fax_data)
// Own data
data["fax_id"] = fax_id
data["fax_name"] = fax_name
data["visible"] = visible_to_network
data["access_additional_faxes"] = access_additional_faxes
data["сan_switch_access"] = access_additional_faxes_check(user)
// In this case, we don't care if the fax is hacked or in the syndicate's network. The main thing is to check the visibility of other faxes.
data["syndicate_network"] = (syndicate_network || (obj_flags & EMAGGED))
data["has_paper"] = !!loaded_item_ref?.resolve()
data["fax_history"] = fax_history
return data
/obj/machinery/fax/ui_act(action, list/params)
. = ..()
if(.)
return
switch(action)
// Pulls the paper out of the fax machine
if("remove")
var/obj/item/loaded = loaded_item_ref?.resolve()
if (!loaded)
return
loaded.forceMove(drop_location())
loaded_item_ref = null
playsound(src, 'sound/machines/eject.ogg', 50, FALSE)
update_appearance()
return TRUE
if("access_additional_faxes_toggle")
access_additional_faxes_toggle()
if("send")
var/obj/item/loaded = loaded_item_ref?.resolve()
if (!loaded)
return
var/destination = params["id"]
if(send(loaded, destination))
log_fax(loaded, destination, params["name"])
loaded_item_ref = null
update_appearance()
return TRUE
if("send_to_additional_fax")
var/obj/item/loaded = loaded_item_ref?.resolve()
if (!loaded)
return
if(istype(loaded, /obj/item/paper))
if(send_to_additional_faxes(loaded, usr, params["name"], params["color"]))
loaded_item_ref = null
update_appearance()
return TRUE
else
say("The destination fax blocks the reception of this item.")
if("history_clear")
history_clear()
return TRUE
/**
* Records logs of bureacratic action
* Arguments:
* * sent - The object being sent
* * destination_id - The unique ID of the fax machine
* * name - The friendly name of the fax machine, but these can be spoofed so the ID is also required
*/
/obj/machinery/fax/proc/log_fax(obj/item/sent, destination_id, name)
if (istype(sent, /obj/item/paper))
var/obj/item/paper/sent_paper = sent
log_paper("[usr] has sent a fax with the message \"[sent_paper.get_raw_text()]\" to [name]/[destination_id].")
return
log_game("[usr] has faxed [sent] to [name]/[destination_id].]")
/**
* The procedure for sending a paper to another fax machine.
*
* The object is called inside /obj/machinery/fax to send the thing to another fax machine.
* The procedure searches among all faxes for the desired fax ID and calls proc/receive() on that fax.
* If the item is sent successfully, it returns TRUE.
* Arguments:
* * loaded - The object to be sent.
* * id - The network ID of the fax machine you want to send the item to.
*/
/obj/machinery/fax/proc/send(obj/item/loaded, id)
for(var/obj/machinery/fax/FAX in GLOB.machines)
if (FAX.fax_id != id)
continue
if (FAX.jammed)
do_sparks(5, TRUE, src)
balloon_alert(usr, "destination port jammed")
playsound(src, 'sound/machines/scanbuzz.ogg', 25, TRUE, SHORT_RANGE_SOUND_EXTRARANGE)
return FALSE
FAX.receive(loaded, fax_name)
playback_sending(loaded, FAX.fax_name)
return TRUE
return FALSE
/**
* The procedure for sending a paper to virtual admins fax machine.
*
* This procedure is similar to the send procedure except that it sends the paper to
* a "virtual" fax to a special administrator list.
* Arguments:
* * paper - The paper to be sent.
* * sender - Reference to the sender's substance.
* * receiver_name - The recipient's fax name, which will be displayed in the administrator's list.
* * receiver_color - The color the receiver_name will be colored in.
*/
/obj/machinery/fax/proc/send_to_additional_faxes(obj/item/paper/paper, mob/sender, receiver_name, receiver_color)
GLOB.fax_manager.receive_request(sender, src, receiver_name, paper, receiver_color)
playback_sending(paper, receiver_name)
return TRUE
/**
* The procedure for playing the animation and the sending sound.
*
* Procedure called to add to the history of sending messages, playing the sending animation and sound.
* Arguments:
* * loaded - Sending item to determine the animation..
* * receiver_name - Recipient's name to be added to the message history.
*/
/obj/machinery/fax/proc/playback_sending(obj/item/loaded, receiver_name)
history_add("Send", receiver_name)
INVOKE_ASYNC(src, .proc/animate_object_travel, loaded, "fax_receive", find_overlay_state(loaded, "send"))
playsound(src, 'sound/machines/high_tech_confirm.ogg', 50, FALSE)
/**
* Procedure for accepting papers from another fax machine.
*
* The procedure is called in proc/send() of the other fax. It receives a paper-like object and "prints" it.
* Arguments:
* * loaded - The object to be printed.
* * sender_name - The sender's name, which will be displayed in the message and recorded in the history of operations.
*/
/obj/machinery/fax/proc/receive(obj/item/loaded, sender_name)
playsound(src, 'sound/machines/printer.ogg', 50, FALSE)
INVOKE_ASYNC(src, .proc/animate_object_travel, loaded, "fax_receive", find_overlay_state(loaded, "receive"))
say("Received correspondence from [sender_name].")
history_add("Receive", sender_name)
addtimer(CALLBACK(src, .proc/vend_item, loaded), 1.9 SECONDS)
/**
* Procedure for animating an object entering or leaving the fax machine.
* Arguments:
* * item - The object which is travelling.
* * animation_state - An icon state to apply to the fax machine.
* * overlay_state - An icon state to apply as an overlay to the fax machine.
*/
/obj/machinery/fax/proc/animate_object_travel(obj/item/item, animation_state, overlay_state)
icon_state = animation_state
var/mutable_appearance/overlay = mutable_appearance(icon, overlay_state)
overlays += overlay
addtimer(CALLBACK(src, .proc/travel_animation_complete, overlay), 2 SECONDS)
/**
* Called when the travel animation should end. Reset animation and overlay states.
* Arguments:
* * remove_overlay - Overlay to remove.
*/
/obj/machinery/fax/proc/travel_animation_complete(mutable_appearance/remove_overlay)
icon_state = "fax"
overlays -= remove_overlay
/**
* Returns an appropriate icon state to represent a passed item.
* Arguments:
* * item - Item to interrogate.
* * state_prefix - Icon state action prefix to mutate.
*/
/obj/machinery/fax/proc/find_overlay_state(obj/item/item, state_prefix)
if (istype(item, /obj/item/paper))
return "[state_prefix]_paper"
if (istype(item, /obj/item/photo))
return "[state_prefix]_photo"
if (iscash(item))
return "[state_prefix]_cash"
if (istype(item, /obj/item/card))
return "[state_prefix]_id"
if (istype(item, /obj/item/food))
return "[state_prefix]_food"
if (istype(item, /obj/item/throwing_star))
return "[state_prefix]_star"
if (istype(item, /obj/item/tcgcard))
return "[state_prefix]_tcg"
return "[state_prefix]_paper"
/**
* Actually vends an item out of the fax machine.
* Moved into its own proc to allow a delay for the animation.
* This will either deposit the item on the fax machine, or throw it if you have hacked a wire.
* Arguments:
* * vend - Item to vend from the fax machine.
*/
/obj/machinery/fax/proc/vend_item(obj/item/vend)
vend.forceMove(drop_location())
if (hurl_contents)
vend.throw_at(get_edge_target_turf(drop_location(), pick(GLOB.alldirs)), rand(1, 4), EMBED_THROWSPEED_THRESHOLD)
if (is_type_in_list(vend, exotic_types) && prob(20))
do_sparks(5, TRUE, src)
jammed = TRUE
/**
* A procedure that makes entries in the history of fax transactions.
*
* Called to record the operation in the fax history list.
* Records the type of operation, the name of the fax machine with which the operation was performed, and the station time.
* Arguments:
* * history_type - Type of operation. By default, "Send" and "Receive" should be used.
* * history_fax_name - The name of the fax machine that performed the operation.
*/
/obj/machinery/fax/proc/history_add(history_type = "Send", history_fax_name)
var/list/history_data = list()
history_data["history_type"] = history_type
history_data["history_fax_name"] = history_fax_name
history_data["history_time"] = station_time_timestamp()
fax_history += list(history_data)
/// Clears the history of fax operations.
/obj/machinery/fax/proc/history_clear()
fax_history = null
/**
* Checks fax names for a match.
*
* Called to check the new fax name against the names of other faxes to prevent the use of identical names.
* Arguments:
* * new_fax_name - The text of the name to be checked for a match.
*/
/obj/machinery/fax/proc/fax_name_exist(new_fax_name)
for(var/obj/machinery/fax/FAX in GLOB.machines)
if (FAX.fax_name == new_fax_name)
return TRUE
return FALSE
/**
* Attempts to shock the passed user, returns true if they are shocked.
*
* Arguments:
* * user - the user to shock
* * chance - probability the shock happens
*/
/obj/machinery/fax/proc/shock(mob/living/user, chance)
if(!istype(user) || machine_stat & (BROKEN|NOPOWER))
return FALSE
if(!prob(chance))
return FALSE
do_sparks(5, TRUE, src)
var/check_range = TRUE
return electrocute_mob(user, get_area(src), src, 0.7, check_range)
/obj/machinery/fax/add_context(atom/source, list/context, obj/item/held_item, mob/user)
. = ..()
if (!held_item)
if (!panel_open)
context[SCREENTIP_CONTEXT_LMB] = "Open interface"
return CONTEXTUAL_SCREENTIP_SET
context[SCREENTIP_CONTEXT_LMB] = "Manipulate wires"
return CONTEXTUAL_SCREENTIP_SET
switch (held_item.tool_behaviour)
if (TOOL_SCREWDRIVER)
if (panel_open)
context[SCREENTIP_CONTEXT_LMB] = "Close maintenance panel"
return CONTEXTUAL_SCREENTIP_SET
context[SCREENTIP_CONTEXT_LMB] = "Open maintenance panel"
return CONTEXTUAL_SCREENTIP_SET
if (TOOL_WRENCH)
if (anchored)
context[SCREENTIP_CONTEXT_LMB] = "Unsecure"
return CONTEXTUAL_SCREENTIP_SET
context[SCREENTIP_CONTEXT_LMB] = "Secure"
return CONTEXTUAL_SCREENTIP_SET
if (TOOL_MULTITOOL)
if (panel_open)
context[SCREENTIP_CONTEXT_LMB] = "Pulse wires"
return CONTEXTUAL_SCREENTIP_SET
context[SCREENTIP_CONTEXT_LMB] = "Rename in network"
return CONTEXTUAL_SCREENTIP_SET
if (TOOL_WIRECUTTER)
if (!panel_open)
return .
context[SCREENTIP_CONTEXT_LMB] = "Manipulate wires"
return CONTEXTUAL_SCREENTIP_SET
if (jammed && is_type_in_list(held_item, list(/obj/item/reagent_containers/spray, /obj/item/soap, /obj/item/reagent_containers/cup/rag)))
context[SCREENTIP_CONTEXT_LMB] = "Clean output tray"
return CONTEXTUAL_SCREENTIP_SET
if (panel_open)
if (istype(held_item, /obj/item/card/emag))
context[SCREENTIP_CONTEXT_LMB] = "Remove network safeties"
return CONTEXTUAL_SCREENTIP_SET
return .
if (is_allowed_type(held_item))
context[SCREENTIP_CONTEXT_LMB] = "Insert into fax machine"
return CONTEXTUAL_SCREENTIP_SET
return .