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.

256 lines
7.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef WEAPON_RPG_H
  8. #define WEAPON_RPG_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "basehlcombatweapon.h"
  13. #include "Sprite.h"
  14. #include "npcevent.h"
  15. #include "beam_shared.h"
  16. class CWeaponRPG;
  17. class CLaserDot;
  18. class RocketTrail;
  19. //###########################################################################
  20. // >> CMissile (missile launcher class is below this one!)
  21. //###########################################################################
  22. class CMissile : public CBaseCombatCharacter
  23. {
  24. DECLARE_CLASS( CMissile, CBaseCombatCharacter );
  25. public:
  26. static const int EXPLOSION_RADIUS = 200;
  27. CMissile();
  28. ~CMissile();
  29. #ifdef HL1_DLL
  30. Class_T Classify( void ) { return CLASS_NONE; }
  31. #else
  32. Class_T Classify( void ) { return CLASS_MISSILE; }
  33. #endif
  34. void Spawn( void );
  35. void Precache( void );
  36. void MissileTouch( CBaseEntity *pOther );
  37. void Explode( void );
  38. void ShotDown( void );
  39. void AccelerateThink( void );
  40. void AugerThink( void );
  41. void IgniteThink( void );
  42. void SeekThink( void );
  43. void DumbFire( void );
  44. void SetGracePeriod( float flGracePeriod );
  45. int OnTakeDamage_Alive( const CTakeDamageInfo &info );
  46. void Event_Killed( const CTakeDamageInfo &info );
  47. virtual float GetDamage() { return m_flDamage; }
  48. virtual void SetDamage(float flDamage) { m_flDamage = flDamage; }
  49. unsigned int PhysicsSolidMaskForEntity( void ) const;
  50. CHandle<CWeaponRPG> m_hOwner;
  51. static CMissile *Create( const Vector &vecOrigin, const QAngle &vecAngles, edict_t *pentOwner );
  52. void CreateDangerSounds( bool bState ){ m_bCreateDangerSounds = bState; }
  53. static void AddCustomDetonator( CBaseEntity *pEntity, float radius, float height = -1 );
  54. static void RemoveCustomDetonator( CBaseEntity *pEntity );
  55. protected:
  56. virtual void DoExplosion();
  57. virtual void ComputeActualDotPosition( CLaserDot *pLaserDot, Vector *pActualDotPosition, float *pHomingSpeed );
  58. virtual int AugerHealth() { return m_iMaxHealth - 20; }
  59. // Creates the smoke trail
  60. void CreateSmokeTrail( void );
  61. // Gets the shooting position
  62. void GetShootPosition( CLaserDot *pLaserDot, Vector *pShootPosition );
  63. CHandle<RocketTrail> m_hRocketTrail;
  64. float m_flAugerTime; // Amount of time to auger before blowing up anyway
  65. float m_flMarkDeadTime;
  66. float m_flDamage;
  67. struct CustomDetonator_t
  68. {
  69. EHANDLE hEntity;
  70. float radiusSq;
  71. float halfHeight;
  72. };
  73. static CUtlVector<CustomDetonator_t> gm_CustomDetonators;
  74. private:
  75. float m_flGracePeriodEndsAt;
  76. bool m_bCreateDangerSounds;
  77. DECLARE_DATADESC();
  78. };
  79. //-----------------------------------------------------------------------------
  80. // Laser dot control
  81. //-----------------------------------------------------------------------------
  82. CBaseEntity *CreateLaserDot( const Vector &origin, CBaseEntity *pOwner, bool bVisibleDot );
  83. void SetLaserDotTarget( CBaseEntity *pLaserDot, CBaseEntity *pTarget );
  84. void EnableLaserDot( CBaseEntity *pLaserDot, bool bEnable );
  85. //-----------------------------------------------------------------------------
  86. // Specialized mizzizzile
  87. //-----------------------------------------------------------------------------
  88. class CAPCMissile : public CMissile
  89. {
  90. DECLARE_CLASS( CMissile, CMissile );
  91. DECLARE_DATADESC();
  92. public:
  93. static CAPCMissile *Create( const Vector &vecOrigin, const QAngle &vecAngles, const Vector &vecVelocity, CBaseEntity *pOwner );
  94. CAPCMissile();
  95. ~CAPCMissile();
  96. void IgniteDelay( void );
  97. void AugerDelay( float flDelayTime );
  98. void ExplodeDelay( float flDelayTime );
  99. void DisableGuiding();
  100. #if defined( HL2_DLL )
  101. virtual Class_T Classify ( void ) { return CLASS_COMBINE; }
  102. #endif
  103. void AimAtSpecificTarget( CBaseEntity *pTarget );
  104. void SetGuidanceHint( const char *pHintName );
  105. void APCSeekThink( void );
  106. CAPCMissile *m_pNext;
  107. protected:
  108. virtual void DoExplosion();
  109. virtual void ComputeActualDotPosition( CLaserDot *pLaserDot, Vector *pActualDotPosition, float *pHomingSpeed );
  110. virtual int AugerHealth();
  111. private:
  112. void Init();
  113. void ComputeLeadingPosition( const Vector &vecShootPosition, CBaseEntity *pTarget, Vector *pLeadPosition );
  114. void BeginSeekThink();
  115. void AugerStartThink();
  116. void ExplodeThink();
  117. void APCMissileTouch( CBaseEntity *pOther );
  118. float m_flReachedTargetTime;
  119. float m_flIgnitionTime;
  120. bool m_bGuidingDisabled;
  121. float m_flLastHomingSpeed;
  122. EHANDLE m_hSpecificTarget;
  123. string_t m_strHint;
  124. };
  125. //-----------------------------------------------------------------------------
  126. // Finds apc missiles in cone
  127. //-----------------------------------------------------------------------------
  128. CAPCMissile *FindAPCMissileInCone( const Vector &vecOrigin, const Vector &vecDirection, float flAngle );
  129. //-----------------------------------------------------------------------------
  130. // RPG
  131. //-----------------------------------------------------------------------------
  132. class CWeaponRPG : public CBaseHLCombatWeapon
  133. {
  134. DECLARE_CLASS( CWeaponRPG, CBaseHLCombatWeapon );
  135. public:
  136. CWeaponRPG();
  137. ~CWeaponRPG();
  138. DECLARE_SERVERCLASS();
  139. void Precache( void );
  140. void PrimaryAttack( void );
  141. virtual float GetFireRate( void ) { return 1; };
  142. void ItemPostFrame( void );
  143. void Activate( void );
  144. void DecrementAmmo( CBaseCombatCharacter *pOwner );
  145. bool Deploy( void );
  146. bool Holster( CBaseCombatWeapon *pSwitchingTo = NULL );
  147. bool Reload( void );
  148. bool WeaponShouldBeLowered( void );
  149. bool Lower( void );
  150. virtual void Drop( const Vector &vecVelocity );
  151. int GetMinBurst() { return 1; }
  152. int GetMaxBurst() { return 1; }
  153. float GetMinRestTime() { return 4.0; }
  154. float GetMaxRestTime() { return 4.0; }
  155. bool WeaponLOSCondition( const Vector &ownerPos, const Vector &targetPos, bool bSetConditions );
  156. int WeaponRangeAttack1Condition( float flDot, float flDist );
  157. void Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator );
  158. void StartGuiding( void );
  159. void StopGuiding( void );
  160. void ToggleGuiding( void );
  161. bool IsGuiding( void );
  162. void NotifyRocketDied( void );
  163. bool HasAnyAmmo( void );
  164. void SuppressGuiding( bool state = true );
  165. void CreateLaserPointer( void );
  166. void UpdateLaserPosition( Vector vecMuzzlePos = vec3_origin, Vector vecEndPos = vec3_origin );
  167. Vector GetLaserPosition( void );
  168. void StartLaserEffects( void );
  169. void StopLaserEffects( void );
  170. void UpdateLaserEffects( void );
  171. // NPC RPG users cheat and directly set the laser pointer's origin
  172. void UpdateNPCLaserPosition( const Vector &vecTarget );
  173. void SetNPCLaserPosition( const Vector &vecTarget );
  174. const Vector &GetNPCLaserPosition( void );
  175. int CapabilitiesGet( void ) { return bits_CAP_WEAPON_RANGE_ATTACK1; }
  176. virtual const Vector& GetBulletSpread( void )
  177. {
  178. static Vector cone = VECTOR_CONE_3DEGREES;
  179. return cone;
  180. }
  181. CBaseEntity *GetMissile( void ) { return m_hMissile; }
  182. DECLARE_ACTTABLE();
  183. DECLARE_DATADESC();
  184. protected:
  185. bool m_bInitialStateUpdate;
  186. bool m_bGuiding;
  187. bool m_bHideGuiding; //User to override the player's wish to guide under certain circumstances
  188. Vector m_vecNPCLaserDot;
  189. CHandle<CLaserDot> m_hLaserDot;
  190. CHandle<CMissile> m_hMissile;
  191. CHandle<CSprite> m_hLaserMuzzleSprite;
  192. CHandle<CBeam> m_hLaserBeam;
  193. };
  194. #endif // WEAPON_RPG_H