Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2693 lines
89 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef BASEENTITY_H
  8. #define BASEENTITY_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #define TEAMNUM_NUM_BITS 6
  13. #include "entitylist.h"
  14. #include "entityoutput.h"
  15. #include "networkvar.h"
  16. #include "collisionproperty.h"
  17. #include "ServerNetworkProperty.h"
  18. #include "shareddefs.h"
  19. #include "engine/ivmodelinfo.h"
  20. class CDamageModifier;
  21. class CDmgAccumulator;
  22. struct CSoundParameters;
  23. class AI_CriteriaSet;
  24. class IResponseSystem;
  25. class IEntitySaveUtils;
  26. class CRecipientFilter;
  27. class CStudioHdr;
  28. // Matching the high level concept is significantly better than other criteria
  29. // FIXME: Could do this in the script file by making it required and bumping up weighting there instead...
  30. #define CONCEPT_WEIGHT 5.0f
  31. typedef CHandle<CBaseEntity> EHANDLE;
  32. #define MANUALMODE_GETSET_PROP(type, accessorName, varName) \
  33. private:\
  34. type varName;\
  35. public:\
  36. inline const type& Get##accessorName##() const { return varName; } \
  37. inline type& Get##accessorName##() { return varName; } \
  38. inline void Set##accessorName##( const type &val ) { varName = val; m_NetStateMgr.StateChanged(); }
  39. #define MANUALMODE_GETSET_EHANDLE(type, accessorName, varName) \
  40. private:\
  41. CHandle<type> varName;\
  42. public:\
  43. inline type* Get##accessorName##() { return varName.Get(); } \
  44. inline void Set##accessorName##( type *pType ) { varName = pType; m_NetStateMgr.StateChanged(); }
  45. // saverestore.h declarations
  46. class CSaveRestoreData;
  47. struct typedescription_t;
  48. class ISave;
  49. class IRestore;
  50. class CBaseEntity;
  51. class CEntityMapData;
  52. class CBaseCombatWeapon;
  53. class IPhysicsObject;
  54. class IPhysicsShadowController;
  55. class CBaseCombatCharacter;
  56. class CTeam;
  57. class Vector;
  58. struct gamevcollisionevent_t;
  59. class CBaseAnimating;
  60. class CBasePlayer;
  61. class IServerVehicle;
  62. struct solid_t;
  63. struct notify_system_event_params_t;
  64. class CAI_BaseNPC;
  65. class CAI_Senses;
  66. class CSquadNPC;
  67. class variant_t;
  68. class CEventAction;
  69. typedef struct KeyValueData_s KeyValueData;
  70. class CUserCmd;
  71. class CSkyCamera;
  72. class CEntityMapData;
  73. class INextBot;
  74. class IHasAttributes;
  75. typedef CUtlVector< CBaseEntity* > EntityList_t;
  76. #if defined( HL2_DLL )
  77. // For CLASSIFY
  78. enum Class_T
  79. {
  80. CLASS_NONE=0,
  81. CLASS_PLAYER,
  82. CLASS_PLAYER_ALLY,
  83. CLASS_PLAYER_ALLY_VITAL,
  84. CLASS_ANTLION,
  85. CLASS_BARNACLE,
  86. CLASS_BULLSEYE,
  87. //CLASS_BULLSQUID,
  88. CLASS_CITIZEN_PASSIVE,
  89. CLASS_CITIZEN_REBEL,
  90. CLASS_COMBINE,
  91. CLASS_COMBINE_GUNSHIP,
  92. CLASS_CONSCRIPT,
  93. CLASS_HEADCRAB,
  94. //CLASS_HOUNDEYE,
  95. CLASS_MANHACK,
  96. CLASS_METROPOLICE,
  97. CLASS_MILITARY,
  98. CLASS_SCANNER,
  99. CLASS_STALKER,
  100. CLASS_VORTIGAUNT,
  101. CLASS_ZOMBIE,
  102. CLASS_PROTOSNIPER,
  103. CLASS_MISSILE,
  104. CLASS_FLARE,
  105. CLASS_EARTH_FAUNA,
  106. CLASS_HACKED_ROLLERMINE,
  107. CLASS_COMBINE_HUNTER,
  108. NUM_AI_CLASSES
  109. };
  110. #elif defined( HL1_DLL )
  111. enum Class_T
  112. {
  113. CLASS_NONE = 0,
  114. CLASS_MACHINE,
  115. CLASS_PLAYER,
  116. CLASS_HUMAN_PASSIVE,
  117. CLASS_HUMAN_MILITARY,
  118. CLASS_ALIEN_MILITARY,
  119. CLASS_ALIEN_MONSTER,
  120. CLASS_ALIEN_PREY,
  121. CLASS_ALIEN_PREDATOR,
  122. CLASS_INSECT,
  123. CLASS_PLAYER_ALLY,
  124. CLASS_PLAYER_BIOWEAPON,
  125. CLASS_ALIEN_BIOWEAPON,
  126. NUM_AI_CLASSES
  127. };
  128. #elif defined( INVASION_DLL )
  129. enum Class_T
  130. {
  131. CLASS_NONE = 0,
  132. CLASS_PLAYER,
  133. CLASS_PLAYER_ALLY,
  134. CLASS_PLAYER_ALLY_VITAL,
  135. CLASS_ANTLION,
  136. CLASS_BARNACLE,
  137. CLASS_BULLSEYE,
  138. //CLASS_BULLSQUID,
  139. CLASS_CITIZEN_PASSIVE,
  140. CLASS_CITIZEN_REBEL,
  141. CLASS_COMBINE,
  142. CLASS_COMBINE_GUNSHIP,
  143. CLASS_CONSCRIPT,
  144. CLASS_HEADCRAB,
  145. //CLASS_HOUNDEYE,
  146. CLASS_MANHACK,
  147. CLASS_METROPOLICE,
  148. CLASS_MILITARY,
  149. CLASS_SCANNER,
  150. CLASS_STALKER,
  151. CLASS_VORTIGAUNT,
  152. CLASS_ZOMBIE,
  153. CLASS_PROTOSNIPER,
  154. CLASS_MISSILE,
  155. CLASS_FLARE,
  156. CLASS_EARTH_FAUNA,
  157. NUM_AI_CLASSES
  158. };
  159. #elif defined( CSTRIKE_DLL )
  160. enum Class_T
  161. {
  162. CLASS_NONE = 0,
  163. CLASS_PLAYER,
  164. CLASS_PLAYER_ALLY,
  165. NUM_AI_CLASSES
  166. };
  167. #else
  168. enum Class_T
  169. {
  170. CLASS_NONE = 0,
  171. CLASS_PLAYER,
  172. CLASS_PLAYER_ALLY,
  173. NUM_AI_CLASSES
  174. };
  175. #endif
  176. //
  177. // Structure passed to input handlers.
  178. //
  179. struct inputdata_t
  180. {
  181. CBaseEntity *pActivator; // The entity that initially caused this chain of output events.
  182. CBaseEntity *pCaller; // The entity that fired this particular output.
  183. variant_t value; // The data parameter for this output.
  184. int nOutputID; // The unique ID of the output that was fired.
  185. };
  186. // Serializable list of context as set by entity i/o and used for deducing proper
  187. // speech state, et al.
  188. struct ResponseContext_t
  189. {
  190. DECLARE_SIMPLE_DATADESC();
  191. string_t m_iszName;
  192. string_t m_iszValue;
  193. float m_fExpirationTime; // when to expire context (0 == never)
  194. };
  195. //-----------------------------------------------------------------------------
  196. // Entity events... targetted to a particular entity
  197. // Each event has a well defined structure to use for parameters
  198. //-----------------------------------------------------------------------------
  199. enum EntityEvent_t
  200. {
  201. ENTITY_EVENT_WATER_TOUCH = 0, // No data needed
  202. ENTITY_EVENT_WATER_UNTOUCH, // No data needed
  203. ENTITY_EVENT_PARENT_CHANGED, // No data needed
  204. };
  205. //-----------------------------------------------------------------------------
  206. typedef void (CBaseEntity::*BASEPTR)(void);
  207. typedef void (CBaseEntity::*ENTITYFUNCPTR)(CBaseEntity *pOther );
  208. typedef void (CBaseEntity::*USEPTR)( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
  209. #define DEFINE_THINKFUNC( function ) DEFINE_FUNCTION_RAW( function, BASEPTR )
  210. #define DEFINE_ENTITYFUNC( function ) DEFINE_FUNCTION_RAW( function, ENTITYFUNCPTR )
  211. #define DEFINE_USEFUNC( function ) DEFINE_FUNCTION_RAW( function, USEPTR )
  212. // Things that toggle (buttons/triggers/doors) need this
  213. enum TOGGLE_STATE
  214. {
  215. TS_AT_TOP,
  216. TS_AT_BOTTOM,
  217. TS_GOING_UP,
  218. TS_GOING_DOWN
  219. };
  220. // Debug overlay bits
  221. enum DebugOverlayBits_t
  222. {
  223. OVERLAY_TEXT_BIT = 0x00000001, // show text debug overlay for this entity
  224. OVERLAY_NAME_BIT = 0x00000002, // show name debug overlay for this entity
  225. OVERLAY_BBOX_BIT = 0x00000004, // show bounding box overlay for this entity
  226. OVERLAY_PIVOT_BIT = 0x00000008, // show pivot for this entity
  227. OVERLAY_MESSAGE_BIT = 0x00000010, // show messages for this entity
  228. OVERLAY_ABSBOX_BIT = 0x00000020, // show abs bounding box overlay
  229. OVERLAY_RBOX_BIT = 0x00000040, // show the rbox overlay
  230. OVERLAY_SHOW_BLOCKSLOS = 0x00000080, // show entities that block NPC LOS
  231. OVERLAY_ATTACHMENTS_BIT = 0x00000100, // show attachment points
  232. OVERLAY_AUTOAIM_BIT = 0x00000200, // Display autoaim radius
  233. OVERLAY_NPC_SELECTED_BIT = 0x00001000, // the npc is current selected
  234. OVERLAY_NPC_NEAREST_BIT = 0x00002000, // show the nearest node of this npc
  235. OVERLAY_NPC_ROUTE_BIT = 0x00004000, // draw the route for this npc
  236. OVERLAY_NPC_TRIANGULATE_BIT = 0x00008000, // draw the triangulation for this npc
  237. OVERLAY_NPC_ZAP_BIT = 0x00010000, // destroy the NPC
  238. OVERLAY_NPC_ENEMIES_BIT = 0x00020000, // show npc's enemies
  239. OVERLAY_NPC_CONDITIONS_BIT = 0x00040000, // show NPC's current conditions
  240. OVERLAY_NPC_SQUAD_BIT = 0x00080000, // show npc squads
  241. OVERLAY_NPC_TASK_BIT = 0x00100000, // show npc task details
  242. OVERLAY_NPC_FOCUS_BIT = 0x00200000, // show line to npc's enemy and target
  243. OVERLAY_NPC_VIEWCONE_BIT = 0x00400000, // show npc's viewcone
  244. OVERLAY_NPC_KILL_BIT = 0x00800000, // kill the NPC, running all appropriate AI.
  245. OVERLAY_WC_CHANGE_ENTITY = 0x01000000, // object changed during WC edit
  246. OVERLAY_BUDDHA_MODE = 0x02000000, // take damage but don't die
  247. OVERLAY_NPC_STEERING_REGULATIONS = 0x04000000, // Show the steering regulations associated with the NPC
  248. OVERLAY_TASK_TEXT_BIT = 0x08000000, // show task and schedule names when they start
  249. OVERLAY_PROP_DEBUG = 0x10000000,
  250. OVERLAY_NPC_RELATION_BIT = 0x20000000, // show relationships between target and all children
  251. OVERLAY_VIEWOFFSET = 0x40000000, // show view offset
  252. };
  253. struct TimedOverlay_t;
  254. /* ========= CBaseEntity ========
  255. All objects in the game are derived from this.
  256. a list of all CBaseEntitys is kept in gEntList
  257. ================================ */
  258. // creates an entity by string name, but does not spawn it
  259. // If iForceEdictIndex is not -1, then it will use the edict by that index. If the index is
  260. // invalid or there is already an edict using that index, it will error out.
  261. CBaseEntity *CreateEntityByName( const char *className, int iForceEdictIndex = -1 );
  262. CBaseNetworkable *CreateNetworkableByName( const char *className );
  263. // creates an entity and calls all the necessary spawn functions
  264. extern void SpawnEntityByName( const char *className, CEntityMapData *mapData = NULL );
  265. // calls the spawn functions for an entity
  266. extern int DispatchSpawn( CBaseEntity *pEntity );
  267. inline CBaseEntity *GetContainingEntity( edict_t *pent );
  268. //-----------------------------------------------------------------------------
  269. // Purpose: think contexts
  270. //-----------------------------------------------------------------------------
  271. struct thinkfunc_t
  272. {
  273. BASEPTR m_pfnThink;
  274. string_t m_iszContext;
  275. int m_nNextThinkTick;
  276. int m_nLastThinkTick;
  277. DECLARE_SIMPLE_DATADESC();
  278. };
  279. struct EmitSound_t;
  280. struct rotatingpushmove_t;
  281. #define CREATE_PREDICTED_ENTITY( className ) \
  282. CBaseEntity::CreatePredictedEntityByName( className, __FILE__, __LINE__ );
  283. //
  284. // Base Entity. All entity types derive from this
  285. //
  286. class CBaseEntity : public IServerEntity
  287. {
  288. public:
  289. DECLARE_CLASS_NOBASE( CBaseEntity );
  290. //----------------------------------------
  291. // Class vars and functions
  292. //----------------------------------------
  293. static inline void Debug_Pause(bool bPause);
  294. static inline bool Debug_IsPaused(void);
  295. static inline void Debug_SetSteps(int nSteps);
  296. static inline bool Debug_ShouldStep(void);
  297. static inline bool Debug_Step(void);
  298. static bool m_bInDebugSelect;
  299. static int m_nDebugPlayer;
  300. protected:
  301. static bool m_bDebugPause; // Whether entity i/o is paused for debugging.
  302. static int m_nDebugSteps; // Number of entity outputs to fire before pausing again.
  303. static bool sm_bDisableTouchFuncs; // Disables PhysicsTouch and PhysicsStartTouch function calls
  304. public:
  305. static bool sm_bAccurateTriggerBboxChecks; // SOLID_BBOX entities do a fully accurate trigger vs bbox check when this is set
  306. public:
  307. // If bServerOnly is true, then the ent never goes to the client. This is used
  308. // by logical entities.
  309. CBaseEntity( bool bServerOnly=false );
  310. virtual ~CBaseEntity();
  311. // prediction system
  312. DECLARE_PREDICTABLE();
  313. // network data
  314. DECLARE_SERVERCLASS();
  315. // data description
  316. DECLARE_DATADESC();
  317. // memory handling
  318. void *operator new( size_t stAllocateBlock );
  319. void *operator new( size_t stAllocateBlock, int nBlockUse, const char *pFileName, int nLine );
  320. void operator delete( void *pMem );
  321. void operator delete( void *pMem, int nBlockUse, const char *pFileName, int nLine ) { operator delete(pMem); }
  322. // Class factory
  323. static CBaseEntity *CreatePredictedEntityByName( const char *classname, const char *module, int line, bool persist = false );
  324. // IHandleEntity overrides.
  325. public:
  326. virtual void SetRefEHandle( const CBaseHandle &handle );
  327. virtual const CBaseHandle& GetRefEHandle() const;
  328. // IServerUnknown overrides
  329. virtual ICollideable *GetCollideable();
  330. virtual IServerNetworkable *GetNetworkable();
  331. virtual CBaseEntity *GetBaseEntity();
  332. // IServerEntity overrides.
  333. public:
  334. virtual void SetModelIndex( int index );
  335. virtual int GetModelIndex( void ) const;
  336. virtual string_t GetModelName( void ) const;
  337. void ClearModelIndexOverrides( void );
  338. virtual void SetModelIndexOverride( int index, int nValue );
  339. public:
  340. // virtual methods for derived classes to override
  341. virtual bool TestCollision( const Ray_t& ray, unsigned int mask, trace_t& trace );
  342. virtual bool TestHitboxes( const Ray_t &ray, unsigned int fContentsMask, trace_t& tr );
  343. virtual void ComputeWorldSpaceSurroundingBox( Vector *pWorldMins, Vector *pWorldMaxs );
  344. // non-virtual methods. Don't override these!
  345. public:
  346. // An inline version the game code can use
  347. CCollisionProperty *CollisionProp();
  348. const CCollisionProperty*CollisionProp() const;
  349. CServerNetworkProperty *NetworkProp();
  350. const CServerNetworkProperty *NetworkProp() const;
  351. bool IsCurrentlyTouching( void ) const;
  352. const Vector& GetAbsOrigin( void ) const;
  353. const QAngle& GetAbsAngles( void ) const;
  354. SolidType_t GetSolid() const;
  355. int GetSolidFlags( void ) const;
  356. int GetEFlags() const;
  357. void SetEFlags( int iEFlags );
  358. void AddEFlags( int nEFlagMask );
  359. void RemoveEFlags( int nEFlagMask );
  360. bool IsEFlagSet( int nEFlagMask ) const;
  361. // Quick way to ask if we have a player entity as a child anywhere in our hierarchy.
  362. void RecalcHasPlayerChildBit();
  363. bool DoesHavePlayerChild();
  364. bool IsTransparent() const;
  365. void SetNavIgnore( float duration = FLT_MAX );
  366. void ClearNavIgnore();
  367. bool IsNavIgnored() const;
  368. // Is the entity floating?
  369. bool IsFloating();
  370. // Called by physics to see if we should avoid a collision test....
  371. virtual bool ShouldCollide( int collisionGroup, int contentsMask ) const;
  372. // Move type / move collide
  373. MoveType_t GetMoveType() const;
  374. MoveCollide_t GetMoveCollide() const;
  375. void SetMoveType( MoveType_t val, MoveCollide_t moveCollide = MOVECOLLIDE_DEFAULT );
  376. void SetMoveCollide( MoveCollide_t val );
  377. // Returns the entity-to-world transform
  378. matrix3x4_t &EntityToWorldTransform();
  379. const matrix3x4_t &EntityToWorldTransform() const;
  380. // Some helper methods that transform a point from entity space to world space + back
  381. void EntityToWorldSpace( const Vector &in, Vector *pOut ) const;
  382. void WorldToEntitySpace( const Vector &in, Vector *pOut ) const;
  383. // This function gets your parent's transform. If you're parented to an attachment,
  384. // this calculates the attachment's transform and gives you that.
  385. //
  386. // You must pass in tempMatrix for scratch space - it may need to fill that in and return it instead of
  387. // pointing you right at a variable in your parent.
  388. matrix3x4_t& GetParentToWorldTransform( matrix3x4_t &tempMatrix );
  389. // Externalized data objects ( see sharreddefs.h for DataObjectType_t )
  390. bool HasDataObjectType( int type ) const;
  391. void AddDataObjectType( int type );
  392. void RemoveDataObjectType( int type );
  393. void *GetDataObject( int type );
  394. void *CreateDataObject( int type );
  395. void DestroyDataObject( int type );
  396. void DestroyAllDataObjects( void );
  397. public:
  398. void SetScaledPhysics( IPhysicsObject *pNewObject );
  399. // virtual methods; you can override these
  400. public:
  401. // Owner entity.
  402. // FIXME: These are virtual only because of CNodeEnt
  403. CBaseEntity *GetOwnerEntity() const;
  404. virtual void SetOwnerEntity( CBaseEntity* pOwner );
  405. void SetEffectEntity( CBaseEntity *pEffectEnt );
  406. CBaseEntity *GetEffectEntity() const;
  407. // Only CBaseEntity implements these. CheckTransmit calls the virtual ShouldTransmit to see if the
  408. // entity wants to be sent. If so, it calls SetTransmit, which will mark any dependents for transmission too.
  409. virtual int ShouldTransmit( const CCheckTransmitInfo *pInfo );
  410. // update the global transmit state if a transmission rule changed
  411. int SetTransmitState( int nFlag);
  412. int GetTransmitState( void );
  413. int DispatchUpdateTransmitState();
  414. // Do NOT call this directly. Use DispatchUpdateTransmitState.
  415. virtual int UpdateTransmitState();
  416. // Entities (like ropes) use this to own the transmit state of another entity
  417. // by forcing it to not call UpdateTransmitState.
  418. void IncrementTransmitStateOwnedCounter();
  419. void DecrementTransmitStateOwnedCounter();
  420. // This marks the entity for transmission and passes the SetTransmit call to any dependents.
  421. virtual void SetTransmit( CCheckTransmitInfo *pInfo, bool bAlways );
  422. // This function finds out if the entity is in the 3D skybox. If so, it sets the EFL_IN_SKYBOX
  423. // flag so the entity gets transmitted to all the clients.
  424. // Entities usually call this during their Activate().
  425. // Returns true if the entity is in the skybox (and EFL_IN_SKYBOX was set).
  426. bool DetectInSkybox();
  427. // Returns which skybox the entity is in
  428. CSkyCamera *GetEntitySkybox();
  429. bool IsSimulatedEveryTick() const;
  430. bool IsAnimatedEveryTick() const;
  431. void SetSimulatedEveryTick( bool sim );
  432. void SetAnimatedEveryTick( bool anim );
  433. public:
  434. virtual const char *GetTracerType( void );
  435. // returns a pointer to the entities edict, if it has one. should be removed!
  436. inline edict_t *edict( void ) { return NetworkProp()->edict(); }
  437. inline const edict_t *edict( void ) const { return NetworkProp()->edict(); }
  438. inline int entindex( ) const { return m_Network.entindex(); };
  439. inline int GetSoundSourceIndex() const { return entindex(); }
  440. // These methods encapsulate MOVETYPE_FOLLOW, which became obsolete
  441. void FollowEntity( CBaseEntity *pBaseEntity, bool bBoneMerge = true );
  442. void StopFollowingEntity( ); // will also change to MOVETYPE_NONE
  443. bool IsFollowingEntity();
  444. CBaseEntity *GetFollowedEntity();
  445. // initialization
  446. virtual void Spawn( void );
  447. virtual void Precache( void ) {}
  448. virtual void SetModel( const char *szModelName );
  449. protected:
  450. // Notification on model load. May be called multiple times for dynamic models.
  451. // Implementations must call BaseClass::OnNewModel and pass return value through.
  452. virtual CStudioHdr *OnNewModel();
  453. public:
  454. virtual void PostConstructor( const char *szClassname );
  455. virtual void PostClientActive( void );
  456. virtual void ParseMapData( CEntityMapData *mapData );
  457. virtual bool KeyValue( const char *szKeyName, const char *szValue );
  458. virtual bool KeyValue( const char *szKeyName, float flValue );
  459. virtual bool KeyValue( const char *szKeyName, const Vector &vecValue );
  460. virtual bool GetKeyValue( const char *szKeyName, char *szValue, int iMaxLen );
  461. void ValidateEntityConnections();
  462. void FireNamedOutput( const char *pszOutput, variant_t variant, CBaseEntity *pActivator, CBaseEntity *pCaller, float flDelay = 0.0f );
  463. // Activate - called for each entity after each load game and level load
  464. virtual void Activate( void );
  465. // Hierarchy traversal
  466. CBaseEntity *GetMoveParent( void );
  467. CBaseEntity *GetRootMoveParent();
  468. CBaseEntity *FirstMoveChild( void );
  469. CBaseEntity *NextMovePeer( void );
  470. void SetName( string_t newTarget );
  471. void SetParent( string_t newParent, CBaseEntity *pActivator, int iAttachment = -1 );
  472. // Set the movement parent. Your local origin and angles will become relative to this parent.
  473. // If iAttachment is a valid attachment on the parent, then your local origin and angles
  474. // are relative to the attachment on this entity. If iAttachment == -1, it'll preserve the
  475. // current m_iParentAttachment.
  476. virtual void SetParent( CBaseEntity* pNewParent, int iAttachment = -1 );
  477. CBaseEntity* GetParent();
  478. int GetParentAttachment();
  479. string_t GetEntityName();
  480. bool NameMatches( const char *pszNameOrWildcard );
  481. bool ClassMatches( const char *pszClassOrWildcard );
  482. bool NameMatches( string_t nameStr );
  483. bool ClassMatches( string_t nameStr );
  484. private:
  485. bool NameMatchesComplex( const char *pszNameOrWildcard );
  486. bool ClassMatchesComplex( const char *pszClassOrWildcard );
  487. void TransformStepData_WorldToParent( CBaseEntity *pParent );
  488. void TransformStepData_ParentToParent( CBaseEntity *pOldParent, CBaseEntity *pNewParent );
  489. void TransformStepData_ParentToWorld( CBaseEntity *pParent );
  490. public:
  491. int GetSpawnFlags( void ) const;
  492. void AddSpawnFlags( int nFlags );
  493. void RemoveSpawnFlags( int nFlags );
  494. void ClearSpawnFlags( void );
  495. bool HasSpawnFlags( int nFlags ) const;
  496. int GetEffects( void ) const;
  497. void AddEffects( int nEffects );
  498. void RemoveEffects( int nEffects );
  499. void ClearEffects( void );
  500. void SetEffects( int nEffects );
  501. bool IsEffectActive( int nEffects ) const;
  502. // makes the entity inactive
  503. void MakeDormant( void );
  504. int IsDormant( void );
  505. void RemoveDeferred( void ); // Sets the entity invisible, and makes it remove itself on the next frame
  506. // checks to see if the entity is marked for deletion
  507. bool IsMarkedForDeletion( void );
  508. // capabilities
  509. virtual int ObjectCaps( void );
  510. // Verifies that the data description is valid in debug builds.
  511. #ifdef _DEBUG
  512. void ValidateDataDescription(void);
  513. #endif // _DEBUG
  514. // handles an input (usually caused by outputs)
  515. // returns true if the the value in the pass in should be set, false if the input is to be ignored
  516. virtual bool AcceptInput( const char *szInputName, CBaseEntity *pActivator, CBaseEntity *pCaller, variant_t Value, int outputID );
  517. //
  518. // Input handlers.
  519. //
  520. void InputAlternativeSorting( inputdata_t &inputdata );
  521. void InputAlpha( inputdata_t &inputdata );
  522. void InputColor( inputdata_t &inputdata );
  523. void InputSetParent( inputdata_t &inputdata );
  524. void SetParentAttachment( const char *szInputName, const char *szAttachment, bool bMaintainOffset );
  525. void InputSetParentAttachment( inputdata_t &inputdata );
  526. void InputSetParentAttachmentMaintainOffset( inputdata_t &inputdata );
  527. void InputClearParent( inputdata_t &inputdata );
  528. void InputSetTeam( inputdata_t &inputdata );
  529. void InputUse( inputdata_t &inputdata );
  530. void InputKill( inputdata_t &inputdata );
  531. void InputKillHierarchy( inputdata_t &inputdata );
  532. void InputSetDamageFilter( inputdata_t &inputdata );
  533. void InputDispatchEffect( inputdata_t &inputdata );
  534. void InputEnableDamageForces( inputdata_t &inputdata );
  535. void InputDisableDamageForces( inputdata_t &inputdata );
  536. void InputAddContext( inputdata_t &inputdata );
  537. void InputRemoveContext( inputdata_t &inputdata );
  538. void InputClearContext( inputdata_t &inputdata );
  539. void InputDispatchResponse( inputdata_t& inputdata );
  540. void InputDisableShadow( inputdata_t &inputdata );
  541. void InputEnableShadow( inputdata_t &inputdata );
  542. void InputAddOutput( inputdata_t &inputdata );
  543. void InputFireUser1( inputdata_t &inputdata );
  544. void InputFireUser2( inputdata_t &inputdata );
  545. void InputFireUser3( inputdata_t &inputdata );
  546. void InputFireUser4( inputdata_t &inputdata );
  547. // Returns the origin at which to play an inputted dispatcheffect
  548. virtual void GetInputDispatchEffectPosition( const char *sInputString, Vector &pOrigin, QAngle &pAngles );
  549. // tries to read a field from the entities data description - result is placed in variant_t
  550. bool ReadKeyField( const char *varName, variant_t *var );
  551. // classname access
  552. void SetClassname( const char *className );
  553. const char* GetClassname();
  554. // Debug Overlays
  555. void EntityText( int text_offset, const char *text, float flDuration, int r = 255, int g = 255, int b = 255, int a = 255 );
  556. const char *GetDebugName(void); // do not make this virtual -- designed to handle NULL this
  557. virtual void DrawDebugGeometryOverlays(void);
  558. virtual int DrawDebugTextOverlays(void);
  559. void DrawTimedOverlays( void );
  560. void DrawBBoxOverlay( float flDuration = 0.0f );
  561. void DrawAbsBoxOverlay();
  562. void DrawRBoxOverlay();
  563. void DrawInputOverlay(const char *szInputName, CBaseEntity *pCaller, variant_t Value);
  564. void DrawOutputOverlay(CEventAction *ev);
  565. void SendDebugPivotOverlay( void );
  566. void AddTimedOverlay( const char *msg, int endTime );
  567. void SetSolid( SolidType_t val );
  568. // save/restore
  569. // only overload these if you have special data to serialize
  570. virtual int Save( ISave &save );
  571. virtual int Restore( IRestore &restore );
  572. virtual bool ShouldSavePhysics();
  573. // handler to reset stuff before you are restored
  574. // NOTE: Always chain to base class when implementing this!
  575. virtual void OnSave( IEntitySaveUtils *pSaveUtils );
  576. // handler to reset stuff after you are restored
  577. // called after all entities have been loaded from all affected levels
  578. // called before activate
  579. // NOTE: Always chain to base class when implementing this!
  580. virtual void OnRestore();
  581. int GetTextureFrameIndex( void );
  582. void SetTextureFrameIndex( int iIndex );
  583. // Entities block Line-Of-Sight for NPCs by default.
  584. // Set this to false if you want to change this behavior.
  585. void SetBlocksLOS( bool bBlocksLOS );
  586. bool BlocksLOS( void );
  587. void SetAIWalkable( bool bBlocksLOS );
  588. bool IsAIWalkable( void );
  589. private:
  590. int SaveDataDescBlock( ISave &save, datamap_t *dmap );
  591. int RestoreDataDescBlock( IRestore &restore, datamap_t *dmap );
  592. public:
  593. // Networking related methods
  594. void NetworkStateChanged();
  595. void NetworkStateChanged( void *pVar );
  596. public:
  597. void CalcAbsolutePosition();
  598. // returns the edict index the entity requires when used in save/restore (eg players, world)
  599. // -1 means it doesn't require any special index
  600. virtual int RequiredEdictIndex( void ) { return -1; }
  601. // interface function pts
  602. void (CBaseEntity::*m_pfnMoveDone)(void);
  603. virtual void MoveDone( void ) { if (m_pfnMoveDone) (this->*m_pfnMoveDone)();};
  604. // Why do we have two separate static Instance functions?
  605. static CBaseEntity *Instance( const CBaseHandle &hEnt );
  606. static CBaseEntity *Instance( const edict_t *pent );
  607. static CBaseEntity *Instance( edict_t *pent );
  608. static CBaseEntity* Instance( int iEnt );
  609. // Think function handling
  610. void (CBaseEntity::*m_pfnThink)(void);
  611. virtual void Think( void ) { if (m_pfnThink) (this->*m_pfnThink)();};
  612. // Think functions with contexts
  613. int RegisterThinkContext( const char *szContext );
  614. BASEPTR ThinkSet( BASEPTR func, float flNextThinkTime = 0, const char *szContext = NULL );
  615. void SetNextThink( float nextThinkTime, const char *szContext = NULL );
  616. float GetNextThink( const char *szContext = NULL );
  617. float GetLastThink( const char *szContext = NULL );
  618. int GetNextThinkTick( const char *szContext = NULL );
  619. int GetLastThinkTick( const char *szContext = NULL );
  620. float GetAnimTime() const;
  621. void SetAnimTime( float at );
  622. float GetSimulationTime() const;
  623. void SetSimulationTime( float st );
  624. void SetRenderMode( RenderMode_t nRenderMode );
  625. RenderMode_t GetRenderMode() const;
  626. private:
  627. // NOTE: Keep this near vtable so it's in cache with vtable.
  628. CServerNetworkProperty m_Network;
  629. public:
  630. // members
  631. string_t m_iClassname; // identifier for entity creation and save/restore
  632. string_t m_iGlobalname; // identifier for carrying entity across level transitions
  633. string_t m_iParent; // the name of the entities parent; linked into m_pParent during Activate()
  634. int m_iHammerID; // Hammer unique edit id number
  635. public:
  636. // was pev->speed
  637. float m_flSpeed;
  638. // was pev->renderfx
  639. CNetworkVar( unsigned char, m_nRenderFX );
  640. // was pev->rendermode
  641. CNetworkVar( unsigned char, m_nRenderMode );
  642. CNetworkVar( short, m_nModelIndex );
  643. #ifdef TF_DLL
  644. CNetworkArray( int, m_nModelIndexOverrides, MAX_VISION_MODES ); // used to override the base model index on the client if necessary
  645. #endif
  646. // was pev->rendercolor
  647. CNetworkColor32( m_clrRender );
  648. const color32 GetRenderColor() const;
  649. void SetRenderColor( byte r, byte g, byte b );
  650. void SetRenderColor( byte r, byte g, byte b, byte a );
  651. void SetRenderColorR( byte r );
  652. void SetRenderColorG( byte g );
  653. void SetRenderColorB( byte b );
  654. void SetRenderColorA( byte a );
  655. // was pev->animtime: consider moving to CBaseAnimating
  656. float m_flPrevAnimTime;
  657. CNetworkVar( float, m_flAnimTime ); // this is the point in time that the client will interpolate to position,angle,frame,etc.
  658. CNetworkVar( float, m_flSimulationTime );
  659. void IncrementInterpolationFrame(); // Call this to cause a discontinuity (teleport)
  660. CNetworkVar( int, m_ubInterpolationFrame );
  661. int m_nLastThinkTick;
  662. #if !defined( NO_ENTITY_PREDICTION )
  663. // Certain entities (projectiles) can be created on the client and thus need a matching id number
  664. CNetworkVar( CPredictableId, m_PredictableID );
  665. #endif
  666. // used so we know when things are no longer touching
  667. int touchStamp;
  668. protected:
  669. // think function handling
  670. enum thinkmethods_t
  671. {
  672. THINK_FIRE_ALL_FUNCTIONS,
  673. THINK_FIRE_BASE_ONLY,
  674. THINK_FIRE_ALL_BUT_BASE,
  675. };
  676. int GetIndexForThinkContext( const char *pszContext );
  677. CUtlVector< thinkfunc_t > m_aThinkFunctions;
  678. #ifdef _DEBUG
  679. int m_iCurrentThinkContext;
  680. #endif
  681. void RemoveExpiredConcepts( void );
  682. int GetContextCount() const; // Call RemoveExpiredConcepts to clean out expired concepts
  683. const char *GetContextName( int index ) const; // note: context may be expired
  684. const char *GetContextValue( int index ) const; // note: context may be expired
  685. bool ContextExpired( int index ) const;
  686. int FindContextByName( const char *name ) const;
  687. public:
  688. void AddContext( const char *nameandvalue );
  689. protected:
  690. CUtlVector< ResponseContext_t > m_ResponseContexts;
  691. // Map defined context sets
  692. string_t m_iszResponseContext;
  693. private:
  694. CBaseEntity( CBaseEntity& );
  695. // list handling
  696. friend class CGlobalEntityList;
  697. friend class CThinkSyncTester;
  698. // was pev->nextthink
  699. CNetworkVarForDerived( int, m_nNextThinkTick );
  700. // was pev->effects
  701. CNetworkVar( int, m_fEffects );
  702. ////////////////////////////////////////////////////////////////////////////
  703. public:
  704. // Returns a CBaseAnimating if the entity is derived from CBaseAnimating.
  705. virtual CBaseAnimating* GetBaseAnimating() { return 0; }
  706. virtual IResponseSystem *GetResponseSystem();
  707. virtual void DispatchResponse( const char *conceptName );
  708. // Classify - returns the type of group (i.e, "houndeye", or "human military" so that NPCs with different classnames
  709. // still realize that they are teammates. (overridden for NPCs that form groups)
  710. virtual Class_T Classify ( void );
  711. virtual void DeathNotice ( CBaseEntity *pVictim ) {}// NPC maker children use this to tell the NPC maker that they have died.
  712. virtual bool ShouldAttractAutoAim( CBaseEntity *pAimingEnt ) { return ((GetFlags() & FL_AIMTARGET) != 0); }
  713. virtual float GetAutoAimRadius();
  714. virtual Vector GetAutoAimCenter() { return WorldSpaceCenter(); }
  715. virtual ITraceFilter* GetBeamTraceFilter( void );
  716. // Call this to do a TraceAttack on an entity, performs filtering. Don't call TraceAttack() directly except when chaining up to base class
  717. void DispatchTraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator = NULL );
  718. virtual bool PassesDamageFilter( const CTakeDamageInfo &info );
  719. protected:
  720. virtual void TraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator = NULL );
  721. public:
  722. virtual bool CanBeHitByMeleeAttack( CBaseEntity *pAttacker ) { return true; }
  723. // returns the amount of damage inflicted
  724. virtual int OnTakeDamage( const CTakeDamageInfo &info );
  725. // This is what you should call to apply damage to an entity.
  726. int TakeDamage( const CTakeDamageInfo &info );
  727. virtual void AdjustDamageDirection( const CTakeDamageInfo &info, Vector &dir, CBaseEntity *pEnt ) {}
  728. virtual int TakeHealth( float flHealth, int bitsDamageType );
  729. virtual bool IsAlive( void );
  730. // Entity killed (only fired once)
  731. virtual void Event_Killed( const CTakeDamageInfo &info );
  732. void SendOnKilledGameEvent( const CTakeDamageInfo &info );
  733. // Notifier that I've killed some other entity. (called from Victim's Event_Killed).
  734. virtual void Event_KilledOther( CBaseEntity *pVictim, const CTakeDamageInfo &info ) { return; }
  735. // UNDONE: Make this data?
  736. virtual int BloodColor( void );
  737. void TraceBleed( float flDamage, const Vector &vecDir, trace_t *ptr, int bitsDamageType );
  738. virtual bool IsTriggered( CBaseEntity *pActivator ) {return true;}
  739. virtual bool IsNPC( void ) const { return false; }
  740. CAI_BaseNPC *MyNPCPointer( void );
  741. virtual CBaseCombatCharacter *MyCombatCharacterPointer( void ) { return NULL; }
  742. virtual INextBot *MyNextBotPointer( void ) { return NULL; }
  743. virtual float GetDelay( void ) { return 0; }
  744. virtual bool IsMoving( void );
  745. bool IsWorld() { return entindex() == 0; }
  746. virtual char const *DamageDecal( int bitsDamageType, int gameMaterial );
  747. virtual void DecalTrace( trace_t *pTrace, char const *decalName );
  748. virtual void ImpactTrace( trace_t *pTrace, int iDamageType, const char *pCustomImpactName = NULL );
  749. void AddPoints( int score, bool bAllowNegativeScore );
  750. void AddPointsToTeam( int score, bool bAllowNegativeScore );
  751. void RemoveAllDecals( void );
  752. virtual bool OnControls( CBaseEntity *pControls ) { return false; }
  753. virtual bool HasTarget( string_t targetname );
  754. virtual bool IsPlayer( void ) const { return false; }
  755. virtual bool IsNetClient( void ) const { return false; }
  756. virtual bool IsTemplate( void ) { return false; }
  757. virtual bool IsBaseObject( void ) const { return false; }
  758. virtual bool IsBaseTrain( void ) const { return false; }
  759. bool IsBSPModel() const;
  760. bool IsCombatCharacter() { return MyCombatCharacterPointer() == NULL ? false : true; }
  761. bool IsInWorld( void ) const;
  762. virtual bool IsCombatItem( void ) const { return false; }
  763. virtual bool IsBaseCombatWeapon( void ) const { return false; }
  764. virtual bool IsWearable( void ) const { return false; }
  765. virtual CBaseCombatWeapon *MyCombatWeaponPointer( void ) { return NULL; }
  766. // If this is a vehicle, returns the vehicle interface
  767. virtual IServerVehicle* GetServerVehicle() { return NULL; }
  768. // UNDONE: Make this data instead of procedural?
  769. virtual bool IsViewable( void ); // is this something that would be looked at (model, sprite, etc.)?
  770. // Team Handling
  771. CTeam *GetTeam( void ) const; // Get the Team this entity is on
  772. int GetTeamNumber( void ) const; // Get the Team number of the team this entity is on
  773. virtual void ChangeTeam( int iTeamNum ); // Assign this entity to a team.
  774. bool IsInTeam( CTeam *pTeam ) const; // Returns true if this entity's in the specified team
  775. bool InSameTeam( const CBaseEntity *pEntity ) const; // Returns true if the specified entity is on the same team as this one
  776. bool IsInAnyTeam( void ) const; // Returns true if this entity is in any team
  777. const char *TeamID( void ) const; // Returns the name of the team this entity is on.
  778. // Entity events... these are events targetted to a particular entity
  779. // Each event defines its own well-defined event data structure
  780. virtual void OnEntityEvent( EntityEvent_t event, void *pEventData );
  781. // can stand on this entity?
  782. bool IsStandable() const;
  783. // UNDONE: Do these three functions actually need to be virtual???
  784. virtual bool CanStandOn( CBaseEntity *pSurface ) const { return (pSurface && !pSurface->IsStandable()) ? false : true; }
  785. virtual bool CanStandOn( edict_t *ent ) const { return CanStandOn( GetContainingEntity( ent ) ); }
  786. virtual CBaseEntity *GetEnemy( void ) { return NULL; }
  787. virtual CBaseEntity *GetEnemy( void ) const { return NULL; }
  788. void ViewPunch( const QAngle &angleOffset );
  789. void VelocityPunch( const Vector &vecForce );
  790. CBaseEntity *GetNextTarget( void );
  791. // fundamental callbacks
  792. void (CBaseEntity ::*m_pfnTouch)( CBaseEntity *pOther );
  793. void (CBaseEntity ::*m_pfnUse)( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
  794. void (CBaseEntity ::*m_pfnBlocked)( CBaseEntity *pOther );
  795. virtual void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
  796. virtual void StartTouch( CBaseEntity *pOther );
  797. virtual void Touch( CBaseEntity *pOther );
  798. virtual void EndTouch( CBaseEntity *pOther );
  799. virtual void StartBlocked( CBaseEntity *pOther ) {}
  800. virtual void Blocked( CBaseEntity *pOther );
  801. virtual void EndBlocked( void ) {}
  802. // Physics simulation
  803. virtual void PhysicsSimulate( void );
  804. public:
  805. // HACKHACK:Get the trace_t from the last physics touch call (replaces the even-hackier global trace vars)
  806. static const trace_t & GetTouchTrace( void );
  807. // FIXME: Should be private, but I can't make em private just yet
  808. void PhysicsImpact( CBaseEntity *other, trace_t &trace );
  809. void PhysicsMarkEntitiesAsTouching( CBaseEntity *other, trace_t &trace );
  810. void PhysicsMarkEntitiesAsTouchingEventDriven( CBaseEntity *other, trace_t &trace );
  811. void PhysicsTouchTriggers( const Vector *pPrevAbsOrigin = NULL );
  812. // Physics helper
  813. static void PhysicsRemoveTouchedList( CBaseEntity *ent );
  814. static void PhysicsNotifyOtherOfUntouch( CBaseEntity *ent, CBaseEntity *other );
  815. static void PhysicsRemoveToucher( CBaseEntity *other, touchlink_t *link );
  816. groundlink_t *AddEntityToGroundList( CBaseEntity *other );
  817. void PhysicsStartGroundContact( CBaseEntity *pentOther );
  818. static void PhysicsNotifyOtherOfGroundRemoval( CBaseEntity *ent, CBaseEntity *other );
  819. static void PhysicsRemoveGround( CBaseEntity *other, groundlink_t *link );
  820. static void PhysicsRemoveGroundList( CBaseEntity *ent );
  821. void StartGroundContact( CBaseEntity *ground );
  822. void EndGroundContact( CBaseEntity *ground );
  823. void SetGroundChangeTime( float flTime );
  824. float GetGroundChangeTime( void );
  825. // Remove this as ground entity for all object resting on this object
  826. void WakeRestingObjects();
  827. bool HasNPCsOnIt();
  828. virtual void UpdateOnRemove( void );
  829. virtual void StopLoopingSounds( void ) {}
  830. // common member functions
  831. void SUB_Remove( void );
  832. void SUB_DoNothing( void );
  833. void SUB_StartFadeOut( float delay = 10.0f, bool bNotSolid = true );
  834. void SUB_StartFadeOutInstant();
  835. void SUB_FadeOut ( void );
  836. void SUB_Vanish( void );
  837. void SUB_CallUseToggle( void ) { this->Use( this, this, USE_TOGGLE, 0 ); }
  838. void SUB_PerformFadeOut( void );
  839. virtual bool SUB_AllowedToFade( void );
  840. // change position, velocity, orientation instantly
  841. // passing NULL means no change
  842. virtual void Teleport( const Vector *newPosition, const QAngle *newAngles, const Vector *newVelocity );
  843. // notify that another entity (that you were watching) was teleported
  844. virtual void NotifySystemEvent( CBaseEntity *pNotify, notify_system_event_t eventType, const notify_system_event_params_t &params );
  845. int ShouldToggle( USE_TYPE useType, int currentState );
  846. // UNDONE: Move these virtuals to CBaseCombatCharacter?
  847. virtual void MakeTracer( const Vector &vecTracerSrc, const trace_t &tr, int iTracerType );
  848. virtual int GetTracerAttachment( void );
  849. virtual void FireBullets( const FireBulletsInfo_t &info );
  850. virtual void DoImpactEffect( trace_t &tr, int nDamageType ); // give shooter a chance to do a custom impact.
  851. // OLD VERSION! Use the struct version
  852. void FireBullets( int cShots, const Vector &vecSrc, const Vector &vecDirShooting,
  853. const Vector &vecSpread, float flDistance, int iAmmoType, int iTracerFreq = 4,
  854. int firingEntID = -1, int attachmentID = -1, int iDamage = 0,
  855. CBaseEntity *pAttacker = NULL, bool bFirstShotAccurate = false, bool bPrimaryAttack = true );
  856. virtual void ModifyFireBulletsDamage( CTakeDamageInfo* dmgInfo ) {}
  857. virtual CBaseEntity *Respawn( void ) { return NULL; }
  858. // Method used to deal with attacks passing through triggers
  859. void TraceAttackToTriggers( const CTakeDamageInfo &info, const Vector& start, const Vector& end, const Vector& dir );
  860. // Do the bounding boxes of these two intersect?
  861. bool Intersects( CBaseEntity *pOther );
  862. virtual bool IsLockedByMaster( void ) { return false; }
  863. // Health accessors.
  864. virtual int GetMaxHealth() const { return m_iMaxHealth; }
  865. void SetMaxHealth( int amt ) { m_iMaxHealth = amt; }
  866. int GetHealth() const { return m_iHealth; }
  867. void SetHealth( int amt ) { m_iHealth = amt; }
  868. float HealthFraction() const;
  869. // Ugly code to lookup all functions to make sure they are in the table when set.
  870. #ifdef _DEBUG
  871. #ifdef GNUC
  872. #define ENTITYFUNCPTR_SIZE 8
  873. #else
  874. #define ENTITYFUNCPTR_SIZE 4
  875. #endif
  876. void FunctionCheck( void *pFunction, const char *name );
  877. ENTITYFUNCPTR TouchSet( ENTITYFUNCPTR func, char *name )
  878. {
  879. COMPILE_TIME_ASSERT( sizeof(func) == ENTITYFUNCPTR_SIZE );
  880. m_pfnTouch = func;
  881. FunctionCheck( *(reinterpret_cast<void **>(&m_pfnTouch)), name );
  882. return func;
  883. }
  884. USEPTR UseSet( USEPTR func, char *name )
  885. {
  886. COMPILE_TIME_ASSERT( sizeof(func) == ENTITYFUNCPTR_SIZE );
  887. m_pfnUse = func;
  888. FunctionCheck( *(reinterpret_cast<void **>(&m_pfnUse)), name );
  889. return func;
  890. }
  891. ENTITYFUNCPTR BlockedSet( ENTITYFUNCPTR func, char *name )
  892. {
  893. COMPILE_TIME_ASSERT( sizeof(func) == ENTITYFUNCPTR_SIZE );
  894. m_pfnBlocked = func;
  895. FunctionCheck( *(reinterpret_cast<void **>(&m_pfnBlocked)), name );
  896. return func;
  897. }
  898. #endif // _DEBUG
  899. virtual void ModifyOrAppendCriteria( AI_CriteriaSet& set );
  900. void AppendContextToCriteria( AI_CriteriaSet& set, const char *prefix = "" );
  901. void DumpResponseCriteria( void );
  902. // Return the IHasAttributes interface for this base entity. Removes the need for:
  903. // dynamic_cast< IHasAttributes * >( pEntity );
  904. // Which is remarkably slow.
  905. // GetAttribInterface( CBaseEntity *pEntity ) in attribute_manager.h uses
  906. // this function, tests for NULL, and Asserts m_pAttributes == dynamic_cast.
  907. inline IHasAttributes *GetHasAttributesInterfacePtr() const { return m_pAttributes; }
  908. protected:
  909. // NOTE: m_pAttributes needs to be set in the leaf class constructor.
  910. IHasAttributes *m_pAttributes;
  911. private:
  912. friend class CAI_Senses;
  913. CBaseEntity *m_pLink;// used for temporary link-list operations.
  914. public:
  915. // variables promoted from edict_t
  916. string_t m_target;
  917. CNetworkVarForDerived( int, m_iMaxHealth ); // CBaseEntity doesn't care about changes to this variable, but there are derived classes that do.
  918. CNetworkVarForDerived( int, m_iHealth );
  919. CNetworkVarForDerived( char, m_lifeState );
  920. CNetworkVarForDerived( char , m_takedamage );
  921. // Damage filtering
  922. string_t m_iszDamageFilterName; // The name of the entity to use as our damage filter.
  923. EHANDLE m_hDamageFilter; // The entity that controls who can damage us.
  924. // Debugging / devolopment fields
  925. int m_debugOverlays; // For debug only (bitfields)
  926. TimedOverlay_t* m_pTimedOverlay; // For debug only
  927. // virtual functions used by a few classes
  928. // creates an entity of a specified class, by name
  929. static CBaseEntity *Create( const char *szName, const Vector &vecOrigin, const QAngle &vecAngles, CBaseEntity *pOwner = NULL );
  930. static CBaseEntity *CreateNoSpawn( const char *szName, const Vector &vecOrigin, const QAngle &vecAngles, CBaseEntity *pOwner = NULL );
  931. // Collision group accessors
  932. int GetCollisionGroup() const;
  933. void SetCollisionGroup( int collisionGroup );
  934. void CollisionRulesChanged();
  935. // Damage accessors
  936. virtual int GetDamageType() const;
  937. virtual float GetDamage() { return 0; }
  938. virtual void SetDamage(float flDamage) {}
  939. virtual Vector EyePosition( void ); // position of eyes
  940. virtual const QAngle &EyeAngles( void ); // Direction of eyes in world space
  941. virtual const QAngle &LocalEyeAngles( void ); // Direction of eyes
  942. virtual Vector EarPosition( void ); // position of ears
  943. Vector EyePosition( void ) const; // position of eyes
  944. const QAngle &EyeAngles( void ) const; // Direction of eyes in world space
  945. const QAngle &LocalEyeAngles( void ) const; // Direction of eyes
  946. Vector EarPosition( void ) const; // position of ears
  947. virtual Vector BodyTarget( const Vector &posSrc, bool bNoisy = true); // position to shoot at
  948. virtual Vector HeadTarget( const Vector &posSrc );
  949. virtual void GetVectors(Vector* forward, Vector* right, Vector* up) const;
  950. virtual const Vector &GetViewOffset() const;
  951. virtual void SetViewOffset( const Vector &v );
  952. // NOTE: Setting the abs velocity in either space will cause a recomputation
  953. // in the other space, so setting the abs velocity will also set the local vel
  954. void SetLocalVelocity( const Vector &vecVelocity );
  955. void ApplyLocalVelocityImpulse( const Vector &vecImpulse );
  956. void SetAbsVelocity( const Vector &vecVelocity );
  957. void ApplyAbsVelocityImpulse( const Vector &vecImpulse );
  958. void ApplyLocalAngularVelocityImpulse( const AngularImpulse &angImpulse );
  959. const Vector& GetLocalVelocity( ) const;
  960. const Vector& GetAbsVelocity( ) const;
  961. // NOTE: Setting the abs velocity in either space will cause a recomputation
  962. // in the other space, so setting the abs velocity will also set the local vel
  963. void SetLocalAngularVelocity( const QAngle &vecAngVelocity );
  964. const QAngle& GetLocalAngularVelocity( ) const;
  965. // FIXME: While we're using (dPitch, dYaw, dRoll) as our local angular velocity
  966. // representation, we can't actually solve this problem
  967. // void SetAbsAngularVelocity( const QAngle &vecAngVelocity );
  968. // const QAngle& GetAbsAngularVelocity( ) const;
  969. const Vector& GetBaseVelocity() const;
  970. void SetBaseVelocity( const Vector& v );
  971. virtual Vector GetSmoothedVelocity( void );
  972. // FIXME: Figure out what to do about this
  973. virtual void GetVelocity(Vector *vVelocity, AngularImpulse *vAngVelocity = NULL);
  974. float GetGravity( void ) const;
  975. void SetGravity( float gravity );
  976. float GetFriction( void ) const;
  977. void SetFriction( float flFriction );
  978. virtual bool FVisible ( CBaseEntity *pEntity, int traceMask = MASK_BLOCKLOS, CBaseEntity **ppBlocker = NULL );
  979. virtual bool FVisible( const Vector &vecTarget, int traceMask = MASK_BLOCKLOS, CBaseEntity **ppBlocker = NULL );
  980. virtual bool CanBeSeenBy( CAI_BaseNPC *pNPC ) { return true; } // allows entities to be 'invisible' to NPC senses.
  981. // This function returns a value that scales all damage done by this entity.
  982. // Use CDamageModifier to hook in damage modifiers on a guy.
  983. virtual float GetAttackDamageScale( CBaseEntity *pVictim );
  984. // This returns a value that scales all damage done to this entity
  985. // Use CDamageModifier to hook in damage modifiers on a guy.
  986. virtual float GetReceivedDamageScale( CBaseEntity *pAttacker );
  987. void SetCheckUntouch( bool check );
  988. bool GetCheckUntouch() const;
  989. void SetGroundEntity( CBaseEntity *ground );
  990. CBaseEntity *GetGroundEntity( void );
  991. CBaseEntity *GetGroundEntity( void ) const { return const_cast<CBaseEntity *>(this)->GetGroundEntity(); }
  992. // Gets the velocity we impart to a player standing on us
  993. virtual void GetGroundVelocityToApply( Vector &vecGroundVel ) { vecGroundVel = vec3_origin; }
  994. int GetWaterLevel() const;
  995. void SetWaterLevel( int nLevel );
  996. int GetWaterType() const;
  997. void SetWaterType( int nType );
  998. virtual bool PhysicsSplash( const Vector &centerPoint, const Vector &normal, float rawSpeed, float scaledSpeed ) { return false; }
  999. virtual void Splash() {}
  1000. void ClearSolidFlags( void );
  1001. void RemoveSolidFlags( int flags );
  1002. void AddSolidFlags( int flags );
  1003. bool IsSolidFlagSet( int flagMask ) const;
  1004. void SetSolidFlags( int flags );
  1005. bool IsSolid() const;
  1006. void SetModelName( string_t name );
  1007. model_t *GetModel( void );
  1008. // These methods return a *world-aligned* box relative to the absorigin of the entity.
  1009. // This is used for collision purposes and is *not* guaranteed
  1010. // to surround the entire entity's visual representation
  1011. // NOTE: It is illegal to ask for the world-aligned bounds for
  1012. // SOLID_BSP objects
  1013. const Vector& WorldAlignMins( ) const;
  1014. const Vector& WorldAlignMaxs( ) const;
  1015. // This defines collision bounds in OBB space
  1016. void SetCollisionBounds( const Vector& mins, const Vector &maxs );
  1017. // NOTE: The world space center *may* move when the entity rotates.
  1018. virtual const Vector& WorldSpaceCenter( ) const;
  1019. const Vector& WorldAlignSize( ) const;
  1020. // Returns a radius of a sphere
  1021. // *centered at the world space center* bounding the collision representation
  1022. // of the entity. NOTE: The world space center *may* move when the entity rotates.
  1023. float BoundingRadius() const;
  1024. bool IsPointSized() const;
  1025. // NOTE: Setting the abs origin or angles will cause the local origin + angles to be set also
  1026. void SetAbsOrigin( const Vector& origin );
  1027. void SetAbsAngles( const QAngle& angles );
  1028. // Origin and angles in local space ( relative to parent )
  1029. // NOTE: Setting the local origin or angles will cause the abs origin + angles to be set also
  1030. void SetLocalOrigin( const Vector& origin );
  1031. const Vector& GetLocalOrigin( void ) const;
  1032. void SetLocalAngles( const QAngle& angles );
  1033. const QAngle& GetLocalAngles( void ) const;
  1034. void SetElasticity( float flElasticity );
  1035. float GetElasticity( void ) const;
  1036. void SetShadowCastDistance( float flDistance );
  1037. float GetShadowCastDistance( void ) const;
  1038. void SetShadowCastDistance( float flDesiredDistance, float flDelay );
  1039. float GetLocalTime( void ) const;
  1040. void IncrementLocalTime( float flTimeDelta );
  1041. float GetMoveDoneTime( ) const;
  1042. void SetMoveDoneTime( float flTime );
  1043. // Used by the PAS filters to ask the entity where in world space the sounds it emits come from.
  1044. // This is used right now because if you have something sitting on an incline, using our axis-aligned
  1045. // bounding boxes can return a position in solid space, so you won't hear sounds emitted by the object.
  1046. // For now, we're hacking around it by moving the sound emission origin up on certain objects like vehicles.
  1047. //
  1048. // When OBBs get in, this can probably go away.
  1049. virtual Vector GetSoundEmissionOrigin() const;
  1050. void AddFlag( int flags );
  1051. void RemoveFlag( int flagsToRemove );
  1052. void ToggleFlag( int flagToToggle );
  1053. int GetFlags( void ) const;
  1054. void ClearFlags( void );
  1055. // Sets the local position from a transform
  1056. void SetLocalTransform( const matrix3x4_t &localTransform );
  1057. // See CSoundEmitterSystem
  1058. void EmitSound( const char *soundname, float soundtime = 0.0f, float *duration = NULL ); // Override for doing the general case of CPASAttenuationFilter filter( this ), and EmitSound( filter, entindex(), etc. );
  1059. void EmitSound( const char *soundname, HSOUNDSCRIPTHANDLE& handle, float soundtime = 0.0f, float *duration = NULL ); // Override for doing the general case of CPASAttenuationFilter filter( this ), and EmitSound( filter, entindex(), etc. );
  1060. void StopSound( const char *soundname );
  1061. void StopSound( const char *soundname, HSOUNDSCRIPTHANDLE& handle );
  1062. void GenderExpandString( char const *in, char *out, int maxlen );
  1063. virtual void ModifyEmitSoundParams( EmitSound_t &params );
  1064. static float GetSoundDuration( const char *soundname, char const *actormodel );
  1065. static bool GetParametersForSound( const char *soundname, CSoundParameters &params, char const *actormodel );
  1066. static bool GetParametersForSound( const char *soundname, HSOUNDSCRIPTHANDLE& handle, CSoundParameters &params, char const *actormodel );
  1067. static void EmitSound( IRecipientFilter& filter, int iEntIndex, const char *soundname, const Vector *pOrigin = NULL, float soundtime = 0.0f, float *duration = NULL );
  1068. static void EmitSound( IRecipientFilter& filter, int iEntIndex, const char *soundname, HSOUNDSCRIPTHANDLE& handle, const Vector *pOrigin = NULL, float soundtime = 0.0f, float *duration = NULL );
  1069. static void StopSound( int iEntIndex, const char *soundname );
  1070. static soundlevel_t LookupSoundLevel( const char *soundname );
  1071. static soundlevel_t LookupSoundLevel( const char *soundname, HSOUNDSCRIPTHANDLE& handle );
  1072. static void EmitSound( IRecipientFilter& filter, int iEntIndex, const EmitSound_t & params );
  1073. static void EmitSound( IRecipientFilter& filter, int iEntIndex, const EmitSound_t & params, HSOUNDSCRIPTHANDLE& handle );
  1074. static void StopSound( int iEntIndex, int iChannel, const char *pSample );
  1075. static void EmitAmbientSound( int entindex, const Vector& origin, const char *soundname, int flags = 0, float soundtime = 0.0f, float *duration = NULL );
  1076. // These files need to be listed in scripts/game_sounds_manifest.txt
  1077. static HSOUNDSCRIPTHANDLE PrecacheScriptSound( const char *soundname );
  1078. static void PrefetchScriptSound( const char *soundname );
  1079. // For each client who appears to be a valid recipient, checks the client has disabled CC and if so, removes them from
  1080. // the recipient list.
  1081. static void RemoveRecipientsIfNotCloseCaptioning( CRecipientFilter& filter );
  1082. static void EmitCloseCaption( IRecipientFilter& filter, int entindex, char const *token, CUtlVector< Vector >& soundorigins, float duration, bool warnifmissing = false );
  1083. static void EmitSentenceByIndex( IRecipientFilter& filter, int iEntIndex, int iChannel, int iSentenceIndex,
  1084. float flVolume, soundlevel_t iSoundlevel, int iFlags = 0, int iPitch = PITCH_NORM,
  1085. const Vector *pOrigin = NULL, const Vector *pDirection = NULL, bool bUpdatePositions = true, float soundtime = 0.0f );
  1086. static bool IsPrecacheAllowed();
  1087. static void SetAllowPrecache( bool allow );
  1088. static bool m_bAllowPrecache;
  1089. static bool IsSimulatingOnAlternateTicks();
  1090. virtual bool IsDeflectable() { return false; }
  1091. virtual void Deflected( CBaseEntity *pDeflectedBy, Vector &vecDir ) {}
  1092. // void Relink() {}
  1093. public:
  1094. // VPHYSICS Integration -----------------------------------------------
  1095. //
  1096. // --------------------------------------------------------------------
  1097. // UNDONE: Move to IEntityVPhysics? or VPhysicsProp() ?
  1098. // Called after spawn, and in the case of self-managing objects, after load
  1099. virtual bool CreateVPhysics();
  1100. // Convenience routines to init the vphysics simulation for this object.
  1101. // This creates a static object. Something that behaves like world geometry - solid, but never moves
  1102. IPhysicsObject *VPhysicsInitStatic( void );
  1103. // This creates a normal vphysics simulated object - physics determines where it goes (gravity, friction, etc)
  1104. // and the entity receives updates from vphysics. SetAbsOrigin(), etc do not affect the object!
  1105. IPhysicsObject *VPhysicsInitNormal( SolidType_t solidType, int nSolidFlags, bool createAsleep, solid_t *pSolid = NULL );
  1106. // This creates a vphysics object with a shadow controller that follows the AI
  1107. // Move the object to where it should be and call UpdatePhysicsShadowToCurrentPosition()
  1108. IPhysicsObject *VPhysicsInitShadow( bool allowPhysicsMovement, bool allowPhysicsRotation, solid_t *pSolid = NULL );
  1109. // Force a non-solid (ie. solid_trigger) physics object to collide with other entities.
  1110. virtual bool ForceVPhysicsCollide( CBaseEntity *pEntity ) { return false; }
  1111. private:
  1112. // called by all vphysics inits
  1113. bool VPhysicsInitSetup();
  1114. public:
  1115. void VPhysicsSetObject( IPhysicsObject *pPhysics );
  1116. // destroy and remove the physics object for this entity
  1117. virtual void VPhysicsDestroyObject( void );
  1118. void VPhysicsSwapObject( IPhysicsObject *pSwap );
  1119. inline IPhysicsObject *VPhysicsGetObject( void ) const { return m_pPhysicsObject; }
  1120. virtual void VPhysicsUpdate( IPhysicsObject *pPhysics );
  1121. void VPhysicsUpdatePusher( IPhysicsObject *pPhysics );
  1122. // react physically to damage (called from CBaseEntity::OnTakeDamage() by default)
  1123. virtual int VPhysicsTakeDamage( const CTakeDamageInfo &info );
  1124. virtual void VPhysicsShadowCollision( int index, gamevcollisionevent_t *pEvent );
  1125. virtual void VPhysicsShadowUpdate( IPhysicsObject *pPhysics ) {}
  1126. virtual void VPhysicsCollision( int index, gamevcollisionevent_t *pEvent );
  1127. virtual void VPhysicsFriction( IPhysicsObject *pObject, float energy, int surfaceProps, int surfacePropsHit );
  1128. // update the shadow so it will coincide with the current AI position at some time
  1129. // in the future (or 0 for now)
  1130. virtual void UpdatePhysicsShadowToCurrentPosition( float deltaTime );
  1131. virtual int VPhysicsGetObjectList( IPhysicsObject **pList, int listMax );
  1132. virtual bool VPhysicsIsFlesh( void );
  1133. // --------------------------------------------------------------------
  1134. public:
  1135. #if !defined( NO_ENTITY_PREDICTION )
  1136. // The player drives simulation of this entity
  1137. void SetPlayerSimulated( CBasePlayer *pOwner );
  1138. void UnsetPlayerSimulated( void );
  1139. bool IsPlayerSimulated( void ) const;
  1140. CBasePlayer *GetSimulatingPlayer( void );
  1141. #endif
  1142. // FIXME: Make these private!
  1143. void PhysicsCheckForEntityUntouch( void );
  1144. bool PhysicsRunThink( thinkmethods_t thinkMethod = THINK_FIRE_ALL_FUNCTIONS );
  1145. bool PhysicsRunSpecificThink( int nContextIndex, BASEPTR thinkFunc );
  1146. bool PhysicsTestEntityPosition( CBaseEntity **ppEntity = NULL );
  1147. void PhysicsPushEntity( const Vector& push, trace_t *pTrace );
  1148. bool PhysicsCheckWater( void );
  1149. void PhysicsCheckWaterTransition( void );
  1150. void PhysicsStepRecheckGround();
  1151. // Computes the water level + type
  1152. void UpdateWaterState();
  1153. bool IsEdictFree() const { return edict()->IsFree(); }
  1154. // Callbacks for the physgun/cannon picking up an entity
  1155. virtual CBasePlayer *HasPhysicsAttacker( float dt ) { return NULL; }
  1156. // UNDONE: Make this data?
  1157. virtual unsigned int PhysicsSolidMaskForEntity( void ) const;
  1158. // Computes the abs position of a point specified in local space
  1159. void ComputeAbsPosition( const Vector &vecLocalPosition, Vector *pAbsPosition );
  1160. // Computes the abs position of a direction specified in local space
  1161. void ComputeAbsDirection( const Vector &vecLocalDirection, Vector *pAbsDirection );
  1162. void SetPredictionEligible( bool canpredict );
  1163. protected:
  1164. // Invalidates the abs state of all children
  1165. void InvalidatePhysicsRecursive( int nChangeFlags );
  1166. int PhysicsClipVelocity (const Vector& in, const Vector& normal, Vector& out, float overbounce );
  1167. void PhysicsRelinkChildren( float dt );
  1168. // Performs the collision resolution for fliers.
  1169. void PerformFlyCollisionResolution( trace_t &trace, Vector &move );
  1170. void ResolveFlyCollisionBounce( trace_t &trace, Vector &vecVelocity, float flMinTotalElasticity = 0.0f );
  1171. void ResolveFlyCollisionSlide( trace_t &trace, Vector &vecVelocity );
  1172. virtual void ResolveFlyCollisionCustom( trace_t &trace, Vector &vecVelocity );
  1173. private:
  1174. // Physics-related private methods
  1175. void PhysicsStep( void );
  1176. void PhysicsPusher( void );
  1177. void PhysicsNone( void );
  1178. void PhysicsNoclip( void );
  1179. void PhysicsStepRunTimestep( float timestep );
  1180. void PhysicsToss( void );
  1181. void PhysicsCustom( void );
  1182. void PerformPush( float movetime );
  1183. // Simulation in local space of rigid children
  1184. void PhysicsRigidChild( void );
  1185. // Computes the base velocity
  1186. void UpdateBaseVelocity( void );
  1187. // Implement this if you use MOVETYPE_CUSTOM
  1188. virtual void PerformCustomPhysics( Vector *pNewPosition, Vector *pNewVelocity, QAngle *pNewAngles, QAngle *pNewAngVelocity );
  1189. void PhysicsDispatchThink( BASEPTR thinkFunc );
  1190. touchlink_t *PhysicsMarkEntityAsTouched( CBaseEntity *other );
  1191. void PhysicsTouch( CBaseEntity *pentOther );
  1192. void PhysicsStartTouch( CBaseEntity *pentOther );
  1193. CBaseEntity *PhysicsPushMove( float movetime );
  1194. CBaseEntity *PhysicsPushRotate( float movetime );
  1195. CBaseEntity *PhysicsCheckRotateMove( rotatingpushmove_t &rotPushmove, CBaseEntity **pPusherList, int pusherListCount );
  1196. CBaseEntity *PhysicsCheckPushMove( const Vector& move, CBaseEntity **pPusherList, int pusherListCount );
  1197. int PhysicsTryMove( float flTime, trace_t *steptrace );
  1198. void PhysicsCheckVelocity( void );
  1199. void PhysicsAddHalfGravity( float timestep );
  1200. void PhysicsAddGravityMove( Vector &move );
  1201. void CalcAbsoluteVelocity();
  1202. void CalcAbsoluteAngularVelocity();
  1203. // Checks a sweep without actually performing the move
  1204. void PhysicsCheckSweep( const Vector& vecAbsStart, const Vector &vecAbsDelta, trace_t *pTrace );
  1205. // Computes new angles based on the angular velocity
  1206. void SimulateAngles( float flFrameTime );
  1207. void CheckStepSimulationChanged();
  1208. // Run regular think and latch off angle/origin changes so we can interpolate them on the server to fake simulation
  1209. void StepSimulationThink( float dt );
  1210. // Compute network origin
  1211. private:
  1212. void ComputeStepSimulationNetwork( StepSimulationData *step );
  1213. public:
  1214. bool UseStepSimulationNetworkOrigin( const Vector **out_v );
  1215. bool UseStepSimulationNetworkAngles( const QAngle **out_a );
  1216. public:
  1217. // Add a discontinuity to a step
  1218. bool AddStepDiscontinuity( float flTime, const Vector &vecOrigin, const QAngle &vecAngles );
  1219. int GetFirstThinkTick(); // get first tick thinking on any context
  1220. private:
  1221. // origin and angles to use in step calculations
  1222. virtual Vector GetStepOrigin( void ) const;
  1223. virtual QAngle GetStepAngles( void ) const;
  1224. // These set entity flags (EFL_*) to help optimize queries
  1225. void CheckHasThinkFunction( bool isThinkingHint = false );
  1226. void CheckHasGamePhysicsSimulation();
  1227. bool WillThink();
  1228. bool WillSimulateGamePhysics();
  1229. friend class CPushBlockerEnum;
  1230. // Sets/Gets the next think based on context index
  1231. void SetNextThink( int nContextIndex, float thinkTime );
  1232. void SetLastThink( int nContextIndex, float thinkTime );
  1233. float GetNextThink( int nContextIndex ) const;
  1234. int GetNextThinkTick( int nContextIndex ) const;
  1235. // Shot statistics
  1236. void UpdateShotStatistics( const trace_t &tr );
  1237. // Handle shot entering water
  1238. bool HandleShotImpactingWater( const FireBulletsInfo_t &info, const Vector &vecEnd, ITraceFilter *pTraceFilter, Vector *pVecTracerDest );
  1239. // Handle shot entering water
  1240. void HandleShotImpactingGlass( const FireBulletsInfo_t &info, const trace_t &tr, const Vector &vecDir, ITraceFilter *pTraceFilter );
  1241. // Should we draw bubbles underwater?
  1242. bool ShouldDrawUnderwaterBulletBubbles();
  1243. // Computes the tracer start position
  1244. void ComputeTracerStartPosition( const Vector &vecShotSrc, Vector *pVecTracerStart );
  1245. // Computes the tracer start position
  1246. void CreateBubbleTrailTracer( const Vector &vecShotSrc, const Vector &vecShotEnd, const Vector &vecShotDir );
  1247. virtual bool ShouldDrawWaterImpacts() { return true; }
  1248. // Changes shadow cast distance over time
  1249. void ShadowCastDistThink( );
  1250. // Precache model sounds + particles
  1251. static void PrecacheModelComponents( int nModelIndex );
  1252. static void PrecacheSoundHelper( const char *pName );
  1253. protected:
  1254. // Which frame did I simulate?
  1255. int m_nSimulationTick;
  1256. // FIXME: Make this private! Still too many references to do so...
  1257. CNetworkVar( int, m_spawnflags );
  1258. private:
  1259. int m_iEFlags; // entity flags EFL_*
  1260. // was pev->flags
  1261. CNetworkVarForDerived( int, m_fFlags );
  1262. string_t m_iName; // name used to identify this entity
  1263. // Damage modifiers
  1264. friend class CDamageModifier;
  1265. CUtlLinkedList<CDamageModifier*,int> m_DamageModifiers;
  1266. EHANDLE m_pParent; // for movement hierarchy
  1267. byte m_nTransmitStateOwnedCounter;
  1268. CNetworkVar( unsigned char, m_iParentAttachment ); // 0 if we're relative to the parent's absorigin and absangles.
  1269. CNetworkVar( unsigned char, m_MoveType ); // One of the MOVETYPE_ defines.
  1270. CNetworkVar( unsigned char, m_MoveCollide );
  1271. // Our immediate parent in the movement hierarchy.
  1272. // FIXME: clarify m_pParent vs. m_pMoveParent
  1273. CNetworkHandle( CBaseEntity, m_hMoveParent );
  1274. // cached child list
  1275. EHANDLE m_hMoveChild;
  1276. // generated from m_pMoveParent
  1277. EHANDLE m_hMovePeer;
  1278. friend class CCollisionProperty;
  1279. friend class CServerNetworkProperty;
  1280. CNetworkVarEmbedded( CCollisionProperty, m_Collision );
  1281. CNetworkHandle( CBaseEntity, m_hOwnerEntity ); // only used to point to an edict it won't collide with
  1282. CNetworkHandle( CBaseEntity, m_hEffectEntity ); // Fire/Dissolve entity.
  1283. CNetworkVar( int, m_CollisionGroup ); // used to cull collision tests
  1284. IPhysicsObject *m_pPhysicsObject; // pointer to the entity's physics object (vphysics.dll)
  1285. CNetworkVar( float, m_flShadowCastDistance );
  1286. float m_flDesiredShadowCastDistance;
  1287. // Team handling
  1288. int m_iInitialTeamNum; // Team number of this entity's team read from file
  1289. CNetworkVar( int, m_iTeamNum ); // Team number of this entity's team.
  1290. // Sets water type + level for physics objects
  1291. unsigned char m_nWaterTouch;
  1292. unsigned char m_nSlimeTouch;
  1293. unsigned char m_nWaterType;
  1294. CNetworkVarForDerived( unsigned char, m_nWaterLevel );
  1295. float m_flNavIgnoreUntilTime;
  1296. CNetworkHandleForDerived( CBaseEntity, m_hGroundEntity );
  1297. float m_flGroundChangeTime; // Time that the ground entity changed
  1298. string_t m_ModelName;
  1299. // Velocity of the thing we're standing on (world space)
  1300. CNetworkVarForDerived( Vector, m_vecBaseVelocity );
  1301. // Global velocity
  1302. Vector m_vecAbsVelocity;
  1303. // Local angular velocity
  1304. QAngle m_vecAngVelocity;
  1305. // Global angular velocity
  1306. // QAngle m_vecAbsAngVelocity;
  1307. // local coordinate frame of entity
  1308. matrix3x4_t m_rgflCoordinateFrame;
  1309. // Physics state
  1310. EHANDLE m_pBlocker;
  1311. // was pev->gravity;
  1312. float m_flGravity; // rename to m_flGravityScale;
  1313. // was pev->friction
  1314. CNetworkVarForDerived( float, m_flFriction );
  1315. CNetworkVar( float, m_flElasticity );
  1316. // was pev->ltime
  1317. float m_flLocalTime;
  1318. // local time at the beginning of this frame
  1319. float m_flVPhysicsUpdateLocalTime;
  1320. // local time the movement has ended
  1321. float m_flMoveDoneTime;
  1322. // A counter to help quickly build a list of potentially pushed objects for physics
  1323. int m_nPushEnumCount;
  1324. Vector m_vecAbsOrigin;
  1325. CNetworkVectorForDerived( m_vecVelocity );
  1326. //Adrian
  1327. CNetworkVar( unsigned char, m_iTextureFrameIndex );
  1328. CNetworkVar( bool, m_bSimulatedEveryTick );
  1329. CNetworkVar( bool, m_bAnimatedEveryTick );
  1330. CNetworkVar( bool, m_bAlternateSorting );
  1331. // User outputs. Fired when the "FireInputX" input is triggered.
  1332. COutputEvent m_OnUser1;
  1333. COutputEvent m_OnUser2;
  1334. COutputEvent m_OnUser3;
  1335. COutputEvent m_OnUser4;
  1336. QAngle m_angAbsRotation;
  1337. CNetworkVector( m_vecOrigin );
  1338. CNetworkQAngle( m_angRotation );
  1339. CBaseHandle m_RefEHandle;
  1340. // was pev->view_ofs ( FIXME: Move somewhere up the hierarch, CBaseAnimating, etc. )
  1341. CNetworkVectorForDerived( m_vecViewOffset );
  1342. private:
  1343. // dynamic model state tracking
  1344. bool m_bDynamicModelAllowed;
  1345. bool m_bDynamicModelPending;
  1346. bool m_bDynamicModelSetBounds;
  1347. void OnModelLoadComplete( const model_t* model );
  1348. friend class CBaseEntityModelLoadProxy;
  1349. protected:
  1350. void EnableDynamicModels() { m_bDynamicModelAllowed = true; }
  1351. public:
  1352. bool IsDynamicModelLoading() const { return m_bDynamicModelPending; }
  1353. void SetCollisionBoundsFromModel();
  1354. #if !defined( NO_ENTITY_PREDICTION )
  1355. CNetworkVar( bool, m_bIsPlayerSimulated );
  1356. // Player who is driving my simulation
  1357. CHandle< CBasePlayer > m_hPlayerSimulationOwner;
  1358. #endif
  1359. int m_fDataObjectTypes;
  1360. // So it can get at the physics methods
  1361. friend class CCollisionEvent;
  1362. // Methods shared by client and server
  1363. public:
  1364. void SetSize( const Vector &vecMin, const Vector &vecMax ); // UTIL_SetSize( this, mins, maxs );
  1365. static int PrecacheModel( const char *name, bool bPreload = true );
  1366. static bool PrecacheSound( const char *name );
  1367. static void PrefetchSound( const char *name );
  1368. void Remove( ); // UTIL_Remove( this );
  1369. private:
  1370. // This is a random seed used by the networking code to allow client - side prediction code
  1371. // randon number generators to spit out the same random numbers on both sides for a particular
  1372. // usercmd input.
  1373. static int m_nPredictionRandomSeed;
  1374. static int m_nPredictionRandomSeedServer;
  1375. static CBasePlayer *m_pPredictionPlayer;
  1376. // FIXME: Make hierarchy a member of CBaseEntity
  1377. // or a contained private class...
  1378. friend void UnlinkChild( CBaseEntity *pParent, CBaseEntity *pChild );
  1379. friend void LinkChild( CBaseEntity *pParent, CBaseEntity *pChild );
  1380. friend void ClearParent( CBaseEntity *pEntity );
  1381. friend void UnlinkAllChildren( CBaseEntity *pParent );
  1382. friend void UnlinkFromParent( CBaseEntity *pRemove );
  1383. friend void TransferChildren( CBaseEntity *pOldParent, CBaseEntity *pNewParent );
  1384. public:
  1385. // Accessors for above
  1386. static int GetPredictionRandomSeed( bool bUseUnSyncedServerPlatTime = false );
  1387. static void SetPredictionRandomSeed( const CUserCmd *cmd );
  1388. static CBasePlayer *GetPredictionPlayer( void );
  1389. static void SetPredictionPlayer( CBasePlayer *player );
  1390. // For debugging shared code
  1391. static bool IsServer( void )
  1392. {
  1393. return true;
  1394. }
  1395. static bool IsClient( void )
  1396. {
  1397. return false;
  1398. }
  1399. static char const *GetDLLType( void )
  1400. {
  1401. return "server";
  1402. }
  1403. // Used to access m_vecAbsOrigin during restore when it's unsafe to call GetAbsOrigin.
  1404. friend class CPlayerRestoreHelper;
  1405. static bool s_bAbsQueriesValid;
  1406. // Call this when hierarchy is not completely set up (such as during Restore) to throw asserts
  1407. // when people call GetAbsAnything.
  1408. static inline void SetAbsQueriesValid( bool bValid )
  1409. {
  1410. s_bAbsQueriesValid = bValid;
  1411. }
  1412. static inline bool IsAbsQueriesValid()
  1413. {
  1414. return s_bAbsQueriesValid;
  1415. }
  1416. virtual bool ShouldBlockNav() const { return true; }
  1417. virtual bool ShouldForceTransmitsForTeam( int iTeam ) { return false; }
  1418. void SetTruceValidForEnt( bool bTruceValidForEnt ) { m_bTruceValidForEnt = bTruceValidForEnt; }
  1419. virtual bool IsTruceValidForEnt( void ) const { return m_bTruceValidForEnt; }
  1420. private:
  1421. CThreadFastMutex m_CalcAbsolutePositionMutex;
  1422. bool m_bTruceValidForEnt;
  1423. };
  1424. // Send tables exposed in this module.
  1425. EXTERN_SEND_TABLE(DT_Edict);
  1426. EXTERN_SEND_TABLE(DT_BaseEntity);
  1427. // Ugly technique to override base member functions
  1428. // Normally it's illegal to cast a pointer to a member function of a derived class to a pointer to a
  1429. // member function of a base class. static_cast is a sleezy way around that problem.
  1430. #ifdef _DEBUG
  1431. #define SetTouch( a ) TouchSet( static_cast <void (CBaseEntity::*)(CBaseEntity *)> (a), #a )
  1432. #define SetUse( a ) UseSet( static_cast <void (CBaseEntity::*)( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )> (a), #a )
  1433. #define SetBlocked( a ) BlockedSet( static_cast <void (CBaseEntity::*)(CBaseEntity *)> (a), #a )
  1434. #else
  1435. #define SetTouch( a ) m_pfnTouch = static_cast <void (CBaseEntity::*)(CBaseEntity *)> (a)
  1436. #define SetUse( a ) m_pfnUse = static_cast <void (CBaseEntity::*)( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )> (a)
  1437. #define SetBlocked( a ) m_pfnBlocked = static_cast <void (CBaseEntity::*)(CBaseEntity *)> (a)
  1438. #endif
  1439. // handling entity/edict transforms
  1440. inline CBaseEntity *GetContainingEntity( edict_t *pent )
  1441. {
  1442. if ( pent && pent->GetUnknown() )
  1443. {
  1444. return pent->GetUnknown()->GetBaseEntity();
  1445. }
  1446. return NULL;
  1447. }
  1448. //-----------------------------------------------------------------------------
  1449. // Purpose: Pauses or resumes entity i/o events. When paused, no outputs will
  1450. // fire unless Debug_SetSteps is called with a nonzero step value.
  1451. // Input : bPause - true to pause, false to resume.
  1452. //-----------------------------------------------------------------------------
  1453. inline void CBaseEntity::Debug_Pause(bool bPause)
  1454. {
  1455. CBaseEntity::m_bDebugPause = bPause;
  1456. }
  1457. //-----------------------------------------------------------------------------
  1458. // Purpose: Returns true if entity i/o is paused, false if not.
  1459. //-----------------------------------------------------------------------------
  1460. inline bool CBaseEntity::Debug_IsPaused(void)
  1461. {
  1462. return(CBaseEntity::m_bDebugPause);
  1463. }
  1464. //-----------------------------------------------------------------------------
  1465. // Purpose: Decrements the debug step counter. Used when the entity i/o system
  1466. // is in single step mode, this is called every time an output is fired.
  1467. // Output : Returns true on to continue firing outputs, false to stop.
  1468. //-----------------------------------------------------------------------------
  1469. inline bool CBaseEntity::Debug_Step(void)
  1470. {
  1471. if (CBaseEntity::m_nDebugSteps > 0)
  1472. {
  1473. CBaseEntity::m_nDebugSteps--;
  1474. }
  1475. return(CBaseEntity::m_nDebugSteps > 0);
  1476. }
  1477. //-----------------------------------------------------------------------------
  1478. // Purpose: Sets the number of entity outputs to allow to fire before pausing
  1479. // the entity i/o system.
  1480. // Input : nSteps - Number of steps to execute.
  1481. //-----------------------------------------------------------------------------
  1482. inline void CBaseEntity::Debug_SetSteps(int nSteps)
  1483. {
  1484. CBaseEntity::m_nDebugSteps = nSteps;
  1485. }
  1486. //-----------------------------------------------------------------------------
  1487. // Purpose: Returns true if we should allow outputs to be fired, false if not.
  1488. //-----------------------------------------------------------------------------
  1489. inline bool CBaseEntity::Debug_ShouldStep(void)
  1490. {
  1491. return(!CBaseEntity::m_bDebugPause || CBaseEntity::m_nDebugSteps > 0);
  1492. }
  1493. //-----------------------------------------------------------------------------
  1494. // Methods relating to traversing hierarchy
  1495. //-----------------------------------------------------------------------------
  1496. inline CBaseEntity *CBaseEntity::GetMoveParent( void )
  1497. {
  1498. return m_hMoveParent.Get();
  1499. }
  1500. inline CBaseEntity *CBaseEntity::FirstMoveChild( void )
  1501. {
  1502. return m_hMoveChild.Get();
  1503. }
  1504. inline CBaseEntity *CBaseEntity::NextMovePeer( void )
  1505. {
  1506. return m_hMovePeer.Get();
  1507. }
  1508. // FIXME: Remove this! There shouldn't be a difference between moveparent + parent
  1509. inline CBaseEntity* CBaseEntity::GetParent()
  1510. {
  1511. return m_pParent.Get();
  1512. }
  1513. inline int CBaseEntity::GetParentAttachment()
  1514. {
  1515. return m_iParentAttachment;
  1516. }
  1517. //-----------------------------------------------------------------------------
  1518. // Inline methods
  1519. //-----------------------------------------------------------------------------
  1520. inline string_t CBaseEntity::GetEntityName()
  1521. {
  1522. return m_iName;
  1523. }
  1524. inline void CBaseEntity::SetName( string_t newName )
  1525. {
  1526. m_iName = newName;
  1527. }
  1528. inline bool CBaseEntity::NameMatches( const char *pszNameOrWildcard )
  1529. {
  1530. if ( IDENT_STRINGS(m_iName, pszNameOrWildcard) )
  1531. return true;
  1532. return NameMatchesComplex( pszNameOrWildcard );
  1533. }
  1534. inline bool CBaseEntity::NameMatches( string_t nameStr )
  1535. {
  1536. if ( IDENT_STRINGS(m_iName, nameStr) )
  1537. return true;
  1538. return NameMatchesComplex( STRING(nameStr) );
  1539. }
  1540. inline bool CBaseEntity::ClassMatches( const char *pszClassOrWildcard )
  1541. {
  1542. if ( IDENT_STRINGS(m_iClassname, pszClassOrWildcard ) )
  1543. return true;
  1544. return ClassMatchesComplex( pszClassOrWildcard );
  1545. }
  1546. inline const char* CBaseEntity::GetClassname()
  1547. {
  1548. return STRING(m_iClassname);
  1549. }
  1550. inline bool CBaseEntity::ClassMatches( string_t nameStr )
  1551. {
  1552. if ( IDENT_STRINGS(m_iClassname, nameStr ) )
  1553. return true;
  1554. return ClassMatchesComplex( STRING(nameStr) );
  1555. }
  1556. inline int CBaseEntity::GetSpawnFlags( void ) const
  1557. {
  1558. return m_spawnflags;
  1559. }
  1560. inline void CBaseEntity::AddSpawnFlags( int nFlags )
  1561. {
  1562. m_spawnflags |= nFlags;
  1563. }
  1564. inline void CBaseEntity::RemoveSpawnFlags( int nFlags )
  1565. {
  1566. m_spawnflags &= ~nFlags;
  1567. }
  1568. inline void CBaseEntity::ClearSpawnFlags( void )
  1569. {
  1570. m_spawnflags = 0;
  1571. }
  1572. inline bool CBaseEntity::HasSpawnFlags( int nFlags ) const
  1573. {
  1574. return (m_spawnflags & nFlags) != 0;
  1575. }
  1576. //-----------------------------------------------------------------------------
  1577. // checks to see if the entity is marked for deletion
  1578. //-----------------------------------------------------------------------------
  1579. inline bool CBaseEntity::IsMarkedForDeletion( void )
  1580. {
  1581. return (m_iEFlags & EFL_KILLME);
  1582. }
  1583. //-----------------------------------------------------------------------------
  1584. // EFlags
  1585. //-----------------------------------------------------------------------------
  1586. inline int CBaseEntity::GetEFlags() const
  1587. {
  1588. return m_iEFlags;
  1589. }
  1590. inline void CBaseEntity::SetEFlags( int iEFlags )
  1591. {
  1592. m_iEFlags = iEFlags;
  1593. if ( iEFlags & ( EFL_FORCE_CHECK_TRANSMIT | EFL_IN_SKYBOX ) )
  1594. {
  1595. DispatchUpdateTransmitState();
  1596. }
  1597. }
  1598. inline void CBaseEntity::AddEFlags( int nEFlagMask )
  1599. {
  1600. m_iEFlags |= nEFlagMask;
  1601. if ( nEFlagMask & ( EFL_FORCE_CHECK_TRANSMIT | EFL_IN_SKYBOX ) )
  1602. {
  1603. DispatchUpdateTransmitState();
  1604. }
  1605. }
  1606. inline void CBaseEntity::RemoveEFlags( int nEFlagMask )
  1607. {
  1608. m_iEFlags &= ~nEFlagMask;
  1609. if ( nEFlagMask & ( EFL_FORCE_CHECK_TRANSMIT | EFL_IN_SKYBOX ) )
  1610. DispatchUpdateTransmitState();
  1611. }
  1612. inline bool CBaseEntity::IsEFlagSet( int nEFlagMask ) const
  1613. {
  1614. return (m_iEFlags & nEFlagMask) != 0;
  1615. }
  1616. inline void CBaseEntity::SetNavIgnore( float duration )
  1617. {
  1618. float flNavIgnoreUntilTime = ( duration == FLT_MAX ) ? FLT_MAX : gpGlobals->curtime + duration;
  1619. if ( flNavIgnoreUntilTime > m_flNavIgnoreUntilTime )
  1620. m_flNavIgnoreUntilTime = flNavIgnoreUntilTime;
  1621. }
  1622. inline void CBaseEntity::ClearNavIgnore()
  1623. {
  1624. m_flNavIgnoreUntilTime = 0;
  1625. }
  1626. inline bool CBaseEntity::IsNavIgnored() const
  1627. {
  1628. return ( gpGlobals->curtime <= m_flNavIgnoreUntilTime );
  1629. }
  1630. inline bool CBaseEntity::GetCheckUntouch() const
  1631. {
  1632. return IsEFlagSet( EFL_CHECK_UNTOUCH );
  1633. }
  1634. //-----------------------------------------------------------------------------
  1635. // Network state optimization
  1636. //-----------------------------------------------------------------------------
  1637. inline CBaseCombatCharacter *ToBaseCombatCharacter( CBaseEntity *pEntity )
  1638. {
  1639. if ( !pEntity )
  1640. return NULL;
  1641. return pEntity->MyCombatCharacterPointer();
  1642. }
  1643. //-----------------------------------------------------------------------------
  1644. // Physics state accessor methods
  1645. //-----------------------------------------------------------------------------
  1646. inline const Vector& CBaseEntity::GetLocalOrigin( void ) const
  1647. {
  1648. return m_vecOrigin.Get();
  1649. }
  1650. inline const QAngle& CBaseEntity::GetLocalAngles( void ) const
  1651. {
  1652. return m_angRotation.Get();
  1653. }
  1654. inline const Vector& CBaseEntity::GetAbsOrigin( void ) const
  1655. {
  1656. Assert( CBaseEntity::IsAbsQueriesValid() );
  1657. if (IsEFlagSet(EFL_DIRTY_ABSTRANSFORM))
  1658. {
  1659. const_cast<CBaseEntity*>(this)->CalcAbsolutePosition();
  1660. }
  1661. return m_vecAbsOrigin;
  1662. }
  1663. inline const QAngle& CBaseEntity::GetAbsAngles( void ) const
  1664. {
  1665. Assert( CBaseEntity::IsAbsQueriesValid() );
  1666. if (IsEFlagSet(EFL_DIRTY_ABSTRANSFORM))
  1667. {
  1668. const_cast<CBaseEntity*>(this)->CalcAbsolutePosition();
  1669. }
  1670. return m_angAbsRotation;
  1671. }
  1672. //-----------------------------------------------------------------------------
  1673. // Returns the entity-to-world transform
  1674. //-----------------------------------------------------------------------------
  1675. inline matrix3x4_t &CBaseEntity::EntityToWorldTransform()
  1676. {
  1677. Assert( CBaseEntity::IsAbsQueriesValid() );
  1678. if (IsEFlagSet(EFL_DIRTY_ABSTRANSFORM))
  1679. {
  1680. CalcAbsolutePosition();
  1681. }
  1682. return m_rgflCoordinateFrame;
  1683. }
  1684. inline const matrix3x4_t &CBaseEntity::EntityToWorldTransform() const
  1685. {
  1686. Assert( CBaseEntity::IsAbsQueriesValid() );
  1687. if (IsEFlagSet(EFL_DIRTY_ABSTRANSFORM))
  1688. {
  1689. const_cast<CBaseEntity*>(this)->CalcAbsolutePosition();
  1690. }
  1691. return m_rgflCoordinateFrame;
  1692. }
  1693. //-----------------------------------------------------------------------------
  1694. // Some helper methods that transform a point from entity space to world space + back
  1695. //-----------------------------------------------------------------------------
  1696. inline void CBaseEntity::EntityToWorldSpace( const Vector &in, Vector *pOut ) const
  1697. {
  1698. if ( GetAbsAngles() == vec3_angle )
  1699. {
  1700. VectorAdd( in, GetAbsOrigin(), *pOut );
  1701. }
  1702. else
  1703. {
  1704. VectorTransform( in, EntityToWorldTransform(), *pOut );
  1705. }
  1706. }
  1707. inline void CBaseEntity::WorldToEntitySpace( const Vector &in, Vector *pOut ) const
  1708. {
  1709. if ( GetAbsAngles() == vec3_angle )
  1710. {
  1711. VectorSubtract( in, GetAbsOrigin(), *pOut );
  1712. }
  1713. else
  1714. {
  1715. VectorITransform( in, EntityToWorldTransform(), *pOut );
  1716. }
  1717. }
  1718. //-----------------------------------------------------------------------------
  1719. // Velocity
  1720. //-----------------------------------------------------------------------------
  1721. inline Vector CBaseEntity::GetSmoothedVelocity( void )
  1722. {
  1723. Vector vel;
  1724. GetVelocity( &vel, NULL );
  1725. return vel;
  1726. }
  1727. inline const Vector &CBaseEntity::GetLocalVelocity( ) const
  1728. {
  1729. return m_vecVelocity.Get();
  1730. }
  1731. inline const Vector &CBaseEntity::GetAbsVelocity( ) const
  1732. {
  1733. Assert( CBaseEntity::IsAbsQueriesValid() );
  1734. if (IsEFlagSet(EFL_DIRTY_ABSVELOCITY))
  1735. {
  1736. const_cast<CBaseEntity*>(this)->CalcAbsoluteVelocity();
  1737. }
  1738. return m_vecAbsVelocity;
  1739. }
  1740. inline const QAngle &CBaseEntity::GetLocalAngularVelocity( ) const
  1741. {
  1742. return m_vecAngVelocity;
  1743. }
  1744. /*
  1745. // FIXME: While we're using (dPitch, dYaw, dRoll) as our local angular velocity
  1746. // representation, we can't actually solve this problem
  1747. inline const QAngle &CBaseEntity::GetAbsAngularVelocity( ) const
  1748. {
  1749. if (IsEFlagSet(EFL_DIRTY_ABSANGVELOCITY))
  1750. {
  1751. const_cast<CBaseEntity*>(this)->CalcAbsoluteAngularVelocity();
  1752. }
  1753. return m_vecAbsAngVelocity;
  1754. }
  1755. */
  1756. inline const Vector& CBaseEntity::GetBaseVelocity() const
  1757. {
  1758. return m_vecBaseVelocity.Get();
  1759. }
  1760. inline void CBaseEntity::SetBaseVelocity( const Vector& v )
  1761. {
  1762. m_vecBaseVelocity = v;
  1763. }
  1764. inline float CBaseEntity::GetGravity( void ) const
  1765. {
  1766. return m_flGravity;
  1767. }
  1768. inline void CBaseEntity::SetGravity( float gravity )
  1769. {
  1770. m_flGravity = gravity;
  1771. }
  1772. inline float CBaseEntity::GetFriction( void ) const
  1773. {
  1774. return m_flFriction;
  1775. }
  1776. inline void CBaseEntity::SetFriction( float flFriction )
  1777. {
  1778. m_flFriction = flFriction;
  1779. }
  1780. inline void CBaseEntity::SetElasticity( float flElasticity )
  1781. {
  1782. m_flElasticity = flElasticity;
  1783. }
  1784. inline float CBaseEntity::GetElasticity( void ) const
  1785. {
  1786. return m_flElasticity;
  1787. }
  1788. inline void CBaseEntity::SetShadowCastDistance( float flDistance )
  1789. {
  1790. m_flShadowCastDistance = flDistance;
  1791. }
  1792. inline float CBaseEntity::GetShadowCastDistance( void ) const
  1793. {
  1794. return m_flShadowCastDistance;
  1795. }
  1796. inline float CBaseEntity::GetLocalTime( void ) const
  1797. {
  1798. return m_flLocalTime;
  1799. }
  1800. inline void CBaseEntity::IncrementLocalTime( float flTimeDelta )
  1801. {
  1802. m_flLocalTime += flTimeDelta;
  1803. }
  1804. inline float CBaseEntity::GetMoveDoneTime( ) const
  1805. {
  1806. return (m_flMoveDoneTime >= 0) ? m_flMoveDoneTime - GetLocalTime() : -1;
  1807. }
  1808. inline CBaseEntity *CBaseEntity::Instance( const edict_t *pent )
  1809. {
  1810. return GetContainingEntity( const_cast<edict_t*>(pent) );
  1811. }
  1812. inline CBaseEntity *CBaseEntity::Instance( edict_t *pent )
  1813. {
  1814. if ( !pent )
  1815. {
  1816. pent = INDEXENT(0);
  1817. }
  1818. return GetContainingEntity( pent );
  1819. }
  1820. inline CBaseEntity* CBaseEntity::Instance( int iEnt )
  1821. {
  1822. return Instance( INDEXENT( iEnt ) );
  1823. }
  1824. inline int CBaseEntity::GetWaterLevel() const
  1825. {
  1826. return m_nWaterLevel;
  1827. }
  1828. inline void CBaseEntity::SetWaterLevel( int nLevel )
  1829. {
  1830. m_nWaterLevel = nLevel;
  1831. }
  1832. inline const color32 CBaseEntity::GetRenderColor() const
  1833. {
  1834. return m_clrRender.Get();
  1835. }
  1836. inline void CBaseEntity::SetRenderColor( byte r, byte g, byte b )
  1837. {
  1838. m_clrRender.Init( r, g, b );
  1839. }
  1840. inline void CBaseEntity::SetRenderColor( byte r, byte g, byte b, byte a )
  1841. {
  1842. m_clrRender.Init( r, g, b, a );
  1843. }
  1844. inline void CBaseEntity::SetRenderColorR( byte r )
  1845. {
  1846. m_clrRender.SetR( r );
  1847. }
  1848. inline void CBaseEntity::SetRenderColorG( byte g )
  1849. {
  1850. m_clrRender.SetG( g );
  1851. }
  1852. inline void CBaseEntity::SetRenderColorB( byte b )
  1853. {
  1854. m_clrRender.SetB( b );
  1855. }
  1856. inline void CBaseEntity::SetRenderColorA( byte a )
  1857. {
  1858. m_clrRender.SetA( a );
  1859. }
  1860. inline void CBaseEntity::SetMoveCollide( MoveCollide_t val )
  1861. {
  1862. m_MoveCollide = val;
  1863. }
  1864. inline bool CBaseEntity::IsTransparent() const
  1865. {
  1866. return m_nRenderMode != kRenderNormal;
  1867. }
  1868. inline int CBaseEntity::GetTextureFrameIndex( void )
  1869. {
  1870. return m_iTextureFrameIndex;
  1871. }
  1872. inline void CBaseEntity::SetTextureFrameIndex( int iIndex )
  1873. {
  1874. m_iTextureFrameIndex = iIndex;
  1875. }
  1876. //-----------------------------------------------------------------------------
  1877. // An inline version the game code can use
  1878. //-----------------------------------------------------------------------------
  1879. inline CCollisionProperty *CBaseEntity::CollisionProp()
  1880. {
  1881. return &m_Collision;
  1882. }
  1883. inline const CCollisionProperty *CBaseEntity::CollisionProp() const
  1884. {
  1885. return &m_Collision;
  1886. }
  1887. inline CServerNetworkProperty *CBaseEntity::NetworkProp()
  1888. {
  1889. return &m_Network;
  1890. }
  1891. inline const CServerNetworkProperty *CBaseEntity::NetworkProp() const
  1892. {
  1893. return &m_Network;
  1894. }
  1895. inline void CBaseEntity::ClearSolidFlags( void )
  1896. {
  1897. CollisionProp()->ClearSolidFlags();
  1898. }
  1899. inline void CBaseEntity::RemoveSolidFlags( int flags )
  1900. {
  1901. CollisionProp()->RemoveSolidFlags( flags );
  1902. }
  1903. inline void CBaseEntity::AddSolidFlags( int flags )
  1904. {
  1905. CollisionProp()->AddSolidFlags( flags );
  1906. }
  1907. inline int CBaseEntity::GetSolidFlags( void ) const
  1908. {
  1909. return CollisionProp()->GetSolidFlags();
  1910. }
  1911. inline bool CBaseEntity::IsSolidFlagSet( int flagMask ) const
  1912. {
  1913. return CollisionProp()->IsSolidFlagSet( flagMask );
  1914. }
  1915. inline bool CBaseEntity::IsSolid() const
  1916. {
  1917. return CollisionProp()->IsSolid( );
  1918. }
  1919. inline void CBaseEntity::SetSolid( SolidType_t val )
  1920. {
  1921. CollisionProp()->SetSolid( val );
  1922. }
  1923. inline void CBaseEntity::SetSolidFlags( int flags )
  1924. {
  1925. CollisionProp()->SetSolidFlags( flags );
  1926. }
  1927. inline SolidType_t CBaseEntity::GetSolid() const
  1928. {
  1929. return CollisionProp()->GetSolid();
  1930. }
  1931. //-----------------------------------------------------------------------------
  1932. // Methods related to IServerUnknown
  1933. //-----------------------------------------------------------------------------
  1934. inline ICollideable *CBaseEntity::GetCollideable()
  1935. {
  1936. return &m_Collision;
  1937. }
  1938. inline IServerNetworkable *CBaseEntity::GetNetworkable()
  1939. {
  1940. return &m_Network;
  1941. }
  1942. inline CBaseEntity *CBaseEntity::GetBaseEntity()
  1943. {
  1944. return this;
  1945. }
  1946. //-----------------------------------------------------------------------------
  1947. // Model related methods
  1948. //-----------------------------------------------------------------------------
  1949. inline void CBaseEntity::SetModelName( string_t name )
  1950. {
  1951. m_ModelName = name;
  1952. DispatchUpdateTransmitState();
  1953. }
  1954. inline string_t CBaseEntity::GetModelName( void ) const
  1955. {
  1956. return m_ModelName;
  1957. }
  1958. inline int CBaseEntity::GetModelIndex( void ) const
  1959. {
  1960. return m_nModelIndex;
  1961. }
  1962. //-----------------------------------------------------------------------------
  1963. // Methods relating to bounds
  1964. //-----------------------------------------------------------------------------
  1965. inline const Vector& CBaseEntity::WorldAlignMins( ) const
  1966. {
  1967. Assert( !CollisionProp()->IsBoundsDefinedInEntitySpace() );
  1968. Assert( CollisionProp()->GetCollisionAngles() == vec3_angle );
  1969. return CollisionProp()->OBBMins();
  1970. }
  1971. inline const Vector& CBaseEntity::WorldAlignMaxs( ) const
  1972. {
  1973. Assert( !CollisionProp()->IsBoundsDefinedInEntitySpace() );
  1974. Assert( CollisionProp()->GetCollisionAngles() == vec3_angle );
  1975. return CollisionProp()->OBBMaxs();
  1976. }
  1977. inline const Vector& CBaseEntity::WorldAlignSize( ) const
  1978. {
  1979. Assert( !CollisionProp()->IsBoundsDefinedInEntitySpace() );
  1980. Assert( CollisionProp()->GetCollisionAngles() == vec3_angle );
  1981. return CollisionProp()->OBBSize();
  1982. }
  1983. // Returns a radius of a sphere *centered at the world space center*
  1984. // bounding the collision representation of the entity
  1985. inline float CBaseEntity::BoundingRadius() const
  1986. {
  1987. return CollisionProp()->BoundingRadius();
  1988. }
  1989. inline bool CBaseEntity::IsPointSized() const
  1990. {
  1991. return CollisionProp()->BoundingRadius() == 0.0f;
  1992. }
  1993. inline void CBaseEntity::SetRenderMode( RenderMode_t nRenderMode )
  1994. {
  1995. m_nRenderMode = nRenderMode;
  1996. }
  1997. inline RenderMode_t CBaseEntity::GetRenderMode() const
  1998. {
  1999. return (RenderMode_t)m_nRenderMode.Get();
  2000. }
  2001. //-----------------------------------------------------------------------------
  2002. // Methods to cast away const
  2003. //-----------------------------------------------------------------------------
  2004. inline Vector CBaseEntity::EyePosition( void ) const
  2005. {
  2006. return const_cast<CBaseEntity*>(this)->EyePosition();
  2007. }
  2008. inline const QAngle &CBaseEntity::EyeAngles( void ) const // Direction of eyes in world space
  2009. {
  2010. return const_cast<CBaseEntity*>(this)->EyeAngles();
  2011. }
  2012. inline const QAngle &CBaseEntity::LocalEyeAngles( void ) const // Direction of eyes
  2013. {
  2014. return const_cast<CBaseEntity*>(this)->LocalEyeAngles();
  2015. }
  2016. inline Vector CBaseEntity::EarPosition( void ) const // position of ears
  2017. {
  2018. return const_cast<CBaseEntity*>(this)->EarPosition();
  2019. }
  2020. //-----------------------------------------------------------------------------
  2021. // Methods relating to networking
  2022. //-----------------------------------------------------------------------------
  2023. inline void CBaseEntity::NetworkStateChanged()
  2024. {
  2025. NetworkProp()->NetworkStateChanged();
  2026. }
  2027. inline void CBaseEntity::NetworkStateChanged( void *pVar )
  2028. {
  2029. // Make sure it's a semi-reasonable pointer.
  2030. Assert( (char*)pVar > (char*)this );
  2031. Assert( (char*)pVar - (char*)this < 32768 );
  2032. // Good, they passed an offset so we can track this variable's change
  2033. // and avoid sending the whole entity.
  2034. NetworkProp()->NetworkStateChanged( (char*)pVar - (char*)this );
  2035. }
  2036. //-----------------------------------------------------------------------------
  2037. // IHandleEntity overrides.
  2038. //-----------------------------------------------------------------------------
  2039. inline const CBaseHandle& CBaseEntity::GetRefEHandle() const
  2040. {
  2041. return m_RefEHandle;
  2042. }
  2043. inline void CBaseEntity::IncrementTransmitStateOwnedCounter()
  2044. {
  2045. Assert( m_nTransmitStateOwnedCounter != 255 );
  2046. m_nTransmitStateOwnedCounter++;
  2047. }
  2048. inline void CBaseEntity::DecrementTransmitStateOwnedCounter()
  2049. {
  2050. Assert( m_nTransmitStateOwnedCounter != 0 );
  2051. m_nTransmitStateOwnedCounter--;
  2052. }
  2053. //-----------------------------------------------------------------------------
  2054. // Bullet firing (legacy)...
  2055. //-----------------------------------------------------------------------------
  2056. inline void CBaseEntity::FireBullets( int cShots, const Vector &vecSrc,
  2057. const Vector &vecDirShooting, const Vector &vecSpread, float flDistance,
  2058. int iAmmoType, int iTracerFreq, int firingEntID, int attachmentID,
  2059. int iDamage, CBaseEntity *pAttacker, bool bFirstShotAccurate, bool bPrimaryAttack )
  2060. {
  2061. FireBulletsInfo_t info;
  2062. info.m_iShots = cShots;
  2063. info.m_vecSrc = vecSrc;
  2064. info.m_vecDirShooting = vecDirShooting;
  2065. info.m_vecSpread = vecSpread;
  2066. info.m_flDistance = flDistance;
  2067. info.m_iAmmoType = iAmmoType;
  2068. info.m_iTracerFreq = iTracerFreq;
  2069. info.m_flDamage = iDamage;
  2070. info.m_pAttacker = pAttacker;
  2071. info.m_nFlags = bFirstShotAccurate ? FIRE_BULLETS_FIRST_SHOT_ACCURATE : 0;
  2072. info.m_bPrimaryAttack = bPrimaryAttack;
  2073. FireBullets( info );
  2074. }
  2075. // Ugly technique to override base member functions
  2076. // Normally it's illegal to cast a pointer to a member function of a derived class to a pointer to a
  2077. // member function of a base class. static_cast is a sleezy way around that problem.
  2078. #define SetThink( a ) ThinkSet( static_cast <void (CBaseEntity::*)(void)> (a), 0, NULL )
  2079. #define SetContextThink( a, b, context ) ThinkSet( static_cast <void (CBaseEntity::*)(void)> (a), (b), context )
  2080. #ifdef _DEBUG
  2081. #define SetMoveDone( a ) \
  2082. do \
  2083. { \
  2084. m_pfnMoveDone = static_cast <void (CBaseEntity::*)(void)> (a); \
  2085. FunctionCheck( (void *)*((int *)((char *)this + ( offsetof(CBaseEntity,m_pfnMoveDone)))), "BaseMoveFunc" ); \
  2086. } while ( 0 )
  2087. #else
  2088. #define SetMoveDone( a ) \
  2089. (void)(m_pfnMoveDone = static_cast <void (CBaseEntity::*)(void)> (a))
  2090. #endif
  2091. inline bool FClassnameIs(CBaseEntity *pEntity, const char *szClassname)
  2092. {
  2093. return pEntity->ClassMatches(szClassname);
  2094. }
  2095. class CPointEntity : public CBaseEntity
  2096. {
  2097. public:
  2098. DECLARE_CLASS( CPointEntity, CBaseEntity );
  2099. void Spawn( void );
  2100. virtual int ObjectCaps( void ) { return BaseClass::ObjectCaps() & ~FCAP_ACROSS_TRANSITION; }
  2101. virtual bool KeyValue( const char *szKeyName, const char *szValue );
  2102. private:
  2103. };
  2104. // Has a position + size
  2105. class CServerOnlyEntity : public CBaseEntity
  2106. {
  2107. DECLARE_CLASS( CServerOnlyEntity, CBaseEntity );
  2108. public:
  2109. CServerOnlyEntity() : CBaseEntity( true ) {}
  2110. virtual int ObjectCaps( void ) { return (BaseClass::ObjectCaps() & ~FCAP_ACROSS_TRANSITION); }
  2111. };
  2112. // Has only a position, no size
  2113. class CServerOnlyPointEntity : public CServerOnlyEntity
  2114. {
  2115. DECLARE_CLASS( CServerOnlyPointEntity, CServerOnlyEntity );
  2116. public:
  2117. virtual bool KeyValue( const char *szKeyName, const char *szValue );
  2118. };
  2119. // Has no position or size
  2120. class CLogicalEntity : public CServerOnlyEntity
  2121. {
  2122. DECLARE_CLASS( CLogicalEntity, CServerOnlyEntity );
  2123. public:
  2124. virtual bool KeyValue( const char *szKeyName, const char *szValue );
  2125. };
  2126. // Network proxy functions
  2127. void SendProxy_Origin( const SendProp *pProp, const void *pStruct, const void *pData, DVariant *pOut, int iElement, int objectID );
  2128. void SendProxy_OriginXY( const SendProp *pProp, const void *pStruct, const void *pData, DVariant *pOut, int iElement, int objectID );
  2129. void SendProxy_OriginZ( const SendProp *pProp, const void *pStruct, const void *pData, DVariant *pOut, int iElement, int objectID );
  2130. #endif // BASEENTITY_H