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.

167 lines
6.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef PHYSPROPCLIENTSIDE_H
  7. #define PHYSPROPCLIENTSIDE_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "c_breakableprop.h"
  12. #include "props_shared.h"
  13. class C_FuncPhysicsRespawnZone;
  14. class C_PhysPropClientside : public C_BreakableProp, public IBreakableWithPropData, public IMultiplayerPhysics
  15. {
  16. public:
  17. DECLARE_CLASS( C_PhysPropClientside, C_BreakableProp );
  18. C_PhysPropClientside();
  19. virtual ~C_PhysPropClientside();
  20. bool Initialize();
  21. void Spawn();
  22. int ParsePropData( void );
  23. virtual bool IsDormant( void ) { return false; } // we could add a PVS check here
  24. virtual void ClientThink( void );
  25. virtual CollideType_t GetCollideType( void ) { return ENTITY_SHOULD_RESPOND; }
  26. virtual void StartTouch( C_BaseEntity *pOther );
  27. virtual void HitSurface( C_BaseEntity *pOther );
  28. virtual void ImpactTrace( trace_t *pTrace, int iDamageType, const char *pCustomImpactName );
  29. virtual bool IsClientCreated( void ) const { return true; }
  30. virtual int GetMultiplayerPhysicsMode() { return m_iPhysicsMode; }
  31. virtual float GetMass();
  32. virtual bool IsAsleep();
  33. virtual bool KeyValue( const char *szKeyName, const char *szValue );
  34. virtual void OnTakeDamage( int iDamage ); // very simple version
  35. virtual void Break();
  36. virtual void Clone( Vector &velocity );
  37. virtual void StartFadeOut( float fTime );
  38. virtual void SetHealth(int iHealth) { m_iHealth = iHealth; }
  39. virtual int GetHealth() const { return m_iHealth; }
  40. int GetNumBreakableChunks( void ) { return m_iNumBreakableChunks; }
  41. void SetRespawnZone( C_FuncPhysicsRespawnZone *pZone );
  42. // IBreakableWithPropData interface:
  43. public:
  44. // IBreakableWithPropData
  45. void SetDmgModBullet( float flDmgMod ) { m_flDmgModBullet = flDmgMod; }
  46. void SetDmgModClub( float flDmgMod ) { m_flDmgModClub = flDmgMod; }
  47. void SetDmgModExplosive( float flDmgMod ) { m_flDmgModExplosive = flDmgMod; }
  48. float GetDmgModBullet( void ) { return m_flDmgModBullet; }
  49. float GetDmgModClub( void ) { return m_flDmgModClub; }
  50. float GetDmgModExplosive( void ) { return m_flDmgModExplosive; }
  51. void SetExplosiveRadius( float flRadius ) { m_explodeRadius = flRadius; }
  52. void SetExplosiveDamage( float flDamage ) { m_explodeDamage = flDamage; }
  53. float GetExplosiveRadius( void ) { return m_explodeRadius; }
  54. float GetExplosiveDamage( void ) { return m_explodeDamage; }
  55. void SetPhysicsDamageTable( string_t iszTableName ) { m_iszPhysicsDamageTableName = iszTableName; }
  56. string_t GetPhysicsDamageTable( void ) { return m_iszPhysicsDamageTableName; }
  57. void SetBreakableModel( string_t iszModel ) { m_iszBreakableModel = iszModel; }
  58. string_t GetBreakableModel( void ) { return m_iszBreakableModel; }
  59. void SetBreakableSkin( int iSkin ) { m_iBreakableSkin = iSkin; }
  60. int GetBreakableSkin( void ) { return m_iBreakableSkin; }
  61. void SetBreakableCount( int iCount ) { m_iBreakableCount = iCount; }
  62. int GetBreakableCount( void ) { return m_iBreakableCount; }
  63. void SetMaxBreakableSize( int iSize ) { m_iMaxBreakableSize = iSize; }
  64. int GetMaxBreakableSize( void ) { return m_iMaxBreakableSize; }
  65. void SetPropDataBlocksLOS( bool bBlocksLOS ) { m_bBlockLOSSetByPropData = true; SetBlocksLOS( bBlocksLOS ); }
  66. void SetPropDataIsAIWalkable( bool b ) { m_bIsWalkableSetByPropData = true; SetAIWalkable( b ); }
  67. void SetBasePropData( string_t iszBase ) { m_iszBasePropData = iszBase; }
  68. string_t GetBasePropData( void ) { return m_iszBasePropData; }
  69. void SetInteraction( propdata_interactions_t Interaction ) { m_iInteractions |= (1 << Interaction); }
  70. bool HasInteraction( propdata_interactions_t Interaction ) { return ( m_iInteractions & (1 << Interaction) ) != 0; }
  71. void SetPhysicsMode(int iMode);
  72. int GetPhysicsMode() { return m_iPhysicsMode; }
  73. void SetMultiplayerBreakMode( mp_break_t mode ) {}
  74. mp_break_t GetMultiplayerBreakMode( void ) const { return MULTIPLAYER_BREAK_DEFAULT; }
  75. // static management fucntions:
  76. static void RecreateAll(); // recreate all clientside props in map
  77. static void DestroyAll(); // clear all clientside created phys props
  78. static C_PhysPropClientside *CreateNew(bool bForce = false);
  79. protected:
  80. static void ParseAllEntities(const char *pMapData);
  81. static const char *ParseEntity( const char *pEntData );
  82. static void InitializePropRespawnZones(void);
  83. public:
  84. int m_iPhysicsMode; // should always be PHYSICS_MULTIPLAYER_CLIENTSIDE
  85. float m_flTouchDelta; // Amount of time that must pass before another touch function can be called
  86. float m_fDeathTime; // Point at which this object self destructs.
  87. // The default of -1 indicates the object shouldn't destruct.
  88. // properties from serverclass CPhysicsProp
  89. float m_impactEnergyScale;
  90. int m_spawnflags;
  91. float m_inertiaScale;
  92. protected:
  93. // Prop data storage
  94. float m_flDmgModBullet;
  95. float m_flDmgModClub;
  96. float m_flDmgModExplosive;
  97. string_t m_iszPhysicsDamageTableName;
  98. string_t m_iszBreakableModel;
  99. int m_iBreakableSkin;
  100. int m_iBreakableCount;
  101. int m_iMaxBreakableSize;
  102. string_t m_iszBasePropData;
  103. int m_iInteractions;
  104. float m_explodeDamage;
  105. float m_explodeRadius;
  106. bool m_bBlockLOSSetByPropData;
  107. bool m_bIsWalkableSetByPropData;
  108. // Count of how many pieces we'll break into, custom or generic
  109. int m_iNumBreakableChunks;
  110. C_FuncPhysicsRespawnZone *m_pRespawnZone;
  111. };
  112. //-----------------------------------------------------------------------------
  113. // Purpose: A clientside zone that respawns physics props in it when the player leaves the PVS
  114. //-----------------------------------------------------------------------------
  115. class C_FuncPhysicsRespawnZone : public C_BaseEntity
  116. {
  117. DECLARE_CLASS( C_FuncPhysicsRespawnZone, C_BaseEntity );
  118. public:
  119. C_FuncPhysicsRespawnZone( void );
  120. ~C_FuncPhysicsRespawnZone( void );
  121. bool KeyValue( const char *szKeyName, const char *szValue );
  122. bool Initialize( void );
  123. void InitializePropsWithin( void );
  124. void PropDestroyed( C_PhysPropClientside *pProp );
  125. bool CanMovePropAt( Vector vecOrigin, const Vector &vecMins, const Vector &vecMaxs );
  126. void RespawnProps( void );
  127. void ClientThink( void );
  128. private:
  129. struct clientsideproprespawn_t
  130. {
  131. string_t iszModelName;
  132. Vector vecOrigin;
  133. QAngle vecAngles;
  134. int iSkin;
  135. int iHealth;
  136. int iSpawnFlags;
  137. ClientEntityHandle_t hClientEntity;
  138. };
  139. CUtlVector<clientsideproprespawn_t> m_PropList;
  140. };
  141. #endif // PHYSPROPCLIENTSIDE_H