Counter Strike : Global Offensive Source Code
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.

2970 lines
103 KiB

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