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.

419 lines
12 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef C_CS_PLAYER_H
  7. #define C_CS_PLAYER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "cs_playeranimstate.h"
  12. #include "c_baseplayer.h"
  13. #include "cs_shareddefs.h"
  14. #include "weapon_csbase.h"
  15. #include "baseparticleentity.h"
  16. #include "beamdraw.h"
  17. class C_PhysicsProp;
  18. extern ConVar cl_disablefreezecam;
  19. class CAddonModel
  20. {
  21. public:
  22. CHandle<C_BaseAnimating> m_hEnt; // The model for the addon.
  23. int m_iAddon; // One of the ADDON_ bits telling which model this is.
  24. int m_iAttachmentPoint; // Which attachment point on the player model this guy is on.
  25. };
  26. class C_CSPlayer : public C_BasePlayer, public ICSPlayerAnimStateHelpers
  27. {
  28. public:
  29. DECLARE_CLASS( C_CSPlayer, C_BasePlayer );
  30. DECLARE_CLIENTCLASS();
  31. DECLARE_PREDICTABLE();
  32. DECLARE_INTERPOLATION();
  33. C_CSPlayer();
  34. ~C_CSPlayer();
  35. virtual void Simulate();
  36. bool HasDefuser() const;
  37. void GiveDefuser();
  38. void RemoveDefuser();
  39. bool HasNightVision() const;
  40. static C_CSPlayer* GetLocalCSPlayer();
  41. CSPlayerState State_Get() const;
  42. virtual float GetMinFOV() const;
  43. // Get how much $$$ this guy has.
  44. int GetAccount() const;
  45. // Returns one of the CS_CLASS_ enums.
  46. int PlayerClass() const;
  47. bool IsInBuyZone();
  48. bool CanShowTeamMenu() const; // Returns true if we're allowed to show the team menu right now.
  49. // Get the amount of armor the player has.
  50. int ArmorValue() const;
  51. bool HasHelmet() const;
  52. int GetCurrentAssaultSuitPrice();
  53. virtual const QAngle& EyeAngles();
  54. virtual const QAngle& GetRenderAngles();
  55. virtual void CalcObserverView( Vector& eyeOrigin, QAngle& eyeAngles, float& fov );
  56. virtual void GetRenderBounds( Vector& theMins, Vector& theMaxs );
  57. virtual void GetShadowRenderBounds( Vector &mins, Vector &maxs, ShadowType_t shadowType );
  58. virtual bool GetShadowCastDirection( Vector *pDirection, ShadowType_t shadowType ) const;
  59. virtual void VPhysicsUpdate( IPhysicsObject *pPhysics );
  60. // Get the ID target entity index. The ID target is the player that is behind our crosshairs, used to
  61. // display the player's name.
  62. int GetIDTarget() const;
  63. virtual void NotifyShouldTransmit( ShouldTransmitState_t state );
  64. virtual void ClientThink();
  65. virtual void OnDataChanged( DataUpdateType_t type );
  66. virtual void PostDataUpdate( DataUpdateType_t updateType );
  67. virtual bool Interpolate( float currentTime );
  68. virtual void UpdateStepSound( surfacedata_t *psurface, const Vector &vecOrigin, const Vector &vecVelocity );
  69. virtual surfacedata_t * GetFootstepSurface( const Vector &origin, const char *surfaceName );
  70. virtual void ValidateModelIndex( void );
  71. virtual int GetMaxHealth() const;
  72. bool Weapon_CanSwitchTo(C_BaseCombatWeapon *pWeapon);
  73. virtual void UpdateClientSideAnimation();
  74. virtual void ProcessMuzzleFlashEvent();
  75. virtual const Vector& GetRenderOrigin( void );
  76. bool CreateMove( float flInputSampleTime, CUserCmd *pCmd );
  77. CUtlVector< C_BaseParticleEntity* > m_SmokeGrenades;
  78. virtual bool ShouldDraw( void );
  79. virtual void BuildTransformations( CStudioHdr *pStudioHdr, Vector *pos, Quaternion q[], const matrix3x4_t& cameraTransform, int boneMask, CBoneBitList &boneComputed );
  80. virtual C_BaseAnimating * BecomeRagdollOnClient();
  81. virtual IRagdoll* GetRepresentativeRagdoll() const;
  82. void ImpactTrace( trace_t *pTrace, int iDamageType, const char *pCustomImpactName );
  83. // Have this player play the sounds from his view model's reload animation.
  84. void PlayReloadEffect();
  85. virtual void FireEvent( const Vector& origin, const QAngle& angles, int event, const char *options );
  86. bool HasC4( void );
  87. virtual void CreateLightEffects( void ) {} //no dimlight effects
  88. // Sometimes the server wants to update the client's cycle to get the two to run in sync (for proper hit detection)
  89. virtual void SetServerIntendedCycle( float intended ) { m_serverIntendedCycle = intended; }
  90. virtual float GetServerIntendedCycle( void ) { return m_serverIntendedCycle; }
  91. virtual bool ShouldReceiveProjectedTextures( int flags )
  92. {
  93. return ( this != C_BasePlayer::GetLocalPlayer() );
  94. }
  95. void ClearSoundEvents()
  96. {
  97. m_SoundEvents.RemoveAll();
  98. }
  99. //=============================================================================
  100. // HPE_BEGIN:
  101. // [menglish] Returns whether this player is dominating or is being dominated by the specified player
  102. //=============================================================================
  103. bool IsPlayerDominated( int iPlayerIndex );
  104. bool IsPlayerDominatingMe( int iPlayerIndex );
  105. virtual void CalcFreezeCamView( Vector& eyeOrigin, QAngle& eyeAngles, float& fov );
  106. virtual float GetDeathCamInterpolationTime();
  107. //=============================================================================
  108. // HPE_END
  109. //=============================================================================
  110. // Called by shared code.
  111. public:
  112. // ICSPlayerAnimState overrides.
  113. virtual CWeaponCSBase* CSAnim_GetActiveWeapon();
  114. virtual bool CSAnim_CanMove();
  115. void DoAnimationEvent( PlayerAnimEvent_t event, int nData = 0 );
  116. // Implemented in shared code.
  117. public:
  118. virtual float GetPlayerMaxSpeed();
  119. void GetBulletTypeParameters(
  120. int iBulletType,
  121. float &fPenetrationPower,
  122. float &flPenetrationDistance );
  123. void FireBullet(
  124. Vector vecSrc,
  125. const QAngle &shootAngles,
  126. float flDistance,
  127. int iPenetration,
  128. int iBulletType,
  129. int iDamage,
  130. float flRangeModifier,
  131. CBaseEntity *pevAttacker,
  132. bool bDoEffects,
  133. float xSpread, float ySpread );
  134. void KickBack(
  135. float up_base,
  136. float lateral_base,
  137. float up_modifier,
  138. float lateral_modifier,
  139. float up_max,
  140. float lateral_max,
  141. int direction_change );
  142. // Returns true if the player is allowed to move.
  143. bool CanMove() const;
  144. void OnJump( float fImpulse );
  145. void OnLand( float fVelocity );
  146. bool HasC4() const; // Is this player carrying a C4 bomb?
  147. bool IsVIP() const; // Is this player the VIP?
  148. virtual void SetAnimation( PLAYER_ANIM playerAnim );
  149. public:
  150. void UpdateIDTarget( void );
  151. void RemoveAddonModels( void );
  152. void UpdateMinModels( void );
  153. void SetActivity( Activity eActivity );
  154. Activity GetActivity( void ) const;
  155. ICSPlayerAnimState *GetPlayerAnimState() { return m_PlayerAnimState; }
  156. public:
  157. ICSPlayerAnimState *m_PlayerAnimState;
  158. // Used to control animation state.
  159. Activity m_Activity;
  160. // Predicted variables.
  161. CNetworkVar( bool, m_bResumeZoom );
  162. CNetworkVar( int , m_iLastZoom ); // after firing a shot, set the FOV to 90, and after showing the animation, bring the FOV back to last zoom level.
  163. CNetworkVar( CSPlayerState, m_iPlayerState ); // SupraFiend: this gives the current state in the joining process, the states are listed above
  164. CNetworkVar( bool, m_bIsDefusing ); // tracks whether this player is currently defusing a bomb
  165. CNetworkVar( bool, m_bInBombZone );
  166. CNetworkVar( bool, m_bInBuyZone );
  167. CNetworkVar( int, m_iThrowGrenadeCounter ); // used to trigger grenade throw animations.
  168. bool IsInHostageRescueZone( void );
  169. // This is a combination of the ADDON_ flags in cs_shareddefs.h.
  170. CNetworkVar( int, m_iAddonBits );
  171. // Clients don't know about holstered weapons, so we need to be told about them here
  172. CNetworkVar( int, m_iPrimaryAddon );
  173. CNetworkVar( int, m_iSecondaryAddon );
  174. // How long the progress bar takes to get to the end. If this is 0, then the progress bar
  175. // should not be drawn.
  176. CNetworkVar( int, m_iProgressBarDuration );
  177. // When the progress bar should start.
  178. CNetworkVar( float, m_flProgressBarStartTime );
  179. CNetworkVar( float, m_flStamina );
  180. CNetworkVar( int, m_iDirection ); // The current lateral kicking direction; 1 = right, 0 = left
  181. CNetworkVar( int, m_iShotsFired ); // number of shots fired recently
  182. CNetworkVar( bool, m_bNightVisionOn );
  183. CNetworkVar( bool, m_bHasNightVision );
  184. //=============================================================================
  185. // HPE_BEGIN:
  186. // [dwenger] Added for fun-fact support
  187. //=============================================================================
  188. //CNetworkVar( bool, m_bPickedUpDefuser );
  189. //CNetworkVar( bool, m_bDefusedWithPickedUpKit );
  190. //=============================================================================
  191. // HPE_END
  192. //=============================================================================
  193. CNetworkVar( float, m_flVelocityModifier );
  194. bool m_bDetected;
  195. EHANDLE m_hRagdoll;
  196. CWeaponCSBase* GetActiveCSWeapon() const;
  197. CWeaponCSBase* GetCSWeapon( CSWeaponID id ) const;
  198. virtual ShadowType_t ShadowCastType();
  199. #ifdef CS_SHIELD_ENABLED
  200. bool HasShield( void ) { return m_bHasShield; }
  201. bool IsShieldDrawn( void ) { return m_bShieldDrawn; }
  202. void SetShieldDrawnState( bool bState ) { m_bShieldDrawn = bState; }
  203. #else
  204. bool HasShield( void ) { return false; }
  205. bool IsShieldDrawn( void ) { return false; }
  206. void SetShieldDrawnState( bool bState ) {}
  207. #endif
  208. float m_flNightVisionAlpha;
  209. float m_flFlashAlpha;
  210. float m_flFlashBangTime;
  211. CNetworkVar( float, m_flFlashMaxAlpha );
  212. CNetworkVar( float, m_flFlashDuration );
  213. // Having the RecvProxy in the player allows us to keep the var private
  214. static void RecvProxy_CycleLatch( const CRecvProxyData *pData, void *pStruct, void *pOut );
  215. // Bots and hostages auto-duck during jumps
  216. bool m_duckUntilOnGround;
  217. Vector m_lastStandingPos; // used by the gamemovement code for finding ladders
  218. void SurpressLadderChecks( const Vector& pos, const Vector& normal );
  219. bool CanGrabLadder( const Vector& pos, const Vector& normal );
  220. //=============================================================================
  221. // HPE_BEGIN:
  222. //=============================================================================
  223. // [tj] checks if this player has another given player on their Steam friends list.
  224. bool HasPlayerAsFriend(C_CSPlayer* player);
  225. private:
  226. CountdownTimer m_ladderSurpressionTimer;
  227. Vector m_lastLadderNormal;
  228. Vector m_lastLadderPos;
  229. void UpdateRadar();
  230. void UpdateSoundEvents();
  231. void CreateAddonModel( int i );
  232. void UpdateAddonModels();
  233. void PushawayThink();
  234. int m_iAccount;
  235. bool m_bHasHelmet;
  236. int m_iClass;
  237. int m_ArmorValue;
  238. QAngle m_angEyeAngles;
  239. bool m_bHasDefuser;
  240. bool m_bInHostageRescueZone;
  241. float m_fNextThinkPushAway;
  242. bool m_bPlayingFreezeCamSound;
  243. #ifdef CS_SHIELD_ENABLED
  244. bool m_bHasShield;
  245. bool m_bShieldDrawn;
  246. #endif
  247. Vector m_vecRagdollVelocity;
  248. CInterpolatedVar< QAngle > m_iv_angEyeAngles;
  249. // ID Target
  250. int m_iIDEntIndex;
  251. CountdownTimer m_delayTargetIDTimer;
  252. // Show the ID target after the cursor leaves the entity
  253. int m_iOldIDEntIndex;
  254. CountdownTimer m_holdTargetIDTimer;
  255. void ReleaseFlashlight( void );
  256. Beam_t *m_pFlashlightBeam;
  257. class CCSSoundEvent
  258. {
  259. public:
  260. string_t m_SoundName;
  261. float m_flEventTime; // Play the event when gpGlobals->curtime goes past this.
  262. };
  263. CUtlLinkedList<CCSSoundEvent,int> m_SoundEvents;
  264. // This is the list of addons hanging off the guy (grenades, C4, nightvision, etc).
  265. CUtlLinkedList<CAddonModel, int> m_AddonModels;
  266. int m_iLastAddonBits;
  267. int m_iLastPrimaryAddon;
  268. int m_iLastSecondaryAddon;
  269. int m_cycleLatch; // server periodically updates this to fix up our anims, here it is a 4 bit fixed point
  270. float m_serverIntendedCycle; // server periodically updates this to fix up our anims, here it is the float we want, or -1 for no override
  271. //=============================================================================
  272. // HPE_BEGIN:
  273. // [tj] Network variables that track who are dominating and being dominated by
  274. //=============================================================================
  275. CNetworkArray( bool, m_bPlayerDominated, MAX_PLAYERS+1 ); // array of state per other player whether player is dominating other players
  276. CNetworkArray( bool, m_bPlayerDominatingMe, MAX_PLAYERS+1 ); // array of state per other player whether other players are dominating this player
  277. //=============================================================================
  278. // HPE_END
  279. //=============================================================================
  280. C_CSPlayer( const C_CSPlayer & );
  281. };
  282. C_CSPlayer* GetLocalOrInEyeCSPlayer( void );
  283. inline C_CSPlayer *ToCSPlayer( CBaseEntity *pEntity )
  284. {
  285. if ( !pEntity || !pEntity->IsPlayer() )
  286. return NULL;
  287. return dynamic_cast<C_CSPlayer*>( pEntity );
  288. }
  289. namespace vgui
  290. {
  291. class IImage;
  292. }
  293. vgui::IImage* GetDefaultAvatarImage( C_BasePlayer *pPlayer );
  294. #endif // C_CS_PLAYER_H