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.

215 lines
7.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // TF Arrow Projectile
  4. //
  5. //=============================================================================
  6. #ifndef TF_PROJECTILE_ARROW_H
  7. #define TF_PROJECTILE_ARROW_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "tf_player.h"
  12. #include "tf_weaponbase_rocket.h"
  13. #include "iscorer.h"
  14. class CTFProjectile_Arrow : public CTFBaseRocket, public IScorer
  15. {
  16. public:
  17. DECLARE_CLASS( CTFProjectile_Arrow, CTFBaseRocket );
  18. DECLARE_NETWORKCLASS();
  19. DECLARE_DATADESC();
  20. CTFProjectile_Arrow();
  21. ~CTFProjectile_Arrow();
  22. // Creation.
  23. static CTFProjectile_Arrow *Create( const Vector &vecOrigin, const QAngle &vecAngles, const float fSpeed, const float fGravity, ProjectileType_t projectileType, CBaseEntity *pOwner = NULL, CBaseEntity *pScorer = NULL );
  24. virtual void InitArrow( const QAngle &vecAngles, const float fSpeed, const float fGravity, ProjectileType_t projectileType, CBaseEntity *pOwner = NULL, CBaseEntity *pScorer = NULL );
  25. virtual void Spawn();
  26. virtual void Precache();
  27. virtual int GetWeaponID( void ) const { return m_iWeaponId; }
  28. virtual int GetProjectileType ( void ) const OVERRIDE;
  29. virtual bool StrikeTarget( mstudiobbox_t *pBox, CBaseEntity *pOther );
  30. virtual void OnArrowImpact( mstudiobbox_t *pBox, CBaseEntity *pOther, CBaseEntity *pAttacker );
  31. virtual bool OnArrowImpactObject( CBaseEntity *pOther );
  32. bool PositionArrowOnBone( mstudiobbox_t *pBox, CBaseAnimating *pOtherAnim );
  33. void GetBoneAttachmentInfo( mstudiobbox_t *pBox, CBaseAnimating *pOtherAnim, Vector &bonePosition, QAngle &boneAngles, int &boneIndexAttached, int &physicsBoneIndex );
  34. void ImpactThink( void );
  35. void BuildingHealingArrow( CBaseEntity *pOther );
  36. int GetArrowSkin() const;
  37. // IScorer interface
  38. virtual CBasePlayer *GetScorer( void );
  39. virtual CBasePlayer *GetAssistant( void ) { return NULL; }
  40. void SetScorer( CBaseEntity *pScorer );
  41. void SetCritical( bool bCritical ) { m_bCritical = bCritical; }
  42. virtual float GetDamage();
  43. virtual bool CanHeadshot();
  44. virtual void OnArrowMissAllPlayers( void );
  45. virtual void ArrowTouch( CBaseEntity *pOther );
  46. virtual void CheckSkyboxImpact( CBaseEntity *pOther );
  47. bool CheckRagdollPinned( const Vector &start, const Vector &vel, int boneIndexAttached, int physicsBoneIndex, CBaseEntity *pOther, int iHitGroup, int iVictim );
  48. virtual void AdjustDamageDirection( const CTakeDamageInfo &info, Vector &dir, CBaseEntity *pEnt );
  49. void ImpactSound( const char *pszSoundName, bool bLoudForAttacker = false );
  50. virtual void BreakArrow();
  51. virtual void ImpactTeamPlayer( CTFPlayer *pOther ) {}
  52. void FadeOut( int iTime );
  53. void RemoveThink();
  54. virtual const char * GetTrailParticleName( void );
  55. void CreateTrail( void );
  56. void RemoveTrail( void );
  57. virtual void IncrementDeflected( void );
  58. virtual void Deflected( CBaseEntity *pDeflectedBy, Vector &vecDir );
  59. virtual bool ShouldNotDetonate( void ) { return true; }
  60. bool IsAlight() { return m_bArrowAlight; }
  61. void SetArrowAlight( bool bAlight ) { m_bArrowAlight = bAlight; }
  62. virtual bool IsDeflectable() OVERRIDE { return true; }
  63. void SetPenetrate( bool bPenetrate = false ) { m_bPenetrate = bPenetrate; SetSolidFlags( FSOLID_NOT_SOLID | FSOLID_TRIGGER ); }
  64. bool CanPenetrate() const { return m_bPenetrate; }
  65. virtual bool IsDestroyable( void ) OVERRIDE { return false; }
  66. virtual bool IsBreakable( void ) const { return true; }
  67. void SetApplyMilkOnHit() { m_bApplyMilkOnHit = true; }
  68. private:
  69. CBaseHandle m_Scorer;
  70. float m_flImpactTime;
  71. Vector m_vecImpactNormal;
  72. float m_flTrailLife;
  73. EHANDLE m_pTrail;
  74. bool m_bStruckEnemy;
  75. CNetworkVar( bool, m_bArrowAlight );
  76. CNetworkVar( bool, m_bCritical );
  77. bool m_bPenetrate;
  78. CNetworkVar( int, m_iProjectileType );
  79. int m_iWeaponId;
  80. bool m_bFiredWhileZoomed;
  81. protected:
  82. CUtlVector< int > m_HitEntities;
  83. float m_flInitTime;
  84. bool m_bApplyMilkOnHit; // For Apothacary's Arrow which can sometimes be special
  85. };
  86. class CTFProjectile_HealingBolt : public CTFProjectile_Arrow
  87. {
  88. public:
  89. DECLARE_CLASS( CTFProjectile_HealingBolt, CTFProjectile_Arrow );
  90. DECLARE_NETWORKCLASS();
  91. DECLARE_DATADESC();
  92. virtual void InitArrow( const QAngle &vecAngles, const float fSpeed, const float fGravity, ProjectileType_t projectileType, CBaseEntity *pOwner = NULL, CBaseEntity *pScorer = NULL ) OVERRIDE;
  93. virtual bool CanHeadshot() { return false; }
  94. virtual void ImpactTeamPlayer( CTFPlayer *pOther );
  95. virtual float GetCollideWithTeammatesDelay() const { return 0.f; }
  96. };
  97. class CTFProjectile_GrapplingHook : public CTFProjectile_Arrow
  98. {
  99. public:
  100. DECLARE_CLASS( CTFProjectile_GrapplingHook, CTFProjectile_Arrow );
  101. DECLARE_NETWORKCLASS();
  102. DECLARE_DATADESC();
  103. CTFProjectile_GrapplingHook();
  104. virtual void Spawn() OVERRIDE;
  105. virtual void Precache() OVERRIDE;
  106. virtual void UpdateOnRemove() OVERRIDE;
  107. virtual void InitArrow( const QAngle &vecAngles, const float fSpeed, const float fGravity, ProjectileType_t projectileType, CBaseEntity *pOwner = NULL, CBaseEntity *pScorer = NULL ) OVERRIDE;
  108. virtual void OnArrowImpact( mstudiobbox_t *pBox, CBaseEntity *pOther, CBaseEntity *pAttacker ) OVERRIDE;
  109. virtual bool OnArrowImpactObject( CBaseEntity *pOther ) OVERRIDE;
  110. virtual void OnArrowMissAllPlayers( void ) OVERRIDE {}
  111. virtual void CheckSkyboxImpact( CBaseEntity *pOther ) OVERRIDE;
  112. virtual void BreakArrow() { /*DO NOTHING*/ }
  113. virtual bool IsDeflectable() OVERRIDE { return false; }
  114. virtual bool IsBreakable( void ) const OVERRIDE { return false; }
  115. virtual float GetDamage() OVERRIDE { return 1.f; }
  116. virtual bool CanHeadshot() OVERRIDE { return false; }
  117. virtual bool CanCollideWithTeammates() const OVERRIDE { return false; }
  118. void HookTarget( CBaseEntity *pOther );
  119. void HookLatchedThink();
  120. private:
  121. void StartImpactFleshSoundLoop();
  122. void StopImpactFleshSoundLoop();
  123. CSoundPatch *m_pImpactFleshSoundLoop;
  124. };
  125. //-----------------------------------------------------------------------------
  126. // Purpose:
  127. //-----------------------------------------------------------------------------
  128. class CTraceFilterCollisionArrows : public CTraceFilterEntitiesOnly
  129. {
  130. public:
  131. DECLARE_CLASS_NOBASE( CTraceFilterCollisionArrows );
  132. CTraceFilterCollisionArrows( const IHandleEntity *passentity, const IHandleEntity *passentity2 )
  133. : m_pPassEnt(passentity), m_pPassEnt2(passentity2)
  134. {
  135. }
  136. virtual bool ShouldHitEntity( IHandleEntity *pHandleEntity, int contentsMask )
  137. {
  138. if ( !PassServerEntityFilter( pHandleEntity, m_pPassEnt ) )
  139. return false;
  140. CBaseEntity *pEntity = EntityFromEntityHandle( pHandleEntity );
  141. if ( pEntity )
  142. {
  143. if ( pEntity == m_pPassEnt2 )
  144. return false;
  145. if ( pEntity->GetCollisionGroup() == TF_COLLISIONGROUP_GRENADES )
  146. return false;
  147. if ( pEntity->GetCollisionGroup() == TFCOLLISION_GROUP_ROCKETS )
  148. return false;
  149. if ( pEntity->GetCollisionGroup() == TFCOLLISION_GROUP_ROCKET_BUT_NOT_WITH_OTHER_ROCKETS )
  150. return false;
  151. if ( pEntity->GetCollisionGroup() == COLLISION_GROUP_DEBRIS )
  152. return false;
  153. if ( pEntity->GetCollisionGroup() == TFCOLLISION_GROUP_RESPAWNROOMS )
  154. return false;
  155. if ( pEntity->GetCollisionGroup() == COLLISION_GROUP_NONE )
  156. return false;
  157. return true;
  158. }
  159. return true;
  160. }
  161. protected:
  162. const IHandleEntity *m_pPassEnt;
  163. const IHandleEntity *m_pPassEnt2;
  164. };
  165. #endif //TF_PROJECTILE_ARROW_H