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.

382 lines
9.3 KiB

  1. //========= Copyright � 1996-2005, 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. #ifndef CLIENT_DLL
  13. #define SERVER_PLATTIME_RNG true
  14. #else
  15. #define SERVER_PLATTIME_RNG
  16. #endif
  17. extern ConVar hl2_episodic;
  18. // Simple shared header file for common base entities
  19. // entity capabilities
  20. // These are caps bits to indicate what an object's capabilities (currently used for +USE, save/restore and level transitions)
  21. // NOTE: (For portal 2 and paint) These +use related caps MUST be the first 6 bits!
  22. #define FCAP_IMPULSE_USE 0x00000001 // can be used by the player
  23. #define FCAP_CONTINUOUS_USE 0x00000002 // can be used by the player
  24. #define FCAP_ONOFF_USE 0x00000004 // can be used by the player
  25. #define FCAP_DIRECTIONAL_USE 0x00000008 // Player sends +/- 1 when using (currently only tracktrains)
  26. // NOTE: Normally +USE only works in direct line of sight. Add these caps for additional searches
  27. #define FCAP_USE_ONGROUND 0x00000010
  28. #define FCAP_USE_IN_RADIUS 0x00000020
  29. #define FCAP_MUST_SPAWN 0x00000040 // Spawn after restore
  30. #define FCAP_ACROSS_TRANSITION 0x00000080 // should transfer between transitions
  31. // UNDONE: This will ignore transition volumes (trigger_transition), but not the PVS!!!
  32. #define FCAP_FORCE_TRANSITION 0x00000100 // ALWAYS goes across transitions
  33. #define FCAP_NOTIFY_ON_TRANSITION 0x00000200 // Entity will receive Inside/Outside transition inputs when a transition occurs
  34. #define FCAP_SAVE_NON_NETWORKABLE 0x00000400
  35. #define FCAP_MASTER 0x10000000 // Can be used to "master" other entities (like multisource)
  36. #define FCAP_WCEDIT_POSITION 0x40000000 // Can change position and update Hammer in edit mode
  37. #define FCAP_DONT_SAVE 0x80000000 // Don't save this
  38. // How many bits are used to transmit parent attachment indices?
  39. #define NUM_PARENTATTACHMENT_BITS 6
  40. // Maximum number of vphysics objects per entity
  41. #define VPHYSICS_MAX_OBJECT_LIST_COUNT 1024
  42. #define DEFAULT_LOOK_AT_USE_ANGLE 0.8f
  43. #if defined( CLIENT_DLL )
  44. #include "c_baseentity.h"
  45. #include "c_baseanimating.h"
  46. #else
  47. #include "baseentity.h"
  48. #ifdef HL2_EPISODIC
  49. #include "info_darknessmode_lightsource.h"
  50. #endif // HL2_EPISODIC
  51. #endif
  52. #include "vscript/ivscript.h"
  53. #include "vscript_shared.h"
  54. #if !defined( NO_ENTITY_PREDICTION )
  55. // CBaseEntity inlines
  56. inline bool CBaseEntity::IsPlayerSimulated( void ) const
  57. {
  58. return m_bIsPlayerSimulated;
  59. }
  60. inline CBasePlayer *CBaseEntity::GetSimulatingPlayer( void )
  61. {
  62. return m_hPlayerSimulationOwner.Get();
  63. }
  64. #endif
  65. inline MoveType_t CBaseEntity::GetMoveType() const
  66. {
  67. return (MoveType_t)(unsigned char)m_MoveType;
  68. }
  69. inline MoveCollide_t CBaseEntity::GetMoveCollide() const
  70. {
  71. return (MoveCollide_t)(unsigned char)m_MoveCollide;
  72. }
  73. //-----------------------------------------------------------------------------
  74. // Collision group accessors
  75. //-----------------------------------------------------------------------------
  76. inline int CBaseEntity::GetCollisionGroup() const
  77. {
  78. return m_CollisionGroup;
  79. }
  80. inline int CBaseEntity::GetFlags( void ) const
  81. {
  82. return m_fFlags;
  83. }
  84. inline bool CBaseEntity::IsAlive( void )const
  85. {
  86. return m_lifeState == LIFE_ALIVE;
  87. }
  88. inline CBaseEntity *CBaseEntity::GetOwnerEntity() const
  89. {
  90. return m_hOwnerEntity.Get();
  91. }
  92. inline CBaseEntity *CBaseEntity::GetEffectEntity() const
  93. {
  94. return m_hEffectEntity.Get();
  95. }
  96. #ifdef CLIENT_DLL
  97. inline int CBaseEntity::GetPredictionRandomSeed( void )
  98. {
  99. return m_nPredictionRandomSeed;
  100. }
  101. #else
  102. inline int CBaseEntity::GetPredictionRandomSeed( bool bUseUnSyncedServerPlatTime )
  103. {
  104. return bUseUnSyncedServerPlatTime ? m_nPredictionRandomSeedServer : m_nPredictionRandomSeed;
  105. }
  106. #endif
  107. inline CBasePlayer *CBaseEntity::GetPredictionPlayer( void )
  108. {
  109. return m_pPredictionPlayer;
  110. }
  111. inline void CBaseEntity::SetPredictionPlayer( CBasePlayer *player )
  112. {
  113. m_pPredictionPlayer = player;
  114. }
  115. inline bool CBaseEntity::IsSimulatedEveryTick() const
  116. {
  117. return m_bSimulatedEveryTick;
  118. }
  119. inline bool CBaseEntity::IsAnimatedEveryTick() const
  120. {
  121. return m_bAnimatedEveryTick;
  122. }
  123. inline void CBaseEntity::SetSimulatedEveryTick( bool sim )
  124. {
  125. if ( m_bSimulatedEveryTick != sim )
  126. {
  127. m_bSimulatedEveryTick = sim;
  128. #ifdef CLIENT_DLL
  129. Interp_UpdateInterpolationAmounts( GetVarMapping() );
  130. #endif
  131. }
  132. }
  133. inline void CBaseEntity::SetAnimatedEveryTick( bool anim )
  134. {
  135. if ( m_bAnimatedEveryTick != anim )
  136. {
  137. m_bAnimatedEveryTick = anim;
  138. #ifdef CLIENT_DLL
  139. Interp_UpdateInterpolationAmounts( GetVarMapping() );
  140. #endif
  141. }
  142. }
  143. inline float CBaseEntity::GetAnimTime() const
  144. {
  145. return m_flAnimTime;
  146. }
  147. inline float CBaseEntity::GetSimulationTime() const
  148. {
  149. return m_flSimulationTime;
  150. }
  151. inline void CBaseEntity::SetAnimTime( float at )
  152. {
  153. m_flAnimTime = at;
  154. }
  155. inline void CBaseEntity::SetSimulationTime( float st )
  156. {
  157. m_flSimulationTime = st;
  158. }
  159. inline int CBaseEntity::GetEffects( void ) const
  160. {
  161. return m_fEffects;
  162. }
  163. inline void CBaseEntity::RemoveEffects( int nEffects )
  164. {
  165. #if !defined( CLIENT_DLL )
  166. #ifdef HL2_EPISODIC
  167. if ( nEffects & (EF_BRIGHTLIGHT|EF_DIMLIGHT) )
  168. {
  169. // Hack for now, to avoid player emitting radius with his flashlight
  170. if ( !IsPlayer() )
  171. {
  172. RemoveEntityFromDarknessCheck( this );
  173. }
  174. }
  175. #endif // HL2_EPISODIC
  176. #endif // !CLIENT_DLL
  177. m_fEffects &= ~nEffects;
  178. if ( nEffects & EF_NODRAW )
  179. {
  180. #ifndef CLIENT_DLL
  181. NetworkProp()->MarkPVSInformationDirty();
  182. DispatchUpdateTransmitState();
  183. #else
  184. UpdateVisibility();
  185. #endif
  186. }
  187. #ifdef CLIENT_DLL
  188. if ( nEffects & EF_MARKED_FOR_FAST_REFLECTION )
  189. {
  190. OnFastReflectionRenderingChanged();
  191. }
  192. OnDisableShadowDepthRenderingChanged();
  193. OnDisableCSMRenderingChanged();
  194. OnShadowDepthRenderingCacheableStateChanged();
  195. #endif
  196. }
  197. inline void CBaseEntity::ClearEffects( void )
  198. {
  199. #if !defined( CLIENT_DLL )
  200. #ifdef HL2_EPISODIC
  201. if ( m_fEffects & (EF_BRIGHTLIGHT|EF_DIMLIGHT) )
  202. {
  203. // Hack for now, to avoid player emitting radius with his flashlight
  204. if ( !IsPlayer() )
  205. {
  206. RemoveEntityFromDarknessCheck( this );
  207. }
  208. }
  209. #endif // HL2_EPISODIC
  210. #endif // !CLIENT_DLL
  211. #ifdef CLIENT_DLL
  212. bool bRendersInFastReflection = ( m_fEffects & EF_MARKED_FOR_FAST_REFLECTION ) != 0;
  213. #endif
  214. m_fEffects = 0;
  215. #ifndef CLIENT_DLL
  216. DispatchUpdateTransmitState();
  217. #else
  218. UpdateVisibility();
  219. if ( bRendersInFastReflection )
  220. {
  221. OnFastReflectionRenderingChanged();
  222. }
  223. OnDisableShadowDepthRenderingChanged();
  224. OnDisableCSMRenderingChanged();
  225. OnShadowDepthRenderingCacheableStateChanged();
  226. #endif
  227. }
  228. inline bool CBaseEntity::IsEffectActive( int nEffects ) const
  229. {
  230. return (m_fEffects & nEffects) != 0;
  231. }
  232. inline HSCRIPT ToHScript( CBaseEntity *pEnt )
  233. {
  234. return ( pEnt ) ? pEnt->GetScriptInstance() : NULL;
  235. }
  236. template <> ScriptClassDesc_t *GetScriptDesc<CBaseEntity>( CBaseEntity * );
  237. inline CBaseEntity *ToEnt( HSCRIPT hScript )
  238. {
  239. return ( hScript ) ? (CBaseEntity *)g_pScriptVM->GetInstanceValue( hScript, GetScriptDescForClass(CBaseEntity) ) : NULL;
  240. }
  241. // convenience functions for fishing out the vectors of this object
  242. // equivalent to GetVectors(), but doesn't need an intermediate stack
  243. // variable (which might cause an LHS anyway)
  244. inline Vector CBaseEntity::Forward() const RESTRICT ///< get my forward (+x) vector
  245. {
  246. const matrix3x4_t &mat = EntityToWorldTransform();
  247. return Vector( mat[0][0], mat[1][0], mat[2][0] );
  248. }
  249. inline Vector CBaseEntity::Left() const RESTRICT ///< get my left (+y) vector
  250. {
  251. const matrix3x4_t &mat = EntityToWorldTransform();
  252. return Vector( mat[0][1], mat[1][1], mat[2][1] );
  253. }
  254. inline Vector CBaseEntity::Up() const RESTRICT ///< get my up (+z) vector
  255. {
  256. const matrix3x4_t &mat = EntityToWorldTransform();
  257. return Vector( mat[0][2], mat[1][2], mat[2][2] );
  258. }
  259. // Shared EntityMessage between game and client .dlls
  260. #define BASEENTITY_MSG_REMOVE_DECALS 1
  261. inline bool IsPushableMoveType( int nMoveType )
  262. {
  263. if ( nMoveType == MOVETYPE_PUSH || nMoveType == MOVETYPE_NONE ||
  264. nMoveType == MOVETYPE_VPHYSICS || nMoveType == MOVETYPE_NOCLIP )
  265. return false;
  266. return true;
  267. }
  268. extern float k_flMaxEntityPosCoord;
  269. extern float k_flMaxEntityEulerAngle;
  270. extern float k_flMaxEntitySpeed;
  271. extern float k_flMaxEntitySpinRate;
  272. inline bool IsEntityCoordinateReasonable( const vec_t c )
  273. {
  274. float r = k_flMaxEntityPosCoord;
  275. return c > -r && c < r;
  276. }
  277. inline bool IsEntityPositionReasonable( const Vector &v )
  278. {
  279. float r = k_flMaxEntityPosCoord;
  280. return
  281. v.x > -r && v.x < r &&
  282. v.y > -r && v.y < r &&
  283. v.z > -r && v.z < r;
  284. }
  285. // Returns:
  286. // -1 - velocity is really, REALLY bad and probably should be rejected.
  287. // 0 - velocity was suspicious and clamped.
  288. // 1 - velocity was OK and not modified
  289. extern int CheckEntityVelocity( Vector &v );
  290. inline bool IsEntityQAngleReasonable( const QAngle &q )
  291. {
  292. float r = k_flMaxEntityEulerAngle;
  293. return
  294. q.x > -r && q.x < r &&
  295. q.y > -r && q.y < r &&
  296. q.z > -r && q.z < r;
  297. }
  298. // Angular velocity in exponential map form
  299. inline bool IsEntityAngularVelocityReasonable( const Vector &q )
  300. {
  301. float r = k_flMaxEntitySpinRate;
  302. return
  303. q.x > -r && q.x < r &&
  304. q.y > -r && q.y < r &&
  305. q.z > -r && q.z < r;
  306. }
  307. // Angular velocity of each Euler angle.
  308. inline bool IsEntityQAngleVelReasonable( const QAngle &q )
  309. {
  310. float r = k_flMaxEntitySpinRate;
  311. return
  312. q.x > -r && q.x < r &&
  313. q.y > -r && q.y < r &&
  314. q.z > -r && q.z < r;
  315. }
  316. // Should we emit physics spew into the log or not?
  317. extern bool CheckEmitReasonablePhysicsSpew();
  318. #endif // BASEENTITY_SHARED_H