-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathasw_inhabitable_npc.cpp
More file actions
1010 lines (846 loc) · 29.6 KB
/
Copy pathasw_inhabitable_npc.cpp
File metadata and controls
1010 lines (846 loc) · 29.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "cbase.h"
#include "asw_inhabitable_npc.h"
#include "asw_alien_classes.h"
#include "asw_player.h"
#include "asw_weapon.h"
#include "env_tonemap_controller.h"
#include "asw_burning.h"
#include "asw_gamerules.h"
#include "asw_marine.h"
#include "asw_gamestats.h"
#include "asw_director.h"
#include "asw_base_spawner.h"
#include "asw_physics_prop_statue.h"
#include "asw_util_shared.h"
#include "ilagcompensationmanager.h"
#include "asw_marine_resource.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
#define NPC_DEBUG_OVERLAY_FLAGS (OVERLAY_NPC_ROUTE_BIT | OVERLAY_BBOX_BIT | OVERLAY_PIVOT_BIT | OVERLAY_TASK_TEXT_BIT | OVERLAY_TEXT_BIT)
static void DebugNPCsChanged( IConVar *var, const char *pOldValue, float flOldValue );
ConVar asw_debug_npcs( "asw_debug_npcs", "0", FCVAR_CHEAT, "Enables debug overlays for various NPCs", DebugNPCsChanged );
ConVar asw_burning_alien_damage_scale( "asw_burning_alien_damage_scale", "1.0", FCVAR_CHEAT );
ConVar asw_burning_alien_damage_scale_melee( "asw_burning_alien_damage_scale_melee", "1.0", FCVAR_CHEAT );
ConVar asw_frozen_alien_damage_scale( "asw_frozen_alien_damage_scale", "1.0", FCVAR_CHEAT );
ConVar asw_frozen_alien_damage_scale_melee( "asw_frozen_alien_damage_scale_melee", "2.0", FCVAR_CHEAT );
ConVar asw_alien_burn_duration( "asw_alien_burn_duration", "5.0", FCVAR_CHEAT, "Alien burn time" );
extern ConVar asw_alien_stunned_speed;
extern ConVar asw_alien_hurt_speed;
extern ConVar asw_stun_grenade_time;
extern ConVar asw_controls;
extern ConVar asw_debug_alien_damage;
extern ConVar rd_use_full_lag_compensation;
extern ConVar rd_burning_interval;
extern ConVar rd_burning_alien_damage;
extern ConVar rd_burning_humanoid_damage;
static void DebugNPCsChanged( IConVar *var, const char *pOldValue, float flOldValue )
{
// don't do anything if sv_cheats isn't on
if ( !ConVarRef( "sv_cheats" ).GetBool() )
return;
bool bSetOverlays = asw_debug_npcs.GetBool();
for ( CBaseEntity *pEnt = gEntList.FirstEnt(); pEnt; pEnt = gEntList.NextEnt( pEnt ) )
{
if ( !pEnt->IsInhabitableNPC() )
continue;
if ( bSetOverlays )
pEnt->m_debugOverlays |= NPC_DEBUG_OVERLAY_FLAGS;
else
pEnt->m_debugOverlays &= ~NPC_DEBUG_OVERLAY_FLAGS;
}
}
LINK_ENTITY_TO_CLASS( funCASW_Inhabitable_NPC, CASW_Inhabitable_NPC );
IMPLEMENT_SERVERCLASS_ST( CASW_Inhabitable_NPC, DT_ASW_Inhabitable_NPC )
SendPropEHandle( SENDINFO( m_Commander ) ),
SendPropEHandle( SENDINFO( m_hUsingEntity ) ),
SendPropVector( SENDINFO( m_vecFacingPointFromServer ), 0, SPROP_NOSCALE ),
SendPropBool( SENDINFO( m_bInhabited ) ),
SendPropBool( SENDINFO( m_bWalking ) ),
SendPropIntWithMinusOneFlag( SENDINFO( m_iControlsOverride ) ),
SendPropInt( SENDINFO( m_iHealth ), ASW_ALIEN_HEALTH_BITS, SPROP_CHANGES_OFTEN ),
SendPropInt( SENDINFO( m_iMaxHealth ), ASW_ALIEN_HEALTH_BITS ),
#if PREDICTION_ERROR_CHECK_LEVEL > 1
SendPropVector( SENDINFO( m_vecBaseVelocity ), -1, SPROP_COORD ),
#else
SendPropVector( SENDINFO( m_vecBaseVelocity ), 20, 0, -1000, 1000 ),
#endif
SendPropBool( SENDINFO( m_bElectroStunned ) ),
SendPropBool( SENDINFO( m_bOnFire ) ),
SendPropFloat( SENDINFO( m_fSpeedScale ) ),
SendPropTime( SENDINFO( m_fHurtSlowMoveTime ) ),
SendPropVector( SENDINFO( m_vecGlowColor ), 10, 0, 0, 1 ),
SendPropFloat( SENDINFO( m_flGlowAlpha ), 8, 0, 0, 1 ),
SendPropBool( SENDINFO( m_bGlowWhenOccluded ) ),
SendPropBool( SENDINFO( m_bGlowWhenUnoccluded ) ),
SendPropBool( SENDINFO( m_bGlowFullBloom ) ),
SendPropInt( SENDINFO( m_iAlienClassIndex ), NumBitsForCount( MAX( NELEMS( g_Aliens ), NELEMS( g_NonSpawnableAliens ) + 2 ) ) + 1 ),
SendPropInt( SENDINFO( m_rgbaHealthBarColor ), 32, SPROP_UNSIGNED, SendProxy_Color32ToInt32 ),
SendPropFloat( SENDINFO( m_flHealthBarScale ) ),
SendPropVector( SENDINFO( m_vecHealthBarOffset ) ),
END_SEND_TABLE()
BEGIN_DATADESC( CASW_Inhabitable_NPC )
DEFINE_FIELD( m_Commander, FIELD_EHANDLE ),
DEFINE_FIELD( m_hUsingEntity, FIELD_EHANDLE ),
DEFINE_FIELD( m_vecFacingPointFromServer, FIELD_VECTOR ),
DEFINE_FIELD( m_nOldButtons, FIELD_INTEGER ),
DEFINE_FIELD( m_hFogController, FIELD_EHANDLE ),
DEFINE_FIELD( m_hPostProcessController, FIELD_EHANDLE ),
DEFINE_FIELD( m_hColorCorrection, FIELD_EHANDLE ),
DEFINE_FIELD( m_hTonemapController, FIELD_EHANDLE ),
DEFINE_FIELD( m_iControlsOverride, FIELD_INTEGER ),
DEFINE_FIELD( m_iAlienClassIndex, FIELD_INTEGER ),
DEFINE_FIELD( m_hSpawner, FIELD_EHANDLE ),
DEFINE_FIELD( m_bOnFire, FIELD_BOOLEAN ),
DEFINE_FIELD( m_fHurtSlowMoveTime, FIELD_TIME ),
DEFINE_FIELD( m_flElectroStunSlowMoveTime, FIELD_TIME ),
DEFINE_FIELD( m_bElectroStunned, FIELD_BOOLEAN ),
DEFINE_FIELD( m_fNextStunSound, FIELD_FLOAT ),
DEFINE_FIELD( m_bIgnoreMarines, FIELD_BOOLEAN ),
DEFINE_FIELD( m_AlienOrders, FIELD_INTEGER ),
DEFINE_FIELD( m_vecAlienOrderSpot, FIELD_POSITION_VECTOR ),
DEFINE_FIELD( m_AlienOrderObject, FIELD_EHANDLE ),
DEFINE_FIELD( m_bHoldoutAlien, FIELD_BOOLEAN ),
DEFINE_FIELD( m_flFrozenTime, FIELD_TIME ),
DEFINE_KEYFIELD( m_bFlammable, FIELD_BOOLEAN, "flammable" ),
DEFINE_KEYFIELD( m_bTeslable, FIELD_BOOLEAN, "teslable" ),
DEFINE_KEYFIELD( m_bFreezable, FIELD_BOOLEAN, "freezable" ),
DEFINE_KEYFIELD( m_flFreezeResistance, FIELD_FLOAT, "freezeresistance" ),
DEFINE_KEYFIELD( m_bFlinchable, FIELD_BOOLEAN, "flinchable" ),
DEFINE_KEYFIELD( m_bGrenadeReflector, FIELD_BOOLEAN, "reflector" ),
DEFINE_KEYFIELD( m_iHealthBonus, FIELD_INTEGER, "healthbonus" ),
DEFINE_KEYFIELD( m_fSizeScale, FIELD_FLOAT, "sizescale" ),
DEFINE_KEYFIELD( m_fSpeedScale, FIELD_FLOAT, "speedscale" ),
DEFINE_INPUT( m_rgbaHealthBarColor, FIELD_COLOR32, "SetHealthBarColor" ),
DEFINE_INPUT( m_flHealthBarScale, FIELD_FLOAT, "SetHealthBarScale" ),
DEFINE_INPUT( m_vecHealthBarOffset, FIELD_VECTOR, "SetHealthBarOffset" ),
END_DATADESC()
BEGIN_ENT_SCRIPTDESC( CASW_Inhabitable_NPC, CBaseCombatCharacter, "Alien Swarm Inhabitable NPC" )
DEFINE_SCRIPTFUNC( IsInhabited, "Returns true if a player is controlling this character, false if it is AI-controlled." )
DEFINE_SCRIPTFUNC_NAMED( ScriptGetCommander, "GetCommander", "Get the player entity that is \"owns\" this character, eg. the player that is playing this marine or added this marine bot to the lobby." )
DEFINE_SCRIPTFUNC_NAMED( ScriptSetControls, "SetControls", "Force this character to use a specific value for asw_controls." )
DEFINE_SCRIPTFUNC_NAMED( ScriptSetFogController, "SetFogController", "Force this character to use a specific env_fog_controller." )
DEFINE_SCRIPTFUNC_NAMED( ScriptSetPostProcessController, "SetPostProcessController", "Force this character to use a specific postprocess_controller." )
DEFINE_SCRIPTFUNC_NAMED( ScriptSetColorCorrection, "SetColorCorrection", "Force this character to use a specific color_correction." )
DEFINE_SCRIPTFUNC_NAMED( ScriptSetTonemapController, "SetTonemapController", "Force this character to use a specific env_tonemap_controller." )
DEFINE_SCRIPTFUNC_NAMED( ScriptSetGlow, "SetGlow", "Make this character glow when occluded or when unoccluded. Does not affect cases where the character would glow due to built-in game logic." )
DEFINE_SCRIPTFUNC_NAMED( ClearAlienOrders, "ClearOrders", "clear the alien's orders" )
DEFINE_SCRIPTFUNC_NAMED( ScriptOrderMoveTo, "OrderMoveTo", "order the alien to move to an entity handle, second parameter ignore marines" )
DEFINE_SCRIPTFUNC_NAMED( ScriptChaseNearestMarine, "ChaseNearestMarine", "order the alien to chase the nearest marine" )
DEFINE_SCRIPTFUNC( Extinguish, "Extinguish a burning alien." )
DEFINE_SCRIPTFUNC_NAMED( ScriptIgnite, "Ignite", "Ignites the alien into flames." )
DEFINE_SCRIPTFUNC( Thaw, "Thaws a frozen alien." )
DEFINE_SCRIPTFUNC_NAMED( ScriptFreeze, "Freeze", "Freezes the alien." )
DEFINE_SCRIPTFUNC_NAMED( ScriptElectroStun, "ElectroStun", "Stuns the alien." )
DEFINE_SCRIPTFUNC( Wake, "Wake up the alien." )
DEFINE_SCRIPTFUNC( SetSpawnZombineOnMarineKill, "Used to spawn a zombine in the place of a killed marine." )
DEFINE_SCRIPTFUNC( SetHealthBarColor, "Sets the health bar color. Cheaper than spawning an asw_health_bar. Set alpha to 0 to disable the health bar." )
DEFINE_SCRIPTFUNC( SetHealthBarScale, "Sets the health bar scale. Negative scales hide the health bar if the alien's health is full." )
DEFINE_SCRIPTFUNC( SetHealthBarOffset, "Sets the health bar offset in local space." )
DEFINE_SCRIPTFUNC( Die, "Simple kill function for aliens and marines." )
END_SCRIPTDESC()
CASW_Inhabitable_NPC::CASW_Inhabitable_NPC()
{
m_nOldButtons = 0;
m_iControlsOverride = -1;
m_fLastMarineCanSeeTime = -100;
m_bLastMarineCanSee = false;
m_bWasOnFireForStats = false;
m_bFlammable = true;
m_bTeslable = true;
m_bFreezable = true;
m_flFreezeResistance = 0.0f;
m_bFlinchable = true;
m_bGrenadeReflector = false;
m_iHealthBonus = 0;
m_fSizeScale = 1.0f;
m_fSpeedScale = 1.0f;
m_fHurtSlowMoveTime = 0;
m_flElectroStunSlowMoveTime = 0;
m_hSpawner = NULL;
m_AlienOrders = AOT_None;
m_vecAlienOrderSpot = vec3_origin;
m_AlienOrderObject = NULL;
m_bIgnoreMarines = false;
m_flBaseThawRate = 0.5f;
m_flFrozenTime = 0.0f;
m_bSpawnZombineOnMarineKill = false;
m_vecGlowColor.Init( 1, 1, 1 );
m_flGlowAlpha = 1;
m_bGlowWhenOccluded = false;
m_bGlowWhenUnoccluded = false;
m_bGlowFullBloom = false;
*m_rgbaHealthBarColor.GetForModify().asInt() = 0;
m_flHealthBarScale = 1.0f;
m_vecHealthBarOffset = vec3_origin;
}
CASW_Inhabitable_NPC::~CASW_Inhabitable_NPC()
{
}
void CASW_Inhabitable_NPC::Precache()
{
BaseClass::Precache();
PrecacheScriptSound( "ASW_Tesla_Laser.Damage" );
}
void CASW_Inhabitable_NPC::Spawn()
{
BaseClass::Spawn();
if ( m_SquadName != NULL_STRING )
{
CapabilitiesAdd( bits_CAP_SQUAD );
}
SetModelScale( m_fSizeScale );
SetHealthByDifficultyLevel();
m_iAlienClassIndex = GetAlienClassIndex( this );
}
void CASW_Inhabitable_NPC::OnRestore()
{
BaseClass::OnRestore();
m_LagCompensation.Init( this );
if ( rd_use_full_lag_compensation.GetBool() )
{
lagcompensation->AddAdditionalEntity( this );
}
}
void CASW_Inhabitable_NPC::NPCInit()
{
BaseClass::NPCInit();
if ( asw_debug_npcs.GetBool() )
{
m_debugOverlays |= NPC_DEBUG_OVERLAY_FLAGS;
}
m_LagCompensation.Init( this );
if ( rd_use_full_lag_compensation.GetBool() )
{
lagcompensation->AddAdditionalEntity( this );
}
}
void CASW_Inhabitable_NPC::NPCThink()
{
BaseClass::NPCThink();
// stop electro stunning if we're slowed
if ( m_bElectroStunned && m_lifeState != LIFE_DYING )
{
if ( m_flElectroStunSlowMoveTime < gpGlobals->curtime )
{
m_bElectroStunned = false;
}
else
{
if ( gpGlobals->curtime >= m_fNextStunSound )
{
m_fNextStunSound = gpGlobals->curtime + RandomFloat( 0.2f, 0.5f );
EmitSound( "ASW_Tesla_Laser.Damage" );
}
}
}
if ( gpGlobals->maxClients > 1 )
m_LagCompensation.StorePositionHistory();
UpdateThawRate();
}
void CASW_Inhabitable_NPC::UpdateOnRemove()
{
BaseClass::UpdateOnRemove();
lagcompensation->RemoveAdditionalEntity( this );
}
int CASW_Inhabitable_NPC::DrawDebugTextOverlays()
{
int text_offset = BaseClass::DrawDebugTextOverlays();
if ( m_debugOverlays & OVERLAY_TEXT_BIT )
{
NDebugOverlay::EntityText( entindex(), text_offset, CFmtStr( "Freeze amt.: %f", m_flFrozen.Get() ), 0 );
text_offset++;
NDebugOverlay::EntityText( entindex(), text_offset, CFmtStr( "Freeze time: %f", MAX( m_flFrozenTime - gpGlobals->curtime, 0.0f ) ), 0 );
text_offset++;
}
return text_offset;
}
bool CASW_Inhabitable_NPC::MarineNearby( float radius, bool bCheck3D )
{
// find the closest marine
CASW_Game_Resource* pGameResource = ASWGameResource();
if ( !pGameResource )
return false;
for ( int i = 0; i < pGameResource->GetMaxMarineResources(); i++ )
{
CASW_Marine_Resource* pMarineResource = pGameResource->GetMarineResource( i );
if ( !pMarineResource )
continue;
CASW_Marine* pMarine = pMarineResource->GetMarineEntity();
if ( !pMarine || pMarine->m_bKnockedOut )
continue;
Vector diff = pMarine->GetAbsOrigin() - GetAbsOrigin();
float dist = bCheck3D ? diff.Length() : diff.Length2D();
if ( dist < radius )
{
return true;
}
}
return false;
}
// checks if a marine can see us
// caches the results and won't recheck unless the specified interval has passed since the last check
bool CASW_Inhabitable_NPC::MarineCanSee( int padding, float interval )
{
if ( gpGlobals->curtime >= m_fLastMarineCanSeeTime + interval )
{
bool bCorpseCanSee = false;
m_bLastMarineCanSee = ( UTIL_ASW_AnyMarineCanSee( GetAbsOrigin(), padding, bCorpseCanSee ) != NULL ) || bCorpseCanSee;
m_fLastMarineCanSeeTime = gpGlobals->curtime;
}
return m_bLastMarineCanSee;
}
// sets which player commands this marine
void CASW_Inhabitable_NPC::SetCommander( CASW_Player *player )
{
if ( m_Commander.Get() == player )
{
return;
}
m_Commander = player;
if ( player )
{
player->OnNPCCommanded( this );
}
}
HSCRIPT CASW_Inhabitable_NPC::ScriptGetCommander() const
{
return ToHScript( GetCommander() );
}
// store ASWNetworkID of first commander
void CASW_Inhabitable_NPC::SetInitialCommander( CASW_Player *player )
{
V_strncpy( m_szInitialCommanderNetworkID, player ? player->GetASWNetworkID() : "None", sizeof( m_szInitialCommanderNetworkID ) );
DevMsg( " %s %d:%s SetInitialCommander id to %s\n", GetClassname(), entindex(), GetEntityNameAsCStr(), m_szInitialCommanderNetworkID );
}
const char *CASW_Inhabitable_NPC::GetPlayerName() const
{
CASW_Player *pPlayer = GetCommander();
if ( !pPlayer )
{
return BaseClass::GetPlayerName();
}
return pPlayer->GetPlayerName();
}
void CASW_Inhabitable_NPC::Suicide()
{
if ( GetFlags() & FL_FROZEN ) // don't allow this if the marine is frozen
return;
m_iHealth = 1;
CTakeDamageInfo info( this, this, Vector( 0, 0, 0 ), GetAbsOrigin(), 100, DMG_NEVERGIB );
TakeDamage( info );
}
void CASW_Inhabitable_NPC::Die()
{
if ( !IsAlive() )
return;
SetHealth( 1 );
CTakeDamageInfo info( NULL, NULL, 100, DMG_FALL );
info.SetCallVScriptHook( false );
TakeDamage( info );
}
// using entities over time
bool CASW_Inhabitable_NPC::StartUsing( CBaseEntity *pEntity )
{
if ( GetHealth() <= 0 )
return false;
IASW_Server_Usable_Entity *pUsable = dynamic_cast< IASW_Server_Usable_Entity * >( pEntity );
if ( pUsable )
{
if ( !pUsable->IsUsable( this ) )
return false;
if ( !pUsable->RequirementsMet( this ) )
return false;
pUsable->NPCStartedUsing( this );
m_hUsingEntity = pEntity;
return true;
}
return false;
}
void CASW_Inhabitable_NPC::StopUsing()
{
if ( !m_hUsingEntity )
return;
IASW_Server_Usable_Entity *pUsable = dynamic_cast< IASW_Server_Usable_Entity * >( m_hUsingEntity.Get() );
if ( pUsable )
{
pUsable->NPCStoppedUsing( this );
}
m_hUsingEntity = NULL;
}
// forces marine to look towards a certain point
void CASW_Inhabitable_NPC::SetFacingPoint( const Vector &vec, float fDuration )
{
m_vecFacingPointFromServer = vec;
m_fStopFacingPointTime = gpGlobals->curtime + fDuration;
}
int CASW_Inhabitable_NPC::TranslateSchedule( int scheduleType )
{
// skip CAI_PlayerAlly as it makes enemies back up when they hit an obstacle
return CAI_BaseActor::TranslateSchedule( scheduleType );
}
float CASW_Inhabitable_NPC::GetIdealSpeed() const
{
if ( const_cast< CASW_Inhabitable_NPC * >( this )->IsMovementFrozen() )
{
return 0.0f;
}
float flBaseSpeed = BaseClass::GetIdealSpeed() * m_fSpeedScale;
// if the alien is hurt, move slower
if ( ShouldMoveSlow() )
{
if ( m_bElectroStunned.Get() )
{
return flBaseSpeed * asw_alien_stunned_speed.GetFloat();
}
else
{
return flBaseSpeed * asw_alien_hurt_speed.GetFloat();
}
}
return flBaseSpeed;
}
bool CASW_Inhabitable_NPC::ModifyAutoMovement( Vector &vecNewPos )
{
float fFactor = 1.0f;
if ( ShouldMoveSlow() )
{
if ( m_bElectroStunned.Get() )
{
fFactor *= asw_alien_stunned_speed.GetFloat() * 0.1f;
}
else
{
fFactor *= asw_alien_hurt_speed.GetFloat() * 0.1f;
}
Vector vecRelPos = vecNewPos - GetAbsOrigin();
vecRelPos *= fFactor;
vecNewPos = GetAbsOrigin() + vecRelPos;
return true;
}
return false;
}
bool CASW_Inhabitable_NPC::OverrideMove( float flInterval )
{
if ( IsMovementFrozen() )
{
SetAbsVelocity( vec3_origin );
GetMotor()->SetMoveVel( vec3_origin );
return true;
}
return BaseClass::OverrideMove( flInterval );
}
void CASW_Inhabitable_NPC::ScriptSetControls( int iControls )
{
m_iControlsOverride = MAX( -1, iControls );
// trigger control scheme update callback
asw_controls.SetValue( asw_controls.GetString() );
}
#define IMPLEMENT_SCRIPT_SET_CONTROLLER_ENT_FUNC( FuncName, EntityClass, MemberVariable, HammerClassName ) \
void CASW_Inhabitable_NPC::FuncName( HSCRIPT hEnt ) \
{ \
CBaseEntity *pEnt = ToEnt( hEnt ); \
if ( !pEnt ) \
{ \
MemberVariable = NULL; \
return; \
} \
\
EntityClass *pController = dynamic_cast< EntityClass * >( pEnt ); \
if ( !pController ) \
{ \
Warning( "[%s] " #FuncName " called with an entity that was not " #HammerClassName ".\n", GetDebugName() ); \
return; \
} \
\
MemberVariable = pController; \
}
IMPLEMENT_SCRIPT_SET_CONTROLLER_ENT_FUNC( ScriptSetFogController, CFogController, m_hFogController, env_fog_controller )
IMPLEMENT_SCRIPT_SET_CONTROLLER_ENT_FUNC( ScriptSetPostProcessController, CPostProcessController, m_hPostProcessController, postprocess_controller )
IMPLEMENT_SCRIPT_SET_CONTROLLER_ENT_FUNC( ScriptSetColorCorrection, CColorCorrection, m_hColorCorrection, color_correction )
IMPLEMENT_SCRIPT_SET_CONTROLLER_ENT_FUNC( ScriptSetTonemapController, CEnvTonemapController, m_hTonemapController, env_tonemap_controller )
void CASW_Inhabitable_NPC::OnTonemapTriggerStartTouch( CTonemapTrigger *pTonemapTrigger )
{
m_hTriggerTonemapList.FindAndRemove( pTonemapTrigger );
m_hTriggerTonemapList.AddToTail( pTonemapTrigger );
}
void CASW_Inhabitable_NPC::OnTonemapTriggerEndTouch( CTonemapTrigger *pTonemapTrigger )
{
m_hTriggerTonemapList.FindAndRemove( pTonemapTrigger );
}
void CASW_Inhabitable_NPC::ScriptSetGlow( Vector vecColor, float flAlpha, bool bGlowWhenOccluded, bool bGlowWhenUnoccluded, bool bFullBloom )
{
m_vecGlowColor = vecColor;
m_flGlowAlpha = flAlpha;
m_bGlowWhenOccluded = bGlowWhenOccluded;
m_bGlowWhenUnoccluded = bGlowWhenUnoccluded;
m_bGlowFullBloom = bFullBloom;
}
void CASW_Inhabitable_NPC::DoImpactEffect( trace_t &tr, int nDamageType )
{
// don't do impact effects, they're simulated clientside by the tracer usermessage
}
void CASW_Inhabitable_NPC::DoMuzzleFlash()
{
// asw - muzzle flashes are triggered by tracer usermessages instead to save bandwidth
}
void CASW_Inhabitable_NPC::MakeTracer( const Vector &vecTracerSrc, const trace_t &tr, int iTracerType, int iDamageType )
{
const char *tracer = "ASWUTracer";
if ( GetActiveASWWeapon() )
tracer = GetActiveASWWeapon()->GetUTracerType();
CRecipientFilter filter;
filter.AddAllPlayers();
if ( IsInhabited() )
{
filter.UsePredictionRules();
}
int iDamageAtt = ( iDamageType & DMG_BUCKSHOT ) ? BULLET_ATT_TRACER_BUCKSHOT : 0;
UserMessageBegin( filter, tracer );
WRITE_SHORT( entindex() );
WRITE_FLOAT( tr.endpos.x );
WRITE_FLOAT( tr.endpos.y );
WRITE_FLOAT( tr.endpos.z );
WRITE_SHORT( m_iDamageAttributeEffects | iDamageAtt );
MessageEnd();
}
void CASW_Inhabitable_NPC::MakeUnattachedTracer( const Vector &vecTracerSrc, const trace_t &tr, int iTracerType, int iDamageType )
{
const char *tracer = "ASWUTracerUnattached";
CRecipientFilter filter;
filter.AddAllPlayers();
if ( IsInhabited() )
{
filter.UsePredictionRules();
}
int iDamageAtt = ( iDamageType & DMG_BUCKSHOT ) ? BULLET_ATT_TRACER_BUCKSHOT : 0;
UserMessageBegin( filter, tracer );
WRITE_SHORT( entindex() );
WRITE_FLOAT( tr.endpos.x );
WRITE_FLOAT( tr.endpos.y );
WRITE_FLOAT( tr.endpos.z );
WRITE_FLOAT( vecTracerSrc.x );
WRITE_FLOAT( vecTracerSrc.y );
WRITE_FLOAT( vecTracerSrc.z );
WRITE_SHORT( m_iDamageAttributeEffects | iDamageAtt );
MessageEnd();
}
// marines override this
void CASW_Inhabitable_NPC::InhabitedPhysicsSimulate()
{
BaseClass::PhysicsSimulate();
CASW_Weapon *pWeapon = GetActiveASWWeapon();
if ( pWeapon )
pWeapon->ItemPostFrame();
// check if offhand weapon needs postframe
CASW_Weapon *pExtra = GetASWWeapon( ASW_INVENTORY_SLOT_EXTRA );
if ( pExtra && pExtra != pWeapon && pExtra->m_bShotDelayed )
{
pExtra->ItemPostFrame();
}
}
void CASW_Inhabitable_NPC::PhysicsSimulate()
{
if ( IsInhabited() )
{
InhabitedPhysicsSimulate();
return;
}
BaseClass::PhysicsSimulate();
CASW_Weapon *pWeapon = GetActiveASWWeapon();
if ( pWeapon )
pWeapon->ItemPostFrame();
// check if offhand weapon needs postframe
CASW_Weapon *pExtra = GetASWWeapon( ASW_INVENTORY_SLOT_EXTRA );
if ( pExtra && pExtra != pWeapon && pExtra->m_bShotDelayed )
{
pExtra->ItemPostFrame();
}
}
void CASW_Inhabitable_NPC::SetHealth( int amt )
{
Assert( amt < ( 1 << ASW_ALIEN_HEALTH_BITS ) || Classify() == CLASS_ASW_QUEEN );
BaseClass::SetHealth( amt );
}
void CASW_Inhabitable_NPC::SetHealthByDifficultyLevel()
{
Assert( ASWGameRules() );
int iHealth = GetBaseHealth();
iHealth = MAX( 1, ASWGameRules()->ModifyAlienHealthBySkillLevel( iHealth ) );
if ( asw_debug_alien_damage.GetBool() )
Msg( "Setting %s's initial health to %d\n", GetClassname(), iHealth + m_iHealthBonus );
SetHealth( iHealth + m_iHealthBonus );
SetMaxHealth( iHealth + m_iHealthBonus );
}
int CASW_Inhabitable_NPC::OnTakeDamage_Alive( const CTakeDamageInfo &info )
{
int iHealthBefore = GetHealth();
CTakeDamageInfo newInfo = info;
int result = 0;
CBaseEntity *pAttacker = info.GetAttacker();
if ( Classify() == CLASS_ASW_MARINE )
{
// marine doesn't want any of this handling, but does want hit confirms
result = BaseClass::OnTakeDamage_Alive( info );
}
else
{
CASW_Burning *pBurning = NULL;
CBaseEntity *pInflictor = info.GetInflictor();
if ( ( info.GetDamageType() & DMG_DIRECT ) && ( IsFrozen() || IsOnFire() ) )
{
bool bIsMelee = ( newInfo.GetDamageType() & DMG_SLASH ) || ( newInfo.GetDamageType() & DMG_CLUB );
ConVar *pIce = bIsMelee ? &asw_frozen_alien_damage_scale_melee : &asw_frozen_alien_damage_scale;
ConVar *pFire = bIsMelee ? &asw_burning_alien_damage_scale_melee : &asw_burning_alien_damage_scale;
ConVar *pScale = pIce;
if ( !IsFrozen() )
{
pScale = pFire;
}
else if ( IsOnFire() )
{
pScale = pIce->GetFloat() > pFire->GetFloat() ? pIce : pFire;
}
newInfo.ScaleDamage( pScale->GetFloat() );
if ( asw_debug_alien_damage.GetBool() )
{
Msg( "%d %s hurt by %f dmg (scaled up by %s)\n", entindex(), GetClassname(), newInfo.GetDamage(), pScale->GetName() );
}
}
else
{
if ( asw_debug_alien_damage.GetBool() )
{
Msg( "%d %s hurt by %f dmg\n", entindex(), GetClassname(), newInfo.GetDamage() );
}
}
result = BaseClass::OnTakeDamage_Alive( newInfo );
// if we take fire damage (but not afterburn damage), catch on fire
if ( result > 0 && ( newInfo.GetDamageType() & DMG_BURN ) && m_bFlammable && newInfo.GetWeapon() && !( newInfo.GetDamageType() & DMG_DIRECT ) )
{
ASW_Ignite( asw_alien_burn_duration.GetFloat(), 0, pAttacker, newInfo.GetWeapon(), newInfo.GetInflictor() );
}
// make the alien move slower for 0.5 seconds
if ( ( newInfo.GetDamageType() & DMG_SHOCK ) && m_bTeslable )
{
ElectroStun( asw_stun_grenade_time.GetFloat() );
m_fNoDamageDecal = true;
}
else
{
if ( m_fHurtSlowMoveTime < gpGlobals->curtime + 0.5f )
m_fHurtSlowMoveTime = gpGlobals->curtime + 0.5f;
}
if ( CASW_Marine *pMarine = CASW_Marine::AsMarine( pAttacker ) )
{
pMarine->HurtAlien( this, newInfo );
}
// Notify gamestats of the damage
CASW_GameStats.Event_AlienTookDamage( this, newInfo );
}
UTIL_RD_HitConfirm( this, iHealthBefore, newInfo );
return result;
}
void CASW_Inhabitable_NPC::Event_Killed( const CTakeDamageInfo &info )
{
if ( Classify() != CLASS_ASW_MARINE )
{
if ( ASWGameRules() )
{
ASWGameRules()->AlienKilled( this, info );
}
CASW_GameStats.Event_AlienKilled( this, info );
if ( ASWDirector() )
{
ASWDirector()->Event_AlienKilled( this, info );
}
if ( m_hSpawner.Get() )
{
m_hSpawner->AlienKilled( this );
}
}
if ( m_flFrozen >= 0.1f )
{
bool bShatter = ( RandomFloat() >= IceStatueChance() );
CreateASWServerStatue( this, COLLISION_GROUP_NONE, info, bShatter, StatueShatterDelay() );
BaseClass::Event_Killed( CTakeDamageInfo( info.GetAttacker(), info.GetAttacker(), info.GetDamage(), DMG_GENERIC | DMG_REMOVENORAGDOLL | DMG_PREVENT_PHYSICS_FORCE ) );
RemoveDeferred();
return;
}
BaseClass::Event_Killed( info );
}
void CASW_Inhabitable_NPC::ASW_Ignite( float flFlameLifetime, float flSize, CBaseEntity *pAttacker, CBaseEntity *pDamagingWeapon, CBaseEntity *pInflictor )
{
if ( AllowedToIgnite( pAttacker, pDamagingWeapon, pInflictor ) )
{
if ( IsOnFire() )
{
if ( ASWBurning() )
ASWBurning()->ExtendBurning( this, flFlameLifetime );;
return;
}
AddFlag( FL_ONFIRE );
m_bOnFire = true;
if ( ASWBurning() )
ASWBurning()->BurnEntity( this, pAttacker, flFlameLifetime, rd_burning_interval.GetFloat(), ( GetHullType() == HULL_HUMAN ? rd_burning_humanoid_damage.GetFloat() : rd_burning_alien_damage.GetFloat() ) * rd_burning_interval.GetFloat(), pDamagingWeapon );
m_OnIgnite.FireOutput( this, this );
}
}
void CASW_Inhabitable_NPC::Ignite( float flFlameLifetime, bool bNPCOnly, float flSize, bool bCalledByLevelDesigner )
{
Assert( 0 ); // use ASW_Ignite instead
}
void CASW_Inhabitable_NPC::ScriptIgnite( float flFlameLifetime )
{
ASW_Ignite( flFlameLifetime, 0, NULL, NULL, NULL );
}
void CASW_Inhabitable_NPC::Extinguish()
{
m_bOnFire = false;
if ( ASWBurning() )
ASWBurning()->Extinguish( this );
RemoveFlag( FL_ONFIRE );
}
void CASW_Inhabitable_NPC::ElectroStun( float flStunTime )
{
if ( m_fHurtSlowMoveTime < gpGlobals->curtime + flStunTime )
m_fHurtSlowMoveTime = gpGlobals->curtime + flStunTime;
if ( m_flElectroStunSlowMoveTime < gpGlobals->curtime + flStunTime )
m_flElectroStunSlowMoveTime = gpGlobals->curtime + flStunTime;
m_bElectroStunned = true;
if ( ASWGameResource() && Classify() != CLASS_ASW_MARINE )
{
ASWGameResource()->m_iElectroStunnedAliens++;
}
// can't jump after being elecrostunned
CapabilitiesRemove( bits_CAP_MOVE_JUMP );
}
void CASW_Inhabitable_NPC::ScriptElectroStun( float flStunTime )
{
ElectroStun( flStunTime );
}
//-----------------------------------------------------------------------------
// Freezes this NPC in place for a period of time.
//-----------------------------------------------------------------------------
void CASW_Inhabitable_NPC::Freeze( float flFreezeAmount, CBaseEntity *pFreezer, Ray_t *pFreezeRay )
{
if ( !m_bFreezable )
return;
if ( flFreezeAmount <= 0.0f )
{
SetCondition( COND_NPC_FREEZE );
SetMoveType( MOVETYPE_NONE );
SetGravity( 0 );
SetLocalAngularVelocity( vec3_angle );
SetAbsVelocity( vec3_origin );
return;
}
float flTargetFreezeAmount = flFreezeAmount * ( 1.0f - m_flFreezeResistance ) + m_flFrozen;
if ( !CanBeFullyFrozen() && flTargetFreezeAmount >= 1.0f )
return;
if ( flTargetFreezeAmount >= 1.0f )
{
float flFreezeDuration = MAX( m_flFrozenTime - gpGlobals->curtime, 0.0f ) + flTargetFreezeAmount - 1.0f;
BaseClass::Freeze( 1.0f, pFreezer, pFreezeRay ); // make alien fully frozen
m_flFrozenTime = gpGlobals->curtime + flFreezeDuration;
}
else
{
// if doing a partial freeze, then freeze resistance reduces that
flFreezeAmount *= ( 1.0f - m_flFreezeResistance );
BaseClass::Freeze( flFreezeAmount, pFreezer, pFreezeRay );
}
UpdateThawRate();
}
void CASW_Inhabitable_NPC::Unfreeze()
{
BaseClass::Unfreeze();
// fix up movement type
if ( IsInhabited() )
{
SetMoveType( MOVETYPE_WALK );
}
}
//-----------------------------------------------------------------------------
// VScript: Freezes this NPC in place for a period of time.
//-----------------------------------------------------------------------------
void CASW_Inhabitable_NPC::ScriptFreeze( float flFreezeAmount )
{
Freeze( flFreezeAmount, NULL, NULL );
}
void CASW_Inhabitable_NPC::UpdateThawRate()
{
if ( m_flFrozenTime > gpGlobals->curtime )
{
m_flFrozenThawRate = 0.0f;
}
else
{
m_flFrozenThawRate = m_flBaseThawRate * ( 1.5f - m_flFrozen );
}
}
// set orders for our alien
// select schedule should activate the appropriate orders
void CASW_Inhabitable_NPC::SetAlienOrders( AlienOrder_t Orders, Vector vecOrderSpot, CBaseEntity *pOrderObject )
{
m_AlienOrders = Orders;
m_vecAlienOrderSpot = vecOrderSpot; // unused currently
m_AlienOrderObject = pOrderObject;
Wake(); // Make sure we at least consider following the orders.
if ( Orders == AOT_None )
{
ClearAlienOrders();
return;
}
ForceDecisionThink();
}
void CASW_Inhabitable_NPC::ClearAlienOrders()
{
m_AlienOrders = AOT_None;
m_vecAlienOrderSpot = vec3_origin;
m_AlienOrderObject = NULL;
m_bIgnoreMarines = false;
m_bFailedMoveTo = false;
}
// we're blocking a fellow alien from spawning, let's move a short distance
void CASW_Inhabitable_NPC::MoveAside()
{
if ( !GetEnemy() && !IsMoving() )
{
// random nearby position
if ( !GetNavigator()->SetWanderGoal( 90, 200 ) )
{
if ( !GetNavigator()->SetRandomGoal( 150.0f ) )
{
return; // couldn't find a wander spot
}
}
}
}
void CASW_Inhabitable_NPC::ScriptOrderMoveTo( HSCRIPT hOrderObject, bool bIgnoreMarines )
{
SetAlienOrders( bIgnoreMarines ? AOT_MoveToIgnoringMarines : AOT_MoveTo, vec3_origin, ToEnt( hOrderObject ) );
}
void CASW_Inhabitable_NPC::ScriptChaseNearestMarine()
{
SetAlienOrders( AOT_MoveToNearestMarine, vec3_origin, NULL );
}
void CASW_Inhabitable_NPC::SetSpawnZombineOnMarineKill( bool bSpawn )
{
m_bSpawnZombineOnMarineKill = bSpawn;
}
void CASW_Inhabitable_NPC::SetHealthBarColor( int r, int g, int b, int a )
{
color32 &color = m_rgbaHealthBarColor.GetForModify();
color.r = r;
color.g = g;
color.b = b;
color.a = a;
}