-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaircraft.cpp
More file actions
4256 lines (3763 loc) · 164 KB
/
Copy pathaircraft.cpp
File metadata and controls
4256 lines (3763 loc) · 164 KB
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
/*******************************************************************************
* O P E N T S
*******************************************************************************
* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright 2025 Electronic Arts Inc.
* Copyright 2026 OpenTS contributors
*
* Contains material derived from Electronic Arts source code.
* Modified by OpenTS contributors, 2026.
* EA's GPLv3 Section 7 additional terms and supplemental warranty
* disclaimers apply; see LICENSE.md.
******************************************************************************/
/* $Header: /CounterStrike/AIRCRAFT.CPP 1 3/03/97 10:24a Joe_bostic $ */
/***********************************************************************************************
*** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
***********************************************************************************************
* *
* Project Name : Command & Conquer *
* *
* File Name : AIRCRAFT.CPP *
* *
* Programmer : Joe L. Bostic *
* *
* Start Date : July 22, 1994 *
* *
* Last Update : November 2, 1996 [JLB] *
* *
*---------------------------------------------------------------------------------------------*
* Functions: *
* AircraftClass::AI -- Processes the normal non-graphic AI for the aircraft. *
* AircraftClass::Active_Click_With -- Handles clicking over specified cell. *
* AircraftClass::Active_Click_With -- Handles clicking over specified object. *
* AircraftClass::AircraftClass -- The constructor for aircraft objects. *
* AircraftClass::Can_Enter_Cell -- Determines if the aircraft can land at this location. *
* AircraftClass::Can_Fire -- Checks to see if the aircraft can fire. *
* AircraftClass::Cell_Seems_Ok -- Checks to see if a cell is good to enter. *
* AircraftClass::Desired_Load_Dir -- Determines where passengers should line up. *
* AircraftClass::Draw_It -- Renders an aircraft object at the location specified. *
* AircraftClass::Draw_Rotors -- Draw rotor blades on the aircraft. *
* AircraftClass::Edge_Of_World_AI -- Detect if aircraft has exited the map. *
* AircraftClass::Enter_Idle_Mode -- Gives the aircraft an appropriate mission. *
* AircraftClass::Exit_Object -- Unloads passenger from aircraft. *
* AircraftClass::Fire_At -- Handles firing a projectile from an aircraft. *
* AircraftClass::Fire_Direction -- Determines the direction of fire. *
* AircraftClass::Good_Fire_Location -- Searches for and finds a good spot to fire from. *
* AircraftClass::Good_LZ -- Locates a good spot ot land. *
* AircraftClass::In_Which_Layer -- Calculates the display layer of the aircraft. *
* AircraftClass::Init -- Initialize the aircraft system to an empty state. *
* AircraftClass::Is_LZ_Clear -- Determines if landing zone is free for landing. *
* AircraftClass::Landing_Takeoff_AI -- Handle aircraft take off and landing processing. *
* AircraftClass::Look -- Aircraft will look if they are on the ground always. *
* AircraftClass::Mission_Attack -- Handles the attack mission for aircraft. *
* AircraftClass::Mission_Enter -- Control aircraft to fly to the helipad or repair center. *
* AircraftClass::Mission_Guard -- Handles aircraft in guard mode. *
* AircraftClass::Mission_Guard_Area -- Handles the aircraft guard area logic. *
* AircraftClass::Mission_Hunt -- Maintains hunt AI for the aircraft. *
* AircraftClass::Mission_Move -- Handles movement mission. *
* AircraftClass::Mission_Retreat -- Handles the aircraft logic for leaving the battlefield. *
* AircraftClass::Mission_Unload -- Handles unloading cargo. *
* AircraftClass::Movement_AI -- Handles aircraft physical movement logic. *
* AircraftClass::New_LZ -- Find a good landing zone. *
* AircraftClass::Overlap_List -- Returns with list of cells the aircraft overlaps. *
* AircraftClass::Paradrop_Cargo -- Drop a passenger by parachute. *
* AircraftClass::Per_Cell_Process -- Handle the aircraft per cell process. *
* AircraftClass::Pip_Count -- Returns the number of "objects" in aircraft. *
* AircraftClass::Player_Assign_Mission -- Handles player input to assign a mission. *
* AircraftClass::Pose_Dir -- Fetches the natural landing facing. *
* AircraftClass::Process_Fly_To -- Handles state machine for flying to destination. *
* AircraftClass::Process_Landing -- Landing process state machine handler. *
* AircraftClass::Process_Take_Off -- State machine support for taking off. *
* AircraftClass::Read_INI -- Reads aircraft object data from an INI file. *
* AircraftClass::Receive_Message -- Handles receipt of radio messages. *
* AircraftClass::Response_Attack -- Gives audio response to attack order. *
* AircraftClass::Response_Move -- Gives audio response to move request. *
* AircraftClass::Response_Select -- Gives audio response when selected. *
* AircraftClass::Rotation_AI -- Handle aircraft body and flight rotation. *
* AircraftClass::Scatter -- Causes the aircraft to move away a bit. *
* AircraftClass::Set_Speed -- Sets the speed for the aircraft. *
* AircraftClass::Shape_Number -- Fetch the shape number to use for the aircraft. *
* AircraftClass::Sort_Y -- Figures the sorting coordinate. *
* AircraftClass::Take_Damage -- Applies damage to the aircraft. *
* AircraftClass::Unlimbo -- Removes an aircraft from the limbo state. *
* AircraftClass::What_Action -- Determines what action to perform. *
* AircraftClass::What_Action -- Determines what action to perform. *
* AircraftClass::operator delete -- Deletes the aircraft object. *
* AircraftClass::operator new -- Allocates a new aircraft object from the pool *
* AircraftClass::~AircraftClass -- Destructor for aircraft object. *
* _Counts_As_Civ_Evac -- Is the specified object a candidate for civilian evac logic? *
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#define INCLUDE_COM
#include "always.h"
#include "aircraft.h"
#include "_map.h"
#include "_rtti.h"
#include "_rules.h"
#include "_tactica.h"
#include "airctype.h"
#include "anim.h"
#include "animtype.h"
#include "building.h"
#include "builtype.h"
#include "bullet.h"
#include "bullettype.h"
#include "ccrand.h"
#include "cell.h"
#include "dbgprint.h"
#include "findmake.h"
#include "house.h"
#include "houstype.h"
#include "incdec.h"
#include "infantry.h"
#include "infatype.h"
#include "inline.h"
#include "ion.h"
#include "map.h"
#include "mono.h"
#include "partsys.h"
#include "queue.h"
#include "rules.h"
#include "scenario.h"
#include "session.h"
#include "stimer.h"
#include "sun.h"
#include "swizzle.h"
#include "tactical.h"
#include "tag.h"
#include "tagtype.h"
#include "team.h"
#include "tracker.h"
#include "unit.h"
#include "waypoint.h"
#include "weapon.h"
char const * const AircraftClass::INI_NAME = "Aircraft";
/***********************************************************************************************
* _Counts_As_Civ_Evac -- Is the specified object a candidate for civilian evac logic? *
* *
* Examines the specified object to see if it qualifies to be a civilian evacuation. This *
* can only occur if it is a civilian (or Tanya) and the special evacuation flag has been *
* set in the scenario control structure. *
* *
* INPUT: candidate -- Candidate object to examine for civilian evacuation legality. *
* *
* OUTPUT: bool; Is the specified object considered a civilian that must be auto-evacuated? *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 06/24/1996 JLB : Created. *
*=============================================================================================*/
bool Counts_As_Civ_Evac(ObjectClass const * candidate)
{
/*
** If the candidate pointer is missing, then return with failure code.
*/
if (candidate == NULL) return(false);
/*
** Only infantry objects can be considered for civilian evacuation action.
*/
InfantryClass const * inf = (candidate->RTTI == RTTI_INFANTRY) ? (InfantryClass const *)candidate : NULL;
if (inf == NULL) return(false);
/*
** If the infantry is not a civilian, then it isn't allowed to be a civilian evacuation.
*/
if (!inf->Class->IsCivilian) return(false);
/*
** Technicians look like civilians, but are not considered a legal evacuation candidate.
*/
if (inf->IsTechnician) return(false);
/*
** All tests pass, so return the success of the infantry as a civilian evacuation candidate.
*/
return(true);
}
/***********************************************************************************************
* AircraftClass::AircraftClass -- The constructor for aircraft objects. *
* *
* This routine is the constructor for aircraft objects. An aircraft object can be *
* created and possibly placed into the game system by this routine. *
* *
* INPUT: classid -- The type of aircraft to create. *
* *
* house -- The owner of this aircraft. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 07/26/1994 JLB : Created. *
*=============================================================================================*/
AircraftClass::AircraftClass(AircraftTypeClass const * type, HouseClass * house) :
BASECLASS(house),
IsToSpendAmmo(false),
Class((AircraftTypeClass *)type),
Passenger(false),
IsKamikaze(false),
field_35B(false),
IsLockedStraight(false),
SightTimer(0),
AttacksRemaining(1),
IsReadyToCommence(true)
{
Create_ID();
if (Class != NULL) {
Locomotion.CreateInstance(Class->Locomotor);
Locomotion->Link_To_Object(this);
}
Init();
Aircraft.Add(this);
TargetTracker.Add_Index(Fetch_ID(), this);
}
/***********************************************************************************************
* AircraftClass::Init -- Initialize the aircraft system to an empty state. *
* *
* This routine is used to clear out the aircraft allocation system. It is called in *
* preparation for a scenario load or save game load. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 09/24/1994 JLB : Created. *
*=============================================================================================*/
void AircraftClass::Init(void)
{
BASECLASS::Init();
if (Class != NULL) {
PrimaryFacing.Set_ROT(Class->ROT);
SecondaryFacing.Set_ROT(Class->ROT);
SecondaryFacing.Set(PrimaryFacing.Current());
HeightAGL = Class->Flight_Level();
Ammo = Class->MaxAmmo;
Strength = Class->MaxStrength;
}
if (House != NULL) {
House->Tracking_Add(this);
}
}
/// <summary>
/// Fetches the requested interface from this aircraft.
/// Aircraft add the fly control interface to the set that every game object supports, so
/// that the flying locomotor can interrogate them about how they wish to be flown.
/// </summary>
/// <param name="guid">The identifier of the interface being asked for.</param>
/// <param name="ppv">Pointer to the pointer to fill in with the interface.</param>
/// <returns>Returns with S_OK if the interface was supplied.</returns>
HRESULT STDMETHODCALLTYPE AircraftClass::QueryInterface(struct _GUID const &guid, void **ppv)
{
HRESULT res = BASECLASS::QueryInterface(guid, ppv);
if (FAILED(res)) {
if (guid == IID_IFlyControl) {
*ppv = (IFlyControl *)(this);
}
res = S_OK;
AddRef();
}
return(res);
}
/// <summary>
/// Adds a reference to this aircraft.
/// </summary>
/// <returns>Returns with the new number of references outstanding.</returns>
ULONG STDMETHODCALLTYPE AircraftClass::AddRef(void)
{
return(BASECLASS::AddRef());
}
/// <summary>
/// Releases a reference to this aircraft.
/// </summary>
/// <returns>Returns with the number of references still outstanding.</returns>
ULONG STDMETHODCALLTYPE AircraftClass::Release(void)
{
return(BASECLASS::Release());
}
/***********************************************************************************************
* AircraftClass::Unlimbo -- Removes an aircraft from the limbo state. *
* *
* This routine is used to transition the aircraft from the limbo to the non limbo state. *
* It occurs when the aircraft is placed on the map for whatever reason. When it is *
* unlimboed, only then will normal game processing recognize it. *
* *
* INPUT: coord -- The coordinate that the aircraft should appear at. *
* *
* dir -- The direction it should start facing. *
* *
* strength (optional) -- sets initial strength *
* *
* mission (optional) -- sets initial mission *
* *
* OUTPUT: bool; Was the aircraft unlimboed successfully? *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 07/26/1994 JLB : Created. *
*=============================================================================================*/
bool AircraftClass::Unlimbo(Coord const & coord, Dir256 dir)
{
Coord ucoord = coord;
if (IsALoaner || !Map.In_Local_Radar(coord)) {
ucoord.Z = Class->Flight_Level() + Map.Get_Height_GL(coord);
} else {
ucoord.Z = Map.Get_Height_GL(coord);
}
if (BASECLASS::Unlimbo(ucoord, dir)) {
if (!Class->IsSelectable || !Class->IsLandable || (PrimaryWeapon != NULL && PrimaryWeapon->IsCamera)) {
IsALoaner = true;
}
/*
** Hack it so that aircraft that are both passenger and cargo carrying
** will carry passengers at the expense of ammo.
*/
if (Cargo.Is_Something_Attached()) {
Ammo = 0;
Passenger = true;
}
/*
** Forces the body of the helicopter to face the correct direction.
*/
SecondaryFacing.Set(dir);
/*
** Start rotor animation.
*/
Set_Rate(1);
Set_Stage(0);
/*
** When starting at flight level, then give it speed. When landed
** then it must be stationary.
*/
if (HeightAGL == Class->Flight_Level()) {
Set_Speed(1);
} else {
Set_Speed(0);
}
return(true);
}
return(false);
}
/***********************************************************************************************
* AircraftClass::Draw_It -- Renders an aircraft object at the location specified. *
* *
* This routine is used to display the aircraft object at the coordinates specified. *
* The tactical map display uses this routine for all aircraft rendering. *
* *
* INPUT: x,y -- The coordinates to render the aircraft at. *
* *
* window -- The window that the coordinates are based upon. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 07/26/1994 JLB : Created. *
*=============================================================================================*/
void AircraftClass::Draw_It(Point2D const & xpoint, Rect const & cliprect) const
{
if (!Debug_Map && MainWindow && Scen->Special.IsFogOfWar) {
Coord headto = (Coord)Locomotion->Head_To_Coord();
headto.Z = PositionCoord.Z;
if (Map.Is_Fogged(headto) && Map.Is_Fogged(PositionCoord) && !House->Is_Player_Control()) {
return;
}
}
Point2D point = xpoint;
point += Locomotion->Draw_Point();
if (Cargo.Is_Something_Attached() && Class->IsCarryall) {
Cargo.Attached_Object()->Draw_It(point, cliprect);
}
if (Class->IsVoxel && Class->Voxel.VoxLib != NULL) {
Coord coord = PositionCoord;
coord.Z = Map.Get_Height_GL(coord);
Point2D shadow;
TacticalMap->Coord_To_Pixel(coord, shadow);
shadow += Locomotion->Shadow_Point();
int key = 0;
int height = HeightAGL;
bool occupies_cell = Occupies_Cells();
((AircraftClass &)*this).IsOccupyingCell = false;
CellClass * cellptr = &Map[Get_Coord()];
bool draw_on_ground = false;
if ((IsOnBridge || height < BRIDGE_LEPTON_HEIGHT) && (!IsOnBridge || height < 0)) {
draw_on_ground = true;
} else {
if (cellptr->IsUnderBridge &&
(cellptr->IsBridgeEastWest && cellptr->Adjacent_Cell(FACING_N).IsUnderBridge ||
!cellptr->IsBridgeEastWest && cellptr->Adjacent_Cell(FACING_W).IsUnderBridge)) {
((AircraftClass &)*this).HeightAGL = BRIDGE_LEPTON_HEIGHT;
shadow.Y -= TacticalMap->Z_Lepton_To_Pixel(BRIDGE_LEPTON_HEIGHT);
} else {
draw_on_ground = true;
}
}
if (draw_on_ground) {
((AircraftClass &)*this).HeightAGL = 0;
}
/*
** Special manual shadow draw code.
*/
Matrix3D matrix;
matrix = Locomotion->Shadow_Matrix(&key);
Draw_Voxel_Shadow(Class->Voxel, 0, key, &Class->ShadowVoxelIndex, cliprect, shadow, Get_Isometric_View_Matrix() * matrix, true);
((AircraftClass &)*this).HeightAGL = height;
((AircraftClass &)*this).IsOccupyingCell = occupies_cell;
TacticalMap->Add_To_Selectables((AircraftClass *)this, point);
int brightness;
if (IonStormClass::Is_Ion_Storm_Active()) {
brightness = Scen->IonLevelLight;
} else {
brightness = Scen->LevelLight;
}
brightness *= (HeightAGL / (2 * LEVEL_LEPTON_H));
int newbrightness = brightness + Map[coord].Brightness + Rule->ExtraAircraftLight;
/*
** Actually draw the root body of the unit.
*/
key = -1;
matrix = Locomotion->Draw_Matrix(&key);
Draw_Voxel(Class->Voxel, 0, key, &Class->VoxelIndex, cliprect, point, Get_Isometric_View_Matrix() * matrix, newbrightness, SHAPE_NORMAL);
}
/*
** This draws any overlay graphics on the aircraft.
*/
BASECLASS::Draw_It(xpoint, cliprect);
}
/***********************************************************************************************
* AircraftClass::Draw_Rotors -- Draw rotor blades on the aircraft. *
* *
* This routine will draw rotor blades on the aircraft. It is presumed that the aircraft *
* has already been drawn at the X and Y pixel coordinates specified. *
* *
* INPUT: x,y -- The X and Y pixel coordinates to draw the rotor blades. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 07/26/1996 JLB : Created. *
*=============================================================================================*/
void AircraftClass::Draw_Rotors(Point2D const & xy, Rect const & cliprect) const
{
ShapeFlags_Type flags = ShapeFlags_Type(SHAPE_CENTER|SHAPE_WIN_REL);
int shapenum;
/*
** The rotor shape number depends on whether the helicopter is idling
** or not. A landed helicopter uses slow moving "idling" blades.
*/
if (HeightAGL == 0) {
shapenum = (Fetch_Stage()%8)+4;
flags = flags;
} else {
shapenum = Fetch_Stage()%4;
flags = ShapeFlags_Type(flags|SHAPE_PREDATOR);
}
#if 0
if (*this == AIRCRAFT_TRANSPORT) {
int _stretch[FACING_COUNT] = {8, 9, 10, 9, 8, 9, 10, 9};
/*
** Dual rotors offset along flight axis.
*/
short xx = x;
short yy = y-LEPTON_TO_PIXEL(Height);
FacingType face = Dir_Facing(SecondaryFacing);
Move_Point(xx, yy, SecondaryFacing.Current(), _stretch[face]);
Draw_Shape(AircraftTypeClass::RRotorData, shapenum, xx, yy-2, window, flags, NULL, DisplayClass::UnitShadow);
Move_Point(xx, yy, SecondaryFacing.Current()+DIR_S, _stretch[face]*2);
Draw_Shape(AircraftTypeClass::LRotorData, shapenum, xx, yy-2, window, flags, NULL, DisplayClass::UnitShadow);
} else {
/*
** Single rotor centered about shape.
*/
Draw_Shape(AircraftTypeClass::RRotorData, shapenum, x, ((y-LEPTON_TO_PIXEL(Height))-2), window, flags, NULL, DisplayClass::UnitShadow);
}
#endif
}
/***********************************************************************************************
* AircraftClass::Mission_Hunt -- Maintains hunt AI for the aircraft. *
* *
* Hunt AI consists of finding a target and attacking it. If there is no target assigned *
* and this unit doesn't automatically hunt for more targets, then it will change *
* mission to a more passive (land and await further orders) type. *
* *
* INPUT: none *
* *
* OUTPUT: Returns with the number of ticks before calling this routine again. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 07/26/1994 JLB : Created. *
*=============================================================================================*/
int AircraftClass::Do_MISSION_HUNT(void)
{
if (!Ammo) {
if (Team) Team->Remove(this);
Enter_Idle_Mode();
} else {
if (TarCom == NULL) {
if (Session.Type != GAME_NORMAL) {
Assign_Target(Greatest_Threat(THREAT_TIBERIUM, PositionCoord, false));
}
if (TarCom == NULL) {
Assign_Target(Greatest_Threat(THREAT_NORMAL, PositionCoord, false));
}
if (TarCom == NULL) {
Enter_Idle_Mode();
return(1);
}
}
Assign_Mission(MISSION_ATTACK);
return(1);
}
return(Current_Mission_Control().Normal_Delay() + Random_Pick(0, 2));
}
/***********************************************************************************************
* AircraftClass::AI -- Processes the normal non-graphic AI for the aircraft. *
* *
* This handles the non-graphic AI processing for the aircraft. This usually entails *
* maintenance and other AI functions. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 07/26/1994 JLB : Created. *
*=============================================================================================*/
void AircraftClass::AI(void)
{
if (Mission == MISSION_SLEEP && HeightAGL > 0) {
Assign_Mission(MISSION_GUARD);
}
if (CurrentMission != MISSION_ATTACK) {
IsLockedStraight = false;
}
if (TarCom != NULL) {
if (TarCom->In_Air()) {
Assign_Target(NULL);
} else if (TarCom->Is_Techno() && !House->Is_Ally(TarCom) && ((TechnoClass*)TarCom)->Cloak == CLOAKED && !((TechnoClass*)TarCom)->Is_Sensed_By_House(House)) {
Assign_Target(NULL);
}
}
/*
** Perform any base class AI processing. If during this process, the aircraft was
** destroyed, then detect this and bail from this AI routine early.
*/
BASECLASS::AI();
if (!IsActive) {
return;
}
if (!Map.In_Local_Radar(PositionCell) && Should_Delete_Off_Map()) {
Delete_Me();
return;
}
if (NavCom == &BlubCell) {
Assign_Destination(NULL);
Assign_Target(NULL);
Enter_Idle_Mode();
}
if (TarCom == &BlubCell) {
Assign_Destination(NULL);
Assign_Target(NULL);
Enter_Idle_Mode();
}
if (Ready_To_Commence()) {
Commence();
}
if (IsToSpendAmmo) {
if (CurrentMission != MISSION_ATTACK) {
IsToSpendAmmo = false;
Ammo--;
}
}
if (House->Is_Ally(PlayerPtr) && SightTimer == 0) {
Look();
SightTimer = TICKS_PER_SECOND;
}
if (HealthRatio < Rule->ConditionRed && HeightAGL > 0) {
if (Percent_Chance(Strength != 0 ? 10 : 80)) {
new AnimClass(AnimTypes[AnimTypeClass::From_Name("SGRYSMK1")], PositionCoord);
}
}
if (Cargo.Is_Something_Attached() && Class->IsCarryall) {
Cargo.Attached_Object()->PrimaryFacing = SecondaryFacing;
Cargo.Attached_Object()->SecondaryFacing = SecondaryFacing;
Cargo.Attached_Object()->PositionCoord = PositionCoord;
}
}
/***********************************************************************************************
* AircraftClass::Mission_Unload -- Handles unloading cargo. *
* *
* This function is used to handle finding, heading toward, landing, and unloading the *
* cargo from the aircraft. Once unloading of cargo has occurred, then the aircraft follows *
* a different mission. *
* *
* INPUT: none *
* *
* OUTPUT: Returns the number of game ticks to delay before calling this function again. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 10/31/94 JLB : Created. *
*=============================================================================================*/
int AircraftClass::Do_MISSION_UNLOAD(void)
{
enum {
SEARCH_FOR_LZ,
FLY_TO_LZ,
LAND_ON_LZ,
UNLOAD_PASSENGERS,
TAKE_OFF
};
switch (Status) {
/*
** Search for an appropriate destination spot if one isn't already assigned.
*/
case SEARCH_FOR_LZ:
if (HeightAGL == 0 && (double)PitchAngle == 0 && (NavCom == NULL || (PositionCoord == NavCom->Center_Coord()))) {
Status = UNLOAD_PASSENGERS;
} else {
if (NavCom == NULL && Class->IsDropship && HeightAGL > 0) {
BuildingClass * building = NULL;
for (int index = 0; index < Class->Dock.Count(); index++) {
building = Find_Docking_Bay(Class->Dock[index], false);
if (building != NULL) {
break;
}
}
if (building != NULL) {
Assign_Destination(building);
break;
} else {
Assign_Destination(Good_LZ());
break;
}
} else if (NavCom == NULL) {
Status = LAND_ON_LZ;
} else if (Is_LZ_Clear(NavCom)) {
if (Class->IsDropship) {
Cell cell = CELL_NONE;
if (NavCom->RTTI != RTTI_CELL) {
cell = Dynamic_Cast<TechnoClass *>(NavCom)->PositionCoord.As_Cell();
}
if (cell != CELL_NONE) {
ObjectClass * occupier = Map[cell].Cell_Occupier();
while (occupier != NULL) {
if (occupier->RTTI != RTTI_BUILDING) {
occupier->Scatter(PositionCoord, true, true);
occupier = occupier->Next;
} else {
Assign_Destination(Good_LZ());
}
}
}
} else {
FootClass * foot = Cargo.Attached_Object();
if (foot != NULL && foot->Team && foot->Team->Class->Get_Origin() != CELL_NONE) {
Assign_Destination(New_LZ(&Map[foot->Team->Class->Get_Origin()]));
} else {
Assign_Destination(New_LZ(&Map[Scen->Get_Waypoint_Cell(WAYPT_REINF)]));
if (Team != NULL) {
Team->Assign_Mission_Target(NavCom);
}
}
}
} else {
if (HeightAGL != Class->Flight_Level()) {
Status = TAKE_OFF;
} else {
Status = FLY_TO_LZ;
}
}
}
break;
/*
** Fly to destination.
*/
case FLY_TO_LZ:
if (!Locomotion->Is_Moving()) {
Status = LAND_ON_LZ;
}
if (!Is_LZ_Clear(NavCom)){
Status = SEARCH_FOR_LZ;
}
break;
/*
** Landing phase. Just delay until landing is complete. At that time,
** transition to the unloading phase.
*/
case LAND_ON_LZ:
if (!Locomotion->Is_Moving()) {
Status = UNLOAD_PASSENGERS;
}
return(1);
/*
** Hold while unloading passengers. When passengers are unloaded the order for this
** transport gets changed to MISSION_RETREAT.
*/
case UNLOAD_PASSENGERS:
if (!IsTethered) {
if (Cargo.Is_Something_Attached()) {
if (Class->IsCarryall) {
Mark(MARK_UP);
Drop_Off_Cargo();
Mark(MARK_DOWN);
} else {
FootClass * unit = (FootClass *)Cargo.Detach_Object();
/*
** First thing is to lift the transport off of the map so that the unlimbo
** process for the passengers is more likely to succeed.
*/
Map.Pick_Up(PositionCell, this);
if (Exit_Object(unit)) {
unit->IsInTransport = false;
}
/*
** Restore the transport back down on the map.
*/
Map.Place_Down(PositionCell, this);
if (!unit->IsInTransport) {
if (unit->Team != NULL) {
Team->Add(unit);
}
}
if (!Cargo.Is_Something_Attached()) {
Enter_Idle_Mode();
}
}
} else {
Enter_Idle_Mode();
}
}
break;
/*
** Aircraft is now taking off. Once the aircraft reaches flying altitude then it
** will either take off or look for another landing spot to try again.
*/
case TAKE_OFF:
Status = SEARCH_FOR_LZ;
return(1);
default:
break;
}
return(Current_Mission_Control().Normal_Delay() + Random_Pick(0, 2));
}
/***********************************************************************************************
* AircraftClass::Mission_Retreat -- Handles the aircraft logic for leaving the battlefield. *
* *
* This mission will be followed when the aircraft decides that it is time to leave the *
* battle. Typically, this occurs when a loaner transport has dropped off its load or when *
* an attack air vehicle has expended its ordinance. *
* *
* INPUT: none *
* *
* OUTPUT: Returns with the number of game ticks to delay before calling this routine again. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 03/19/1995 JLB : Created. *
* 08/13/1995 JLB : Handles aircraft altitude gain after takeoff logic. *
*=============================================================================================*/
int AircraftClass::Do_MISSION_RETREAT(void)
{
return(0);
#if NEVER
//assert(IsActive);
if (Class->IsFixedWing) {
if (Class->IsFixedWing && Height < FLIGHT_LEVEL) {
Height += 1;
return(3);
}
return(TICKS_PER_SECOND*10);
}
enum {
TAKE_OFF,
FACE_MAP_EDGE,
KEEP_FLYING
};
switch (Status) {
/*
** Take off if landed.
*/
case TAKE_OFF:
if (Process_Take_Off()) {
Status = FACE_MAP_EDGE;
}
return(1);
/*
** Set facing and speed toward the friendly map edge.
*/
case FACE_MAP_EDGE:
Set_Speed(MPH_LIGHT_SPEED);
/*
** Take advantage of the fact that the source map edge enumerations happen to
** occur in a clockwise order and are the first four enumerations of the map
** edge default for the house. If this value is masked and then shifted, a
** normalized direction value results. Use this value to head the aircraft
** toward the "friendly" map edge.
*/
PrimaryFacing.Set_Desired((Dir256)((House->Control.Edge & 0x03) << 6));
SecondaryFacing.Set_Desired(PrimaryFacing.Desired());
Status = KEEP_FLYING;
break;
/*
** Just do nothing since we are headed toward the map edge. When the edge is
** reached, the aircraft should be automatically eliminated.
*/
case KEEP_FLYING:
break;
default:
break;
}
return(MissionControl[Mission].Normal_Delay() + Random_Pick(0, 2));
#endif
}
/***********************************************************************************************
* AircraftClass::Exit_Object -- Unloads passenger from aircraft. *
* *
* This routine is called when the aircraft is to unload a passenger. The passenger must *
* be able to move under its own power. Typical situation is when a transport helicopter *
* is to unload an infantry unit. *
* *
* INPUT: unit -- Pointer to the unit that is to be unloaded from this aircraft. *
* *
* OUTPUT: bool; Was the unit unloaded successfully? *
* *
* WARNINGS: The unload process is merely started by this routine. Radio contact is *
* established with the unloading unit and when the unit is clear of the aircraft *
* the radio contact will be broken and then the aircraft is free to pursue *
* other. *
* *
* HISTORY: *
* 01/10/1995 JLB : Created. *
*=============================================================================================*/
int AircraftClass::Exit_Object(TechnoClass * unit)
{
static FacingType _toface[FACING_COUNT] = {FACING_S, FACING_SW, FACING_SE, FACING_NW, FACING_NE, FACING_N, FACING_W, FACING_E};
Cell cell(0,0);
/*
** Find a free cell to drop the unit off at.
*/
FacingType face;
for (face = FACING_N; face < FACING_COUNT; face++) {
cell = Adjacent_Cell(PositionCell, _toface[face]);
if (unit->Can_Enter_Cell(&Map[cell]) == MOVE_OK) break;
}
// Should perform a check here to see if no cell could be found.
/*
** If the passenger can be placed on the map, then start it moving toward the
** destination cell and establish radio contact with the transport. This is used
** to make sure that the transport waits until the passenger is clear before
** unloading the next passenger or taking off.
*/
if (unit->Unlimbo(PositionCoord, Facing_Dir(_toface[face]))) {
unit->Assign_Mission(MISSION_MOVE);
unit->Assign_Destination(&Map[cell]);
if (Transmit_Message(RADIO_HELLO, unit) == RADIO_ROGER) {
Transmit_Message(RADIO_UNLOAD);
}
return(true);
}
return(false);
}
/***********************************************************************************************
* AircraftClass::Paradrop_Cargo -- Drop a passenger by parachute. *
* *
* Call this routine when a passenger needs to be dropped off by parachute. One passenger *
* is offloaded by a call to this routine. *
* *
* INPUT: none *
* *
* OUTPUT: Returns with the delay time that it is safe to wait before processing any further *
* paradrop actions. *