Counter Strike : Global Offensive Source Code
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.

333 lines
11 KiB

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