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.

246 lines
7.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Engineer's Sentrygun
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef TF_OBJ_SENTRYGUN_H
  8. #define TF_OBJ_SENTRYGUN_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "tf_obj.h"
  13. #include "tf_projectile_rocket.h"
  14. class CTFPlayer;
  15. enum
  16. {
  17. SENTRY_LEVEL_1 = 0,
  18. // SENTRY_LEVEL_1_UPGRADING,
  19. SENTRY_LEVEL_2,
  20. // SENTRY_LEVEL_2_UPGRADING,
  21. SENTRY_LEVEL_3,
  22. };
  23. #define SF_SENTRY_UPGRADEABLE (LAST_SF_BASEOBJ<<1)
  24. #define SF_SENTRY_INFINITE_AMMO (LAST_SF_BASEOBJ<<2)
  25. #define SENTRYGUN_MAX_HEALTH 150
  26. #define SENTRYGUN_MINI_MAX_HEALTH 100
  27. #define SENTRY_MAX_RANGE 1100.0f // magic numbers are evil, people. adding this #define to demystify the value. (MSB 5/14/09)
  28. #define SENTRY_MAX_RANGE_SQRD 1210000.0f
  29. // ------------------------------------------------------------------------ //
  30. // Sentrygun object that's built by the player
  31. // ------------------------------------------------------------------------ //
  32. class CObjectSentrygun : public CBaseObject
  33. {
  34. DECLARE_CLASS( CObjectSentrygun, CBaseObject );
  35. public:
  36. DECLARE_SERVERCLASS();
  37. CObjectSentrygun();
  38. static CObjectSentrygun* Create(const Vector &vOrigin, const QAngle &vAngles);
  39. virtual void Spawn();
  40. virtual void FirstSpawn();
  41. virtual void Precache();
  42. virtual void OnGoActive( void );
  43. virtual int DrawDebugTextOverlays(void);
  44. virtual int OnTakeDamage( const CTakeDamageInfo &info );
  45. virtual void Killed( const CTakeDamageInfo &info );
  46. virtual void SetModel( const char *pModel );
  47. virtual bool StartBuilding( CBaseEntity *pBuilder );
  48. virtual void SetStartBuildingModel( void );
  49. virtual void StartPlacement( CTFPlayer *pPlayer );
  50. // Engineer hit me with a wrench
  51. virtual bool OnWrenchHit( CTFPlayer *pPlayer, CTFWrench *pWrench, Vector hitLoc );
  52. virtual void OnStartDisabled( void );
  53. virtual void OnEndDisabled( void );
  54. virtual int GetTracerAttachment( void );
  55. virtual bool IsUpgrading( void ) const { return m_iState == SENTRY_STATE_UPGRADING; }
  56. virtual float GetTimeSinceLastFired( void ) const { return m_timeSinceLastFired.GetElapsedTime(); }
  57. virtual const QAngle &GetTurretAngles( void ) const { return m_vecCurAngles; }
  58. virtual void SetBuildingSize( void );
  59. void ClearTarget( void ) { m_hEnemy = NULL; }
  60. CBaseEntity *GetTarget( void ) { return m_hEnemy.Get(); }
  61. void FireNextFrame( void ) { m_bFireNextFrame = true; }
  62. void FireRocketNextFrame( void ) {m_bFireRocketNextFrame = true; }
  63. void SetAutoAimTarget( CTFPlayer* pPlayer );
  64. int GetFireAttachment( void );
  65. void OnKilledEnemy(CBasePlayer* pVictim);
  66. virtual void MakeMiniBuilding( CTFPlayer* pPlayer );
  67. virtual void MakeCarriedObject( CTFPlayer *pCarrier );
  68. void MakeScaledBuilding( CTFPlayer* pPlayer );
  69. float GetPushMultiplier();
  70. void EmitSentrySound( const char* soundname );
  71. void EmitSentrySound( IRecipientFilter& filter, int iEntIndex, const char *soundname );
  72. CTFPlayer * GetAssistingTeammate( float maxAssistDuration = -1.0f ) const;
  73. virtual int GetBaseHealth( void ) { return SENTRYGUN_MAX_HEALTH; }
  74. void SetShieldLevel( int nLevel, float flDuration ) { m_nShieldLevel = nLevel; m_flShieldFadeTime = gpGlobals->curtime + flDuration; }
  75. virtual int GetMaxUpgradeLevel( void ) OVERRIDE;
  76. virtual int GetMiniBuildingStartingHealth( void ) OVERRIDE { return SENTRYGUN_MINI_MAX_HEALTH; }
  77. void RemoveAllAmmo();
  78. virtual int GetMaxHealthForCurrentLevel( void );
  79. virtual int GetUpgradeMetalRequired();
  80. bool IsScaledSentry() { return m_flScaledSentry != 1.0f; }
  81. virtual int GetShieldLevel() { return m_nShieldLevel; }
  82. virtual bool IsTruceValidForEnt( void ) const OVERRIDE { return true; }
  83. private:
  84. Vector GetEnemyAimPosition( CBaseEntity* pEnemy ) const;
  85. // Main think
  86. void SentryThink( void );
  87. // If the players hit us with a wrench, should we upgrade
  88. bool CanBeUpgraded( CTFPlayer *pPlayer );
  89. void StartUpgrading( void );
  90. void FinishUpgrading( void );
  91. // Target acquisition
  92. bool FindTarget( void );
  93. bool ValidTargetPlayer( CTFPlayer *pPlayer, const Vector &vecStart, const Vector &vecEnd );
  94. bool ValidTargetObject( CBaseObject *pObject, const Vector &vecStart, const Vector &vecEnd );
  95. bool ValidTargetBot( CBaseCombatCharacter *pBot, const Vector &vecStart, const Vector &vecEnd );
  96. void FoundTarget( CBaseEntity *pTarget, const Vector &vecSoundCenter, bool bNoSound=false );
  97. bool FInViewCone ( CBaseEntity *pEntity );
  98. int Range( CBaseEntity *pTarget );
  99. // Rotations
  100. void SentryRotate( void );
  101. bool MoveTurret( void );
  102. // Attack
  103. void Attack( void );
  104. void MakeTracer( const Vector &vecTracerSrc, const trace_t &tr, int iTracerType );
  105. bool Fire( void );
  106. bool FireRocket( void );
  107. virtual void ModifyFireBulletsDamage( CTakeDamageInfo* dmgInfo );
  108. int GetBaseTurnRate( void );
  109. virtual void MakeDisposableBuilding( CTFPlayer *pPlayer );
  110. CNetworkVar( int, m_iState );
  111. float m_flNextAttack;
  112. float m_flFireRate;
  113. IntervalTimer m_timeSinceLastFired;
  114. // Rotation
  115. int m_iRightBound;
  116. int m_iLeftBound;
  117. int m_iBaseTurnRate;
  118. bool m_bTurningRight;
  119. QAngle m_vecCurAngles;
  120. QAngle m_vecGoalAngles;
  121. float m_flTurnRate;
  122. // Ammo
  123. CNetworkVar( int, m_iAmmoShells );
  124. CNetworkVar( int, m_iMaxAmmoShells );
  125. CNetworkVar( int, m_iAmmoRockets );
  126. CNetworkVar( int, m_iMaxAmmoRockets );
  127. int m_iOldAmmoShells;
  128. int m_iOldAmmoRockets;
  129. int m_iAmmoType;
  130. float m_flNextRocketAttack;
  131. // Target player / object
  132. CNetworkHandle( CBaseEntity, m_hEnemy );
  133. bool m_bFireNextFrame;
  134. bool m_bFireRocketNextFrame;
  135. float m_flSentryRange;
  136. // Player control shield.
  137. CNetworkVar( bool, m_bPlayerControlled );
  138. CNetworkVar( uint32, m_nShieldLevel );
  139. float m_flShieldFadeTime;
  140. // PDQ Sentry
  141. CNetworkVar( bool, m_bPDQSentry );
  142. //cached attachment indeces
  143. int m_iAttachments[4];
  144. int m_iPitchPoseParameter;
  145. int m_iYawPoseParameter;
  146. float m_flLastAttackedTime;
  147. float m_flHeavyBulletResist;
  148. CNetworkHandle( CTFPlayer, m_hAutoAimTarget );
  149. float m_flAutoAimStartTime;
  150. // for achievement: ACHIEVEMENT_TF_ENGINEER_MANUAL_SENTRY_ABSORB_DMG
  151. int m_iLifetimeShieldedDamage;
  152. DECLARE_DATADESC();
  153. CountdownTimer m_inCombatThrottleTimer;
  154. void UpdateNavMeshCombatStatus( void );
  155. CHandle< CTFPlayer > m_lastTeammateWrenchHit; // which teammate last hit us with a wrench
  156. IntervalTimer m_lastTeammateWrenchHitTimer; // time since last wrench hit
  157. int m_iLastMuzzleAttachmentFired;
  158. float m_flScaledSentry;
  159. };
  160. // sentry rocket class just to give it a unique class name, so we can distinguish it from other rockets
  161. class CTFProjectile_SentryRocket : public CTFProjectile_Rocket
  162. {
  163. public:
  164. DECLARE_CLASS( CTFProjectile_SentryRocket, CTFProjectile_Rocket );
  165. DECLARE_NETWORKCLASS();
  166. CTFProjectile_SentryRocket();
  167. virtual int GetProjectileType() const OVERRIDE { return TF_PROJECTILE_SENTRY_ROCKET; }
  168. // Creation.
  169. static CTFProjectile_SentryRocket *Create( const Vector &vecOrigin, const QAngle &vecAngles, CBaseEntity *pOwner = NULL, CBaseEntity *pScorer = NULL );
  170. virtual void Spawn();
  171. };
  172. #endif // TF_OBJ_SENTRYGUN_H