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.

158 lines
4.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: TF basic grenade projectile functionality.
  4. //
  5. //=============================================================================//
  6. #ifndef TF_WEAPONBASE_GRENADEPROJ_H
  7. #define TF_WEAPONBASE_GRENADEPROJ_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "tf_shareddefs.h"
  12. #include "tf_weaponbase.h"
  13. #include "basegrenade_shared.h"
  14. #include "networkstringtabledefs.h"
  15. #define TF_GRENADE_DESTROYABLE_TIMER (0.25)
  16. // Client specific.
  17. #ifdef CLIENT_DLL
  18. #define CTFWeaponBaseGrenadeProj C_TFWeaponBaseGrenadeProj
  19. #endif
  20. //=============================================================================
  21. //
  22. // TF base grenade projectile class.
  23. //
  24. class CTFWeaponBaseGrenadeProj : public CBaseGrenade
  25. {
  26. public:
  27. DECLARE_CLASS( CTFWeaponBaseGrenadeProj, CBaseGrenade );
  28. DECLARE_NETWORKCLASS();
  29. CTFWeaponBaseGrenadeProj();
  30. virtual ~CTFWeaponBaseGrenadeProj();
  31. virtual void Spawn();
  32. virtual void Precache();
  33. #ifdef GAME_DLL
  34. virtual void InitGrenade( const Vector &velocity, const AngularImpulse &angVelocity, CBaseCombatCharacter *pOwner, const CTFWeaponInfo &weaponInfo );
  35. virtual void InitGrenade( const Vector &velocity, const AngularImpulse &angVelocity, CBaseCombatCharacter *pOwner, const int iDamage, const float flRadius );
  36. virtual int GetBaseProjectileType() const { return TF_BASE_PROJECTILE_GRENADE; }
  37. #endif
  38. // Unique identifier.
  39. virtual int GetWeaponID( void ) const { return TF_WEAPON_NONE; }
  40. virtual int GetCustomDamageType() const { return TF_DMG_CUSTOM_NONE; }
  41. // This gets sent to the client and placed in the client's interpolation history
  42. // so the projectile starts out moving right off the bat.
  43. CNetworkVector( m_vInitialVelocity );
  44. virtual float GetShakeAmplitude( void ) { return 10.0; }
  45. virtual float GetShakeRadius( void ) { return 300.0; }
  46. void SetCritical( bool bCritical ) { m_bCritical = bCritical; }
  47. virtual int GetDamageType();
  48. virtual void SetLauncher( CBaseEntity *pLauncher ) OVERRIDE { m_hLauncher = pLauncher; BaseClass::SetLauncher( pLauncher ); }
  49. CBaseEntity *GetLauncher( void ) { return m_hLauncher; }
  50. virtual void IncrementDeflected( void ) { m_iDeflected++; }
  51. void ResetDeflected( void ) { m_iDeflected = 0; }
  52. int GetDeflected( void ) { return m_iDeflected; }
  53. void SetDeflectOwner( CBaseEntity *pPlayer ) { m_hDeflectOwner = pPlayer; }
  54. CBaseEntity *GetDeflectOwner( void ) { return m_hDeflectOwner; }
  55. virtual float GetDamageRadius();
  56. virtual int GetDamageCustom();
  57. virtual int GetCustomParticleIndex() { return INVALID_STRING_INDEX; }
  58. void BounceOff( IPhysicsObject *pPhysics );
  59. protected:
  60. CNetworkHandleForDerived( CBaseEntity, m_hLauncher );
  61. private:
  62. CTFWeaponBaseGrenadeProj( const CTFWeaponBaseGrenadeProj & );
  63. CNetworkVar( int, m_iDeflected );
  64. CNetworkHandle( CBaseEntity, m_hDeflectOwner );
  65. // Client specific.
  66. #ifdef CLIENT_DLL
  67. public:
  68. virtual void OnDataChanged( DataUpdateType_t type );
  69. float m_flSpawnTime;
  70. bool m_bCritical;
  71. // Server specific.
  72. #else
  73. public:
  74. DECLARE_DATADESC();
  75. static CTFWeaponBaseGrenadeProj *Create( const char *szName, const Vector &position, const QAngle &angles,
  76. const Vector &velocity, const AngularImpulse &angVelocity,
  77. CBaseCombatCharacter *pOwner, const CTFWeaponInfo &weaponInfo, int iFlags );
  78. int OnTakeDamage( const CTakeDamageInfo &info );
  79. virtual void DetonateThink( void );
  80. void Detonate( void );
  81. void SetupInitialTransmittedGrenadeVelocity( const Vector &velocity ) { m_vInitialVelocity = velocity; }
  82. bool ShouldNotDetonate( void );
  83. virtual void Destroy( bool bBlinkOut = true, bool bBreak = false ) OVERRIDE;
  84. void SetTimer( float time ){ m_flDetonateTime = time; }
  85. float GetDetonateTime( void ){ return m_flDetonateTime; }
  86. void SetDetonateTimerLength( float timer );
  87. void VPhysicsUpdate( IPhysicsObject *pPhysics );
  88. virtual bool IsAllowedToExplode( void ) { return true; }
  89. void Explode( trace_t *pTrace, int bitsDamageType );
  90. bool UseImpactNormal() { return m_bUseImpactNormal; }
  91. const Vector &GetImpactNormal( void ) const { return m_vecImpactNormal; }
  92. bool IsCritical() { return m_bCritical; }
  93. virtual bool IsDestroyable( void ){ return gpGlobals->curtime > m_flDestroyableTime; }
  94. virtual CBaseEntity *GetEnemy( void ) { return m_hEnemy; }
  95. protected:
  96. #ifdef STAGING_ONLY
  97. void DrawRadius( float flRadius );
  98. #endif
  99. bool m_bUseImpactNormal;
  100. Vector m_vecImpactNormal;
  101. // Custom collision to allow for constant elasticity on hit surfaces.
  102. virtual void ResolveFlyCollisionCustom( trace_t &trace, Vector &vecVelocity );
  103. float m_flDetonateTime;
  104. CHandle<CBaseEntity> m_hEnemy;
  105. private:
  106. bool m_bInSolid;
  107. CNetworkVar( bool, m_bCritical );
  108. float m_flDestroyableTime;
  109. bool m_bIsMerasmusGrenade;
  110. #endif
  111. };
  112. #endif // TF_WEAPONBASE_GRENADEPROJ_H