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.

515 lines
18 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef PROPS_H
  8. #define PROPS_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "props_shared.h"
  13. #include "baseanimating.h"
  14. #include "physics_bone_follower.h"
  15. #include "player_pickup.h"
  16. #include "positionwatcher.h"
  17. #include "nav_mesh.h"
  18. //=============================================================================================================
  19. // PROP TYPES
  20. //=============================================================================================================
  21. //-----------------------------------------------------------------------------
  22. // Purpose:
  23. //-----------------------------------------------------------------------------
  24. class CBaseProp : public CBaseAnimating
  25. {
  26. DECLARE_CLASS( CBaseProp, CBaseAnimating );
  27. public:
  28. void Spawn( void );
  29. void Precache( void );
  30. void Activate( void );
  31. bool KeyValue( const char *szKeyName, const char *szValue );
  32. void CalculateBlockLOS( void );
  33. int ParsePropData( void );
  34. void DrawDebugGeometryOverlays( void );
  35. // Don't treat as a live target
  36. virtual bool IsAlive( void ) { return false; }
  37. virtual bool OverridePropdata() { return true; }
  38. };
  39. //-----------------------------------------------------------------------------
  40. // Purpose:
  41. //-----------------------------------------------------------------------------
  42. class CBreakableProp : public CBaseProp, public IBreakableWithPropData, public CDefaultPlayerPickupVPhysics
  43. {
  44. public:
  45. CBreakableProp();
  46. DECLARE_CLASS( CBreakableProp, CBaseProp );
  47. DECLARE_SERVERCLASS();
  48. DECLARE_DATADESC();
  49. virtual void Spawn();
  50. virtual void Precache();
  51. virtual float GetAutoAimRadius() { return 24.0f; }
  52. virtual void UpdateOnRemove();
  53. void BreakablePropTouch( CBaseEntity *pOther );
  54. virtual int OnTakeDamage( const CTakeDamageInfo &info );
  55. void Event_Killed( const CTakeDamageInfo &info );
  56. void Break( CBaseEntity *pBreaker, const CTakeDamageInfo &info );
  57. void BreakThink( void );
  58. void AnimateThink( void );
  59. virtual void PlayPuntSound();
  60. void InputBreak( inputdata_t &inputdata );
  61. void InputAddHealth( inputdata_t &inputdata );
  62. void InputRemoveHealth( inputdata_t &inputdata );
  63. void InputSetHealth( inputdata_t &inputdata );
  64. int GetNumBreakableChunks( void ) { return m_iNumBreakableChunks; }
  65. virtual bool OverridePropdata() { return false; }
  66. virtual IPhysicsObject *GetRootPhysicsObjectForBreak();
  67. bool PropDataOverrodeBlockLOS( void ) { return m_bBlockLOSSetByPropData; }
  68. bool PropDataOverrodeAIWalkable( void ) { return m_bIsWalkableSetByPropData; }
  69. virtual bool HasPreferredCarryAnglesForPlayer( CBasePlayer *pPlayer )
  70. {
  71. if ( HasInteraction( PROPINTER_PHYSGUN_LAUNCH_SPIN_Z ) )
  72. return true;
  73. return false;
  74. }
  75. virtual QAngle PreferredCarryAngles( void ) { return m_preferredCarryAngles; }
  76. virtual void Ignite( float flFlameLifetime, bool bNPCOnly, float flSize = 0.0f, bool bCalledByLevelDesigner = false );
  77. // Specific interactions
  78. void HandleFirstCollisionInteractions( int index, gamevcollisionevent_t *pEvent );
  79. void HandleInteractionStick( int index, gamevcollisionevent_t *pEvent );
  80. void StickAtPosition( const Vector &stickPosition, const Vector &savePosition, const QAngle &saveAngles );
  81. // Disable auto fading under dx7 or when level fades are specified
  82. void DisableAutoFade();
  83. public:
  84. COutputEvent m_OnBreak;
  85. COutputFloat m_OnHealthChanged;
  86. COutputEvent m_OnTakeDamage;
  87. float m_impactEnergyScale;
  88. int m_iMinHealthDmg;
  89. QAngle m_preferredCarryAngles;
  90. public:
  91. // IBreakableWithPropData
  92. void SetDmgModBullet( float flDmgMod ) { m_flDmgModBullet = flDmgMod; }
  93. void SetDmgModClub( float flDmgMod ) { m_flDmgModClub = flDmgMod; }
  94. void SetDmgModExplosive( float flDmgMod ) { m_flDmgModExplosive = flDmgMod; }
  95. void SetDmgModFire( float flDmgMod ) { m_flDmgModFire = flDmgMod; }
  96. float GetDmgModBullet( void ) { return m_flDmgModBullet; }
  97. float GetDmgModClub( void ) { return m_flDmgModClub; }
  98. float GetDmgModExplosive( void ) { return m_flDmgModExplosive; }
  99. float GetDmgModFire( void ) { return m_flDmgModFire; }
  100. void SetExplosiveRadius( float flRadius ) { m_explodeRadius = flRadius; }
  101. void SetExplosiveDamage( float flDamage ) { m_explodeDamage = flDamage; }
  102. float GetExplosiveRadius( void ) { return m_explodeRadius; }
  103. float GetExplosiveDamage( void ) { return m_explodeDamage; }
  104. void SetPhysicsDamageTable( string_t iszTableName ) { m_iszPhysicsDamageTableName = iszTableName; }
  105. string_t GetPhysicsDamageTable( void ) { return m_iszPhysicsDamageTableName; }
  106. void SetBreakableModel( string_t iszModel ) { m_iszBreakableModel = iszModel; }
  107. string_t GetBreakableModel( void ) { return m_iszBreakableModel; }
  108. void SetBreakableSkin( int iSkin ) { m_iBreakableSkin = iSkin; }
  109. int GetBreakableSkin( void ) { return m_iBreakableSkin; }
  110. void SetBreakableCount( int iCount ) { m_iBreakableCount = iCount; }
  111. int GetBreakableCount( void ) { return m_iBreakableCount; }
  112. void SetMaxBreakableSize( int iSize ) { m_iMaxBreakableSize = iSize; }
  113. int GetMaxBreakableSize( void ) { return m_iMaxBreakableSize; }
  114. void SetPropDataBlocksLOS( bool bBlocksLOS ) { m_bBlockLOSSetByPropData = true; SetBlocksLOS( bBlocksLOS ); }
  115. void SetPropDataIsAIWalkable( bool b ) { m_bIsWalkableSetByPropData = true; SetAIWalkable( b ); }
  116. void SetBasePropData( string_t iszBase ) { m_iszBasePropData = iszBase; }
  117. string_t GetBasePropData( void ) { return m_iszBasePropData; }
  118. void SetInteraction( propdata_interactions_t Interaction ) { m_iInteractions |= (1 << Interaction); }
  119. void RemoveInteraction( propdata_interactions_t Interaction ) { m_iInteractions &= ~(1 << Interaction); }
  120. bool HasInteraction( propdata_interactions_t Interaction ) { return ( m_iInteractions & (1 << Interaction) ) != 0; }
  121. void SetMultiplayerBreakMode( mp_break_t mode ) { m_mpBreakMode = mode; }
  122. mp_break_t GetMultiplayerBreakMode( void ) const { return m_mpBreakMode; }
  123. // derived by multiplayer phys props:
  124. // Base prop_physics can be client-side etc
  125. virtual void SetPhysicsMode(int iMode) { m_iPhysicsMode = iMode; }
  126. virtual int GetPhysicsMode() { return m_iPhysicsMode; }
  127. // Copy fade from another breakable prop
  128. void CopyFadeFrom( CBreakableProp *pSource );
  129. protected:
  130. bool UpdateHealth( int iNewHealth, CBaseEntity *pActivator );
  131. virtual void OnBreak( const Vector &vecVelocity, const AngularImpulse &angVel, CBaseEntity *pBreaker ) {}
  132. protected:
  133. //Base prop_physics can be client-side etc
  134. int m_iPhysicsMode;
  135. unsigned int m_createTick;
  136. float m_flPressureDelay;
  137. EHANDLE m_hBreaker;
  138. PerformanceMode_t m_PerformanceMode;
  139. // Prop data storage
  140. float m_flDmgModBullet;
  141. float m_flDmgModClub;
  142. float m_flDmgModExplosive;
  143. float m_flDmgModFire;
  144. string_t m_iszPhysicsDamageTableName;
  145. string_t m_iszBreakableModel;
  146. int m_iBreakableSkin;
  147. int m_iBreakableCount;
  148. int m_iMaxBreakableSize;
  149. string_t m_iszBasePropData;
  150. int m_iInteractions;
  151. float m_explodeDamage;
  152. float m_explodeRadius;
  153. // Count of how many pieces we'll break into, custom or generic
  154. int m_iNumBreakableChunks;
  155. void SetEnableMotionPosition( const Vector &position, const QAngle &angles );
  156. bool GetEnableMotionPosition( Vector *pPosition, QAngle *pAngles );
  157. void ClearEnableMotionPosition();
  158. private:
  159. CBaseEntity *FindEnableMotionFixup();
  160. public:
  161. virtual bool OnAttemptPhysGunPickup( CBasePlayer *pPhysGunUser, PhysGunPickup_t reason );
  162. virtual void OnPhysGunPickup( CBasePlayer *pPhysGunUser, PhysGunPickup_t reason );
  163. virtual void OnPhysGunDrop( CBasePlayer *pPhysGunUser, PhysGunDrop_t reason );
  164. virtual AngularImpulse PhysGunLaunchAngularImpulse();
  165. virtual CBasePlayer *HasPhysicsAttacker( float dt );
  166. void SetPhysicsAttacker( CBasePlayer *pEntity, float flTime );
  167. #ifdef HL2_EPISODIC
  168. void CreateFlare( float flLifetime );
  169. #endif //HL2_EPISODIC
  170. protected:
  171. void CheckRemoveRagdolls();
  172. private:
  173. void InputEnablePhyscannonPickup( inputdata_t &inputdata );
  174. void InputDisablePhyscannonPickup( inputdata_t &inputdata );
  175. void InputEnablePuntSound( inputdata_t &inputdata ) { m_bUsePuntSound = true; }
  176. void InputDisablePuntSound( inputdata_t &inputdata ) { m_bUsePuntSound = false; }
  177. // Prevents fade scale from happening
  178. void ForceFadeScaleToAlwaysVisible();
  179. void RampToDefaultFadeScale();
  180. private:
  181. enum PhysgunState_t
  182. {
  183. PHYSGUN_MUST_BE_DETACHED = 0,
  184. PHYSGUN_IS_DETACHING,
  185. PHYSGUN_CAN_BE_GRABBED,
  186. PHYSGUN_ANIMATE_ON_PULL,
  187. PHYSGUN_ANIMATE_IS_ANIMATING,
  188. PHYSGUN_ANIMATE_FINISHED,
  189. PHYSGUN_ANIMATE_IS_PRE_ANIMATING,
  190. PHYSGUN_ANIMATE_IS_POST_ANIMATING,
  191. };
  192. CHandle<CBasePlayer> m_hPhysicsAttacker;
  193. float m_flLastPhysicsInfluenceTime;
  194. bool m_bBlockLOSSetByPropData;
  195. bool m_bIsWalkableSetByPropData;
  196. bool m_bOriginalBlockLOS; // BlockLOS state before physgun pickup
  197. char m_nPhysgunState; // Ripped-off state
  198. COutputEvent m_OnPhysCannonDetach; // We've ripped it off!
  199. COutputEvent m_OnPhysCannonAnimatePreStarted; // Started playing the pre-pull animation
  200. COutputEvent m_OnPhysCannonAnimatePullStarted; // Player started the pull anim
  201. COutputEvent m_OnPhysCannonAnimatePostStarted; // Started playing the post-pull animation
  202. COutputEvent m_OnPhysCannonPullAnimFinished; // We've had our pull anim finished, or the post-pull has finished if there is one
  203. float m_flDefaultFadeScale; // Things may temporarily change the fade scale, but this is its steady-state condition
  204. mp_break_t m_mpBreakMode;
  205. EHANDLE m_hLastAttacker; // Last attacker that harmed me.
  206. EHANDLE m_hFlareEnt;
  207. string_t m_iszPuntSound;
  208. CNetworkVar( bool, m_noGhostCollision );
  209. bool m_bUsePuntSound;
  210. protected:
  211. CNetworkQAngle( m_qPreferredPlayerCarryAngles );
  212. CNetworkVar( bool, m_bClientPhysics );
  213. };
  214. // Spawnflags
  215. #define SF_DYNAMICPROP_USEHITBOX_FOR_RENDERBOX 64
  216. #define SF_DYNAMICPROP_NO_VPHYSICS 128
  217. #define SF_DYNAMICPROP_DISABLE_COLLISION 256
  218. //-----------------------------------------------------------------------------
  219. // Purpose:
  220. //-----------------------------------------------------------------------------
  221. class CDynamicProp : public CBreakableProp, public IPositionWatcher
  222. {
  223. DECLARE_CLASS( CDynamicProp, CBreakableProp );
  224. public:
  225. DECLARE_SERVERCLASS();
  226. DECLARE_DATADESC();
  227. CDynamicProp();
  228. void Spawn( void );
  229. bool CreateVPhysics( void );
  230. void CreateBoneFollowers();
  231. void UpdateOnRemove( void );
  232. void AnimThink( void );
  233. void PropSetSequence( int nSequence );
  234. void OnRestore( void );
  235. bool OverridePropdata( void );
  236. virtual void HandleAnimEvent( animevent_t *pEvent );
  237. virtual int ShouldTransmit( const CCheckTransmitInfo *pInfo );
  238. // baseentity - watch dynamic hierarchy updates
  239. virtual void SetParent( CBaseEntity* pNewParent, int iAttachment = -1 );
  240. bool TestCollision( const Ray_t &ray, unsigned int mask, trace_t& trace );
  241. // breakable prop
  242. virtual IPhysicsObject *GetRootPhysicsObjectForBreak();
  243. // IPositionWatcher
  244. virtual void NotifyPositionChanged( CBaseEntity *pEntity );
  245. inline void SetGlowColor( int r, int g, int b );
  246. inline const color24 GetGlowColor() const;
  247. // Input handlers
  248. void InputSetAnimation( inputdata_t &inputdata );
  249. void InputSetAnimationNoReset( inputdata_t &inputdata );
  250. void InputSetDefaultAnimation( inputdata_t &inputdata );
  251. void InputTurnOn( inputdata_t &inputdata );
  252. void InputTurnOff( inputdata_t &inputdata );
  253. void InputDisableCollision( inputdata_t &inputdata );
  254. void InputEnableCollision( inputdata_t &inputdata );
  255. void InputSetPlaybackRate( inputdata_t &inputdata );
  256. void InputBecomeRagdoll( inputdata_t &inputdata );
  257. void InputFadeAndKill( inputdata_t &inputdata );
  258. void InputSetGlowEnabled( inputdata_t &inputdata );
  259. void InputSetGlowDisabled( inputdata_t &inputdata );
  260. void InputSetGlowColor( inputdata_t &inputdata );
  261. void InputGlowColorRedValue( inputdata_t &inputdata );
  262. void InputGlowColorGreenValue( inputdata_t &inputdata );
  263. void InputGlowColorBlueValue( inputdata_t &inputdata );
  264. void UpdateBoneFollowers( void );
  265. COutputEvent m_pOutputAnimBegun;
  266. COutputEvent m_pOutputAnimOver;
  267. string_t m_iszDefaultAnim;
  268. int m_iGoalSequence;
  269. int m_iTransitionDirection;
  270. // Random animations
  271. bool m_bAnimationDone;
  272. bool m_bHoldAnimation;
  273. bool m_bRandomAnimator;
  274. bool m_bDisableBoneFollowers;
  275. float m_flNextRandAnim;
  276. float m_flMinRandAnimTime;
  277. float m_flMaxRandAnimTime;
  278. short m_nPendingSequence;
  279. bool m_bStartDisabled;
  280. bool m_bAnimateEveryFrame;
  281. CNetworkVar( bool, m_bUseHitboxesForRenderBox );
  282. CNetworkVar( float, m_flGlowMaxDist );
  283. CNetworkVar( bool, m_bShouldGlow );
  284. CNetworkColor32( m_clrGlow );
  285. CNetworkVar( int, m_nGlowStyle );
  286. protected:
  287. void FinishSetSequence( int nSequence );
  288. void PropSetAnim( const char *szAnim );
  289. bool ShouldSetCreateTime( inputdata_t &inputdata );
  290. void BoneFollowerHierarchyChanged();
  291. // Contained Bone Follower manager
  292. CBoneFollowerManager m_BoneFollowerManager;
  293. };
  294. //-----------------------------------------------------------------------------
  295. // Purpose:
  296. //-----------------------------------------------------------------------------
  297. class CPhysicsProp : public CBreakableProp, public INavAvoidanceObstacle
  298. {
  299. DECLARE_CLASS( CPhysicsProp, CBreakableProp );
  300. DECLARE_SERVERCLASS();
  301. public:
  302. ~CPhysicsProp();
  303. CPhysicsProp( void );
  304. void Spawn( void );
  305. void Precache();
  306. bool CreateVPhysics( void );
  307. bool OverridePropdata( void );
  308. virtual void VPhysicsUpdate( IPhysicsObject *pPhysics );
  309. virtual void VPhysicsCollision( int index, gamevcollisionevent_t *pEvent );
  310. void InputWake( inputdata_t &inputdata );
  311. void InputSleep( inputdata_t &inputdata );
  312. void InputEnableMotion( inputdata_t &inputdata );
  313. void InputDisableMotion( inputdata_t &inputdata );
  314. void InputDisableFloating( inputdata_t &inputdata );
  315. void EnableMotion( void );
  316. bool CanBePickedUpByPhyscannon( void );
  317. void OnPhysGunPickup( CBasePlayer *pPhysGunUser, PhysGunPickup_t reason );
  318. void OnPhysGunDrop( CBasePlayer *pPhysGunUser, PhysGunDrop_t reason );
  319. bool GetPropDataAngles( const char *pKeyName, QAngle &vecAngles );
  320. float GetCarryDistanceOffset( void );
  321. int ObjectCaps();
  322. void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
  323. bool ShouldDisableMotionOnFreeze( void );
  324. void GetMassCenter( Vector *pMassCenter );
  325. float GetMass() const;
  326. int ExploitableByPlayer() const { return m_iExploitableByPlayer; }
  327. void ClearFlagsThink( void );
  328. virtual bool IsPotentiallyAbleToObstructNavAreas( void ) const; // could we at some future time obstruct nav?
  329. virtual float GetNavObstructionHeight( void ) const; // height at which to obstruct nav areas
  330. virtual bool CanObstructNavAreas( void ) const; // can we obstruct nav right this instant?
  331. virtual CBaseEntity *GetObstructingEntity( void ) { return this; }
  332. virtual void OnNavMeshLoaded( void );
  333. void NavThink( void );
  334. virtual int OnTakeDamage( const CTakeDamageInfo &info );
  335. int DrawDebugTextOverlays(void);
  336. bool IsGib();
  337. DECLARE_DATADESC();
  338. // Specific interactions
  339. void HandleAnyCollisionInteractions( int index, gamevcollisionevent_t *pEvent );
  340. private:
  341. // Compute impulse to apply to the enabled entity.
  342. void ComputeEnablingImpulse( int index, gamevcollisionevent_t *pEvent );
  343. COutputEvent m_MotionEnabled;
  344. COutputEvent m_OnAwakened;
  345. COutputEvent m_OnPhysGunPickup;
  346. COutputEvent m_OnPhysGunPunt;
  347. COutputEvent m_OnPhysGunOnlyPickup;
  348. COutputEvent m_OnPhysGunDrop;
  349. COutputEvent m_OnPlayerUse;
  350. COutputEvent m_OnPlayerPickup;
  351. COutputEvent m_OnOutOfWorld;
  352. float m_massScale;
  353. float m_inertiaScale;
  354. int m_damageType;
  355. string_t m_iszOverrideScript;
  356. int m_damageToEnableMotion;
  357. float m_flForceToEnableMotion;
  358. bool m_bThrownByPlayer;
  359. bool m_bFirstCollisionAfterLaunch;
  360. int m_iExploitableByPlayer;
  361. bool m_bHasBeenAwakened;
  362. float m_fNextCheckDisableMotionContactsTime;
  363. protected:
  364. CNetworkVar( bool, m_bAwake );
  365. #ifdef PORTAL2
  366. bool m_bAllowPortalFunnel;
  367. #endif // PORTAL2
  368. };
  369. //--------------------------------------------------------------------------------------------------------
  370. class CCSPropExplodingBarrel : public CPhysicsProp
  371. {
  372. DECLARE_CLASS( CCSPropExplodingBarrel, CPhysicsProp );
  373. public:
  374. DECLARE_DATADESC();
  375. virtual void Spawn( void );
  376. virtual void Precache( void );
  377. void FadeOut( void );
  378. void StopParticle( void );
  379. virtual int OnTakeDamage( const CTakeDamageInfo &info );
  380. virtual void Event_Killed( const CTakeDamageInfo &info );
  381. virtual int DrawDebugTextOverlays( void );
  382. bool IsBreakable( void ) { return true; }
  383. EHANDLE m_hBarrelTop;
  384. private:
  385. bool m_bExploded;
  386. };
  387. // An interface so that objects parented to props can receive collision interaction events.
  388. enum parentCollisionInteraction_t
  389. {
  390. COLLISIONINTER_PARENT_FIRST_IMPACT = 1,
  391. };
  392. abstract_class IParentPropInteraction
  393. {
  394. public:
  395. virtual void OnParentCollisionInteraction( parentCollisionInteraction_t eType, int index, gamevcollisionevent_t *pEvent ) = 0;
  396. virtual void OnParentPhysGunDrop( CBasePlayer *pPhysGunUser, PhysGunDrop_t Reason ) = 0;
  397. };
  398. // Used by prop_physics_create and the server benchmark.
  399. // pModelName should not include the "models/" prefix.
  400. CPhysicsProp* CreatePhysicsProp( const char *pModelName, const Vector &vTraceStart, const Vector &vTraceEnd, const IHandleEntity *pTraceIgnore, bool bRequireVCollide, const char *pClassName="physics_prop" );
  401. float GetBreakableDamage( const CTakeDamageInfo &inputInfo, IBreakableWithPropData *pProp = NULL );
  402. int PropBreakablePrecacheAll( string_t modelName );
  403. extern ConVar func_breakdmg_bullet;
  404. extern ConVar func_breakdmg_club;
  405. extern ConVar func_breakdmg_explosive;
  406. #ifdef PORTAL2
  407. bool UTIL_PropIsMotionDisabled( CBaseEntity *pObject );
  408. void UTIL_SetPropMotionDisabled( CBaseEntity *pObject );
  409. #endif // PORTAL2
  410. #endif // PROPS_H