forked from ValveSoftware/source-sdk-2013
-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathbaseentity.h
More file actions
3135 lines (2510 loc) · 106 KB
/
baseentity.h
File metadata and controls
3135 lines (2510 loc) · 106 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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#ifndef BASEENTITY_H
#define BASEENTITY_H
#ifdef _WIN32
#pragma once
#endif
#define TEAMNUM_NUM_BITS 6
#include "entitylist.h"
#include "entityoutput.h"
#include "networkvar.h"
#include "collisionproperty.h"
#include "ServerNetworkProperty.h"
#include "shareddefs.h"
#include "engine/ivmodelinfo.h"
#ifdef NEW_RESPONSE_SYSTEM
#include "AI_Criteria.h"
#include "AI_ResponseSystem.h"
#endif
#include "vscript/ivscript.h"
#include "vscript_server.h"
class CDamageModifier;
class CDmgAccumulator;
struct CSoundParameters;
#ifndef NEW_RESPONSE_SYSTEM
class AI_CriteriaSet;
class IResponseSystem;
#endif
class IEntitySaveUtils;
class CRecipientFilter;
class CStudioHdr;
// Matching the high level concept is significantly better than other criteria
// FIXME: Could do this in the script file by making it required and bumping up weighting there instead...
#define CONCEPT_WEIGHT 5.0f
#ifdef NEW_RESPONSE_SYSTEM
// Relax the namespace standard a bit so that less code has to be changed
#define IResponseSystem ResponseRules::IResponseSystem
#endif
typedef CHandle<CBaseEntity> EHANDLE;
#define MANUALMODE_GETSET_PROP(type, accessorName, varName) \
private:\
type varName;\
public:\
inline const type& Get##accessorName##() const { return varName; } \
inline type& Get##accessorName##() { return varName; } \
inline void Set##accessorName##( const type &val ) { varName = val; m_NetStateMgr.StateChanged(); }
#define MANUALMODE_GETSET_EHANDLE(type, accessorName, varName) \
private:\
CHandle<type> varName;\
public:\
inline type* Get##accessorName##() { return varName.Get(); } \
inline void Set##accessorName##( type *pType ) { varName = pType; m_NetStateMgr.StateChanged(); }
// saverestore.h declarations
class CSaveRestoreData;
struct typedescription_t;
class ISave;
class IRestore;
class CBaseEntity;
class CEntityMapData;
class CBaseCombatWeapon;
class IPhysicsObject;
class IPhysicsShadowController;
class CBaseCombatCharacter;
class CTeam;
class Vector;
struct gamevcollisionevent_t;
class CBaseAnimating;
class CBasePlayer;
class IServerVehicle;
struct solid_t;
struct notify_system_event_params_t;
class CAI_BaseNPC;
class CAI_Senses;
class CSquadNPC;
class variant_t;
class CEventAction;
typedef struct KeyValueData_s KeyValueData;
class CUserCmd;
class CSkyCamera;
class CEntityMapData;
class CWorld;
class INextBot;
typedef CUtlVector< CBaseEntity* > EntityList_t;
#if defined( HL2_DLL )
// For CLASSIFY
enum Class_T
{
CLASS_NONE=0,
CLASS_PLAYER,
CLASS_PLAYER_ALLY,
CLASS_PLAYER_ALLY_VITAL,
CLASS_ANTLION,
CLASS_BARNACLE,
CLASS_BULLSEYE,
//CLASS_BULLSQUID,
CLASS_CITIZEN_PASSIVE,
CLASS_CITIZEN_REBEL,
CLASS_COMBINE,
CLASS_COMBINE_GUNSHIP,
CLASS_CONSCRIPT,
CLASS_HEADCRAB,
//CLASS_HOUNDEYE,
CLASS_MANHACK,
CLASS_METROPOLICE,
CLASS_MILITARY,
CLASS_SCANNER,
CLASS_STALKER,
CLASS_VORTIGAUNT,
CLASS_ZOMBIE,
CLASS_PROTOSNIPER,
CLASS_MISSILE,
CLASS_FLARE,
CLASS_EARTH_FAUNA,
CLASS_HACKED_ROLLERMINE,
CLASS_COMBINE_HUNTER,
NUM_AI_CLASSES
};
#elif defined( HL1_DLL )
enum Class_T
{
CLASS_NONE = 0,
CLASS_MACHINE,
CLASS_PLAYER,
CLASS_HUMAN_PASSIVE,
CLASS_HUMAN_MILITARY,
CLASS_ALIEN_MILITARY,
CLASS_ALIEN_MONSTER,
CLASS_ALIEN_PREY,
CLASS_ALIEN_PREDATOR,
CLASS_INSECT,
CLASS_PLAYER_ALLY,
CLASS_PLAYER_BIOWEAPON,
CLASS_ALIEN_BIOWEAPON,
NUM_AI_CLASSES
};
#elif defined( INVASION_DLL )
enum Class_T
{
CLASS_NONE = 0,
CLASS_PLAYER,
CLASS_PLAYER_ALLY,
CLASS_PLAYER_ALLY_VITAL,
CLASS_ANTLION,
CLASS_BARNACLE,
CLASS_BULLSEYE,
//CLASS_BULLSQUID,
CLASS_CITIZEN_PASSIVE,
CLASS_CITIZEN_REBEL,
CLASS_COMBINE,
CLASS_COMBINE_GUNSHIP,
CLASS_CONSCRIPT,
CLASS_HEADCRAB,
//CLASS_HOUNDEYE,
CLASS_MANHACK,
CLASS_METROPOLICE,
CLASS_MILITARY,
CLASS_SCANNER,
CLASS_STALKER,
CLASS_VORTIGAUNT,
CLASS_ZOMBIE,
CLASS_PROTOSNIPER,
CLASS_MISSILE,
CLASS_FLARE,
CLASS_EARTH_FAUNA,
NUM_AI_CLASSES
};
#elif defined( CSTRIKE_DLL )
enum Class_T
{
CLASS_NONE = 0,
CLASS_PLAYER,
CLASS_PLAYER_ALLY,
NUM_AI_CLASSES
};
#else
enum Class_T
{
CLASS_NONE = 0,
CLASS_PLAYER,
CLASS_PLAYER_ALLY,
NUM_AI_CLASSES
};
#endif
//
// Structure passed to input handlers.
//
struct inputdata_t
{
CBaseEntity *pActivator; // The entity that initially caused this chain of output events.
CBaseEntity *pCaller; // The entity that fired this particular output.
variant_t value; // The data parameter for this output.
int nOutputID; // The unique ID of the output that was fired.
};
// Serializable list of context as set by entity i/o and used for deducing proper
// speech state, et al.
struct ResponseContext_t
{
DECLARE_SIMPLE_DATADESC();
string_t m_iszName;
string_t m_iszValue;
float m_fExpirationTime; // when to expire context (0 == never)
};
//-----------------------------------------------------------------------------
// Entity events... targetted to a particular entity
// Each event has a well defined structure to use for parameters
//-----------------------------------------------------------------------------
enum EntityEvent_t
{
ENTITY_EVENT_WATER_TOUCH = 0, // No data needed
ENTITY_EVENT_WATER_UNTOUCH, // No data needed
ENTITY_EVENT_PARENT_CHANGED, // No data needed
};
//-----------------------------------------------------------------------------
typedef void (CBaseEntity::*BASEPTR)(void);
typedef void (CBaseEntity::*ENTITYFUNCPTR)(CBaseEntity *pOther );
typedef void (CBaseEntity::*USEPTR)( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
#define DEFINE_THINKFUNC( function ) DEFINE_FUNCTION_RAW( function, BASEPTR )
#define DEFINE_ENTITYFUNC( function ) DEFINE_FUNCTION_RAW( function, ENTITYFUNCPTR )
#define DEFINE_USEFUNC( function ) DEFINE_FUNCTION_RAW( function, USEPTR )
// Things that toggle (buttons/triggers/doors) need this
enum TOGGLE_STATE
{
TS_AT_TOP,
TS_AT_BOTTOM,
TS_GOING_UP,
TS_GOING_DOWN
};
// Debug overlay bits
enum DebugOverlayBits_t
{
OVERLAY_TEXT_BIT = 0x00000001, // show text debug overlay for this entity
OVERLAY_NAME_BIT = 0x00000002, // show name debug overlay for this entity
OVERLAY_BBOX_BIT = 0x00000004, // show bounding box overlay for this entity
OVERLAY_PIVOT_BIT = 0x00000008, // show pivot for this entity
OVERLAY_MESSAGE_BIT = 0x00000010, // show messages for this entity
OVERLAY_ABSBOX_BIT = 0x00000020, // show abs bounding box overlay
OVERLAY_RBOX_BIT = 0x00000040, // show the rbox overlay
OVERLAY_SHOW_BLOCKSLOS = 0x00000080, // show entities that block NPC LOS
OVERLAY_ATTACHMENTS_BIT = 0x00000100, // show attachment points
OVERLAY_AUTOAIM_BIT = 0x00000200, // Display autoaim radius
OVERLAY_NPC_SELECTED_BIT = 0x00001000, // the npc is current selected
OVERLAY_NPC_NEAREST_BIT = 0x00002000, // show the nearest node of this npc
OVERLAY_NPC_ROUTE_BIT = 0x00004000, // draw the route for this npc
OVERLAY_NPC_TRIANGULATE_BIT = 0x00008000, // draw the triangulation for this npc
OVERLAY_NPC_ZAP_BIT = 0x00010000, // destroy the NPC
OVERLAY_NPC_ENEMIES_BIT = 0x00020000, // show npc's enemies
OVERLAY_NPC_CONDITIONS_BIT = 0x00040000, // show NPC's current conditions
OVERLAY_NPC_SQUAD_BIT = 0x00080000, // show npc squads
OVERLAY_NPC_TASK_BIT = 0x00100000, // show npc task details
OVERLAY_NPC_FOCUS_BIT = 0x00200000, // show line to npc's enemy and target
OVERLAY_NPC_VIEWCONE_BIT = 0x00400000, // show npc's viewcone
OVERLAY_NPC_KILL_BIT = 0x00800000, // kill the NPC, running all appropriate AI.
OVERLAY_WC_CHANGE_ENTITY = 0x01000000, // object changed during WC edit
OVERLAY_BUDDHA_MODE = 0x02000000, // take damage but don't die
OVERLAY_NPC_STEERING_REGULATIONS = 0x04000000, // Show the steering regulations associated with the NPC
OVERLAY_TASK_TEXT_BIT = 0x08000000, // show task and schedule names when they start
OVERLAY_PROP_DEBUG = 0x10000000,
OVERLAY_NPC_RELATION_BIT = 0x20000000, // show relationships between target and all children
OVERLAY_VIEWOFFSET = 0x40000000, // show view offset
};
struct TimedOverlay_t;
/* ========= CBaseEntity ========
All objects in the game are derived from this.
a list of all CBaseEntitys is kept in gEntList
================================ */
// creates an entity by string name, but does not spawn it
// If iForceEdictIndex is not -1, then it will use the edict by that index. If the index is
// invalid or there is already an edict using that index, it will error out.
CBaseEntity *CreateEntityByName( const char *className, int iForceEdictIndex = -1 );
CBaseNetworkable *CreateNetworkableByName( const char *className );
CBaseEntity* ToEnt(HSCRIPT hScript);
// creates an entity and calls all the necessary spawn functions
extern void SpawnEntityByName( const char *className, CEntityMapData *mapData = NULL );
// calls the spawn functions for an entity
extern int DispatchSpawn( CBaseEntity *pEntity, bool bRunVScripts = true);
inline CBaseEntity *GetContainingEntity( edict_t *pent );
//-----------------------------------------------------------------------------
// Purpose: think contexts
//-----------------------------------------------------------------------------
struct thinkfunc_t
{
BASEPTR m_pfnThink;
string_t m_iszContext;
int m_nNextThinkTick;
int m_nLastThinkTick;
DECLARE_SIMPLE_DATADESC();
};
#ifdef MAPBASE_VSCRIPT
struct scriptthinkfunc_t
{
float m_flNextThink;
HSCRIPT m_hfnThink;
unsigned m_iContextHash;
bool m_bNoParam;
};
#endif
struct EmitSound_t;
struct rotatingpushmove_t;
#define CREATE_PREDICTED_ENTITY( className ) \
CBaseEntity::CreatePredictedEntityByName( className, __FILE__, __LINE__ );
//
// Base Entity. All entity types derive from this
//
class CBaseEntity : public IServerEntity
{
public:
DECLARE_CLASS_NOBASE( CBaseEntity );
//----------------------------------------
// Class vars and functions
//----------------------------------------
static inline void Debug_Pause(bool bPause);
static inline bool Debug_IsPaused(void);
static inline void Debug_SetSteps(int nSteps);
static inline bool Debug_ShouldStep(void);
static inline bool Debug_Step(void);
static bool m_bInDebugSelect;
static int m_nDebugPlayer;
protected:
static bool m_bDebugPause; // Whether entity i/o is paused for debugging.
static int m_nDebugSteps; // Number of entity outputs to fire before pausing again.
static bool sm_bDisableTouchFuncs; // Disables PhysicsTouch and PhysicsStartTouch function calls
public:
static bool sm_bAccurateTriggerBboxChecks; // SOLID_BBOX entities do a fully accurate trigger vs bbox check when this is set
public:
// If bServerOnly is true, then the ent never goes to the client. This is used
// by logical entities.
CBaseEntity( bool bServerOnly=false );
virtual ~CBaseEntity();
// prediction system
DECLARE_PREDICTABLE();
// network data
DECLARE_SERVERCLASS();
// data description
DECLARE_DATADESC();
// script description
DECLARE_ENT_SCRIPTDESC();
// memory handling
void *operator new( size_t stAllocateBlock );
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); }
// Class factory
static CBaseEntity *CreatePredictedEntityByName( const char *classname, const char *module, int line, bool persist = false );
// IHandleEntity overrides.
public:
virtual void SetRefEHandle( const CBaseHandle &handle );
virtual const CBaseHandle& GetRefEHandle() const;
// IServerUnknown overrides
virtual ICollideable *GetCollideable();
virtual IServerNetworkable *GetNetworkable();
virtual CBaseEntity *GetBaseEntity();
// IServerEntity overrides.
public:
virtual void SetModelIndex( int index );
virtual int GetModelIndex( void ) const;
virtual string_t GetModelName( void ) const;
void ClearModelIndexOverrides( void );
virtual void SetModelIndexOverride( int index, int nValue );
public:
// virtual methods for derived classes to override
virtual bool TestCollision( const Ray_t& ray, unsigned int mask, trace_t& trace );
virtual bool TestHitboxes( const Ray_t &ray, unsigned int fContentsMask, trace_t& tr );
virtual void ComputeWorldSpaceSurroundingBox( Vector *pWorldMins, Vector *pWorldMaxs );
// non-virtual methods. Don't override these!
public:
// An inline version the game code can use
CCollisionProperty *CollisionProp();
const CCollisionProperty*CollisionProp() const;
CServerNetworkProperty *NetworkProp();
const CServerNetworkProperty *NetworkProp() const;
bool IsCurrentlyTouching( void ) const;
const Vector& GetAbsOrigin( void ) const;
const QAngle& GetAbsAngles( void ) const;
SolidType_t GetSolid() const;
int GetSolidFlags( void ) const;
int GetEFlags() const;
void SetEFlags( int iEFlags );
void AddEFlags( int nEFlagMask );
void RemoveEFlags( int nEFlagMask );
bool IsEFlagSet( int nEFlagMask ) const;
// Quick way to ask if we have a player entity as a child anywhere in our hierarchy.
void RecalcHasPlayerChildBit();
bool DoesHavePlayerChild();
bool IsTransparent() const;
void SetNavIgnore( float duration = FLT_MAX );
void ClearNavIgnore();
bool IsNavIgnored() const;
// Is the entity floating?
bool IsFloating();
// Called by physics to see if we should avoid a collision test....
virtual bool ShouldCollide( int collisionGroup, int contentsMask ) const;
// Move type / move collide
MoveType_t GetMoveType() const;
MoveCollide_t GetMoveCollide() const;
void SetMoveType( MoveType_t val, MoveCollide_t moveCollide = MOVECOLLIDE_DEFAULT );
void SetMoveCollide( MoveCollide_t val );
// 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 );
// 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 );
public:
void SetScaledPhysics( IPhysicsObject *pNewObject );
// virtual methods; you can override these
public:
// Owner entity.
// FIXME: These are virtual only because of CNodeEnt
CBaseEntity *GetOwnerEntity() const;
virtual void SetOwnerEntity( CBaseEntity* pOwner );
void SetEffectEntity( CBaseEntity *pEffectEnt );
CBaseEntity *GetEffectEntity() const;
HSCRIPT GetScriptOwnerEntity();
virtual void SetScriptOwnerEntity(HSCRIPT pOwner);
// Only CBaseEntity implements these. CheckTransmit calls the virtual ShouldTransmit to see if the
// entity wants to be sent. If so, it calls SetTransmit, which will mark any dependents for transmission too.
virtual int ShouldTransmit( const CCheckTransmitInfo *pInfo );
// update the global transmit state if a transmission rule changed
int SetTransmitState( int nFlag);
int GetTransmitState( void );
int DispatchUpdateTransmitState();
// Do NOT call this directly. Use DispatchUpdateTransmitState.
virtual int UpdateTransmitState();
// Entities (like ropes) use this to own the transmit state of another entity
// by forcing it to not call UpdateTransmitState.
void IncrementTransmitStateOwnedCounter();
void DecrementTransmitStateOwnedCounter();
// This marks the entity for transmission and passes the SetTransmit call to any dependents.
virtual void SetTransmit( CCheckTransmitInfo *pInfo, bool bAlways );
// This function finds out if the entity is in the 3D skybox. If so, it sets the EFL_IN_SKYBOX
// flag so the entity gets transmitted to all the clients.
// Entities usually call this during their Activate().
// Returns true if the entity is in the skybox (and EFL_IN_SKYBOX was set).
bool DetectInSkybox();
// Returns which skybox the entity is in
CSkyCamera *GetEntitySkybox();
bool IsSimulatedEveryTick() const;
bool IsAnimatedEveryTick() const;
void SetSimulatedEveryTick( bool sim );
void SetAnimatedEveryTick( bool anim );
public:
virtual const char *GetTracerType( void );
// returns a pointer to the entities edict, if it has one. should be removed!
inline edict_t *edict( void ) { return NetworkProp()->edict(); }
inline const edict_t *edict( void ) const { return NetworkProp()->edict(); }
inline int entindex( ) const { return m_Network.entindex(); };
inline int GetSoundSourceIndex() const { return entindex(); }
// These methods encapsulate MOVETYPE_FOLLOW, which became obsolete
void FollowEntity( CBaseEntity *pBaseEntity, bool bBoneMerge = true );
void StopFollowingEntity( ); // will also change to MOVETYPE_NONE
bool IsFollowingEntity();
CBaseEntity *GetFollowedEntity();
#ifdef MAPBASE_VSCRIPT
void ScriptFollowEntity( HSCRIPT hBaseEntity, bool bBoneMerge );
HSCRIPT ScriptGetFollowedEntity();
#endif
// initialization
virtual void Spawn( void );
virtual void Precache( void ) {}
virtual void SetModel( const char *szModelName );
protected:
// Notification on model load. May be called multiple times for dynamic models.
// Implementations must call BaseClass::OnNewModel and pass return value through.
virtual CStudioHdr *OnNewModel();
public:
virtual void PostConstructor( const char *szClassname );
virtual void PostClientActive( void );
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 );
bool KeyValueFromString( const char *szKeyName, const char *szValue ) { return KeyValue( szKeyName, szValue ); }
bool KeyValueFromFloat( const char *szKeyName, float flValue ) { return KeyValue( szKeyName, flValue ); }
bool KeyValueFromInt( const char *szKeyName, int nValue ) { return KeyValue( szKeyName, nValue ); }
bool KeyValueFromVector( const char *szKeyName, const Vector &vecValue ) { return KeyValue( szKeyName, vecValue ); }
void ValidateEntityConnections();
void FireNamedOutput( const char *pszOutput, variant_t variant, CBaseEntity *pActivator, CBaseEntity *pCaller, float flDelay = 0.0f );
#ifdef MAPBASE
virtual
#endif
CBaseEntityOutput *FindNamedOutput( const char *pszOutput );
#ifdef MAPBASE_VSCRIPT
void ScriptFireOutput( const char *pszOutput, HSCRIPT hActivator, HSCRIPT hCaller, const char *szValue, float flDelay );
float GetMaxOutputDelay( const char *pszOutput );
//void CancelEventsByInput( const char *szInput );
#endif
// Activate - called for each entity after each load game and level load
virtual void Activate( void );
// Hierarchy traversal
CBaseEntity *GetMoveParent( void );
CBaseEntity *GetRootMoveParent();
CBaseEntity *FirstMoveChild( void );
CBaseEntity *NextMovePeer( void );
void SetName( string_t newTarget );
#ifdef MAPBASE_VSCRIPT
void SetNameAsCStr( const char *newTarget );
#endif
void SetParent( string_t newParent, CBaseEntity *pActivator, int iAttachment = -1 );
// 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. If iAttachment == -1, it'll preserve the
// current m_iParentAttachment.
virtual void SetParent( CBaseEntity* pNewParent, int iAttachment = -1 );
CBaseEntity* GetParent();
int GetParentAttachment();
string_t GetEntityName();
const char* GetEntityNameAsCStr(); // This method is temporary for VSCRIPT functionality until we figure out what to do with string_t (sjb)
const char* GetPreTemplateName(); // Not threadsafe. Get the name stripped of template unique decoration
bool NameMatches( const char *pszNameOrWildcard );
bool NameMatches( string_t nameStr );
virtual bool ClassMatches( string_t nameStr );
virtual bool ClassMatches( const char *pszClassOrWildcard );
private:
bool NameMatchesComplex( const char *pszNameOrWildcard );
bool ClassMatchesComplex( const char *pszClassOrWildcard );
void TransformStepData_WorldToParent( CBaseEntity *pParent );
void TransformStepData_ParentToParent( CBaseEntity *pOldParent, CBaseEntity *pNewParent );
void TransformStepData_ParentToWorld( CBaseEntity *pParent );
public:
int GetSpawnFlags( void ) const;
void AddSpawnFlags( int nFlags );
void RemoveSpawnFlags( int nFlags );
void ClearSpawnFlags( void );
bool HasSpawnFlags( int nFlags ) const;
int GetEffects( void ) const;
void AddEffects( int nEffects );
void RemoveEffects( int nEffects );
void ClearEffects( void );
void SetEffects( int nEffects );
bool IsEffectActive( int nEffects ) const;
// makes the entity inactive
void MakeDormant( void );
int IsDormant( void );
void RemoveDeferred( void ); // Sets the entity invisible, and makes it remove itself on the next frame
// checks to see if the entity is marked for deletion
bool IsMarkedForDeletion( void );
// capabilities
virtual int ObjectCaps( void );
// Verifies that the data description is valid in debug builds.
#ifdef _DEBUG
void ValidateDataDescription(void);
#endif // _DEBUG
// handles an input (usually caused by outputs)
// returns true if the the value in the pass in should be set, false if the input is to be ignored
virtual bool AcceptInput( const char *szInputName, CBaseEntity *pActivator, CBaseEntity *pCaller, variant_t Value, int outputID );
#ifdef MAPBASE_VSCRIPT
bool ScriptAcceptInput(const char *szInputName, const char *szValue, HSCRIPT hActivator, HSCRIPT hCaller);
#endif
bool ScriptInputHook( const char *szInputName, CBaseEntity *pActivator, CBaseEntity *pCaller, variant_t Value, ScriptVariant_t &functionReturn );
void ScriptInputHookClearParams();
#ifdef MAPBASE_VSCRIPT
bool ScriptDeathHook( CTakeDamageInfo *info );
#endif
//
// Input handlers.
//
void InputAlternativeSorting( inputdata_t &inputdata );
void InputAlpha( inputdata_t &inputdata );
void InputColor( inputdata_t &inputdata );
void InputSetParent( inputdata_t &inputdata );
void SetParentAttachment( const char *szInputName, const char *szAttachment, bool bMaintainOffset );
void InputSetParentAttachment( inputdata_t &inputdata );
void InputSetParentAttachmentMaintainOffset( inputdata_t &inputdata );
void InputClearParent( inputdata_t &inputdata );
void InputSetTeam( inputdata_t &inputdata );
void InputUse( inputdata_t &inputdata );
void InputKill( inputdata_t &inputdata );
void InputKillHierarchy( inputdata_t &inputdata );
void InputSetDamageFilter( inputdata_t &inputdata );
void InputDispatchEffect( inputdata_t &inputdata );
void InputEnableDamageForces( inputdata_t &inputdata );
void InputDisableDamageForces( inputdata_t &inputdata );
void InputAddContext( inputdata_t &inputdata );
void InputRemoveContext( inputdata_t &inputdata );
void InputClearContext( inputdata_t &inputdata );
void InputDispatchResponse( inputdata_t& inputdata );
void InputDisableShadow( inputdata_t &inputdata );
void InputEnableShadow( inputdata_t &inputdata );
void InputAddOutput( inputdata_t &inputdata );
#ifdef MAPBASE
void InputChangeVariable( inputdata_t &inputdata );
#endif
void InputFireUser1( inputdata_t &inputdata );
void InputFireUser2( inputdata_t &inputdata );
void InputFireUser3( inputdata_t &inputdata );
void InputFireUser4( inputdata_t &inputdata );
#ifdef MAPBASE
void InputPassUser1( inputdata_t &inputdata );
void InputPassUser2( inputdata_t &inputdata );
void InputPassUser3( inputdata_t &inputdata );
void InputPassUser4( inputdata_t &inputdata );
void InputFireRandomUser( inputdata_t &inputdata );
void InputPassRandomUser( inputdata_t &inputdata );
void InputSetEntityName( inputdata_t &inputdata );
virtual void InputSetTarget( inputdata_t &inputdata );
virtual void InputSetOwnerEntity( inputdata_t &inputdata );
virtual void InputAddHealth( inputdata_t &inputdata );
virtual void InputRemoveHealth( inputdata_t &inputdata );
virtual void InputSetHealth( inputdata_t &inputdata );
virtual void InputSetMaxHealth( inputdata_t &inputdata );
void InputFireOutput( inputdata_t &inputdata );
void InputRemoveOutput( inputdata_t &inputdata );
//virtual void InputCancelOutput( inputdata_t &inputdata ); // Find a way to implement this
void InputReplaceOutput( inputdata_t &inputdata );
void InputAcceptInput( inputdata_t &inputdata );
virtual void InputCancelPending( inputdata_t &inputdata );
void InputFreeChildren( inputdata_t &inputdata );
void InputSetLocalOrigin( inputdata_t &inputdata );
void InputSetLocalAngles( inputdata_t &inputdata );
void InputSetAbsOrigin( inputdata_t &inputdata );
void InputSetAbsAngles( inputdata_t &inputdata );
void InputSetLocalVelocity( inputdata_t &inputdata );
void InputSetLocalAngularVelocity( inputdata_t &inputdata );
void InputAddSpawnFlags( inputdata_t &inputdata );
void InputRemoveSpawnFlags( inputdata_t &inputdata );
void InputSetRenderMode( inputdata_t &inputdata );
void InputSetRenderFX( inputdata_t &inputdata );
void InputSetViewHideFlags( inputdata_t &inputdata );
void InputAddEffects( inputdata_t &inputdata );
void InputRemoveEffects( inputdata_t &inputdata );
void InputDrawEntity( inputdata_t &inputdata );
void InputUndrawEntity( inputdata_t &inputdata );
void InputEnableReceivingFlashlight( inputdata_t &inputdata );
void InputDisableReceivingFlashlight( inputdata_t &inputdata );
void InputAddEFlags( inputdata_t &inputdata );
void InputRemoveEFlags( inputdata_t &inputdata );
void InputAddSolidFlags( inputdata_t &inputdata );
void InputRemoveSolidFlags( inputdata_t &inputdata );
void InputSetMoveType( inputdata_t &inputdata );
void InputSetCollisionGroup( inputdata_t &inputdata );
void InputTouch( inputdata_t &inputdata );
virtual void InputKilledNPC( inputdata_t &inputdata );
void InputKillIfNotVisible( inputdata_t &inputdata );
void InputKillWhenNotVisible( inputdata_t &inputdata );
void InputSetThinkNull( inputdata_t &inputdata );
COutputEvent m_OnKilled;
#endif
void InputRunScript(inputdata_t& inputdata);
void InputRunScriptFile(inputdata_t& inputdata);
void InputCallScriptFunction(inputdata_t& inputdata);
#ifdef MAPBASE_VSCRIPT
void InputRunScriptQuotable(inputdata_t& inputdata);
void InputClearScriptScope(inputdata_t& inputdata);
#endif
bool RunScriptFile(const char* pScriptFile, bool bUseRootScope = false);
bool RunScript(const char* pScriptText, const char* pDebugFilename = "CBaseEntity::RunScript");
// Returns the origin at which to play an inputted dispatcheffect
virtual void GetInputDispatchEffectPosition( const char *sInputString, Vector &pOrigin, QAngle &pAngles );
// tries to read a field from the entities data description - result is placed in variant_t
bool ReadKeyField( const char *varName, variant_t *var );
// classname access
void SetClassname( const char *className );
virtual const char* GetClassname();
// Debug Overlays
void EntityText( int text_offset, const char *text, float flDuration, int r = 255, int g = 255, int b = 255, int a = 255 );
const char *GetDebugName(void); // do not make this virtual -- designed to handle NULL this
virtual void DrawDebugGeometryOverlays(void);
virtual int DrawDebugTextOverlays(void);
void DrawTimedOverlays( void );
void DrawBBoxOverlay( float flDuration = 0.0f );
void DrawAbsBoxOverlay();
void DrawRBoxOverlay();
void DrawInputOverlay(const char *szInputName, CBaseEntity *pCaller, variant_t Value);
void DrawOutputOverlay(CEventAction *ev);
void SendDebugPivotOverlay( void );
void AddTimedOverlay( const char *msg, int endTime );
void SetSolid( SolidType_t val );
// save/restore
// only overload these if you have special data to serialize
virtual int Save( ISave &save );
virtual int Restore( IRestore &restore );
virtual bool ShouldSavePhysics();
// handler to reset stuff before you are restored
// NOTE: Always chain to base class when implementing this!
virtual void OnSave( IEntitySaveUtils *pSaveUtils );
// handler to reset stuff after you are restored
// called after all entities have been loaded from all affected levels
// called before activate
// NOTE: Always chain to base class when implementing this!
virtual void OnRestore();
int GetTextureFrameIndex( void );
void SetTextureFrameIndex( int iIndex );
// 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 );
#ifdef MAPBASE
// Handle a potentially complex command from a client.
// Returns true if the command was handled successfully.
virtual bool HandleEntityCommand(CBasePlayer* pClient, KeyValues* pKeyValues) { return false; }
#endif // MAPBASE
private:
int SaveDataDescBlock( ISave &save, datamap_t *dmap );
int RestoreDataDescBlock( IRestore &restore, datamap_t *dmap );
public:
// Networking related methods
void NetworkStateChanged();
void NetworkStateChanged( void *pVar );
public:
void CalcAbsolutePosition();
// returns the edict index the entity requires when used in save/restore (eg players, world)
// -1 means it doesn't require any special index
virtual int RequiredEdictIndex( void ) { return -1; }
// interface function pts
void (CBaseEntity::*m_pfnMoveDone)(void);
virtual void MoveDone( void ) { if (m_pfnMoveDone) (this->*m_pfnMoveDone)();};
// Why do we have two separate static Instance functions?
static CBaseEntity *Instance( const CBaseHandle &hEnt );
static CBaseEntity *Instance( const edict_t *pent );
static CBaseEntity *Instance( edict_t *pent );
static CBaseEntity* Instance( int iEnt );
// Think function handling
void (CBaseEntity::*m_pfnThink)(void);
virtual void Think( void ) { if (m_pfnThink) (this->*m_pfnThink)();};
// Think functions with contexts
int RegisterThinkContext( const char *szContext );
BASEPTR ThinkSet( BASEPTR func, float flNextThinkTime = 0, const char *szContext = NULL );
void SetNextThink( float nextThinkTime, const char *szContext = NULL );
float GetNextThink( const char *szContext = NULL );
float GetLastThink( const char *szContext = NULL );
int GetNextThinkTick( const char *szContext = NULL );
int GetLastThinkTick( const char *szContext = NULL );
float GetAnimTime() const;
void SetAnimTime( float at );
float GetSimulationTime() const;
void SetSimulationTime( float st );
void SetRenderMode( RenderMode_t nRenderMode );
RenderMode_t GetRenderMode() const;
private:
// NOTE: Keep this near vtable so it's in cache with vtable.
CServerNetworkProperty m_Network;
public:
// members
string_t m_iClassname; // identifier for entity creation and save/restore
string_t m_iGlobalname; // identifier for carrying entity across level transitions
string_t m_iParent; // the name of the entities parent; linked into m_pParent during Activate()
int m_iHammerID; // Hammer unique edit id number
public:
// was pev->speed
float m_flSpeed;
// was pev->renderfx
CNetworkVar( unsigned char, m_nRenderFX );
// was pev->rendermode
CNetworkVar( unsigned char, m_nRenderMode );
CNetworkVar( short, m_nModelIndex );
#ifdef TF_DLL
CNetworkArray( int, m_nModelIndexOverrides, MAX_VISION_MODES ); // used to override the base model index on the client if necessary
#endif
#ifdef MAPBASE
// Prevents this entity from drawing under certain view IDs. Each flag is (1 << the view ID to hide from).
// For example, hiding an entity from VIEW_MONITOR prevents it from showing up on RT camera monitors
// and hiding an entity from VIEW_MAIN just prevents it from showing up through the player's own "eyes".
// Doing this via flags allows for the entity to be hidden from multiple view IDs at the same time.
//
// This was partly inspired by Underhell's keyvalue that allows entities to only render in mirrors and cameras.
CNetworkVar( int, m_iViewHideFlags );
// Disables receiving projected textures. Based on a keyvalue from later Source games.
CNetworkVar( bool, m_bDisableFlashlight );
#endif
// was pev->rendercolor
CNetworkColor32( m_clrRender );
const color32 GetRenderColor() const;
void SetRenderColor( byte r, byte g, byte b );
void SetRenderColor( byte r, byte g, byte b, byte a );
void SetRenderColorR( byte r );
void SetRenderColorG( byte g );
void SetRenderColorB( byte b );
void SetRenderColorA( byte a );
// was pev->animtime: consider moving to CBaseAnimating
float m_flPrevAnimTime;
CNetworkVar( float, m_flAnimTime ); // this is the point in time that the client will interpolate to position,angle,frame,etc.
CNetworkVar( float, m_flSimulationTime );
void IncrementInterpolationFrame(); // Call this to cause a discontinuity (teleport)
CNetworkVar( int, m_ubInterpolationFrame );
int m_nLastThinkTick;
#if !defined( NO_ENTITY_PREDICTION )
// Certain entities (projectiles) can be created on the client and thus need a matching id number
CNetworkVar( CPredictableId, m_PredictableID );
#endif
// used so we know when things are no longer touching
int touchStamp;
protected:
// think function handling
enum thinkmethods_t
{
THINK_FIRE_ALL_FUNCTIONS,
THINK_FIRE_BASE_ONLY,
THINK_FIRE_ALL_BUT_BASE,