/
portable_turret.dm
1087 lines (946 loc) · 35.5 KB
/
portable_turret.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 TURRET_STUN 0
#define TURRET_LETHAL 1
#define POPUP_ANIM_TIME 5
#define POPDOWN_ANIM_TIME 5 //Be sure to change the icon animation at the same time or it'll look bad
#define TURRET_FLAG_SHOOT_ALL_REACT (1<<0) // The turret gets pissed off and shoots at people nearby (unless they have sec access!)
#define TURRET_FLAG_AUTH_WEAPONS (1<<1) // Checks if it can shoot people that have a weapon they aren't authorized to have
#define TURRET_FLAG_SHOOT_CRIMINALS (1<<2) // Checks if it can shoot people that are wanted
#define TURRET_FLAG_SHOOT_ALL (1<<3) // The turret gets pissed off and shoots at people nearby (unless they have sec access!)
#define TURRET_FLAG_SHOOT_ANOMALOUS (1<<4) // Checks if it can shoot at unidentified lifeforms (ie xenos)
#define TURRET_FLAG_SHOOT_UNSHIELDED (1<<5) // Checks if it can shoot people that aren't mindshielded and who arent heads
#define TURRET_FLAG_SHOOT_BORGS (1<<6) // checks if it can shoot cyborgs
#define TURRET_FLAG_SHOOT_HEADS (1<<7) // checks if it can shoot at heads of staff
DEFINE_BITFIELD(turret_flags, list(
"TURRET_FLAG_SHOOT_ALL_REACT" = TURRET_FLAG_SHOOT_ALL_REACT,
"TURRET_FLAG_AUTH_WEAPONS" = TURRET_FLAG_AUTH_WEAPONS,
"TURRET_FLAG_SHOOT_CRIMINALS" = TURRET_FLAG_SHOOT_CRIMINALS,
"TURRET_FLAG_SHOOT_ALL" = TURRET_FLAG_SHOOT_ALL,
"TURRET_FLAG_SHOOT_ANOMALOUS" = TURRET_FLAG_SHOOT_ANOMALOUS,
"TURRET_FLAG_SHOOT_UNSHIELDED" = TURRET_FLAG_SHOOT_UNSHIELDED,
"TURRET_FLAG_SHOOT_BORGS" = TURRET_FLAG_SHOOT_BORGS,
"TURRET_FLAG_SHOOT_HEADS" = TURRET_FLAG_SHOOT_HEADS,
))
/obj/machinery/porta_turret
name = "turret"
icon = 'icons/obj/turrets.dmi'
icon_state = "turretCover"
layer = OBJ_LAYER
invisibility = INVISIBILITY_OBSERVER //the turret is invisible if it's inside its cover
density = TRUE
desc = "A covered turret that shoots at its enemies."
use_power = IDLE_POWER_USE //this turret uses and requires power
idle_power_usage = 50 //when inactive, this turret takes up constant 50 Equipment power
active_power_usage = 300 //when active, this turret takes up constant 300 Equipment power
req_access = list(ACCESS_SECURITY) /// Only people with Security access
power_channel = AREA_USAGE_EQUIP //drains power from the EQUIPMENT channel
max_integrity = 160 //the turret's health
integrity_failure = 0.5
armor = list("melee" = 50, "bullet" = 30, "laser" = 30, "energy" = 30, "bomb" = 30, "bio" = 0, "rad" = 0, "fire" = 90, "acid" = 90)
base_icon_state = "standard"
/// Scan range of the turret for locating targets
var/scan_range = 7
/// For turrets inside other objects
var/atom/base = null
/// If the turret cover is "open" and the turret is raised
var/raised = FALSE
/// If the turret is currently opening or closing its cover
var/raising = FALSE
/// If the turret's behaviour control access is locked
var/locked = TRUE
/// If the turret responds to control panels
var/controllock = FALSE
/// The type of weapon installed by default
var/installation = /obj/item/gun/energy/e_gun/turret
/// What stored gun is in the turret
var/obj/item/gun/stored_gun = null
/// The charge of the gun when retrieved from wreckage
var/gun_charge = 0
/// In which mode is turret in, stun or lethal
var/mode = TURRET_STUN
/// Stun mode projectile type
var/stun_projectile = null
/// Sound of stun projectile
var/stun_projectile_sound
/// Lethal mode projectile type
var/lethal_projectile = null
/// Sound of lethal projectile
var/lethal_projectile_sound
/// Power needed per shot
var/reqpower = 500
/// Will stay active
var/always_up = FALSE
/// Hides the cover
var/has_cover = TRUE
/// The cover that is covering this turret
var/obj/machinery/porta_turret_cover/cover = null
/// World.time the turret last fired
var/last_fired = 0
/// Ticks until next shot (1.5 ?)
var/shot_delay = 15
/// Turret flags about who is turret allowed to shoot
var/turret_flags = TURRET_FLAG_SHOOT_CRIMINALS | TURRET_FLAG_SHOOT_ANOMALOUS
/// Determines if the turret is on
var/on = TRUE
/// Same faction mobs will never be shot at, no matter the other settings
var/list/faction = list("turret")
/// The spark system, used for generating... sparks?
var/datum/effect_system/spark_spread/spark_system
/// Linked turret control panel of the turret
var/obj/machinery/turretid/cp = null
/// The turret will try to shoot from a turf in that direction when in a wall
var/wall_turret_direction
/// If the turret is manually controlled
var/manual_control = FALSE
/// Action button holder for quitting manual control
var/datum/action/turret_quit/quit_action
/// Action button holder for switching between turret modes when manually controlling
var/datum/action/turret_toggle/toggle_action
/// Mob that is remotely controlling the turret
var/mob/remote_controller
/obj/machinery/porta_turret/Initialize()
. = ..()
if(!base)
base = src
update_appearance()
//Sets up a spark system
spark_system = new /datum/effect_system/spark_spread
spark_system.set_up(5, 0, src)
spark_system.attach(src)
setup()
if(has_cover)
cover = new /obj/machinery/porta_turret_cover(loc)
cover.parent_turret = src
var/mutable_appearance/base = mutable_appearance('icons/obj/turrets.dmi', "basedark")
base.layer = NOT_HIGH_OBJ_LAYER
underlays += base
if(!has_cover)
INVOKE_ASYNC(src, PROC_REF(popUp))
/obj/machinery/porta_turret/proc/toggle_on(set_to)
var/current = on
if (!isnull(set_to))
on = set_to
else
on = !on
if (current != on)
check_should_process()
if (!on)
popDown()
/obj/machinery/porta_turret/proc/check_should_process()
if (datum_flags & DF_ISPROCESSING)
if (!on || !anchored || (machine_stat & BROKEN) || !powered())
end_processing()
else
if (on && anchored && !(machine_stat & BROKEN) && powered())
begin_processing()
/obj/machinery/porta_turret/update_icon_state()
if(!anchored)
icon_state = "turretCover"
return ..()
if(machine_stat & BROKEN)
icon_state = "[base_icon_state]_broken"
return ..()
if(!powered())
icon_state = "[base_icon_state]_unpowered"
return ..()
if(!on || !raised)
icon_state = "[base_icon_state]_off"
return ..()
switch(mode)
if(TURRET_STUN)
icon_state = "[base_icon_state]_stun"
if(TURRET_LETHAL)
icon_state = "[base_icon_state]_lethal"
return ..()
/obj/machinery/porta_turret/proc/setup(obj/item/gun/turret_gun)
if(stored_gun)
qdel(stored_gun)
stored_gun = null
if(installation && !turret_gun)
stored_gun = new installation(src)
else if (turret_gun)
stored_gun = turret_gun
var/list/gun_properties = stored_gun.get_turret_properties()
//required properties
stun_projectile = gun_properties["stun_projectile"]
stun_projectile_sound = gun_properties["stun_projectile_sound"]
lethal_projectile = gun_properties["lethal_projectile"]
lethal_projectile_sound = gun_properties["lethal_projectile_sound"]
base_icon_state = gun_properties["base_icon_state"]
//optional properties
if(gun_properties["shot_delay"])
shot_delay = gun_properties["shot_delay"]
if(gun_properties["reqpower"])
reqpower = gun_properties["reqpower"]
update_appearance()
return gun_properties
/obj/machinery/porta_turret/Destroy()
//deletes its own cover with it
QDEL_NULL(cover)
base = null
if(cp)
cp.turrets -= src
cp = null
QDEL_NULL(stored_gun)
QDEL_NULL(spark_system)
remove_control()
return ..()
/obj/machinery/porta_turret/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "PortableTurret", name)
ui.open()
/obj/machinery/porta_turret/ui_data(mob/user)
var/list/data = list(
"locked" = locked,
"on" = on,
"check_weapons" = turret_flags & TURRET_FLAG_AUTH_WEAPONS,
"neutralize_criminals" = turret_flags & TURRET_FLAG_SHOOT_CRIMINALS,
"neutralize_all" = turret_flags & TURRET_FLAG_SHOOT_ALL,
"neutralize_unidentified" = turret_flags & TURRET_FLAG_SHOOT_ANOMALOUS,
"neutralize_nonmindshielded" = turret_flags & TURRET_FLAG_SHOOT_UNSHIELDED,
"neutralize_cyborgs" = turret_flags & TURRET_FLAG_SHOOT_BORGS,
"ignore_heads" = turret_flags & TURRET_FLAG_SHOOT_HEADS,
"manual_control" = manual_control,
"silicon_user" = FALSE,
"allow_manual_control" = FALSE,
)
if(issilicon(user))
data["silicon_user"] = TRUE
if(!manual_control)
var/mob/living/silicon/S = user
if(S.hack_software)
data["allow_manual_control"] = TRUE
return data
/obj/machinery/porta_turret/ui_act(action, list/params)
. = ..()
if(.)
return
switch(action)
if("power")
if(anchored)
toggle_on()
return TRUE
else
to_chat(usr, "<span class='warning'>It has to be secured first!</span>")
if("authweapon")
turret_flags ^= TURRET_FLAG_AUTH_WEAPONS
return TRUE
if("shootcriminals")
turret_flags ^= TURRET_FLAG_SHOOT_CRIMINALS
return TRUE
if("shootall")
turret_flags ^= TURRET_FLAG_SHOOT_ALL
return TRUE
if("checkxenos")
turret_flags ^= TURRET_FLAG_SHOOT_ANOMALOUS
return TRUE
if("checkloyal")
turret_flags ^= TURRET_FLAG_SHOOT_UNSHIELDED
return TRUE
if("shootborgs")
turret_flags ^= TURRET_FLAG_SHOOT_BORGS
return TRUE
if("shootheads")
turret_flags ^= TURRET_FLAG_SHOOT_HEADS
return TRUE
if("manual")
if(!issilicon(usr))
return
give_control(usr)
return TRUE
/obj/machinery/porta_turret/ui_host(mob/user)
if(has_cover && cover)
return cover
if(base)
return base
return src
/obj/machinery/porta_turret/power_change()
. = ..()
if(!anchored || (machine_stat & BROKEN) || !powered())
update_appearance()
remove_control()
check_should_process()
/obj/machinery/porta_turret/attackby(obj/item/I, mob/user, params)
if(machine_stat & BROKEN)
if(I.tool_behaviour == TOOL_CROWBAR)
//If the turret is destroyed, you can remove it with a crowbar to
//try and salvage its components
to_chat(user, "<span class='notice'>You begin prying the metal coverings off...</span>")
if(I.use_tool(src, user, 20))
if(prob(70))
if(stored_gun)
stored_gun.forceMove(loc)
stored_gun = null
to_chat(user, "<span class='notice'>You remove the turret and salvage some components.</span>")
if(prob(50))
new /obj/item/stack/sheet/metal(loc, rand(1,4))
if(prob(50))
new /obj/item/assembly/prox_sensor(loc)
else
to_chat(user, "<span class='notice'>You remove the turret but did not manage to salvage anything.</span>")
qdel(src)
if(I.tool_behaviour == TOOL_WELDER && user.a_intent == INTENT_HELP)
if(obj_integrity < max_integrity)
if(!I.tool_start_check(user, amount=0))
return
to_chat(user, "<span class='notice'>You begin repairing [src]...</span>")
if(I.use_tool(src, user, 40, volume=50))
obj_integrity = obj_integrity + 20
to_chat(user, "<span class='notice'>You repair [src].</span>")
if(obj_integrity > (max_integrity * integrity_failure) && BROKEN)
obj_integrity = max_integrity
set_machine_stat(machine_stat & ~BROKEN)
update_appearance()
check_should_process()
else
to_chat(user, "<span class='warning'>[src] is already in good condition!</span>")
return
else if((I.tool_behaviour == TOOL_WRENCH) && (!on))
if(raised)
return
//This code handles moving the turret around. After all, it's a portable turret!
if(!anchored && !isinspace())
set_anchored(TRUE)
invisibility = INVISIBILITY_MAXIMUM
update_appearance()
to_chat(user, "<span class='notice'>You secure the exterior bolts on the turret.</span>")
if(has_cover)
cover = new /obj/machinery/porta_turret_cover(loc) //create a new turret. While this is handled in process(), this is to workaround a bug where the turret becomes invisible for a split second
cover.parent_turret = src //make the cover's parent src
else if(anchored)
set_anchored(FALSE)
to_chat(user, "<span class='notice'>You unsecure the exterior bolts on the turret.</span>")
power_change()
invisibility = 0
qdel(cover) //deletes the cover, and the turret instance itself becomes its own cover.
if(I.GetID())
//Behavior lock/unlock mangement
if(allowed(user))
locked = !locked
to_chat(user, "<span wclass='notice'>Controls are now [locked ? "locked" : "unlocked"].</span>")
else
to_chat(user, "<span class='alert'>Access denied.</span>")
return
if(I.tool_behaviour == TOOL_MULTITOOL && !locked)
if(!multitool_check_buffer(user, I))
return
var/obj/item/multitool/M = I
M.buffer = src
to_chat(user, "<span class='notice'>You add [src] to multitool buffer.</span>")
return
return ..()
/obj/machinery/porta_turret/emag_act(mob/user)
if(obj_flags & EMAGGED)
return
to_chat(user, "<span class='warning'>You short out [src]'s threat assessment circuits.</span>")
audible_message("<span class='hear'>[src] hums oddly...</span>")
obj_flags |= EMAGGED
controllock = TRUE
toggle_on(FALSE) //turns off the turret temporarily
update_appearance()
//6 seconds for the traitor to gtfo of the area before the turret decides to ruin his shit
addtimer(CALLBACK(src, PROC_REF(toggle_on), TRUE), 6 SECONDS)
//turns it back on. The cover popUp() popDown() are automatically called in process(), no need to define it here
/obj/machinery/porta_turret/emp_act(severity)
. = ..()
if (. & EMP_PROTECT_SELF)
return
if(on)
//if the turret is on, the EMP no matter how severe disables the turret for a while
//and scrambles its settings, with a slight chance of having an emag effect
if(prob(50))
turret_flags |= TURRET_FLAG_SHOOT_CRIMINALS
if(prob(50))
turret_flags |= TURRET_FLAG_AUTH_WEAPONS
if(prob(20))
turret_flags |= TURRET_FLAG_SHOOT_ALL // Shooting everyone is a pretty big deal, so it's least likely to get turned on
toggle_on(FALSE)
remove_control()
addtimer(CALLBACK(src, PROC_REF(toggle_on), TRUE), rand(60,600))
/obj/machinery/porta_turret/take_damage(damage, damage_type = BRUTE, damage_flag = 0, sound_effect = 1)
. = ..()
if(. && obj_integrity > 0) //damage received
if(prob(30))
spark_system.start()
if(on && !(turret_flags & TURRET_FLAG_SHOOT_ALL_REACT) && !(obj_flags & EMAGGED))
turret_flags |= TURRET_FLAG_SHOOT_ALL_REACT
addtimer(CALLBACK(src, PROC_REF(reset_attacked)), 60)
/obj/machinery/porta_turret/proc/reset_attacked()
turret_flags &= ~TURRET_FLAG_SHOOT_ALL_REACT
/obj/machinery/porta_turret/deconstruct(disassembled = TRUE)
qdel(src)
/obj/machinery/porta_turret/obj_break(damage_flag)
. = ..()
if(.)
power_change()
invisibility = 0
spark_system.start() //creates some sparks because they look cool
qdel(cover) //deletes the cover - no need on keeping it there!
/obj/machinery/porta_turret/process()
//the main machinery process
if(cover == null && anchored) //if it has no cover and is anchored
if(machine_stat & BROKEN) //if the turret is borked
qdel(cover) //delete its cover, assuming it has one. Workaround for a pesky little bug
else
if(has_cover)
cover = new /obj/machinery/porta_turret_cover(loc) //if the turret has no cover and is anchored, give it a cover
cover.parent_turret = src //assign the cover its parent_turret, which would be this (src)
if(!on || (machine_stat & (NOPOWER|BROKEN)) || manual_control)
return PROCESS_KILL
var/list/targets = list()
for(var/mob/A in view(scan_range, base))
if(A.invisibility > SEE_INVISIBLE_LIVING)
continue
if(turret_flags & TURRET_FLAG_SHOOT_ANOMALOUS)//if it's set to check for simple animals
if(isanimal(A))
var/mob/living/simple_animal/SA = A
if(SA.stat || in_faction(SA)) //don't target if dead or in faction
continue
targets += SA
continue
if(issilicon(A))
var/mob/living/silicon/sillycone = A
if(ispAI(A))
continue
if((turret_flags & TURRET_FLAG_SHOOT_BORGS) && sillycone.stat != DEAD && iscyborg(sillycone))
targets += sillycone
continue
if(sillycone.stat || in_faction(sillycone))
continue
if(iscyborg(sillycone))
var/mob/living/silicon/robot/sillyconerobot = A
if(LAZYLEN(faction) && (ROLE_SYNDICATE in faction) && sillyconerobot.emagged == TRUE)
continue
else if(iscarbon(A))
var/mob/living/carbon/C = A
//If not emagged, only target carbons that can use items
if(mode != TURRET_LETHAL && (C.stat || C.handcuffed || !(C.mobility_flags & MOBILITY_USE)))
continue
//If emagged, target all but dead carbons
if(mode == TURRET_LETHAL && C.stat == DEAD)
continue
//if the target is a human and not in our faction, analyze threat level
if(ishuman(C) && !in_faction(C))
if(assess_perp(C) >= 4)
targets += C
else if(turret_flags & TURRET_FLAG_SHOOT_ANOMALOUS) //non humans who are not simple animals (xenos etc)
if(!in_faction(C))
targets += C
for(var/A in GLOB.mechas_list)
if((get_dist(A, base) < scan_range) && can_see(base, A, scan_range))
var/obj/mecha/Mech = A
if(Mech.occupant && !in_faction(Mech.occupant)) //If there is a user and they're not in our faction
if(assess_perp(Mech.occupant) >= 4)
targets += Mech
if((turret_flags & TURRET_FLAG_SHOOT_ANOMALOUS) && GLOB.blobs.len && (mode == TURRET_LETHAL))
for(var/obj/structure/blob/B in view(scan_range, base))
targets += B
if(targets.len)
tryToShootAt(targets)
else if(!always_up)
popDown() // no valid targets, close the cover
/obj/machinery/porta_turret/proc/tryToShootAt(list/atom/movable/targets)
while(targets.len > 0)
var/atom/movable/M = pick(targets)
targets -= M
if(target(M))
return 1
/obj/machinery/porta_turret/proc/popUp() //pops the turret up
if(!anchored)
return
if(raising || raised)
return
if(machine_stat & BROKEN)
return
invisibility = 0
raising = 1
if(cover)
flick("popup", cover)
sleep(POPUP_ANIM_TIME)
raising = 0
if(cover)
cover.icon_state = "openTurretCover"
raised = 1
layer = MOB_LAYER
/obj/machinery/porta_turret/proc/popDown() //pops the turret down
if(raising || !raised)
return
if(machine_stat & BROKEN)
return
layer = OBJ_LAYER
raising = 1
if(cover)
flick("popdown", cover)
sleep(POPDOWN_ANIM_TIME)
raising = 0
if(cover)
cover.icon_state = "turretCover"
raised = 0
invisibility = 2
update_appearance()
/obj/machinery/porta_turret/proc/assess_perp(mob/living/carbon/human/perp)
var/threatcount = 0 //the integer returned
if(obj_flags & EMAGGED)
return 10 //if emagged, always return 10.
if((turret_flags & (TURRET_FLAG_SHOOT_ALL | TURRET_FLAG_SHOOT_ALL_REACT)) && !allowed(perp))
//if the turret has been attacked or is angry, target all non-sec people
if(!allowed(perp))
return 10
if(turret_flags & TURRET_FLAG_AUTH_WEAPONS) //check for weapon authorization
if(isnull(perp.wear_id) || istype(perp.wear_id.GetID(), /obj/item/card/id/syndicate))
if(allowed(perp)) //if the perp has security access, return 0
return 0
if(perp.is_holding_item_of_type(/obj/item/gun) || perp.is_holding_item_of_type(/obj/item/melee/baton))
threatcount += 4
if(istype(perp.belt, /obj/item/gun) || istype(perp.belt, /obj/item/melee/baton))
threatcount += 2
if(turret_flags & TURRET_FLAG_SHOOT_CRIMINALS) //if the turret can check the records, check if they are set to *Arrest* on records
var/perpname = perp.get_face_name(perp.get_id_name())
var/datum/data/record/R = find_record("name", perpname, GLOB.data_core.security)
if(!R || (R.fields["criminal"] == "*Arrest*"))
threatcount += 4
if((turret_flags & TURRET_FLAG_SHOOT_UNSHIELDED) && (!HAS_TRAIT(perp, TRAIT_MINDSHIELD)))
threatcount += 4
// If we aren't shooting heads then return a threatcount of 0
if (!(turret_flags & TURRET_FLAG_SHOOT_HEADS) && (perp.get_assignment() in GLOB.command_positions))
return 0
return threatcount
/obj/machinery/porta_turret/proc/in_faction(mob/target)
for(var/faction1 in faction)
if(faction1 in target.faction)
return TRUE
if(ismouse(target))
return TRUE
return FALSE
/obj/machinery/porta_turret/proc/target(atom/movable/target)
if(target)
popUp() //pop the turret up if it's not already up.
setDir(get_dir(base, target))//even if you can't shoot, follow the target
shootAt(target)
return 1
return
/obj/machinery/porta_turret/proc/shootAt(atom/movable/target)
if(!raised) //the turret has to be raised in order to fire - makes sense, right?
return
if(!(obj_flags & EMAGGED)) //if it hasn't been emagged, cooldown before shooting again
if(last_fired + shot_delay > world.time)
return
last_fired = world.time
var/turf/T = get_turf(src)
var/turf/U = get_turf(target)
if(!istype(T) || !istype(U))
return
//Wall turrets will try to find adjacent empty turf to shoot from to cover full arc
if(T.density)
if(wall_turret_direction)
var/turf/closer = get_step(T,wall_turret_direction)
if(istype(closer) && !closer.is_blocked_turf() && T.Adjacent(closer))
T = closer
else
var/target_dir = get_dir(T,target)
for(var/d in list(0,-45,45))
var/turf/closer = get_step(T,turn(target_dir,d))
if(istype(closer) && !closer.is_blocked_turf() && T.Adjacent(closer))
T = closer
break
update_appearance()
var/obj/projectile/A
//any emagged turrets drains 2x power and uses a different projectile?
if(mode == TURRET_STUN)
use_power(reqpower)
A = new stun_projectile(T)
playsound(loc, stun_projectile_sound, 75, TRUE)
else
use_power(reqpower * 2)
A = new lethal_projectile(T)
playsound(loc, lethal_projectile_sound, 75, TRUE)
//Shooting Code:
A.preparePixelProjectile(target, T)
A.firer = src
A.fired_from = src
A.fire()
return A
/obj/machinery/porta_turret/proc/setState(on, mode, shoot_cyborgs)
if(controllock)
return
shoot_cyborgs ? (turret_flags |= TURRET_FLAG_SHOOT_BORGS) : (turret_flags &= ~TURRET_FLAG_SHOOT_BORGS)
toggle_on(on)
src.mode = mode
power_change()
/datum/action/turret_toggle
name = "Toggle Mode"
icon_icon = 'icons/mob/actions/actions_mecha.dmi'
button_icon_state = "mech_cycle_equip_off"
/datum/action/turret_toggle/Trigger()
var/obj/machinery/porta_turret/P = target
if(!istype(P))
return
P.setState(P.on,!P.mode)
/datum/action/turret_quit
name = "Release Control"
icon_icon = 'icons/mob/actions/actions_mecha.dmi'
button_icon_state = "mech_eject"
/datum/action/turret_quit/Trigger()
var/obj/machinery/porta_turret/P = target
if(!istype(P))
return
P.remove_control(FALSE)
/obj/machinery/porta_turret/proc/give_control(mob/A)
if(manual_control || !can_interact(A))
return FALSE
remote_controller = A
if(!quit_action)
quit_action = new(src)
quit_action.Grant(remote_controller)
if(!toggle_action)
toggle_action = new(src)
toggle_action.Grant(remote_controller)
remote_controller.reset_perspective(src)
remote_controller.click_intercept = src
manual_control = TRUE
always_up = TRUE
popUp()
return TRUE
/obj/machinery/porta_turret/proc/remove_control(warning_message = TRUE)
if(!manual_control)
return FALSE
if(remote_controller)
if(warning_message)
to_chat(remote_controller, "<span class='warning'>Your uplink to [src] has been severed!</span>")
quit_action.Remove(remote_controller)
toggle_action.Remove(remote_controller)
remote_controller.click_intercept = null
remote_controller.reset_perspective()
always_up = initial(always_up)
manual_control = FALSE
remote_controller = null
return TRUE
/obj/machinery/porta_turret/proc/InterceptClickOn(mob/living/caller, params, atom/A)
if(!manual_control)
return FALSE
if(!can_interact(caller))
remove_control()
return FALSE
log_combat(caller,A,"fired with manual turret control at")
target(A)
return TRUE
/obj/machinery/porta_turret/syndicate
installation = null
always_up = 1
use_power = NO_POWER_USE
has_cover = 0
scan_range = 9
req_access = list(ACCESS_SYNDICATE)
mode = TURRET_LETHAL
stun_projectile = /obj/projectile/bullet
lethal_projectile = /obj/projectile/bullet
lethal_projectile_sound = 'sound/weapons/gun/pistol/shot.ogg'
stun_projectile_sound = 'sound/weapons/gun/pistol/shot.ogg'
icon_state = "syndie_off"
base_icon_state = "syndie"
faction = list(ROLE_SYNDICATE)
desc = "A ballistic machine gun auto-turret."
/obj/machinery/porta_turret/syndicate/ComponentInitialize()
. = ..()
AddComponent(/datum/component/empprotection, EMP_PROTECT_SELF | EMP_PROTECT_WIRES)
/obj/machinery/porta_turret/syndicate/setup()
return
/obj/machinery/porta_turret/syndicate/assess_perp(mob/living/carbon/human/perp)
return 10 //Syndicate turrets shoot everything not in their faction
/obj/machinery/porta_turret/syndicate/energy
icon_state = "standard_lethal"
base_icon_state = "standard"
stun_projectile = /obj/projectile/energy/electrode
stun_projectile_sound = 'sound/weapons/taser.ogg'
lethal_projectile = /obj/projectile/beam/laser
lethal_projectile_sound = 'sound/weapons/laser.ogg'
desc = "An energy blaster auto-turret."
/obj/machinery/porta_turret/syndicate/energy/heavy
icon_state = "standard_lethal"
base_icon_state = "standard"
stun_projectile = /obj/projectile/energy/electrode
stun_projectile_sound = 'sound/weapons/taser.ogg'
lethal_projectile = /obj/projectile/beam/laser/heavylaser
lethal_projectile_sound = 'sound/weapons/lasercannonfire.ogg'
desc = "An energy blaster auto-turret."
/obj/machinery/porta_turret/syndicate/energy/raven
stun_projectile = /obj/projectile/beam/laser
stun_projectile_sound = 'sound/weapons/laser.ogg'
faction = list("neutral","silicon","turret")
/obj/machinery/porta_turret/syndicate/pod
integrity_failure = 0.5
max_integrity = 40
stun_projectile = /obj/projectile/bullet/syndicate_turret
lethal_projectile = /obj/projectile/bullet/syndicate_turret
/obj/machinery/porta_turret/syndicate/shuttle
scan_range = 9
shot_delay = 3
stun_projectile = /obj/projectile/bullet/p50/penetrator/shuttle
lethal_projectile = /obj/projectile/bullet/p50/penetrator/shuttle
lethal_projectile_sound = 'sound/weapons/gun/smg/shot.ogg'
stun_projectile_sound = 'sound/weapons/gun/smg/shot.ogg'
armor = list("melee" = 50, "bullet" = 30, "laser" = 30, "energy" = 30, "bomb" = 80, "bio" = 0, "rad" = 0, "fire" = 90, "acid" = 90)
/obj/machinery/porta_turret/syndicate/shuttle/target(atom/movable/target)
if(target)
setDir(get_dir(base, target))//even if you can't shoot, follow the target
shootAt(target)
addtimer(CALLBACK(src, PROC_REF(shootAt), target), 5)
addtimer(CALLBACK(src, PROC_REF(shootAt), target), 10)
addtimer(CALLBACK(src, PROC_REF(shootAt), target), 15)
return TRUE
/obj/machinery/porta_turret/ai
faction = list("silicon")
turret_flags = TURRET_FLAG_SHOOT_CRIMINALS | TURRET_FLAG_SHOOT_ANOMALOUS | TURRET_FLAG_SHOOT_HEADS
/obj/machinery/porta_turret/ai/assess_perp(mob/living/carbon/human/perp)
return 10 //AI turrets shoot at everything not in their faction
/obj/machinery/porta_turret/ship
installation = null
max_integrity = 300
always_up = 1
use_power = ACTIVE_POWER_USE
active_power_usage = 300
has_cover = 0
scan_range = 9
stun_projectile = /obj/projectile/beam/disabler
lethal_projectile = /obj/projectile/beam/laser
lethal_projectile_sound = 'sound/weapons/plasma_cutter.ogg'
stun_projectile_sound = 'sound/weapons/plasma_cutter.ogg'
icon_state = "syndie_off"
base_icon_state = "syndie"
faction = list("neutral", "turret")
mode = TURRET_STUN
/obj/machinery/porta_turret/ship/ComponentInitialize()
. = ..()
AddComponent(/datum/component/empprotection, EMP_PROTECT_SELF | EMP_PROTECT_WIRES)
/obj/machinery/porta_turret/ship/setup()
return
/obj/machinery/porta_turret/ship/examine(mob/user)
. = ..()
if(in_range(user, src) || isobserver(user))
if(!(machine_stat & BROKEN))
. += "<span class='notice'>Its reports that it's integrity is currently [(obj_integrity / max_integrity) * 100] percent.</span>"
/obj/machinery/porta_turret/ship/weak
max_integrity = 120
integrity_failure = 0.5
name = "Old Laser Turret"
desc = "A turret built with substandard parts and run down further with age. Still capable of delivering lethal lasers to the odd space carp, but not much else."
stun_projectile = /obj/projectile/beam/disabler/weak
lethal_projectile = /obj/projectile/beam/weak/penetrator
faction = list("neutral", "turret")
/obj/machinery/porta_turret/ship/ballistic
stun_projectile = /obj/projectile/bullet/turret/rubber
lethal_projectile = /obj/projectile/bullet/turret
lethal_projectile_sound = 'sound/weapons/gun/smg/shot.ogg'
stun_projectile_sound = 'sound/weapons/gun/smg/shot.ogg'
desc = "A ballistic machine gun auto-turret."
/obj/machinery/porta_turret/ship/solgov
faction = list("playerSolgov", "turret")
/obj/machinery/porta_turret/ship/syndicate
faction = list(FACTION_PLAYER_SYNDICATE, "turret")
icon_state = "standard_lethal"
base_icon_state = "standard"
/obj/machinery/porta_turret/ship/syndicate/weak
name = "Light Laser Turret"
desc = "A low powered turret designed by the Gorlex Maurauders during the ICW. Effectively weaponizes mining equipment."
stun_projectile = /obj/projectile/beam/disabler/weak
lethal_projectile = /obj/projectile/beam/weak/penetrator
icon_state = "syndie_off"
base_icon_state = "syndie"
/obj/machinery/porta_turret/ship/syndicate/heavy
name = "Heavy Laser Turret"
desc = "Produced by Cybersun, this turret is a duel mount of a propietary heavy laser, and crowd control taser system."
stun_projectile = /obj/projectile/energy/electrode
stun_projectile_sound = 'sound/weapons/taser.ogg'
lethal_projectile = /obj/projectile/beam/laser/heavylaser
lethal_projectile_sound = 'sound/weapons/lasercannonfire.ogg'
////////////////////////
//Turret Control Panel//
////////////////////////
/obj/machinery/turretid
name = "turret control panel"
desc = "Used to control a room's automated defenses."
icon = 'icons/obj/machines/turret_control.dmi'
icon_state = "control_standby"
base_icon_state = "control"
density = FALSE
req_access = list(ACCESS_AI_UPLOAD)
resistance_flags = INDESTRUCTIBLE | LAVA_PROOF | FIRE_PROOF | UNACIDABLE | ACID_PROOF
/// Variable dictating if linked turrets are active and will shoot targets
var/enabled = TRUE
/// Variable dictating if linked turrets will shoot lethal projectiles
var/lethal = FALSE
/// Variable dictating if the panel is locked, preventing changes to turret settings
var/locked = TRUE
/// An area in which linked turrets are located, it can be an area name, path or nothing
var/control_area = null
/// AI is unable to use this machine if set to TRUE
var/ailock = FALSE
/// Variable dictating if linked turrets will shoot cyborgs
var/shoot_cyborgs = FALSE
/// List of all linked turrets
var/list/turrets = list()
/obj/machinery/turretid/Initialize(mapload, ndir = 0, built = 0)
. = ..()
if(built)
setDir(ndir)
locked = FALSE
pixel_x = (dir & 3)? 0 : (dir == 4 ? -24 : 24)
pixel_y = (dir & 3)? (dir ==1 ? -24 : 24) : 0
power_change() //Checks power and initial settings
/obj/machinery/turretid/Destroy()
turrets.Cut()
return ..()
/obj/machinery/turretid/Initialize(mapload) //map-placed turrets autolink turrets
. = ..()
if(!mapload)
return
if(control_area)
control_area = get_area_instance_from_text(control_area)
if(control_area == null)
control_area = get_area(src)
stack_trace("Bad control_area path for [src], [src.control_area]")
else if(!control_area)
control_area = get_area(src)
for(var/obj/machinery/porta_turret/T in control_area)
turrets |= T
T.cp = src
/obj/machinery/turretid/examine(mob/user)
. += ..()
if(issilicon(user) && !(machine_stat & BROKEN))
. += {"<span class='notice'>Ctrl-click [src] to [ enabled ? "disable" : "enable"] turrets.</span>
<span class='notice'>Alt-click [src] to set turrets to [ lethal ? "stun" : "kill"].</span>"}
/obj/machinery/turretid/attackby(obj/item/I, mob/user, params)
if(machine_stat & BROKEN)
return
if(I.tool_behaviour == TOOL_MULTITOOL)
if(!multitool_check_buffer(user, I))
return
var/obj/item/multitool/M = I
if(M.buffer && istype(M.buffer, /obj/machinery/porta_turret))
turrets |= M.buffer
to_chat(user, "<span class='notice'>You link \the [M.buffer] with \the [src].</span>")
return
if (issilicon(user))
return attack_hand(user)
if (get_dist(src, user) == 0) // trying to unlock the interface
if (allowed(usr))
if(obj_flags & EMAGGED)
to_chat(user, "<span class='warning'>The turret control is unresponsive!</span>")
return
locked = !locked
to_chat(user, "<span class='notice'>You [ locked ? "lock" : "unlock"] the panel.</span>")
else
to_chat(user, "<span class='alert'>Access denied.</span>")
/obj/machinery/turretid/emag_act(mob/user)
if(obj_flags & EMAGGED)
return
to_chat(user, "<span class='notice'>You short out the turret controls' access analysis module.</span>")
obj_flags |= EMAGGED
locked = FALSE
/obj/machinery/turretid/attack_ai(mob/user)
if(!ailock || isAdminGhostAI(user))
return attack_hand(user)
else
to_chat(user, "<span class='warning'>There seems to be a firewall preventing you from accessing this device!</span>")
/obj/machinery/turretid/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "TurretControl", name)
ui.open()
/obj/machinery/turretid/ui_data(mob/user)
var/list/data = list()
data["locked"] = locked
data["siliconUser"] = user.has_unlimited_silicon_privilege && check_ship_ai_access(user)
data["enabled"] = enabled
data["lethal"] = lethal
data["shootCyborgs"] = shoot_cyborgs
return data
/obj/machinery/turretid/ui_act(action, list/params)
. = ..()
if(.)
return
switch(action)
if("lock")
if(!usr.has_unlimited_silicon_privilege)
return
if((obj_flags & EMAGGED) || (machine_stat & BROKEN))
to_chat(usr, "<span class='warning'>The turret control is unresponsive!</span>")
return
locked = !locked
return TRUE
if("power")
toggle_on(usr)
return TRUE
if("mode")