/
npc_scanner.cpp
3029 lines (2576 loc) · 88 KB
/
npc_scanner.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:
//
//=============================================================================//
#include "cbase.h"
#include "npcevent.h"
#include "soundenvelope.h"
#include "ai_hint.h"
#include "ai_moveprobe.h"
#include "ai_squad.h"
#include "beam_shared.h"
#include "globalstate.h"
#include "soundent.h"
#include "npc_citizen17.h"
#include "gib.h"
#include "spotlightend.h"
#include "IEffects.h"
#include "items.h"
#include "ai_route.h"
#include "player_pickup.h"
#include "weapon_physcannon.h"
#include "hl2_player.h"
#include "npc_scanner.h"
#include "materialsystem/imaterialsystemhardwareconfig.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
//-----------------------------------------------------------------------------
// Singleton interfaces
//-----------------------------------------------------------------------------
extern IMaterialSystemHardwareConfig *g_pMaterialSystemHardwareConfig;
//-----------------------------------------------------------------------------
// Parameters for how the scanner relates to citizens.
//-----------------------------------------------------------------------------
#define SCANNER_CIT_INSPECT_DELAY 10 // Check for citizens this often
#define SCANNER_CIT_INSPECT_GROUND_DIST 500 // How far to look for citizens to inspect
#define SCANNER_CIT_INSPECT_FLY_DIST 1500 // How far to look for citizens to inspect
#define SCANNER_CIT_INSPECT_LENGTH 5 // How long does the inspection last
#define SCANNER_HINT_INSPECT_LENGTH 5 // How long does the inspection last
#define SCANNER_SOUND_INSPECT_LENGTH 5 // How long does the inspection last
#define SCANNER_HINT_INSPECT_DELAY 15 // Check for hint nodes this often
#define SPOTLIGHT_WIDTH 32
#define SCANNER_SPOTLIGHT_NEAR_DIST 64
#define SCANNER_SPOTLIGHT_FAR_DIST 256
#define SCANNER_SPOTLIGHT_FLY_HEIGHT 72
#define SCANNER_NOSPOTLIGHT_FLY_HEIGHT 72
#define SCANNER_FLASH_MIN_DIST 900 // How far does flash effect enemy
#define SCANNER_FLASH_MAX_DIST 1200 // How far does flash effect enemy
#define SCANNER_FLASH_MAX_VALUE 240 // How bright is maximum flash
#define SCANNER_PHOTO_NEAR_DIST 64
#define SCANNER_PHOTO_FAR_DIST 128
#define SCANNER_FOLLOW_DIST 128
#define SCANNER_NUM_GIBS 6 // Number of gibs in gib file
// Strider Scout Scanners
#define SCANNER_SCOUT_MAX_SPEED 150
ConVar sk_scanner_health( "sk_scanner_health","0");
ConVar g_debug_cscanner( "g_debug_cscanner", "0" );
//-----------------------------------------------------------------------------
// Private activities.
//-----------------------------------------------------------------------------
static int ACT_SCANNER_SMALL_FLINCH_ALERT = 0;
static int ACT_SCANNER_SMALL_FLINCH_COMBAT = 0;
static int ACT_SCANNER_INSPECT = 0;
static int ACT_SCANNER_WALK_ALERT = 0;
static int ACT_SCANNER_WALK_COMBAT = 0;
static int ACT_SCANNER_FLARE = 0;
static int ACT_SCANNER_RETRACT = 0;
static int ACT_SCANNER_FLARE_PRONGS = 0;
static int ACT_SCANNER_RETRACT_PRONGS = 0;
static int ACT_SCANNER_FLARE_START = 0;
//-----------------------------------------------------------------------------
// Interactions
//-----------------------------------------------------------------------------
int g_interactionScannerInspect = 0;
int g_interactionScannerInspectBegin = 0;
int g_interactionScannerInspectHandsUp = 0;
int g_interactionScannerInspectShowArmband = 0;//<<TEMP>>still to be completed
int g_interactionScannerInspectDone = 0;
int g_interactionScannerSupportEntity = 0;
int g_interactionScannerSupportPosition = 0;
//-----------------------------------------------------------------------------
// Animation events
//------------------------------------------------------------------------
int AE_SCANNER_CLOSED;
//-----------------------------------------------------------------------------
// Attachment points
//-----------------------------------------------------------------------------
#define SCANNER_ATTACHMENT_LIGHT "light"
#define SCANNER_ATTACHMENT_FLASH 1
#define SCANNER_ATTACHMENT_LPRONG 2
#define SCANNER_ATTACHMENT_RPRONG 3
//-----------------------------------------------------------------------------
// Other defines.
//-----------------------------------------------------------------------------
#define SCANNER_MAX_BEAMS 4
BEGIN_DATADESC( CNPC_CScanner )
DEFINE_SOUNDPATCH( m_pEngineSound ),
DEFINE_EMBEDDED( m_KilledInfo ),
DEFINE_FIELD( m_flGoalOverrideDistance, FIELD_FLOAT ),
DEFINE_FIELD( m_bPhotoTaken, FIELD_BOOLEAN ),
DEFINE_FIELD( m_vInspectPos, FIELD_VECTOR ),
DEFINE_FIELD( m_fInspectEndTime, FIELD_TIME ),
DEFINE_FIELD( m_fCheckCitizenTime, FIELD_TIME ),
DEFINE_FIELD( m_fCheckHintTime, FIELD_TIME ),
DEFINE_KEYFIELD( m_bShouldInspect, FIELD_BOOLEAN, "ShouldInspect" ),
DEFINE_KEYFIELD( m_bOnlyInspectPlayers, FIELD_BOOLEAN, "OnlyInspectPlayers" ),
DEFINE_KEYFIELD( m_bNeverInspectPlayers,FIELD_BOOLEAN, "NeverInspectPlayers" ),
DEFINE_FIELD( m_fNextPhotographTime, FIELD_TIME ),
// DEFINE_FIELD( m_pEyeFlash, FIELD_CLASSPTR ),
DEFINE_FIELD( m_vSpotlightTargetPos, FIELD_POSITION_VECTOR ),
DEFINE_FIELD( m_vSpotlightCurrentPos, FIELD_POSITION_VECTOR ),
// don't save (recreated after restore/transition)
// DEFINE_FIELD( m_hSpotlight, FIELD_EHANDLE ),
// DEFINE_FIELD( m_hSpotlightTarget, FIELD_EHANDLE ),
DEFINE_FIELD( m_vSpotlightDir, FIELD_VECTOR ),
DEFINE_FIELD( m_vSpotlightAngVelocity, FIELD_VECTOR ),
DEFINE_FIELD( m_flSpotlightCurLength, FIELD_FLOAT ),
DEFINE_FIELD( m_fNextSpotlightTime, FIELD_TIME ),
DEFINE_FIELD( m_nHaloSprite, FIELD_INTEGER ),
DEFINE_FIELD( m_fNextFlySoundTime, FIELD_TIME ),
DEFINE_FIELD( m_nFlyMode, FIELD_INTEGER ),
DEFINE_FIELD( m_nPoseTail, FIELD_INTEGER ),
DEFINE_FIELD( m_nPoseDynamo, FIELD_INTEGER ),
DEFINE_FIELD( m_nPoseFlare, FIELD_INTEGER ),
DEFINE_FIELD( m_nPoseFaceVert, FIELD_INTEGER ),
DEFINE_FIELD( m_nPoseFaceHoriz, FIELD_INTEGER ),
DEFINE_FIELD( m_bIsClawScanner, FIELD_BOOLEAN ),
DEFINE_FIELD( m_bIsOpen, FIELD_BOOLEAN ),
// DEFINE_FIELD( m_bHasSpoken, FIELD_BOOLEAN ),
DEFINE_FIELD( m_pSmokeTrail, FIELD_CLASSPTR ),
DEFINE_FIELD( m_flFlyNoiseBase, FIELD_FLOAT ),
DEFINE_FIELD( m_flEngineStallTime, FIELD_TIME ),
DEFINE_FIELD( m_vecDiveBombDirection, FIELD_VECTOR ),
DEFINE_FIELD( m_flDiveBombRollForce, FIELD_FLOAT ),
DEFINE_KEYFIELD( m_flSpotlightMaxLength, FIELD_FLOAT, "SpotlightLength"),
DEFINE_KEYFIELD( m_flSpotlightGoalWidth, FIELD_FLOAT, "SpotlightWidth"),
// Physics Influence
DEFINE_FIELD( m_hPhysicsAttacker, FIELD_EHANDLE ),
DEFINE_FIELD( m_flLastPhysicsInfluenceTime, FIELD_TIME ),
DEFINE_KEYFIELD( m_bNoLight, FIELD_BOOLEAN, "SpotlightDisabled" ),
DEFINE_INPUTFUNC( FIELD_VOID, "DisableSpotlight", InputDisableSpotlight ),
DEFINE_INPUTFUNC( FIELD_STRING, "InspectTargetPhoto", InputInspectTargetPhoto ),
DEFINE_INPUTFUNC( FIELD_STRING, "InspectTargetSpotlight", InputInspectTargetSpotlight ),
DEFINE_INPUTFUNC( FIELD_INTEGER, "InputShouldInspect", InputShouldInspect ),
DEFINE_INPUTFUNC( FIELD_STRING, "SetFollowTarget", InputSetFollowTarget ),
DEFINE_INPUTFUNC( FIELD_VOID, "ClearFollowTarget", InputClearFollowTarget ),
DEFINE_INPUTFUNC( FIELD_STRING, "DeployMine", InputDeployMine ),
DEFINE_INPUTFUNC( FIELD_STRING, "EquipMine", InputEquipMine ),
DEFINE_OUTPUT( m_OnPhotographPlayer, "OnPhotographPlayer" ),
DEFINE_OUTPUT( m_OnPhotographNPC, "OnPhotographNPC" ),
END_DATADESC()
LINK_ENTITY_TO_CLASS(npc_cscanner, CNPC_CScanner);
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CNPC_CScanner::CNPC_CScanner()
{
#ifdef _DEBUG
m_vInspectPos.Init();
m_vSpotlightTargetPos.Init();
m_vSpotlightCurrentPos.Init();
m_vSpotlightDir.Init();
m_vSpotlightAngVelocity.Init();
#endif
m_bShouldInspect = true;
m_bOnlyInspectPlayers = false;
m_bNeverInspectPlayers = false;
char szMapName[256];
Q_strncpy(szMapName, STRING(gpGlobals->mapname), sizeof(szMapName) );
Q_strlower(szMapName);
if( !Q_strnicmp( szMapName, "d3_c17", 6 ) )
{
// Streetwar scanners are claw scanners
m_bIsClawScanner = true;
}
else
{
m_bIsClawScanner = false;
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CNPC_CScanner::Spawn(void)
{
// Check for user error
if (m_flSpotlightMaxLength <= 0)
{
DevMsg("CNPC_CScanner::Spawn: Invalid spotlight length <= 0, setting to 500\n");
m_flSpotlightMaxLength = 500;
}
if (m_flSpotlightGoalWidth <= 0)
{
DevMsg("CNPC_CScanner::Spawn: Invalid spotlight width <= 0, setting to 100\n");
m_flSpotlightGoalWidth = 100;
}
if (m_flSpotlightGoalWidth > MAX_BEAM_WIDTH )
{
DevMsg("CNPC_CScanner::Spawn: Invalid spotlight width %.1f (max %.1f).\n", m_flSpotlightGoalWidth, MAX_BEAM_WIDTH );
m_flSpotlightGoalWidth = MAX_BEAM_WIDTH;
}
Precache();
if( m_bIsClawScanner )
{
SetModel( "models/shield_scanner.mdl");
}
else
{
SetModel( "models/combine_scanner.mdl");
}
m_iHealth = sk_scanner_health.GetFloat();
m_iMaxHealth = m_iHealth;
// ------------------------------------
// Init all class vars
// ------------------------------------
m_vInspectPos = vec3_origin;
m_fInspectEndTime = 0;
m_fCheckCitizenTime = gpGlobals->curtime + SCANNER_CIT_INSPECT_DELAY;
m_fCheckHintTime = gpGlobals->curtime + SCANNER_HINT_INSPECT_DELAY;
m_fNextPhotographTime = 0;
m_vSpotlightTargetPos = vec3_origin;
m_vSpotlightCurrentPos = vec3_origin;
m_hSpotlight = NULL;
m_hSpotlightTarget = NULL;
AngleVectors( GetLocalAngles(), &m_vSpotlightDir );
m_vSpotlightAngVelocity = vec3_origin;
m_pEyeFlash = 0;
m_fNextSpotlightTime = 0;
m_nFlyMode = SCANNER_FLY_PATROL;
m_vCurrentBanking = m_vSpotlightDir;
m_flSpotlightCurLength = m_flSpotlightMaxLength;
m_nPoseTail = LookupPoseParameter( "tail_control" );
m_nPoseDynamo = LookupPoseParameter( "dynamo_wheel" );
m_nPoseFlare = LookupPoseParameter( "alert_control" );
m_nPoseFaceVert = LookupPoseParameter( "flex_vert" );
m_nPoseFaceHoriz = LookupPoseParameter( "flex_horz" );
// --------------------------------------------
CapabilitiesAdd( bits_CAP_INNATE_MELEE_ATTACK1 );
m_bPhotoTaken = false;
BaseClass::Spawn();
// Watch for this error state
if ( m_bOnlyInspectPlayers && m_bNeverInspectPlayers )
{
Assert( 0 );
Warning( "ERROR: Scanner set to never and always inspect players!\n" );
}
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void CNPC_CScanner::Activate()
{
BaseClass::Activate();
// Have to do this here because sprites do not go across level transitions
m_pEyeFlash = CSprite::SpriteCreate( "sprites/blueflare1.vmt", GetLocalOrigin(), FALSE );
m_pEyeFlash->SetTransparency( kRenderGlow, 255, 255, 255, 0, kRenderFxNoDissipation );
m_pEyeFlash->SetAttachment( this, LookupAttachment( SCANNER_ATTACHMENT_LIGHT ) );
m_pEyeFlash->SetBrightness( 0 );
m_pEyeFlash->SetScale( 1.4 );
}
//------------------------------------------------------------------------------
// Purpose: Override to split in two when attacked
//------------------------------------------------------------------------------
int CNPC_CScanner::OnTakeDamage_Alive( const CTakeDamageInfo &info )
{
// Turn off my spotlight when shot
SpotlightDestroy();
m_fNextSpotlightTime = gpGlobals->curtime + 2.0f;
return (BaseClass::OnTakeDamage_Alive( info ));
}
//------------------------------------------------------------------------------
// Purpose:
//------------------------------------------------------------------------------
void CNPC_CScanner::Gib( void )
{
if ( IsMarkedForDeletion() )
return;
// Spawn all gibs
if( m_bIsClawScanner )
{
CGib::SpawnSpecificGibs( this, 1, 500, 250, "models/gibs/Shield_Scanner_Gib1.mdl");
CGib::SpawnSpecificGibs( this, 1, 500, 250, "models/gibs/Shield_Scanner_Gib2.mdl");
CGib::SpawnSpecificGibs( this, 1, 500, 250, "models/gibs/Shield_Scanner_Gib3.mdl");
CGib::SpawnSpecificGibs( this, 1, 500, 250, "models/gibs/Shield_Scanner_Gib4.mdl");
CGib::SpawnSpecificGibs( this, 1, 500, 250, "models/gibs/Shield_Scanner_Gib5.mdl");
CGib::SpawnSpecificGibs( this, 1, 500, 250, "models/gibs/Shield_Scanner_Gib6.mdl");
}
else
{
CGib::SpawnSpecificGibs( this, 1, 500, 250, "models/gibs/scanner_gib01.mdl" );
CGib::SpawnSpecificGibs( this, 1, 500, 250, "models/gibs/scanner_gib02.mdl" );
CGib::SpawnSpecificGibs( this, 1, 500, 250, "models/gibs/scanner_gib04.mdl" );
CGib::SpawnSpecificGibs( this, 1, 500, 250, "models/gibs/scanner_gib05.mdl" );
}
// Add a random chance of spawning a battery...
if ( !HasSpawnFlags(SF_NPC_NO_WEAPON_DROP) && random->RandomFloat( 0.0f, 1.0f) < 0.3f )
{
CItem *pBattery = (CItem*)CreateEntityByName("item_battery");
if ( pBattery )
{
pBattery->SetAbsOrigin( GetAbsOrigin() );
pBattery->SetAbsVelocity( GetAbsVelocity() );
pBattery->SetLocalAngularVelocity( GetLocalAngularVelocity() );
pBattery->ActivateWhenAtRest();
pBattery->Spawn();
}
}
DeployMine();
BaseClass::Gib();
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : pInflictor -
// pAttacker -
// flDamage -
// bitsDamageType -
//-----------------------------------------------------------------------------
void CNPC_CScanner::Event_Killed( const CTakeDamageInfo &info )
{
// Copy off the takedamage info that killed me, since we're not going to call
// up into the base class's Event_Killed() until we gib. (gibbing is ultimate death)
m_KilledInfo = info;
DeployMine();
ClearInspectTarget();
// Interrupt whatever schedule I'm on
SetCondition(COND_SCHEDULE_DONE);
// Remove spotlight
SpotlightDestroy();
// Remove sprite
UTIL_Remove(m_pEyeFlash);
m_pEyeFlash = NULL;
// If I have an enemy and I'm up high, do a dive bomb (unless dissolved)
if ( !m_bIsClawScanner && GetEnemy() != NULL && (info.GetDamageType() & DMG_DISSOLVE) == false )
{
Vector vecDelta = GetLocalOrigin() - GetEnemy()->GetLocalOrigin();
if ( ( vecDelta.z > 120 ) && ( vecDelta.Length() > 360 ) )
{
// If I'm divebombing, don't take any more damage. It will make Event_Killed() be called again.
// This is especially bad if someone machineguns the divebombing scanner.
AttackDivebomb();
return;
}
}
Gib();
}
//-----------------------------------------------------------------------------
// Purpose: Tells use whether or not the NPC cares about a given type of hint node.
// Input : sHint -
// Output : TRUE if the NPC is interested in this hint type, FALSE if not.
//-----------------------------------------------------------------------------
bool CNPC_CScanner::FValidateHintType(CAI_Hint *pHint)
{
return( pHint->HintType() == HINT_WORLD_WINDOW );
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : Type -
//-----------------------------------------------------------------------------
int CNPC_CScanner::TranslateSchedule( int scheduleType )
{
switch ( scheduleType )
{
case SCHED_IDLE_STAND:
{
return SCHED_SCANNER_PATROL;
}
case SCHED_SCANNER_PATROL:
return SCHED_CSCANNER_PATROL;
}
return BaseClass::TranslateSchedule(scheduleType);
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : idealActivity -
// *pIdealWeaponActivity -
// Output : int
//-----------------------------------------------------------------------------
Activity CNPC_CScanner::NPC_TranslateActivity( Activity eNewActivity )
{
if( !m_bIsClawScanner )
{
return BaseClass::NPC_TranslateActivity( eNewActivity );
}
// The claw scanner came along a little late and doesn't have the activities
// of the city scanner. So Just pick between these three
if( eNewActivity == ACT_DISARM )
{
// Closing up.
return eNewActivity;
}
if( m_bIsOpen )
{
return ACT_IDLE_ANGRY;
}
else
{
return ACT_IDLE;
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CNPC_CScanner::HandleAnimEvent( animevent_t *pEvent )
{
if( pEvent->event == AE_SCANNER_CLOSED )
{
m_bIsOpen = false;
SetActivity( ACT_IDLE );
return;
}
BaseClass::HandleAnimEvent( pEvent );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
char *CNPC_CScanner::GetEngineSound( void )
{
if( m_bIsClawScanner )
return "NPC_SScanner.FlyLoop";
return "NPC_CScanner.FlyLoop";
}
//-----------------------------------------------------------------------------
// Purpose: Plays the engine sound.
//-----------------------------------------------------------------------------
void CNPC_CScanner::NPCThink(void)
{
if (!IsAlive())
{
SetActivity((Activity)ACT_SCANNER_RETRACT_PRONGS);
StudioFrameAdvance( );
SetNextThink( gpGlobals->curtime + 0.1f );
}
else
{
BaseClass::NPCThink();
SpotlightUpdate();
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CNPC_CScanner::Precache(void)
{
// Model
if( m_bIsClawScanner )
{
PrecacheModel("models/shield_scanner.mdl");
PrecacheModel("models/gibs/Shield_Scanner_Gib1.mdl");
PrecacheModel("models/gibs/Shield_Scanner_Gib2.mdl");
PrecacheModel("models/gibs/Shield_Scanner_Gib3.mdl");
PrecacheModel("models/gibs/Shield_Scanner_Gib4.mdl");
PrecacheModel("models/gibs/Shield_Scanner_Gib5.mdl");
PrecacheModel("models/gibs/Shield_Scanner_Gib6.mdl");
PrecacheScriptSound( "NPC_SScanner.Shoot");
PrecacheScriptSound( "NPC_SScanner.Alert" );
PrecacheScriptSound( "NPC_SScanner.Die" );
PrecacheScriptSound( "NPC_SScanner.Combat" );
PrecacheScriptSound( "NPC_SScanner.Idle" );
PrecacheScriptSound( "NPC_SScanner.Pain" );
PrecacheScriptSound( "NPC_SScanner.TakePhoto" );
PrecacheScriptSound( "NPC_SScanner.AttackFlash" );
PrecacheScriptSound( "NPC_SScanner.DiveBombFlyby" );
PrecacheScriptSound( "NPC_SScanner.DiveBomb" );
PrecacheScriptSound( "NPC_SScanner.DeployMine" );
PrecacheScriptSound( "NPC_SScanner.FlyLoop" );
UTIL_PrecacheOther( "combine_mine" );
}
else
{
PrecacheModel("models/combine_scanner.mdl");
PrecacheModel("models/gibs/scanner_gib01.mdl" );
PrecacheModel("models/gibs/scanner_gib02.mdl" );
PrecacheModel("models/gibs/scanner_gib02.mdl" );
PrecacheModel("models/gibs/scanner_gib04.mdl" );
PrecacheModel("models/gibs/scanner_gib05.mdl" );
PrecacheScriptSound( "NPC_CScanner.Shoot");
PrecacheScriptSound( "NPC_CScanner.Alert" );
PrecacheScriptSound( "NPC_CScanner.Die" );
PrecacheScriptSound( "NPC_CScanner.Combat" );
PrecacheScriptSound( "NPC_CScanner.Idle" );
PrecacheScriptSound( "NPC_CScanner.Pain" );
PrecacheScriptSound( "NPC_CScanner.TakePhoto" );
PrecacheScriptSound( "NPC_CScanner.AttackFlash" );
PrecacheScriptSound( "NPC_CScanner.DiveBombFlyby" );
PrecacheScriptSound( "NPC_CScanner.DiveBomb" );
PrecacheScriptSound( "NPC_CScanner.DeployMine" );
PrecacheScriptSound( "NPC_CScanner.FlyLoop" );
}
// Sprites
m_nHaloSprite = PrecacheModel("sprites/light_glow03.vmt");
PrecacheModel( "sprites/glow_test02.vmt" );
BaseClass::Precache();
}
//------------------------------------------------------------------------------
// Purpose: Request help inspecting from other squad members
//------------------------------------------------------------------------------
void CNPC_CScanner::RequestInspectSupport(void)
{
if (m_pSquad)
{
AISquadIter_t iter;
for (CAI_BaseNPC *pSquadMember = m_pSquad->GetFirstMember( &iter ); pSquadMember; pSquadMember = m_pSquad->GetNextMember( &iter ) )
{
if (pSquadMember != this)
{
if (GetTarget())
{
pSquadMember->DispatchInteraction(g_interactionScannerSupportEntity,((void *)((CBaseEntity*)GetTarget())),this);
}
else
{
pSquadMember->DispatchInteraction(g_interactionScannerSupportPosition,((void *)m_vInspectPos.Base()),this);
}
}
}
}
}
//------------------------------------------------------------------------------
// Purpose:
//------------------------------------------------------------------------------
bool CNPC_CScanner::IsValidInspectTarget(CBaseEntity *pEntity)
{
// If a citizen, make sure he can be inspected again
if (pEntity->Classify() == CLASS_CITIZEN_PASSIVE)
{
if (((CNPC_Citizen*)pEntity)->GetNextScannerInspectTime() > gpGlobals->curtime)
{
return false;
}
}
// Make sure no other squad member has already chosen to
// inspect this entity
if (m_pSquad)
{
AISquadIter_t iter;
for (CAI_BaseNPC *pSquadMember = m_pSquad->GetFirstMember( &iter ); pSquadMember; pSquadMember = m_pSquad->GetNextMember( &iter ) )
{
if (pSquadMember->GetTarget() == pEntity)
{
return false;
}
}
}
// Do not inspect friendly targets
if ( IRelationType( pEntity ) == D_LI )
return false;
return true;
}
//------------------------------------------------------------------------------
// Purpose:
//------------------------------------------------------------------------------
CBaseEntity* CNPC_CScanner::BestInspectTarget(void)
{
if ( !m_bShouldInspect )
return NULL;
CBaseEntity* pBestEntity = NULL;
float fBestDist = MAX_COORD_RANGE;
float fTestDist;
CBaseEntity *pEntity = NULL;
// If I have a spotlight, search from the spotlight position
// otherwise search from my position
Vector vSearchOrigin;
float fSearchDist;
if (m_hSpotlightTarget != NULL)
{
vSearchOrigin = m_hSpotlightTarget->GetAbsOrigin();
fSearchDist = SCANNER_CIT_INSPECT_GROUND_DIST;
}
else
{
vSearchOrigin = WorldSpaceCenter();
fSearchDist = SCANNER_CIT_INSPECT_FLY_DIST;
}
if ( m_bOnlyInspectPlayers )
{
CBasePlayer *pPlayer = AI_GetSinglePlayer();
if ( !pPlayer )
return NULL;
if ( !pPlayer->IsAlive() || (pPlayer->GetFlags() & FL_NOTARGET) )
return NULL;
return WorldSpaceCenter().DistToSqr( pPlayer->EyePosition() ) <= (fSearchDist * fSearchDist) ? pPlayer : NULL;
}
CUtlVector<CBaseEntity *> candidates;
float fSearchDistSq = fSearchDist * fSearchDist;
int i;
// Inspect players unless told otherwise
if ( m_bNeverInspectPlayers == false )
{
// Players
for ( i = 1; i <= gpGlobals->maxClients; i++ )
{
CBaseEntity *pPlayer = UTIL_PlayerByIndex( i );
if ( pPlayer )
{
if ( vSearchOrigin.DistToSqr(pPlayer->GetAbsOrigin()) < fSearchDistSq )
{
candidates.AddToTail( pPlayer );
}
}
}
}
// NPCs
CAI_BaseNPC **ppAIs = g_AI_Manager.AccessAIs();
for ( i = 0; i < g_AI_Manager.NumAIs(); i++ )
{
if ( ppAIs[i] != this && vSearchOrigin.DistToSqr(ppAIs[i]->GetAbsOrigin()) < fSearchDistSq )
{
candidates.AddToTail( ppAIs[i] );
}
}
for ( i = 0; i < candidates.Count(); i++ )
{
pEntity = candidates[i];
Assert( pEntity != this && (pEntity->MyNPCPointer() || pEntity->IsPlayer() ) );
CAI_BaseNPC *pNPC = pEntity->MyNPCPointer();
if ( ( pNPC && pNPC->Classify() == CLASS_CITIZEN_PASSIVE ) || pEntity->IsPlayer() )
{
if ( pEntity->GetFlags() & FL_NOTARGET )
continue;
if ( pEntity->IsAlive() == false )
continue;
// Ensure it's within line of sight
if ( !FVisible( pEntity ) )
continue;
fTestDist = ( GetAbsOrigin() - pEntity->EyePosition() ).Length();
if ( fTestDist < fBestDist )
{
if ( IsValidInspectTarget( pEntity ) )
{
fBestDist = fTestDist;
pBestEntity = pEntity;
}
}
}
}
return pBestEntity;
}
//------------------------------------------------------------------------------
// Purpose: Clears any previous inspect target and set inspect target to
// the given entity and set the durection of the inspection
//------------------------------------------------------------------------------
void CNPC_CScanner::SetInspectTargetToEnt(CBaseEntity *pEntity, float fInspectDuration)
{
ClearInspectTarget();
SetTarget(pEntity);
m_fInspectEndTime = gpGlobals->curtime + fInspectDuration;
}
//------------------------------------------------------------------------------
// Purpose: Clears any previous inspect target and set inspect target to
// the given hint node and set the durection of the inspection
//------------------------------------------------------------------------------
void CNPC_CScanner::SetInspectTargetToHint(CAI_Hint *pHint, float fInspectDuration)
{
ClearInspectTarget();
float yaw = pHint->Yaw();
// --------------------------------------------
// Figure out the location that the hint hits
// --------------------------------------------
Vector vHintDir = UTIL_YawToVector( yaw );
Vector vHintOrigin;
pHint->GetPosition( this, &vHintOrigin );
Vector vHintEnd = vHintOrigin + (vHintDir * 512);
trace_t tr;
AI_TraceLine ( vHintOrigin, vHintEnd, MASK_BLOCKLOS, this, COLLISION_GROUP_NONE, &tr);
if ( g_debug_cscanner.GetBool() )
{
NDebugOverlay::Line( vHintOrigin, tr.endpos, 255, 0, 0, true, 4.0f );
NDebugOverlay::Cross3D( tr.endpos, -Vector(8,8,8), Vector(8,8,8), 255, 0, 0, true, 4.0f );
}
if (tr.fraction == 1.0f )
{
DevMsg("ERROR: Scanner hint node not facing a surface!\n");
}
else
{
SetHintNode( pHint );
m_vInspectPos = tr.endpos;
pHint->Lock( this );
m_fInspectEndTime = gpGlobals->curtime + fInspectDuration;
}
}
//------------------------------------------------------------------------------
// Purpose: Clears any previous inspect target and set inspect target to
// the given position and set the durection of the inspection
// Input :
// Output :
//------------------------------------------------------------------------------
void CNPC_CScanner::SetInspectTargetToPos(const Vector &vInspectPos, float fInspectDuration)
{
ClearInspectTarget();
m_vInspectPos = vInspectPos;
m_fInspectEndTime = gpGlobals->curtime + fInspectDuration;
}
//------------------------------------------------------------------------------
// Purpose: Clears out any previous inspection targets
//------------------------------------------------------------------------------
void CNPC_CScanner::ClearInspectTarget(void)
{
if ( GetIdealState() != NPC_STATE_SCRIPT )
{
SetTarget( NULL );
}
ClearHintNode( SCANNER_HINT_INSPECT_LENGTH );
m_vInspectPos = vec3_origin;
}
//------------------------------------------------------------------------------
// Purpose: Returns true if there is a position to be inspected.
//------------------------------------------------------------------------------
bool CNPC_CScanner::HaveInspectTarget( void )
{
if ( GetTarget() != NULL )
return true;
if ( m_vInspectPos != vec3_origin )
return true;
return false;
}
//------------------------------------------------------------------------------
// Purpose:
//------------------------------------------------------------------------------
Vector CNPC_CScanner::InspectTargetPosition(void)
{
// If we have a target, return an adjust position
if ( GetTarget() != NULL )
{
Vector vEyePos = GetTarget()->EyePosition();
// If in spotlight mode, aim for ground below target unless is client
if ( m_nFlyMode == SCANNER_FLY_SPOT && !(GetTarget()->GetFlags() & FL_CLIENT) )
{
Vector vInspectPos;
vInspectPos.x = vEyePos.x;
vInspectPos.y = vEyePos.y;
vInspectPos.z = GetFloorZ( vEyePos );
// Let's take three-quarters between eyes and ground
vInspectPos.z += ( vEyePos.z - vInspectPos.z ) * 0.75f;
return vInspectPos;
}
else
{
// Otherwise aim for eyes
return vEyePos;
}
}
else if ( m_vInspectPos != vec3_origin )
{
return m_vInspectPos;
}
else
{
DevMsg("InspectTargetPosition called with no target!\n");
return m_vInspectPos;
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CNPC_CScanner::InputShouldInspect( inputdata_t &inputdata )
{
m_bShouldInspect = ( inputdata.value.Int() != 0 );
if ( !m_bShouldInspect )
{
if ( GetEnemy() == GetTarget() )
SetEnemy(NULL);
ClearInspectTarget();
SetTarget(NULL);
SpotlightDestroy();
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CNPC_CScanner::DeployMine()
{
CBaseEntity *child;
// iterate through all children
for ( child = FirstMoveChild(); child != NULL; child = child->NextMovePeer() )
{
if( FClassnameIs( child, "combine_mine" ) )
{
child->SetParent( NULL );
child->SetAbsVelocity( GetAbsVelocity() );
child->SetOwnerEntity( this );
ScannerEmitSound( "DeployMine" );
IPhysicsObject *pPhysObj = child->VPhysicsGetObject();
if( pPhysObj )
{
// Make sure the mine's awake
pPhysObj->Wake();
}
if( m_bIsClawScanner )
{
// Fold up.
SetActivity( ACT_DISARM );
}
return;
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
float CNPC_CScanner::GetMaxSpeed()
{
if( IsStriderScout() )
{
return SCANNER_SCOUT_MAX_SPEED;
}
return BaseClass::GetMaxSpeed();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CNPC_CScanner::InputDeployMine(inputdata_t &inputdata)
{
DeployMine();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CNPC_CScanner::InputEquipMine(inputdata_t &inputdata)
{
CBaseEntity *child;
// iterate through all children
for ( child = FirstMoveChild(); child != NULL; child = child->NextMovePeer() )
{
if( FClassnameIs( child, "combine_mine" ) )
{
// Already have a mine!
return;
}
}
CBaseEntity *pEnt;
pEnt = CreateEntityByName( "combine_mine" );
bool bPlacedMine = false;
if( m_bIsClawScanner )
{