/
npc_combinedropship.cpp
3007 lines (2525 loc) · 92.3 KB
/
npc_combinedropship.cpp
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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Large vehicle what delivers combine troops.
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "ai_default.h"
#include "ai_basenpc.h"
#include "soundenvelope.h"
#include "cbasehelicopter.h"
#include "ai_schedule.h"
#include "engine/IEngineSound.h"
#include "smoke_trail.h"
#include "IEffects.h"
#include "props.h"
#include "TemplateEntities.h"
#include "baseanimating.h"
#include "ai_senses.h"
#include "entitylist.h"
#include "ammodef.h"
#include "ndebugoverlay.h"
#include "npc_combines.h"
#include "soundent.h"
#include "mapentities.h"
#include "npc_rollermine.h"
#include "scripted.h"
#include "explode.h"
#include "gib.h"
#include "EntityFlame.h"
#include "entityblocker.h"
#include "eventqueue.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
// Spawnflags
#define SF_DROPSHIP_WAIT_FOR_DROPOFF_INPUT ( 1 << 15 )
#define DROPSHIP_ACCEL_RATE 300
// Timers
#define DROPSHIP_LANDING_HOVER_TIME 5 // Time to spend on the ground if we have no troops to drop
#define DROPSHIP_TIME_BETWEEN_MINES 0.5f
// Special actions
#define DROPSHIP_DEFAULT_SOLDIERS 4
#define DROPSHIP_MAX_SOLDIERS 6
// Movement
#define DROPSHIP_BUFF_TIME 0.3f
#define DROPSHIP_MAX_LAND_TILT 2.5f
#define DROPSHIP_CONTAINER_HEIGHT 130.0f
#define DROPSHIP_MAX_SPEED (60 * 17.6) // 120 miles per hour.
// Pathing data
#define DROPSHIP_LEAD_DISTANCE 800.0f
#define DROPSHIP_MIN_CHASE_DIST_DIFF 128.0f // Distance threshold used to determine when a target has moved enough to update our navigation to it
#define DROPSHIP_AVOID_DIST 256.0f
#define DROPSHIP_ARRIVE_DIST 128.0f
#define CRATE_BBOX_MIN (Vector( -100, -80, -60 ))
#define CRATE_BBOX_MAX (Vector( 100, 80, 80 ))
// Size
// With crate
#define DROPSHIP_BBOX_CRATE_MIN (-Vector(40,40,60))
#define DROPSHIP_BBOX_CRATE_MAX (Vector(40,40,40))
// Without crate
#define DROPSHIP_BBOX_MIN (-Vector(40,40,0))
#define DROPSHIP_BBOX_MAX (Vector(40,40,40))
// Container gun
#define DROPSHIP_GUN_SPEED 10 // Rotation speed
#define DROPSHIP_CRATE_ROCKET_HITS 4
enum DROP_STATES
{
DROP_IDLE = 0,
DROP_NEXT,
};
enum CRATE_TYPES
{
CRATE_JEEP = -3,
CRATE_APC = -2,
CRATE_STRIDER = -1,
CRATE_ROLLER_HOPPER,
CRATE_SOLDIER,
CRATE_NONE,
};
ConVar g_debug_dropship( "g_debug_dropship", "0" );
ConVar sk_dropship_container_health( "sk_dropship_container_health", "750" );
ConVar sk_npc_dmg_dropship( "sk_npc_dmg_dropship","5", FCVAR_NONE, "Dropship container cannon damage." );
//=====================================
// Animation Events
//=====================================
#define AE_DROPSHIP_RAMP_OPEN 1 // the tailgate is open.
//=====================================
// Custom activities
//=====================================
// Without Cargo
Activity ACT_DROPSHIP_FLY_IDLE; // Flying. Vertical aspect
Activity ACT_DROPSHIP_FLY_IDLE_EXAGG; // Exaggerated version of the flying idle
// With Cargo
Activity ACT_DROPSHIP_FLY_IDLE_CARGO; // Flying. Vertical aspect
Activity ACT_DROPSHIP_DESCEND_IDLE; // waiting to touchdown
Activity ACT_DROPSHIP_DEPLOY_IDLE; // idle on the ground with door open. Troops are leaving.
Activity ACT_DROPSHIP_LIFTOFF; // transition back to FLY IDLE
enum LandingState_t
{
LANDING_NO = 0,
// Dropoff
LANDING_LEVEL_OUT, // Heading to a point above the dropoff point
LANDING_DESCEND, // Descending from to the dropoff point
LANDING_TOUCHDOWN,
LANDING_UNLOADING,
LANDING_UNLOADED,
LANDING_LIFTOFF,
// Pickup
LANDING_SWOOPING, // Swooping down to the target
// Hovering, which we're saying is a type of landing since there's so much landing code to leverage
LANDING_START_HOVER,
LANDING_HOVER_LEVEL_OUT,
LANDING_HOVER_DESCEND,
LANDING_HOVER_TOUCHDOWN,
LANDING_END_HOVER,
};
#define DROPSHIP_NEAR_SOUND_MIN_DISTANCE 1000
#define DROPSHIP_NEAR_SOUND_MAX_DISTANCE 2500
#define DROPSHIP_GROUND_WASH_MIN_ALTITUDE 100.0f
#define DROPSHIP_GROUND_WASH_MAX_ALTITUDE 750.0f
//=============================================================================
// The combine dropship container
//=============================================================================
#define DROPSHIP_CONTAINER_MODEL "models/combine_dropship_container.mdl"
#define DROPSHIP_CONTAINER_MAX_CHUNKS 3
static const char *s_pChunkModelName[DROPSHIP_CONTAINER_MAX_CHUNKS] =
{
"models/gibs/helicopter_brokenpiece_01.mdl",
"models/gibs/helicopter_brokenpiece_02.mdl",
"models/gibs/helicopter_brokenpiece_03.mdl",
};
#define DROPSHIP_CONTAINER_MAX_GIBS 1
static const char *s_pGibModelName[DROPSHIP_CONTAINER_MAX_GIBS] =
{
"models/combine_dropship_container.mdl",
};
class CCombineDropshipContainer : public CPhysicsProp
{
DECLARE_CLASS( CCombineDropshipContainer, CPhysicsProp );
DECLARE_DATADESC();
public:
void Precache();
virtual void Spawn();
virtual bool OverridePropdata( void );
virtual int OnTakeDamage( const CTakeDamageInfo &info );
virtual void Event_Killed( const CTakeDamageInfo &info );
private:
enum
{
MAX_SMOKE_TRAILS = 4,
MAX_EXPLOSIONS = 4,
};
// Should we trigger a damage effect?
bool ShouldTriggerDamageEffect( int nPrevHealth, int nEffectCount ) const;
// Add a smoke trail since we've taken more damage
void AddSmokeTrail( const Vector &vecPos );
// Pow!
void ThrowFlamingGib();
// Create a corpse
void CreateCorpse();
private:
int m_nSmokeTrailCount;
EHANDLE m_hLastInflictor;
float m_flLastHitTime;
};
//=============================================================================
// The combine dropship
//=============================================================================
class CNPC_CombineDropship : public CBaseHelicopter
{
DECLARE_CLASS( CNPC_CombineDropship, CBaseHelicopter );
public:
~CNPC_CombineDropship();
// Setup
void Spawn( void );
void Precache( void );
void Activate( void );
// Thinking/init
void InitializeRotorSound( void );
void StopLoopingSounds();
void PrescheduleThink( void );
// Flight/sound
void Hunt( void );
void Flight( void );
float GetAltitude( void );
void DoRotorWash( void );
void UpdateRotorSoundPitch( int iPitch );
void UpdatePickupNavigation( void );
void UpdateLandTargetNavigation( void );
void CalculateSoldierCount( int iSoldiers );
// Updates the facing direction
virtual void UpdateFacingDirection();
// Combat
void GatherEnemyConditions( CBaseEntity *pEnemy );
void DoCombatStuff( void );
void SpawnTroop( void );
void DropMine( void );
void UpdateContainerGunFacing( Vector &vecMuzzle, Vector &vecToTarget, Vector &vecAimDir, float *flTargetRange );
bool FireCannonRound( void );
void DoImpactEffect( trace_t &tr, int nDamageType );
void StartCannon( void );
void StopCannon( void );
void MakeTracer( const Vector &vecTracerSrc, const trace_t &tr, int iTracerType );
int OnTakeDamage_Alive( const CTakeDamageInfo &inputInfo );
// Input handlers.
void InputLandLeave( inputdata_t &inputdata );
void InputLandTake( inputdata_t &inputdata );
void InputSetLandTarget( inputdata_t &inputdata );
void InputDropMines( inputdata_t &inputdata );
void InputDropStrider( inputdata_t &inputdata );
void InputDropAPC( inputdata_t &inputdata );
void InputPickup( inputdata_t &inputdata );
void InputSetGunRange( inputdata_t &inputdata );
void InputNPCFinishDustoff( inputdata_t &inputdata );
void InputStopWaitingForDropoff( inputdata_t &inputdata );
void InputHover( inputdata_t &inputdata );
// From AI_TrackPather
virtual void InputFlyToPathTrack( inputdata_t &inputdata );
Vector GetDropoffFinishPosition( Vector vecOrigin, CAI_BaseNPC *pNPC, Vector vecMins, Vector vecMaxs );
void LandCommon( bool bHover = false );
Class_T Classify( void ) { return CLASS_COMBINE_GUNSHIP; }
// Drop the soldier container
void DropSoldierContainer( );
// Sounds
virtual void UpdateRotorWashVolume();
private:
void SetLandingState( LandingState_t landingState );
LandingState_t GetLandingState() const { return (LandingState_t)m_iLandState; }
bool IsHovering();
void UpdateGroundRotorWashSound( float flAltitude );
void UpdateRotorWashVolume( CSoundPatch *pRotorSound, float flVolume, float flDeltaTime );
private:
// Timers
float m_flTimeTakeOff;
float m_flNextTroopSpawnAttempt;
float m_flDropDelay; // delta between each mine
float m_flTimeNextAttack;
float m_flLastTime;
// States and counters
int m_iMineCount; // index for current mine # being deployed
int m_totalMinesToDrop; // total # of mines to drop as a group (based upon triggered input)
int m_soldiersToDrop;
int m_iDropState;
int m_iLandState;
float m_engineThrust; // for tracking sound volume/pitch
float m_existPitch;
float m_existRoll;
bool m_bDropMines; // signal to drop mines
bool m_bIsFiring;
int m_iBurstRounds;
bool m_leaveCrate;
bool m_bHasDroppedOff;
int m_iCrateType;
float m_flLandingSpeed;
float m_flGunRange;
bool m_bInvulnerable;
QAngle m_vecAngAcceleration;
// Misc Vars
CHandle<CBaseAnimating> m_hContainer;
EHANDLE m_hPickupTarget;
int m_iContainerMoveType;
bool m_bWaitForDropoffInput;
DECLARE_DATADESC();
DEFINE_CUSTOM_AI;
EHANDLE m_hLandTarget;
string_t m_iszLandTarget;
string_t m_iszAPCVehicleName;
// Templates for soldier's dropped off
string_t m_sNPCTemplate[ DROPSHIP_MAX_SOLDIERS ];
string_t m_sNPCTemplateData[ DROPSHIP_MAX_SOLDIERS ];
string_t m_sDustoffPoints[ DROPSHIP_MAX_SOLDIERS ];
int m_iCurrentTroopExiting;
EHANDLE m_hLastTroopToLeave;
// Template for rollermines dropped by this dropship
string_t m_sRollermineTemplate;
string_t m_sRollermineTemplateData;
// Cached attachment points
int m_iMuzzleAttachment;
int m_iMachineGunBaseAttachment;
int m_iMachineGunRefAttachment;
int m_iAttachmentTroopDeploy;
int m_iAttachmentDeployStart;
// Sounds
CSoundPatch *m_pCannonSound;
CSoundPatch *m_pRotorOnGroundSound;
CSoundPatch *m_pDescendingWarningSound;
CSoundPatch *m_pNearRotorSound;
// Outputs
COutputEvent m_OnFinishedDropoff;
COutputEvent m_OnFinishedPickup;
COutputFloat m_OnContainerShotDownBeforeDropoff;
COutputEvent m_OnContainerShotDownAfterDropoff;
protected:
// Because the combine dropship is a leaf class, we can use
// static variables to store this information, and save some memory.
// Should the dropship end up having inheritors, their activate may
// stomp these numbers, in which case you should make these ordinary members
// again.
static int m_poseBody_Accel, m_poseBody_Sway, m_poseCargo_Body_Accel, m_poseCargo_Body_Sway,
m_poseWeapon_Pitch, m_poseWeapon_Yaw;
static bool m_sbStaticPoseParamsLoaded;
virtual void PopulatePoseParameters( void );
};
bool CNPC_CombineDropship::m_sbStaticPoseParamsLoaded = false;
int CNPC_CombineDropship::m_poseBody_Accel = 0;
int CNPC_CombineDropship::m_poseBody_Sway = 0;
int CNPC_CombineDropship::m_poseCargo_Body_Accel = 0;
int CNPC_CombineDropship::m_poseCargo_Body_Sway = 0;
int CNPC_CombineDropship::m_poseWeapon_Pitch = 0;
int CNPC_CombineDropship::m_poseWeapon_Yaw = 0;
//-----------------------------------------------------------------------------
// Purpose: Cache whatever pose parameters we intend to use
//-----------------------------------------------------------------------------
void CNPC_CombineDropship::PopulatePoseParameters( void )
{
if (!m_sbStaticPoseParamsLoaded)
{
m_poseBody_Accel = LookupPoseParameter( "body_accel");
m_poseBody_Sway = LookupPoseParameter( "body_sway" );
m_poseCargo_Body_Accel = LookupPoseParameter( "cargo_body_accel" );
m_poseCargo_Body_Sway = LookupPoseParameter( "cargo_body_sway" );
// m_poseWeapon_Pitch = LookupPoseParameter("weapon_pitch");
// m_poseWeapon_Yaw = LookupPoseParameter("weapon_yaw");
m_sbStaticPoseParamsLoaded = true;
}
BaseClass::PopulatePoseParameters();
}
//------------------------------------------------------------------------------
//
// Combine Dropship Container implementation:
//
//------------------------------------------------------------------------------
LINK_ENTITY_TO_CLASS( prop_dropship_container, CCombineDropshipContainer )
BEGIN_DATADESC( CCombineDropshipContainer )
DEFINE_FIELD( m_nSmokeTrailCount, FIELD_INTEGER ),
DEFINE_FIELD( m_hLastInflictor, FIELD_EHANDLE ),
DEFINE_FIELD( m_flLastHitTime, FIELD_TIME ),
END_DATADESC()
//-----------------------------------------------------------------------------
// Precache
//-----------------------------------------------------------------------------
void CCombineDropshipContainer::Precache()
{
PrecacheModel( DROPSHIP_CONTAINER_MODEL );
// Set this here to quiet base prop warnings
SetModel( DROPSHIP_CONTAINER_MODEL );
BaseClass::Precache();
int i;
for ( i = 0; i < DROPSHIP_CONTAINER_MAX_CHUNKS; ++i )
{
PrecacheModel( s_pChunkModelName[i] );
}
for ( i = 0; i < DROPSHIP_CONTAINER_MAX_GIBS; ++i )
{
PrecacheModel( s_pGibModelName[i] );
}
PropBreakablePrecacheAll( GetModelName() );
}
//-----------------------------------------------------------------------------
// Spawn
//-----------------------------------------------------------------------------
void CCombineDropshipContainer::Spawn()
{
// NOTE: Model must be set before spawn
SetModel( DROPSHIP_CONTAINER_MODEL );
SetSolid( SOLID_VPHYSICS );
BaseClass::Spawn();
#ifdef _XBOX
AddEffects( EF_NOSHADOW );
#endif //_XBOX
m_iHealth = m_iMaxHealth = sk_dropship_container_health.GetFloat();
}
//-----------------------------------------------------------------------------
// Allows us to use vphysics
//-----------------------------------------------------------------------------
bool CCombineDropshipContainer::OverridePropdata( void )
{
return true;
}
//-----------------------------------------------------------------------------
// Should we trigger a damage effect?
//-----------------------------------------------------------------------------
inline bool CCombineDropshipContainer::ShouldTriggerDamageEffect( int nPrevHealth, int nEffectCount ) const
{
int nPrevRange = (int)( ((float)nPrevHealth / (float)GetMaxHealth()) * nEffectCount );
int nRange = (int)( ((float)GetHealth() / (float)GetMaxHealth()) * nEffectCount );
return ( nRange != nPrevRange );
}
//-----------------------------------------------------------------------------
// Character killed (only fired once)
//-----------------------------------------------------------------------------
void CCombineDropshipContainer::CreateCorpse()
{
m_lifeState = LIFE_DEAD;
Vector vecNormalizedMins, vecNormalizedMaxs;
Vector vecAbsMins, vecAbsMaxs;
CollisionProp()->WorldSpaceAABB( &vecAbsMins, &vecAbsMaxs );
CollisionProp()->WorldToNormalizedSpace( vecAbsMins, &vecNormalizedMins );
CollisionProp()->WorldToNormalizedSpace( vecAbsMaxs, &vecNormalizedMaxs );
// Explode
Vector vecAbsPoint;
CPASFilter filter( GetAbsOrigin() );
CollisionProp()->RandomPointInBounds( vecNormalizedMins, vecNormalizedMaxs, &vecAbsPoint);
te->Explosion( filter, 0.0f, &vecAbsPoint, g_sModelIndexFireball,
random->RandomInt( 4, 10 ), random->RandomInt( 8, 15 ), TE_EXPLFLAG_NOPARTICLES, 100, 0 );
// Break into chunks
Vector angVelocity;
QAngleToAngularImpulse( GetLocalAngularVelocity(), angVelocity );
PropBreakableCreateAll( GetModelIndex(), VPhysicsGetObject(), GetAbsOrigin(), GetAbsAngles(), GetAbsVelocity(), angVelocity, 1.0, 250, COLLISION_GROUP_NPC, this );
// Create flaming gibs
int iChunks = random->RandomInt( 4, 6 );
for ( int i = 0; i < iChunks; i++ )
{
ThrowFlamingGib();
}
AddSolidFlags( FSOLID_NOT_SOLID );
AddEffects( EF_NODRAW );
UTIL_Remove( this );
}
//-----------------------------------------------------------------------------
// Character killed (only fired once)
//-----------------------------------------------------------------------------
void CCombineDropshipContainer::ThrowFlamingGib( void )
{
Vector vecAbsMins, vecAbsMaxs;
CollisionProp()->WorldSpaceAABB( &vecAbsMins, &vecAbsMaxs );
Vector vecNormalizedMins, vecNormalizedMaxs;
CollisionProp()->WorldToNormalizedSpace( vecAbsMins, &vecNormalizedMins );
CollisionProp()->WorldToNormalizedSpace( vecAbsMaxs, &vecNormalizedMaxs );
Vector vecAbsPoint;
CPASFilter filter( GetAbsOrigin() );
CollisionProp()->RandomPointInBounds( vecNormalizedMins, vecNormalizedMaxs, &vecAbsPoint);
// Throw a flaming, smoking chunk.
CGib *pChunk = CREATE_ENTITY( CGib, "gib" );
pChunk->Spawn( "models/gibs/hgibs.mdl" );
pChunk->SetBloodColor( DONT_BLEED );
QAngle vecSpawnAngles;
vecSpawnAngles.Random( -90, 90 );
pChunk->SetAbsOrigin( vecAbsPoint );
pChunk->SetAbsAngles( vecSpawnAngles );
int nGib = random->RandomInt( 0, DROPSHIP_CONTAINER_MAX_CHUNKS - 1 );
pChunk->Spawn( s_pChunkModelName[nGib] );
pChunk->SetOwnerEntity( this );
pChunk->m_lifeTime = random->RandomFloat( 6.0f, 8.0f );
pChunk->SetCollisionGroup( COLLISION_GROUP_DEBRIS );
IPhysicsObject *pPhysicsObject = pChunk->VPhysicsInitNormal( SOLID_VPHYSICS, pChunk->GetSolidFlags(), false );
// Set the velocity
if ( pPhysicsObject )
{
pPhysicsObject->EnableMotion( true );
Vector vecVelocity;
QAngle angles;
angles.x = random->RandomFloat( -20, 20 );
angles.y = random->RandomFloat( 0, 360 );
angles.z = 0.0f;
AngleVectors( angles, &vecVelocity );
vecVelocity *= random->RandomFloat( 300, 900 );
vecVelocity += GetAbsVelocity();
AngularImpulse angImpulse;
angImpulse = RandomAngularImpulse( -180, 180 );
pChunk->SetAbsVelocity( vecVelocity );
pPhysicsObject->SetVelocity(&vecVelocity, &angImpulse );
}
CEntityFlame *pFlame = CEntityFlame::Create( pChunk, false );
if ( pFlame != NULL )
{
pFlame->SetLifetime( pChunk->m_lifeTime );
}
SmokeTrail *pSmokeTrail = SmokeTrail::CreateSmokeTrail();
if( pSmokeTrail )
{
pSmokeTrail->m_SpawnRate = 80;
pSmokeTrail->m_ParticleLifetime = 0.8f;
pSmokeTrail->m_StartColor.Init(0.3, 0.3, 0.3);
pSmokeTrail->m_EndColor.Init(0.5, 0.5, 0.5);
pSmokeTrail->m_StartSize = 10;
pSmokeTrail->m_EndSize = 40;
pSmokeTrail->m_SpawnRadius = 5;
pSmokeTrail->m_Opacity = 0.4;
pSmokeTrail->m_MinSpeed = 15;
pSmokeTrail->m_MaxSpeed = 25;
pSmokeTrail->SetLifetime( pChunk->m_lifeTime );
pSmokeTrail->SetParent( pChunk, 0 );
pSmokeTrail->SetLocalOrigin( vec3_origin );
pSmokeTrail->SetMoveType( MOVETYPE_NONE );
}
}
//-----------------------------------------------------------------------------
// Character killed (only fired once)
//-----------------------------------------------------------------------------
void CCombineDropshipContainer::Event_Killed( const CTakeDamageInfo &info )
{
if ( GetOwnerEntity() )
{
CNPC_CombineDropship *pDropship = assert_cast<CNPC_CombineDropship *>(GetOwnerEntity() );
pDropship->DropSoldierContainer();
}
CreateCorpse();
}
//-----------------------------------------------------------------------------
// Damage effects
//-----------------------------------------------------------------------------
int CCombineDropshipContainer::OnTakeDamage( const CTakeDamageInfo &info )
{
if ( m_iHealth == 0 )
return 0;
// Airboat guns + explosive damage is all that can hurt it
if (( info.GetDamageType() & (DMG_BLAST | DMG_AIRBOAT) ) == 0 )
return 0;
CTakeDamageInfo dmgInfo = info;
int nPrevHealth = GetHealth();
if ( info.GetDamageType() & DMG_BLAST )
{
// This check is necessary to prevent double-counting of rocket damage
// from the blast hitting both the dropship + the container
if ( (info.GetInflictor() != m_hLastInflictor) || (gpGlobals->curtime != m_flLastHitTime) )
{
m_iHealth -= (m_iMaxHealth / DROPSHIP_CRATE_ROCKET_HITS) + 1;
m_hLastInflictor = info.GetInflictor();
m_flLastHitTime = gpGlobals->curtime;
}
}
else
{
m_iHealth -= dmgInfo.GetDamage();
}
if ( m_iHealth <= 0 )
{
m_iHealth = 0;
Event_Killed( dmgInfo );
return 0;
}
// Spawn damage effects
if ( nPrevHealth != GetHealth() )
{
if ( ShouldTriggerDamageEffect( nPrevHealth, MAX_SMOKE_TRAILS ) )
{
AddSmokeTrail( dmgInfo.GetDamagePosition() );
}
if ( ShouldTriggerDamageEffect( nPrevHealth, MAX_EXPLOSIONS ) )
{
ExplosionCreate( dmgInfo.GetDamagePosition(), vec3_angle, this, 1000, 500.0f,
SF_ENVEXPLOSION_NODAMAGE | SF_ENVEXPLOSION_NOSPARKS | SF_ENVEXPLOSION_NODLIGHTS | SF_ENVEXPLOSION_NOSMOKE, 0 );
UTIL_ScreenShake( dmgInfo.GetDamagePosition(), 25.0, 150.0, 1.0, 750.0f, SHAKE_START );
ThrowFlamingGib();
}
}
return 1;
}
//-----------------------------------------------------------------------------
// Add a smoke trail since we've taken more damage
//-----------------------------------------------------------------------------
void CCombineDropshipContainer::AddSmokeTrail( const Vector &vecPos )
{
// Start this trail out with a bang!
ExplosionCreate( vecPos, vec3_angle, this, 1000, 500.0f, SF_ENVEXPLOSION_NODAMAGE |
SF_ENVEXPLOSION_NOSPARKS | SF_ENVEXPLOSION_NODLIGHTS | SF_ENVEXPLOSION_NOSMOKE, 0 );
UTIL_ScreenShake( vecPos, 25.0, 150.0, 1.0, 750.0f, SHAKE_START );
if ( m_nSmokeTrailCount == MAX_SMOKE_TRAILS )
return;
SmokeTrail *pSmokeTrail = SmokeTrail::CreateSmokeTrail();
if( !pSmokeTrail )
return;
// See if there's an attachment for this smoke trail
char buf[32];
Q_snprintf( buf, 32, "damage%d", m_nSmokeTrailCount );
int nAttachment = LookupAttachment( buf );
++m_nSmokeTrailCount;
pSmokeTrail->m_SpawnRate = 20;
pSmokeTrail->m_ParticleLifetime = 4.0f;
pSmokeTrail->m_StartColor.Init( 0.7f, 0.7f, 0.7f );
pSmokeTrail->m_EndColor.Init( 0.6, 0.6, 0.6 );
pSmokeTrail->m_StartSize = 15;
pSmokeTrail->m_EndSize = 50;
pSmokeTrail->m_SpawnRadius = 15;
pSmokeTrail->m_Opacity = 0.75f;
pSmokeTrail->m_MinSpeed = 10;
pSmokeTrail->m_MaxSpeed = 20;
pSmokeTrail->m_MinDirectedSpeed = 100.0f;
pSmokeTrail->m_MaxDirectedSpeed = 120.0f;
pSmokeTrail->SetLifetime( 5 );
pSmokeTrail->SetParent( this, nAttachment );
if ( nAttachment == 0 )
{
pSmokeTrail->SetAbsOrigin( vecPos );
}
else
{
pSmokeTrail->SetLocalOrigin( vec3_origin );
}
Vector vecForward( -1, 0, 0 );
QAngle angles;
VectorAngles( vecForward, angles );
pSmokeTrail->SetAbsAngles( angles );
pSmokeTrail->SetMoveType( MOVETYPE_NONE );
}
//------------------------------------------------------------------------------
//
// Combine Dropship implementation:
//
//------------------------------------------------------------------------------
LINK_ENTITY_TO_CLASS( npc_combinedropship, CNPC_CombineDropship );
BEGIN_DATADESC( CNPC_CombineDropship )
DEFINE_FIELD( m_flTimeTakeOff, FIELD_TIME ),
DEFINE_FIELD( m_flNextTroopSpawnAttempt, FIELD_TIME ),
DEFINE_FIELD( m_flDropDelay, FIELD_TIME ),
DEFINE_FIELD( m_flTimeNextAttack, FIELD_TIME ),
DEFINE_FIELD( m_flLastTime, FIELD_TIME ),
DEFINE_FIELD( m_iMineCount, FIELD_INTEGER ),
DEFINE_FIELD( m_totalMinesToDrop, FIELD_INTEGER ),
DEFINE_FIELD( m_soldiersToDrop, FIELD_INTEGER ),
DEFINE_FIELD( m_iDropState, FIELD_INTEGER ),
DEFINE_FIELD( m_bDropMines, FIELD_BOOLEAN ),
DEFINE_FIELD( m_iLandState, FIELD_INTEGER ),
DEFINE_FIELD( m_engineThrust, FIELD_FLOAT ),
DEFINE_FIELD( m_bIsFiring, FIELD_BOOLEAN ),
DEFINE_FIELD( m_iBurstRounds, FIELD_INTEGER ),
DEFINE_FIELD( m_existPitch, FIELD_FLOAT ),
DEFINE_FIELD( m_existRoll, FIELD_FLOAT ),
DEFINE_FIELD( m_leaveCrate, FIELD_BOOLEAN ),
DEFINE_KEYFIELD( m_iCrateType, FIELD_INTEGER, "CrateType" ),
DEFINE_FIELD( m_flLandingSpeed, FIELD_FLOAT ),
DEFINE_KEYFIELD( m_flGunRange, FIELD_FLOAT, "GunRange" ),
DEFINE_FIELD( m_vecAngAcceleration,FIELD_VECTOR ),
DEFINE_FIELD( m_hContainer, FIELD_EHANDLE ),
DEFINE_FIELD( m_hPickupTarget, FIELD_EHANDLE ),
DEFINE_FIELD( m_iContainerMoveType, FIELD_INTEGER ),
DEFINE_FIELD( m_bWaitForDropoffInput, FIELD_BOOLEAN ),
DEFINE_FIELD( m_hLandTarget, FIELD_EHANDLE ),
DEFINE_FIELD( m_bHasDroppedOff, FIELD_BOOLEAN ),
DEFINE_KEYFIELD( m_bInvulnerable, FIELD_BOOLEAN, "Invulnerable" ),
DEFINE_KEYFIELD( m_iszLandTarget, FIELD_STRING, "LandTarget" ),
DEFINE_SOUNDPATCH( m_pRotorOnGroundSound ),
DEFINE_SOUNDPATCH( m_pDescendingWarningSound ),
DEFINE_SOUNDPATCH( m_pNearRotorSound ),
DEFINE_KEYFIELD( m_iszAPCVehicleName, FIELD_STRING, "APCVehicleName" ),
DEFINE_KEYFIELD( m_sRollermineTemplate, FIELD_STRING, "RollermineTemplate" ),
DEFINE_FIELD( m_sRollermineTemplateData, FIELD_STRING ),
DEFINE_ARRAY( m_sNPCTemplateData, FIELD_STRING, DROPSHIP_MAX_SOLDIERS ),
DEFINE_KEYFIELD( m_sNPCTemplate[0], FIELD_STRING, "NPCTemplate" ),
DEFINE_KEYFIELD( m_sNPCTemplate[1], FIELD_STRING, "NPCTemplate2" ),
DEFINE_KEYFIELD( m_sNPCTemplate[2], FIELD_STRING, "NPCTemplate3" ),
DEFINE_KEYFIELD( m_sNPCTemplate[3], FIELD_STRING, "NPCTemplate4" ),
DEFINE_KEYFIELD( m_sNPCTemplate[4], FIELD_STRING, "NPCTemplate5" ),
DEFINE_KEYFIELD( m_sNPCTemplate[5], FIELD_STRING, "NPCTemplate6" ),
// Here to shut classcheck up
//DEFINE_ARRAY( m_sNPCTemplate, FIELD_STRING, DROPSHIP_MAX_SOLDIERS ),
//DEFINE_ARRAY( m_sDustoffPoints, FIELD_STRING, DROPSHIP_MAX_SOLDIERS ),
DEFINE_KEYFIELD( m_sDustoffPoints[0], FIELD_STRING, "Dustoff1" ),
DEFINE_KEYFIELD( m_sDustoffPoints[1], FIELD_STRING, "Dustoff2" ),
DEFINE_KEYFIELD( m_sDustoffPoints[2], FIELD_STRING, "Dustoff3" ),
DEFINE_KEYFIELD( m_sDustoffPoints[3], FIELD_STRING, "Dustoff4" ),
DEFINE_KEYFIELD( m_sDustoffPoints[4], FIELD_STRING, "Dustoff5" ),
DEFINE_KEYFIELD( m_sDustoffPoints[5], FIELD_STRING, "Dustoff6" ),
DEFINE_FIELD( m_iCurrentTroopExiting, FIELD_INTEGER ),
DEFINE_FIELD( m_hLastTroopToLeave, FIELD_EHANDLE ),
DEFINE_FIELD( m_iMuzzleAttachment, FIELD_INTEGER ),
DEFINE_FIELD( m_iMachineGunBaseAttachment, FIELD_INTEGER ),
DEFINE_FIELD( m_iMachineGunRefAttachment, FIELD_INTEGER ),
DEFINE_FIELD( m_iAttachmentTroopDeploy, FIELD_INTEGER ),
DEFINE_FIELD( m_iAttachmentDeployStart , FIELD_INTEGER ),
DEFINE_SOUNDPATCH( m_pCannonSound ),
DEFINE_INPUTFUNC( FIELD_INTEGER, "LandLeaveCrate", InputLandLeave ),
DEFINE_INPUTFUNC( FIELD_INTEGER, "LandTakeCrate", InputLandTake ),
DEFINE_INPUTFUNC( FIELD_STRING, "SetLandTarget", InputSetLandTarget ),
DEFINE_INPUTFUNC( FIELD_INTEGER, "DropMines", InputDropMines ),
DEFINE_INPUTFUNC( FIELD_VOID, "DropStrider", InputDropStrider ),
DEFINE_INPUTFUNC( FIELD_VOID, "DropAPC", InputDropAPC ),
DEFINE_INPUTFUNC( FIELD_STRING, "Pickup", InputPickup ),
DEFINE_INPUTFUNC( FIELD_FLOAT, "SetGunRange", InputSetGunRange ),
DEFINE_INPUTFUNC( FIELD_STRING, "NPCFinishDustoff", InputNPCFinishDustoff ),
DEFINE_INPUTFUNC( FIELD_VOID, "StopWaitingForDropoff", InputStopWaitingForDropoff ),
DEFINE_INPUTFUNC( FIELD_STRING, "Hover", InputHover ),
DEFINE_INPUTFUNC( FIELD_STRING, "FlyToPathTrack", InputFlyToPathTrack ),
DEFINE_OUTPUT( m_OnFinishedDropoff, "OnFinishedDropoff" ),
DEFINE_OUTPUT( m_OnFinishedPickup, "OnFinishedPickup" ),
DEFINE_OUTPUT( m_OnContainerShotDownBeforeDropoff, "OnCrateShotDownBeforeDropoff" ),
DEFINE_OUTPUT( m_OnContainerShotDownAfterDropoff, "OnCrateShotDownAfterDropoff" ),
END_DATADESC()
//------------------------------------------------------------------------------
// Purpose : Destructor
//------------------------------------------------------------------------------
CNPC_CombineDropship::~CNPC_CombineDropship(void)
{
if ( m_hContainer )
{
UTIL_Remove( m_hContainer ); // get rid of container
}
}
//------------------------------------------------------------------------------
// Purpose :
// Input :
// Output :
//------------------------------------------------------------------------------
void CNPC_CombineDropship::Spawn( void )
{
Precache( );
SetModel( "models/combine_dropship.mdl" );
#ifdef _XBOX
AddEffects( EF_NOSHADOW );
#endif //_XBOX
InitPathingData( DROPSHIP_ARRIVE_DIST, DROPSHIP_MIN_CHASE_DIST_DIFF, DROPSHIP_AVOID_DIST );
m_iContainerMoveType = MOVETYPE_NONE;
m_iCurrentTroopExiting = 0;
m_bHasDroppedOff = false;
m_iMuzzleAttachment = -1;
m_iMachineGunBaseAttachment = -1;
m_iMachineGunRefAttachment = -1;
m_iAttachmentTroopDeploy = -1;
m_iAttachmentDeployStart = -1;
// create the correct bin for the ship to carry
switch ( m_iCrateType )
{
case CRATE_ROLLER_HOPPER:
break;
case CRATE_SOLDIER:
m_hContainer = (CBaseAnimating*)CreateEntityByName( "prop_dropship_container" );
if ( m_hContainer )
{
m_hContainer->SetName( AllocPooledString("dropship_container") );
m_hContainer->SetAbsOrigin( GetAbsOrigin() );
m_hContainer->SetAbsAngles( GetAbsAngles() );
m_hContainer->SetParent(this, 0);
m_hContainer->SetOwnerEntity(this);
m_hContainer->Spawn();
IPhysicsObject *pPhysicsObject = m_hContainer->VPhysicsGetObject();
if ( pPhysicsObject )
{
pPhysicsObject->SetShadow( 1e4, 1e4, false, false );
pPhysicsObject->UpdateShadow( m_hContainer->GetAbsOrigin(), m_hContainer->GetAbsAngles(), false, 0 );
}
m_hContainer->SetMoveType( MOVETYPE_PUSH );
m_hContainer->SetGroundEntity( NULL );
// Cache off container's attachment points
m_iAttachmentTroopDeploy = m_hContainer->LookupAttachment( "deploy_landpoint" );
m_iAttachmentDeployStart = m_hContainer->LookupAttachment( "Deploy_Start" );
m_iMuzzleAttachment = m_hContainer->LookupAttachment( "muzzle" );
m_iMachineGunBaseAttachment = m_hContainer->LookupAttachment( "gun_base" );
// NOTE: gun_ref must have the same position as gun_base, but rotates with the gun
m_iMachineGunRefAttachment = m_hContainer->LookupAttachment( "gun_ref" );
}
break;
case CRATE_STRIDER:
m_hContainer = (CBaseAnimating*)CreateEntityByName( "npc_strider" );
m_hContainer->SetAbsOrigin( GetAbsOrigin() - Vector( 0, 0 , 100 ) );
m_hContainer->SetAbsAngles( GetAbsAngles() );
m_hContainer->SetParent(this, 0);
m_hContainer->SetOwnerEntity(this);
m_hContainer->Spawn();
m_hContainer->SetAbsOrigin( GetAbsOrigin() - Vector( 0, 0 , 100 ) );
break;
case CRATE_APC:
{
m_soldiersToDrop = 0;
m_hContainer = (CBaseAnimating*)gEntList.FindEntityByName( NULL, m_iszAPCVehicleName );
if ( !m_hContainer )
{
Warning("Unable to find APC %s\n", STRING( m_iszAPCVehicleName ) );
break;
}
Vector apcPosition = GetAbsOrigin() - Vector( 0, 0 , 25 );
QAngle apcAngles = GetAbsAngles();
VMatrix mat, rot, result;
MatrixFromAngles( apcAngles, mat );
MatrixBuildRotateZ( rot, -90 );
MatrixMultiply( mat, rot, result );
MatrixToAngles( result, apcAngles );
m_hContainer->Teleport( &apcPosition, &apcAngles, NULL );
m_iContainerMoveType = m_hContainer->GetMoveType();
IPhysicsObject *pPhysicsObject = m_hContainer->VPhysicsGetObject();
if ( pPhysicsObject )
{
pPhysicsObject->SetShadow( 1e4, 1e4, false, false );
}
m_hContainer->SetParent(this, 0);
m_hContainer->SetOwnerEntity(this);
m_hContainer->SetMoveType( MOVETYPE_PUSH );
m_hContainer->SetGroundEntity( NULL );
m_hContainer->UpdatePhysicsShadowToCurrentPosition(0);
}
break;
case CRATE_JEEP:
m_hContainer = (CBaseAnimating*)CreateEntityByName( "prop_dynamic_override" );
if ( m_hContainer )
{
m_hContainer->SetModel( "models/buggy.mdl" );
m_hContainer->SetName( AllocPooledString("dropship_jeep") );
m_hContainer->SetAbsOrigin( GetAbsOrigin() );//- Vector( 0, 0 , 25 ) );
QAngle angles = GetAbsAngles();
VMatrix mat, rot, result;
MatrixFromAngles( angles, mat );
MatrixBuildRotateZ( rot, -90 );
MatrixMultiply( mat, rot, result );
MatrixToAngles( result, angles );
m_hContainer->SetAbsAngles( angles );
m_hContainer->SetParent(this, 0);
m_hContainer->SetOwnerEntity(this);
m_hContainer->SetSolid( SOLID_VPHYSICS );
m_hContainer->Spawn();
}
break;
case CRATE_NONE:
default:
break;
}
// Setup our bbox
if ( m_hContainer )
{
UTIL_SetSize( this, DROPSHIP_BBOX_CRATE_MIN, DROPSHIP_BBOX_CRATE_MAX );
SetIdealActivity( (Activity)ACT_DROPSHIP_FLY_IDLE_CARGO );
}
else
{
UTIL_SetSize( this, DROPSHIP_BBOX_MIN, DROPSHIP_BBOX_MAX );
SetIdealActivity( (Activity)ACT_DROPSHIP_FLY_IDLE_EXAGG );
}
m_cullBoxMins = WorldAlignMins() - Vector(300,300,200);
m_cullBoxMaxs = WorldAlignMaxs() + Vector(300,300,200);
BaseClass::Spawn();
// Dropship ignores all damage, but can deal it to its carried container
m_takedamage = m_bInvulnerable ? DAMAGE_NO : DAMAGE_YES;
if ( m_bInvulnerable && m_hContainer )
{
m_hContainer->m_takedamage = DAMAGE_NO;
}
m_iHealth = 100;
m_flFieldOfView = 0.5; // 60 degrees