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.

327 lines
10 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. //
  4. //=============================================================================
  5. #ifndef TF_WEAPON_FLAMETHROWER_H
  6. #define TF_WEAPON_FLAMETHROWER_H
  7. #ifdef _WIN32
  8. #pragma once
  9. #endif
  10. #include "tf_weaponbase_gun.h"
  11. #include "tf_weaponbase_rocket.h"
  12. #ifdef STAGING_ONLY
  13. #include "tf_weapon_jar.h"
  14. #endif // STAGING_ONLY
  15. // Client specific.
  16. #ifdef CLIENT_DLL
  17. #include "particlemgr.h"
  18. #include "particle_util.h"
  19. #include "particles_simple.h"
  20. #include "c_tf_projectile_rocket.h"
  21. #define CTFFlameThrower C_TFFlameThrower
  22. #define CTFFlameRocket C_TFFlameRocket
  23. #ifdef STAGING_ONLY
  24. #define CTFProjectile_Napalm C_TFProjectile_Napalm
  25. #endif // STAGING_ONLY
  26. #else
  27. #include "tf_projectile_rocket.h"
  28. #include "baseentity.h"
  29. #include "iscorer.h"
  30. #endif
  31. enum FlameThrowerState_t
  32. {
  33. // Firing states.
  34. FT_STATE_IDLE = 0,
  35. FT_STATE_STARTFIRING,
  36. FT_STATE_FIRING,
  37. FT_STATE_SECONDARY,
  38. };
  39. enum EFlameThrowerAirblastFunction
  40. {
  41. TF_FUNCTION_AIRBLAST_PUSHBACK = 0x01,
  42. TF_FUNCTION_AIRBLAST_PUT_OUT_TEAMMATES = 0x02,
  43. TF_FUNCTION_AIRBLAST_REFLECT_PROJECTILES = 0x04,
  44. TF_FUNCTION_AIRBLAST_PUSHBACK__STUN = 0x08, // dependent on TF_FUNCTION_AIRBLAST_PUSHBACK
  45. TF_FUNCTION_AIRBLAST_PUSHBACK__VIEW_PUNCH = 0x10, // dependent on TF_FUNCTION_AIRBLAST_PUSHBACK
  46. };
  47. //=========================================================
  48. // Flamethrower Weapon
  49. //=========================================================
  50. #ifdef GAME_DLL
  51. class CTFFlameThrower : public CTFWeaponBaseGun, public CGameEventListener
  52. #else
  53. class CTFFlameThrower : public CTFWeaponBaseGun
  54. #endif // GAME_DLL
  55. {
  56. DECLARE_CLASS( CTFFlameThrower, CTFWeaponBaseGun );
  57. public:
  58. DECLARE_DATADESC();
  59. DECLARE_NETWORKCLASS();
  60. DECLARE_PREDICTABLE();
  61. CTFFlameThrower();
  62. ~CTFFlameThrower();
  63. virtual void Spawn( void );
  64. virtual int GetWeaponID( void ) const { return TF_WEAPON_FLAMETHROWER; }
  65. virtual bool Holster( CBaseCombatWeapon *pSwitchingTo );
  66. virtual void ItemPostFrame( void );
  67. virtual void PrimaryAttack();
  68. virtual void SecondaryAttack();
  69. virtual bool Lower( void );
  70. virtual void WeaponReset( void );
  71. virtual void DestroySounds( void );
  72. virtual void Precache( void );
  73. bool CanAirBlast() const;
  74. bool SupportsAirBlastFunction( EFlameThrowerAirblastFunction eFunction ) const;
  75. void FireAirBlast( int iAmmoPerShot );
  76. float GetSpinUpTime( void ) const;
  77. virtual bool IsFiring( void ) const OVERRIDE { return m_iWeaponState == FT_STATE_FIRING; }
  78. void SetWeaponState( int nWeaponState );
  79. void UseRage( void );
  80. Vector GetVisualMuzzlePos();
  81. Vector GetFlameOriginPos();
  82. void IncrementFlameDamageCount( void );
  83. void DecrementFlameDamageCount( void );
  84. void IncrementActiveFlameCount( void );
  85. void DecrementActiveFlameCount( void );
  86. void ResetFlameHitCount( void );
  87. virtual int GetBuffType() { int iBuffType = 0; CALL_ATTRIB_HOOK_INT( iBuffType, set_buff_type ); return iBuffType; }
  88. float GetProgress( void );
  89. bool IsRageFull( void ); // same as GetProgress() without the division by 100.0f
  90. const char* GetEffectLabelText( void ) { return "#TF_PYRORAGE"; }
  91. bool EffectMeterShouldFlash( void );
  92. virtual bool Deploy( void );
  93. #if defined( CLIENT_DLL )
  94. virtual void OnDataChanged(DataUpdateType_t updateType);
  95. virtual void UpdateOnRemove( void );
  96. virtual void SetDormant( bool bDormant );
  97. virtual int GetWorldModelIndex( void );
  98. // Start/stop flame sound and particle effects
  99. void StartFlame();
  100. void StopFlame( bool bAbrupt = false );
  101. virtual void RestartParticleEffect();
  102. virtual const char* FlameEffectName( bool bIsFirstPersonView );
  103. virtual const char* FlameCritEffectName( bool bIsFirstPersonView );
  104. virtual const char* FullCritChargedEffectName( void );
  105. void ClientEffectsThink( void );
  106. // constant pilot light sound
  107. void StartPilotLight();
  108. void StopPilotLight();
  109. void StopFullCritEffect();
  110. // burning sound when you hit a player/building
  111. void StopHitSound();
  112. float GetFlameHitRatio( void );
  113. #else
  114. void SetHitTarget( void );
  115. void HitTargetThink( void );
  116. virtual Vector GetDeflectionSize();
  117. virtual bool DeflectPlayer( CTFPlayer *pTarget, CTFPlayer *pOwner, Vector &vecForward, Vector &vecCenter, Vector &vecSize );
  118. virtual bool DeflectEntity( CBaseEntity *pTarget, CTFPlayer *pOwner, Vector &vecForward, Vector &vecCenter, Vector &vecSize );
  119. virtual void PlayDeflectionSound( bool bPlayer );
  120. #endif
  121. #ifdef STAGING_ONLY
  122. bool RocketPackCanActivate( int nAmmoCost );
  123. bool RocketPackLaunch( int nAmmoCost );
  124. bool ShootsNapalm( void );
  125. #endif // STAGING_ONLY
  126. virtual void FireGameEvent( IGameEvent *event );
  127. void CalculateHalloweenSpell( void );
  128. private:
  129. Vector GetMuzzlePosHelper( bool bVisualPos );
  130. CNetworkVar( int, m_iWeaponState );
  131. CNetworkVar( bool, m_bCritFire );
  132. CNetworkVar( bool, m_bHitTarget );
  133. CNetworkVar( int, m_iActiveFlames ); // Number of flames we have in the world
  134. CNetworkVar( int, m_iDamagingFlames ); // Number of flames that have done damage
  135. CNetworkVar( float, m_flChargeBeginTime );
  136. CNetworkVar( float, m_flSpinupBeginTime );
  137. CNetworkVar( bool, m_bHasHalloweenSpell );
  138. float m_flStartFiringTime;
  139. float m_flNextPrimaryAttackAnim;
  140. int m_iParticleWaterLevel;
  141. float m_flAmmoUseRemainder;
  142. float m_flResetBurstEffect;
  143. bool m_bFiredSecondary;
  144. bool m_bFiredBothAttacks;
  145. #if defined( CLIENT_DLL )
  146. CSoundPatch *m_pFiringStartSound;
  147. CSoundPatch *m_pFiringLoop;
  148. CSoundPatch *m_pFiringAccuracyLoop;
  149. CSoundPatch *m_pFiringHitLoop;
  150. bool m_bFiringLoopCritical;
  151. bool m_bFiringHitTarget;
  152. CSoundPatch *m_pPilotLightSound;
  153. CSoundPatch *m_pSpinUpSound;
  154. float m_flFlameHitRatio;
  155. float m_flPrevFlameHitRatio;
  156. const char *m_szAccuracySound;
  157. bool m_bEffectsThinking;
  158. bool m_bFullRageEffect;
  159. class FlameEffect_t
  160. {
  161. public:
  162. FlameEffect_t( CTFWeaponBase* pOwner ) : m_pFlameEffect(NULL), m_pOwner(pOwner), m_hEffectWeapon(NULL)
  163. {}
  164. void StartEffects( const char* pszEffectName);
  165. bool StopEffects();
  166. private:
  167. CNewParticleEffect* m_pFlameEffect;
  168. CTFWeaponBase* m_pOwner;
  169. EHANDLE m_hEffectWeapon;
  170. };
  171. FlameEffect_t m_FlameEffects;
  172. FlameEffect_t m_MmmmphEffect;
  173. #else
  174. float m_flTimeToStopHitSound;
  175. #endif
  176. CTFFlameThrower( const CTFFlameThrower & );
  177. };
  178. //-----------------------------------------------------------------------------
  179. // Flame rocket. Not used in TF2, but is a part of data tables in demos and
  180. // must live on forever.
  181. //-----------------------------------------------------------------------------
  182. class CTFFlameRocket : public CTFBaseRocket
  183. {
  184. DECLARE_CLASS( CTFFlameRocket, CTFBaseRocket );
  185. public:
  186. DECLARE_NETWORKCLASS();
  187. };
  188. #ifdef GAME_DLL
  189. //-----------------------------------------------------------------------------
  190. // Purpose:
  191. //-----------------------------------------------------------------------------
  192. DECLARE_AUTO_LIST( ITFFlameEntityAutoList );
  193. class CTFFlameEntity : public CBaseEntity, public ITFFlameEntityAutoList
  194. {
  195. DECLARE_CLASS( CTFFlameEntity, CBaseEntity );
  196. public:
  197. CTFFlameEntity();
  198. virtual void Spawn( void );
  199. public:
  200. static CTFFlameEntity *Create( const Vector &vecOrigin, const QAngle &vecAngles, CBaseEntity *pOwner, float flSpeed, int iDmgType, float m_flDmgAmount, bool bAlwaysCritFromBehind, bool bRandomize=true );
  201. void FlameThink( void );
  202. void SetCritFromBehind( bool bState ) { m_bCritFromBehind = bState; }
  203. bool IsEntityAttacker( CBaseEntity *pEnt ) { return m_hAttacker.Get() == pEnt; }
  204. private:
  205. void RemoveFlame();
  206. void OnCollide( CBaseEntity *pOther );
  207. void OnCollideWithTeammate( CTFPlayer *pPlayer );
  208. void SetHitTarget( void );
  209. bool IsBehindTarget( CBaseEntity *pTarget );
  210. float DotProductToTarget( CBaseEntity *pTarget );
  211. void UpdateFlameThrowerHitRatio( void );
  212. float GetFlameFloat( void );
  213. float GetFlameDrag( void );
  214. Vector m_vecInitialPos; // position the flame was fired from
  215. Vector m_vecPrevPos; // position from previous frame
  216. Vector m_vecBaseVelocity; // base velocity vector of the flame (ignoring rise effect)
  217. Vector m_vecAttackerVelocity; // velocity of attacking player at time flame was fired
  218. float m_flTimeRemove; // time at which the flame should be removed
  219. int m_iDmgType; // damage type
  220. float m_flDmgAmount; // amount of base damage
  221. CUtlVector<EHANDLE> m_hEntitiesBurnt; // list of entities this flame has burnt
  222. EHANDLE m_hAttacker; // attacking player
  223. int m_iAttackerTeam; // team of attacking player
  224. bool m_bCritFromBehind; // Always crits from behind.
  225. bool m_bBurnedEnemy; // We track hitting to calculate hit/miss ratio in the Flamethrower
  226. CHandle< CTFFlameThrower > m_hFlameThrower;
  227. };
  228. #endif // GAME_DLL
  229. #ifdef STAGING_ONLY
  230. //-----------------------------------------------------------------------------
  231. // Purpose:
  232. //-----------------------------------------------------------------------------
  233. class CTFProjectile_Napalm : public CTFProjectile_Jar
  234. {
  235. DECLARE_CLASS( CTFProjectile_Napalm, CTFProjectile_Jar );
  236. DECLARE_NETWORKCLASS();
  237. DECLARE_PREDICTABLE();
  238. DECLARE_DATADESC();
  239. public:
  240. CTFProjectile_Napalm();
  241. ~CTFProjectile_Napalm();
  242. virtual void Precache();
  243. virtual void Spawn();
  244. #ifdef GAME_DLL
  245. static CTFProjectile_Napalm *Create( CBaseCombatCharacter *pOwner, CTFFlameThrower *pLauncher );
  246. virtual int UpdateTransmitState();
  247. void NapalmThink( void );
  248. virtual void Explode( trace_t *pTrace, int bitsDamageType );
  249. virtual void PipebombTouch( CBaseEntity *pOther );
  250. virtual void ApplyBlastDamage( CTFPlayer *pThrower, Vector vecOrigin );
  251. virtual bool InitialExplodeEffects( CTFPlayer *pThrower, const trace_t *pTrace );
  252. virtual void ExplodeEffectOnTarget( CTFPlayer *pThrower, CTFPlayer *pTarget, CBaseCombatCharacter *pBaseTarget );
  253. virtual const char *GetImpactEffect( void );
  254. virtual void SetCustomPipebombModel( void );
  255. #endif
  256. #ifdef CLIENT_DLL
  257. virtual void OnDataChanged( DataUpdateType_t updateType );
  258. virtual const char *GetTrailParticleName( void );
  259. #endif // CLIENT_DLL
  260. CNetworkHandle( CTFFlameThrower, m_hFlameThrower );
  261. #ifdef GAME_DLL
  262. Vector m_vecBaseVelocity;
  263. float m_flRemoveTime;
  264. int m_nHitCount;
  265. float m_flLastBurnTime;
  266. #endif // CLIENT_DLL
  267. };
  268. #endif // STAGING_ONLY
  269. #endif // TF_WEAPON_FLAMETHROWER_H