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.

299 lines
7.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef TF_WEAPON_MEDIGUN_H
  7. #define TF_WEAPON_MEDIGUN_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "tf_weaponbase_gun.h"
  12. #if defined( CLIENT_DLL )
  13. #define CWeaponMedigun C_WeaponMedigun
  14. #define CTFMedigunShield C_TFMedigunShield
  15. #endif
  16. class CTFMedigunShield;
  17. class CTFReviveMarker;
  18. enum medigun_weapontypes_t
  19. {
  20. MEDIGUN_STANDARD = 0,
  21. MEDIGUN_UBER,
  22. MEDIGUN_QUICKFIX,
  23. MEDIGUN_RESIST,
  24. };
  25. enum medigun_resist_types_t
  26. {
  27. MEDIGUN_BULLET_RESIST = 0,
  28. MEDIGUN_BLAST_RESIST,
  29. MEDIGUN_FIRE_RESIST,
  30. MEDIGUN_NUM_RESISTS
  31. };
  32. struct MedigunEffects_t
  33. {
  34. ETFCond eCondition;
  35. ETFCond eWearingOffCondition;
  36. const char *pszChargeOnSound;
  37. const char *pszChargeOffSound;
  38. };
  39. extern MedigunEffects_t g_MedigunEffects[MEDIGUN_NUM_CHARGE_TYPES];
  40. #define MAX_HEALING_TARGETS 1 //6
  41. #define CLEAR_ALL_TARGETS -1
  42. //=========================================================
  43. // Beam healing gun
  44. //=========================================================
  45. class CWeaponMedigun : public CTFWeaponBaseGun
  46. {
  47. DECLARE_CLASS( CWeaponMedigun, CTFWeaponBaseGun );
  48. public:
  49. DECLARE_NETWORKCLASS();
  50. DECLARE_PREDICTABLE();
  51. CWeaponMedigun( void );
  52. ~CWeaponMedigun( void );
  53. virtual void Precache();
  54. virtual bool Deploy( void );
  55. virtual bool Holster( CBaseCombatWeapon *pSwitchingTo );
  56. virtual void UpdateOnRemove( void );
  57. virtual void ItemHolsterFrame( void );
  58. virtual void ItemPostFrame( void );
  59. virtual bool Lower( void );
  60. virtual void PrimaryAttack( void );
  61. virtual void SecondaryAttack( void );
  62. virtual void WeaponIdle( void );
  63. void DrainCharge( void );
  64. virtual void WeaponReset( void );
  65. virtual float GetTargetRange( void );
  66. virtual float GetStickRange( void );
  67. virtual float GetHealRate( void );
  68. virtual bool AppliesModifier( void ) { return true; }
  69. virtual int GetWeaponID( void ) const { return TF_WEAPON_MEDIGUN; }
  70. int GetMedigunType( void ) const;
  71. bool IsReleasingCharge( void ) const;
  72. medigun_charge_types GetChargeType( void ) const;
  73. void CycleResistType();
  74. medigun_resist_types_t GetResistType() const;
  75. CBaseEntity *GetHealTarget( void ) { return IsAttachedToBuilding() ? NULL : m_hHealingTarget.Get(); }
  76. bool IsAllowedToTargetBuildings( void );
  77. bool IsAttachedToBuilding( void );
  78. #ifdef GAME_DLL
  79. // We may or may not be healing this person still. Resets on WeaponReset
  80. CBaseEntity *GetMostRecentHealTarget( void ) { return m_hLastHealingTarget.Get(); }
  81. void RecalcEffectOnTarget( CTFPlayer *pPlayer, bool bInstantRemove = false );
  82. #endif
  83. float GetReleaseStartedAt( void ) { return m_flReleaseStartedAt; }
  84. #if defined( CLIENT_DLL )
  85. // Stop all sounds being output.
  86. void StopHealSound( bool bStopHealingSound = true, bool bStopNoTargetSound = true );
  87. virtual void OnDataChanged( DataUpdateType_t updateType );
  88. virtual void ClientThink();
  89. void UpdateEffects( void );
  90. void ForceHealingTargetUpdate( void ) { m_bUpdateHealingTargets = true; }
  91. void StopChargeEffect( bool bImmediately );
  92. void ManageChargeEffect( void );
  93. void UpdateMedicAutoCallers( void );
  94. #else
  95. void HealTargetThink( void );
  96. void AddCharge( float flPercentage );
  97. void SubtractCharge( float flPercentage );
  98. #endif
  99. void SetChargeLevel( float flChargeLevel ) { m_flChargeLevel = flChargeLevel; }
  100. float GetChargeLevel( void ) const { return m_flChargeLevel; }
  101. float GetMinChargeAmount( void ) const;
  102. virtual void OnControlStunned( void );
  103. virtual bool IsHolstered(){ return m_bHolstered; }
  104. float GetProgress( void );
  105. const char* GetEffectLabelText( void ) { return "#TF_Rescue"; }
  106. bool EffectMeterShouldFlash( void );
  107. private:
  108. void SubtractChargeAndUpdateDeployState( float flSubtractAmount, bool bForceDrain );
  109. bool FindAndHealTargets( void );
  110. void MaintainTargetInSlot();
  111. void FindNewTargetForSlot();
  112. void RemoveHealingTarget( bool bStopHealingSelf = false );
  113. bool HealingTarget( CBaseEntity *pTarget );
  114. bool AllowedToHealTarget( CBaseEntity *pTarget );
  115. void CheckAchievementsOnHealTarget( void );
  116. void StartHealingTarget( CBaseEntity *pTarget );
  117. void StopHealingOwner( void );
  118. const char *GetHealSound() const;
  119. #ifdef GAME_DLL
  120. void UberchargeChunkDeployed();
  121. #endif
  122. void CreateMedigunShield( void );
  123. void RemoveMedigunShield( void );
  124. public:
  125. #ifdef STAGING_ONLY
  126. CTFMedigunShield *GetMedigunShield() const { return m_hMedigunShield; }
  127. bool HasPermanentShield() const;
  128. #endif // STAGING_ONLY
  129. #ifdef GAME_DLL
  130. CNetworkHandle( CBaseEntity, m_hHealingTarget );
  131. CHandle< CBaseEntity > m_hLastHealingTarget;
  132. #else
  133. CNetworkHandle( C_BaseEntity, m_hHealingTarget );
  134. #endif
  135. bool m_bWasHealingBeforeDeath;
  136. protected:
  137. // Networked data.
  138. CNetworkVar( bool, m_bHealing );
  139. CNetworkVar( bool, m_bAttacking );
  140. double m_flNextBuzzTime;
  141. float m_flHealEffectLifetime; // Count down until the healing effect goes off.
  142. float m_flReleaseStartedAt;
  143. CNetworkVar( bool, m_bHolstered );
  144. CNetworkVar( bool, m_bChargeRelease );
  145. CNetworkVar( float, m_flChargeLevel );
  146. CNetworkVar( int, m_nChargeResistType );
  147. float m_flNextTargetCheckTime;
  148. bool m_bCanChangeTarget; // used to track the PrimaryAttack key being released for AutoHeal mode
  149. bool m_bAttack2Down;
  150. bool m_bAttack3Down;
  151. bool m_bReloadDown;
  152. float m_flEndResistCharge;
  153. struct targetdetachtimes_t
  154. {
  155. float flTime;
  156. EHANDLE hTarget;
  157. };
  158. CUtlVector<targetdetachtimes_t> m_DetachedTargets; // Tracks times we last applied charge to a target. Used to drain faster for more targets.
  159. #ifdef GAME_DLL
  160. CDamageModifier m_DamageModifier; // This attaches to whoever we're healing.
  161. bool m_bHealingSelf;
  162. int m_nHealTargetClass;
  163. int m_nChargesReleased;
  164. #endif
  165. CHandle< CTFMedigunShield > m_hMedigunShield;
  166. CHandle< CTFReviveMarker > m_hReviveMarker;
  167. #ifdef CLIENT_DLL
  168. bool m_bPlayingSound;
  169. bool m_bUpdateHealingTargets;
  170. struct healingtargeteffects_t
  171. {
  172. C_BaseEntity *pOwner;
  173. C_BaseEntity *pTarget;
  174. CNewParticleEffect *pEffect;
  175. CNewParticleEffect *pCustomEffect;
  176. };
  177. healingtargeteffects_t m_hHealingTargetEffect;
  178. float m_flDenySecondary;
  179. bool m_bOldChargeRelease;
  180. int m_nOldChargeResistType;
  181. C_BaseEntity *m_pChargeEffectOwner;
  182. CNewParticleEffect *m_pChargeEffect;
  183. CSoundPatch *m_pChargedSound;
  184. CSoundPatch *m_pDisruptSound;
  185. CUtlVector< int > m_iAutoCallers;
  186. float m_flAutoCallerCheckTime;
  187. #endif
  188. private:
  189. CWeaponMedigun( const CWeaponMedigun & );
  190. };
  191. class CTFMedigunShield : public CBaseAnimating
  192. {
  193. DECLARE_CLASS( CTFMedigunShield, CBaseAnimating );
  194. public:
  195. DECLARE_NETWORKCLASS();
  196. DECLARE_PREDICTABLE();
  197. DECLARE_DATADESC();
  198. CTFMedigunShield();
  199. ~CTFMedigunShield();
  200. virtual void Spawn();
  201. virtual void Precache();
  202. virtual bool IsCombatItem( void ) const { return true; }
  203. void UpdateShieldPosition( void );
  204. #ifdef GAME_DLL
  205. virtual void TraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator );
  206. virtual int OnTakeDamage( const CTakeDamageInfo &info );
  207. static CTFMedigunShield *Create( CTFPlayer *pOwner );
  208. // virtual bool TestCollision( const Ray_t &ray, unsigned int mask, trace_t& trace );
  209. virtual bool ShouldCollide( int collisionGroup, int contentsMask ) const;
  210. virtual void StartTouch( CBaseEntity *pOther ) OVERRIDE;
  211. void ShieldTouch( CBaseEntity *pOther );
  212. virtual void EndTouch( CBaseEntity *pOther ) OVERRIDE;
  213. void ShieldThink( void );
  214. void RemoveShield( void );
  215. #ifdef STAGING_ONLY
  216. void SetPermanentShield( bool bPermanent ) { m_bPermanentShield = bPermanent; }
  217. #endif // STAGING_ONLY
  218. #else
  219. virtual void ClientThink();
  220. #endif
  221. private:
  222. int m_nBlinkCount;
  223. #ifdef GAME_DLL
  224. float m_flShieldEnergyLevel;
  225. CSoundPatch *m_pTouchLoop;
  226. #ifdef STAGING_ONLY
  227. bool m_bPermanentShield;
  228. #endif // STAGING_ONLY
  229. #endif // GAME_DLL
  230. };
  231. #endif // TF_WEAPON_MEDIGUN_H