-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZHK_SAV_AI.cs
1825 lines (1614 loc) · 66.1 KB
/
ZHK_SAV_AI.cs
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 ZHK_Debug
using System;
using SaccFlightAndVehicles;
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
using VRC.Udon.Common.Interfaces;
using Random = UnityEngine.Random;
[UdonBehaviourSyncMode(BehaviourSyncMode.Manual)]
public class ZHK_SAV_AI : UdonSharpBehaviour
{
/*
/ Zhakami Modules - SAV AI
/ D: ZhakamiZhako#2147 | TW: @ZZhako | gmail: zhintamizhakami@gmail.com
/ v 0.0003 -
/ For use in development and testing purposes. Not for redistribution outside Sacchill's Jet boys and/or selected persons
/
/ The current state of this shit is only to test how the planes behave during taxi, sound testing, flying as a dummy target, follow waypoints
/ and to validate an aircraft's behaviour on certain things. This is not ready for world distribution quality; but rather this is meant only to
/ validate certain things such as damage handling, sound checking, target checking, taxiing and other things.
/
/ The use of this script is at your own risk.
/
/ Instructions:
/ - Apply a ZHK_SAV_AI to a SaccAirVehicle by adding it as a separate gameobject component. Assign SaccAirVehicle, Waypoints and other behaviours. Stock values
/ are recommended. Assign as an Udon Extension Behaviour.
/ - You are expected to place DFUNC_ToggleEngine as well in the aircraft.
/ - Insert a ZHK_AI_BRAKE object and assign it for both the ZHK_SAV_AI and the SaccEntity's Udon Extension Behaviours. Assign the DFUNC_Brake object of it. This will change on the next update.
/
/ Waypoint guides
Assigning waypoints will have to be done on transforms. You may have multiple attributes on each waypoint. The waypoint attributes shall be named on the gameobject and separated with the semicolon ";".
Apart from this, the AI will ignore other strings and will treat it as a name. Assigning a waypoint without attributes will allow the aircraft to just continue towards the next waypoint without chaging whatever
the last attributes were.
e.g. SP=150;LD;WAYPOINT_BRAVO
- This means that the AI will take a speed in 150 knots, Landing mode. Anything else will be ignored.
/
/ Waypoint assignment
/ Type || Description
/ TK || Take off Cue. Will result to full throttle/Afterburner.
/ LD || Landing cue. Gears down.
/ SP=xx || Speed restriction. Where xx = speed in knots
/ ESC || Escort. Must be placed in the same hierarchy level of a SaccAirVehicle.
/
/ How do i activate the AI?
/ - Tick the 'IsActiveAI' checkbox.
/
/
/ Combat?
/ - Insert a ZHK_AI_TargetList.
/
/ Formation flights?
/ - wip; Insert an empty GameObject with a name ESC; in it.
*/
public Transform[] Waypoints;
// public GameObject[] Targets;
[FieldChangeCallback(nameof(isActiveAI))] [UdonSynced(UdonSyncMode.None)]
public bool _isActiveAI = false;
public bool isActiveAI
{
set
{
_isActiveAI = value;
//reserved
// if (value)
// {
// SAV.ThrottleOverridden = 1;
// SAV.JoystickOverridden = 1;
// }
// else
// {
// SAV.ThrottleOverridden = 0;
// SAV.JoystickOverridden = 0;
// }
}
get => _isActiveAI;
}
public float distanceToChangeWaypoint = 100f; //meters
public float distanceToChangeWaypointTaxi = 50;
public SaccAirVehicle SAV;
private UdonBehaviour SAVU;
public float ThrottleInput;
public float RollInput;
public float PitchInput;
public float YawInput;
public float BrakeInput;
private float prevBrakeInput = 0f;
public bool checkForward = true;
public int checkState = 0; // 0 - bottom, 1 - forward, 2 - left, 3 - right, 4 - up
public bool ExecuteEventsOnStart;
public string[] runEventsOnStart;
public float[] timePerEvent;
public float timerEvent;
public int EventIndex = 0;
private bool ranEventsOnStart = false;
[UdonSynced] public int _currentWaypointIndex = 0;
public int currentWaypointIndex
{
get => _currentWaypointIndex;
set
{
_currentWaypointIndex = value;
UpdateWaypoint();
}
}
public bool returnToAnotherWaypointWhenFinished = false;
public int waypointReturnIndex = -1;
public int LandingWaypointIndex = 0; // Reserved in the future
public float currentSpeed;
public float currentAltitude;
public float TimeLerper = 4;
[Header("Should be auto assigned")] public SaccEntity ENTITY;
public Transform AircraftTransform;
public SAV_EffectsController EFFECTS;
public DFUNC_Brake DFUNC_BRAKE;
public ZHK_AI_Brakes BRAKES;
public DFUNC_Flaps DFUNC_FLAPS;
public DFUNC_Limits DFUNC_LIMITS;
public DFUNC_ToggleEngine DFUNC_ENGINETOGGLE;
public DFUNC_Canopy DFUNC_CANOPY;
public DFUNC_Bomb DFUNC_BOMB;
public DFUNC_Flares DFUNC_FLARES;
public DFUNC_Gear DFUNC_GEAR;
public DFUNC_Cruise DFUNC_CRUISE;
public DFUNC_Hook DFUNC_HOOK;
public DFUNC_Gun DFUNC_GUN;
public DFUNC_AAM DFUNC_AAM;
public DFUNC_Smoke DFUNC_SMOKE;
public ZHK_OpenWorldMovementLogic OpenWorldMovementLogic;
// Reserved for Dialogue System
[Header("Trigger/Dialogue Manager")]
public UdonBehaviour DialogueManager;
public String CallSign;
public UdonBehaviour[] SpecialNumberTrigger;
public UdonBehaviour[] TriggerIncoming;
public UdonBehaviour[] TriggerLowAltitude;
public UdonBehaviour[] TriggerGearDown;
public UdonBehaviour[] TriggerGearUp;
public UdonBehaviour[] TriggerBeingLocked;
public UdonBehaviour[] TriggerTakeOff;
public UdonBehaviour[] TriggerApproach;
public UdonBehaviour[] TriggerTaxiHolding;
public UdonBehaviour[] TriggerTaxiContinue;
public UdonBehaviour[] TriggerTaxi;
public UdonBehaviour[] TriggerAbortLanding;
public UdonBehaviour[] TriggerLanding;
public UdonBehaviour[] TriggerNavigate;
public UdonBehaviour[] TriggerAttacking;
public UdonBehaviour[] TriggerWeaponsRelease;
public UdonBehaviour[] TriggerOutOfAmmo;
public UdonBehaviour[] TriggerGuns;
public UdonBehaviour[] TriggerTakingDamage;
public UdonBehaviour[] TriggerMissileDamage;
public UdonBehaviour[] TriggerEject;
public UdonBehaviour[] TriggerLowFuel;
public UdonBehaviour[] TriggerFox;
public UdonBehaviour[] TriggerClear;
public UdonBehaviour[] TriggerDead;
public UdonBehaviour[] TriggerEngineStarting;
public UdonBehaviour[] TriggerEngineOn;
public UdonBehaviour[] TriggerNumbers;
public UdonBehaviour[] TriggerSmoke;
public UdonBehaviour[] TriggerSmokeOff;
[Header("Misc")]
public float taxiCollisionRadius = 40f;
public float waitTime = 0f;
public float waitTimer = 0f;
public float TaxiWaitTime = 0f;
public float TaxiWaitTimer = 0f;
//new vars
public float MinimumAnglePitch = 100f;
public float MinimumAngleYaw = 100f;
public float MinimumAngleRoll = 800f;
public float YawAngleMax = 25;
public float currentWaypointSpeed = 0f;
public bool returnToOrigin = true;
public float debug_PitchAngle = 0f;
public float debug_YawAngle = 0f;
public float debug_pitchAngleDot;
public float debug_yawAngleDot;
public float debug_deltaAngle;
public Vector3 DebugTargetRoll = Vector3.zero;
public Vector3 DebugRotationAxis = Vector3.zero;
public float DebugDeltaAngle = 0f;
public Vector3 ControlInputs;
public float shouldRollAngle = 0f;
public float maxRollAngle = 90f;
public float rollStrength = 1000f;
public float gunparticleForward = 30f;
public Vector3 originalGunparticleForward = Vector3.zero;
[Header("AI States")] public bool state_engineon = false;
public bool state_canopy = false;
[UdonSynced()] [FieldChangeCallback(nameof(state_combat))]
public bool _state_combat = false;
public bool state_combat
{
get => _state_combat;
set
{
_state_combat = value;
if (value)
{
DialogueExec(TriggerAttacking);
if (DFUNC_AAM)
{
DFUNC_AAM.gameObject.SetActive(true);
}
if (disableLimitsOnCombat)
{
if (DFUNC_LIMITS)
{
DFUNC_LIMITS.gameObject.SetActive(false);
}
}
}
if (!value)
{
foundAAM = false;
air_combat_target_aamTarget = null;
// air_combat_target = null;
if (DFUNC_AAM)
{
DFUNC_AAM.AAMTarget = 0;
}
if (disableLimitsOnCombat)
{
if (DFUNC_LIMITS)
{
DFUNC_LIMITS.gameObject.SetActive(true);
}
}
}
}
}
public bool state_refueling = false;
public bool state_airrefueling = false; //reserved
[FieldChangeCallback(nameof(state_lowfuel))]public bool _state_lowfuel = false; //reserved
public bool state_lowfuel
{
get => _state_lowfuel;
set
{
_state_lowfuel = value;
if (value)
{
DialogueExec(TriggerLowFuel);
}
}
}
[FieldChangeCallback(nameof(state_hold_taxi))]public bool _state_hold_taxi = false;
public bool state_hold_taxi
{
get => _state_hold_taxi;
set
{
_state_hold_taxi = value;
if (value)
{
DialogueExec(TriggerTaxiHolding);
}
}
}
public bool state_smoke = false;
public bool state_flapsUp = false;
[FieldChangeCallback(nameof(state_gearsUp))]public bool _state_gearsUp = false;
public bool state_gearsUp
{
get => _state_gearsUp;
set
{
_state_gearsUp = value;
if (value)
{
DialogueExec(TriggerGearUp);
}
if (!value)
{
DialogueExec(TriggerGearDown);
}
}
}
[FieldChangeCallback(nameof(state_landing))]public bool _state_landing = false;
public bool state_landing
{
get => _state_landing;
set
{
_state_landing = value;
if (value)
{
DialogueExec(TriggerLanding);
}
}
}
[FieldChangeCallback(nameof(state_landing))]public bool _state_takingoff = false;
public bool state_takingoff
{
get => _state_takingoff;
set
{
_state_takingoff = value;
if (value)
{
DialogueExec(TriggerTakeOff);
}
}
}
public bool state_escort;
public bool state_taxiing;
// AI Will deploy flaps when pulling up to add 'emergency' lift.
[FieldChangeCallback(nameof(state_pullingup))] public bool _state_pullingup;
public bool state_pullingup
{
get => _state_pullingup;
set
{
if(_state_pullingup!=value)
{
_state_pullingup = value;
if (value)
{
DialogueExec(TriggerLowAltitude);
if (DFUNC_FLAPS && !DFUNC_FLAPS.Flaps)
{
DFUNC_FLAPS.SetFlapsOn();
}
}
else
{
if (DFUNC_FLAPS && DFUNC_FLAPS.Flaps)
{
DFUNC_FLAPS.SetFlapsOff();
}
}
}
}
}
[FieldChangeCallback(nameof(state_targeted))]public bool _state_targeted = false; //reserved
public bool state_targeted
{
get => _state_targeted;
set
{
if(_state_targeted!=value)
{
_state_targeted = value;
if (value)
{
DialogueExec(TriggerBeingLocked);
}
}
}
}
// AI will launch flares when state_missile is true.
[FieldChangeCallback(nameof(state_missile))]public bool _state_missile = false;
public bool state_missile
{
set
{
_state_missile = value;
if (value)
{
DialogueExec(TriggerIncoming);
directionEvade = Random.Range(0, 4);
}
else
{
directionEvade = -1;
}
}
get => _state_missile;
}
public int directionEvade = -1;
[Tooltip("Startup time before the AI Script activates")][InspectorName("Startup Time")]public float initTime = 10f;
private float initTimer = 0f;
private bool inited = false;
public bool useAsPilot = true;
[HideInInspector]public bool setOnce;
[Header("Taxi Options")] public float taxiClearanceDistance = 20;
public LayerMask TaxiClearanceDetection;
private float taxiCorrectionTime = 2f; //When OWML Kicks in, Planes may be 'afloat' while on the ground.
private float taxiCorrectionTimer = 0f;
[Header("Formation Settings")] public SaccAirVehicle EscortedAircraft;
public float formationThreshold = 1.2f;
public float minFormationThreshold = 0.8f;
public float maxFormationThreshold = 2f;
public float formationThresholdTimeMultiplier = 1f;
[Header("Combat Settings")]
public float distanceToTarget = 0f;
public bool disableLimitsOnCombat = false;
public ZHK_SAV_AI_TargetList targetList;
public float rangeForEngagement = 80000;
public SaccAirVehicle air_combat_target;
public GameObject air_combat_target_aamTarget;
public bool canDogfight = false;
public float engageRadius = 12000;
public LayerMask AAMTargetLayer;
public float SpherecastTime = 5f;
public float SpherecastTimer = 0f;
public float GunRange = 3000f;
public float minGunAngle = 5f;
public float targetAngle = 0f;
public float targetAngleMissile = 0f;
public Transform gunOffset;
public float combatSpeedFar = 800;
public float combatSpeedNear = 400;
public float minMissileRange = 4000f;
public float maxMissileRange = 10000f;
public float missileCooldownTime = 20f;
private float missileCooldownTimer = 0f;
public float MaxAngleMissile = 5f;
private bool foundAAM = false;
private bool initCruiseTaxi = false;
private float CruiseIntegrator;
private float DeltaTime;
private float CruiseIntegratorMin = -5;
private float CruiseIntegratorMax = 5;
private float CruiseProportional = .1f;
private float CruiseIntegral = .1f;
private float TriggerTapTime = 1;
private float FlareTimer = 0f;
public float FlareTime = 1f;
private KeyCode AfterburnerKey = KeyCode.T;
private RaycastHit hit;
private RaycastHit targetChecker;
private RaycastHit terrainCheck;
private float raycastTerrainTime = .4f;
private float raycastTerrainTimer = 0f;
public float minimumPullupDist = 3000f;
public float DISTPULL = 0;
public LayerMask TerrainLayers;
public float Limit = 5f;
private bool breakScan = false;
private int scanIndex = 0;
public RaycastHit[] SpherecastStuff = new RaycastHit[10];
// brake stuff
// public AudioSource Airbrake_snd;
// public Animator BrakeAnimator;
// public Transform GroundBrakeForcePosition;
// public float BrakeInput;
// public bool HasAirBrake;
// public float AirBrakeStrength;
// public float GroundBrakeStrength;
// public float WaterBrakeStrength;
// public bool NoPilotAlwaysGroundBrake;
// public float GroundBrakeSpeed;
//
//
public void SFEXT_O_LowFuel()
{
state_lowfuel = true;
}
public void SFEXT_O_NoFuel()
{
//reserved
}
public void SetActiveAI()
{
isActiveAI = true;
RequestSerialization();
}
public void SetInactiveAI()
{
isActiveAI = false;
RequestSerialization();
}
public void SFEXT_O_RespawnButton()
{
if (SAV.Occupied)
{
SAV.Occupied = false;
SAV.SFEXT_O_RespawnButton();
BrakeInput = 0;
RollInput = 0;
YawInput = 0;
SFEXT_G_ReAppear();
}
}
public void eject()
{
DialogueExec(TriggerEject);
}
public void SFEXT_L_AAMTargeted()
{
DialogueExec(TriggerBeingLocked);
}
public void SFEXT_G_MissileHit25()
{
CallDamageMissile();
}
public void SFEXT_G_MissileHit50()
{
CallDamageMissile();
}
public void SFEXT_G_MissileHit75()
{
CallDamageMissile();
}
public void SFEXT_G_MissileHit100()
{
CallDamageMissile();
}
public void CallDamageMissile()
{
DialogueExec(TriggerMissileDamage);
}
public void SFEXT_L_EntityStart()
{
startAI = isActiveAI;
ENTITY = SAV.EntityControl;
SAVU = SAV.gameObject.GetComponent<UdonBehaviour>();
EFFECTS = (SAV_EffectsController) ENTITY.GetExtention(GetUdonTypeName<SAV_EffectsController>());
DFUNC_BRAKE = (DFUNC_Brake) ENTITY.GetExtention(GetUdonTypeName<DFUNC_Brake>());
BRAKES = (ZHK_AI_Brakes) ENTITY.GetExtention(GetUdonTypeName<ZHK_AI_Brakes>());
DFUNC_FLAPS = (DFUNC_Flaps) ENTITY.GetExtention(GetUdonTypeName<DFUNC_Flaps>());
DFUNC_LIMITS = (DFUNC_Limits) ENTITY.GetExtention(GetUdonTypeName<DFUNC_Limits>());
DFUNC_ENGINETOGGLE = (DFUNC_ToggleEngine) ENTITY.GetExtention(GetUdonTypeName<DFUNC_ToggleEngine>());
DFUNC_CANOPY = (DFUNC_Canopy) ENTITY.GetExtention(GetUdonTypeName<DFUNC_Canopy>());
DFUNC_BOMB = (DFUNC_Bomb) ENTITY.GetExtention(GetUdonTypeName<DFUNC_Bomb>());
DFUNC_FLARES = (DFUNC_Flares) ENTITY.GetExtention(GetUdonTypeName<DFUNC_Flares>());
DFUNC_GEAR = (DFUNC_Gear) ENTITY.GetExtention(GetUdonTypeName<DFUNC_Gear>());
DFUNC_HOOK = (DFUNC_Hook) ENTITY.GetExtention(GetUdonTypeName<DFUNC_Hook>());
DFUNC_GUN = (DFUNC_Gun) ENTITY.GetExtention(GetUdonTypeName<DFUNC_Gun>());
DFUNC_AAM = (DFUNC_AAM) ENTITY.GetExtention(GetUdonTypeName<DFUNC_AAM>());
DFUNC_CRUISE = (DFUNC_Cruise) ENTITY.GetExtention(GetUdonTypeName<DFUNC_Cruise>());
DFUNC_SMOKE = (DFUNC_Smoke) ENTITY.GetExtention(GetUdonTypeName<DFUNC_Smoke>());
if (DFUNC_GUN)
{
originalGunparticleForward = DFUNC_GUN.GunDamageParticle.localPosition;
DFUNC_GUN.GunDamageParticle.position = new Vector3(originalGunparticleForward.x,
originalGunparticleForward.y, originalGunparticleForward.z + gunparticleForward);
}
OpenWorldMovementLogic =
(ZHK_OpenWorldMovementLogic) ENTITY.GetExtention(GetUdonTypeName<ZHK_OpenWorldMovementLogic>());
if (DFUNC_CRUISE)
{
initCruiseTaxi = DFUNC_CRUISE.AllowCruiseGrounded;
}
AfterburnerKey = SAV.AfterBurnerKey;
SAV.AfterBurnerKey = KeyCode.None;
if (BRAKES)
{
if (DFUNC_BRAKE)
{
DFUNC_BRAKE.gameObject.SetActive(false);
DFUNC_BRAKE.enabled = false;
}
}
AircraftTransform = SAV.EntityControl.transform;
gameObject.SetActive(true);
if (OpenWorldMovementLogic != null)
{
OpenWorldMovementLogic.AI = true;
}
}
public void SFEXT_G_Dead()
{
state_engineon = false;
state_canopy = false;
state_combat = false;
state_refueling = false;
state_lowfuel = false;
state_airrefueling = false;
state_gearsUp = false;
state_flapsUp = false;
state_escort = false;
EscortedAircraft = null;
if (DFUNC_GUN) DFUNC_GUN.Firing = false;
currentWaypointIndex = 0;
}
public void ClearCombat()
{
state_combat = false;
if (air_combat_target)
{
air_combat_target.EntityControl.SendEventToExtensions("ZHKEXT_T_RWRClear_net");
}
air_combat_target = null;
currentWaypointSpeed = 0;
ThrottleInput = .75f;
}
public void ZHKEXT_T_RWRWarning_net()
{
state_targeted = true;
}
public void ZHKEXT_T_RWRClear_net()
{
state_targeted = false;
}
public void SFEXT_G_ReAppear()
{
state_engineon = false;
state_canopy = false;
state_combat = false;
state_refueling = false;
state_lowfuel = false;
state_airrefueling = false;
state_gearsUp = false;
state_flapsUp = false;
EscortedAircraft = null;
SAV.Occupied = false;
BrakeInput = 0;
RollInput = 0;
YawInput = 0;
currentWaypointIndex = 0;
inited = false;
initTime = 5f;
initTimer = 0f;
timerEvent = 0;
EventIndex = 0;
ranEventsOnStart = false;
}
public bool startAI = false;
public void Update()
{
if (Networking.IsOwner(gameObject))
{
if (!inited && initTimer < initTime)
{
initTimer = initTimer + Time.deltaTime;
return;
}
if (!inited && initTimer > initTime)
{
if (ExecuteEventsOnStart && !ranEventsOnStart)
{
if (EventIndex < runEventsOnStart.Length)
{
if (timerEvent > timePerEvent[EventIndex])
{
ENTITY.SendEventToExtensions(runEventsOnStart[EventIndex]);
EventIndex = EventIndex + 1;
timerEvent = 0;
}
else
{
timerEvent = timerEvent + Time.deltaTime;
}
}
else
{
ranEventsOnStart = true;
}
}
else
{
inited = true;
isActiveAI = true;
RequestSerialization();
}
}
bool changeWaypoint = false;
currentSpeed = SAV.CurrentVel.magnitude * 1.9438445f;
// currentAltitude = OpenWorldMovementLogic ? OpenWorldMovementLogic.Map.transform.position + : AircraftTransform.position.y * 3.28084f;
//Owner only.
if (isActiveAI)
{
if (!setOnce)
{
// Debug.Log("Overriding Controls...");
if (SAV.JoystickOverridden < 1)
{
#if ZHK_Debug
Debug.Log("Overriding Joystick");
#endif
SAVU.SetProgramVariable("JoystickOverridden",
(int) SAVU.GetProgramVariable("JoystickOverridden") + 1);
// SAV.JoystickOverridden = 1;
}
if (SAV.ThrottleOverridden < 1)
{
Debug.Log("Overriding Throttle");
SAVU.SetProgramVariable("JoystickOverridden",
(int) SAVU.GetProgramVariable("ThrottleOverridden") + 1);
// SAV.ThrottleOverridden = 1;
}
setOnce = true;
SAV.SFEXT_L_KeepAwake();
if (BRAKES)
{
BRAKES.EnableAI = true;
}
if (DFUNC_CRUISE)
{
DFUNC_CRUISE.AllowCruiseGrounded = true;
}
ENTITY.SendEventToExtensions("ZHK_AI_ENABLE");
// if (runEventsOnStart.Length > 0)
// {
// foreach (string s in runEventsOnStart)
// {
// ENTITY.SendEventToExtensions(s);
// }
// }
}
if (!SAV.EngineOn && SAV.Fuel > 0f)
{
if (!state_engineon)
{
EFFECTS.gameObject.GetComponent<UdonBehaviour>().SendCustomNetworkEvent(NetworkEventTarget.All,
nameof(EFFECTS.SFEXT_G_PilotEnter));
state_engineon = true;
BrakeInput = 0;
if (DFUNC_ENGINETOGGLE)
{
if (!ExecuteEventsOnStart)
{
DFUNC_ENGINETOGGLE.KeyboardInput();
DialogueExec(TriggerEngineStarting);
waitTime = DFUNC_ENGINETOGGLE.StartUpTime;
}
else
{
float total = 0;
foreach (float x in timePerEvent)
{
total = total + x;
}
waitTime = total;
}
}
}
if (state_engineon)
{
if (state_taxiing)
{
if (waitTimer < waitTime)
{
EFFECTS.DoEffects = 0f;
if (waitTimer / waitTime > 0 && waitTimer / waitTime < 0.3f)
{
PitchInput = Mathf.Lerp(PitchInput, 1f, Time.deltaTime);
}
if (waitTimer / waitTime > 0.3f && waitTimer / waitTime < 0.4f)
{
PitchInput = Mathf.Lerp(PitchInput, -1f, Time.deltaTime);
}
if (waitTimer / waitTime > 0.4f && waitTimer / waitTime < 0.5f)
{
PitchInput = Mathf.Lerp(PitchInput, 0f, Time.deltaTime);
RollInput = Mathf.Lerp(RollInput, 1f, Time.deltaTime);
}
if (waitTimer / waitTime > 0.5f && waitTimer / waitTime < 0.6f)
{
PitchInput = 0f;
RollInput = Mathf.Lerp(RollInput, -1f, Time.deltaTime);
}
if (waitTimer / waitTime > 0.6f && waitTimer / waitTime < 0.7f)
{
RollInput = Mathf.Lerp(RollInput, 0f, Time.deltaTime);
YawInput = Mathf.Lerp(YawInput, 1f, Time.deltaTime);
}
if (waitTimer / waitTime > 0.7f && waitTimer / waitTime < 0.8f)
{
RollInput = 0f;
YawInput = Mathf.Lerp(YawInput, -1f, Time.deltaTime);
}
if (waitTimer / waitTime > 0.8f && waitTimer / waitTime < 0.9f)
{
YawInput = Mathf.Lerp(YawInput, 0f, Time.deltaTime);
}
if (waitTimer / waitTime > 0.9f)
{
// Sequence done, setting controls to 0, wait timer to 0;
YawInput = 0f;
waitTime = 0f;
waitTimer = 0f;
}
}
// add Controls check sequence here
}
}
}
if (SAV.EngineOn)
{
if (!state_canopy)
{
state_canopy = true;
if (DFUNC_CANOPY)
{
DFUNC_CANOPY.KeyboardInput();
}
if (DFUNC_AAM)
{
DFUNC_AAM.gameObject.SetActive(true);
}
if (DFUNC_FLARES)
{
DFUNC_FLARES.gameObject.SetActive(true);
}
SAV.Occupied = true;
SAV.Asleep = false;
SAVU.SetProgramVariable("DisablePhysicsAndInputs", 0);
SAV.SFEXT_L_KeepAwake();
if (useAsPilot) SAV.SFEXT_O_PilotEnter();
SAV.EntityControl.SendEventToExtensions("SFEXT_G_PilotEnter");
UpdateWaypoint();
SAV.SetCollidersLayer(SAV.OutsideVehicleLayer); // set them back to solid ffs.
// SAV.Piloting = false;
// SAV.DisablePhysicsAndInputs = 0;
}
}
// State Checker
if (SAV.Taxiing)
{
state_taxiing = true;
}
else
{
if (state_taxiing && taxiCorrectionTimer < taxiCorrectionTime)
{
taxiCorrectionTimer = taxiCorrectionTimer + Time.deltaTime;
}
else
{
state_taxiing = false;
taxiCorrectionTimer = 0f;
}
}
if (!state_taxiing)
{
if (SAV.MissilesIncomingHeat > 0 || SAV.MissilesIncomingOther > 0 || SAV.MissilesIncomingRadar > 0)
{
if(!state_missile)
state_missile = true;
}
else
{
if (state_missile)
{
state_missile = false;
}
}
if (state_missile)
{
Debug.Log("AI SHOULD BE FLARING");
if (DFUNC_FLARES)
{
if (FlareTimer > FlareTime)
{
DFUNC_FLARES.KeyboardInput();
FlareTimer = 0f;
}
else
{
FlareTimer = FlareTimer + Time.deltaTime;
}
}
}
if (Vector3.Distance(AircraftTransform.position, Waypoints[currentWaypointIndex].position) <
distanceToChangeWaypoint)
{
if (!state_escort)
{
changeWaypoint = true;
}
else
{
if (currentWaypointIndex + 1 < Waypoints.Length)
{
if (Vector3.Distance(AircraftTransform.position,
Waypoints[currentWaypointIndex + 1].position) <
distanceToChangeWaypoint)
{
currentWaypointIndex = currentWaypointIndex + 1;
changeWaypoint = true;
}
}
//else, do nothing.
}
}
if (!state_combat)