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.

307 lines
8.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. #ifndef NPC_TURRET_FLOOR_H
  3. #define NPC_TURRET_FLOOR_H
  4. #ifdef _WIN32
  5. #pragma once
  6. #endif
  7. #include "ai_basenpc.h"
  8. #include "player_pickup.h"
  9. #include "particle_system.h"
  10. //Turret states
  11. enum turretState_e
  12. {
  13. TURRET_SEARCHING,
  14. TURRET_AUTO_SEARCHING,
  15. TURRET_ACTIVE,
  16. TURRET_SUPPRESSING,
  17. TURRET_DEPLOYING,
  18. TURRET_RETIRING,
  19. TURRET_TIPPED,
  20. TURRET_SELF_DESTRUCTING,
  21. TURRET_STATE_TOTAL
  22. };
  23. //Eye states
  24. enum eyeState_t
  25. {
  26. TURRET_EYE_SEE_TARGET, //Sees the target, bright and big
  27. TURRET_EYE_SEEKING_TARGET, //Looking for a target, blinking (bright)
  28. TURRET_EYE_DORMANT, //Not active
  29. TURRET_EYE_DEAD, //Completely invisible
  30. TURRET_EYE_DISABLED, //Turned off, must be reactivated before it'll deploy again (completely invisible)
  31. TURRET_EYE_ALARM, // On side, but warning player to pick it back up
  32. };
  33. //Spawnflags
  34. // BUG: These all stomp Base NPC spawnflags. Any Base NPC code called by this
  35. // this class may have undesired side effects due to these being set.
  36. #define SF_FLOOR_TURRET_AUTOACTIVATE 0x00000020
  37. #define SF_FLOOR_TURRET_STARTINACTIVE 0x00000040
  38. #define SF_FLOOR_TURRET_FASTRETIRE 0x00000080
  39. #define SF_FLOOR_TURRET_OUT_OF_AMMO 0x00000100
  40. #define SF_FLOOR_TURRET_CITIZEN 0x00000200 // Citizen modified turret
  41. class CTurretTipController;
  42. class CBeam;
  43. class CSprite;
  44. //-----------------------------------------------------------------------------
  45. // Purpose: Floor turret
  46. //-----------------------------------------------------------------------------
  47. class CNPC_FloorTurret : public CNPCBaseInteractive<CAI_BaseNPC>, public CDefaultPlayerPickupVPhysics
  48. {
  49. DECLARE_CLASS( CNPC_FloorTurret, CNPCBaseInteractive<CAI_BaseNPC> );
  50. public:
  51. CNPC_FloorTurret( void );
  52. virtual void Precache( void );
  53. virtual void Spawn( void );
  54. virtual void Activate( void );
  55. virtual bool CreateVPhysics( void );
  56. virtual void UpdateOnRemove( void );
  57. virtual int OnTakeDamage( const CTakeDamageInfo &info );
  58. virtual void PlayerPenetratingVPhysics( void );
  59. virtual int VPhysicsTakeDamage( const CTakeDamageInfo &info );
  60. virtual bool CanBecomeServerRagdoll( void ) { return false; }
  61. #ifdef HL2_EPISODIC
  62. // We don't want to be NPCSOLID because we'll collide with NPC clips
  63. virtual unsigned int PhysicsSolidMaskForEntity( void ) const { return MASK_SOLID; }
  64. #endif // HL2_EPISODIC
  65. // Player pickup
  66. virtual void OnPhysGunPickup( CBasePlayer *pPhysGunUser, PhysGunPickup_t reason );
  67. virtual void OnPhysGunDrop( CBasePlayer *pPhysGunUser, PhysGunDrop_t Reason );
  68. virtual bool HasPreferredCarryAnglesForPlayer( CBasePlayer *pPlayer );
  69. virtual QAngle PreferredCarryAngles( void );
  70. virtual bool OnAttemptPhysGunPickup( CBasePlayer *pPhysGunUser, PhysGunPickup_t reason );
  71. const char *GetTracerType( void ) { return "AR2Tracer"; }
  72. bool ShouldSavePhysics() { return true; }
  73. bool HandleInteraction( int interactionType, void *data, CBaseCombatCharacter *sourceEnt );
  74. // Think functions
  75. virtual void Retire( void );
  76. virtual void Deploy( void );
  77. virtual void ActiveThink( void );
  78. virtual void SearchThink( void );
  79. virtual void AutoSearchThink( void );
  80. virtual void TippedThink( void );
  81. virtual void InactiveThink( void );
  82. virtual void SuppressThink( void );
  83. virtual void DisabledThink( void );
  84. virtual void SelfDestructThink( void );
  85. virtual void BreakThink( void );
  86. virtual void HackFindEnemy( void );
  87. virtual float GetAttackDamageScale( CBaseEntity *pVictim );
  88. virtual Vector GetAttackSpread( CBaseCombatWeapon *pWeapon, CBaseEntity *pTarget );
  89. // Do we have a physics attacker?
  90. CBasePlayer *HasPhysicsAttacker( float dt );
  91. bool IsHeldByPhyscannon( ) { return VPhysicsGetObject() && (VPhysicsGetObject()->GetGameFlags() & FVPHYSICS_PLAYER_HELD); }
  92. // Use functions
  93. void ToggleUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
  94. int ObjectCaps()
  95. {
  96. return BaseClass::ObjectCaps() | FCAP_IMPULSE_USE;
  97. }
  98. void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
  99. {
  100. CBasePlayer *pPlayer = ToBasePlayer( pActivator );
  101. if ( pPlayer )
  102. {
  103. pPlayer->PickupObject( this, false );
  104. }
  105. }
  106. // Inputs
  107. void InputToggle( inputdata_t &inputdata );
  108. void InputEnable( inputdata_t &inputdata );
  109. void InputDisable( inputdata_t &inputdata );
  110. void InputDepleteAmmo( inputdata_t &inputdata );
  111. void InputRestoreAmmo( inputdata_t &inputdata );
  112. void InputSelfDestruct( inputdata_t &inputdata );
  113. virtual bool IsValidEnemy( CBaseEntity *pEnemy );
  114. bool CanBeAnEnemyOf( CBaseEntity *pEnemy );
  115. bool IsBeingCarriedByPlayer( void ) { return m_bCarriedByPlayer; }
  116. bool WasJustDroppedByPlayer( void );
  117. int BloodColor( void ) { return DONT_BLEED; }
  118. float MaxYawSpeed( void );
  119. virtual Class_T Classify( void );
  120. Vector EyePosition( void )
  121. {
  122. UpdateMuzzleMatrix();
  123. Vector vecOrigin;
  124. MatrixGetColumn( m_muzzleToWorld, 3, vecOrigin );
  125. Vector vecForward;
  126. MatrixGetColumn( m_muzzleToWorld, 0, vecForward );
  127. // Note: We back up into the model to avoid an edge case where the eyes clip out of the world and
  128. // cause problems with the PVS calculations -- jdw
  129. vecOrigin -= vecForward * 8.0f;
  130. return vecOrigin;
  131. }
  132. Vector EyeOffset( Activity nActivity ) { return Vector( 0, 0, 58 ); }
  133. // Restore the turret to working operation after falling over
  134. void ReturnToLife( void );
  135. int DrawDebugTextOverlays( void );
  136. // INPCInteractive Functions
  137. virtual bool CanInteractWith( CAI_BaseNPC *pUser ) { return false; } // Disabled for now (sjb)
  138. virtual bool HasBeenInteractedWith() { return m_bHackedByAlyx; }
  139. virtual void NotifyInteraction( CAI_BaseNPC *pUser )
  140. {
  141. // For now, turn green so we can tell who is hacked.
  142. SetRenderColor( 0, 255, 0 );
  143. m_bHackedByAlyx = true;
  144. }
  145. static float fMaxTipControllerVelocity;
  146. static float fMaxTipControllerAngularVelocity;
  147. protected:
  148. virtual bool PreThink( turretState_e state );
  149. virtual void Shoot( const Vector &vecSrc, const Vector &vecDirToEnemy, bool bStrict = false );
  150. virtual void SetEyeState( eyeState_t state );
  151. void Ping( void );
  152. void Toggle( void );
  153. void Enable( void );
  154. void Disable( void );
  155. void SpinUp( void );
  156. void SpinDown( void );
  157. virtual bool OnSide( void );
  158. bool IsCitizenTurret( void ) { return HasSpawnFlags( SF_FLOOR_TURRET_CITIZEN ); }
  159. bool UpdateFacing( void );
  160. void DryFire( void );
  161. void UpdateMuzzleMatrix();
  162. protected:
  163. matrix3x4_t m_muzzleToWorld;
  164. int m_muzzleToWorldTick;
  165. int m_iAmmoType;
  166. bool m_bAutoStart;
  167. bool m_bActive; //Denotes the turret is deployed and looking for targets
  168. bool m_bBlinkState;
  169. bool m_bEnabled; //Denotes whether the turret is able to deploy or not
  170. bool m_bNoAlarmSounds;
  171. bool m_bSelfDestructing; // Going to blow up
  172. float m_flDestructStartTime;
  173. float m_flShotTime;
  174. float m_flLastSight;
  175. float m_flThrashTime;
  176. float m_flPingTime;
  177. float m_flNextActivateSoundTime;
  178. bool m_bCarriedByPlayer;
  179. bool m_bUseCarryAngles;
  180. float m_flPlayerDropTime;
  181. int m_iKeySkin;
  182. CHandle<CBaseCombatCharacter> m_hLastNPCToKickMe; // Stores the last NPC who tried to knock me over
  183. float m_flKnockOverFailedTime; // Time at which we should tell the NPC that he failed to knock me over
  184. QAngle m_vecGoalAngles;
  185. int m_iEyeAttachment;
  186. int m_iMuzzleAttachment;
  187. eyeState_t m_iEyeState;
  188. CHandle<CSprite> m_hEyeGlow;
  189. CHandle<CBeam> m_hLaser;
  190. CHandle<CTurretTipController> m_pMotionController;
  191. CHandle<CParticleSystem> m_hFizzleEffect;
  192. Vector m_vecEnemyLKP;
  193. // physics influence
  194. CHandle<CBasePlayer> m_hPhysicsAttacker;
  195. float m_flLastPhysicsInfluenceTime;
  196. static const char *m_pShotSounds[];
  197. COutputEvent m_OnDeploy;
  198. COutputEvent m_OnRetire;
  199. COutputEvent m_OnTipped;
  200. COutputEvent m_OnPhysGunPickup;
  201. COutputEvent m_OnPhysGunDrop;
  202. bool m_bHackedByAlyx;
  203. HSOUNDSCRIPTHANDLE m_ShotSounds;
  204. DECLARE_DATADESC();
  205. DEFINE_CUSTOM_AI;
  206. };
  207. //
  208. // Tip controller
  209. //
  210. class CTurretTipController : public CPointEntity, public IMotionEvent
  211. {
  212. DECLARE_CLASS( CTurretTipController, CPointEntity );
  213. DECLARE_DATADESC();
  214. public:
  215. ~CTurretTipController( void );
  216. void Spawn( void );
  217. void Activate( void );
  218. void Enable( bool state = true );
  219. void Suspend( float time );
  220. float SuspendedTill( void );
  221. bool Enabled( void );
  222. static CTurretTipController *CreateTipController( CNPC_FloorTurret *pOwner )
  223. {
  224. if ( pOwner == NULL )
  225. return NULL;
  226. CTurretTipController *pController = (CTurretTipController *) Create( "floorturret_tipcontroller", pOwner->GetAbsOrigin(), pOwner->GetAbsAngles() );
  227. if ( pController != NULL )
  228. {
  229. pController->m_pParentTurret = pOwner;
  230. }
  231. return pController;
  232. }
  233. // IMotionEvent
  234. virtual simresult_e Simulate( IPhysicsMotionController *pController, IPhysicsObject *pObject, float deltaTime, Vector &linear, AngularImpulse &angular );
  235. private:
  236. bool m_bEnabled;
  237. float m_flSuspendTime;
  238. Vector m_worldGoalAxis;
  239. Vector m_localTestAxis;
  240. IPhysicsMotionController *m_pController;
  241. float m_angularLimit;
  242. CNPC_FloorTurret *m_pParentTurret;
  243. };
  244. #endif //#ifndef NPC_TURRET_FLOOR_H