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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Bullseyes act as targets for other NPC's to attack and to trigger
// events
//
// $Workfile: $
// $Date: $
//
//-----------------------------------------------------------------------------
// $Log: $
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "ai_default.h"
#include "ai_task.h"
#include "ai_schedule.h"
#include "ai_node.h"
#include "ai_hull.h"
#include "ai_hint.h"
#include "ai_memory.h"
#include "ai_route.h"
#include "ai_motor.h"
#include "ai_squadslot.h"
#include "soundent.h"
#include "game.h"
#include "npcevent.h"
#include "entitylist.h"
#include "activitylist.h"
#include "animation.h"
#include "basecombatweapon.h"
#include "IEffects.h"
#include "vstdlib/random.h"
#include "engine/IEngineSound.h"
#include "ammodef.h"
#include "te.h"
#include "hl1_ai_basenpc.h"
ConVar sk_agrunt_health( "sk_agrunt_health", "0" );
ConVar sk_agrunt_dmg_punch( "sk_agrunt_dmg_punch", "0" );
//=========================================================
// Monster's Anim Events Go Here
//=========================================================
#define AGRUNT_AE_HORNET1 ( 1 )
#define AGRUNT_AE_HORNET2 ( 2 )
#define AGRUNT_AE_HORNET3 ( 3 )
#define AGRUNT_AE_HORNET4 ( 4 )
#define AGRUNT_AE_HORNET5 ( 5 )
// some events are set up in the QC file that aren't recognized by the code yet.
#define AGRUNT_AE_PUNCH ( 6 )
#define AGRUNT_AE_BITE ( 7 )
#define AGRUNT_AE_LEFT_FOOT ( 10 )
#define AGRUNT_AE_RIGHT_FOOT ( 11 )
#define AGRUNT_AE_LEFT_PUNCH ( 12 )
#define AGRUNT_AE_RIGHT_PUNCH ( 13 )
#define AGRUNT_MELEE_DIST 100
int iAgruntMuzzleFlash;
int ACT_THREAT_DISPLAY;
// -----------------------------------------------
// > Squad slots
// -----------------------------------------------
enum AGruntSquadSlot_T
{
AGRUNT_SQUAD_SLOT_HORNET1 = LAST_SHARED_SQUADSLOT,
AGRUNT_SQUAD_SLOT_HORNET2,
AGRUNT_SQUAD_SLOT_CHASE,
};
enum
{
SCHED_AGRUNT_FAIL = LAST_SHARED_SCHEDULE,
SCHED_AGRUNT_COMBAT_FAIL,
SCHED_AGRUNT_STANDOFF,
SCHED_AGRUNT_SUPPRESS_HORNET,
SCHED_AGRUNT_RANGE_ATTACK,
SCHED_AGRUNT_HIDDEN_RANGE_ATTACK,
SCHED_AGRUNT_TAKE_COVER_FROM_ENEMY,
SCHED_AGRUNT_VICTORY_DANCE,
SCHED_AGRUNT_THREAT_DISPLAY,
};
//=========================================================
// monster-specific tasks
//=========================================================
enum
{
TASK_AGRUNT_SETUP_HIDE_ATTACK = LAST_SHARED_TASK,
TASK_AGRUNT_GET_PATH_TO_ENEMY_CORPSE,
TASK_AGRUNT_RANGE_ATTACK1_NOTURN,
};
class CNPC_AlienGrunt : public CHL1BaseNPC
{
DECLARE_CLASS( CNPC_AlienGrunt, CHL1BaseNPC );
public:
void Spawn( void );
void Precache( void );
float MaxYawSpeed( void );
Class_T Classify ( void ){ return CLASS_ALIEN_MILITARY; }
int GetSoundInterests ( void );
void HandleAnimEvent( animevent_t *pEvent );
void AlertSound( void );
void DeathSound( const CTakeDamageInfo &info );
void PainSound( const CTakeDamageInfo &info );
void AttackSound( void );
bool ShouldSpeak( void );
void PrescheduleThink ( void );
bool FCanCheckAttacks ( void );
int MeleeAttack1Conditions ( float flDot, float flDist );
int RangeAttack1Conditions ( float flDot, float flDist );
void StopTalking ( void );
void StartTask( const Task_t *pTask );
void RunTask( const Task_t *pTask );
int TranslateSchedule( int scheduleType ); //GetScheduleOfType
int SelectSchedule( void ); // GetSchedule
void TraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator );
int IRelationPriority( CBaseEntity *pTarget );
/*
int IRelationship( CBaseEntity *pTarget );
*/
public:
DECLARE_DATADESC();
DEFINE_CUSTOM_AI;
bool m_fCanHornetAttack;
float m_flNextHornetAttackCheck;
float m_flNextPainTime;
// three hacky fields for speech stuff. These don't really need to be saved.
float m_flNextSpeakTime;
float m_flNextWordTime;
float m_flDamageTime;
};
LINK_ENTITY_TO_CLASS( monster_alien_grunt, CNPC_AlienGrunt );
BEGIN_DATADESC( CNPC_AlienGrunt )
DEFINE_FIELD( m_fCanHornetAttack, FIELD_BOOLEAN ),
DEFINE_FIELD( m_flNextHornetAttackCheck, FIELD_TIME ),
DEFINE_FIELD( m_flNextPainTime, FIELD_TIME ),
DEFINE_FIELD( m_flNextSpeakTime, FIELD_TIME ),
DEFINE_FIELD( m_flNextWordTime, FIELD_TIME ),
DEFINE_FIELD( m_flDamageTime, FIELD_TIME ),
END_DATADESC()
int CNPC_AlienGrunt::IRelationPriority( CBaseEntity *pTarget )
{
//I hate grunts more than anything.
if ( pTarget->Classify() == CLASS_HUMAN_MILITARY )
{
if ( FClassnameIs( pTarget, "monster_human_grunt" ) )
{
return ( BaseClass::IRelationPriority ( pTarget ) + 1 );
}
}
return BaseClass::IRelationPriority( pTarget );
}
void CNPC_AlienGrunt::Spawn()
{
Precache();
SetModel( "models/agrunt.mdl");
UTIL_SetSize( this, Vector( -32, -32, 0 ), Vector( 32, 32, 64 ) );
SetSolid( SOLID_BBOX );
AddSolidFlags( FSOLID_NOT_STANDABLE );
Vector vecSurroundingMins( -32, -32, 0 );
Vector vecSurroundingMaxs( 32, 32, 85 );
CollisionProp()->SetSurroundingBoundsType( USE_SPECIFIED_BOUNDS, &vecSurroundingMins, &vecSurroundingMaxs );
SetMoveType( MOVETYPE_STEP );
m_bloodColor = BLOOD_COLOR_GREEN;
ClearEffects();
m_iHealth = sk_agrunt_health.GetFloat();
m_flFieldOfView = 0.2;// indicates the width of this monster's forward view cone ( as a dotproduct result )
m_NPCState = NPC_STATE_NONE;
CapabilitiesClear();
CapabilitiesAdd ( bits_CAP_SQUAD | bits_CAP_MOVE_GROUND );
CapabilitiesAdd(bits_CAP_INNATE_RANGE_ATTACK1 );
// Innate range attack for kicking
CapabilitiesAdd(bits_CAP_INNATE_MELEE_ATTACK1 );
m_HackedGunPos = Vector( 24, 64, 48 );
m_flNextSpeakTime = m_flNextWordTime = gpGlobals->curtime + 10 + random->RandomInt( 0, 10 );
SetHullType(HULL_WIDE_HUMAN);
SetHullSizeNormal();
SetRenderColor( 255, 255, 255, 255 );
NPCInit();
BaseClass::Spawn();
}
//=========================================================
// Precache - precaches all resources this monster needs
//=========================================================
void CNPC_AlienGrunt::Precache()
{
PrecacheModel("models/agrunt.mdl");
iAgruntMuzzleFlash = PrecacheModel( "sprites/muz4.vmt" );
UTIL_PrecacheOther( "hornet" );
PrecacheScriptSound( "Weapon_Hornetgun.Single" );
PrecacheScriptSound( "AlienGrunt.LeftFoot" );
PrecacheScriptSound( "AlienGrunt.RightFoot" );
PrecacheScriptSound( "AlienGrunt.AttackHit" );
PrecacheScriptSound( "AlienGrunt.AttackMiss" );
PrecacheScriptSound( "AlienGrunt.Die" );
PrecacheScriptSound( "AlienGrunt.Alert" );
PrecacheScriptSound( "AlienGrunt.Attack" );
PrecacheScriptSound( "AlienGrunt.Pain" );
PrecacheScriptSound( "AlienGrunt.Idle" );
}
float CNPC_AlienGrunt::MaxYawSpeed( void )
{
float ys;
switch ( GetActivity() )
{
case ACT_TURN_LEFT:
case ACT_TURN_RIGHT:
ys = 110;
break;
default:
ys = 100;
}
return ys;
}
int CNPC_AlienGrunt::GetSoundInterests ( void )
{
return SOUND_WORLD |
SOUND_COMBAT |
SOUND_PLAYER |
SOUND_DANGER;
}
//=========================================================
// HandleAnimEvent - catches the monster-specific messages
// that occur when tagged animation frames are played.
//
// Returns number of events handled, 0 if none.
//=========================================================
void CNPC_AlienGrunt::HandleAnimEvent( animevent_t *pEvent )
{
switch( pEvent->event )
{
case AGRUNT_AE_HORNET1:
case AGRUNT_AE_HORNET2:
case AGRUNT_AE_HORNET3:
case AGRUNT_AE_HORNET4:
case AGRUNT_AE_HORNET5:
{
// m_vecEnemyLKP should be center of enemy body
Vector vecArmPos;
QAngle angArmDir;
Vector vecDirToEnemy;
QAngle angDir;
if (HasCondition( COND_SEE_ENEMY) && GetEnemy())
{
Vector vecEnemyLKP = GetEnemy()->GetAbsOrigin();
vecDirToEnemy = ( ( vecEnemyLKP ) - GetAbsOrigin() );
VectorAngles( vecDirToEnemy, angDir );
VectorNormalize( vecDirToEnemy );
}
else
{
angDir = GetAbsAngles();
angDir.x = -angDir.x;
Vector vForward;
AngleVectors( angDir, &vForward );
vecDirToEnemy = vForward;
}
DoMuzzleFlash();
// make angles +-180
if (angDir.x > 180)
{
angDir.x = angDir.x - 360;
}
// SetBlending( 0, angDir.x );
GetAttachment( "0", vecArmPos, angArmDir );
vecArmPos = vecArmPos + vecDirToEnemy * 32;
CPVSFilter filter( GetAbsOrigin() );
te->Sprite( filter, 0.0,
&vecArmPos, iAgruntMuzzleFlash, random->RandomFloat( 0.4, 0.8 ), 128 );
CBaseEntity *pHornet = CBaseEntity::Create( "hornet", vecArmPos, QAngle( 0, 0, 0 ), this );
Vector vForward;
AngleVectors( angDir, &vForward );
pHornet->SetAbsVelocity( vForward * 300 );
pHornet->SetOwnerEntity( this );
EmitSound( "Weapon_Hornetgun.Single" );
CHL1BaseNPC *pHornetMonster = (CHL1BaseNPC *)pHornet->MyNPCPointer();
if ( pHornetMonster )
{
pHornetMonster->SetEnemy( GetEnemy() );
}
}
break;
case AGRUNT_AE_LEFT_FOOT:
// left foot
{
CPASAttenuationFilter filter2( this );
EmitSound( filter2, entindex(), "AlienGrunt.LeftFoot" );
}
break;
case AGRUNT_AE_RIGHT_FOOT:
// right foot
{
CPASAttenuationFilter filter3( this );
EmitSound( filter3, entindex(), "AlienGrunt.RightFoot" );
}
break;
case AGRUNT_AE_LEFT_PUNCH:
{
Vector vecMins = GetHullMins();
Vector vecMaxs = GetHullMaxs();
vecMins.z = vecMins.x;
vecMaxs.z = vecMaxs.x;
CBaseEntity *pHurt = CheckTraceHullAttack( AGRUNT_MELEE_DIST, vecMins, vecMaxs, sk_agrunt_dmg_punch.GetFloat(), DMG_CLUB );
CPASAttenuationFilter filter4( this );
if ( pHurt )
{
if ( pHurt->GetFlags() & ( FL_NPC | FL_CLIENT ) )
pHurt->ViewPunch( QAngle( -25, 8, 0) );
Vector vRight;
AngleVectors( GetAbsAngles(), NULL, &vRight, NULL );
// OK to use gpGlobals without calling MakeVectors, cause CheckTraceHullAttack called it above.
if ( pHurt->IsPlayer() )
{
// this is a player. Knock him around.
pHurt->SetAbsVelocity( pHurt->GetAbsVelocity() + vRight * 250 );
}
EmitSound(filter4, entindex(), "AlienGrunt.AttackHit" );
Vector vecArmPos;
QAngle angArmAng;
GetAttachment( 0, vecArmPos, angArmAng );
SpawnBlood(vecArmPos, g_vecAttackDir, pHurt->BloodColor(), 25);// a little surface blood.
}
else
{
// Play a random attack miss sound
EmitSound(filter4, entindex(), "AlienGrunt.AttackMiss" );
}
}
break;
case AGRUNT_AE_RIGHT_PUNCH:
{
Vector vecMins = GetHullMins();
Vector vecMaxs = GetHullMaxs();
vecMins.z = vecMins.x;
vecMaxs.z = vecMaxs.x;
CBaseEntity *pHurt = CheckTraceHullAttack( AGRUNT_MELEE_DIST, vecMins, vecMaxs, sk_agrunt_dmg_punch.GetFloat(), DMG_CLUB );
CPASAttenuationFilter filter5( this );
if ( pHurt )
{
if ( pHurt->GetFlags() & ( FL_NPC | FL_CLIENT ) )
pHurt->ViewPunch( QAngle( 25, 8, 0) );
// OK to use gpGlobals without calling MakeVectors, cause CheckTraceHullAttack called it above.
if ( pHurt->IsPlayer() )
{
// this is a player. Knock him around.
Vector vRight;
AngleVectors( GetAbsAngles(), NULL, &vRight, NULL );
pHurt->SetAbsVelocity( pHurt->GetAbsVelocity() + vRight * -250 );
}
EmitSound( filter5, entindex(), "AlienGrunt.AttackHit" );
Vector vecArmPos;
QAngle angArmAng;
GetAttachment( 0, vecArmPos, angArmAng );
SpawnBlood(vecArmPos, g_vecAttackDir, pHurt->BloodColor(), 25);// a little surface blood.
}
else
{
// Play a random attack miss sound
EmitSound( filter5, entindex(), "AlienGrunt.AttackMiss" );
}
}
break;
default:
BaseClass::HandleAnimEvent( pEvent );
break;
}
}
//=========================================================
// DieSound
//=========================================================
void CNPC_AlienGrunt::DeathSound( const CTakeDamageInfo &info )
{
StopTalking();
CPASAttenuationFilter filter( this );
EmitSound( filter, entindex(), "AlienGrunt.Die" );
}
//=========================================================
// AlertSound
//=========================================================
void CNPC_AlienGrunt::AlertSound( void )
{
StopTalking();
CPASAttenuationFilter filter( this );
EmitSound( filter, entindex(), "AlienGrunt.Alert" );
}
//=========================================================
// AttackSound
//=========================================================
void CNPC_AlienGrunt::AttackSound( void )
{
StopTalking();
CPASAttenuationFilter filter( this );
EmitSound( filter, entindex(), "AlienGrunt.Attack" );
}
//=========================================================
// PainSound
//=========================================================
void CNPC_AlienGrunt::PainSound( const CTakeDamageInfo &info )
{
if ( m_flNextPainTime > gpGlobals->curtime )
{
return;
}
m_flNextPainTime = gpGlobals->curtime + 0.6;
StopTalking();
CPASAttenuationFilter filter( this );
EmitSound( filter, entindex(),"AlienGrunt.Pain" );
}
//=========================================================
// ShouldSpeak - Should this agrunt be talking?
//=========================================================
bool CNPC_AlienGrunt::ShouldSpeak( void )
{
if ( m_flNextSpeakTime > gpGlobals->curtime )
{
// my time to talk is still in the future.
return FALSE;
}
if ( m_spawnflags & SF_NPC_GAG )
{
if ( m_NPCState != NPC_STATE_COMBAT )
{
// if gagged, don't talk outside of combat.
// if not going to talk because of this, put the talk time
// into the future a bit, so we don't talk immediately after
// going into combat
m_flNextSpeakTime = gpGlobals->curtime + 3;
return FALSE;
}
}
return TRUE;
}
//=========================================================
// PrescheduleThink
//=========================================================
void CNPC_AlienGrunt::PrescheduleThink ( void )
{
BaseClass::PrescheduleThink();
if ( ShouldSpeak() )
{
if ( m_flNextWordTime < gpGlobals->curtime )
{
// play a new sound
CPASAttenuationFilter filter( this );
EmitSound( filter, entindex(), "AlienGrunt.Idle" );
// is this word our last?
if ( random->RandomInt( 1, 10 ) <= 1 )
{
// stop talking.
StopTalking();
}
else
{
m_flNextWordTime = gpGlobals->curtime + random->RandomFloat( 0.5, 1 );
}
}
}
}
//=========================================================
// FCanCheckAttacks - this is overridden for alien grunts
// because they can use their smart weapons against unseen
// enemies. Base class doesn't attack anyone it can't see.
//=========================================================
bool CNPC_AlienGrunt::FCanCheckAttacks ( void )
{
if ( !HasCondition( COND_ENEMY_TOO_FAR ) )
return true;
else
return false;
}
//=========================================================
// CheckMeleeAttack1 - alien grunts zap the crap out of
// any enemy that gets too close.
//=========================================================
int CNPC_AlienGrunt::MeleeAttack1Conditions ( float flDot, float flDist )
{
if ( flDist > AGRUNT_MELEE_DIST )
return COND_NONE;
if ( flDot < 0.6 )
return COND_NONE;
if ( HasCondition ( COND_SEE_ENEMY ) && GetEnemy() != NULL )
return COND_CAN_MELEE_ATTACK1;
return COND_NONE;
}
//=========================================================
// CheckRangeAttack1
//
// !!!LATER - we may want to load balance this. Several
// tracelines are done, so we may not want to do this every
// server frame. Definitely not while firing.
//=========================================================
int CNPC_AlienGrunt::RangeAttack1Conditions ( float flDot, float flDist )
{
if ( gpGlobals->curtime < m_flNextHornetAttackCheck )
{
if ( HasCondition( COND_SEE_ENEMY ) )
{
if ( m_fCanHornetAttack == true )
{
return COND_CAN_RANGE_ATTACK1;
}
else
{
return COND_NONE;
}
}
else
return COND_NONE;
}
if ( flDist < AGRUNT_MELEE_DIST )
return COND_NONE;
if ( flDist > 1024 )
return COND_NONE;
if ( flDot < 0.5 )
return COND_NONE;
if ( HasCondition( COND_SEE_ENEMY ) )
{
trace_t tr;
Vector vecArmPos;
QAngle angArmDir;
// verify that a shot fired from the gun will hit the enemy before the world.
// !!!LATER - we may wish to do something different for projectile weapons as opposed to instant-hit
GetAttachment( "0", vecArmPos, angArmDir );
UTIL_TraceLine( vecArmPos, GetEnemy()->BodyTarget( vecArmPos ), MASK_SOLID, this, COLLISION_GROUP_NONE, &tr);
if ( tr.fraction == 1.0 || tr.m_pEnt == GetEnemy() )
{
m_flNextHornetAttackCheck = gpGlobals->curtime + random->RandomFloat( 2, 5 );
m_fCanHornetAttack = true;
return COND_CAN_RANGE_ATTACK1;
}
}
m_flNextHornetAttackCheck = gpGlobals->curtime + 0.2;// don't check for half second if this check wasn't successful
m_fCanHornetAttack = false;
return COND_NONE;
}
//=========================================================
// StopTalking - won't speak again for 10-20 seconds.
//=========================================================
void CNPC_AlienGrunt::StopTalking( void )
{
m_flNextWordTime = m_flNextSpeakTime = gpGlobals->curtime + 10 + random->RandomInt(0, 10);
}
void CNPC_AlienGrunt::StartTask ( const Task_t *pTask )
{
switch ( pTask->iTask )
{
case TASK_AGRUNT_RANGE_ATTACK1_NOTURN:
{
SetLastAttackTime( gpGlobals->curtime );
ResetIdealActivity( ACT_RANGE_ATTACK1 );
}
break;
case TASK_AGRUNT_GET_PATH_TO_ENEMY_CORPSE:
{
Vector forward;
AngleVectors( GetAbsAngles(), &forward );
Vector flEnemyLKP = GetEnemyLKP();
GetNavigator()->SetGoal( flEnemyLKP - forward * 64, AIN_CLEAR_TARGET);
if ( GetNavigator()->SetGoal( flEnemyLKP - forward * 64, AIN_CLEAR_TARGET) )
{
TaskComplete();
}
else
{
Msg ( "AGruntGetPathToEnemyCorpse failed!!\n" );
TaskFail( FAIL_NO_ROUTE );
}
}
break;
case TASK_AGRUNT_SETUP_HIDE_ATTACK:
// alien grunt shoots hornets back out into the open from a concealed location.
// try to find a spot to throw that gives the smart weapon a good chance of finding the enemy.
// ideally, this spot is along a line that is perpendicular to a line drawn from the agrunt to the enemy.
CHL1BaseNPC *pEnemyMonsterPtr;
pEnemyMonsterPtr = (CHL1BaseNPC *)GetEnemy()->MyNPCPointer();
if ( pEnemyMonsterPtr )
{
Vector vecCenter, vForward, vRight, vecEnemyLKP;
QAngle angTmp;
trace_t tr;
BOOL fSkip;
fSkip = FALSE;
vecCenter = WorldSpaceCenter();
vecEnemyLKP = GetEnemyLKP();
VectorAngles( vecEnemyLKP - GetAbsOrigin(), angTmp );
SetAbsAngles( angTmp );
AngleVectors( GetAbsAngles(), &vForward, &vRight, NULL );
UTIL_TraceLine( WorldSpaceCenter() + vForward * 128, vecEnemyLKP, MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &tr);
if ( tr.fraction == 1.0 )
{
GetMotor()->SetIdealYawToTargetAndUpdate ( GetAbsOrigin() + vRight * 128 );
fSkip = TRUE;
TaskComplete();
}
if ( !fSkip )
{
UTIL_TraceLine( WorldSpaceCenter() - vForward * 128, vecEnemyLKP, MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &tr);
if ( tr.fraction == 1.0 )
{
GetMotor()->SetIdealYawToTargetAndUpdate ( GetAbsOrigin() - vRight * 128 );
fSkip = TRUE;
TaskComplete();
}
}
if ( !fSkip )
{
UTIL_TraceLine( WorldSpaceCenter() + vForward * 256, vecEnemyLKP, MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &tr);
if ( tr.fraction == 1.0 )
{
GetMotor()->SetIdealYawToTargetAndUpdate ( GetAbsOrigin() + vRight * 256 );
fSkip = TRUE;
TaskComplete();
}
}
if ( !fSkip )
{
UTIL_TraceLine( WorldSpaceCenter() - vForward * 256, vecEnemyLKP, MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &tr);
if ( tr.fraction == 1.0 )
{
GetMotor()->SetIdealYawToTargetAndUpdate ( GetAbsOrigin() - vRight * 256 );
fSkip = TRUE;
TaskComplete();
}
}
if ( !fSkip )
{
TaskFail( FAIL_NO_COVER );
}
}
else
{
Msg ( "AGRunt - no enemy monster ptr!!!\n" );
TaskFail( FAIL_NO_ENEMY );
}
break;
default:
BaseClass::StartTask ( pTask );
break;
}
}
void CNPC_AlienGrunt::RunTask( const Task_t *pTask )
{
switch ( pTask->iTask )
{
// NOTE: This is obsolete. Don't use it for HL2 code
case TASK_AGRUNT_RANGE_ATTACK1_NOTURN:
{
AutoMovement( );
if ( IsActivityFinished() )
{
TaskComplete();
}
break;
}
default:
BaseClass::RunTask( pTask );
}
}
//=========================================================
// GetSchedule - Decides which type of schedule best suits
// the monster's current state and conditions. Then calls
// monster's member function to get a pointer to a schedule
// of the proper type.
//=========================================================
int CNPC_AlienGrunt::SelectSchedule( void )
{
if ( HasCondition( COND_HEAR_DANGER ) )
{
return SCHED_TAKE_COVER_FROM_BEST_SOUND;
}
switch ( m_NPCState )
{
case NPC_STATE_COMBAT:
{
// dead enemy
if ( HasCondition( COND_ENEMY_DEAD ) )
{
// call base class, all code to handle dead enemies is centralized there.
return BaseClass::SelectSchedule();
}
if ( HasCondition( COND_NEW_ENEMY) )
{
return SCHED_WAKE_ANGRY;
}
// zap player!
if ( HasCondition ( COND_CAN_MELEE_ATTACK1 ) )
{
AttackSound();// this is a total hack. Should be parto f the schedule
return SCHED_MELEE_ATTACK1;
}
if ( HasCondition ( COND_HEAVY_DAMAGE ) )
{
return SCHED_SMALL_FLINCH;
}
// can attack
if ( HasCondition ( COND_CAN_RANGE_ATTACK1 ) && OccupyStrategySlotRange( AGRUNT_SQUAD_SLOT_HORNET1, AGRUNT_SQUAD_SLOT_HORNET2 ) )
{
return SCHED_RANGE_ATTACK1;
}
if ( OccupyStrategySlot ( AGRUNT_SQUAD_SLOT_CHASE ) )
{
return SCHED_CHASE_ENEMY;
}
return SCHED_STANDOFF;
}
}
return BaseClass::SelectSchedule();
}
int CNPC_AlienGrunt::TranslateSchedule( int scheduleType )
{
switch ( scheduleType )
{
case SCHED_TAKE_COVER_FROM_ENEMY:
return SCHED_AGRUNT_TAKE_COVER_FROM_ENEMY;
break;
/*case SCHED_RANGE_ATTACK1:
if ( HasCondition( COND_SEE_ENEMY ) )
return SCHED_AGRUNT_RANGE_ATTACK;
// else
// return SCHED_AGRUNT_HIDDEN_RANGE_ATTACK;
break;*/
case SCHED_STANDOFF:
return SCHED_AGRUNT_STANDOFF;
break;
case SCHED_VICTORY_DANCE:
return SCHED_AGRUNT_VICTORY_DANCE;
break;
case SCHED_FAIL:
// no fail schedule specified, so pick a good generic one.
{
if ( GetEnemy() != NULL )
{
// I have an enemy
// !!!LATER - what if this enemy is really far away and i'm chasing him?
// this schedule will make me stop, face his last known position for 2
// seconds, and then try to move again
return SCHED_AGRUNT_COMBAT_FAIL;
}
return SCHED_AGRUNT_FAIL;
}
break;
}
return BaseClass::TranslateSchedule( scheduleType );
}
void CNPC_AlienGrunt::TraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator )
{
CTakeDamageInfo ainfo = info;
float flDamage = ainfo.GetDamage();
if ( ptr->hitgroup == 10 && (ainfo.GetDamageType() & (DMG_BULLET | DMG_SLASH | DMG_CLUB)))
{
// hit armor
if ( m_flDamageTime != gpGlobals->curtime || (random->RandomInt(0,10) < 1) )
{
CPVSFilter filter( ptr->endpos );
te->ArmorRicochet( filter, 0.0, &ptr->endpos, &ptr->plane.normal );
m_flDamageTime = gpGlobals->curtime;
}
if ( random->RandomInt( 0, 1 ) == 0 )
{
Vector vecTracerDir = vecDir;
vecTracerDir.x += random->RandomFloat( -0.3, 0.3 );
vecTracerDir.y += random->RandomFloat( -0.3, 0.3 );
vecTracerDir.z += random->RandomFloat( -0.3, 0.3 );
vecTracerDir = vecTracerDir * -512;
Vector vEndPos = ptr->endpos + vecTracerDir;
UTIL_Tracer( ptr->endpos, vEndPos, ENTINDEX( edict() ) );
}
flDamage -= 20;
if (flDamage <= 0)
flDamage = 0.1;// don't hurt the monster much, but allow bits_COND_LIGHT_DAMAGE to be generated
ainfo.SetDamage( flDamage );
}
else
{
SpawnBlood( ptr->endpos, vecDir, BloodColor(), flDamage);// a little surface blood.
TraceBleed( flDamage, vecDir, ptr, ainfo.GetDamageType() );
}
AddMultiDamage( ainfo, this );
}
//=========================================================
// AI Schedules Specific to this monster
//=========================================================
AI_BEGIN_CUSTOM_NPC( monster_alien_grunt, CNPC_AlienGrunt )
DECLARE_ACTIVITY( ACT_THREAT_DISPLAY )
DECLARE_TASK ( TASK_AGRUNT_SETUP_HIDE_ATTACK )
DECLARE_TASK ( TASK_AGRUNT_GET_PATH_TO_ENEMY_CORPSE )
DECLARE_TASK ( TASK_AGRUNT_RANGE_ATTACK1_NOTURN )
DECLARE_SQUADSLOT( AGRUNT_SQUAD_SLOT_HORNET1 )
DECLARE_SQUADSLOT( AGRUNT_SQUAD_SLOT_HORNET2 )
DECLARE_SQUADSLOT( AGRUNT_SQUAD_SLOT_CHASE )
//=========================================================
// Fail Schedule
//=========================================================
DEFINE_SCHEDULE
(
SCHED_AGRUNT_FAIL,
" Tasks"
" TASK_STOP_MOVING 0"
" TASK_SET_ACTIVITY ACTIVITY:ACT_IDLE"
" TASK_WAIT 2"
" TASK_WAIT_PVS 0"
" "
" Interrupts"
" COND_CAN_RANGE_ATTACK1"
" COND_CAN_MELEE_ATTACK1"
)
//=========================================================
// Combat Fail Schedule
//=========================================================
DEFINE_SCHEDULE
(
SCHED_AGRUNT_COMBAT_FAIL,
" Tasks"
" TASK_STOP_MOVING 0"
" TASK_SET_ACTIVITY ACTIVITY:ACT_IDLE"
" TASK_WAIT_FACE_ENEMY 2"
" TASK_WAIT_PVS 0"
" "
" Interrupts"
" COND_CAN_RANGE_ATTACK1"
" COND_CAN_MELEE_ATTACK1"
)
//=========================================================
// Standoff schedule. Used in combat when a monster is
// hiding in cover or the enemy has moved out of sight.
// Should we look around in this schedule?
//=========================================================
DEFINE_SCHEDULE
(
SCHED_AGRUNT_STANDOFF,
" Tasks"
" TASK_STOP_MOVING 0"
" TASK_SET_ACTIVITY ACTIVITY:ACT_IDLE"
" TASK_WAIT_FACE_ENEMY 2"
" "
" Interrupts"
" COND_CAN_RANGE_ATTACK1"
" COND_CAN_MELEE_ATTACK1"
" COND_SEE_ENEMY"
" COND_NEW_ENEMY"
" COND_HEAR_DANGER"
)
//=========================================================
// Suppress
//=========================================================
DEFINE_SCHEDULE
(
SCHED_AGRUNT_SUPPRESS_HORNET,
" Tasks"
" TASK_STOP_MOVING 0"
" TASK_RANGE_ATTACK1 0"
)
//=========================================================
// primary range attacks
//=========================================================
DEFINE_SCHEDULE
(
SCHED_AGRUNT_RANGE_ATTACK,
" Tasks"
" TASK_STOP_MOVING 0"
" TASK_FACE_ENEMY 0"
" TASK_RANGE_ATTACK1 0"
" "
" Interrupts"
" COND_NEW_ENEMY"
" COND_ENEMY_DEAD"
" COND_HEAVY_DAMAGE"
)
DEFINE_SCHEDULE
(
SCHED_AGRUNT_HIDDEN_RANGE_ATTACK,
" Tasks"
" TASK_SET_FAIL_SCHEDULE SCHEDULE:SCHED_AGRUNT_STANDOFF"
" TASK_AGRUNT_SETUP_HIDE_ATTACK 0"
" TASK_STOP_MOVING 0"
" TASK_FACE_IDEAL 0"
" TASK_AGRUNT_RANGE_ATTACK1_NOTURN 0"
" "
" Interrupts"
" COND_NEW_ENEMY"
" COND_HEAVY_DAMAGE"
" COND_HEAR_DANGER"
)
//=========================================================
// Take cover from enemy! Tries lateral cover before node
// cover!
//=========================================================
DEFINE_SCHEDULE
(
SCHED_AGRUNT_TAKE_COVER_FROM_ENEMY,
" Tasks"
" TASK_STOP_MOVING 0"
" TASK_WAIT 0.2"
" TASK_FIND_COVER_FROM_ENEMY 0"
" TASK_RUN_PATH 0"
" TASK_WAIT_FOR_MOVEMENT 0"
" TASK_REMEMBER MEMORY:INCOVER"
" TASK_FACE_ENEMY 0"
" "
" Interrupts"
" COND_NEW_ENEMY"
)
//=========================================================
// Victory dance!
//=========================================================
DEFINE_SCHEDULE
(
SCHED_AGRUNT_VICTORY_DANCE,
" Tasks"
" TASK_STOP_MOVING 0"
" TASK_SET_FAIL_SCHEDULE SCHEDULE:SCHED_AGRUNT_THREAT_DISPLAY"
" TASK_WAIT 0.2"
" TASK_AGRUNT_GET_PATH_TO_ENEMY_CORPSE 0"
" TASK_WALK_PATH 0"
" TASK_WAIT_FOR_MOVEMENT 0"
" TASK_FACE_ENEMY 0"
" TASK_PLAY_SEQUENCE ACTIVITY:ACT_CROUCH"
" TASK_PLAY_SEQUENCE ACTIVITY:ACT_VICTORY_DANCE"
" TASK_PLAY_SEQUENCE ACTIVITY:ACT_VICTORY_DANCE"
" TASK_PLAY_SEQUENCE ACTIVITY:ACT_STAND"
" TASK_PLAY_SEQUENCE ACTIVITY:ACT_THREAT_DISPLAY"
" TASK_PLAY_SEQUENCE ACTIVITY:ACT_CROUCH"
" TASK_PLAY_SEQUENCE ACTIVITY:ACT_VICTORY_DANCE"
" TASK_PLAY_SEQUENCE ACTIVITY:ACT_VICTORY_DANCE"
" TASK_PLAY_SEQUENCE ACTIVITY:ACT_VICTORY_DANCE"
" TASK_PLAY_SEQUENCE ACTIVITY:ACT_VICTORY_DANCE"
" TASK_PLAY_SEQUENCE ACTIVITY:ACT_VICTORY_DANCE"
" TASK_PLAY_SEQUENCE ACTIVITY:ACT_STAND"
" "
" Interrupts"
" COND_NEW_ENEMY"
" COND_LIGHT_DAMAGE"
" COND_HEAVY_DAMAGE"
)
//=========================================================
//=========================================================
DEFINE_SCHEDULE
(
SCHED_AGRUNT_THREAT_DISPLAY,
" Tasks"
" TASK_STOP_MOVING 0"
" TASK_FACE_ENEMY 0"
" TASK_PLAY_SEQUENCE ACTIVITY:ACT_THREAT_DISPLAY"
" "
" Interrupts"
" COND_NEW_ENEMY"
" COND_LIGHT_DAMAGE"
" COND_HEAVY_DAMAGE"
" COND_HEAR_PLAYER"
" COND_HEAR_COMBAT"
" COND_HEAR_WORLD"
)
AI_END_CUSTOM_NPC()
|