-
Notifications
You must be signed in to change notification settings - Fork 555
/
apc.dm
1379 lines (1199 loc) · 45.1 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
#define APC_WIRE_MAIN_POWER 1
#define APC_WIRE_IDSCAN 2
GLOBAL_LIST_INIT(apc_wire_descriptions, list(
APC_WIRE_MAIN_POWER = "Main power",
APC_WIRE_IDSCAN = "ID scanner"
))
#define APC_COVER_CLOSED 0
#define APC_COVER_OPEN 1
#define APC_COVER_REMOVED 2
// APC charging status:
/// The APC is not charging.
#define APC_NOT_CHARGING 0
/// The APC is charging.
#define APC_CHARGING 1
/// The APC is fully charged.
#define APC_FULLY_CHARGED 2
//update_state
#define UPSTATE_CELL_IN 1
#define UPSTATE_OPENED1 2
#define UPSTATE_OPENED2 4
#define UPSTATE_MAINT 8
#define UPSTATE_BROKE 16
#define UPSTATE_BLUESCREEN 32
#define UPSTATE_WIREEXP 64
#define UPSTATE_ALLGOOD 128
//update_overlay
#define APC_UPOVERLAY_CHARGEING0 1
#define APC_UPOVERLAY_CHARGEING1 2
#define APC_UPOVERLAY_CHARGEING2 4
#define APC_UPOVERLAY_EQUIPMENT0 8
#define APC_UPOVERLAY_EQUIPMENT1 16
#define APC_UPOVERLAY_EQUIPMENT2 32
#define APC_UPOVERLAY_LIGHTING0 64
#define APC_UPOVERLAY_LIGHTING1 128
#define APC_UPOVERLAY_LIGHTING2 256
#define APC_UPOVERLAY_ENVIRON0 512
#define APC_UPOVERLAY_ENVIRON1 1024
#define APC_UPOVERLAY_ENVIRON2 2048
#define APC_UPOVERLAY_LOCKED 4096
#define APC_UPOVERLAY_OPERATING 8192
#define APC_UPDATE_ICON_COOLDOWN 100 //10 seconds
//The Area Power Controller (APC), formerly Power Distribution Unit (PDU)
//One per area, needs wire conection to power network
//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
//NOTE: STUFF STOLEN FROM AIRLOCK.DM thx
/obj/structure/machinery/power/apc/weak
cell_type = /obj/item/cell
/obj/structure/machinery/power/apc/high
cell_type = /obj/item/cell/high
/obj/structure/machinery/power/apc/super
cell_type = /obj/item/cell/super
/obj/structure/machinery/power/apc/hyper
cell_type = /obj/item/cell/hyper
/obj/structure/machinery/power/apc
name = "area power controller"
desc = "A control terminal for the area electrical systems."
icon = 'icons/obj/structures/machinery/power.dmi'
icon_state = "apc_mapicon"
anchored = TRUE
use_power = USE_POWER_NONE
req_one_access = list(ACCESS_CIVILIAN_ENGINEERING, ACCESS_MARINE_ENGINEERING)
unslashable = TRUE
unacidable = TRUE
var/area/area
var/areastring = null
var/obj/item/cell/cell
var/start_charge = 90 //Initial cell charge %
var/cell_type = /obj/item/cell/apc/empty //0 = no cell, 1 = regular, 2 = high-cap (x5) <- old, now it's just 0 = no cell, otherwise dictate cellcapacity by changing this value. 1 used to be 1000, 2 was 2500
var/opened = APC_COVER_CLOSED
var/shorted = 0
var/lighting = 3
var/equipment = 3
var/environ = 3
var/operating = 1
var/charging = APC_NOT_CHARGING
var/chargemode = 1
var/chargecount = 0
var/locked = 1
var/coverlocked = 1
var/aidisabled = 0
var/tdir = null
var/obj/structure/machinery/power/terminal/terminal = null
var/lastused_light = 0
var/lastused_equip = 0
var/lastused_environ = 0
var/lastused_oneoff = 0
var/lastused_total = 0
var/main_status = 0
var/wiresexposed = 0
var/apcwires = 3
powernet = 0 //Set so that APCs aren't found as powernet nodes //Hackish, Horrible, was like this before I changed it :(
var/debug = 0
var/autoflag = 0 // 0 = off, 1 = eqp and lights off, 2 = eqp off, 3 = all on.
var/has_electronics = 0 // 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/longtermpower = 10
var/update_state = -1
var/update_overlay = -1
var/global/status_overlays = 0
var/updating_icon = 0
var/crash_break_probability = 85 //Probability of APC being broken by a shuttle crash on the same z-level
var/global/list/status_overlays_lock
var/global/list/status_overlays_charging
var/global/list/status_overlays_equipment
var/global/list/status_overlays_lighting
var/global/list/status_overlays_environ
var/printout = FALSE
power_machine = TRUE
appearance_flags = TILE_BOUND
/obj/structure/machinery/power/apc/Initialize(mapload, ndir, building=0)
. = ..()
//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)
set_pixel_location()
if(building == 0)
init()
else
area = get_area(src)
opened = APC_COVER_OPEN
operating = 0
name = "\improper [area.name] APC"
stat |= MAINT
update_icon()
addtimer(CALLBACK(src, PROC_REF(update)), 5)
start_processing()
if(!start_charge && is_ground_level(z) && prob(10))
set_broken()
/obj/structure/machinery/power/apc/set_pixel_location()
tdir = dir //To fix Vars bug
setDir(SOUTH)
pixel_x = (tdir & 3) ? 0 : (tdir == 4 ? 24 : -24)
pixel_y = (tdir & 3) ? (tdir == 1 ? 24 : -24) : 0
/obj/structure/machinery/power/apc/Destroy()
if(terminal)
terminal.master = null
terminal = null
QDEL_NULL(cell)
area = null
. = ..()
// TGUI SHIT \\
/obj/structure/machinery/power/apc/tgui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
if(!opened && wiresexposed)
ui = new(user, src, "Wires", "[name] Wires")
ui.open()
else
ui = new(user, src, "Apc", name)
ui.open()
/obj/structure/machinery/power/apc/ui_status(mob/user)
. = ..()
if(opened || !can_use(user, TRUE))
return UI_DISABLED
/obj/structure/machinery/power/apc/ui_state(mob/user)
return GLOB.not_incapacitated_and_adjacent_state
/obj/structure/machinery/power/apc/ui_static_data(mob/user)
. = list()
.["wire_descs"] = GLOB.apc_wire_descriptions
/obj/structure/machinery/power/apc/ui_data(mob/user)
var/list/data = list(
"locked" = locked,
"isOperating" = operating,
"externalPower" = main_status,
"powerCellStatus" = cell ? cell.percent() : null,
"chargeMode" = chargemode,
"chargingStatus" = charging,
"totalLoad" = display_power(lastused_total),
"coverLocked" = coverlocked,
"siliconUser" = FALSE,
"powerChannels" = list(
list(
"title" = "Equipment",
"powerLoad" = display_power(lastused_equip),
"status" = equipment,
"topicParams" = list(
"auto" = list("eqp" = 3),
"on" = list("eqp" = 2),
"off" = list("eqp" = 1),
)
),
list(
"title" = "Lighting",
"powerLoad" = display_power(lastused_light),
"status" = lighting,
"topicParams" = list(
"auto" = list("lgt" = 3),
"on" = list("lgt" = 2),
"off" = list("lgt" = 1),
)
),
list(
"title" = "Environment",
"powerLoad" = display_power(lastused_environ),
"status" = environ,
"topicParams" = list(
"auto" = list("env" = 3),
"on" = list("env" = 2),
"off" = list("env" = 1),
)
)
)
)
var/list/payload = list()
for(var/wire in 1 to length(GLOB.apc_wire_descriptions))
payload.Add(list(list(
"number" = wire,
"cut" = isWireCut(wire),
)))
data["wires"] = payload
data["proper_name"] = name
return data
/obj/structure/machinery/power/apc/ui_act(action, params)
. = ..()
if(. || !can_use(usr, 1))
return
var/target_wire = params["wire"]
if(locked && !target_wire) //wire cutting etc does not require the apc to be unlocked
to_chat(usr, SPAN_WARNING("\The [src] is locked! Unlock it by swiping an ID card or dogtag."))
return
add_fingerprint(usr)
switch(action)
if("lock")
locked = !locked
update_icon()
. = TRUE
if("cover")
coverlocked = !coverlocked
. = TRUE
if("breaker")
toggle_breaker(usr)
. = TRUE
if("charge")
chargemode = !chargemode
if(!chargemode)
charging = APC_NOT_CHARGING
update_icon()
. = TRUE
if("channel")
if(params["eqp"])
var/val = text2num(params["eqp"])
equipment = (val == 1) ? 0 : val
update_icon()
update()
else if(params["lgt"])
var/val = text2num(params["lgt"])
lighting = (val == 1) ? 0 : val
update_icon()
update()
else if(params["env"])
var/val = text2num(params["env"])
environ = (val == 1) ? 0 :val
update_icon()
update()
. = TRUE
CHECK_TICK
if("overload")
if(isRemoteControlling(usr) && !aidisabled)
overload_lighting()
. = TRUE
if("cut")
var/obj/item/held_item = usr.get_held_item()
if (!held_item || !HAS_TRAIT(held_item, TRAIT_TOOL_WIRECUTTERS))
to_chat(usr, SPAN_WARNING("You need wirecutters!"))
return TRUE
if(isWireCut(target_wire))
mend(target_wire, usr)
else
playsound(src.loc, 'sound/items/Wirecutter.ogg', 25, 1)
cut(target_wire, usr)
. = TRUE
if("pulse")
var/obj/item/held_item = usr.get_held_item()
if (!held_item || !HAS_TRAIT(held_item, TRAIT_TOOL_MULTITOOL))
to_chat(usr, SPAN_WARNING("You need a multitool!"))
return TRUE
playsound(src.loc, 'sound/effects/zzzt.ogg', 25, 1)
pulse(target_wire, usr)
. = TRUE
return TRUE
/obj/structure/machinery/power/apc/proc/toggle_breaker(mob/user)
operating = !operating
update()
msg_admin_niche("[user] turned [operating ? "on" : "off"] \the [src] in [AREACOORD(src)] [ADMIN_JMP(loc)].")
update_icon()
// the very fact that i have to override this screams to me that apcs shouldnt be under machinery - spookydonut
/obj/structure/machinery/power/apc/power_change()
return
/obj/structure/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/structure/machinery/power/terminal(src.loc)
terminal.setDir(tdir)
terminal.master = src
/obj/structure/machinery/power/apc/proc/init()
has_electronics = 2 //Installed and secured
//Is starting with a power cell installed, create it and set its charge level
if(cell_type)
cell = new cell_type(src)
cell.charge = start_charge * cell.maxcharge / 100 //Convert percentage to actual value
var/area/A = loc.loc
//If area isn't specified use current
if(isarea(A) && src.areastring == null)
area = A
name = "\improper [area.name] APC"
else
area = get_area_name(areastring)
name = "\improper [area.name] APC"
update_icon()
make_terminal()
addtimer(CALLBACK(src, PROC_REF(update)), 5)
/obj/structure/machinery/power/apc/get_examine_text(mob/user)
. = list(desc)
if(stat & BROKEN)
. += SPAN_INFO("It appears to be completely broken. It's hard to see what else is wrong with it.")
return
if(opened)
if(has_electronics && terminal)
. += SPAN_INFO("The cover is [opened == APC_COVER_REMOVED ? "removed":"open"] and the power cell is [cell ? "installed":"missing"].")
else if (!has_electronics && terminal)
. += SPAN_INFO("There are some wires but no any electronics.")
else if (has_electronics && !terminal)
. += SPAN_INFO("Electronics installed but not wired.")
else
. += SPAN_INFO("There is no electronics nor connected wires.")
else
if(stat & MAINT)
. += SPAN_INFO("The cover is closed. Something is wrong with it, it doesn't work.")
else
. += SPAN_INFO("The cover is closed.")
//Update the APC icon to show the three base states
//Also add overlays for indicator lights
/obj/structure/machinery/power/apc/update_icon()
if(!status_overlays)
status_overlays = 1
status_overlays_lock = new
status_overlays_charging = new
status_overlays_equipment = new
status_overlays_lighting = new
status_overlays_environ = new
status_overlays_lock.len = 2
status_overlays_charging.len = 3
status_overlays_equipment.len = 4
status_overlays_lighting.len = 4
status_overlays_environ.len = 4
status_overlays_lock[1] = image(icon, "apcox-0") //0 = blue, 1 = red
status_overlays_lock[2] = image(icon, "apcox-1")
status_overlays_charging[1] = image(icon, "apco3-0")
status_overlays_charging[2] = image(icon, "apco3-1")
status_overlays_charging[3] = image(icon, "apco3-2")
status_overlays_equipment[1] = image(icon, "apco0-0") //0 = red, 1 = green, 2 = blue
status_overlays_equipment[2] = image(icon, "apco0-1")
status_overlays_equipment[3] = image(icon, "apco0-2")
status_overlays_equipment[4] = image(icon, "apco0-3")
status_overlays_lighting[1] = image(icon, "apco1-0")
status_overlays_lighting[2] = image(icon, "apco1-1")
status_overlays_lighting[3] = image(icon, "apco1-2")
status_overlays_lighting[4] = image(icon, "apco1-3")
status_overlays_environ[1] = image(icon, "apco2-0")
status_overlays_environ[2] = image(icon, "apco2-1")
status_overlays_environ[3] = image(icon, "apco2-2")
status_overlays_environ[4] = image(icon, "apco2-3")
var/update = check_updates() //Returns 0 if no need to update icons.
//1 if we need to update the icon_state
//2 if we need to update the overlays
if(!update)
return
if(update & 1) //Updating the 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)
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"
if(!(update_state & UPSTATE_ALLGOOD))
if(length(overlays))
overlays = 0
return
if(update & 2)
if(length(overlays))
overlays = 0
if(!(stat & (BROKEN|MAINT)) && update_state & UPSTATE_ALLGOOD)
overlays += status_overlays_lock[locked + 1]
overlays += status_overlays_charging[charging + 1]
if(operating)
overlays += status_overlays_equipment[equipment + 1]
overlays += status_overlays_lighting[lighting + 1]
overlays += status_overlays_environ[environ + 1]
/obj/structure/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 == 1)
update_state |= UPSTATE_OPENED1
if(opened == 2)
update_state |= UPSTATE_OPENED2
else if(wiresexposed)
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
var/results = 0
if(last_update_state == update_state && last_update_overlay == update_overlay)
return 0
if(last_update_state != update_state)
results++
if(last_update_overlay != update_overlay && update_overlay != 0)
results += 2
return results
/obj/structure/machinery/power/apc/proc/queue_icon_update()
if(!updating_icon)
updating_icon = 1
//Start the update
spawn(APC_UPDATE_ICON_COOLDOWN)
update_icon()
updating_icon = 0
//Attack with an item - open/close cover, insert cell, or (un)lock interface
/obj/structure/machinery/power/apc/attackby(obj/item/W, mob/user)
if(isRemoteControlling(user) && get_dist(src, user) > 1)
return attack_hand(user)
add_fingerprint(user)
if(HAS_TRAIT(W, TRAIT_TOOL_CROWBAR) && opened)
if(has_electronics == 1)
if(user.action_busy) return
if(!skillcheck(user, SKILL_ENGINEER, SKILL_ENGINEER_ENGI))
to_chat(user, SPAN_WARNING("You have no idea how to deconstruct [src]."))
return
if(terminal)
to_chat(user, SPAN_WARNING("Disconnect the terminal first."))
return
playsound(loc, 'sound/items/Crowbar.ogg', 25, 1)
user.visible_message(SPAN_NOTICE("[user] starts removing [src]'s power control board."),
SPAN_NOTICE("You start removing [src]'s power control board.")) //lpeters - fixed grammar issues
if(do_after(user, 50 * user.get_skill_duration_multiplier(SKILL_ENGINEER), INTERRUPT_ALL|BEHAVIOR_IMMOBILE, BUSY_ICON_BUILD) && has_electronics == 1)
has_electronics = 0
if((stat & BROKEN))
user.visible_message(SPAN_NOTICE("[user] breaks [src]'s charred power control board and removes the remains."),
SPAN_NOTICE("You break [src]'s charred power control board and remove the remains."))
else
user.visible_message(SPAN_NOTICE("[user] removes [src]'s power control board."),
SPAN_NOTICE("You remove [src]'s power control board."))
new /obj/item/circuitboard/apc(loc)
SSclues.create_print(get_turf(user), user, "The fingerprint contains specks of electronics.")
SEND_SIGNAL(user, COMSIG_MOB_APC_REMOVE_BOARD, src)
else if(opened != APC_COVER_REMOVED) //Cover isn't removed
opened = APC_COVER_CLOSED
update_icon()
else if(HAS_TRAIT(W, TRAIT_TOOL_CROWBAR) && !(stat & BROKEN))
if(coverlocked && !(stat & MAINT))
to_chat(user, SPAN_WARNING("The cover is locked and cannot be opened."))
return
else
opened = APC_COVER_OPEN
update_icon()
else if(istype(W, /obj/item/cell) && opened) //Trying to put a cell inside
if(!skillcheck(user, SKILL_ENGINEER, SKILL_ENGINEER_ENGI))
to_chat(user, SPAN_WARNING("You have no idea how to fit [W] into [src]."))
return
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.drop_inv_item_to_loc(W, src))
cell = W
user.visible_message(SPAN_NOTICE("[user] inserts [W] into [src]!"), \
SPAN_NOTICE("You insert [W] into [src]!"))
chargecount = 0
update_icon()
else if(HAS_TRAIT(W, TRAIT_TOOL_SCREWDRIVER)) //Haxing
if(opened)
if(!skillcheck(user, SKILL_ENGINEER, SKILL_ENGINEER_ENGI))
to_chat(user, SPAN_WARNING("\The [src]'s wiring confuses you."))
return
if(cell)
to_chat(user, SPAN_WARNING("Close the APC first.")) //Less hints more mystery!
return
else
if(has_electronics == 1 && terminal)
has_electronics = 2
stat &= ~MAINT
playsound(loc, 'sound/items/Screwdriver.ogg', 25, 1)
user.visible_message(SPAN_NOTICE("[user] screws [src]'s circuit electronics into place."),
SPAN_NOTICE("You screw [src]'s circuit electronics into place."))
else if(has_electronics == 2)
has_electronics = 1
stat |= MAINT
playsound(loc, 'sound/items/Screwdriver.ogg', 25, 1)
user.visible_message(SPAN_NOTICE("[user] unfastens [src]'s circuit electronics."),
SPAN_NOTICE("You unfasten [src]'s circuit electronics."))
else
to_chat(user, SPAN_WARNING("There is nothing to secure."))
return
update_icon()
else
wiresexposed = !wiresexposed
beenhit = wiresexposed ? XENO_HITS_TO_EXPOSE_WIRES_MIN : 0
user.visible_message(SPAN_NOTICE("[user] [wiresexposed ? "exposes" : "unexposes"] [src]'s wiring."),
SPAN_NOTICE("You [wiresexposed ? "expose" : "unexpose"] [src]'s wiring."))
playsound(src.loc, 'sound/items/Screwdriver.ogg', 25, 1)
update_icon()
if(SStgui.close_uis(src)) //if you had UIs open before from this APC...
tgui_interact(user) //then close them and open up the new ones (wires/panel)
else if(istype(W, /obj/item/card/id)) //Trying to unlock the interface with an ID card
if(!skillcheck(user, SKILL_ENGINEER, SKILL_ENGINEER_ENGI))
to_chat(user, SPAN_WARNING("You're not sure where to swipe \the [W] on [src]."))
return
if(opened)
to_chat(user, SPAN_WARNING("You must close the cover to swipe an ID card."))
else if(wiresexposed)
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))
locked = !locked
user.visible_message(SPAN_NOTICE("[user] [locked ? "locks" : "unlocks"] [src]'s interface."),
SPAN_NOTICE("You [locked ? "lock" : "unlock"] [src]'s interface."))
update_icon()
else
to_chat(user, SPAN_WARNING("Access denied."))
else if(iswire(W) && !terminal && opened && has_electronics != 2)
if(!skillcheck(user, SKILL_ENGINEER, SKILL_ENGINEER_ENGI))
to_chat(user, SPAN_WARNING("You have no idea what to do with [src]."))
return
if(loc:intact_tile)
to_chat(user, SPAN_WARNING("You must remove the floor plating in front of the APC first."))
return
var/obj/item/stack/cable_coil/C = W
if(C.get_amount() < 10)
to_chat(user, SPAN_WARNING("You need more wires."))
return
user.visible_message(SPAN_NOTICE("[user] starts wiring [src]'s frame."),
SPAN_NOTICE("You start wiring [src]'s frame."))
playsound(src.loc, 'sound/items/Deconstruct.ogg', 25, 1)
if(do_after(user, 20 * user.get_skill_duration_multiplier(SKILL_ENGINEER), INTERRUPT_ALL|BEHAVIOR_IMMOBILE, BUSY_ICON_BUILD) && !terminal && opened && has_electronics != 2)
var/turf/T = get_turf(src)
var/obj/structure/cable/N = T.get_cable_node()
if(prob(50) && electrocute_mob(usr, N, N))
var/datum/effect_system/spark_spread/spark = new /datum/effect_system/spark_spread
spark.set_up(5, 1, src)
spark.start()
return
if(C.use(10))
user.visible_message(SPAN_NOTICE("[user] wires [src]'s frame."),
SPAN_NOTICE("You wire [src]'s frame."))
make_terminal()
terminal.connect_to_network()
else if(HAS_TRAIT(W, TRAIT_TOOL_WIRECUTTERS) && terminal && opened && has_electronics != 2)
if(!skillcheck(user, SKILL_ENGINEER, SKILL_ENGINEER_ENGI))
to_chat(user, SPAN_WARNING("You have no idea what to do with [W]."))
return
if(loc:intact_tile)
to_chat(user, SPAN_WARNING("You must remove the floor plating in front of the APC first."))
return
user.visible_message(SPAN_NOTICE("[user] starts removing [src]'s wiring and terminal."),
SPAN_NOTICE("You start removing [src]'s wiring and terminal."))
playsound(src.loc, 'sound/items/Deconstruct.ogg', 25, 1)
if(do_after(user, 50 * user.get_skill_duration_multiplier(SKILL_ENGINEER), INTERRUPT_ALL|BEHAVIOR_IMMOBILE, BUSY_ICON_BUILD))
if(!terminal)
to_chat(user, SPAN_WARNING("\The [src] lacks a terminal to remove."))
return
if (prob(50) && electrocute_mob(user, terminal.powernet, terminal))
var/datum/effect_system/spark_spread/spark = new /datum/effect_system/spark_spread
spark.set_up(5, 1, src)
spark.start()
return
new /obj/item/stack/cable_coil(loc,10)
user.visible_message(SPAN_NOTICE("[user] removes [src]'s wiring and terminal."),
SPAN_NOTICE("You remove [src]'s wiring and terminal."))
qdel(terminal)
terminal = null
else if(istype(W, /obj/item/circuitboard/apc) && opened && has_electronics == 0 && !(stat & BROKEN))
if(!skillcheck(user, SKILL_ENGINEER, SKILL_ENGINEER_ENGI))
to_chat(user, SPAN_WARNING("You have no idea what to do with [W]."))
return
user.visible_message(SPAN_NOTICE("[user] starts inserting the power control board into [src]."),
SPAN_NOTICE("You start inserting the power control board into [src]."))
playsound(src.loc, 'sound/items/Deconstruct.ogg', 25, 1)
if(do_after(user, 15, INTERRUPT_ALL|BEHAVIOR_IMMOBILE, BUSY_ICON_BUILD))
has_electronics = 1
user.visible_message(SPAN_NOTICE("[user] inserts the power control board into [src]."),
SPAN_NOTICE("You insert the power control board into [src]."))
qdel(W)
else if(istype(W, /obj/item/circuitboard/apc) && opened && has_electronics == 0 && (stat & BROKEN))
if(!skillcheck(user, SKILL_ENGINEER, SKILL_ENGINEER_ENGI))
to_chat(user, SPAN_WARNING("You have no idea what to do with [W]."))
return
to_chat(user, SPAN_WARNING("You cannot put the board inside, the frame is damaged."))
return
else if(iswelder(W) && opened && has_electronics == 0 && !terminal)
if(!HAS_TRAIT(W, TRAIT_TOOL_BLOWTORCH))
to_chat(user, SPAN_WARNING("You need a stronger blowtorch!"))
return
if(!skillcheck(user, SKILL_ENGINEER, SKILL_ENGINEER_ENGI))
to_chat(user, SPAN_WARNING("You have no idea what to do with [W]."))
return
var/obj/item/tool/weldingtool/WT = W
if(WT.get_fuel() < 3)
to_chat(user, SPAN_WARNING("You need more welding fuel to complete this task."))
return
user.visible_message(SPAN_NOTICE("[user] starts welding [src]'s frame."),
SPAN_NOTICE("You start welding [src]'s frame."))
playsound(src.loc, 'sound/items/Welder.ogg', 25, 1)
if(do_after(user, 50 * user.get_skill_duration_multiplier(SKILL_ENGINEER), INTERRUPT_ALL|BEHAVIOR_IMMOBILE, BUSY_ICON_BUILD))
if(!src || !WT.remove_fuel(3, user))
return
user.visible_message(SPAN_NOTICE("[user] welds [src]'s frame apart."), SPAN_NOTICE("You weld [src]'s frame apart."))
deconstruct()
return
else if(istype(W, /obj/item/frame/apc) && opened && (stat & BROKEN))
if(!skillcheck(user, SKILL_ENGINEER, SKILL_ENGINEER_ENGI))
to_chat(user, SPAN_WARNING("You have no idea what to do with [W]."))
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(SPAN_NOTICE("[user] begins replacing [src]'s damaged frontal panel with a new one."),
SPAN_NOTICE("You begin replacing [src]'s damaged frontal panel with a new one."))
if(do_after(user, 50 * user.get_skill_duration_multiplier(SKILL_ENGINEER), INTERRUPT_ALL|BEHAVIOR_IMMOBILE, BUSY_ICON_BUILD))
user.visible_message(SPAN_NOTICE("[user] replaces [src]'s damaged frontal panel with a new one."),
SPAN_NOTICE("You replace [src]'s damaged frontal panel with a new one."))
user.count_niche_stat(STATISTICS_NICHE_REPAIR_APC)
qdel(W)
beenhit = 0
stat &= ~BROKEN
if(opened == 2)
opened = APC_COVER_OPEN
update_icon()
else
if(((stat & BROKEN)) && !opened && W.force >= 5)
opened = APC_COVER_REMOVED
user.visible_message(SPAN_WARNING("[user] knocks down [src]'s cover with [W]!"), \
SPAN_WARNING("You knock down [src]'s cover with [W]!"))
update_icon()
else
if(isRemoteControlling(user))
return attack_hand(user)
if(!opened && wiresexposed && (HAS_TRAIT(W, TRAIT_TOOL_MULTITOOL) || HAS_TRAIT(W, TRAIT_TOOL_WIRECUTTERS)))
return attack_hand(user)
user.visible_message(SPAN_DANGER("[user] hits [src] with \the [W]!"), \
SPAN_DANGER("You hit [src] with \the [W]!"))
/obj/structure/machinery/power/apc/deconstruct(disassembled = TRUE)
if(disassembled)
if((stat & BROKEN) || opened == 2)
new /obj/item/stack/sheet/metal(loc)
else
new /obj/item/frame/apc(loc)
return ..()
//Attack with hand - remove cell (if cover open) or interact with the APC
/obj/structure/machinery/power/apc/attack_hand(mob/user)
if(!user)
return
add_fingerprint(user)
//Human mob special interaction goes here.
if(ishuman(user))
var/mob/living/carbon/human/grabber = user
if(grabber.a_intent == INTENT_GRAB)
//Synthpack recharge
if((grabber.species.flags & IS_SYNTHETIC) && istype(grabber.back, /obj/item/storage/backpack/marine/smartpack))
var/obj/item/storage/backpack/marine/smartpack/s_pack = grabber.back
if(grabber.action_busy)
return
if(!do_after(grabber, 20, INTERRUPT_ALL, BUSY_ICON_GENERIC))
return
playsound(src.loc, 'sound/effects/sparks2.ogg', 25, 1)
if(stat & BROKEN)
var/datum/effect_system/spark_spread/spark = new()
spark.set_up(3, 1, src)
spark.start()
to_chat(grabber, SPAN_DANGER("The APC's power currents surge eratically, damaging your chassis!"))
grabber.apply_damage(10,0, BURN)
else if(cell && cell.charge > 0)
if(!istype(s_pack))
return
if(s_pack.battery_charge < SMARTPACK_MAX_POWER_STORED)
var/charge_to_use = min(cell.charge, SMARTPACK_MAX_POWER_STORED - s_pack.battery_charge)
if(!(cell.use(charge_to_use)))
return
s_pack.battery_charge += charge_to_use
to_chat(user, SPAN_NOTICE("You slot your fingers into the APC interface and siphon off some of the stored charge. [s_pack.name] now has [s_pack.battery_charge]/[SMARTPACK_MAX_POWER_STORED]"))
charging = APC_CHARGING
else
to_chat(user, SPAN_WARNING("[s_pack.name] is already fully charged."))
else
to_chat(user, SPAN_WARNING("There is no charge to draw from that APC."))
return
// Yautja Bracer Recharge
var/obj/item/clothing/gloves/yautja/bracer = grabber.gloves
if(istype(bracer))
if(grabber.action_busy)
return FALSE
if(!COOLDOWN_FINISHED(bracer, bracer_recharge))
to_chat(user, SPAN_WARNING("It is too soon for [bracer.name] to siphon power again. Wait [COOLDOWN_SECONDSLEFT(bracer, bracer_recharge)] seconds."))
return FALSE
to_chat(user, SPAN_NOTICE("You rest your bracer against the APC interface and begin to siphon off some of the stored energy."))
if(!do_after(grabber, 20, INTERRUPT_ALL, BUSY_ICON_HOSTILE))
return FALSE
if(stat & BROKEN)
var/datum/effect_system/spark_spread/spark = new()
spark.set_up(3, 1, src)
spark.start()
to_chat(grabber, SPAN_DANGER("The APC's power currents surge eratically, super-heating your bracer!"))
playsound(src.loc, 'sound/effects/sparks2.ogg', 25, 1)
grabber.apply_damage(10,0, BURN)
return FALSE
if(!cell || cell.charge <= 0)
to_chat(user, SPAN_WARNING("There is no charge to draw from that APC."))
return FALSE
if(bracer.charge_max <= bracer.charge)
to_chat(user, SPAN_WARNING("[bracer.name] is already fully charged."))
return FALSE
var/charge_to_use = min(cell.charge, bracer.charge_max - bracer.charge)
if(!(cell.use(charge_to_use)))
return FALSE
playsound(src.loc, 'sound/effects/sparks2.ogg', 25, 1)
bracer.charge += charge_to_use
COOLDOWN_START(bracer, bracer_recharge, bracer.charge_cooldown)
to_chat(grabber, SPAN_YAUTJABOLD("[icon2html(bracer)] \The <b>[bracer]</b> beep: Power siphon complete. Charge at [bracer.charge]/[bracer.charge_max]."))
if(bracer.notification_sound)
playsound(bracer.loc, 'sound/items/pred_bracer.ogg', 75, 1)
charging = APC_CHARGING
set_broken() // Breaks the APC
return TRUE
else if(grabber.species.can_shred(grabber))
var/allcut = TRUE
for(var/wire = 1; wire < length(get_wire_descriptions()); wire++)
if(!isWireCut(wire))
allcut = FALSE
break
if(allcut)
to_chat(user, SPAN_NOTICE("[src] is already broken!"))
return
user.visible_message(SPAN_WARNING("[user.name] slashes [src]!"),
SPAN_WARNING("You slash [src]!"))
playsound(src.loc, 'sound/weapons/slash.ogg', 25, 1)
if(wiresexposed)
for(var/wire = 1; wire < length(get_wire_descriptions()); wire++)
cut(wire, user)
update_icon()
visible_message(SPAN_WARNING("[src]'s wires are shredded!"))
else if(beenhit >= pick(3, 4))
wiresexposed = TRUE
update_icon()
visible_message(SPAN_WARNING("[src]'s cover flies open, exposing the wires!"))
else
beenhit++
return
if(usr == user && opened && (!isRemoteControlling(user)))
if(cell)
if(!skillcheck(user, SKILL_ENGINEER, SKILL_ENGINEER_ENGI))
to_chat(user, SPAN_WARNING("You have no idea how to remove the power cell from [src]."))
return
user.put_in_hands(cell)
cell.add_fingerprint(user)
cell.update_icon()
src.cell = null
user.visible_message(SPAN_NOTICE("[user] removes the power cell from [src]!"),
SPAN_NOTICE("You remove the power cell from [src]."))
charging = APC_NOT_CHARGING
update_icon()
SSclues.create_print(get_turf(user), user, "The fingerprint contains small parts of battery acid.")
SEND_SIGNAL(user, COMSIG_MOB_APC_REMOVE_CELL, src)
return
if(stat & (BROKEN|MAINT))
return
tgui_interact(user)
/obj/structure/machinery/power/apc/proc/report()
return "[area.name] : [equipment]/[lighting]/[environ] ([lastused_total]) : [cell? cell.percent() : "N/C"] ([charging])"
/obj/structure/machinery/power/apc/proc/update()
if(operating && !shorted)
area.update_power_channels((equipment > 1), (lighting > 1), (environ > 1))
else
area.update_power_channels(FALSE, FALSE, FALSE)
/obj/structure/machinery/power/apc/proc/get_wire_descriptions()
return list(
APC_WIRE_MAIN_POWER = "Main power",
APC_WIRE_IDSCAN = "ID scanner"
)
/obj/structure/machinery/power/apc/proc/isWireCut(wire)
var/wireFlag = getWireFlag(wire)
return !(apcwires & wireFlag)
/obj/structure/machinery/power/apc/proc/cut(wire, mob/user, with_message = TRUE)
apcwires ^= getWireFlag(wire)
switch(wire)
if(APC_WIRE_MAIN_POWER)
if(user)
shock(usr, 50)
visible_message(SPAN_WARNING("\The [src] begins flashing error messages wildly!"))
SSclues.create_print(get_turf(user), user, "The fingerprint contains specks of wire.")
SEND_SIGNAL(user, COMSIG_MOB_APC_CUT_WIRE, src)
shorted = 1
if(with_message)
visible_message(SPAN_WARNING("\The [src] begins flashing error messages wildly!"))
if(APC_WIRE_IDSCAN)
locked = 0
if(with_message)
visible_message(SPAN_NOTICE("\The [src] emits a click."))
/obj/structure/machinery/power/apc/proc/mend(wire)
apcwires |= getWireFlag(wire)
switch(wire)
if(APC_WIRE_MAIN_POWER)
if(!isWireCut(APC_WIRE_MAIN_POWER))
beenhit = 0
shorted = 0
shock(usr, 50)
if(APC_WIRE_IDSCAN)
locked = 1
visible_message(SPAN_NOTICE("\The [src] emits a slight thunk."))
/obj/structure/machinery/power/apc/proc/pulse(wire, mob/user)
if(isWireCut(wire))
if(user)
to_chat(user, SPAN_WARNING("You can't pulse a cut wire!"))
return
switch(wire)
if(APC_WIRE_IDSCAN) //Unlocks the APC for 30 seconds, if you have a better way to hack an APC I'm all ears
locked = 0
visible_message(SPAN_NOTICE("\The [src] emits a click."))
spawn(30 SECONDS)
locked = 1
visible_message(SPAN_NOTICE("\The [src] emits a slight thunk."))
if(APC_WIRE_MAIN_POWER)
if(shorted == 0)
shorted = 1
visible_message(SPAN_WARNING("\The [src] begins flashing error messages wildly!"))
if(user)