forked from hitmen047/Source-PlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc_baseentity.h
2216 lines (1704 loc) · 73.6 KB
/
c_baseentity.h
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: A base class for the client-side representation of entities.
//
// This class encompasses both entities that are created on the server
// and networked to the client AND entities that are created on the
// client.
//
// $NoKeywords: $
//===========================================================================//
#ifndef C_BASEENTITY_H
#define C_BASEENTITY_H
#ifdef _WIN32
#pragma once
#endif
#include "mathlib/vector.h"
#include "icliententityinternal.h"
#include "engine/ivmodelinfo.h"
#include "engine/ivmodelrender.h"
#include "client_class.h"
#include "iclientshadowmgr.h"
#include "ehandle.h"
#include "iclientunknown.h"
#include "client_thinklist.h"
#if !defined( NO_ENTITY_PREDICTION )
#include "predictableid.h"
#endif
#include "soundflags.h"
#include "shareddefs.h"
#include "networkvar.h"
#include "interpolatedvar.h"
#include "collisionproperty.h"
#include "particle_property.h"
#include "toolframework/itoolentity.h"
#include "tier0/threadtools.h"
class C_Team;
class IPhysicsObject;
class IClientVehicle;
class CPredictionCopy;
class C_BasePlayer;
struct studiohdr_t;
class CStudioHdr;
class CDamageModifier;
class IRecipientFilter;
class CUserCmd;
struct solid_t;
class ISave;
class IRestore;
class C_BaseAnimating;
class C_AI_BaseNPC;
struct EmitSound_t;
class C_RecipientFilter;
class CTakeDamageInfo;
class C_BaseCombatCharacter;
class CEntityMapData;
class ConVar;
class CDmgAccumulator;
class IHasAttributes;
struct CSoundParameters;
typedef unsigned int AimEntsListHandle_t;
#define INVALID_AIMENTS_LIST_HANDLE (AimEntsListHandle_t)~0
extern void RecvProxy_IntToColor32( const CRecvProxyData *pData, void *pStruct, void *pOut );
extern void RecvProxy_LocalVelocity( const CRecvProxyData *pData, void *pStruct, void *pOut );
enum CollideType_t
{
ENTITY_SHOULD_NOT_COLLIDE = 0,
ENTITY_SHOULD_COLLIDE,
ENTITY_SHOULD_RESPOND
};
class VarMapEntry_t
{
public:
unsigned short type;
unsigned short m_bNeedsToInterpolate; // Set to false when this var doesn't
// need Interpolate() called on it anymore.
void *data;
IInterpolatedVar *watcher;
};
struct VarMapping_t
{
VarMapping_t()
{
m_nInterpolatedEntries = 0;
}
CUtlVector< VarMapEntry_t > m_Entries;
int m_nInterpolatedEntries;
float m_lastInterpolationTime;
};
#define DECLARE_INTERPOLATION()
// How many data slots to use when in multiplayer.
#define MULTIPLAYER_BACKUP 90
struct serialentity_t;
typedef CHandle<C_BaseEntity> EHANDLE; // The client's version of EHANDLE.
typedef void (C_BaseEntity::*BASEPTR)(void);
typedef void (C_BaseEntity::*ENTITYFUNCPTR)(C_BaseEntity *pOther );
// For entity creation on the client
typedef C_BaseEntity* (*DISPATCHFUNCTION)( void );
#include "touchlink.h"
#include "groundlink.h"
#if !defined( NO_ENTITY_PREDICTION )
//-----------------------------------------------------------------------------
// Purpose: For fully client side entities we use this information to determine
// authoritatively if the server has acknowledged creating this entity, etc.
//-----------------------------------------------------------------------------
struct PredictionContext
{
PredictionContext()
{
m_bActive = false;
m_nCreationCommandNumber = -1;
m_pszCreationModule = NULL;
m_nCreationLineNumber = 0;
m_hServerEntity = NULL;
}
// The command_number of the usercmd which created this entity
bool m_bActive;
int m_nCreationCommandNumber;
char const *m_pszCreationModule;
int m_nCreationLineNumber;
// The entity to whom we are attached
CHandle< C_BaseEntity > m_hServerEntity;
};
#endif
//-----------------------------------------------------------------------------
// Purpose: think contexts
//-----------------------------------------------------------------------------
struct thinkfunc_t
{
BASEPTR m_pfnThink;
string_t m_iszContext;
int m_nNextThinkTick;
int m_nLastThinkTick;
};
#define CREATE_PREDICTED_ENTITY( className ) \
C_BaseEntity::CreatePredictedEntityByName( className, __FILE__, __LINE__ );
// Entity flags that only exist on the client.
#define ENTCLIENTFLAG_GETTINGSHADOWRENDERBOUNDS 0x0001 // Tells us if we're getting the real ent render bounds or the shadow render bounds.
#define ENTCLIENTFLAG_DONTUSEIK 0x0002 // Don't use IK on this entity even if its model has IK.
#define ENTCLIENTFLAG_ALWAYS_INTERPOLATE 0x0004 // Used by view models.
//-----------------------------------------------------------------------------
// Purpose: Base client side entity object
//-----------------------------------------------------------------------------
class C_BaseEntity : public IClientEntity
{
// Construction
DECLARE_CLASS_NOBASE( C_BaseEntity );
friend class CPrediction;
friend void cc_cl_interp_all_changed( IConVar *pConVar, const char *pOldString, float flOldValue );
public:
DECLARE_DATADESC();
DECLARE_CLIENTCLASS();
DECLARE_PREDICTABLE();
C_BaseEntity();
virtual ~C_BaseEntity();
static C_BaseEntity *CreatePredictedEntityByName( const char *classname, const char *module, int line, bool persist = false );
// FireBullets uses shared code for prediction.
virtual void FireBullets( const FireBulletsInfo_t &info );
virtual void ModifyFireBulletsDamage( CTakeDamageInfo* dmgInfo ) {}
virtual bool ShouldDrawUnderwaterBulletBubbles();
virtual bool ShouldDrawWaterImpacts( void ) { return true; }
virtual bool HandleShotImpactingWater( const FireBulletsInfo_t &info,
const Vector &vecEnd, ITraceFilter *pTraceFilter, Vector *pVecTracerDest );
virtual ITraceFilter* GetBeamTraceFilter( void );
virtual void DispatchTraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator = NULL );
virtual void TraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator = NULL );
virtual void DoImpactEffect( trace_t &tr, int nDamageType );
virtual void MakeTracer( const Vector &vecTracerSrc, const trace_t &tr, int iTracerType );
virtual int GetTracerAttachment( void );
void ComputeTracerStartPosition( const Vector &vecShotSrc, Vector *pVecTracerStart );
void TraceBleed( float flDamage, const Vector &vecDir, trace_t *ptr, int bitsDamageType );
virtual int BloodColor();
virtual const char* GetTracerType();
virtual void Spawn( void );
virtual void SpawnClientEntity( void );
virtual void Precache( void );
virtual void Activate();
virtual void ParseMapData( CEntityMapData *mapData );
virtual bool KeyValue( const char *szKeyName, const char *szValue );
virtual bool KeyValue( const char *szKeyName, float flValue );
virtual bool KeyValue( const char *szKeyName, const Vector &vecValue );
virtual bool GetKeyValue( const char *szKeyName, char *szValue, int iMaxLen );
// Entities block Line-Of-Sight for NPCs by default.
// Set this to false if you want to change this behavior.
void SetBlocksLOS( bool bBlocksLOS );
bool BlocksLOS( void );
void SetAIWalkable( bool bBlocksLOS );
bool IsAIWalkable( void );
void Interp_SetupMappings( VarMapping_t *map );
// Returns 1 if there are no more changes (ie: we could call RemoveFromInterpolationList).
int Interp_Interpolate( VarMapping_t *map, float currentTime );
void Interp_RestoreToLastNetworked( VarMapping_t *map );
void Interp_UpdateInterpolationAmounts( VarMapping_t *map );
void Interp_HierarchyUpdateInterpolationAmounts();
// Called by the CLIENTCLASS macros.
virtual bool Init( int entnum, int iSerialNum );
// Called in the destructor to shutdown everything.
void Term();
// memory handling, uses calloc so members are zero'd out on instantiation
void *operator new( size_t stAllocateBlock );
void *operator new[]( size_t stAllocateBlock );
void *operator new( size_t stAllocateBlock, int nBlockUse, const char *pFileName, int nLine );
void *operator new[]( size_t stAllocateBlock, int nBlockUse, const char *pFileName, int nLine );
void operator delete( void *pMem );
void operator delete( void *pMem, int nBlockUse, const char *pFileName, int nLine ) { operator delete( pMem ); }
// This just picks one of the routes to IClientUnknown.
IClientUnknown* GetIClientUnknown() { return this; }
virtual C_BaseAnimating* GetBaseAnimating() { return NULL; }
virtual void SetClassname( const char *className );
string_t m_iClassname;
// IClientUnknown overrides.
public:
virtual void SetRefEHandle( const CBaseHandle &handle );
virtual const CBaseHandle& GetRefEHandle() const;
void SetToolHandle( HTOOLHANDLE handle );
HTOOLHANDLE GetToolHandle() const;
void EnableInToolView( bool bEnable );
bool IsEnabledInToolView() const;
void SetToolRecording( bool recording );
bool IsToolRecording() const;
bool HasRecordedThisFrame() const;
virtual void RecordToolMessage();
// used to exclude entities from being recorded in the SFM tools
void DontRecordInTools();
bool ShouldRecordInTools() const;
virtual void Release();
virtual ICollideable* GetCollideable() { return &m_Collision; }
virtual IClientNetworkable* GetClientNetworkable() { return this; }
virtual IClientRenderable* GetClientRenderable() { return this; }
virtual IClientEntity* GetIClientEntity() { return this; }
virtual C_BaseEntity* GetBaseEntity() { return this; }
virtual IClientThinkable* GetClientThinkable() { return this; }
// Methods of IClientRenderable
public:
virtual const Vector& GetRenderOrigin( void );
virtual const QAngle& GetRenderAngles( void );
virtual Vector GetObserverCamOrigin( void ) { return GetRenderOrigin(); } // Return the origin for player observers tracking this target
virtual const matrix3x4_t & RenderableToWorldTransform();
virtual bool IsTransparent( void );
virtual bool IsTwoPass( void );
virtual bool UsesPowerOfTwoFrameBufferTexture();
virtual bool UsesFullFrameBufferTexture();
virtual bool IgnoresZBuffer( void ) const;
virtual const model_t *GetModel( void ) const;
virtual int DrawModel( int flags );
virtual void ComputeFxBlend( void );
virtual int GetFxBlend( void );
virtual bool LODTest() { return true; } // NOTE: UNUSED
virtual void GetRenderBounds( Vector& mins, Vector& maxs );
virtual IPVSNotify* GetPVSNotifyInterface();
virtual void GetRenderBoundsWorldspace( Vector& absMins, Vector& absMaxs );
virtual void GetShadowRenderBounds( Vector &mins, Vector &maxs, ShadowType_t shadowType );
// Determine the color modulation amount
virtual void GetColorModulation( float* color );
virtual void OnThreadedDrawSetup() {}
public:
virtual bool TestCollision( const Ray_t &ray, unsigned int fContentsMask, trace_t& tr );
virtual bool TestHitboxes( const Ray_t &ray, unsigned int fContentsMask, trace_t& tr );
// To mimic server call convention
C_BaseEntity *GetOwnerEntity( void ) const;
void SetOwnerEntity( C_BaseEntity *pOwner );
C_BaseEntity *GetEffectEntity( void ) const;
void SetEffectEntity( C_BaseEntity *pEffectEnt );
// This function returns a value that scales all damage done by this entity.
// Use CDamageModifier to hook in damage modifiers on a guy.
virtual float GetAttackDamageScale( void );
// IClientNetworkable implementation.
public:
virtual void NotifyShouldTransmit( ShouldTransmitState_t state );
// save out interpolated values
virtual void PreDataUpdate( DataUpdateType_t updateType );
virtual void PostDataUpdate( DataUpdateType_t updateType );
virtual void OnDataUnchangedInPVS();
virtual void ValidateModelIndex( void );
// pvs info. NOTE: Do not override these!!
virtual void SetDormant( bool bDormant );
virtual bool IsDormant( void );
// Tells the entity that it's about to be destroyed due to the client receiving
// an uncompressed update that's caused it to destroy all entities & recreate them.
virtual void SetDestroyedOnRecreateEntities( void );
virtual int GetEFlags() const;
virtual void SetEFlags( int iEFlags );
void AddEFlags( int nEFlagMask );
void RemoveEFlags( int nEFlagMask );
bool IsEFlagSet( int nEFlagMask ) const;
// checks to see if the entity is marked for deletion
bool IsMarkedForDeletion( void );
virtual int entindex( void ) const;
// This works for client-only entities and returns the GetEntryIndex() of the entity's handle,
// so the sound system can get an IClientEntity from it.
int GetSoundSourceIndex() const;
// Server to client message received
virtual void ReceiveMessage( int classID, bf_read &msg );
virtual void* GetDataTableBasePtr();
// IClientThinkable.
public:
// Called whenever you registered for a think message (with SetNextClientThink).
virtual void ClientThink();
virtual ClientThinkHandle_t GetThinkHandle();
virtual void SetThinkHandle( ClientThinkHandle_t hThink );
public:
void AddVar( void *data, IInterpolatedVar *watcher, int type, bool bSetup=false );
void RemoveVar( void *data, bool bAssert=true );
VarMapping_t* GetVarMapping();
VarMapping_t m_VarMap;
public:
// An inline version the game code can use
CCollisionProperty *CollisionProp();
const CCollisionProperty*CollisionProp() const;
CParticleProperty *ParticleProp();
const CParticleProperty *ParticleProp() const;
// Simply here for game shared
bool IsFloating();
virtual bool ShouldSavePhysics();
// save/restore stuff
virtual void OnSave();
virtual void OnRestore();
// capabilities for save/restore
virtual int ObjectCaps( void );
// only overload these if you have special data to serialize
virtual int Save( ISave &save );
virtual int Restore( IRestore &restore );
private:
int SaveDataDescBlock( ISave &save, datamap_t *dmap );
int RestoreDataDescBlock( IRestore &restore, datamap_t *dmap );
// Called after restoring data into prediction slots. This function is used in place of proxies
// on the variables, so if some variable like m_nModelIndex needs to update other state (like
// the model pointer), it is done here.
void OnPostRestoreData();
public:
// Called after spawn, and in the case of self-managing objects, after load
virtual bool CreateVPhysics();
// Convenience routines to init the vphysics simulation for this object.
// This creates a static object. Something that behaves like world geometry - solid, but never moves
IPhysicsObject *VPhysicsInitStatic( void );
// This creates a normal vphysics simulated object
IPhysicsObject *VPhysicsInitNormal( SolidType_t solidType, int nSolidFlags, bool createAsleep, solid_t *pSolid = NULL );
// This creates a vphysics object with a shadow controller that follows the AI
// Move the object to where it should be and call UpdatePhysicsShadowToCurrentPosition()
IPhysicsObject *VPhysicsInitShadow( bool allowPhysicsMovement, bool allowPhysicsRotation, solid_t *pSolid = NULL );
private:
// called by all vphysics inits
bool VPhysicsInitSetup();
public:
void VPhysicsSetObject( IPhysicsObject *pPhysics );
// destroy and remove the physics object for this entity
virtual void VPhysicsDestroyObject( void );
// Purpose: My physics object has been updated, react or extract data
virtual void VPhysicsUpdate( IPhysicsObject *pPhysics );
inline IPhysicsObject *VPhysicsGetObject( void ) const { return m_pPhysicsObject; }
virtual int VPhysicsGetObjectList( IPhysicsObject **pList, int listMax );
virtual bool VPhysicsIsFlesh( void );
// IClientEntity implementation.
public:
virtual bool SetupBones( matrix3x4_t *pBoneToWorldOut, int nMaxBones, int boneMask, float currentTime );
virtual void SetupWeights( const matrix3x4_t *pBoneToWorld, int nFlexWeightCount, float *pFlexWeights, float *pFlexDelayedWeights );
virtual bool UsesFlexDelayedWeights() { return false; }
virtual void DoAnimationEvents( void );
// Add entity to visible entities list?
virtual void AddEntity( void );
virtual const Vector& GetAbsOrigin( void ) const;
virtual const QAngle& GetAbsAngles( void ) const;
const Vector& GetNetworkOrigin() const;
const QAngle& GetNetworkAngles() const;
void SetNetworkOrigin( const Vector& org );
void SetNetworkAngles( const QAngle& ang );
const Vector& GetLocalOrigin( void ) const;
void SetLocalOrigin( const Vector& origin );
vec_t GetLocalOriginDim( int iDim ) const; // You can use the X_INDEX, Y_INDEX, and Z_INDEX defines here.
void SetLocalOriginDim( int iDim, vec_t flValue );
const QAngle& GetLocalAngles( void ) const;
void SetLocalAngles( const QAngle& angles );
vec_t GetLocalAnglesDim( int iDim ) const; // You can use the X_INDEX, Y_INDEX, and Z_INDEX defines here.
void SetLocalAnglesDim( int iDim, vec_t flValue );
virtual const Vector& GetPrevLocalOrigin() const;
virtual const QAngle& GetPrevLocalAngles() const;
void SetLocalTransform( const matrix3x4_t &localTransform );
void SetModelName( string_t name );
string_t GetModelName( void ) const;
int GetModelIndex( void ) const;
void SetModelIndex( int index );
virtual int CalcOverrideModelIndex() { return -1; }
// These methods return a *world-aligned* box relative to the absorigin of the entity.
// This is used for collision purposes and is *not* guaranteed
// to surround the entire entity's visual representation
// NOTE: It is illegal to ask for the world-aligned bounds for
// SOLID_BSP objects
virtual const Vector& WorldAlignMins( ) const;
virtual const Vector& WorldAlignMaxs( ) const;
// This defines collision bounds *in whatever space is currently defined by the solid type*
// SOLID_BBOX: World Align
// SOLID_OBB: Entity space
// SOLID_BSP: Entity space
// SOLID_VPHYSICS Not used
void SetCollisionBounds( const Vector& mins, const Vector &maxs );
// NOTE: These use the collision OBB to compute a reasonable center point for the entity
virtual const Vector& WorldSpaceCenter( ) const;
// FIXME: Do we want this?
const Vector& WorldAlignSize( ) const;
bool IsPointSized() const;
// Returns a radius of a sphere
// *centered at the world space center* bounding the collision representation
// of the entity. NOTE: The world space center *may* move when the entity rotates.
float BoundingRadius() const;
// Used when the collision prop is told to ask game code for the world-space surrounding box
virtual void ComputeWorldSpaceSurroundingBox( Vector *pVecWorldMins, Vector *pVecWorldMaxs );
virtual float GetHealthBarHeightOffset() const { return 0.f; }
// Returns the entity-to-world transform
matrix3x4_t &EntityToWorldTransform();
const matrix3x4_t &EntityToWorldTransform() const;
// Some helper methods that transform a point from entity space to world space + back
void EntityToWorldSpace( const Vector &in, Vector *pOut ) const;
void WorldToEntitySpace( const Vector &in, Vector *pOut ) const;
// This function gets your parent's transform. If you're parented to an attachment,
// this calculates the attachment's transform and gives you that.
//
// You must pass in tempMatrix for scratch space - it may need to fill that in and return it instead of
// pointing you right at a variable in your parent.
matrix3x4_t& GetParentToWorldTransform( matrix3x4_t &tempMatrix );
void GetVectors(Vector* forward, Vector* right, Vector* up) const;
// Sets abs angles, but also sets local angles to be appropriate
void SetAbsOrigin( const Vector& origin );
void SetAbsAngles( const QAngle& angles );
void AddFlag( int flags );
void RemoveFlag( int flagsToRemove );
void ToggleFlag( int flagToToggle );
int GetFlags( void ) const;
void ClearFlags();
MoveType_t GetMoveType( void ) const;
MoveCollide_t GetMoveCollide( void ) const;
virtual SolidType_t GetSolid( void ) const;
virtual int GetSolidFlags( void ) const;
bool IsSolidFlagSet( int flagMask ) const;
void SetSolidFlags( int nFlags );
void AddSolidFlags( int nFlags );
void RemoveSolidFlags( int nFlags );
bool IsSolid() const;
virtual class CMouthInfo *GetMouth( void );
// Retrieve sound spatialization info for the specified sound on this entity
// Return false to indicate sound is not audible
virtual bool GetSoundSpatialization( SpatializationInfo_t& info );
// Attachments
virtual int LookupAttachment( const char *pAttachmentName ) { return -1; }
virtual bool GetAttachment( int number, matrix3x4_t &matrix );
virtual bool GetAttachment( int number, Vector &origin );
virtual bool GetAttachment( int number, Vector &origin, QAngle &angles );
virtual bool GetAttachmentVelocity( int number, Vector &originVel, Quaternion &angleVel );
// Team handling
virtual C_Team *GetTeam( void );
virtual int GetTeamNumber( void ) const;
virtual void ChangeTeam( int iTeamNum ); // Assign this entity to a team.
virtual int GetRenderTeamNumber( void );
virtual bool InSameTeam( C_BaseEntity *pEntity ); // Returns true if the specified entity is on the same team as this one
virtual bool InLocalTeam( void );
// ID Target handling
virtual bool IsValidIDTarget( void ) { return false; }
virtual const char *GetIDString( void ) { return ""; };
// See CSoundEmitterSystem
virtual void ModifyEmitSoundParams( EmitSound_t ¶ms );
void EmitSound( const char *soundname, float soundtime = 0.0f, float *duration = NULL ); // Override for doing the general case of CPASAttenuationFilter( this ), and EmitSound( filter, entindex(), etc. );
void EmitSound( const char *soundname, HSOUNDSCRIPTHANDLE& handle, float soundtime = 0.0f, float *duration = NULL ); // Override for doing the general case of CPASAttenuationFilter( this ), and EmitSound( filter, entindex(), etc. );
void StopSound( const char *soundname );
void StopSound( const char *soundname, HSOUNDSCRIPTHANDLE& handle );
void GenderExpandString( char const *in, char *out, int maxlen );
static float GetSoundDuration( const char *soundname, char const *actormodel );
static bool GetParametersForSound( const char *soundname, CSoundParameters ¶ms, const char *actormodel );
static bool GetParametersForSound( const char *soundname, HSOUNDSCRIPTHANDLE& handle, CSoundParameters ¶ms, const char *actormodel );
static void EmitSound( IRecipientFilter& filter, int iEntIndex, const char *soundname, const Vector *pOrigin = NULL, float soundtime = 0.0f, float *duration = NULL );
static void EmitSound( IRecipientFilter& filter, int iEntIndex, const char *soundname, HSOUNDSCRIPTHANDLE& handle, const Vector *pOrigin = NULL, float soundtime = 0.0f, float *duration = NULL );
static void StopSound( int iEntIndex, const char *soundname );
static soundlevel_t LookupSoundLevel( const char *soundname );
static soundlevel_t LookupSoundLevel( const char *soundname, HSOUNDSCRIPTHANDLE& handle );
static void EmitSound( IRecipientFilter& filter, int iEntIndex, const EmitSound_t & params );
static void EmitSound( IRecipientFilter& filter, int iEntIndex, const EmitSound_t & params, HSOUNDSCRIPTHANDLE& handle );
static void StopSound( int iEntIndex, int iChannel, const char *pSample );
static void EmitAmbientSound( int entindex, const Vector& origin, const char *soundname, int flags = 0, float soundtime = 0.0f, float *duration = NULL );
// These files need to be listed in scripts/game_sounds_manifest.txt
static HSOUNDSCRIPTHANDLE PrecacheScriptSound( const char *soundname );
static void PrefetchScriptSound( const char *soundname );
// For each client who appears to be a valid recipient, checks the client has disabled CC and if so, removes them from
// the recipient list.
static void RemoveRecipientsIfNotCloseCaptioning( C_RecipientFilter& filter );
static void EmitCloseCaption( IRecipientFilter& filter, int entindex, char const *token, CUtlVector< Vector >& soundorigins, float duration, bool warnifmissing = false );
// Moves all aiments into their correct position for the frame
static void MarkAimEntsDirty();
static void CalcAimEntPositions();
static bool IsPrecacheAllowed();
static void SetAllowPrecache( bool allow );
static bool m_bAllowPrecache;
static bool IsSimulatingOnAlternateTicks();
// C_BaseEntity local functions
public:
void UpdatePartitionListEntry();
// This can be used to setup the entity as a client-only entity.
// Override this to perform per-entity clientside setup
virtual bool InitializeAsClientEntity( const char *pszModelName, RenderGroup_t renderGroup );
// This function gets called on all client entities once per simulation phase.
// It dispatches events like OnDataChanged(), and calls the legacy function AddEntity().
virtual void Simulate();
// This event is triggered during the simulation phase if an entity's data has changed. It is
// better to hook this instead of PostDataUpdate() because in PostDataUpdate(), server entity origins
// are incorrect and attachment points can't be used.
virtual void OnDataChanged( DataUpdateType_t type );
// This is called once per frame before any data is read in from the server.
virtual void OnPreDataChanged( DataUpdateType_t type );
bool IsStandable() const;
bool IsBSPModel() const;
// If this is a vehicle, returns the vehicle interface
virtual IClientVehicle* GetClientVehicle() { return NULL; }
// Returns the aiment render origin + angles
virtual void GetAimEntOrigin( IClientEntity *pAttachedTo, Vector *pAbsOrigin, QAngle *pAbsAngles );
// get network origin from previous update
virtual const Vector& GetOldOrigin();
// Methods relating to traversing hierarchy
C_BaseEntity *GetMoveParent( void ) const;
C_BaseEntity *GetRootMoveParent();
C_BaseEntity *FirstMoveChild( void ) const;
C_BaseEntity *NextMovePeer( void ) const;
inline ClientEntityHandle_t GetClientHandle() const { return ClientEntityHandle_t( m_RefEHandle ); }
inline bool IsServerEntity( void );
virtual RenderGroup_t GetRenderGroup();
virtual void GetToolRecordingState( KeyValues *msg );
virtual void CleanupToolRecordingState( KeyValues *msg );
// The value returned by here determines whether or not (and how) the entity
// is put into the spatial partition.
virtual CollideType_t GetCollideType( void );
virtual bool ShouldDraw();
inline bool IsVisible() const { return m_hRender != INVALID_CLIENT_RENDER_HANDLE; }
virtual void UpdateVisibility();
// Returns true if the entity changes its position every frame on the server but it doesn't
// set animtime. In that case, the client returns true here so it copies the server time to
// animtime in OnDataChanged and the position history is correct for interpolation.
virtual bool IsSelfAnimating();
// Set appropriate flags and store off data when these fields are about to change
virtual void OnLatchInterpolatedVariables( int flags );
// For predictable entities, stores last networked value
void OnStoreLastNetworkedValue();
// Initialize things given a new model.
virtual CStudioHdr *OnNewModel();
virtual void OnNewParticleEffect( const char *pszParticleName, CNewParticleEffect *pNewParticleEffect );
bool IsSimulatedEveryTick() const;
bool IsAnimatedEveryTick() const;
void SetSimulatedEveryTick( bool sim );
void SetAnimatedEveryTick( bool anim );
void Interp_Reset( VarMapping_t *map );
virtual void ResetLatched();
float GetInterpolationAmount( int flags );
float GetLastChangeTime( int flags );
// Interpolate the position for rendering
virtual bool Interpolate( float currentTime );
// Did the object move so far that it shouldn't interpolate?
bool Teleported( void );
// Is this a submodel of the world ( *1 etc. in name ) ( brush models only )
virtual bool IsSubModel( void );
// Deal with EF_* flags
virtual void CreateLightEffects( void );
void AddToAimEntsList();
void RemoveFromAimEntsList();
// Reset internal fields
virtual void Clear( void );
// Helper to draw raw brush models
virtual int DrawBrushModel( bool bTranslucent, int nFlags, bool bTwoPass );
// returns the material animation start time
virtual float GetTextureAnimationStartTime();
// Indicates that a texture animation has wrapped
virtual void TextureAnimationWrapped();
// Set the next think time. Pass in CLIENT_THINK_ALWAYS to have Think() called each frame.
virtual void SetNextClientThink( float nextThinkTime );
// anything that has health can override this...
virtual void SetHealth(int iHealth) {}
virtual int GetHealth() const { return 0; }
virtual int GetMaxHealth() const { return 1; }
virtual bool IsVisibleToTargetID( void ) const { return false; }
virtual bool IsHealthBarVisible( void ) const { return false; }
// Returns the health fraction
float HealthFraction() const;
// Should this object cast shadows?
virtual ShadowType_t ShadowCastType();
// Should this object receive shadows?
virtual bool ShouldReceiveProjectedTextures( int flags );
// Shadow-related methods
virtual bool IsShadowDirty( );
virtual void MarkShadowDirty( bool bDirty );
virtual IClientRenderable *GetShadowParent();
virtual IClientRenderable *FirstShadowChild();
virtual IClientRenderable *NextShadowPeer();
// Sets up a render handle so the leaf system will draw this entity.
void AddToLeafSystem();
void AddToLeafSystem( RenderGroup_t group );
// remove entity form leaf system again
void RemoveFromLeafSystem();
// A method to apply a decal to an entity
virtual void AddDecal( const Vector& rayStart, const Vector& rayEnd,
const Vector& decalCenter, int hitbox, int decalIndex, bool doTrace, trace_t& tr, int maxLODToDecal = ADDDECAL_TO_ALL_LODS );
virtual void AddColoredDecal( const Vector& rayStart, const Vector& rayEnd,
const Vector& decalCenter, int hitbox, int decalIndex, bool doTrace, trace_t& tr, Color cColor, int maxLODToDecal = ADDDECAL_TO_ALL_LODS );
// A method to remove all decals from an entity
void RemoveAllDecals( void );
// Is this a brush model?
bool IsBrushModel() const;
// A random value 0-1 used by proxies to make sure they're not all in sync
float ProxyRandomValue() const { return m_flProxyRandomValue; }
// The spawn time of this entity
float SpawnTime() const { return m_flSpawnTime; }
virtual bool IsClientCreated( void ) const;
virtual void UpdateOnRemove( void );
virtual void SUB_Remove( void );
// Prediction stuff
/////////////////
void CheckInitPredictable( const char *context );
void AllocateIntermediateData( void );
void DestroyIntermediateData( void );
void ShiftIntermediateDataForward( int slots_to_remove, int previous_last_slot );
void *GetPredictedFrame( int framenumber );
void *GetOriginalNetworkDataObject( void );
bool IsIntermediateDataAllocated( void ) const;
void InitPredictable( void );
void ShutdownPredictable( void );
virtual void SetPredictable( bool state );
bool GetPredictable( void ) const;
void PreEntityPacketReceived( int commands_acknowledged );
void PostEntityPacketReceived( void );
bool PostNetworkDataReceived( int commands_acknowledged );
bool GetPredictionEligible( void ) const;
void SetPredictionEligible( bool canpredict );
enum
{
SLOT_ORIGINALDATA = -1,
};
int SaveData( const char *context, int slot, int type );
virtual int RestoreData( const char *context, int slot, int type );
virtual char const * DamageDecal( int bitsDamageType, int gameMaterial );
virtual void DecalTrace( trace_t *pTrace, char const *decalName );
virtual void ImpactTrace( trace_t *pTrace, int iDamageType, const char *pCustomImpactName );
virtual bool ShouldPredict( void ) { return false; };
// interface function pointers
void (C_BaseEntity::*m_pfnThink)(void);
virtual void Think( void )
{
AssertMsg( m_pfnThink != &C_BaseEntity::Think, "Infinite recursion is infinitely bad." );
if ( m_pfnThink )
{
( this->*m_pfnThink )();
}
}
void PhysicsDispatchThink( BASEPTR thinkFunc );
// Toggle the visualization of the entity's abs/bbox
enum
{
VISUALIZE_COLLISION_BOUNDS = 0x1,
VISUALIZE_SURROUNDING_BOUNDS = 0x2,
VISUALIZE_RENDER_BOUNDS = 0x4,
};
void ToggleBBoxVisualization( int fVisFlags );
void DrawBBoxVisualizations( void );
// Methods implemented on both client and server
public:
void SetSize( const Vector &vecMin, const Vector &vecMax ); // UTIL_SetSize( pev, mins, maxs );
char const *GetClassname( void );
char const *GetDebugName( void );
static int PrecacheModel( const char *name );
static bool PrecacheSound( const char *name );
static void PrefetchSound( const char *name );
void Remove( ); // UTIL_Remove( this );
public:
// Returns the attachment point index on our parent that our transform is relative to.
// 0 if we're relative to the parent's absorigin and absangles.
unsigned char GetParentAttachment() const;
// Externalized data objects ( see sharreddefs.h for DataObjectType_t )
bool HasDataObjectType( int type ) const;
void AddDataObjectType( int type );
void RemoveDataObjectType( int type );
void *GetDataObject( int type );
void *CreateDataObject( int type );
void DestroyDataObject( int type );
void DestroyAllDataObjects( void );
// Determine approximate velocity based on updates from server
void EstimateAbsVelocity( Vector& vel );
#if !defined( NO_ENTITY_PREDICTION )
// The player drives simulation of this entity
void SetPlayerSimulated( C_BasePlayer *pOwner );
bool IsPlayerSimulated( void ) const;
CBasePlayer *GetSimulatingPlayer( void );
void UnsetPlayerSimulated( void );
#endif
// Sorry folks, here lies TF2-specific stuff that really has no other place to go
virtual bool CanBePoweredUp( void ) { return false; }
virtual bool AttemptToPowerup( int iPowerup, float flTime, float flAmount = 0, C_BaseEntity *pAttacker = NULL, CDamageModifier *pDamageModifier = NULL ) { return false; }
void SetCheckUntouch( bool check );
bool GetCheckUntouch() const;
virtual bool IsCurrentlyTouching( void ) const;
virtual void StartTouch( C_BaseEntity *pOther );
virtual void Touch( C_BaseEntity *pOther );
virtual void EndTouch( C_BaseEntity *pOther );
void (C_BaseEntity ::*m_pfnTouch)( C_BaseEntity *pOther );
void PhysicsStep( void );
protected:
static bool sm_bDisableTouchFuncs; // Disables PhysicsTouch and PhysicsStartTouch function calls
public:
touchlink_t *PhysicsMarkEntityAsTouched( C_BaseEntity *other );
void PhysicsTouch( C_BaseEntity *pentOther );
void PhysicsStartTouch( C_BaseEntity *pentOther );
// HACKHACK:Get the trace_t from the last physics touch call (replaces the even-hackier global trace vars)
static const trace_t &GetTouchTrace( void );
// FIXME: Should be private, but I can't make em private just yet
void PhysicsImpact( C_BaseEntity *other, trace_t &trace );
void PhysicsMarkEntitiesAsTouching( C_BaseEntity *other, trace_t &trace );
void PhysicsMarkEntitiesAsTouchingEventDriven( C_BaseEntity *other, trace_t &trace );
// Physics helper
static void PhysicsRemoveTouchedList( C_BaseEntity *ent );
static void PhysicsNotifyOtherOfUntouch( C_BaseEntity *ent, C_BaseEntity *other );
static void PhysicsRemoveToucher( C_BaseEntity *other, touchlink_t *link );
groundlink_t *AddEntityToGroundList( CBaseEntity *other );
void PhysicsStartGroundContact( CBaseEntity *pentOther );
static void PhysicsNotifyOtherOfGroundRemoval( CBaseEntity *ent, CBaseEntity *other );
static void PhysicsRemoveGround( CBaseEntity *other, groundlink_t *link );
static void PhysicsRemoveGroundList( CBaseEntity *ent );
void StartGroundContact( CBaseEntity *ground );
void EndGroundContact( CBaseEntity *ground );
void SetGroundChangeTime( float flTime );
float GetGroundChangeTime( void );
// Remove this as ground entity for all object resting on this object
void WakeRestingObjects();
bool HasNPCsOnIt();
bool PhysicsCheckWater( void );
void PhysicsCheckVelocity( void );
void PhysicsAddHalfGravity( float timestep );
void PhysicsAddGravityMove( Vector &move );
virtual unsigned int PhysicsSolidMaskForEntity( void ) const;
void SetGroundEntity( C_BaseEntity *ground );
C_BaseEntity *GetGroundEntity( void );
void PhysicsPushEntity( const Vector& push, trace_t *pTrace );
void PhysicsCheckWaterTransition( void );
// Performs the collision resolution for fliers.
void PerformFlyCollisionResolution( trace_t &trace, Vector &move );
void ResolveFlyCollisionBounce( trace_t &trace, Vector &vecVelocity, float flMinTotalElasticity = 0.0f );
void ResolveFlyCollisionSlide( trace_t &trace, Vector &vecVelocity );
void ResolveFlyCollisionCustom( trace_t &trace, Vector &vecVelocity );
void PhysicsCheckForEntityUntouch( void );
// Creates the shadow (if it doesn't already exist) based on shadow cast type
void CreateShadow();
// Destroys the shadow; causes its type to be recomputed if the entity doesn't go away immediately.
void DestroyShadow();
protected:
// think function handling
enum thinkmethods_t
{
THINK_FIRE_ALL_FUNCTIONS,
THINK_FIRE_BASE_ONLY,
THINK_FIRE_ALL_BUT_BASE,
};
public:
// Unlinks from hierarchy
// Set the movement parent. Your local origin and angles will become relative to this parent.
// If iAttachment is a valid attachment on the parent, then your local origin and angles
// are relative to the attachment on this entity.
void SetParent( C_BaseEntity *pParentEntity, int iParentAttachment=0 );
bool PhysicsRunThink( thinkmethods_t thinkMethod = THINK_FIRE_ALL_FUNCTIONS );
bool PhysicsRunSpecificThink( int nContextIndex, BASEPTR thinkFunc );
virtual void PhysicsSimulate( void );
virtual bool IsAlive( void );