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.

305 lines
8.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: TF Sniper Rifle
  4. //
  5. //=============================================================================//
  6. #ifndef TF_WEAPON_SNIPERRIFLE_H
  7. #define TF_WEAPON_SNIPERRIFLE_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "tf_weaponbase_gun.h"
  12. #include "Sprite.h"
  13. #if defined( CLIENT_DLL )
  14. #define CTFSniperRifle C_TFSniperRifle
  15. #define CTFSniperRifleDecap C_TFSniperRifleDecap
  16. #define CTFSniperRifleClassic C_TFSniperRifleClassic
  17. #define CTFSniperRifleRevolver C_TFSniperRifleRevolver
  18. #define CSniperDot C_SniperDot
  19. #endif
  20. enum RifleTypes_t
  21. {
  22. RIFLE_NORMAL = 0,
  23. RIFLE_JARATE,
  24. RIFLE_MACHINA,
  25. RIFLE_CLASSIC,
  26. };
  27. //=============================================================================
  28. //
  29. // Sniper Rifle Laser Dot class.
  30. //
  31. class CSniperDot : public CBaseEntity
  32. {
  33. public:
  34. DECLARE_CLASS( CSniperDot, CBaseEntity );
  35. DECLARE_NETWORKCLASS();
  36. DECLARE_DATADESC();
  37. // Creation/Destruction.
  38. CSniperDot( void );
  39. ~CSniperDot( void );
  40. static CSniperDot *Create( const Vector &origin, CBaseEntity *pOwner = NULL, bool bVisibleDot = true );
  41. void ResetChargeTime( void ) { m_flChargeStartTime = gpGlobals->curtime; }
  42. // Attributes.
  43. int ObjectCaps() { return (BaseClass::ObjectCaps() & ~FCAP_ACROSS_TRANSITION) | FCAP_DONT_SAVE; }
  44. // Targeting.
  45. void Update( CBaseEntity *pTarget, const Vector &vecOrigin, const Vector &vecNormal );
  46. CBaseEntity *GetTargetEntity( void ) { return m_hTargetEnt; }
  47. Vector GetChasePosition();
  48. // Client specific.
  49. #ifdef CLIENT_DLL
  50. bool GetRenderingPositions( C_TFPlayer *pPlayer, Vector &vecAttachment, Vector &vecEndPos, float &flSize );
  51. // Rendering.
  52. virtual bool IsTransparent( void ) { return true; }
  53. virtual RenderGroup_t GetRenderGroup( void ) { return RENDER_GROUP_TRANSLUCENT_ENTITY; }
  54. virtual int DrawModel( int flags );
  55. virtual bool ShouldDraw( void );
  56. virtual void ClientThink( void );
  57. virtual void OnDataChanged( DataUpdateType_t updateType );
  58. CMaterialReference m_hSpriteMaterial;
  59. HPARTICLEFFECT m_laserBeamEffect;
  60. #endif
  61. protected:
  62. Vector m_vecSurfaceNormal;
  63. EHANDLE m_hTargetEnt;
  64. CNetworkVar( float, m_flChargeStartTime );
  65. };
  66. //=============================================================================
  67. //
  68. // Sniper Rifle class.
  69. //
  70. class CTFSniperRifle : public CTFWeaponBaseGun
  71. {
  72. public:
  73. DECLARE_CLASS( CTFSniperRifle, CTFWeaponBaseGun );
  74. DECLARE_NETWORKCLASS();
  75. DECLARE_PREDICTABLE();
  76. DECLARE_DATADESC();
  77. CTFSniperRifle();
  78. virtual ~CTFSniperRifle();
  79. virtual int GetWeaponID( void ) const { return TF_WEAPON_SNIPERRIFLE; }
  80. virtual void Spawn();
  81. virtual void Precache() OVERRIDE;
  82. void ResetTimers( void );
  83. virtual bool Reload( void );
  84. virtual bool CanHolster( void ) const;
  85. virtual bool Holster( CBaseCombatWeapon *pSwitchingTo );
  86. virtual bool OwnerCanJump( void ) OVERRIDE;
  87. virtual void HandleZooms( void );
  88. virtual void ItemPostFrame( void );
  89. virtual bool Lower( void );
  90. virtual float GetProjectileDamage( void );
  91. virtual int GetDamageType() const;
  92. int GetRifleType( void ) const { int iMode = 0; CALL_ATTRIB_HOOK_INT( iMode, set_weapon_mode ); return iMode; };
  93. virtual void WeaponReset( void );
  94. virtual bool CanFireCriticalShot( bool bIsHeadshot = false );
  95. virtual void PlayWeaponShootSound( void );
  96. virtual bool MustBeZoomedToFire( void );
  97. virtual ETFDmgCustom GetPenetrateType() const;
  98. #ifdef CLIENT_DLL
  99. float GetHUDDamagePerc( void );
  100. virtual bool ShouldEjectBrass();
  101. #endif
  102. bool IsZoomed( void );
  103. bool IsFullyCharged( void ) const; // have we been zoomed in long enough for our shot to do max damage
  104. virtual void OnControlStunned( void );
  105. virtual int GetCustomDamageType() const;
  106. #ifdef GAME_DLL
  107. // Hit tracking for achievements
  108. virtual void OnPlayerKill( CTFPlayer *pVictim, const CTakeDamageInfo &info ) OVERRIDE;
  109. virtual void OnBulletFire( int iEnemyPlayersHit ) OVERRIDE;
  110. void ExplosiveHeadShot( CTFPlayer *pAttacker, CTFPlayer *pVictim );
  111. #endif
  112. void Detach( void ) OVERRIDE;
  113. virtual bool IsJarateRifle( void ) const;
  114. virtual float GetJarateTime( void ) const;
  115. virtual float SniperRifleChargeRateMod() { return 0.f; }
  116. virtual int GetBuffType() { int iBuffType = 0; CALL_ATTRIB_HOOK_INT( iBuffType, set_buff_type ); return iBuffType; }
  117. float GetProgress( void );
  118. bool IsRageFull( void ); // same as GetProgress() without the division by 100.0f
  119. const char* GetEffectLabelText( void ) { return "#TF_SNIPERRAGE"; }
  120. bool EffectMeterShouldFlash( void );
  121. #ifdef SIXENSE
  122. float GetRezoomTime() const;
  123. #endif
  124. virtual void ZoomIn( void );
  125. virtual void ZoomOut( void );
  126. void ApplyScopeSpeedModifications( float &flBaseRef );
  127. void ApplyChargeSpeedModifications( float &flBaseRef );
  128. protected:
  129. float GetJarateTimeInternal( void ) const;
  130. bool m_bCurrentShotIsHeadshot;
  131. void CreateSniperDot( void );
  132. void DestroySniperDot( void );
  133. void UpdateSniperDot( void );
  134. void Fire( CTFPlayer *pPlayer );
  135. // Auto-rezooming handling
  136. void SetRezoom( bool bRezoom, float flDelay );
  137. virtual void Zoom( void );
  138. void ZoomOutIn( void );
  139. void HandleNoScopeFireDeny( void );
  140. CNetworkVar( float, m_flChargedDamage );
  141. #ifdef GAME_DLL
  142. CHandle<CSniperDot> m_hSniperDot;
  143. #else
  144. bool m_bPlayedBell;
  145. #endif
  146. // Handles rezooming after the post-fire unzoom
  147. float m_flUnzoomTime;
  148. float m_flRezoomTime;
  149. bool m_bRezoomAfterShot;
  150. float m_flChargePerSec;
  151. bool m_bWasAimedAtEnemy;
  152. CTFSniperRifle( const CTFSniperRifle & );
  153. };
  154. class CTFSniperRifleDecap : public CTFSniperRifle
  155. {
  156. public:
  157. DECLARE_CLASS( CTFSniperRifleDecap, CTFSniperRifle );
  158. DECLARE_NETWORKCLASS();
  159. DECLARE_PREDICTABLE();
  160. virtual int GetWeaponID( void ) const { return TF_WEAPON_SNIPERRIFLE_DECAP; }
  161. #ifdef GAME_DLL
  162. virtual void OnPlayerKill( CTFPlayer *pVictim, const CTakeDamageInfo &info );
  163. #endif // GAME_DLL
  164. virtual float SniperRifleChargeRateMod() OVERRIDE;
  165. const char* GetEffectLabelText( void ) { return "#TF_BERZERK"; }
  166. float GetProgress( void ) { return 0.f; }
  167. int GetCount( void );
  168. };
  169. //=============================================================================
  170. //
  171. // Classic Sniper Rifle class.
  172. //
  173. class CTFSniperRifleClassic : public CTFSniperRifle
  174. {
  175. public:
  176. DECLARE_CLASS( CTFSniperRifleClassic, CTFSniperRifle );
  177. DECLARE_NETWORKCLASS();
  178. DECLARE_PREDICTABLE();
  179. CTFSniperRifleClassic();
  180. ~CTFSniperRifleClassic();
  181. virtual void Precache() OVERRIDE;
  182. virtual int GetWeaponID( void ) const { return TF_WEAPON_SNIPERRIFLE_CLASSIC; }
  183. virtual void ZoomOut( void ) OVERRIDE;
  184. virtual void ZoomIn( void ) OVERRIDE;
  185. virtual void Zoom( void ) OVERRIDE;
  186. virtual void HandleZooms( void ) OVERRIDE;
  187. virtual void ItemPostFrame( void ) OVERRIDE;
  188. virtual bool Lower( void ) OVERRIDE;
  189. virtual bool Deploy( void ) OVERRIDE;
  190. virtual bool MustBeZoomedToFire( void ) OVERRIDE { return false; }
  191. virtual int GetDamageType() const OVERRIDE;
  192. virtual bool Holster( CBaseCombatWeapon *pSwitchingTo ) OVERRIDE;
  193. virtual void WeaponReset( void ) OVERRIDE;
  194. #ifdef CLIENT_DLL
  195. virtual void OnDataChanged( DataUpdateType_t updateType ) OVERRIDE;
  196. #endif
  197. void Detach( void ) OVERRIDE;
  198. private:
  199. CNetworkVar( bool, m_bCharging );
  200. #ifdef CLIENT_DLL
  201. void ManageChargeBeam( void );
  202. HPARTICLEFFECT m_pChargedEffect;
  203. #endif
  204. };
  205. #ifdef STAGING_ONLY
  206. //=============================================================================
  207. //
  208. // Projectile Based Sniper Rifle
  209. //
  210. class CTFSniperRifleRevolver : public CTFSniperRifleClassic
  211. {
  212. public:
  213. DECLARE_CLASS( CTFSniperRifleRevolver, CTFSniperRifleClassic );
  214. DECLARE_NETWORKCLASS();
  215. DECLARE_PREDICTABLE();
  216. virtual int GetWeaponID( void ) const { return TF_WEAPON_SNIPERRIFLE_REVOLVER; }
  217. // Fire the sniper shot.
  218. virtual void PrimaryAttack() OVERRIDE;
  219. virtual float GetProjectileDamage() OVERRIDE;
  220. virtual void ZoomIn( void ) OVERRIDE;
  221. virtual void ZoomOut( void ) OVERRIDE;
  222. virtual bool Reload( void ) OVERRIDE;
  223. virtual void ItemPostFrame( void ) OVERRIDE;
  224. virtual bool CanFireCriticalShot( bool bIsHeadshot = false ) OVERRIDE;
  225. virtual float GetProjectileSpeed( void ) OVERRIDE;
  226. virtual float GetProjectileGravity( void ) OVERRIDE;
  227. };
  228. #endif // STAGING_ONLY
  229. #endif // TF_WEAPON_SNIPERRIFLE_H