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

314 lines
7.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef BASEENTITY_SHARED_H
  8. #define BASEENTITY_SHARED_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. extern ConVar hl2_episodic;
  13. // Simple shared header file for common base entities
  14. // entity capabilities
  15. // These are caps bits to indicate what an object's capabilities (currently used for +USE, save/restore and level transitions)
  16. #define FCAP_MUST_SPAWN 0x00000001 // Spawn after restore
  17. #define FCAP_ACROSS_TRANSITION 0x00000002 // should transfer between transitions
  18. // UNDONE: This will ignore transition volumes (trigger_transition), but not the PVS!!!
  19. #define FCAP_FORCE_TRANSITION 0x00000004 // ALWAYS goes across transitions
  20. #define FCAP_NOTIFY_ON_TRANSITION 0x00000008 // Entity will receive Inside/Outside transition inputs when a transition occurs
  21. #define FCAP_IMPULSE_USE 0x00000010 // can be used by the player
  22. #define FCAP_CONTINUOUS_USE 0x00000020 // can be used by the player
  23. #define FCAP_ONOFF_USE 0x00000040 // can be used by the player
  24. #define FCAP_DIRECTIONAL_USE 0x00000080 // Player sends +/- 1 when using (currently only tracktrains)
  25. // NOTE: Normally +USE only works in direct line of sight. Add these caps for additional searches
  26. #define FCAP_USE_ONGROUND 0x00000100
  27. #define FCAP_USE_IN_RADIUS 0x00000200
  28. #define FCAP_SAVE_NON_NETWORKABLE 0x00000400
  29. #define FCAP_MASTER 0x10000000 // Can be used to "master" other entities (like multisource)
  30. #define FCAP_WCEDIT_POSITION 0x40000000 // Can change position and update Hammer in edit mode
  31. #define FCAP_DONT_SAVE 0x80000000 // Don't save this
  32. // How many bits are used to transmit parent attachment indices?
  33. #define NUM_PARENTATTACHMENT_BITS 6
  34. // Maximum number of vphysics objects per entity
  35. #define VPHYSICS_MAX_OBJECT_LIST_COUNT 1024
  36. //-----------------------------------------------------------------------------
  37. // For invalidate physics recursive
  38. //-----------------------------------------------------------------------------
  39. enum InvalidatePhysicsBits_t
  40. {
  41. POSITION_CHANGED = 0x1,
  42. ANGLES_CHANGED = 0x2,
  43. VELOCITY_CHANGED = 0x4,
  44. ANIMATION_CHANGED = 0x8,
  45. };
  46. #if defined( CLIENT_DLL )
  47. #include "c_baseentity.h"
  48. #include "c_baseanimating.h"
  49. #else
  50. #include "baseentity.h"
  51. #ifdef HL2_EPISODIC
  52. #include "info_darknessmode_lightsource.h"
  53. #endif // HL2_EPISODIC
  54. #endif
  55. #if !defined( NO_ENTITY_PREDICTION )
  56. // CBaseEntity inlines
  57. inline bool CBaseEntity::IsPlayerSimulated( void ) const
  58. {
  59. return m_bIsPlayerSimulated;
  60. }
  61. inline CBasePlayer *CBaseEntity::GetSimulatingPlayer( void )
  62. {
  63. return m_hPlayerSimulationOwner;
  64. }
  65. #endif
  66. inline MoveType_t CBaseEntity::GetMoveType() const
  67. {
  68. return (MoveType_t)(unsigned char)m_MoveType;
  69. }
  70. inline MoveCollide_t CBaseEntity::GetMoveCollide() const
  71. {
  72. return (MoveCollide_t)(unsigned char)m_MoveCollide;
  73. }
  74. //-----------------------------------------------------------------------------
  75. // Collision group accessors
  76. //-----------------------------------------------------------------------------
  77. inline int CBaseEntity::GetCollisionGroup() const
  78. {
  79. return m_CollisionGroup;
  80. }
  81. inline int CBaseEntity::GetFlags( void ) const
  82. {
  83. return m_fFlags;
  84. }
  85. inline bool CBaseEntity::IsAlive( void )
  86. {
  87. return m_lifeState == LIFE_ALIVE;
  88. }
  89. inline CBaseEntity *CBaseEntity::GetOwnerEntity() const
  90. {
  91. return m_hOwnerEntity.Get();
  92. }
  93. inline CBaseEntity *CBaseEntity::GetEffectEntity() const
  94. {
  95. return m_hEffectEntity.Get();
  96. }
  97. inline int CBaseEntity::GetPredictionRandomSeed( bool bUseUnSyncedServerPlatTime )
  98. {
  99. #ifdef GAME_DLL
  100. return bUseUnSyncedServerPlatTime ? m_nPredictionRandomSeedServer : m_nPredictionRandomSeed;
  101. #else
  102. return m_nPredictionRandomSeed;
  103. #endif
  104. }
  105. inline CBasePlayer *CBaseEntity::GetPredictionPlayer( void )
  106. {
  107. return m_pPredictionPlayer;
  108. }
  109. inline void CBaseEntity::SetPredictionPlayer( CBasePlayer *player )
  110. {
  111. m_pPredictionPlayer = player;
  112. }
  113. inline bool CBaseEntity::IsSimulatedEveryTick() const
  114. {
  115. return m_bSimulatedEveryTick;
  116. }
  117. inline bool CBaseEntity::IsAnimatedEveryTick() const
  118. {
  119. return m_bAnimatedEveryTick;
  120. }
  121. inline void CBaseEntity::SetSimulatedEveryTick( bool sim )
  122. {
  123. if ( m_bSimulatedEveryTick != sim )
  124. {
  125. m_bSimulatedEveryTick = sim;
  126. #ifdef CLIENT_DLL
  127. Interp_UpdateInterpolationAmounts( GetVarMapping() );
  128. #endif
  129. }
  130. }
  131. inline void CBaseEntity::SetAnimatedEveryTick( bool anim )
  132. {
  133. if ( m_bAnimatedEveryTick != anim )
  134. {
  135. m_bAnimatedEveryTick = anim;
  136. #ifdef CLIENT_DLL
  137. Interp_UpdateInterpolationAmounts( GetVarMapping() );
  138. #endif
  139. }
  140. }
  141. inline float CBaseEntity::GetAnimTime() const
  142. {
  143. return m_flAnimTime;
  144. }
  145. inline float CBaseEntity::GetSimulationTime() const
  146. {
  147. return m_flSimulationTime;
  148. }
  149. inline void CBaseEntity::SetAnimTime( float at )
  150. {
  151. m_flAnimTime = at;
  152. }
  153. inline void CBaseEntity::SetSimulationTime( float st )
  154. {
  155. m_flSimulationTime = st;
  156. }
  157. inline int CBaseEntity::GetEffects( void ) const
  158. {
  159. return m_fEffects;
  160. }
  161. inline void CBaseEntity::RemoveEffects( int nEffects )
  162. {
  163. #if !defined( CLIENT_DLL )
  164. #ifdef HL2_EPISODIC
  165. if ( nEffects & (EF_BRIGHTLIGHT|EF_DIMLIGHT) )
  166. {
  167. // Hack for now, to avoid player emitting radius with his flashlight
  168. if ( !IsPlayer() )
  169. {
  170. RemoveEntityFromDarknessCheck( this );
  171. }
  172. }
  173. #endif // HL2_EPISODIC
  174. #endif // !CLIENT_DLL
  175. m_fEffects &= ~nEffects;
  176. if ( nEffects & EF_NODRAW )
  177. {
  178. #ifndef CLIENT_DLL
  179. NetworkProp()->MarkPVSInformationDirty();
  180. DispatchUpdateTransmitState();
  181. #else
  182. UpdateVisibility();
  183. #endif
  184. }
  185. }
  186. inline void CBaseEntity::ClearEffects( void )
  187. {
  188. #if !defined( CLIENT_DLL )
  189. #ifdef HL2_EPISODIC
  190. if ( m_fEffects & (EF_BRIGHTLIGHT|EF_DIMLIGHT) )
  191. {
  192. // Hack for now, to avoid player emitting radius with his flashlight
  193. if ( !IsPlayer() )
  194. {
  195. RemoveEntityFromDarknessCheck( this );
  196. }
  197. }
  198. #endif // HL2_EPISODIC
  199. #endif // !CLIENT_DLL
  200. m_fEffects = 0;
  201. #ifndef CLIENT_DLL
  202. DispatchUpdateTransmitState();
  203. #else
  204. UpdateVisibility();
  205. #endif
  206. }
  207. inline bool CBaseEntity::IsEffectActive( int nEffects ) const
  208. {
  209. return (m_fEffects & nEffects) != 0;
  210. }
  211. // Shared EntityMessage between game and client .dlls
  212. #define BASEENTITY_MSG_REMOVE_DECALS 1
  213. extern float k_flMaxEntityPosCoord;
  214. extern float k_flMaxEntityEulerAngle;
  215. extern float k_flMaxEntitySpeed;
  216. extern float k_flMaxEntitySpinRate;
  217. inline bool IsEntityCoordinateReasonable ( const vec_t c )
  218. {
  219. float r = k_flMaxEntityPosCoord;
  220. return c > -r && c < r;
  221. }
  222. inline bool IsEntityPositionReasonable( const Vector &v )
  223. {
  224. float r = k_flMaxEntityPosCoord;
  225. return
  226. v.x > -r && v.x < r &&
  227. v.y > -r && v.y < r &&
  228. v.z > -r && v.z < r;
  229. }
  230. // Returns:
  231. // -1 - velocity is really, REALLY bad and probably should be rejected.
  232. // 0 - velocity was suspicious and clamped.
  233. // 1 - velocity was OK and not modified
  234. extern int CheckEntityVelocity( Vector &v );
  235. inline bool IsEntityQAngleReasonable( const QAngle &q )
  236. {
  237. float r = k_flMaxEntityEulerAngle;
  238. return
  239. q.x > -r && q.x < r &&
  240. q.y > -r && q.y < r &&
  241. q.z > -r && q.z < r;
  242. }
  243. // Angular velocity in exponential map form
  244. inline bool IsEntityAngularVelocityReasonable( const Vector &q )
  245. {
  246. float r = k_flMaxEntitySpinRate;
  247. return
  248. q.x > -r && q.x < r &&
  249. q.y > -r && q.y < r &&
  250. q.z > -r && q.z < r;
  251. }
  252. // Angular velocity of each Euler angle.
  253. inline bool IsEntityQAngleVelReasonable( const QAngle &q )
  254. {
  255. float r = k_flMaxEntitySpinRate;
  256. return
  257. q.x > -r && q.x < r &&
  258. q.y > -r && q.y < r &&
  259. q.z > -r && q.z < r;
  260. }
  261. extern bool CheckEmitReasonablePhysicsSpew();
  262. #endif // BASEENTITY_SHARED_H