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 PROP_COMBINE_BALL_H
  7. #define PROP_COMBINE_BALL_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. //-----------------------------------------------------------------------------
  12. // Includes
  13. //-----------------------------------------------------------------------------
  14. #include "player_pickup.h" // for combine ball inheritance
  15. //-----------------------------------------------------------------------------
  16. // Forward declarations
  17. //-----------------------------------------------------------------------------
  18. class CFuncCombineBallSpawner;
  19. class CSpriteTrail;
  20. //-----------------------------------------------------------------------------
  21. // Looks for enemies, bounces a max # of times before it breaks
  22. //-----------------------------------------------------------------------------
  23. class CPropCombineBall : public CBaseAnimating, public CDefaultPlayerPickupVPhysics
  24. {
  25. public:
  26. DECLARE_CLASS( CPropCombineBall, CBaseAnimating );
  27. DECLARE_DATADESC();
  28. DECLARE_SERVERCLASS();
  29. virtual void Precache();
  30. virtual void Spawn();
  31. virtual void UpdateOnRemove();
  32. void StopLoopingSounds();
  33. virtual void OnPhysGunPickup( CBasePlayer *pPhysGunUser, PhysGunPickup_t reason );
  34. virtual void OnPhysGunDrop( CBasePlayer *pPhysGunUser, PhysGunDrop_t Reason );
  35. virtual void VPhysicsCollision( int index, gamevcollisionevent_t *pEvent );
  36. virtual bool OverridePropdata();
  37. virtual bool CreateVPhysics();
  38. CFuncCombineBallSpawner *GetSpawner();
  39. virtual void ExplodeThink( void );
  40. // Override of IPlayerPickupVPhysics;
  41. virtual bool ShouldPuntUseLaunchForces( PhysGunForce_t reason ) { return ( reason == PHYSGUN_FORCE_PUNTED ); }
  42. void SetRadius( float flRadius );
  43. void SetSpeed( float flSpeed ) { m_flSpeed = flSpeed; }
  44. float GetSpeed( void ) const { return m_flSpeed; }
  45. void CaptureBySpawner( );
  46. bool IsBeingCaptured() const { return m_bCaptureInProgress; }
  47. void ReplaceInSpawner( float flSpeed );
  48. // Input
  49. void InputExplode( inputdata_t &inputdata );
  50. void InputFadeAndRespawn( inputdata_t &inputdata );
  51. void InputKill( inputdata_t &inputdata );
  52. void InputSocketed( inputdata_t &inputdata );
  53. enum
  54. {
  55. STATE_NOT_THROWN = 0,
  56. STATE_HOLDING,
  57. STATE_THROWN,
  58. STATE_LAUNCHED, //by a combine_ball launcher
  59. };
  60. void SetState( int state );
  61. bool IsInField() const;
  62. void StartWhizSoundThink( void );
  63. void StartLifetime( float flDuration );
  64. void ClearLifetime( );
  65. void SetMass( float mass );
  66. void SetWeaponLaunched( bool state = true ) { m_bWeaponLaunched = state; m_bLaunched = state; }
  67. bool WasWeaponLaunched( void ) const { return m_bWeaponLaunched; }
  68. bool WasFiredByNPC() const { return (GetOwnerEntity() && GetOwnerEntity()->IsNPC()); }
  69. bool ShouldHitPlayer() const;
  70. virtual CBasePlayer *HasPhysicsAttacker( float dt );
  71. void SetSpawner( CFuncCombineBallSpawner *pSpawner ) { m_hSpawner = pSpawner; }
  72. void NotifySpawnerOfRemoval( void );
  73. float LastCaptureTime() const;
  74. unsigned char GetState() const { return m_nState; }
  75. int NumBounces( void ) const { return m_nBounceCount; }
  76. void SetMaxBounces( int iBounces )
  77. {
  78. m_nMaxBounces = iBounces;
  79. }
  80. void SetEmitState( bool bEmit )
  81. {
  82. m_bEmit = bEmit;
  83. }
  84. void SetOriginalOwner( CBaseEntity *pEntity ) { m_hOriginalOwner = pEntity; }
  85. CBaseEntity *GetOriginalOwner() { return m_hOriginalOwner; }
  86. private:
  87. void SetPlayerLaunched( CBasePlayer *pOwner );
  88. float GetBallHoldDissolveTime();
  89. float GetBallHoldSoundRampTime();
  90. // Pow!
  91. void DoExplosion( );
  92. void StartAnimating( void );
  93. void StopAnimating( void );
  94. void SetBallAsLaunched( void );
  95. void CollisionEventToTrace( int index, gamevcollisionevent_t *pEvent, trace_t &tr );
  96. bool DissolveEntity( CBaseEntity *pEntity );
  97. void OnHitEntity( CBaseEntity *pHitEntity, float flSpeed, int index, gamevcollisionevent_t *pEvent );
  98. void DoImpactEffect( const Vector &preVelocity, int index, gamevcollisionevent_t *pEvent );
  99. // Bounce inside the spawner:
  100. void BounceInSpawner( float flSpeed, int index, gamevcollisionevent_t *pEvent );
  101. bool IsAttractiveTarget( CBaseEntity *pEntity );
  102. // Deflects the ball toward enemies in case of a collision
  103. void DeflectTowardEnemy( float flSpeed, int index, gamevcollisionevent_t *pEvent );
  104. // Is this something we can potentially dissolve?
  105. bool IsHittableEntity( CBaseEntity *pHitEntity );
  106. // Sucky.
  107. void WhizSoundThink();
  108. void DieThink();
  109. void DissolveThink();
  110. void DissolveRampSoundThink();
  111. void AnimThink( void );
  112. void FadeOut( float flDuration );
  113. bool OutOfBounces( void ) const
  114. {
  115. return ( m_nState == STATE_LAUNCHED && m_nMaxBounces != 0 && m_nBounceCount >= m_nMaxBounces );
  116. }
  117. private:
  118. int m_nBounceCount;
  119. int m_nMaxBounces;
  120. bool m_bBounceDie;
  121. float m_flLastBounceTime;
  122. bool m_bFiredGrabbedOutput;
  123. bool m_bStruckEntity; // Has hit an entity already (control accuracy)
  124. bool m_bWeaponLaunched; // Means this was fired from the AR2
  125. bool m_bForward; // Movement direction in ball spawner
  126. unsigned char m_nState;
  127. bool m_bCaptureInProgress;
  128. float m_flSpeed;
  129. CSpriteTrail *m_pGlowTrail;
  130. CSoundPatch *m_pHoldingSound;
  131. float m_flNextDamageTime;
  132. float m_flLastCaptureTime;
  133. CHandle < CFuncCombineBallSpawner > m_hSpawner;
  134. EHANDLE m_hOriginalOwner;
  135. CNetworkVar( bool, m_bEmit );
  136. CNetworkVar( bool, m_bHeld );
  137. CNetworkVar( bool, m_bLaunched );
  138. CNetworkVar( float, m_flRadius );
  139. };
  140. class CFuncCombineBallSpawner : public CBaseEntity
  141. {
  142. DECLARE_CLASS( CFuncCombineBallSpawner, CBaseEntity );
  143. DECLARE_DATADESC();
  144. public:
  145. CFuncCombineBallSpawner();
  146. virtual void Spawn();
  147. virtual void Precache();
  148. // Balls call this to figure out where to bounce to
  149. void GetTargetEndpoint( bool bForward, Vector *pVecEndpoint );
  150. // Balls call this when they've been removed from the spawner
  151. void RespawnBall( float flRespawnTime );
  152. void RespawnBallPostExplosion( void );
  153. // Fire ball grabbed output
  154. void BallGrabbed( CBaseEntity *pEntity );
  155. // Get speed of ball to place into the field
  156. float GetBallSpeed( ) const;
  157. // Register that a reflection occurred
  158. void RegisterReflection( CPropCombineBall *pBall, bool bForward );
  159. // Spawn a ball
  160. virtual void SpawnBall();
  161. private:
  162. // Choose a random point inside the cylinder
  163. void ChoosePointInCylinder( Vector *pVecPoint );
  164. // Choose a random point inside the box
  165. void ChoosePointInBox( Vector *pVecPoint );
  166. // Used to determine when to respawn balls
  167. void BallThink();
  168. // Input
  169. void InputEnable( inputdata_t &inputdata );
  170. void InputDisable( inputdata_t &inputdata );
  171. // Fire ball grabbed output
  172. void GrabBallTouch( CBaseEntity *pOther );
  173. public:
  174. bool m_bShooter;
  175. float m_flBallRadius;
  176. float m_flBallRespawnTime;
  177. float m_flMinSpeed;
  178. float m_flMaxSpeed;
  179. private:
  180. CUtlVector< float > m_BallRespawnTime;
  181. int m_nBallCount;
  182. int m_nBallsRemainingInField;
  183. float m_flRadius;
  184. float m_flDisableTime;
  185. bool m_bEnabled;
  186. COutputEvent m_OnBallGrabbed;
  187. COutputEvent m_OnBallReinserted;
  188. COutputEvent m_OnBallHitTopSide;
  189. COutputEvent m_OnBallHitBottomSide;
  190. COutputEvent m_OnLastBallGrabbed;
  191. COutputEvent m_OnFirstBallReinserted;
  192. };
  193. class CPointCombineBallLauncher : public CFuncCombineBallSpawner
  194. {
  195. DECLARE_CLASS( CPointCombineBallLauncher, CFuncCombineBallSpawner );
  196. DECLARE_DATADESC();
  197. public:
  198. virtual void Spawn( void );
  199. virtual void SpawnBall( void );
  200. void InputLaunchBall ( inputdata_t &inputdata );
  201. CPointCombineBallLauncher();
  202. private:
  203. int m_iBounces;
  204. float m_flConeDegrees;
  205. string_t m_iszBullseyeName;
  206. };
  207. // Creates a combine ball
  208. CBaseEntity *CreateCombineBall( const Vector &origin, const Vector &velocity, float radius, float mass, float lifetime, CBaseEntity *pOwner );
  209. // Query function to find out if a physics object is a combine ball (used for collision checks)
  210. bool UTIL_IsCombineBall( CBaseEntity *pEntity );
  211. bool UTIL_IsCombineBallDefinite( CBaseEntity *pEntity );
  212. bool UTIL_IsAR2CombineBall( CBaseEntity *pEntity );
  213. #endif // PROP_COMBINE_BALL_H