-
-
Notifications
You must be signed in to change notification settings - Fork 452
/
mecha.dm
1323 lines (1172 loc) · 47 KB
/
mecha.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 MECHA_INT_FIRE (1<<0)
#define MECHA_INT_TEMP_CONTROL (1<<1)
#define MECHA_INT_SHORT_CIRCUIT (1<<2)
#define MECHA_INT_TANK_BREACH (1<<3)
#define MECHA_INT_CONTROL_LOST (1<<4)
#define MECHA_MELEE (1<<0)
#define MECHA_RANGED (1<<1)
#define FRONT_ARMOUR 1
#define SIDE_ARMOUR 2
#define BACK_ARMOUR 3
#define MECHA_MAX_COOLDOWN 30 // Prevents long cooldown equipment from messing up combat
/obj/mecha
name = "mecha"
desc = "Exosuit"
icon = 'icons/mecha/mecha.dmi'
density = TRUE //Dense. To raise the heat.
opacity = TRUE ///opaque. Menacing.
move_resist = MOVE_FORCE_EXTREMELY_STRONG //no pulling around.
resistance_flags = FIRE_PROOF | ACID_PROOF
layer = BELOW_MOB_LAYER//icon draw layer
infra_luminosity = 15 //byond implementation is bugged.
force = 5
light_system = MOVABLE_LIGHT_DIRECTIONAL
light_range = 8
light_on = FALSE
flags_1 = HEAR_1
demolition_mod = 3 // mech punch go brr
var/ruin_mecha = FALSE //if the mecha starts on a ruin, don't automatically give it a tracking beacon to prevent metagaming.
var/can_move = 0 //time of next allowed movement
var/mob/living/carbon/occupant = null
var/step_in = 10 //make a step in step_in/10 sec.
var/dir_in = 2//What direction will the mech face when entered/powered on? Defaults to South.
var/normal_step_energy_drain = 0 //How much energy the mech will consume each time it moves. This variable is a backup for when leg actuators affect the energy drain.
var/step_energy_drain = 0
var/melee_energy_drain = 15
var/overload_step_energy_drain_min = 100
max_integrity = 300 //max_integrity is base health
var/deflect_chance = 10 //chance to deflect the incoming projectiles, hits, or lesser the effect of ex_act.
var/super_deflects = FALSE //Redirection of projectiles rather than just L bozoing them
armor = list(MELEE = 20, BULLET = 10, LASER = 0, ENERGY = 0, BOMB = 0, BIO = 0, RAD = 0, FIRE = 100, ACID = 100)
var/list/facing_modifiers = list(FRONT_ARMOUR = 1.5, SIDE_ARMOUR = 1, BACK_ARMOUR = 0.5)
var/equipment_disabled = 0 //disabled due to EMP
var/obj/item/stock_parts/cell/cell ///Keeps track of the mech's cell
var/obj/item/stock_parts/scanning_module/scanmod ///Keeps track of the mech's scanning module
var/obj/item/stock_parts/capacitor/capacitor ///Keeps track of the mech's capacitor
var/state = 0
var/last_message = 0
var/add_req_access = 1
var/maint_access = FALSE
var/dna_lock //dna-locking the mech
var/list/proc_res = list() //stores proc owners, like proc_res["functionname"] = owner reference
var/datum/effect_system/spark_spread/spark_system = new
var/lights = FALSE
var/last_user_hud = 1 // used to show/hide the mecha hud while preserving previous preference
var/completely_disabled = FALSE //stops the mech from doing anything
var/omnidirectional_attacks = FALSE //lets mech shoot anywhere, not just in front of it
var/bumpsmash = 0 //Whether or not the mech destroys walls by running into it.
//inner atmos
var/use_internal_tank = FALSE
var/internal_tank_valve = ONE_ATMOSPHERE
var/obj/machinery/portable_atmospherics/canister/internal_tank
var/datum/gas_mixture/cabin_air
var/obj/machinery/atmospherics/components/unary/portables_connector/connected_port = null
var/obj/item/radio/mech/radio
var/list/trackers = list()
var/max_temperature = 25000
var/internal_damage_threshold = 50 //health percentage below which internal damage is possible
var/internal_damage = 0 //contains bitflags
var/list/operation_req_access = list()//required access level for mecha operation
var/list/internals_req_access = list(ACCESS_MECH_ENGINE, ACCESS_MECH_SCIENCE)//REQUIRED ACCESS LEVEL TO OPEN CELL COMPARTMENT
var/wreckage
var/list/equipment = new
var/obj/item/mecha_parts/mecha_equipment/selected
var/max_equip = 3
var/datum/events/events
var/stepsound = 'sound/mecha/mechstep.ogg'
var/turnsound = 'sound/mecha/mechturn.ogg'
var/meleesound = TRUE //does it play a sound when melee attacking (so mime mech can turn it off)
var/melee_cooldown = 10
var/melee_can_hit = TRUE
var/silicon_pilot = FALSE //set to true if an AI or MMI is piloting.
///Camera installed into the mech
var/obj/machinery/camera/exosuit/chassis_camera
var/enter_delay = 40 //Time taken to enter the mech
var/exit_delay = 20 //Time to exit mech
var/destruction_sleep_duration = 20 //Time that mech pilot is put to sleep for if mech is destroyed
var/enclosed = TRUE //Set to false for open-cockpit mechs
var/silicon_icon_state = null //if the mech has a different icon when piloted by an AI or MMI
var/is_currently_ejecting = FALSE //Mech cannot use equiptment when true, set to true if pilot is trying to exit mech
var/guns_allowed = FALSE //Whether or not the mech is allowed to mount guns (mecha_equipment/weapon)
var/melee_allowed = FALSE //Whether or not the mech is allowed to mount melee weapons (mecha_equipment/melee_weapon)
//Action datums
var/datum/action/innate/mecha/mech_eject/eject_action = new
var/datum/action/innate/mecha/mech_toggle_internals/internals_action = new
var/datum/action/innate/mecha/mech_cycle_equip/cycle_action = new
var/datum/action/innate/mecha/mech_toggle_lights/lights_action = new
var/datum/action/innate/mecha/mech_view_stats/stats_action = new
var/datum/action/innate/mecha/mech_defence_mode/defence_action = new
var/datum/action/innate/mecha/mech_overload_mode/overload_action = new
var/datum/effect_system/fluid_spread/smoke/smoke_system = new //not an action, but trigged by one
var/datum/action/innate/mecha/mech_smoke/smoke_action = new
var/datum/action/innate/mecha/mech_zoom/zoom_action = new
var/datum/action/innate/mecha/mech_switch_damtype/switch_damtype_action = new
var/datum/action/innate/mecha/mech_toggle_phasing/phasing_action = new
var/datum/action/innate/mecha/strafe/strafing_action = new
//Action vars
var/defence_mode = FALSE
var/defence_mode_deflect_chance = 15
var/leg_overload_mode = FALSE
var/leg_overload_coeff = 100
var/zoom_mode = FALSE
var/smoke = 5
var/smoke_ready = 1
var/smoke_cooldown = 100
var/phasing = FALSE
var/phasing_energy_drain = 200
var/phase_state = "" //icon_state when phasing
var/strafe = FALSE //If we are strafing
var/pivot_step = FALSE
var/nextsmash = 0
var/smashcooldown = 3 //deciseconds
var/ejection_distance = 0 //violently ejects the pilot when destroyed
var/occupant_sight_flags = 0 //sight flags to give to the occupant (e.g. mech mining scanner gives meson-like vision)
var/mouse_pointer
hud_possible = list (DIAG_STAT_HUD, DIAG_BATT_HUD, DIAG_MECH_HUD, DIAG_TRACK_HUD)
/obj/item/radio/mech //this has to go somewhere
/obj/mecha/Initialize(mapload)
. = ..()
events = new
icon_state += "-open"
add_radio()
add_cabin()
if (enclosed)
add_airtank()
spark_system.set_up(2, 0, src)
spark_system.attach(src)
smoke_system.set_up(3, location = src)
smoke_system.attach(src)
add_cell()
add_scanmod()
add_capacitor()
START_PROCESSING(SSobj, src)
GLOB.poi_list |= src
log_message("[src.name] created.", LOG_MECHA)
GLOB.mechas_list += src //global mech list
prepare_huds()
for(var/datum/atom_hud/data/diagnostic/diag_hud in GLOB.huds)
diag_hud.add_atom_to_hud(src)
diag_hud_set_mechhealth()
diag_hud_set_mechcell()
diag_hud_set_mechstat()
RegisterSignal(src, COMSIG_LIGHT_EATER_ACT, PROC_REF(on_light_eater))
ADD_TRAIT(src, TRAIT_SHIELDBUSTER, INNATE_TRAIT) // previously it didn't even check shields at all, now it still doesn't but does some fun stuff in the process
/// Special light eater handling
/obj/mecha/proc/on_light_eater(obj/vehicle/sealed/source, datum/light_eater)
SIGNAL_HANDLER
visible_message(span_danger("[src]'s lights burn out!"))
set_light_on(FALSE)
lights_action.Remove(occupant)
return COMPONENT_BLOCK_LIGHT_EATER
/obj/mecha/update_icon_state()
. = ..()
if (silicon_pilot && silicon_icon_state)
icon_state = silicon_icon_state
/obj/mecha/get_cell()
return cell
/obj/mecha/Destroy()
var/mob/living/carbon/C = occupant
if(C && !ejection_distance)
C.SetSleeping(destruction_sleep_duration)
go_out()
var/mob/living/silicon/ai/AI
for(var/mob/M in src) //Let's just be ultra sure
if(isAI(M))
occupant = null
AI = M //AIs are loaded into the mech computer itself. When the mech dies, so does the AI. They can be recovered with an AI card from the wreck.
else
M.forceMove(loc)
if(C && ejection_distance)
var/turf/target = get_edge_target_turf(C, dir)
C.throw_at(target, 10, 1)
for(var/obj/item/mecha_parts/mecha_equipment/E in equipment)
E.detach(loc)
qdel(E)
if(cell)
qdel(cell)
if(scanmod)
qdel(scanmod)
if(capacitor)
qdel(capacitor)
if(internal_tank)
qdel(internal_tank)
if(AI)
AI.gib() //No wreck, no AI to recover
STOP_PROCESSING(SSobj, src)
GLOB.poi_list.Remove(src)
equipment.Cut()
cell = null
scanmod = null
capacitor = null
internal_tank = null
assume_air(cabin_air)
cabin_air = null
qdel(spark_system)
spark_system = null
qdel(smoke_system)
smoke_system = null
GLOB.mechas_list -= src //global mech list
return ..()
/obj/mecha/proc/restore_equipment()
equipment_disabled = FALSE
if(occupant)
SEND_SOUND(occupant, sound('sound/items/timer.ogg', volume=50))
to_chat(occupant, "<span=notice>Equipment control unit has been rebooted successfully.</span>")
occupant.update_mouse_pointer()
/obj/mecha/CheckParts(list/parts_list)
..()
cell = locate(/obj/item/stock_parts/cell) in contents
scanmod = locate(/obj/item/stock_parts/scanning_module) in contents
capacitor = locate(/obj/item/stock_parts/capacitor) in contents
////////////////////////
////// Helpers /////////
////////////////////////
/obj/mecha/proc/add_airtank()
internal_tank = new /obj/machinery/portable_atmospherics/canister/air(src)
return internal_tank
/obj/mecha/proc/add_cell(obj/item/stock_parts/cell/C=null) ///Adds a cell, for use in Map-spawned mechs, Nuke Ops mechs, and admin-spawned mechs. Mechs built by hand will replace this.
QDEL_NULL(cell)
if(C)
C.forceMove(src)
cell = C
return
cell = new /obj/item/stock_parts/cell/high/plus(src)
/obj/mecha/proc/add_scanmod(obj/item/stock_parts/scanning_module/sm=null) ///Adds a scanning module, for use in Map-spawned mechs, Nuke Ops mechs, and admin-spawned mechs. Mechs built by hand will replace this.
QDEL_NULL(scanmod)
if(sm)
sm.forceMove(src)
scanmod = sm
return
scanmod = new /obj/item/stock_parts/scanning_module(src)
/obj/mecha/proc/add_capacitor(obj/item/stock_parts/capacitor/cap=null) ///Adds a capacitor, for use in Map-spawned mechs, Nuke Ops mechs, and admin-spawned mechs. Mechs built by hand will replace this.
QDEL_NULL(capacitor)
if(cap)
cap.forceMove(src)
capacitor = cap
return
capacitor = new /obj/item/stock_parts/capacitor(src)
/obj/mecha/proc/add_cabin()
cabin_air = new
cabin_air.set_temperature(T20C)
cabin_air.set_volume(200)
cabin_air.set_moles(GAS_O2, O2STANDARD*cabin_air.return_volume()/(R_IDEAL_GAS_EQUATION*cabin_air.return_temperature()))
cabin_air.set_moles(GAS_N2, N2STANDARD*cabin_air.return_volume()/(R_IDEAL_GAS_EQUATION*cabin_air.return_temperature()))
return cabin_air
/obj/mecha/proc/add_radio()
radio = new(src)
radio.name = "[src] radio"
radio.icon = icon
radio.icon_state = icon_state
radio.subspace_transmission = TRUE
/obj/mecha/proc/can_use(mob/user)
if(user != occupant)
return FALSE
if(user && ismob(user))
if(!user.incapacitated())
return TRUE
return FALSE
/obj/mecha/CanAllowThrough(atom/movable/mover, turf/target)
. = ..() // if something can go through machines it can go through mechs
if(istype(mover) && (mover.pass_flags & PASSMECH))
return TRUE
////////////////////////////////////////////////////////////////////////////////
/obj/mecha/examine(mob/user)
. = ..()
var/hide_weapon = locate(/obj/item/mecha_parts/concealed_weapon_bay) in contents
var/hidden_weapon = hide_weapon ? (locate(/obj/item/mecha_parts/mecha_equipment/weapon) in equipment) : null
var/list/visible_equipment = equipment - hidden_weapon
if(visible_equipment.len)
. += "It's equipped with:"
for(var/obj/item/mecha_parts/mecha_equipment/ME in visible_equipment)
. += "[icon2html(ME, user)] \A [ME]."
if(occupant && occupant == user)
if(armor.bio || armor.bomb || armor.bullet || armor.energy || armor.laser || armor.melee || armor.fire || armor.acid || deflect_chance || max_temperature)
. += "<span class='notice'>It has a <a href='?src=[REF(src)];list_armor=1'>tag</a> listing its protection classes.</span>"
if(!enclosed)
if(silicon_pilot)
. += "[src] appears to be piloting itself..."
else if(occupant && occupant != user) //!silicon_pilot implied
. += "You can see [occupant] inside."
if(ishuman(user))
var/mob/living/carbon/human/H = user
for(var/O in H.held_items)
if(istype(O, /obj/item/gun))
. += span_warning("It looks like you can hit the pilot directly if you target the center or above.")
break //in case user is holding two guns
//Armor tag
/obj/mecha/Topic(href, href_list)
. = ..()
if(href_list["list_armor"])
to_chat(usr, "[armor.show_protection_classes()]")
//processing internal damage, temperature, air regulation, alert updates, lights power use.
/obj/mecha/process()
var/internal_temp_regulation = TRUE
if(internal_damage)
if(internal_damage & MECHA_INT_FIRE)
if(!(internal_damage & MECHA_INT_TEMP_CONTROL) && prob(5))
clearInternalDamage(MECHA_INT_FIRE)
if(internal_tank)
var/datum/gas_mixture/int_tank_air = internal_tank.return_air()
if(int_tank_air.return_pressure() > internal_tank.maximum_pressure && !(internal_damage & MECHA_INT_TANK_BREACH))
setInternalDamage(MECHA_INT_TANK_BREACH)
if(int_tank_air && int_tank_air.return_volume() > 0) //heat the air_contents
int_tank_air.set_temperature(min(6000+T0C, int_tank_air.return_temperature()+rand(10,15)))
if(cabin_air && cabin_air.return_volume()>0)
cabin_air.set_temperature(min(6000+T0C, cabin_air.return_temperature()+rand(10,15)))
if(cabin_air.return_temperature() > max_temperature/2)
take_damage(4/round(max_temperature/cabin_air.return_temperature(),0.1), BURN, 0, 0)
if(internal_damage & MECHA_INT_TEMP_CONTROL)
internal_temp_regulation = FALSE
if(internal_damage & MECHA_INT_TANK_BREACH) //remove some air from internal tank
if(internal_tank)
assume_air_ratio(internal_tank.return_air(), 0.1)
if(internal_damage & MECHA_INT_SHORT_CIRCUIT)
if(get_charge())
spark_system.start()
cell.charge -= min(20,cell.charge)
cell.maxcharge -= min(20,cell.maxcharge)
if(internal_temp_regulation)
if(cabin_air && cabin_air.return_volume() > 0)
var/delta = cabin_air.return_temperature() - T20C
cabin_air.set_temperature(cabin_air.return_temperature() - max(-10, min(10, round(delta/4,0.1))))
if(internal_tank)
var/datum/gas_mixture/tank_air = internal_tank.return_air()
var/release_pressure = internal_tank_valve
var/cabin_pressure = cabin_air.return_pressure()
var/pressure_delta = min(release_pressure - cabin_pressure, (tank_air.return_pressure() - cabin_pressure)/2)
var/transfer_moles = 0
if(pressure_delta > 0) //cabin pressure lower than release pressure
if(tank_air.return_temperature() > 0)
transfer_moles = pressure_delta*cabin_air.return_volume()/(cabin_air.return_temperature() * R_IDEAL_GAS_EQUATION)
tank_air.transfer_to(cabin_air,transfer_moles)
else if(pressure_delta < 0) //cabin pressure higher than release pressure
var/datum/gas_mixture/t_air = return_air()
pressure_delta = cabin_pressure - release_pressure
if(t_air)
pressure_delta = min(cabin_pressure - t_air.return_pressure(), pressure_delta)
if(pressure_delta > 0) //if location pressure is lower than cabin pressure
transfer_moles = pressure_delta*cabin_air.return_volume()/(cabin_air.return_temperature() * R_IDEAL_GAS_EQUATION)
cabin_air.transfer_to(t_air, transfer_moles)
if(occupant)
if(cell)
var/cellcharge = cell.charge/cell.maxcharge
switch(cellcharge)
if(0.75 to INFINITY)
occupant.clear_alert("charge")
if(0.5 to 0.75)
occupant.throw_alert("charge", /atom/movable/screen/alert/lowcell, 1)
if(0.25 to 0.5)
occupant.throw_alert("charge", /atom/movable/screen/alert/lowcell, 2)
if(0.01 to 0.25)
occupant.throw_alert("charge", /atom/movable/screen/alert/lowcell, 3)
else
occupant.throw_alert("charge", /atom/movable/screen/alert/emptycell)
var/integrity = atom_integrity/max_integrity*100
switch(integrity)
if(30 to 45)
occupant.throw_alert("mech damage", /atom/movable/screen/alert/low_mech_integrity, 1)
if(15 to 35)
occupant.throw_alert("mech damage", /atom/movable/screen/alert/low_mech_integrity, 2)
if(-INFINITY to 15)
occupant.throw_alert("mech damage", /atom/movable/screen/alert/low_mech_integrity, 3)
else
occupant.clear_alert("mech damage")
var/atom/checking = occupant.loc
// recursive check to handle all cases regarding very nested occupants,
// such as brainmob inside brainitem inside MMI inside mecha
while (!isnull(checking))
if (isturf(checking))
// hit a turf before hitting the mecha, seems like they have
// been moved out
occupant.clear_alert("charge")
occupant.clear_alert("mech damage")
RemoveActions(occupant, human_occupant=1)
occupant = null
break
else if (checking == src)
break // all good
checking = checking.loc
if(lights)
var/lights_energy_drain = 2
use_power(lights_energy_drain)
if(!enclosed && occupant?.incapacitated()) //no sides mean it's easy to just sorta fall out if you're incapacitated.
visible_message(span_warning("[occupant] tumbles out of the cockpit!"))
go_out() //Maybe we should install seat belts?
//Diagnostic HUD updates
diag_hud_set_mechhealth()
diag_hud_set_mechcell()
diag_hud_set_mechstat()
/obj/mecha/fire_act() //Check if we should ignite the pilot of an open-canopy mech
. = ..()
if (occupant && !enclosed && !silicon_pilot)
if (occupant.fire_stacks < 5)
occupant.adjust_fire_stacks(1)
occupant.ignite_mob()
/obj/mecha/proc/drop_item()//Derpfix, but may be useful in future for engineering exosuits.
return
/obj/mecha/Hear(message, atom/movable/speaker, message_language, raw_message, radio_freq, list/spans, list/message_mods = list())
. = ..()
if(speaker == occupant)
if(radio?.broadcasting)
radio.talk_into(speaker, text, , spans, message_language, message_mods)
//flick speech bubble
var/list/speech_bubble_recipients = list()
for(var/mob/M in get_hearers_in_view(7,src))
if(M.client)
speech_bubble_recipients.Add(M.client)
INVOKE_ASYNC(GLOBAL_PROC, /proc/flick_overlay_global, image('icons/mob/talk.dmi', src, "machine[say_test(raw_message)]",MOB_LAYER+1), speech_bubble_recipients, 30)
////////////////////////////
///// Action processing ////
////////////////////////////
/obj/mecha/proc/click_action(atom/target, mob/user, params)
if(!occupant || occupant != user )
return
if(!locate(/turf) in list(target,target.loc)) // Prevents inventory from being drilled
return
if(completely_disabled)
return
if(is_currently_ejecting)
return
if(phasing)
occupant_message("Unable to interact with objects while phasing")
return
if(user.incapacitated())
return
if(state)
occupant_message(span_warning("Maintenance protocols in effect."))
return
if(!get_charge())
return
if(src == target)
return
var/dir_to_target = get_dir(src,target)
if(!omnidirectional_attacks && dir_to_target && !(dir_to_target & dir))//wrong direction
return
if(internal_damage & MECHA_INT_CONTROL_LOST)
target = pick(view(3,target))
if(!target)
return
// No shotgun swapping
for(var/obj/item/mecha_parts/mecha_equipment/weapon/W in equipment)
if(!W.equip_ready && (W.equip_cooldown < MECHA_MAX_COOLDOWN))
return
var/mob/living/L = user
if(!Adjacent(target))
if(!synth_check(user, SYNTH_RESTRICTED_WEAPON))
return
if(selected && selected.is_ranged())
if(HAS_TRAIT(L, TRAIT_PACIFISM) && selected.harmful)
to_chat(user, span_warning("You don't want to harm other living beings!"))
return
if(selected.action(target, user, params))
selected.start_cooldown()
else if(selected && selected.is_melee())
if(!synth_check(user, SYNTH_RESTRICTED_WEAPON))
return
if(isliving(target) && selected.harmful && HAS_TRAIT(L, TRAIT_PACIFISM))
to_chat(user, span_warning("You don't want to harm other living beings!"))
return
if(isliving(target) && !selected.harmful && HAS_TRAIT(L, TRAIT_NO_STUN_WEAPONS))
to_chat(user, span_warning("You cannot use non-lethal weapons!"))
return
if(istype(selected, /obj/item/mecha_parts/mecha_equipment/melee_weapon)) //Need to make a special check for melee weapons with cleave attacks
var/obj/item/mecha_parts/mecha_equipment/melee_weapon/W = selected
if(HAS_TRAIT(L, TRAIT_PACIFISM) && W.cleave)
to_chat(user, span_warning("You don't want to harm other living beings!"))
return
if(selected.action(target, user, params))
selected.start_cooldown()
else
default_melee_attack(target)
/obj/mecha/proc/default_melee_attack(atom/target)
if(internal_damage & MECHA_INT_CONTROL_LOST)
target = pick(oview(1,src))
if(!melee_can_hit || !istype(target, /atom))
return
if(equipment_disabled)
return
target.mech_melee_attack(src, force, TRUE)
melee_can_hit = FALSE
spawn(melee_cooldown)
melee_can_hit = TRUE
/obj/mecha/proc/range_action(atom/target)
return
//////////////////////////////////
//////// Movement procs ////////
//////////////////////////////////
/obj/mecha/Move(atom/newloc, direct)
. = ..()
if(.)
events.fireEvent("onMove",get_turf(src))
if (internal_tank?.disconnect()) // Something moved us and broke connection
occupant_message(span_warning("Air port connection teared off!"))
log_message("Lost connection to gas port.", LOG_MECHA)
/obj/mecha/Process_Spacemove(movement_dir = 0)
. = ..()
if(.)
return TRUE
var/atom/movable/backup = get_spacemove_backup()
if(backup)
if(istype(backup) && movement_dir && !backup.anchored)
if(backup.newtonian_move(turn(movement_dir, 180)))
if(occupant)
to_chat(occupant, span_info("You push off of [backup] to propel yourself."))
return TRUE
/obj/mecha/relaymove(mob/user,direction)
if(completely_disabled)
return
if(!direction)
return
if(user != occupant) //While not "realistic", this piece is player friendly.
user.forceMove(get_turf(src))
to_chat(user, span_notice("You climb out from [src]."))
return FALSE
if(internal_tank?.connected_port)
if(world.time - last_message > 20)
occupant_message(span_warning("Unable to move while connected to the air system port!"))
last_message = world.time
return FALSE
if(state)
if(world.time - last_message > 20)
occupant_message(span_danger("Maintenance protocols in effect."))
last_message = world.time
return
return domove(direction)
/obj/mecha/proc/domove(direction)
if(can_move >= world.time)
return FALSE
if((direction & (DOWN|UP)) && !get_step_multiz(get_turf(src), direction))
direction &= ~(DOWN|UP) // remove vertical component
if(!direction) // don't bother moving without a direction
return FALSE
if(!Process_Spacemove(direction))
return FALSE
if(!has_charge(step_energy_drain))
return FALSE
if(defence_mode)
if(world.time - last_message > 20)
occupant_message(span_danger("Unable to move while in defence mode"))
last_message = world.time
return FALSE
if(zoom_mode)
if(world.time - last_message > 20)
occupant_message("Unable to move while in zoom mode.")
last_message = world.time
return FALSE
if(!cell)
if(world.time - last_message > 20)
occupant_message(span_warning("Missing power cell."))
last_message = world.time
return FALSE
if(!scanmod || !capacitor)
if(world.time - last_message > 20)
occupant_message(span_warning("Missing [scanmod? "capacitor" : "scanning module"]."))
last_message = world.time
return FALSE
var/move_result = 0
var/oldloc = loc
if(internal_damage & MECHA_INT_CONTROL_LOST)
set_glide_size(DELAY_TO_GLIDE_SIZE(step_in * check_eva()))
move_result = mechsteprand()
else if(dir != direction && (!strafe || occupant?.client?.keys_held["Alt"]))
move_result = mechturn(direction)
else
set_glide_size(DELAY_TO_GLIDE_SIZE(step_in * check_eva()))
move_result = mechstep(direction)
if(move_result || loc != oldloc)// halfway done diagonal move still returns false
use_power(step_energy_drain)
if(leg_overload_mode)
take_damage(2, BRUTE)
can_move = world.time + step_in * check_eva()
return TRUE
return FALSE
/obj/mecha/proc/mechturn(direction)
setDir(direction)
if(turnsound && has_gravity())
playsound(src,turnsound,40,1)
return TRUE
/obj/mecha/proc/mechstep(direction)
var/current_dir = dir
var/result = step(src,direction)
if(strafe && !pivot_step)
setDir(current_dir)
if(result && stepsound && has_gravity())
playsound(src,stepsound,40,1)
return result
/obj/mecha/proc/mechsteprand()
var/result = step_rand(src)
if(result && stepsound && has_gravity())
playsound(src,stepsound,40,1)
return result
/obj/mecha/setDir()
. = ..()
if(occupant)
occupant.setDir(dir) // keep the pilot facing the direction of the mech or bad things happen
/obj/mecha/Bump(atom/obstacle)
var/turf/newloc = get_step(src,dir)
var/area/newarea = newloc.loc
if(phasing && ((newloc.turf_flags & NOJAUNT) || newarea.noteleport || SSmapping.level_trait(newloc.z, ZTRAIT_NOPHASE)))
to_chat(occupant, span_warning("Some strange aura is blocking the way."))
return //If we're trying to phase and it's NOT ALLOWED, don't bump
if(istype(newloc, /turf/closed/indestructible))
return //If the turf is indestructible don't bother trying
if(phasing && get_charge() >= phasing_energy_drain && !throwing)
spawn()
if(can_move)
can_move = 0
if(phase_state)
flick(phase_state, src)
forceMove(newloc)
use_power(phasing_energy_drain)
sleep(step_in * check_eva()*3)
can_move = TRUE
else
if(..()) //mech was thrown
return
if(bumpsmash && occupant) //Need a pilot to push the PUNCH button.
if(!equipment_disabled)
if(nextsmash < world.time)
obstacle.mech_melee_attack(src, force, FALSE) //Non-equipment melee attack
nextsmash = world.time + smashcooldown
if(!obstacle || obstacle.CanPass(src,newloc))
step(src,dir)
if(isobj(obstacle))
var/obj/O = obstacle
if(!O.anchored)
step(obstacle, dir)
else if(ismob(obstacle))
var/mob/M = obstacle
if(!M.anchored)
step(obstacle, dir)
///////////////////////////////////
//////// Internal damage ////////
///////////////////////////////////
/obj/mecha/proc/check_for_internal_damage(list/possible_int_damage,ignore_threshold=null)
if(!islist(possible_int_damage) || !length(possible_int_damage))
return
if(prob(20))
if(ignore_threshold || atom_integrity*100/max_integrity < internal_damage_threshold)
for(var/T in possible_int_damage)
if(internal_damage & T)
possible_int_damage -= T
var/int_dam_flag = pick(possible_int_damage)
if(int_dam_flag)
setInternalDamage(int_dam_flag)
if(prob(5))
if(ignore_threshold || atom_integrity*100/max_integrity < internal_damage_threshold)
var/obj/item/mecha_parts/mecha_equipment/ME = pick(equipment)
if(ME)
qdel(ME)
return
/obj/mecha/proc/setInternalDamage(int_dam_flag)
internal_damage |= int_dam_flag
log_message("Internal damage of type [int_dam_flag].", LOG_MECHA)
SEND_SOUND(occupant, sound('sound/machines/warning-buzzer.ogg',wait=0))
diag_hud_set_mechstat()
return
/obj/mecha/proc/clearInternalDamage(int_dam_flag)
if(internal_damage & int_dam_flag)
switch(int_dam_flag)
if(MECHA_INT_TEMP_CONTROL)
occupant_message(span_boldnotice("Life support system reactivated."))
if(MECHA_INT_FIRE)
occupant_message(span_boldnotice("Internal fire extinquished."))
if(MECHA_INT_TANK_BREACH)
occupant_message(span_boldnotice("Damaged internal tank has been sealed."))
internal_damage &= ~int_dam_flag
diag_hud_set_mechstat()
/////////////////////////////////////
//////////// AI piloting ////////////
/////////////////////////////////////
/obj/mecha/attack_ai(mob/living/silicon/ai/user)
if(!isAI(user))
return
//Allows the Malf to scan a mech's status and loadout, helping it to decide if it is a worthy chariot.
if(user.can_dominate_mechs)
examine(user) //Get diagnostic information!
if(user.nuking)
to_chat(user, span_warning("Unable to assume control of mech while attempting to self-destruct the station."))
return
for(var/obj/item/mecha_parts/mecha_tracking/B in trackers)
to_chat(user, span_danger("Warning: Tracking Beacon detected. Enter at your own risk. Beacon Data:"))
to_chat(user, "[B.get_mecha_info()]")
break
//Nothing like a big, red link to make the player feel powerful!
to_chat(user, "<a href='?src=[REF(user)];ai_take_control=[REF(src)]'>[span_userdanger("ASSUME DIRECT CONTROL?")]</a><br>")
else
examine(user)
if(occupant)
to_chat(user, span_warning("This exosuit has a pilot and cannot be controlled."))
return
var/can_control_mech = FALSE
for(var/obj/item/mecha_parts/mecha_tracking/ai_control/A in trackers)
can_control_mech = TRUE
to_chat(user, "[span_notice("[icon2html(src, user)] Status of [name]:")]\n[A.get_mecha_info()]")
break
if(!can_control_mech)
to_chat(user, span_warning("You cannot control exosuits without AI control beacons installed."))
return
to_chat(user, "<a href='?src=[REF(user)];ai_take_control=[REF(src)]'>[span_boldnotice("Take control of exosuit?")]</a><br>")
/obj/mecha/transfer_ai(interaction, mob/user, mob/living/silicon/ai/AI, obj/item/aicard/card)
if(!..())
return
//Transfer from core or card to mech. Proc is called by mech.
switch(interaction)
if(AI_TRANS_TO_CARD) //Upload AI from mech to AI card.
if(!state) //Mech must be in maint mode to allow carding.
to_chat(user, span_warning("[name] must have maintenance protocols active in order to allow a transfer."))
return
AI = occupant
if(!AI || !isAI(occupant)) //Mech does not have an AI for a pilot
to_chat(user, span_warning("No AI detected in the [name] onboard computer."))
return
AI.ai_restore_power()//So the AI initially has power.
AI.control_disabled = TRUE
AI.radio_enabled = FALSE
AI.disconnect_shell()
RemoveActions(AI, TRUE)
occupant = null
silicon_pilot = FALSE
AI.forceMove(card)
card.AI = AI
AI.controlled_mech = null
AI.remote_control = null
icon_state = initial(icon_state)+"-open"
to_chat(AI, "You have been downloaded to a mobile storage device. Wireless connection offline.")
to_chat(user, "[span_boldnotice("Transfer successful")]: [AI.name] ([rand(1000,9999)].exe) removed from [name] and stored within local memory.")
if(AI_MECH_HACK) //Called by AIs on the mech
if(AI.can_dominate_mechs)
if(occupant) //Oh, I am sorry, were you using that?
to_chat(AI, span_warning("Pilot detected! Forced ejection initiated!"))
to_chat(occupant, span_danger("You have been forcibly ejected!"))
go_out(1) //IT IS MINE, NOW. SUCK IT, RD!
ai_enter_mech(AI, interaction)
if(AI_TRANS_FROM_CARD) //Using an AI card to upload to a mech.
AI = card.AI
if(!AI)
to_chat(user, span_warning("There is no AI currently installed on this device."))
return
if(AI.deployed_shell) //Recall AI if shelled so it can be checked for a client
AI.disconnect_shell()
if(AI.stat || !AI.client)
to_chat(user, span_warning("[AI.name] is currently unresponsive, and cannot be uploaded."))
return
if(occupant || dna_lock) //Normal AIs cannot steal mechs!
to_chat(user, span_warning("Access denied. [name] is [occupant ? "currently occupied" : "secured with a DNA lock"]."))
return
AI.control_disabled = FALSE
AI.radio_enabled = TRUE
to_chat(user, "[span_boldnotice("Transfer successful")]: [AI.name] ([rand(1000,9999)].exe) installed and executed successfully. Local copy has been removed.")
card.AI = null
ai_enter_mech(AI, interaction)
//Hack and From Card interactions share some code, so leave that here for both to use.
/obj/mecha/proc/ai_enter_mech(mob/living/silicon/ai/AI, interaction)
AI.ai_restore_power()
AI.forceMove(src)
occupant = AI
silicon_pilot = TRUE
icon_state = initial(icon_state)
update_appearance()
playsound(src, 'sound/machines/windowdoor.ogg', 50, 1)
if(!internal_damage)
SEND_SOUND(occupant, sound('sound/mecha/nominal.ogg',volume=50))
AI.eyeobj?.forceMove(src)
AI.eyeobj?.RegisterSignal(src, COMSIG_MOVABLE_MOVED, TYPE_PROC_REF(/mob/camera/ai_eye, update_visibility))
AI.controlled_mech = src
AI.remote_control = src
AI.mobility_flags = ALL //Much easier than adding AI checks! Be sure to set this back to 0 if you decide to allow an AI to leave a mech somehow.
AI.can_shunt = FALSE //ONE AI ENTERS. NO AI LEAVES.
to_chat(AI, AI.can_dominate_mechs ? span_announce("Takeover of [name] complete! You are now loaded onto the onboard computer. Do not attempt to leave the station sector!") :\
span_notice("You have been uploaded to a mech's onboard computer."))
to_chat(AI, "<span class='reallybig boldnotice'>Use Middle-Mouse to activate mech functions and equipment. Click normally for AI interactions.</span>")
register_occupant(AI)
if(interaction == AI_TRANS_FROM_CARD)
GrantActions(AI, FALSE) //No eject/return to core action for AI uploaded by card
else
GrantActions(AI, !AI.can_dominate_mechs)
//An actual AI (simple_animal mecha pilot) entering the mech
/obj/mecha/proc/aimob_enter_mech(mob/living/simple_animal/hostile/syndicate/mecha_pilot/pilot_mob)
if(pilot_mob && pilot_mob.Adjacent(src))
if(occupant)
return
icon_state = initial(icon_state)
occupant = pilot_mob
pilot_mob.mecha = src
pilot_mob.forceMove(src)
register_occupant(pilot_mob)
GrantActions(pilot_mob)//needed for checks, and incase a badmin puts somebody in the mob
/obj/mecha/proc/aimob_exit_mech(mob/living/simple_animal/hostile/syndicate/mecha_pilot/pilot_mob)
if(occupant == pilot_mob)
occupant = null
if(pilot_mob.mecha == src)
pilot_mob.mecha = null
icon_state = "[initial(icon_state)]-open"
pilot_mob.forceMove(get_turf(src))
register_occupant(pilot_mob)
RemoveActions(pilot_mob)
/////////////////////////////////////
//////// Atmospheric stuff ////////
/////////////////////////////////////
/obj/mecha/remove_air(amount)
if(use_internal_tank)
return cabin_air.remove(amount)
return ..()
/obj/mecha/remove_air_ratio(ratio)
if(use_internal_tank)
return cabin_air.remove_ratio(ratio)
return ..()
/obj/mecha/return_air()
if(use_internal_tank)
return cabin_air
return ..()
/obj/mecha/return_analyzable_air()
return cabin_air
/obj/mecha/proc/return_pressure()
var/datum/gas_mixture/t_air = return_air()
if(t_air)
. = t_air.return_pressure()
return
/obj/mecha/return_temperature()
var/datum/gas_mixture/t_air = return_air()
if(t_air)
. = t_air.return_temperature()
return
/obj/mecha/MouseDrop_T(mob/M, mob/user)
if (!user.canUseTopic(src) || (user != M))
return
if(!ishuman(user)) // no silicons or drones in mechas.
return
log_message("[user] tries to move in.", LOG_MECHA)
if (occupant)
to_chat(usr, span_warning("The [name] is already occupied!"))
log_message("Permission denied (Occupied).", LOG_MECHA)
return
if(dna_lock)
var/passed = FALSE
if(user.has_dna())
var/mob/living/carbon/C = user
if(C.dna.unique_enzymes==dna_lock)
passed = TRUE
if (!passed)
to_chat(user, span_warning("Access denied. [name] is secured with a DNA lock."))
log_message("Permission denied (DNA LOCK).", LOG_MECHA)
return
if(!operation_allowed(user))
to_chat(user, span_warning("Access denied. Insufficient operation keycodes."))
log_message("Permission denied (No keycode).", LOG_MECHA)
return
if(user.buckled)
to_chat(user, span_warning("You are currently buckled and cannot move."))
log_message("Permission denied (Buckled).", LOG_MECHA)
return
if(user.has_buckled_mobs()) //mob attached to us
to_chat(user, span_warning("You can't enter the exosuit with other creatures attached to you!"))
log_message("Permission denied (Attached mobs).", LOG_MECHA)
return
visible_message("[user] starts to climb into [name].")
if(do_after(user, enter_delay, src))
if(atom_integrity <= 0)
to_chat(user, span_warning("You cannot get in the [name], it has been destroyed!"))
else if(occupant)
to_chat(user, span_danger("[occupant] was faster! Try better next time, loser."))
else if(user.buckled)
to_chat(user, span_warning("You can't enter the exosuit while buckled."))
else if(user.has_buckled_mobs())
to_chat(user, span_warning("You can't enter the exosuit with other creatures attached to you!"))
else
moved_inside(user)
else
to_chat(user, span_warning("You stop entering the exosuit!"))
return
/obj/mecha/proc/register_occupant(mob/living/new_occupant)
RegisterSignal(new_occupant, COMSIG_MOVABLE_KEYBIND_FACE_DIR, PROC_REF(on_turn), TRUE)
/obj/mecha/proc/unregister_occupant(mob/living/new_occupant)
UnregisterSignal(new_occupant, COMSIG_MOVABLE_KEYBIND_FACE_DIR)
/obj/mecha/proc/on_turn()
SIGNAL_HANDLER