/
portable_turret.dm
1226 lines (1065 loc) · 39.4 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/weapons/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."
req_access = list(ACCESS_SECURITY) /// Only people with Security access
power_channel = AREA_USAGE_EQUIP //drains power from the EQUIPMENT channel
idle_power_usage = BASE_MACHINE_IDLE_CONSUMPTION * 0.15
max_integrity = 160 //the turret's health
integrity_failure = 0.5
armor_type = /datum/armor/machinery_porta_turret
base_icon_state = "standard"
blocks_emissive = EMISSIVE_BLOCK_UNIQUE
// Same faction mobs will never be shot at, no matter the other settings
faction = list(FACTION_TURRET)
///if TRUE this will cause the turret to stop working if the stored_gun var is null in process()
var/uses_stored = TRUE
/// 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
/// Determines if our projectiles hit our faction
var/ignore_faction = FALSE
/// The spark system, used for generating... sparks?
var/datum/effect_system/spark_spread/spark_system
/// 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
/// While the cooldown is still going on, it cannot be re-enabled.
COOLDOWN_DECLARE(disabled_time)
/datum/armor/machinery_porta_turret
melee = 50
bullet = 30
laser = 30
energy = 30
bomb = 30
fire = 90
acid = 90
/obj/machinery/porta_turret/Initialize(mapload)
. = ..()
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/weapons/turrets.dmi', "basedark")
base.layer = NOT_HIGH_OBJ_LAYER
underlays += base
if(!has_cover)
INVOKE_ASYNC(src, PROC_REF(popUp))
RegisterSignal(src, COMSIG_HIT_BY_SABOTEUR, PROC_REF(on_saboteur))
AddElement(/datum/element/hostile_machine)
///Toggles the turret on or off depending on the value of the turn_on arg.
/obj/machinery/porta_turret/proc/toggle_on(turn_on = TRUE)
if(on == turn_on)
return
if(on && !COOLDOWN_FINISHED(src, disabled_time))
return
on = turn_on
check_should_process()
if (!on)
popDown()
///Prevents turned from being turned on for a duration, then restarts them after that if the second ard is true.
/obj/machinery/porta_turret/proc/set_disabled(duration = 6 SECONDS, will_restart = on)
COOLDOWN_START(src, disabled_time, duration)
if(will_restart)
addtimer(CALLBACK(src, PROC_REF(toggle_on), TRUE), duration + 1) //the cooldown isn't over until the tick after its end.
toggle_on(FALSE)
/obj/machinery/porta_turret/proc/on_saboteur(datum/source, disrupt_duration)
SIGNAL_HANDLER
INVOKE_ASYNC(src, PROC_REF(set_disabled), disrupt_duration)
return COMSIG_SABOTEUR_SUCCESS
/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]_off"
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)
turret_gun.forceMove(src)
stored_gun = turret_gun
RegisterSignal(stored_gun, COMSIG_QDELETING, PROC_REF(null_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
///destroys reference to stored_gun to prevent hard deletions
/obj/machinery/porta_turret/proc/null_gun()
SIGNAL_HANDLER
stored_gun = null
/obj/machinery/porta_turret/Destroy()
//deletes its own cover with it
QDEL_NULL(cover)
base = 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,
"neutralize_heads" = turret_flags & TURRET_FLAG_SHOOT_HEADS,
"manual_control" = manual_control,
"silicon_user" = FALSE,
"allow_manual_control" = FALSE,
"lasertag_turret" = istype(src, /obj/machinery/porta_turret/lasertag),
)
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(!on)
return TRUE
else
to_chat(usr, span_warning("It has to be secured first!"))
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_notice("You begin prying the metal coverings off..."))
if(I.use_tool(src, user, 20))
if(prob(70))
if(stored_gun)
stored_gun.forceMove(loc)
stored_gun = null
to_chat(user, span_notice("You remove the turret and salvage some components."))
if(prob(50))
new /obj/item/stack/sheet/iron(loc, rand(1,4))
if(prob(50))
new /obj/item/assembly/prox_sensor(loc)
else
to_chat(user, span_notice("You remove the turret but did not manage to salvage anything."))
qdel(src)
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)
RemoveInvisibility(id=type)
update_appearance()
to_chat(user, span_notice("You secure the exterior bolts on the turret."))
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_notice("You unsecure the exterior bolts on the turret."))
power_change()
SetInvisibility(INVISIBILITY_NONE, id=type)
qdel(cover) //deletes the cover, and the turret instance itself becomes its own cover.
else if(I.GetID())
//Behavior lock/unlock mangement
if(allowed(user))
locked = !locked
to_chat(user, span_notice("Controls are now [locked ? "locked" : "unlocked"]."))
else
to_chat(user, span_alert("Access denied."))
else if(I.tool_behaviour == TOOL_MULTITOOL && !locked)
if(!multitool_check_buffer(user, I))
return
var/obj/item/multitool/M = I
M.set_buffer(src)
balloon_alert(user, "saved to multitool buffer")
else
return ..()
/obj/machinery/porta_turret/emag_act(mob/user, obj/item/card/emag/emag_card)
if(obj_flags & EMAGGED)
return FALSE
balloon_alert(user, "threat assessment circuits shorted")
audible_message(span_hear("[src] hums oddly..."))
obj_flags |= EMAGGED
controllock = TRUE
set_disabled(6 SECONDS)
update_appearance()
//turns it back on. The cover popUp() popDown() are automatically called in process(), no need to define it here
return TRUE
/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
set_disabled(rand(6 SECONDS, 20 SECONDS))
remove_control()
/obj/machinery/porta_turret/take_damage(damage_amount, damage_type = BRUTE, damage_flag = "", sound_effect = TRUE, attack_dir, armour_penetration = 0)
. = ..()
if(. && atom_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)), 6 SECONDS)
/obj/machinery/porta_turret/proc/reset_attacked()
turret_flags &= ~TURRET_FLAG_SHOOT_ALL_REACT
/obj/machinery/porta_turret/atom_break(damage_flag)
. = ..()
if(.)
power_change()
SetInvisibility(INVISIBILITY_NONE, id=type)
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)))
return PROCESS_KILL
if(manual_control)
return PROCESS_KILL
if(uses_stored && !stored_gun)
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_or_basicmob(A))
var/mob/living/animal = A
if(animal.stat || in_faction(animal)) //don't target if dead or in faction
continue
targets += animal
continue
if(issilicon(A))
if(!(turret_flags & TURRET_FLAG_SHOOT_BORGS))
continue
var/mob/living/silicon/sillycone = A
if(ispAI(A))
continue
if(iscyborg(sillycone))
var/mob/living/silicon/robot/sillyconerobot = A
if(sillyconerobot.stat != CONSCIOUS)
continue
if(in_faction(sillyconerobot)) // borgs in faction are friendly
continue
if((ROLE_SYNDICATE in faction) && sillyconerobot.emagged) // special case: emagged station borgs are friendly to syndicate turrets
continue
targets += sillyconerobot
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/vehicle/sealed/mecha/mech = A
for(var/O in mech.occupants)
var/mob/living/occupant = O
if(!in_faction(occupant)) //If there is a user and they're not in our faction
if(assess_perp(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
SetInvisibility(INVISIBILITY_NONE, id=type)
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
SetInvisibility(2, id=type)
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 we aren't shooting heads then return a threatcount of 0
if (!(turret_flags & TURRET_FLAG_SHOOT_HEADS))
var/datum/job/apparent_job = SSjob.GetJob(perp.get_assignment())
if(apparent_job?.job_flags & JOB_HEAD_OF_STAFF)
return 0
if(turret_flags & TURRET_FLAG_AUTH_WEAPONS) //check for weapon authorization
if(!istype(perp.wear_id?.GetID(), /obj/item/card/id/advanced/chameleon))
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/record/crew/target = find_record(perpname)
if(!target || (target.wanted_status == WANTED_ARREST))
threatcount += 4
if((turret_flags & TURRET_FLAG_SHOOT_UNSHIELDED) && (!HAS_TRAIT(perp, TRAIT_MINDSHIELD)))
threatcount += 4
return threatcount
/obj/machinery/porta_turret/proc/in_faction(mob/target)
for(var/faction1 in faction)
if(faction1 in target.faction)
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_energy(reqpower)
A = new stun_projectile(T)
playsound(loc, stun_projectile_sound, 75, TRUE)
else
use_energy(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
if(ignore_faction)
A.ignored_factions = faction
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"
button_icon = 'icons/mob/actions/actions_mecha.dmi'
button_icon_state = "mech_cycle_equip_off"
/datum/action/turret_toggle/Trigger(trigger_flags)
var/obj/machinery/porta_turret/P = target
if(!istype(P))
return
P.setState(P.on,!P.mode)
/datum/action/turret_quit
name = "Release Control"
button_icon = 'icons/mob/actions/actions_mecha.dmi'
button_icon_state = "mech_eject"
/datum/action/turret_quit/Trigger(trigger_flags)
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_warning("Your uplink to [src] has been severed!"))
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 = TRUE
use_power = NO_POWER_USE
has_cover = FALSE
scan_range = 9
req_access = list(ACCESS_SYNDICATE)
uses_stored = FALSE
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)
turret_flags = TURRET_FLAG_SHOOT_CRIMINALS | TURRET_FLAG_SHOOT_ANOMALOUS | TURRET_FLAG_SHOOT_BORGS
desc = "A ballistic machine gun auto-turret."
/obj/machinery/porta_turret/syndicate/Initialize(mapload)
. = ..()
AddElement(/datum/element/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."
armor_type = /datum/armor/syndicate_turret
/datum/armor/syndicate_turret
melee = 40
bullet = 40
laser = 60
energy = 60
bomb = 60
fire = 100
acid = 100
/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(FACTION_NEUTRAL,FACTION_SILICON,FACTION_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/irs
lethal_projectile = /obj/projectile/bullet/c10mm/ap
lethal_projectile_sound = 'sound/weapons/gun/smg/shot.ogg'
stun_projectile = /obj/projectile/bullet/c10mm/ap
stun_projectile_sound = 'sound/weapons/gun/smg/shot.ogg'
armor_type = /datum/armor/syndicate_turret
faction = list(FACTION_PIRATE)
/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_type = /datum/armor/syndicate_shuttle
/datum/armor/syndicate_shuttle
melee = 50
bullet = 30
laser = 30
energy = 30
bomb = 80
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), 0.5 SECONDS)
addtimer(CALLBACK(src, PROC_REF(shootAt), target), 1 SECONDS)
addtimer(CALLBACK(src, PROC_REF(shootAt), target), 1.5 SECONDS)
return TRUE
/obj/machinery/porta_turret/ai
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/aux_base
name = "perimeter defense turret"
desc = "A plasma beam turret calibrated to defend outposts against non-humanoid fauna. It is more effective when exposed to the environment."
installation = null
uses_stored = FALSE
lethal_projectile = /obj/projectile/plasma/turret
lethal_projectile_sound = 'sound/weapons/plasma_cutter.ogg'
mode = TURRET_LETHAL //It would be useless in stun mode anyway
faction = list(FACTION_NEUTRAL,FACTION_SILICON,FACTION_TURRET) //Minebots, medibots, etc that should not be shot.
/obj/machinery/porta_turret/aux_base/assess_perp(mob/living/carbon/human/perp)
return 0 //Never shoot humanoids. You are on your own if Ashwalkers or the like attack!
/obj/machinery/porta_turret/aux_base/setup()
return
/obj/machinery/porta_turret/aux_base/interact(mob/user) //Controlled solely from the base console.
return
/obj/machinery/porta_turret/aux_base/Initialize(mapload)
. = ..()
cover.name = name
cover.desc = desc
/obj/machinery/porta_turret/centcom_shuttle
installation = null
max_integrity = 260
always_up = TRUE
use_power = NO_POWER_USE
has_cover = FALSE
scan_range = 9
stun_projectile = /obj/projectile/beam/laser
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(FACTION_NEUTRAL,FACTION_SILICON,FACTION_TURRET)
mode = TURRET_LETHAL
/obj/machinery/porta_turret/centcom_shuttle/Initialize(mapload)
. = ..()
AddElement(/datum/element/empprotection, EMP_PROTECT_SELF | EMP_PROTECT_WIRES)
/obj/machinery/porta_turret/centcom_shuttle/assess_perp(mob/living/carbon/human/perp)
return 0
/obj/machinery/porta_turret/centcom_shuttle/setup()
return
/obj/machinery/porta_turret/centcom_shuttle/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/weak/penetrator
lethal_projectile = /obj/projectile/beam/weak/penetrator
faction = list(FACTION_NEUTRAL,FACTION_SILICON,FACTION_TURRET)
////////////////////////
//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
interaction_flags_click = ALLOW_SILICON_REACH
/// 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 weakrefs to all turrets
var/list/turrets = list()
/obj/machinery/turretid/Initialize(mapload, ndir = 0, built = 0)
. = ..()
if(built)
locked = FALSE
power_change() //Checks power and initial settings
find_and_hang_on_wall()
/obj/machinery/turretid/Destroy()
turrets.Cut()
return ..()
/obj/machinery/turretid/Initialize(mapload) //map-placed turrets autolink turrets
. = ..()
if(!mapload)
return
// The actual area that control_area refers to
var/area/control_area_instance
if(control_area)
control_area_instance = get_area_instance_from_text(control_area)
if(!control_area_instance)
log_mapping("Bad control_area path for [src] at [AREACOORD(src)]: [control_area]")
if(!control_area_instance)
control_area_instance = get_area(src)
for(var/obj/machinery/porta_turret/T in control_area_instance)
turrets |= WEAKREF(T)
/obj/machinery/turretid/examine(mob/user)
. += ..()
if(issilicon(user) && !(machine_stat & BROKEN))
. += {"[span_notice("Ctrl-click [src] to [ enabled ? "disable" : "enable"] turrets.")]
[span_notice("Alt-click [src] to set turrets to [ lethal ? "stun" : "kill"].")]"}
/obj/machinery/turretid/attackby(obj/item/attacking_item, mob/user, params)
if(machine_stat & BROKEN)
return
if(attacking_item.tool_behaviour == TOOL_MULTITOOL)
if(!multitool_check_buffer(user, attacking_item))
return
var/obj/item/multitool/M = attacking_item
if(M.buffer && istype(M.buffer, /obj/machinery/porta_turret))
turrets |= WEAKREF(M.buffer)
to_chat(user, span_notice("You link \the [M.buffer] with \the [src]."))
return
if (issilicon(user))
return attack_hand(user)
var/id = attacking_item.GetID()
if(isnull(id))
return
if (check_access(id))
if(obj_flags & EMAGGED)
to_chat(user, span_warning("The turret control is unresponsive!"))
return
locked = !locked
to_chat(user, span_notice("You [ locked ? "lock" : "unlock"] the panel."))
else
to_chat(user, span_alert("Access denied."))
/obj/machinery/turretid/emag_act(mob/user, obj/item/card/emag/emag_card)
if(obj_flags & EMAGGED)
return FALSE
balloon_alert(user, "access analysis module shorted")
obj_flags |= EMAGGED
locked = FALSE