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.

176 lines
7.0 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Defines a class for objects that break after taking a certain amount
  4. // of damage.
  5. //
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. #ifndef FUNC_BREAK_H
  9. #define FUNC_BREAK_H
  10. #pragma once
  11. #include "entityoutput.h"
  12. #include "props.h"
  13. typedef enum { expRandom = 0, expDirected, expUsePrecise} Explosions;
  14. typedef enum { matGlass = 0, matWood, matMetal, matFlesh, matCinderBlock, matCeilingTile, matComputer, matUnbreakableGlass, matRocks, matMetalPanel, matNone, matLastMaterial } Materials;
  15. #define NUM_SHARDS 6 // this many shards spawned when breakable objects break;
  16. // Spawnflags for func breakable
  17. #define SF_BREAK_TRIGGER_ONLY 0x0001 // may only be broken by trigger
  18. #define SF_BREAK_TOUCH 0x0002 // can be 'crashed through' by running player (plate glass)
  19. #define SF_BREAK_PRESSURE 0x0004 // can be broken by a player standing on it
  20. #define SF_BREAK_PHYSICS_BREAK_IMMEDIATELY 0x0200 // the first physics collision this breakable has will immediately break it
  21. #define SF_BREAK_DONT_TAKE_PHYSICS_DAMAGE 0x0400 // this breakable doesn't take damage from physics collisions
  22. #define SF_BREAK_NO_BULLET_PENETRATION 0x0800 // don't allow bullets to penetrate
  23. // Spawnflags for func_pushable (it's also func_breakable, so don't collide with those flags)
  24. #define SF_PUSH_BREAKABLE 0x0080
  25. #define SF_PUSH_NO_USE 0x0100 // player cannot +use pickup this ent
  26. //-----------------------------------------------------------------------------
  27. // Purpose:
  28. //-----------------------------------------------------------------------------
  29. class CBreakable : public CBaseEntity, public IBreakableWithPropData, public CDefaultPlayerPickupVPhysics
  30. {
  31. public:
  32. DECLARE_CLASS( CBreakable, CBaseEntity );
  33. // basic functions
  34. virtual void Spawn( void );
  35. void ParsePropData( void );
  36. bool CreateVPhysics( void );
  37. virtual void Precache( void );
  38. virtual bool KeyValue( const char *szKeyName, const char *szValue );
  39. virtual void VPhysicsCollision( int index, gamevcollisionevent_t *pEvent );
  40. void BreakTouch( CBaseEntity *pOther );
  41. void DamageSound( void );
  42. void Break( CBaseEntity *pBreaker );
  43. // Input handlers
  44. void InputAddHealth( inputdata_t &inputdata );
  45. void InputBreak( inputdata_t &inputdata );
  46. void InputRemoveHealth( inputdata_t &inputdata );
  47. void InputSetHealth( inputdata_t &inputdata );
  48. void InputSetMass( inputdata_t &inputdata );
  49. // breakables use an overridden takedamage
  50. virtual int OnTakeDamage( const CTakeDamageInfo &info );
  51. // To spark when hit
  52. void TraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr );
  53. bool IsBreakable( void );
  54. bool SparkWhenHit( void );
  55. char const *DamageDecal( int bitsDamageType, int gameMaterial );
  56. virtual void Die( void );
  57. void ResetOnGroundFlags(void);
  58. inline bool Explodable( void ) { return GetExplosiveRadius() > 0; }
  59. Materials GetMaterialType( void ) { return m_Material; }
  60. static void MaterialSoundRandom( int entindex, Materials soundMaterial, float volume );
  61. static const char *MaterialSound( Materials precacheMaterial );
  62. static const char *pSpawnObjects[];
  63. int DrawDebugTextOverlays(void);
  64. DECLARE_DATADESC();
  65. public:
  66. // IBreakableWithPropData
  67. void SetDmgModBullet( float flDmgMod ) { m_flDmgModBullet = flDmgMod; }
  68. void SetDmgModClub( float flDmgMod ) { m_flDmgModClub = flDmgMod; }
  69. void SetDmgModExplosive( float flDmgMod ) { m_flDmgModExplosive = flDmgMod; }
  70. void SetDmgModFire( float flDmgMod ) { m_flDmgModFire = flDmgMod; }
  71. float GetDmgModBullet( void ) { return m_flDmgModBullet; }
  72. float GetDmgModClub( void ) { return m_flDmgModClub; }
  73. float GetDmgModExplosive( void ) { return m_flDmgModExplosive; }
  74. float GetDmgModFire( void ) { return m_flDmgModFire; }
  75. void SetExplosiveRadius( float flRadius ) { m_explodeRadius = flRadius; }
  76. void SetExplosiveDamage( float flDamage ) { m_ExplosionMagnitude = flDamage; }
  77. float GetExplosiveRadius( void ) { return m_explodeRadius; }
  78. float GetExplosiveDamage( void ) { return m_ExplosionMagnitude; }
  79. void SetPhysicsDamageTable( string_t iszTableName ) { m_iszPhysicsDamageTableName = iszTableName; }
  80. string_t GetPhysicsDamageTable( void ) { return m_iszPhysicsDamageTableName; }
  81. void SetBreakableModel( string_t iszModel ) { m_iszBreakableModel = iszModel; }
  82. string_t GetBreakableModel( void ) { return m_iszBreakableModel; }
  83. void SetBreakableSkin( int iSkin ) { m_iBreakableSkin = iSkin; }
  84. int GetBreakableSkin( void ) { return m_iBreakableSkin; }
  85. void SetBreakableCount( int iCount ) { m_iBreakableCount = iCount; }
  86. int GetBreakableCount( void ) { return m_iBreakableCount; }
  87. void SetMaxBreakableSize( int iSize ) { m_iMaxBreakableSize = iSize; }
  88. int GetMaxBreakableSize( void ) { return m_iMaxBreakableSize; }
  89. void SetPropDataBlocksLOS( bool bBlocksLOS ) { SetBlocksLOS( bBlocksLOS ); }
  90. void SetPropDataIsAIWalkable( bool bBlocksLOS ) { SetAIWalkable( bBlocksLOS ); }
  91. void SetBasePropData( string_t iszBase ) { m_iszBasePropData = iszBase; }
  92. string_t GetBasePropData( void ) { return m_iszBasePropData; }
  93. void SetInteraction( propdata_interactions_t Interaction ) { m_iInteractions |= (1 << Interaction); }
  94. bool HasInteraction( propdata_interactions_t Interaction ) { return ( m_iInteractions & (1 << Interaction) ) != 0; }
  95. void SetPhysicsMode(int iMode){}
  96. int GetPhysicsMode() { return PHYSICS_MULTIPLAYER_SOLID; }
  97. void SetMultiplayerBreakMode( mp_break_t mode ) {}
  98. mp_break_t GetMultiplayerBreakMode( void ) const { return MULTIPLAYER_BREAK_DEFAULT; }
  99. protected:
  100. Materials m_Material;
  101. EHANDLE m_hBreaker; // The entity that broke us. Held as a data member because sometimes breaking is delayed.
  102. private:
  103. Explosions m_Explosion;
  104. QAngle m_GibDir;
  105. string_t m_iszGibModel;
  106. string_t m_iszSpawnObject;
  107. int m_ExplosionMagnitude;
  108. float m_flPressureDelay; // Delay before breaking when destoyed by pressure
  109. int m_iMinHealthDmg; // minimum damage attacker must have to cause damage
  110. bool m_bTookPhysicsDamage;
  111. string_t m_iszPropData;
  112. string_t m_iszModelName;
  113. protected:
  114. bool UpdateHealth( int iNewHealth, CBaseEntity *pActivator );
  115. float m_impactEnergyScale;
  116. COutputEvent m_OnBreak;
  117. COutputFloat m_OnHealthChanged;
  118. // Prop data storage
  119. float m_flDmgModBullet;
  120. float m_flDmgModClub;
  121. float m_flDmgModExplosive;
  122. float m_flDmgModFire;
  123. string_t m_iszPhysicsDamageTableName;
  124. string_t m_iszBreakableModel;
  125. int m_iBreakableSkin;
  126. int m_iBreakableCount;
  127. int m_iMaxBreakableSize;
  128. string_t m_iszBasePropData;
  129. int m_iInteractions;
  130. PerformanceMode_t m_PerformanceMode;
  131. float m_explodeRadius;
  132. public:
  133. // IPlayerPickupVPhysics
  134. virtual void OnPhysGunPickup( CBasePlayer *pPhysGunUser, PhysGunPickup_t reason );
  135. virtual void OnPhysGunDrop( CBasePlayer *pPhysGunUser, PhysGunDrop_t Reason );
  136. virtual CBasePlayer *HasPhysicsAttacker( float dt );
  137. private:
  138. CHandle<CBasePlayer> m_hPhysicsAttacker;
  139. float m_flLastPhysicsInfluenceTime;
  140. };
  141. #endif // FUNC_BREAK_H