-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathapc.dm
1635 lines (1471 loc) · 53.5 KB
/
apc.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
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//update_state
#define UPSTATE_CELL_IN (1<<0)
#define UPSTATE_OPENED1 (1<<1)
#define UPSTATE_OPENED2 (1<<2)
#define UPSTATE_MAINT (1<<3)
#define UPSTATE_BROKE (1<<4)
#define UPSTATE_BLUESCREEN (1<<5)
#define UPSTATE_WIREEXP (1<<6)
#define UPSTATE_ALLGOOD (1<<7)
#define APC_RESET_EMP "emp"
//update_overlay
#define APC_UPOVERLAY_CHARGEING0 (1<<0)
#define APC_UPOVERLAY_CHARGEING1 (1<<1)
#define APC_UPOVERLAY_CHARGEING2 (1<<2)
#define APC_UPOVERLAY_EQUIPMENT0 (1<<3)
#define APC_UPOVERLAY_EQUIPMENT1 (1<<4)
#define APC_UPOVERLAY_EQUIPMENT2 (1<<5)
#define APC_UPOVERLAY_LIGHTING0 (1<<6)
#define APC_UPOVERLAY_LIGHTING1 (1<<7)
#define APC_UPOVERLAY_LIGHTING2 (1<<8)
#define APC_UPOVERLAY_ENVIRON0 (1<<9)
#define APC_UPOVERLAY_ENVIRON1 (1<<10)
#define APC_UPOVERLAY_ENVIRON2 (1<<11)
#define APC_UPOVERLAY_LOCKED (1<<12)
#define APC_UPOVERLAY_OPERATING (1<<13)
#define APC_ELECTRONICS_MISSING 0 // None
#define APC_ELECTRONICS_INSTALLED 1 // Installed but not secured
#define APC_ELECTRONICS_SECURED 2 // Installed and secured
#define APC_COVER_CLOSED 0
#define APC_COVER_OPENED 1
#define APC_COVER_REMOVED 2
#define APC_NOT_CHARGING 0
#define APC_CHARGING 1
#define APC_FULLY_CHARGED 2
//Ethereal stuff
#define APC_POWER_GAIN 250 ///amount of power transferred to an APC by an overcharging Ethereal
// the Area Power Controller (APC), formerly Power Distribution Unit (PDU)
// one per area, needs wire connection to power network through a terminal
// controls power to devices in that area
// may be opened to change power cell
// three different channels (lighting/equipment/environ) - may each be set to on, off, or auto
/obj/machinery/power/apc
name = "area power controller"
desc = "A control terminal for the area's electrical systems."
icon_state = "apc0"
use_power = NO_POWER_USE
req_access = list(ACCESS_ENGINE_EQUIP) // Yogs -- changed to allow for use of req_one_access
max_integrity = 200
integrity_failure = 50
resistance_flags = FIRE_PROOF
interaction_flags_machine = INTERACT_MACHINE_WIRES_IF_OPEN | INTERACT_MACHINE_ALLOW_SILICON | INTERACT_MACHINE_OPEN_SILICON
clicksound = 'sound/machines/terminal_select.ogg'
works_with_rped_anyways = TRUE
FASTDMM_PROP(\
set_instance_vars(\
pixel_x = dir == EAST ? 24 : (dir == WEST ? -25 : INSTANCE_VAR_DEFAULT),\
pixel_y = dir == NORTH ? 23 : (dir == SOUTH ? -23 : INSTANCE_VAR_DEFAULT)\
),\
dir_amount = 4\
)
var/light_on_range = 1.5
var/area/area
var/areastring = null
var/obj/item/stock_parts/cell/cell
var/start_charge = 90 // initial cell charge %
var/cell_type = /obj/item/stock_parts/cell/upgraded //Base cell has 2500 capacity. Enter the path of a different cell you want to use. cell determines charge rates, max capacity, ect. These can also be changed with other APC vars, but isn't recommended to minimize the risk of accidental usage of dirty editted APCs
var/opened = APC_COVER_CLOSED
var/shorted = 0
var/lighting = 3
var/equipment = 3
var/environ = 3
var/operating = TRUE
var/charging = APC_NOT_CHARGING
var/chargemode = 1
var/chargecount = 0
var/locked = TRUE
var/coverlocked = TRUE
var/aidisabled = 0
var/tdir = null
var/obj/machinery/power/terminal/terminal = null
var/lastused_light = 0
var/lastused_equip = 0
var/lastused_environ = 0
var/lastused_total = 0
var/main_status = 0
powernet = 0 // set so that APCs aren't found as powernet nodes //Hackish, Horrible, was like this before I changed it :(
var/malfhack = 0 //New var for my changes to AI malf. --NeoFite
var/mob/living/silicon/ai/malfai = null //See above --NeoFite
var/has_electronics = APC_ELECTRONICS_MISSING // 0 - none, 1 - plugged in, 2 - secured by screwdriver
var/overload = 1 //used for the Blackout malf module
var/beenhit = 0 // used for counting how many times it has been hit, used for Aliens at the moment
var/mob/living/silicon/ai/occupier = null
var/transfer_in_progress = FALSE //Is there an AI being transferred out of us?
var/obj/item/clockwork/integration_cog/integration_cog //Is there a cog siphoning power?
var/longtermpower = 10
var/auto_name = 0
var/failure_timer = 0
var/force_update = 0
var/emergency_lights = FALSE
var/nightshift_lights = FALSE
var/last_light_switch = 0
var/update_state = -1
var/update_overlay = -1
var/icon_update_needed = FALSE
var/obj/machinery/computer/apc_control/remote_control = null
/obj/machinery/power/apc/unlocked
locked = FALSE
/obj/machinery/power/apc/syndicate //general syndicate access
req_access = list(ACCESS_SYNDICATE)
/obj/machinery/power/apc/away //general away mission access
req_access = list(ACCESS_RUINS_GENERAL)
/obj/machinery/power/apc/highcap/five_k
cell_type = /obj/item/stock_parts/cell/upgraded/plus
/obj/machinery/power/apc/highcap/ten_k
cell_type = /obj/item/stock_parts/cell/high
/obj/machinery/power/apc/highcap/fifteen_k
cell_type = /obj/item/stock_parts/cell/high/plus
/obj/machinery/power/apc/auto_name
auto_name = TRUE
/obj/machinery/power/apc/auto_name/north //Pixel offsets get overwritten on New()
dir = NORTH
pixel_y = 23
/obj/machinery/power/apc/auto_name/south
dir = SOUTH
pixel_y = -23
/obj/machinery/power/apc/auto_name/east
dir = EAST
pixel_x = 24
/obj/machinery/power/apc/auto_name/west
dir = WEST
pixel_x = -25
/obj/machinery/power/apc/get_cell()
return cell
/obj/machinery/power/apc/connect_to_network()
//Override because the APC does not directly connect to the network; it goes through a terminal.
//The terminal is what the power computer looks for anyway.
if(terminal)
terminal.connect_to_network()
/obj/machinery/power/apc/New(turf/loc, ndir, building=0, mob/user)
//if (!req_access)
//req_access = list(ACCESS_ENGINE_EQUIP) // Yogs -- Commented out to allow for use of req_one_access. Also this is just generally bad and the guy who wrote this doesn't get OOP
if (!armor)
armor = list(MELEE = 20, BULLET = 20, LASER = 10, ENERGY = 10, BOMB = 30, BIO = 100, RAD = 100, FIRE = 90, ACID = 50, ELECTRIC = 100)
..()
GLOB.apcs_list += src
wires = new /datum/wires/apc(src)
// offset 24 pixels in direction of dir
// this allows the APC to be embedded in a wall, yet still inside an area
if (building)
setDir(ndir)
src.tdir = dir // to fix Vars bug
setDir(SOUTH)
if(auto_name)
name = "\improper [get_area(src)] APC"
switch(tdir)
if(NORTH)
if((pixel_y != initial(pixel_y)) && (pixel_y != 23))
log_mapping("APC: ([src]) at [AREACOORD(src)] with dir ([tdir] | [uppertext(dir2text(tdir))]) has pixel_y value ([pixel_y] - should be 23.)")
pixel_y = 23
if(SOUTH)
if((pixel_y != initial(pixel_y)) && (pixel_y != -23))
log_mapping("APC: ([src]) at [AREACOORD(src)] with dir ([tdir] | [uppertext(dir2text(tdir))]) has pixel_y value ([pixel_y] - should be -23.)")
pixel_y = -23
if(EAST)
if((pixel_y != initial(pixel_x)) && (pixel_x != 24))
log_mapping("APC: ([src]) at [AREACOORD(src)] with dir ([tdir] | [uppertext(dir2text(tdir))]) has pixel_x value ([pixel_x] - should be 24.)")
pixel_x = 24
if(WEST)
if((pixel_y != initial(pixel_x)) && (pixel_x != -25))
log_mapping("APC: ([src]) at [AREACOORD(src)] with dir ([tdir] | [uppertext(dir2text(tdir))]) has pixel_x value ([pixel_x] - should be -25.)")
pixel_x = -25
if (building)
if(user)
area = get_area(user)
else
area = get_area(src)
opened = APC_COVER_OPENED
operating = FALSE
name = "[area.name] APC"
stat |= MAINT
addtimer(CALLBACK(src, PROC_REF(update)), 5)
update_appearance(UPDATE_ICON)
/obj/machinery/power/apc/Destroy()
GLOB.apcs_list -= src
if(malfai && operating)
malfai.malf_picker.processing_time = clamp(malfai.malf_picker.processing_time - 10,0,1000)
area.power_light = FALSE
area.power_equip = FALSE
area.power_environ = FALSE
area.poweralert(1, src)
area.power_change()
if(occupier)
malfvacate(1)
QDEL_NULL(wires)
if(cell)
qdel(cell)
if(terminal)
disconnect_terminal()
. = ..()
/obj/machinery/power/apc/handle_atom_del(atom/A)
if(A == cell)
cell = null
update_appearance()
updateUsrDialog()
/obj/machinery/power/apc/proc/make_terminal()
// create a terminal object at the same position as original turf loc
// wires will attach to this
terminal = new/obj/machinery/power/terminal(src.loc)
terminal.setDir(tdir)
terminal.master = src
/obj/machinery/power/apc/Initialize(mapload)
. = ..()
if(!mapload)
return
has_electronics = APC_ELECTRONICS_SECURED
// is starting with a power cell installed, create it and set its charge level
if(cell_type)
cell = new cell_type
cell.charge = start_charge * cell.maxcharge / 100 // (convert percentage to actual value)
var/area/A = get_area(loc)
//if area isn't specified use current
if(areastring)
src.area = get_area_instance_from_text(areastring)
if(!src.area)
src.area = A
stack_trace("Bad areastring path for [src], [src.areastring]")
else if(isarea(A) && src.areastring == null)
src.area = A
if(prob(10))
locked = FALSE
make_terminal()
addtimer(CALLBACK(src, PROC_REF(update)), 5)
update_appearance()
/obj/machinery/power/apc/examine(mob/user)
. = ..()
if(stat & BROKEN)
return
if(opened)
if(has_electronics && terminal)
. += "The cover is [opened==APC_COVER_REMOVED?"removed":"open"] and the power cell is [ cell ? "installed" : "missing"]."
else
. += {"It's [ !terminal ? "not" : "" ] wired up.\n
The electronics are[!has_electronics?"n't":""] installed."}
if(user.Adjacent(src) && integration_cog)
. += span_warning("[src]'s innards have been replaced by strange brass machinery!")
else
if (stat & MAINT)
. += "The cover is closed. Something is wrong with it. It doesn't work."
else if (malfhack)
. += "The cover is broken. It may be hard to force it open."
else
. += "The cover is closed."
if(integration_cog && is_servant_of_ratvar(user))
. += span_brass("There is an integration cog installed!")
. += span_notice("Right-Click the APC to [ locked ? "unlock" : "lock"] the interface.")
if(issilicon(user))
. += span_notice("Ctrl-Click the APC to switch the breaker [ operating ? "off" : "on"].")
/obj/machinery/power/apc/exchange_parts(mob/user, obj/item/storage/part_replacer/W)
if(!istype(W))
return FALSE
if(!opened && !W.works_from_distance)
return FALSE
var/current_cell_rating = cell ? cell.get_part_rating() : -1
var/best_cell_rating = current_cell_rating
var/obj/item/stock_parts/cell/best_cell
for(var/C in W.contents)
var/obj/item/stock_parts/cell/cell = C
if (!cell || !istype(cell))
continue
var/cell_rating = cell.get_part_rating()
if (cell_rating > best_cell_rating || (cell_rating == best_cell_rating && cell.charge > best_cell.charge))
best_cell_rating = cell_rating
best_cell = cell
if (best_cell)
if (cell)
SEND_SIGNAL(W, COMSIG_TRY_STORAGE_INSERT, cell, null, null, TRUE)
to_chat(user, span_notice("[capitalize(cell.name)] replaced with [best_cell.name]."))
best_cell.forceMove(src)
var/amount_to_charge = min(best_cell.maxcharge - best_cell.charge, cell.charge)
if (cell.use(amount_to_charge))
best_cell.give(amount_to_charge)
cell = best_cell
W.play_rped_sound()
/obj/machinery/power/apc/update_appearance(updates = check_updates())
icon_update_needed = FALSE
if(!updates)
return
. = ..()
// And now, separately for cleanness, the lighting changing
if(update_state & UPSTATE_ALLGOOD)
switch(charging)
if(APC_NOT_CHARGING)
light_color = LIGHT_COLOR_RED
if(APC_CHARGING)
light_color = LIGHT_COLOR_BLUE
if(APC_FULLY_CHARGED)
light_color = LIGHT_COLOR_GREEN
set_light(light_on_range)
else if(update_state & UPSTATE_BLUESCREEN)
light_color = LIGHT_COLOR_BLUE
set_light(light_on_range)
else
set_light(0)
// update the APC icon to show the three base states
// also add overlays for indicator lights
/obj/machinery/power/apc/update_icon_state()
. = ..()
if(update_state & UPSTATE_ALLGOOD)
icon_state = "apc0"
else if(update_state & (UPSTATE_OPENED1|UPSTATE_OPENED2))
var/basestate = "apc[ cell ? "2" : "1" ]"
if(update_state & UPSTATE_OPENED1)
if(update_state & (UPSTATE_MAINT|UPSTATE_BROKE))
icon_state = "apcmaint" //disabled APC cannot hold cell
else
icon_state = basestate
else if(update_state & UPSTATE_OPENED2)
if (update_state & UPSTATE_BROKE || malfhack)
icon_state = "[basestate]-b-nocover"
else
icon_state = "[basestate]-nocover"
else if(update_state & UPSTATE_BROKE)
icon_state = "apc-b"
else if(update_state & UPSTATE_BLUESCREEN)
icon_state = "apcemag"
else if(update_state & UPSTATE_WIREEXP)
icon_state = "apcewires"
else if(update_state & UPSTATE_MAINT)
icon_state = "apc0"
/obj/machinery/power/apc/update_overlays()
. = ..()
if(!(update_state & UPSTATE_ALLGOOD))
return
if(!(stat & (BROKEN|MAINT)) && update_state & UPSTATE_ALLGOOD)
. += mutable_appearance(icon, "apcox-[locked]")
. += emissive_appearance(icon, "apcox-[locked]", src)
. += mutable_appearance(icon, "apco3-[charging]")
. += emissive_appearance(icon, "apco3-[charging]", src)
if(operating)
. += mutable_appearance(icon, "apco0-[equipment]")
. += emissive_appearance(icon, "apco0-[equipment]", src)
. += mutable_appearance(icon, "apco1-[lighting]")
. += emissive_appearance(icon, "apco1-[lighting]", src)
. += mutable_appearance(icon, "apco2-[environ]")
. += emissive_appearance(icon, "apco2-[environ]", src)
/obj/machinery/power/apc/proc/check_updates()
var/last_update_state = update_state
var/last_update_overlay = update_overlay
update_state = 0
update_overlay = 0
if(cell)
update_state |= UPSTATE_CELL_IN
if(stat & BROKEN)
update_state |= UPSTATE_BROKE
if(stat & MAINT)
update_state |= UPSTATE_MAINT
if(opened)
if(opened==APC_COVER_OPENED)
update_state |= UPSTATE_OPENED1
if(opened==APC_COVER_REMOVED)
update_state |= UPSTATE_OPENED2
else if(obj_flags & EMAGGED)
update_state |= UPSTATE_BLUESCREEN
else if(panel_open)
update_state |= UPSTATE_WIREEXP
if(update_state <= 1)
update_state |= UPSTATE_ALLGOOD
if(operating)
update_overlay |= APC_UPOVERLAY_OPERATING
if(update_state & UPSTATE_ALLGOOD)
if(locked)
update_overlay |= APC_UPOVERLAY_LOCKED
if(!charging)
update_overlay |= APC_UPOVERLAY_CHARGEING0
else if(charging == APC_CHARGING)
update_overlay |= APC_UPOVERLAY_CHARGEING1
else if(charging == APC_FULLY_CHARGED)
update_overlay |= APC_UPOVERLAY_CHARGEING2
if (!equipment)
update_overlay |= APC_UPOVERLAY_EQUIPMENT0
else if(equipment == 1)
update_overlay |= APC_UPOVERLAY_EQUIPMENT1
else if(equipment == 2)
update_overlay |= APC_UPOVERLAY_EQUIPMENT2
if(!lighting)
update_overlay |= APC_UPOVERLAY_LIGHTING0
else if(lighting == 1)
update_overlay |= APC_UPOVERLAY_LIGHTING1
else if(lighting == 2)
update_overlay |= APC_UPOVERLAY_LIGHTING2
if(!environ)
update_overlay |= APC_UPOVERLAY_ENVIRON0
else if(environ==1)
update_overlay |= APC_UPOVERLAY_ENVIRON1
else if(environ==2)
update_overlay |= APC_UPOVERLAY_ENVIRON2
if(last_update_state == update_state && last_update_overlay == update_overlay)
return
var/results = NONE
if(last_update_state != update_state)
results ^= UPDATE_ICON_STATE
if(last_update_overlay != update_overlay)
results ^= UPDATE_OVERLAYS
return results
// Used in process so it doesn't update the icon too much
/obj/machinery/power/apc/proc/queue_icon_update()
icon_update_needed = TRUE
//attack with an item - open/close cover, insert cell, or (un)lock interface
/obj/machinery/power/apc/crowbar_act(mob/user, obj/item/W)
. = TRUE
if (opened)
if (has_electronics == APC_ELECTRONICS_INSTALLED)
if (terminal)
to_chat(user, span_warning("Disconnect the wires first!"))
return
W.play_tool_sound(src)
to_chat(user, span_notice("You attempt to remove the power control board...") )
if(W.use_tool(src, user, 50))
if (has_electronics == APC_ELECTRONICS_INSTALLED)
has_electronics = APC_ELECTRONICS_MISSING
if (stat & BROKEN)
user.visible_message(\
"[user.name] has broken the charred power control board inside [src.name]!", //Yogs -- Makes this message a bit more clear
span_notice("You break the charred power control board and remove the remains."),
span_italics("You hear a crack."))
return
else if (obj_flags & EMAGGED)
obj_flags &= ~EMAGGED
user.visible_message(\
"[user.name] has discarded a sparking power control board from [src.name]!", // Yogs -- Makes this message make more sense.
span_notice("You discard the emagged power control board."))
return
else if (malfhack)
user.visible_message(\
"[user.name] has discarded a strange-looking power control board from [src.name]!", //Yogs -- Makes this message make more sense.
span_notice("You discard the strangely programmed board."))
malfai = null
malfhack = 0
return
else
user.visible_message(\
"[user.name] has removed the power control board from [src.name]!",\
span_notice("You remove the power control board."))
new /obj/item/electronics/apc(loc)
return
else if(integration_cog)
user.visible_message(span_notice("[user] starts prying [integration_cog] from [src]..."), \
span_notice("You painstakingly start tearing [integration_cog] out of [src]'s guts..."))
W.play_tool_sound(src)
if(W.use_tool(src, user, 100))
user.visible_message(span_notice("[user] destroys [integration_cog] in [src]!"), \
span_notice("[integration_cog] comes free with a clank and snaps in two as the machinery returns to normal!"))
playsound(src, 'sound/items/deconstruct.ogg', 50, TRUE)
QDEL_NULL(integration_cog)
return
else if (opened!=APC_COVER_REMOVED)
opened = APC_COVER_CLOSED
coverlocked = TRUE //closing cover relocks it
update_appearance()
return
else if (!(stat & BROKEN))
if(coverlocked && !(stat & MAINT)) // locked...
to_chat(user, span_warning("The cover is locked and cannot be opened!"))
return
else if (panel_open)
to_chat(user, span_warning("Exposed wires prevents you from opening it!"))
return
else
opened = APC_COVER_OPENED
update_appearance()
return
else
W.play_tool_sound(src)
to_chat(user, span_notice("You attempt to pry off the broken cover..."))
if(W.use_tool(src, user, 3 SECONDS))
W.play_tool_sound(src)
to_chat(user, span_notice("You pry the broken cover off of [src]."))
opened = APC_COVER_REMOVED
update_appearance()
return
/obj/machinery/power/apc/screwdriver_act(mob/living/user, obj/item/W)
if(..())
return TRUE
. = TRUE
if(opened)
if(cell)
user.visible_message("[user] removes \the [cell] from [src]!",span_notice("You remove \the [cell]."))
var/turf/T = get_turf(user)
cell.forceMove(T)
cell.update_appearance()
cell = null
charging = APC_NOT_CHARGING
update_appearance()
return
else
switch (has_electronics)
if (APC_ELECTRONICS_INSTALLED)
has_electronics = APC_ELECTRONICS_SECURED
stat &= ~MAINT
W.play_tool_sound(src)
to_chat(user, span_notice("You screw the circuit electronics into place."))
if (APC_ELECTRONICS_SECURED)
has_electronics = APC_ELECTRONICS_INSTALLED
stat |= MAINT
W.play_tool_sound(src)
to_chat(user, span_notice("You unfasten the electronics."))
else
to_chat(user, span_warning("There is nothing to secure!"))
return
update_appearance()
else if(obj_flags & EMAGGED)
to_chat(user, span_warning("The interface is broken!"))
return
else
panel_open = !panel_open
to_chat(user, span_notice("The wires have been [panel_open ? "exposed" : "unexposed"]."))
update_appearance()
/obj/machinery/power/apc/wirecutter_act(mob/living/user, obj/item/W)
if (terminal && opened)
terminal.dismantle(user, W)
return TRUE
/obj/machinery/power/apc/welder_act(mob/living/user, obj/item/W)
if (opened && !has_electronics && !terminal)
if(!W.tool_start_check(user, amount=3))
return
user.visible_message("[user.name] welds [src].", \
span_notice("You start welding the APC frame..."), \
span_italics("You hear welding."))
if(W.use_tool(src, user, 50, volume=50, amount=3))
if ((stat & BROKEN) || opened==APC_COVER_REMOVED)
new /obj/item/stack/sheet/metal(loc)
user.visible_message(\
"[user.name] has cut [src] apart with [W].",\
span_notice("You disassembled the broken APC frame."))
else
new /obj/item/wallframe/apc(loc)
user.visible_message(\
"[user.name] has cut [src] from the wall with [W].",\
span_notice("You cut the APC frame from the wall."))
qdel(src)
return TRUE
/obj/machinery/power/apc/attackby(obj/item/W, mob/living/user, params)
if(issilicon(user) && get_dist(src,user)>1)
return attack_hand(user)
if (istype(W, /obj/item/stock_parts/cell) && opened)
if(cell)
to_chat(user, span_warning("There is a power cell already installed!"))
return
else
if (stat & MAINT)
to_chat(user, span_warning("There is no connector for your power cell!"))
return
if(!user.transferItemToLoc(W, src))
return
cell = W
user.visible_message(\
"[user.name] has inserted the power cell to [src.name]!",\
span_notice("You insert the power cell."))
chargecount = 0
update_appearance()
else if (W.GetID())
togglelock(user)
else if (istype(W, /obj/item/stack/cable_coil) && opened)
var/turf/host_turf = get_turf(src)
if(!host_turf)
CRASH("attackby on APC when it's not on a turf")
if(host_turf.underfloor_accessibility < UNDERFLOOR_INTERACTABLE)
to_chat(user, span_warning("You must remove the floor plating in front of the APC first!"))
return
else if (terminal)
to_chat(user, span_warning("This APC is already wired!"))
return
else if (!has_electronics)
to_chat(user, span_warning("There is nothing to wire!"))
return
var/obj/item/stack/cable_coil/C = W
if(C.get_amount() < 10)
to_chat(user, span_warning("You need ten lengths of cable for APC!"))
return
user.visible_message("[user.name] adds cables to the APC frame.", \
span_notice("You start adding cables to the APC frame..."))
playsound(src.loc, 'sound/items/deconstruct.ogg', 50, 1)
if(do_after(user, 2 SECONDS, src))
if (C.get_amount() < 10 || !C)
return
if (C.get_amount() >= 10 && !terminal && opened && has_electronics)
var/turf/T = get_turf(src)
var/obj/structure/cable/N = T.get_cable_node()
if (prob(50) && electrocute_mob(usr, N, N, 1, TRUE))
do_sparks(5, TRUE, src)
return
C.use(10)
to_chat(user, span_notice("You add cables to the APC frame."))
make_terminal()
terminal.connect_to_network()
else if (istype(W, /obj/item/electronics/apc) && opened)
if (has_electronics)
to_chat(user, span_warning("There is already a board inside the [src]!"))
return
else if (stat & BROKEN)
to_chat(user, span_warning("You cannot put the board inside, the frame is damaged!"))
return
user.visible_message("[user.name] inserts the power control board into [src].", \
span_notice("You start to insert the power control board into the frame..."))
playsound(src.loc, 'sound/items/deconstruct.ogg', 50, 1)
if(do_after(user, 1 SECONDS, src))
if(!has_electronics)
has_electronics = APC_ELECTRONICS_INSTALLED
locked = FALSE
to_chat(user, span_notice("You place the power control board inside the frame."))
qdel(W)
else if(istype(W, /obj/item/electroadaptive_pseudocircuit) && opened)
var/obj/item/electroadaptive_pseudocircuit/P = W
if(!has_electronics)
if(stat & BROKEN)
to_chat(user, span_warning("[src]'s frame is too damaged to support a circuit."))
return
if(!P.adapt_circuit(user, 50))
return
user.visible_message(span_notice("[user] fabricates a circuit and places it into [src]."), \
span_notice("You adapt a power control board and click it into place in [src]'s guts."))
has_electronics = APC_ELECTRONICS_INSTALLED
locked = FALSE
else if(!cell)
if(stat & MAINT)
to_chat(user, span_warning("There's no connector for a power cell."))
return
if(!P.adapt_circuit(user, 500))
return
var/obj/item/stock_parts/cell/crap/empty/C = new(src)
C.forceMove(src)
cell = C
chargecount = 0
user.visible_message(span_notice("[user] fabricates a weak power cell and places it into [src]."), \
span_warning("Your [P.name] whirrs with strain as you create a weak power cell and place it into [src]!"))
update_appearance()
else
to_chat(user, span_warning("[src] has both electronics and a cell."))
return
else if (istype(W, /obj/item/wallframe/apc) && opened)
if (!(stat & BROKEN || opened==APC_COVER_REMOVED || atom_integrity < max_integrity)) // There is nothing to repair
to_chat(user, span_warning("You found no reason for repairing this APC"))
return
if (!(stat & BROKEN) && opened==APC_COVER_REMOVED) // Cover is the only thing broken, we do not need to remove elctronicks to replace cover
user.visible_message("[user.name] replaces missing APC's cover.",\
span_notice("You begin to replace APC's cover..."))
if(do_after(user, 2 SECONDS, src)) // replacing cover is quicker than replacing whole frame
to_chat(user, span_notice("You replace missing APC's cover."))
qdel(W)
opened = APC_COVER_OPENED
update_appearance()
return
if (has_electronics)
to_chat(user, span_warning("You cannot repair this APC until you remove the electronics still inside!"))
return
user.visible_message("[user.name] replaces the damaged APC frame with a new one.",\
span_notice("You begin to replace the damaged APC frame..."))
if(do_after(user, 5 SECONDS, src))
to_chat(user, span_notice("You replace the damaged APC frame with a new one."))
qdel(W)
stat &= ~BROKEN
update_integrity(max_integrity)
if (opened==APC_COVER_REMOVED)
opened = APC_COVER_OPENED
update_appearance()
else if(istype(W, /obj/item/clockwork/integration_cog) && is_servant_of_ratvar(user))
if(integration_cog)
to_chat(user, span_warning("This APC already has a cog."))
return
if(!opened)
user.visible_message(span_warning("[user] slices [src]'s cover lock, and it swings wide open!"), \
span_alloy("You slice [src]'s cover lock apart with [W], and the cover swings open."))
opened = APC_COVER_OPENED
update_appearance()
else
user.visible_message(span_warning("[user] presses [W] into [src]!"), \
span_alloy("You hold [W] in place within [src], and it slowly begins to warm up..."))
playsound(src, 'sound/machines/click.ogg', 50, TRUE)
if(!do_after(user, 7 SECONDS, src))
return
user.visible_message(span_warning("[user] installs [W] in [src]!"), \
"[span_alloy("Replicant alloy rapidly covers the APC's innards, replacing the machinery.")]<br>\
[span_brass("This APC will now passively provide power for the cult!")]")
playsound(user, 'sound/machines/clockcult/integration_cog_install.ogg', 50, TRUE)
user.transferItemToLoc(W, src)
integration_cog = W
START_PROCESSING(SSfastprocess, W)
playsound(src, 'sound/machines/clockcult/steam_whoosh.ogg', 50, FALSE)
opened = APC_COVER_CLOSED
locked = FALSE
update_appearance()
return
else if(istype(W, /obj/item/apc_powercord))
return //because we put our fancy code in the right places, and this is all in the powercord's afterattack()
else if(panel_open && !opened && is_wire_tool(W))
wires.interact(user)
else
return ..()
/obj/machinery/power/apc/AltClick(mob/user)
. = ..()
if(!user.canUseTopic(src, !issilicon(user)) || !isturf(loc))
return
if(ethereal_act(user))
return
togglelock(user)
/obj/machinery/power/apc/rcd_vals(mob/user, obj/item/construction/rcd/the_rcd)
if(the_rcd.upgrade & RCD_UPGRADE_SIMPLE_CIRCUITS)
if(!has_electronics)
if(stat & BROKEN)
to_chat(user, span_warning("[src]'s frame is too damaged to support a circuit."))
return FALSE
return list("mode" = RCD_UPGRADE_SIMPLE_CIRCUITS, "delay" = 20, "cost" = 1)
else if(!cell)
if(stat & MAINT)
to_chat(user, span_warning("There's no connector for a power cell."))
return FALSE
return list("mode" = RCD_UPGRADE_SIMPLE_CIRCUITS, "delay" = 50, "cost" = 10) //16 for a wall
else
to_chat(user, span_warning("[src] has both electronics and a cell."))
return FALSE
return FALSE
/obj/machinery/power/apc/rcd_act(mob/user, obj/item/construction/rcd/the_rcd, passed_mode)
switch(passed_mode)
if(RCD_UPGRADE_SIMPLE_CIRCUITS)
if(!has_electronics)
if(stat & BROKEN)
to_chat(user, span_warning("[src]'s frame is too damaged to support a circuit."))
return
user.visible_message(span_notice("[user] fabricates a circuit and places it into [src]."), \
span_notice("You adapt a power control board and click it into place in [src]'s guts."))
has_electronics = TRUE
locked = TRUE
return TRUE
else if(!cell)
if(stat & MAINT)
to_chat(user, span_warning("There's no connector for a power cell."))
return FALSE
var/obj/item/stock_parts/cell/crap/empty/C = new(src)
C.forceMove(src)
cell = C
chargecount = 0
user.visible_message(span_notice("[user] fabricates a weak power cell and places it into [src]."), \
span_warning("Your [the_rcd.name] whirrs with strain as you create a weak power cell and place it into [src]!"))
update_appearance()
return TRUE
else
to_chat(user, span_warning("[src] has both electronics and a cell."))
return FALSE
return FALSE
/obj/machinery/power/apc/proc/togglelock(mob/living/user)
if(obj_flags & EMAGGED)
to_chat(user, span_warning("The interface is broken!"))
else if(opened)
to_chat(user, span_warning("You must close the cover to swipe an ID card!"))
else if(panel_open)
to_chat(user, span_warning("You must close the panel!"))
else if(stat & (BROKEN|MAINT))
to_chat(user, span_warning("Nothing happens!"))
else
if((allowed(usr) && !wires.is_cut(WIRE_IDSCAN) && !malfhack) || integration_cog)
locked = !locked
to_chat(user, span_notice("You [ locked ? "lock" : "unlock"] the APC interface."))
update_appearance()
updateUsrDialog()
else
to_chat(user, span_warning("Access denied."))
/obj/machinery/power/apc/proc/toggle_lights(mob/living/user)
if(last_light_switch > world.time - 10 SECONDS) //~10 seconds between each toggle to prevent spamming
to_chat(usr, span_warning("[src]'s lighting circuit breaker is still cycling!"))
return
last_light_switch = world.time
area.lightswitch = !area.lightswitch
area.update_appearance()
for(var/obj/machinery/light_switch/L in area)
L.update_appearance()
area.power_change()
/obj/machinery/power/apc/proc/toggle_nightshift_lights(mob/living/user)
if(last_light_switch > world.time - 10 SECONDS) //~10 seconds between each toggle to prevent spamming
to_chat(usr, span_warning("[src]'s lighting circuit breaker is still cycling!"))
return
last_light_switch = world.time
set_nightshift(!nightshift_lights)
/obj/machinery/power/apc/run_atom_armor(damage_amount, damage_type, damage_flag = 0, attack_dir)
if(damage_flag == MELEE && damage_amount < 10 && (!(stat & BROKEN) || malfai))
return 0
. = ..()
/obj/machinery/power/apc/atom_break(damage_flag)
. = ..()
if(.)
set_broken()
/obj/machinery/power/apc/deconstruct(disassembled = TRUE)
if(!(flags_1 & NODECONSTRUCT_1))
if(!(stat & BROKEN))
set_broken()
if(opened != APC_COVER_REMOVED)
opened = APC_COVER_REMOVED
coverlocked = FALSE
visible_message(span_warning("The APC cover is knocked down!"))
update_appearance()
/obj/machinery/power/apc/emag_act(mob/user, obj/item/card/emag/emag_card)
if((obj_flags & EMAGGED) || malfhack)
return FALSE
if(opened)
to_chat(user, span_warning("You must close the cover to swipe an ID card!"))
return FALSE
if(panel_open)
to_chat(user, span_warning("You must close the panel first!"))
return FALSE
if(stat & (BROKEN|MAINT))
to_chat(user, span_warning("Nothing happens!"))
return FALSE
flick("apc-spark", src)
playsound(src, "sparks", 75, 1)
obj_flags |= EMAGGED
locked = FALSE
to_chat(user, span_notice("You emag the APC interface."))
update_appearance()
return TRUE
// attack with hand - remove cell (if cover open) or interact with the APC
/obj/machinery/power/apc/attack_hand(mob/living/user, modifiers)
. = ..()
if(.)
return
if(opened && (!issilicon(user)))
if(cell)
user.visible_message("[user] removes \the [cell] from [src]!",span_notice("You remove \the [cell]."))
user.put_in_hands(cell)
cell.update_appearance()
src.cell = null
charging = APC_NOT_CHARGING
src.update_appearance()
return
if((stat & MAINT) && !opened) //no board; no interface
return
/obj/machinery/power/apc/attack_hand_secondary(mob/living/user, modifiers)
togglelock(user)
return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN
/obj/machinery/power/apc/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "Apc", name)
ui.open()
/obj/machinery/power/apc/ui_data(mob/user)
var/list/data = list(
"locked" = locked && !(integration_cog && is_servant_of_ratvar(user)),
"failTime" = failure_timer,
"isOperating" = operating,
"externalPower" = main_status,
"powerCellStatus" = cell ? cell.percent() : null,
"chargeMode" = chargemode,
"chargingStatus" = charging,
"totalLoad" = DisplayPower(lastused_total),
"coverLocked" = coverlocked,
"siliconUser" = user.has_unlimited_silicon_privilege || user.using_power_flow_console(),
"malfStatus" = get_malf_status(user),
"lights" = area.lightswitch,
"emergencyLights" = !emergency_lights,
"nightshiftLights" = nightshift_lights,
"powerChannels" = list(
list(
"title" = "Equipment",
"powerLoad" = DisplayPower(lastused_equip),
"status" = equipment,
"topicParams" = list(
"auto" = list("eqp" = 3),
"on" = list("eqp" = 2),
"off" = list("eqp" = 1)
)
),
list(
"title" = "Lighting",
"powerLoad" = DisplayPower(lastused_light),
"status" = lighting,
"topicParams" = list(
"auto" = list("lgt" = 3),
"on" = list("lgt" = 2),
"off" = list("lgt" = 1)
)
),
list(
"title" = "Environment",
"powerLoad" = DisplayPower(lastused_environ),
"status" = environ,
"topicParams" = list(
"auto" = list("env" = 3),
"on" = list("env" = 2),
"off" = list("env" = 1)
)
)
)
)
return data
/obj/machinery/power/apc/proc/get_malf_status(mob/living/silicon/ai/malf)
if(istype(malf) && malf.malf_picker)
if(malfai == (malf.parent || malf))
if(occupier == malf)
return 3 // 3 = User is shunted in this APC
else if(istype(malf.loc, /obj/machinery/power/apc))
return 4 // 4 = User is shunted in another APC
else
return 2 // 2 = APC hacked by user, and user is in its core.
else
return 1 // 1 = APC not hacked.
else
return 0 // 0 = User is not a Malf AI
/obj/machinery/power/apc/proc/report()
return "[area.name] : [equipment]/[lighting]/[environ] ([lastused_equip+lastused_light+lastused_environ]) : [cell? cell.percent() : "N/C"] ([charging])"