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.

352 lines
12 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef FUNC_TANK_H
  7. #define FUNC_TANK_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "triggers.h"
  12. #define SF_TANK_ACTIVE 0x0001
  13. #define SF_TANK_PLAYER 0x0002
  14. #define SF_TANK_HUMANS 0x0004
  15. #define SF_TANK_ALIENS 0x0008
  16. #define SF_TANK_LINEOFSIGHT 0x0010
  17. #define SF_TANK_CANCONTROL 0x0020
  18. #define SF_TANK_DAMAGE_KICK 0x0040 // Kick when take damage
  19. #define SF_TANK_AIM_AT_POS 0x0080 // Aim at a particular position
  20. #define SF_TANK_AIM_ASSISTANCE 0x0100
  21. #define SF_TANK_NPC 0x0200
  22. #define SF_TANK_NPC_CONTROLLABLE 0x0400 // 1024
  23. #define SF_TANK_NPC_SET_CONTROLLER 0x0800 // 2048
  24. #define SF_TANK_ALLOW_PLAYER_HITS 0x1000 // 4096 Allow friendly NPCs to fire upon enemies near the player
  25. #define SF_TANK_IGNORE_RANGE_IN_VIEWCONE 0x2000 // 8192 Don't use range as a factor in determining if something is in view cone
  26. #define SF_TANK_NOTSOLID 0x8000 // 32768
  27. #define SF_TANK_SOUNDON 0x10000 // FIXME: This is not really a spawnflag! It holds transient state!!!
  28. #define SF_TANK_HACKPLAYERHIT 0x20000 // 131072 Make this func_tank cheat and hit the player regularly
  29. #define FUNCTANK_DISTANCE_MAX 1200 // 100 ft.
  30. #define FUNCTANK_DISTANCE_MIN_TO_ENEMY 180
  31. #define FUNCTANK_FIREVOLUME 1000
  32. #define FUNCTANK_NPC_ROUTE_TIME 5.0f
  33. // Effect handling
  34. // If the func_tank has a chosen method of handling effects, use that
  35. // instead of the individual effect settings. (muzzleflash, sound, tracer, etc)
  36. enum FUNCTANK_EFFECT_HANDLING
  37. {
  38. EH_NONE, // Use the effect settings
  39. EH_AR2, // Use AR2 effects
  40. EH_COMBINE_CANNON // Large Combine cannon
  41. };
  42. enum TANKBULLET
  43. {
  44. TANK_BULLET_NONE = 0,
  45. TANK_BULLET_SMALL = 1,
  46. TANK_BULLET_MEDIUM = 2,
  47. TANK_BULLET_LARGE = 3,
  48. };
  49. #define MORTAR_BLAST_RADIUS 350
  50. // Custom damage
  51. // env_laser (duration is 0.5 rate of fire)
  52. // rockets
  53. // explosion?
  54. class CFuncTank : public CBaseEntity
  55. {
  56. DECLARE_CLASS( CFuncTank, CBaseEntity );
  57. public:
  58. CFuncTank();
  59. ~CFuncTank();
  60. void Spawn( void );
  61. void Activate( void );
  62. void Precache( void );
  63. bool CreateVPhysics( void );
  64. bool KeyValue( const char *szKeyName, const char *szValue );
  65. void UpdateOnRemove();
  66. void SetYawRate( float flYawRate ) { m_yawRate = flYawRate; }
  67. void SetPitchRate( float flPitchRate ) { m_pitchRate = flPitchRate; }
  68. int ObjectCaps( void )
  69. {
  70. return ( BaseClass::ObjectCaps() | FCAP_IMPULSE_USE | FCAP_USE_IN_RADIUS );
  71. }
  72. void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
  73. virtual void FuncTankPreThink() { return; }
  74. void Think( void );
  75. virtual void FuncTankPostThink() { return; }
  76. int GetAmmoCount( void ) { return m_iAmmoCount; }
  77. // NPC
  78. bool NPC_FindManPoint( Vector &vecPos );
  79. bool NPC_HasEnemy( void );
  80. void NPC_Fire( void );
  81. void NPC_InterruptRoute( void );
  82. void NPC_JustSawPlayer( CBaseEntity *pTarget );
  83. void NPC_SetInRoute( bool bInRoute ) { m_bNPCInRoute = bInRoute; }
  84. void NPC_SetIdleAngle( Vector vecIdle ) { m_vecNPCIdleTarget = vecIdle; }
  85. // LOS
  86. bool IsEntityInViewCone( CBaseEntity *pEntity );
  87. bool HasLOSTo( CBaseEntity *pEntity );
  88. // Controller
  89. CBaseCombatCharacter *GetController( void );
  90. bool StartControl( CBaseCombatCharacter *pController );
  91. void StopControl( void );
  92. Vector GetTargetPosition() { return m_vTargetPosition; }
  93. void SetTargetPosition( const Vector &vecPos ) { m_vTargetPosition = vecPos; }
  94. const float YawCenter() const { return m_yawCenter; }
  95. const float YawCenterWorld() const { return m_yawCenterWorld; }
  96. const float YawRange() const { return m_yawRange; }
  97. const float PitchCenter() const { return m_pitchCenter; }
  98. const float PitchCenterWorld() const { return m_pitchCenterWorld; }
  99. const float PitchRange() const { return m_pitchRange; }
  100. virtual void PhysicsSimulate( void );
  101. virtual void OnStartControlled() {}
  102. virtual void OnStopControlled() {}
  103. // SF Tests.
  104. inline bool IsControllable( void ) { return ( m_spawnflags & SF_TANK_CANCONTROL ) ? true : false; }
  105. inline bool IsActive( void ) { return ( m_spawnflags & SF_TANK_ACTIVE ) ? true : false; }
  106. inline bool IsNPCControllable( void ) { return ( m_spawnflags & SF_TANK_NPC_CONTROLLABLE ) ? true : false; }
  107. inline bool IsNPCSetController( void ) { return ( m_spawnflags & SF_TANK_NPC_SET_CONTROLLER ) ? true : false; }
  108. virtual void DoMuzzleFlash( void );
  109. virtual const char *GetTracerType( void );
  110. protected:
  111. virtual float GetShotSpeed() { return 0; }
  112. virtual Vector WorldBarrelPosition( void );
  113. void UpdateMatrix( void );
  114. float GetNextAttack() const { return m_flNextAttack; }
  115. virtual void SetNextAttack( float flWait ) { m_flNextAttack = flWait; }
  116. virtual void Fire( int bulletCount, const Vector &barrelEnd, const Vector &forward, CBaseEntity *pAttacker, bool bIgnoreSpread );
  117. void TankTrace( const Vector &vecStart, const Vector &vecForward, const Vector &vecSpread, trace_t &tr );
  118. int GetRandomBurst( void );
  119. float GetRandomFireTime( void );
  120. void CalcPlayerCrosshairTarget( Vector *pVecTarget );
  121. void CalcNPCEnemyTarget( Vector *pVecTarget );
  122. inline bool IsPlayerManned( void ) { return m_hController && m_hController->IsPlayer() && ( m_spawnflags & SF_TANK_PLAYER ); }
  123. inline bool IsNPCManned( void ) { return m_hController && m_hController->MyNPCPointer() && ( m_spawnflags & SF_TANK_NPC ); }
  124. private:
  125. void TrackTarget( void );
  126. int DrawDebugTextOverlays(void);
  127. void DrawDebugGeometryOverlays(void);
  128. virtual void FiringSequence( const Vector &barrelEnd, const Vector &forward, CBaseEntity *pAttacker );
  129. void StartRotSound( void );
  130. void StopRotSound( void );
  131. // Input handlers.
  132. void InputActivate( inputdata_t &inputdata );
  133. void InputDeactivate( inputdata_t &inputdata );
  134. void InputSetFireRate( inputdata_t &inputdata );
  135. void InputSetDamage( inputdata_t &inputdata );
  136. void InputSetTargetDir( inputdata_t &inputdata );
  137. void InputSetTargetPosition( inputdata_t &inputdata );
  138. void InputSetTargetEntityName( inputdata_t &inputdata );
  139. protected:
  140. virtual void InputSetTargetEntity( inputdata_t &inputdata );
  141. virtual void InputClearTargetEntity( inputdata_t &inputdata );
  142. private:
  143. void InputFindNPCToManTank( inputdata_t &inputdata );
  144. void InputStopFindingNPCs( inputdata_t &inputdata );
  145. void InputStartFindingNPCs( inputdata_t &inputdata );
  146. void InputForceNPCOff( inputdata_t &inputdata );
  147. void InputSetMaxRange( inputdata_t &inputdata );
  148. inline bool CanFire( void );
  149. bool InRange( float range );
  150. bool InRange2( float flRange2 );
  151. void TraceAttack( CBaseEntity *pAttacker, float flDamage, const Vector &vecDir, trace_t *ptr, int bitsDamageType);
  152. QAngle AimBarrelAt( const Vector &parentTarget );
  153. DECLARE_DATADESC();
  154. bool OnControls( CBaseEntity *pTest );
  155. bool HasController( void );
  156. CBaseEntity *FindTarget( string_t targetName, CBaseEntity *pActivator );
  157. // NPC
  158. void NPC_FindController( void );
  159. bool NPC_InRoute( void ) { return m_bNPCInRoute; }
  160. bool NPC_InterruptController( void );
  161. // Aim the tank at the player crosshair
  162. void AimBarrelAtPlayerCrosshair( QAngle *pAngles );
  163. // Aim the tank at the NPC's enemy
  164. void AimBarrelAtNPCEnemy( QAngle *pAngles );
  165. // Aim the tank at the func_tank's enemy
  166. void AimFuncTankAtTarget( void );
  167. // Returns true if the desired angles are out of range
  168. bool RotateTankToAngles( const QAngle &angles, float *pDistX = NULL, float *pDistY = NULL );
  169. // We lost our target!
  170. void LostTarget( void );
  171. // Purpose:
  172. void ComputeLeadingPosition( const Vector &vecShootPosition, CBaseEntity *pTarget, Vector *pLeadPosition );
  173. protected:
  174. virtual void ControllerPostFrame( void );
  175. virtual void TankActivate(void);
  176. virtual void TankDeactivate(void);
  177. float m_fireLast; // Last time I fired
  178. float m_fireRate; // How many rounds/second
  179. EHANDLE m_hTarget;
  180. TANKBULLET m_bulletType; // Bullet type
  181. int m_iBulletDamage; // 0 means use Bullet type's default damage
  182. int m_iBulletDamageVsPlayer; // Damage vs player. 0 means use m_iBulletDamage
  183. #ifdef HL2_EPISODIC
  184. string_t m_iszAmmoType; // The name of the ammodef that we use when we fire. Bullet damage still comes from keyvalues.
  185. int m_iAmmoType; // The cached index of the ammodef that we use when we fire.
  186. #else
  187. int m_iSmallAmmoType;
  188. int m_iMediumAmmoType;
  189. int m_iLargeAmmoType;
  190. #endif // HL2_EPISODIC
  191. int m_spread; // firing spread
  192. EntityMatrix m_parentMatrix;
  193. Vector m_sightOrigin; // Last sight of target
  194. EHANDLE m_hFuncTankTarget;
  195. int m_nBulletCount;
  196. private:
  197. // This is either the player manning the func_tank, or an NPC. The NPC is either manning the tank, or running
  198. // to the man point. If he's en-route, m_bNPCInRoute will be true.
  199. CHandle<CBaseCombatCharacter> m_hController;
  200. float m_flNextAttack;
  201. Vector m_vecControllerUsePos;
  202. float m_yawCenter; // "Center" yaw
  203. float m_yawCenterWorld; // "Center" yaw in world space
  204. float m_yawRate; // Max turn rate to track targets
  205. float m_yawRange; // Range of turning motion (one-sided: 30 is +/- 30 degress from center)
  206. // Zero is full rotation
  207. float m_yawTolerance; // Tolerance angle
  208. float m_pitchCenter; // "Center" pitch
  209. float m_pitchCenterWorld; // "Center" pitch in world space
  210. float m_pitchRate; // Max turn rate on pitch
  211. float m_pitchRange; // Range of pitch motion as above
  212. float m_pitchTolerance; // Tolerance angle
  213. float m_fireTime; // How much time has been used to fire the weapon so far.
  214. float m_lastSightTime;// Last time I saw target
  215. float m_persist; // Persistence of firing (how long do I shoot when I can't see)
  216. float m_persist2; // Secondary persistence of firing (randomly shooting when I can't see)
  217. float m_persist2burst;// How long secondary persistence burst lasts
  218. float m_minRange; // Minimum range to aim/track
  219. float m_maxRange; // Max range to aim/track
  220. float m_flMinRange2;
  221. float m_flMaxRange2;
  222. int m_iAmmoCount; // ammo
  223. Vector m_barrelPos; // Length of the freakin barrel
  224. float m_spriteScale; // Scale of any sprites we shoot
  225. string_t m_iszSpriteSmoke;
  226. string_t m_iszSpriteFlash;
  227. string_t m_iszMaster; // Master entity (game_team_master or multisource)
  228. string_t m_soundStartRotate;
  229. string_t m_soundStopRotate;
  230. string_t m_soundLoopRotate;
  231. float m_flPlayerGracePeriod;
  232. float m_flIgnoreGraceUpto;
  233. float m_flPlayerLockTimeBeforeFire;
  234. float m_flLastSawNonPlayer;
  235. string_t m_targetEntityName;
  236. Vector m_vTargetPosition;
  237. Vector m_vecNPCIdleTarget;
  238. // Used for when the gun is attached to another entity
  239. string_t m_iszBarrelAttachment;
  240. int m_nBarrelAttachment;
  241. string_t m_iszBaseAttachment;
  242. // Used when the gun is actually a part of the parent entity, and pose params aim it
  243. string_t m_iszYawPoseParam;
  244. string_t m_iszPitchPoseParam;
  245. float m_flYawPoseCenter;
  246. float m_flPitchPoseCenter;
  247. bool m_bUsePoseParameters;
  248. // Lead the target?
  249. bool m_bPerformLeading;
  250. float m_flStartLeadFactor;
  251. float m_flStartLeadFactorTime;
  252. float m_flNextLeadFactor;
  253. float m_flNextLeadFactorTime;
  254. COutputEvent m_OnFire;
  255. COutputEvent m_OnLoseTarget;
  256. COutputEvent m_OnAquireTarget;
  257. COutputEvent m_OnAmmoDepleted;
  258. COutputEvent m_OnGotController;
  259. COutputEvent m_OnLostController;
  260. COutputEvent m_OnGotPlayerController;
  261. COutputEvent m_OnLostPlayerController;
  262. COutputEvent m_OnReadyToFire;
  263. CHandle<CBaseTrigger> m_hControlVolume;
  264. string_t m_iszControlVolume;
  265. float m_flNextControllerSearch;
  266. bool m_bShouldFindNPCs;
  267. bool m_bNPCInRoute;
  268. string_t m_iszNPCManPoint;
  269. bool m_bReadyToFire;
  270. int m_iEffectHandling;
  271. };
  272. #endif // FUNC_TANK_H