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.

1017 lines
34 KiB

  1. //===== Copyright (c) Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose: Client-side CBasePlayer.
  4. //
  5. // - Manages the player's flashlight effect.
  6. //
  7. //==================================================================//
  8. #ifndef C_BASEPLAYER_H
  9. #define C_BASEPLAYER_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "c_playerlocaldata.h"
  14. #include "c_basecombatcharacter.h"
  15. #include "PlayerState.h"
  16. #include "usercmd.h"
  17. #include "shareddefs.h"
  18. #include "timedevent.h"
  19. #include "smartptr.h"
  20. #include "fx_water.h"
  21. #include "hintsystem.h"
  22. #include "SoundEmitterSystem/isoundemittersystembase.h"
  23. #include "c_env_fog_controller.h"
  24. #include "c_postprocesscontroller.h"
  25. #include "c_colorcorrection.h"
  26. #include "usermessages.h"
  27. class C_BaseCombatWeapon;
  28. class C_BaseViewModel;
  29. class C_FuncLadder;
  30. enum CrossPlayPlatform_t;
  31. class C_WearableItem;
  32. extern int g_nKillCamMode;
  33. extern int g_nKillCamTarget1;
  34. extern int g_nKillCamTarget2;
  35. class C_CommandContext
  36. {
  37. public:
  38. bool needsprocessing;
  39. CUserCmd cmd;
  40. int command_number;
  41. };
  42. class C_PredictionError
  43. {
  44. public:
  45. float time;
  46. Vector error;
  47. };
  48. #define CHASE_CAM_DISTANCE 76.0f
  49. #define WALL_OFFSET 6.0f
  50. enum PlayerRenderMode_t
  51. {
  52. PLAYER_RENDER_NONE = 0,
  53. PLAYER_RENDER_FIRSTPERSON,
  54. PLAYER_RENDER_THIRDPERSON,
  55. };
  56. bool IsInFreezeCam( void );
  57. //-----------------------------------------------------------------------------
  58. // Purpose: Base Player class
  59. //-----------------------------------------------------------------------------
  60. class C_BasePlayer : public C_BaseCombatCharacter
  61. {
  62. public:
  63. DECLARE_CLASS( C_BasePlayer, C_BaseCombatCharacter );
  64. DECLARE_CLIENTCLASS();
  65. DECLARE_PREDICTABLE();
  66. DECLARE_INTERPOLATION();
  67. C_BasePlayer();
  68. virtual ~C_BasePlayer();
  69. virtual void Spawn( void );
  70. virtual void SharedSpawn(); // Shared between client and server.
  71. virtual bool GetSteamID( CSteamID *pID );
  72. virtual void UpdateOnRemove( void );
  73. Class_T Classify( void ) { return CLASS_PLAYER; }
  74. // IClientEntity overrides.
  75. virtual void OnPreDataChanged( DataUpdateType_t updateType );
  76. virtual void OnDataChanged( DataUpdateType_t updateType );
  77. virtual void PreDataUpdate( DataUpdateType_t updateType );
  78. virtual void PostDataUpdate( DataUpdateType_t updateType );
  79. virtual void OnTimeJump();
  80. static void OnTimeJumpAllPlayers();
  81. virtual void ClientThink( ) OVERRIDE;
  82. virtual void ReceiveMessage( int classID, bf_read &msg );
  83. virtual void OnRestore();
  84. virtual void MakeTracer( const Vector &vecTracerSrc, const trace_t &tr, int iTracerType );
  85. virtual void GetToolRecordingState( KeyValues *msg );
  86. virtual float GetPlayerMaxSpeed();
  87. #ifdef PORTAL2
  88. bool ClearUseEntity();
  89. #endif
  90. void SetAnimationExtension( const char *pExtension );
  91. C_BaseViewModel *GetViewModel( int viewmodelindex = 0 ) const;
  92. C_BaseCombatWeapon *GetActiveWeapon( void ) const;
  93. const char *GetTracerType( void );
  94. // View model prediction setup
  95. virtual void CalcView( Vector &eyeOrigin, QAngle &eyeAngles, float &zNear, float &zFar, float &fov );
  96. virtual void CalcViewModelView( const Vector& eyeOrigin, const QAngle& eyeAngles);
  97. // Handle view smoothing when going up stairs
  98. void SmoothViewOnStairs( Vector& eyeOrigin );
  99. virtual float CalcRoll (const QAngle& angles, const Vector& velocity, float rollangle, float rollspeed);
  100. void CalcViewRoll( QAngle& eyeAngles );
  101. virtual void CalcViewBob( Vector& eyeOrigin );
  102. virtual void CalcAddViewmodelCameraAnimation( Vector& eyeOrigin, QAngle& eyeAngles );
  103. void CreateWaterEffects( void );
  104. virtual void SetPlayerUnderwater( bool state );
  105. void UpdateUnderwaterState( void );
  106. bool IsPlayerUnderwater( void ) { return m_bPlayerUnderwater; }
  107. virtual C_BaseCombatCharacter *ActivePlayerCombatCharacter( void ) { return this; }
  108. virtual Vector Weapon_ShootPosition();
  109. virtual bool Weapon_CanUse( C_BaseCombatWeapon *pWeapon );
  110. virtual void Weapon_DropPrimary( void ) {}
  111. virtual Vector GetAutoaimVector( float flScale );
  112. void SetSuitUpdate(char *name, int fgroup, int iNoRepeat);
  113. // Input handling
  114. virtual bool CreateMove( float flInputSampleTime, CUserCmd *pCmd );
  115. virtual void AvoidPhysicsProps( CUserCmd *pCmd );
  116. virtual void PlayerUse( void );
  117. CBaseEntity *FindUseEntity( void );
  118. virtual bool IsUseableEntity( CBaseEntity *pEntity, unsigned int requiredCaps );
  119. #ifdef PORTAL2
  120. virtual bool CanPickupObject( CBaseEntity *pObject, float massLimit, float sizeLimit );
  121. virtual float GetHeldObjectMass( IPhysicsObject *pHeldObject );
  122. virtual void ForceDropOfCarriedPhysObjects(){};
  123. #endif
  124. // Data handlers
  125. virtual bool IsPlayer( void ) const { return true; }
  126. virtual int GetHealth() const { return m_iHealth; }
  127. int GetBonusProgress() const { return m_iBonusProgress; }
  128. int GetBonusChallenge() const { return m_iBonusChallenge; }
  129. // observer mode
  130. virtual int GetObserverMode() const;
  131. virtual CBaseEntity *GetObserverTarget() const;
  132. virtual void SetObserverTarget( EHANDLE hObserverTarget );
  133. bool AudioStateIsUnderwater( Vector vecMainViewOrigin );
  134. bool IsObserver() const;
  135. bool IsCameraMan() const;
  136. bool IsActiveCameraMan() const { return m_bActiveCameraMan; }
  137. bool IsHLTV() const;
  138. #if defined( REPLAY_ENABLED )
  139. bool IsReplay() const;
  140. #endif
  141. void ResetObserverMode();
  142. bool IsBot( void ) const;
  143. // Eye position..
  144. virtual Vector EyePosition();
  145. virtual const QAngle &EyeAngles(); // Direction of eyes
  146. void EyePositionAndVectors( Vector *pPosition, Vector *pForward, Vector *pRight, Vector *pUp );
  147. virtual const QAngle &LocalEyeAngles(); // Direction of eyes
  148. // This can be overridden to return something other than m_pRagdoll if the mod uses separate
  149. // entities for ragdolls.
  150. virtual IRagdoll* GetRepresentativeRagdoll() const;
  151. // override the initial bone position for ragdolls
  152. virtual void GetRagdollInitBoneArrays( matrix3x4a_t *pDeltaBones0, matrix3x4a_t *pDeltaBones1, matrix3x4a_t *pCurrentBones, float boneDt );
  153. // Returns eye vectors
  154. void EyeVectors( Vector *pForward, Vector *pRight = NULL, Vector *pUp = NULL );
  155. void CacheVehicleView( void ); // Calculate and cache the position of the player in the vehicle
  156. bool IsSuitEquipped( void ) { return m_Local.m_bWearingSuit; };
  157. // Team handlers
  158. virtual void TeamChange( int iNewTeam );
  159. // Flashlight
  160. void Flashlight( void );
  161. void UpdateFlashlight( void );
  162. void TurnOffFlashlight( void ); // TERROR
  163. virtual const char *GetFlashlightTextureName( void ) const { return NULL; } // TERROR
  164. virtual float GetFlashlightFOV( void ) const { return 0.0f; } // TERROR
  165. virtual float GetFlashlightFarZ( void ) const { return 0.0f; } // TERROR
  166. virtual float GetFlashlightLinearAtten( void ) const { return 0.0f; } // TERROR
  167. virtual bool CastsFlashlightShadows( void ) const { return true; } // TERROR
  168. virtual void GetFlashlightOffset( const Vector &vecForward, const Vector &vecRight, const Vector &vecUp, Vector *pVecOffset ) const;
  169. Vector m_vecFlashlightOrigin;
  170. Vector m_vecFlashlightForward;
  171. Vector m_vecFlashlightUp;
  172. Vector m_vecFlashlightRight;
  173. // Weapon selection code
  174. virtual bool IsAllowedToSwitchWeapons( void ) { return !IsObserver(); }
  175. virtual C_BaseCombatWeapon *GetActiveWeaponForSelection( void );
  176. // Returns the view model if this is the local player. If you're in third person or
  177. // this is a remote player, it returns the active weapon
  178. // (and its appropriate left/right weapon if this is TF2).
  179. virtual C_BaseAnimating* GetRenderedWeaponModel();
  180. virtual bool IsOverridingViewmodel( void ) { return false; };
  181. virtual int DrawOverriddenViewmodel( C_BaseViewModel *pViewmodel, int flags, const RenderableInstance_t &instance ) { return 0; };
  182. virtual float GetDefaultAnimSpeed( void ) { return 1.0; }
  183. void SetMaxSpeed( float flMaxSpeed ) { m_flMaxspeed = flMaxSpeed; }
  184. float MaxSpeed() const { return m_flMaxspeed; }
  185. // Should this object cast shadows?
  186. virtual ShadowType_t ShadowCastType() { return SHADOWS_NONE; }
  187. virtual bool ShouldReceiveProjectedTextures( int flags )
  188. {
  189. return false;
  190. }
  191. // Makes sure s_pLocalPlayer is properly initialized
  192. void CheckForLocalPlayer( int nSplitScreenSlot );
  193. void SetAsLocalPlayer();
  194. /// Is the passed in player one of the split screen users
  195. static bool IsLocalPlayer( const C_BaseEntity *pl );
  196. /// is this player a local player ( call when you have already verified that your pointer really is a C_BasePlayer )
  197. inline bool IsLocalPlayer( void ) const;
  198. // Global/static methods
  199. virtual void ThirdPersonSwitch( bool bThirdperson );
  200. bool ShouldDrawLocalPlayer();
  201. static C_BasePlayer *GetLocalPlayer( int nSlot = -1 );
  202. static void SetRemoteSplitScreenPlayerViewsAreLocalPlayer( bool bSet ); //if true, calls to GetLocalPlayer() will return a remote splitscreen player when applicable.
  203. static bool HasAnyLocalPlayer();
  204. static int GetSplitScreenSlotForPlayer( C_BaseEntity *pl );
  205. void AddSplitScreenPlayer( C_BasePlayer *pOther );
  206. void RemoveSplitScreenPlayer( C_BasePlayer *pOther );
  207. CUtlVector< CHandle< C_BasePlayer > >& GetSplitScreenPlayers( void );
  208. void AddPictureInPicturePlayer( C_BasePlayer *pOther );
  209. void RemovePictureInPicturePlayer( C_BasePlayer *pOther );
  210. CUtlVector< CHandle< C_BasePlayer > >& GetSplitScreenAndPictureInPicturePlayers( void );
  211. CUtlVector< CHandle< C_BasePlayer > >& GetPictureInPicturePlayers( void );
  212. bool IsSplitScreenPartner( C_BasePlayer *pPlayer );
  213. bool IsSplitScreenPlayer() const;
  214. int GetSplitScreenPlayerSlot();
  215. bool HasAttachedSplitScreenPlayers() const;
  216. virtual IClientModelRenderable* GetClientModelRenderable();
  217. CrossPlayPlatform_t GetCrossPlayPlatform( void ) const;
  218. virtual bool PreRender( int nSplitScreenPlayerSlot );
  219. int GetUserID( void ) const;
  220. virtual bool CanSetSoundMixer( void );
  221. // return the entity used for soundscape radius checks
  222. virtual C_BaseEntity *GetSoundscapeListener();
  223. virtual int GetLastKillerIndex() { return 0; }
  224. #if !defined( NO_ENTITY_PREDICTION )
  225. void AddToPlayerSimulationList( C_BaseEntity *other );
  226. void SimulatePlayerSimulatedEntities( void );
  227. void RemoveFromPlayerSimulationList( C_BaseEntity *ent );
  228. void ClearPlayerSimulationList( void );
  229. #endif
  230. virtual void PhysicsSimulate( void );
  231. virtual void VPhysicsShadowUpdate( IPhysicsObject *pPhysics );
  232. virtual bool IsFollowingPhysics( void ) { return false; }
  233. bool IsRideablePhysics( IPhysicsObject *pPhysics );
  234. IPhysicsObject *GetGroundVPhysics();
  235. void UpdatePhysicsShadowToCurrentPosition( void );
  236. void UpdateVPhysicsPosition( const Vector &position, const Vector &velocity, float secondsToArrival );
  237. void UpdatePhysicsShadowToPosition( const Vector &vecAbsOrigin );
  238. void PostThinkVPhysics( void );
  239. void SetTouchedPhysics( bool bTouch );
  240. bool TouchedPhysics( void );
  241. void SetPhysicsFlag( int nFlag, bool bSet );
  242. bool HasPhysicsFlag( unsigned int flag ) { return (m_afPhysicsFlags & flag) != 0; }
  243. void SetVCollisionState( const Vector &vecAbsOrigin, const Vector &vecAbsVelocity, int collisionState );
  244. virtual unsigned int PhysicsSolidMaskForEntity( void ) const { return MASK_PLAYERSOLID; }
  245. void PhysicsTouchTriggers( const Vector *pPrevAbsOrigin = NULL ); // prediction calls it on C_BasePlayer object
  246. // Prediction stuff
  247. virtual bool ShouldPredict( void );
  248. virtual C_BasePlayer *GetPredictionOwner( void );
  249. virtual void PreThink( void );
  250. virtual void PostThink( void );
  251. virtual void ItemPreFrame( void );
  252. virtual void ItemPostFrame( void );
  253. virtual void AbortReload( void );
  254. virtual void SelectLastItem(void);
  255. virtual void Weapon_SetLast( C_BaseCombatWeapon *pWeapon );
  256. virtual bool Weapon_ShouldSetLast( C_BaseCombatWeapon *pOldWeapon, C_BaseCombatWeapon *pNewWeapon ) { return true; }
  257. virtual bool Weapon_ShouldSelectItem( C_BaseCombatWeapon *pWeapon );
  258. virtual void Weapon_Drop( C_BaseCombatWeapon *pWeapon, const Vector *pvecTarget /* = NULL */, const Vector *pVelocity /* = NULL */ );
  259. virtual bool Weapon_Switch( C_BaseCombatWeapon *pWeapon, int viewmodelindex = 0 ); // Switch to given weapon if has ammo (false if failed)
  260. virtual C_BaseCombatWeapon *GetLastWeapon( void ) { return m_hLastWeapon.Get(); }
  261. void ResetAutoaim( void );
  262. virtual void SelectItem( const char *pstr, int iSubType = 0 );
  263. virtual void UpdateClientData( void );
  264. virtual float GetFOV( void ) const;
  265. virtual int GetDefaultFOV( void ) const;
  266. virtual bool IsZoomed( void ) { return false; }
  267. bool SetFOV( CBaseEntity *pRequester, int FOV, float zoomRate = 0.0f, int iZoomStart = 0 );
  268. void ClearZoomOwner( void );
  269. float GetFOVDistanceAdjustFactor();
  270. virtual void ViewPunch( const QAngle &angleOffset );
  271. void ViewPunchReset( float tolerance = 0 );
  272. void UpdateButtonState( int nUserCmdButtonMask );
  273. int GetImpulse( void ) const;
  274. virtual bool Simulate();
  275. virtual bool ShouldInterpolate();
  276. virtual bool ShouldDraw();
  277. virtual int DrawModel( int flags, const RenderableInstance_t &instance );
  278. virtual bool ShouldSuppressForSplitScreenPlayer( int nSlot );
  279. virtual const char * GetPlayerModelName( void );
  280. // Called when not in tactical mode. Allows view to be overriden for things like driving a tank.
  281. virtual void OverrideView( CViewSetup *pSetup );
  282. C_BaseEntity *GetViewEntity( void ) const { return m_hViewEntity; }
  283. // returns the player name
  284. const char * GetPlayerName();
  285. virtual const Vector GetPlayerMins( void ) const; // uses local player
  286. virtual const Vector GetPlayerMaxs( void ) const; // uses local player
  287. virtual void UpdateCollisionBounds( void );
  288. // Is the player dead?
  289. bool IsPlayerDead();
  290. bool IsPoisoned( void ) { return m_Local.m_bPoisoned; }
  291. virtual C_BaseEntity* GetUseEntity( void ) const;
  292. virtual C_BaseEntity* GetPotentialUseEntity( void ) const;
  293. // Vehicles...
  294. IClientVehicle *GetVehicle();
  295. const IClientVehicle *GetVehicle() const;
  296. bool IsInAVehicle() const { return ( NULL != m_hVehicle.Get() ) ? true : false; }
  297. virtual void SetVehicleRole( int nRole );
  298. void LeaveVehicle( void );
  299. bool UsingStandardWeaponsInVehicle( void );
  300. virtual void SetAnimation( PLAYER_ANIM playerAnim );
  301. float GetTimeBase( void ) const;
  302. float GetFinalPredictedTime() const;
  303. float PredictedServerTime() const;
  304. float m_fLastUpdateServerTime;
  305. int m_nLastUpdateTickBase;
  306. int m_nLastUpdateServerTickCount;
  307. bool IsInVGuiInputMode() const;
  308. bool IsInViewModelVGuiInputMode() const;
  309. C_CommandContext *GetCommandContext();
  310. // Get the command number associated with the current usercmd we're running (if in predicted code).
  311. int CurrentCommandNumber() const;
  312. const CUserCmd *GetCurrentUserCommand() const;
  313. CUserCmd const *GetLastUserCommand( void );
  314. virtual QAngle GetViewPunchAngle();
  315. void SetViewPunchAngle( const QAngle &angle );
  316. virtual QAngle GetAimPunchAngle();
  317. void SetAimPunchAngle( const QAngle &angle );
  318. void SetAimPunchAngleVelocity( const QAngle &punchAngleVelocity );
  319. // TrackIR
  320. const Vector& GetEyeOffset() const;
  321. void SetEyeOffset( const Vector& v );
  322. const QAngle & GetEyeAngleOffset() const;
  323. void SetEyeAngleOffset( const QAngle & qa );
  324. // TrackIR
  325. const Vector & GetAimDirection() const;
  326. void SetAimDirection( const Vector & v );
  327. bool IsCoach( void ) const;
  328. int GetCoachingTeam( void ) const;
  329. // This supercedes GetTeamNumber(). It returns the same value if the user is a T or CT.
  330. // If the player is a coach it returns coaching team.
  331. int GetAssociatedTeamNumber( void ) const;
  332. // Is TEAM_SPECTATOR and is not a coach.
  333. // Use this when you want true omniscient spectators and not team coaches.
  334. bool IsSpectator( void ) const;
  335. // Returns the eye or pointer angle plus the punch angle.
  336. QAngle GetFinalAimAngle();
  337. float GetWaterJumpTime() const;
  338. void SetWaterJumpTime( float flWaterJumpTime );
  339. float GetSwimSoundTime( void ) const;
  340. void SetSwimSoundTime( float flSwimSoundTime );
  341. float GetNextDecalTime( void ) const { return m_flNextDecalTime; }
  342. float GetDeathTime( void ) { return m_flDeathTime; }
  343. float GetForceTeamTime( void ) { return m_fForceTeam; }
  344. void SetPreviouslyPredictedOrigin( const Vector &vecAbsOrigin );
  345. const Vector &GetPreviouslyPredictedOrigin() const;
  346. // CS wants to allow small FOVs for zoomed-in AWPs.
  347. virtual float GetMinFOV() const;
  348. virtual void DoMuzzleFlash();
  349. virtual void UpdateStepSound( surfacedata_t *psurface, const Vector &vecOrigin, const Vector &vecVelocity );
  350. virtual void PlayStepSound( Vector &vecOrigin, surfacedata_t *psurface, float fvol, bool force );
  351. virtual surfacedata_t * GetFootstepSurface( const Vector &origin, const char *surfaceName );
  352. virtual void GetStepSoundVelocities( float *velwalk, float *velrun );
  353. virtual void SetStepSoundTime( stepsoundtimes_t iStepSoundTime, bool bWalking );
  354. // Called by prediction when it detects a prediction correction.
  355. // vDelta is the line from where the client had predicted the player to at the usercmd in question,
  356. // to where the server says the client should be at said usercmd.
  357. void NotePredictionError( const Vector &vDelta );
  358. // Called by the renderer to apply the prediction error smoothing.
  359. void GetPredictionErrorSmoothingVector( Vector &vOffset );
  360. virtual void ExitLadder() {}
  361. surfacedata_t *GetLadderSurface( const Vector &origin );
  362. void ForceButtons( int nButtons );
  363. void UnforceButtons( int nButtons );
  364. void SetLadderNormal( Vector vecLadderNormal ) { m_vecLadderNormal = vecLadderNormal; }
  365. const Vector &GetLadderNormal( void ) const { return m_vecLadderNormal; }
  366. int GetLadderSurfaceProps( void ) const { return m_ladderSurfaceProps; }
  367. // Hints
  368. virtual CHintSystem *Hints( void ) { return NULL; }
  369. bool ShouldShowHints( void ) { return Hints() ? Hints()->ShouldShowHints() : false; }
  370. bool HintMessage( int hint, bool bForce = false, bool bOnlyIfClear = false ) { return Hints() ? Hints()->HintMessage( hint, bForce, bOnlyIfClear ) : false; }
  371. void HintMessage( const char *pMessage ) { if (Hints()) Hints()->HintMessage( pMessage ); }
  372. virtual IMaterial *GetHeadLabelMaterial( void );
  373. virtual void UpdateSpeechVOIP( bool bVoice );
  374. virtual bool ShouldShowVOIPIcon() const;
  375. virtual const char *GetVOIPParticleEffectName() const { return /*TODO: make real effect*/"impact_physics_dust"; }
  376. virtual CNewParticleEffect *GetVOIPParticleEffect( void );
  377. virtual bool IsPlayerTalkingOverVOIP() { return m_bPlayerIsTalkingOverVOIP; }
  378. bool m_bPlayerIsTalkingOverVOIP;
  379. void SetLastKillerDamageAndFreezeframe( int nLastKillerDamageTaken, int nLastKillerHitsTaken, int nLastKillerDamageGiven, int nLastKillerHitsGiven );
  380. // Fog
  381. virtual fogparams_t *GetFogParams( void ) { return &m_CurrentFog; }
  382. void FogControllerChanged( bool bSnap );
  383. void UpdateFogController( void );
  384. void UpdateFogBlend( void );
  385. C_PostProcessController* GetActivePostProcessController() const;
  386. C_ColorCorrection* GetActiveColorCorrection() const;
  387. void IncrementEFNoInterpParity();
  388. int GetEFNoInterpParity() const;
  389. float GetFOVTime( void ){ return m_flFOVTime; }
  390. virtual PlayerRenderMode_t GetPlayerRenderMode( int nSlot );
  391. virtual void OnAchievementAchieved( int iAchievement ) {}
  392. bool ShouldAnnounceAchievement( void ){ return m_flNextAchievementAnnounceTime < gpGlobals->curtime; }
  393. void SetNextAchievementAnnounceTime( float flTime ){ m_flNextAchievementAnnounceTime = flTime; }
  394. virtual void OnSwitchWeapons( C_BaseCombatWeapon* pWeapon ){}
  395. bool HasFiredWeapon( void ) { return m_bFiredWeapon; }
  396. void SetFiredWeapon( bool bFlag ) { m_bFiredWeapon = bFlag; }
  397. CNetworkVar( int, m_iCoachingTeam ); // When on TEAM_SPECTATOR, is this player restricted to a team, aka 'coaching' a team
  398. protected:
  399. fogparams_t m_CurrentFog;
  400. EHANDLE m_hOldFogController;
  401. public:
  402. // RecvProxies
  403. static void RecvProxy_LocalVelocityX( const CRecvProxyData *pData, void *pStruct, void *pOut );
  404. static void RecvProxy_LocalVelocityY( const CRecvProxyData *pData, void *pStruct, void *pOut );
  405. static void RecvProxy_LocalVelocityZ( const CRecvProxyData *pData, void *pStruct, void *pOut );
  406. static void RecvProxy_ObserverTarget( const CRecvProxyData *pData, void *pStruct, void *pOut );
  407. static void RecvProxy_ObserverMode( const CRecvProxyData *pData, void *pStruct, void *pOut );
  408. void OnObserverModeChange( bool bIsObserverTarget = false );
  409. static void RecvProxy_LocalOriginXY( const CRecvProxyData *pData, void *pStruct, void *pOut );
  410. static void RecvProxy_LocalOriginZ( const CRecvProxyData *pData, void *pStruct, void *pOut );
  411. static void RecvProxy_NonLocalOriginXY( const CRecvProxyData *pData, void *pStruct, void *pOut );
  412. static void RecvProxy_NonLocalOriginZ( const CRecvProxyData *pData, void *pStruct, void *pOut );
  413. static void RecvProxy_NonLocalCellOriginXY( const CRecvProxyData *pData, void *pStruct, void *pOut );
  414. static void RecvProxy_NonLocalCellOriginZ( const CRecvProxyData *pData, void *pStruct, void *pOut );
  415. virtual bool ShouldRegenerateOriginFromCellBits() const;
  416. void SetUseEntity( CBaseEntity *pUseEntity );
  417. public:
  418. int m_StuckLast;
  419. CNetworkVar( float, m_flDuckAmount );
  420. CNetworkVar( float, m_flDuckSpeed );
  421. Vector2D m_vecLastPositionAtFullCrouchSpeed;
  422. // Data for only the local player
  423. CNetworkVarEmbedded( CPlayerLocalData, m_Local );
  424. EHANDLE m_hTonemapController;
  425. // Data common to all other players, too
  426. CPlayerState pl;
  427. public:
  428. // BEGIN PREDICTION DATA COMPACTION (these fields are together to allow for faster copying in prediction system)
  429. // FTYPEDESC_INSENDTABLE STUFF
  430. // Player FOV values
  431. int m_iFOV; // field of view
  432. int m_iFOVStart; // starting value of the FOV changing over time (client only)
  433. int m_afButtonLast;
  434. int m_afButtonPressed;
  435. int m_afButtonReleased;
  436. int m_nButtons;
  437. protected:
  438. int m_nImpulse;
  439. CNetworkVar( int, m_ladderSurfaceProps );
  440. int m_flPhysics;
  441. public:
  442. float m_flFOVTime; // starting time of the FOV zoom
  443. private:
  444. float m_flWaterJumpTime; // used to be called teleport_time
  445. float m_flSwimSoundTime;
  446. float m_ignoreLadderJumpTime;
  447. bool m_bHasWalkMovedSinceLastJump;
  448. protected:
  449. float m_flStepSoundTime;
  450. float m_surfaceFriction;
  451. private:
  452. CNetworkVector( m_vecLadderNormal );
  453. // FTYPEDESC_INSENDTABLE STUFF (end)
  454. public:
  455. char m_szAnimExtension[32];
  456. private:
  457. int m_nOldTickBase;
  458. private:
  459. int m_iBonusProgress;
  460. int m_iBonusChallenge;
  461. private:
  462. float m_flMaxspeed;
  463. public:
  464. EHANDLE m_hZoomOwner; // This is a pointer to the entity currently controlling the player's zoom
  465. protected:
  466. //HACKHACK: these 9 are only partially ported from server counterpart
  467. IPhysicsPlayerController *m_pPhysicsController;
  468. IPhysicsObject *m_pShadowStand;
  469. IPhysicsObject *m_pShadowCrouch;
  470. int m_vphysicsCollisionState;
  471. Vector m_oldOrigin;
  472. bool m_bTouchedPhysObject;
  473. bool m_bPhysicsWasFrozen;
  474. Vector m_vNewVPhysicsPosition;
  475. Vector m_vNewVPhysicsVelocity;
  476. CUserCmd m_LastCmd;
  477. unsigned int m_afPhysicsFlags;
  478. EHANDLE m_hVehicle;
  479. typedef CHandle<C_BaseCombatWeapon> CBaseCombatWeaponHandle;
  480. CBaseCombatWeaponHandle m_hLastWeapon;
  481. // players own view models, left & right hand
  482. CHandle< C_BaseViewModel > m_hViewModel[ MAX_VIEWMODELS ];
  483. CUtlReference< CNewParticleEffect > m_speechVOIPParticleEffect;
  484. bool m_bCanShowFreezeFrameNow;
  485. public:
  486. int m_nLastKillerDamageTaken;
  487. int m_nLastKillerHitsTaken;
  488. int m_nLastKillerDamageGiven;
  489. int m_nLastKillerHitsGiven;
  490. public:
  491. // For weapon prediction
  492. bool m_fOnTarget; //Is the crosshair on a target?
  493. EHANDLE m_hUseEntity;
  494. // END PREDICTION DATA COMPACTION
  495. public:
  496. int m_iDefaultFOV; // default FOV if no other zooms are occurring
  497. // Only this entity can change the zoom state once it has ownership
  498. int m_afButtonForced; // These are forced onto the player's inputs
  499. CUserCmd *m_pCurrentCommand;
  500. EHANDLE m_hViewEntity;
  501. bool m_bShouldDrawPlayerWhileUsingViewEntity;
  502. // Movement constraints
  503. EHANDLE m_hConstraintEntity;
  504. Vector m_vecConstraintCenter;
  505. float m_flConstraintRadius;
  506. float m_flConstraintWidth;
  507. float m_flConstraintSpeedFactor;
  508. bool m_bConstraintPastRadius;
  509. CUserMessageBinder m_UMCMsg_SendLastKillerDamageToClient;
  510. // Record hits on client and server for comparison.
  511. int m_totalHitsOnClient;
  512. int m_iDeathPostEffect;
  513. protected:
  514. virtual void CalcPlayerView( Vector& eyeOrigin, QAngle& eyeAngles, float& fov );
  515. void CalcVehicleView(IClientVehicle *pVehicle, Vector& eyeOrigin, QAngle& eyeAngles,
  516. float& zNear, float& zFar, float& fov );
  517. virtual void CalcObserverView( Vector& eyeOrigin, QAngle& eyeAngles, float& fov );
  518. virtual Vector GetChaseCamViewOffset( CBaseEntity *target );
  519. void CalcChaseCamView( Vector& eyeOrigin, QAngle& eyeAngles, float& fov );
  520. void CalcInEyeCamView( Vector& eyeOrigin, QAngle& eyeAngles, float& fov );
  521. virtual float GetDeathCamInterpolationTime();
  522. virtual void CalcDeathCamView( Vector& eyeOrigin, QAngle& eyeAngles, float& fov );
  523. virtual void CalcRoamingView(Vector& eyeOrigin, QAngle& eyeAngles, float& fov);
  524. virtual void CalcFreezeCamView( Vector& eyeOrigin, QAngle& eyeAngles, float& fov );
  525. // Check to see if we're in vgui input mode...
  526. void DetermineVguiInputMode( CUserCmd *pCmd );
  527. // Used by prediction, sets the view angles for the player
  528. virtual void SetLocalViewAngles( const QAngle &viewAngles );
  529. virtual void SetViewAngles( const QAngle& ang );
  530. // used by client side player footsteps
  531. surfacedata_t* GetGroundSurface();
  532. protected:
  533. // Did we just enter a vehicle this frame?
  534. bool JustEnteredVehicle();
  535. // DATA
  536. int m_iObserverMode; // if in spectator mode != 0
  537. bool m_bActiveCameraMan;
  538. bool m_bCameraManXRay;
  539. bool m_bCameraManOverview;
  540. bool m_bCameraManScoreBoard;
  541. uint8 m_uCameraManGraphs;
  542. bool m_bLastActiveCameraManState;
  543. bool m_bLastCameraManXRayState;
  544. bool m_bLastCameraManOverviewState;
  545. bool m_bLastCameraManScoreBoardState;
  546. uint8 m_uLastCameraManGraphsState;
  547. int m_iOldObserverMode;
  548. EHANDLE m_hObserverTarget; // current observer target
  549. float m_flObserverChaseDistance; // last distance to observer traget
  550. float m_flObserverChaseApproach;
  551. Vector m_vecObserverEyeDirPrevious;
  552. Vector m_vecFreezeFrameStart;
  553. float m_flFreezeFrameStartTime; // Time at which we entered freeze frame observer mode
  554. float m_flFreezeFrameDistance;
  555. bool m_bWasFreezeFraming;
  556. float m_flFreezePanelExtendedStartTime;
  557. bool m_bWasFreezePanelExtended;
  558. float m_flDeathTime; // last time player died
  559. float m_flNextDecalTime; // next time player can paint a decal
  560. float m_fForceTeam; // last time player died
  561. CDiscontinuousInterpolatedVar< Vector > m_iv_vecViewOffset;
  562. private:
  563. // Make sure no one calls this...
  564. C_BasePlayer& operator=( const C_BasePlayer& src );
  565. C_BasePlayer( const C_BasePlayer & ); // not defined, not accessible
  566. // Vehicle stuff.
  567. EHANDLE m_hOldVehicle;
  568. // Not replicated
  569. Vector m_vecWaterJumpVel;
  570. protected:
  571. QAngle m_vecOldViewAngles;
  572. private:
  573. bool m_bWasFrozen;
  574. int m_nTickBase;
  575. int m_nFinalPredictedTick;
  576. EHANDLE m_pCurrentVguiScreen;
  577. bool m_bFiredWeapon;
  578. // Player flashlight dynamic light pointers
  579. bool m_bFlashlightEnabled[ MAX_SPLITSCREEN_PLAYERS ];
  580. #if !defined( NO_ENTITY_PREDICTION )
  581. CUtlVector< CHandle< C_BaseEntity > > m_SimulatedByThisPlayer;
  582. #endif
  583. float m_flOldPlayerZ;
  584. float m_flOldPlayerViewOffsetZ;
  585. Vector m_vecVehicleViewOrigin; // Used to store the calculated view of the player while riding in a vehicle
  586. QAngle m_vecVehicleViewAngles; // Vehicle angles
  587. float m_flVehicleViewFOV;
  588. int m_nVehicleViewSavedFrame; // Used to mark which frame was the last one the view was calculated for
  589. // For UI purposes...
  590. int m_iOldAmmo[ MAX_AMMO_TYPES ];
  591. C_CommandContext m_CommandContext;
  592. // For underwater effects
  593. float m_flWaterSurfaceZ;
  594. bool m_bResampleWaterSurface;
  595. TimedEvent m_tWaterParticleTimer;
  596. CSmartPtr<WaterDebrisEffect> m_pWaterEmitter;
  597. bool m_bPlayerUnderwater;
  598. friend class CPrediction;
  599. friend class CASW_Prediction;
  600. friend class CDOTAPrediction;
  601. // HACK FOR TF2 Prediction
  602. friend class CTFGameMovementRecon;
  603. friend class CGameMovement;
  604. friend class CTFGameMovement;
  605. friend class CCSGameMovement;
  606. friend class CHL2GameMovement;
  607. friend class CPortalGameMovement;
  608. friend class CASW_MarineGameMovement;
  609. // Accessors for gamemovement
  610. float GetStepSize( void ) const { return m_Local.m_flStepSize; }
  611. float m_flNextAvoidanceTime;
  612. float m_flAvoidanceRight;
  613. float m_flAvoidanceForward;
  614. float m_flAvoidanceDotForward;
  615. float m_flAvoidanceDotRight;
  616. protected:
  617. virtual bool IsDucked( void ) const { return m_Local.m_bDucked; }
  618. virtual bool IsDucking( void ) const { return m_Local.m_bDucking; }
  619. virtual float GetFallVelocity( void ) { return m_Local.m_flFallVelocity; }
  620. void ForceSetupBonesAtTimeFakeInterpolation( matrix3x4a_t *pBonesOut, float curtimeOffset );
  621. float m_flLaggedMovementValue;
  622. // These are used to smooth out prediction corrections. They're most useful when colliding with
  623. // vphysics objects. The server will be sending constant prediction corrections, and these can help
  624. // the errors not be so jerky.
  625. Vector m_vecPredictionError;
  626. float m_flPredictionErrorTime;
  627. Vector m_vecPreviouslyPredictedOrigin; // Used to determine if non-gamemovement game code has teleported, or tweaked the player's origin
  628. char m_szLastPlaceName[MAX_PLACE_NAME_LENGTH]; // received from the server
  629. // Texture names and surface data, used by CGameMovement
  630. int m_surfaceProps;
  631. surfacedata_t* m_pSurfaceData;
  632. char m_chTextureType;
  633. bool m_bStartedFreezeFrame;
  634. bool m_bAbortedFreezeFrame;
  635. bool m_bSentFreezeFrame;
  636. float m_flFreezeZOffset;
  637. byte m_ubEFNoInterpParity;
  638. byte m_ubOldEFNoInterpParity;
  639. float m_flNextAchievementAnnounceTime;
  640. // If we have any attached split users, this is the list of them
  641. CUtlVector< CHandle< CBasePlayer > > m_hSplitScreenPlayers;
  642. CUtlVector< CHandle< CBasePlayer > > m_hSplitScreenAndPipPlayers;
  643. CUtlVector< CHandle< CBasePlayer > > m_hPipPlayers;
  644. int m_nSplitScreenSlot; //-1 == not a split player
  645. CHandle< CBasePlayer > m_hSplitOwner;
  646. bool m_bIsLocalPlayer;
  647. private:
  648. struct StepSoundCache_t
  649. {
  650. StepSoundCache_t() : m_usSoundNameIndex( 0 ) {}
  651. CSoundParameters m_SoundParameters;
  652. unsigned short m_usSoundNameIndex;
  653. };
  654. // One for left and one for right side of step
  655. StepSoundCache_t m_StepSoundCache[ 2 ];
  656. public:
  657. // HACK: Only used for cstrike players, making virtual here because a ton of base player code needs to know about that state.
  658. enum eObserverInterpState
  659. {
  660. OBSERVER_INTERP_NONE, // Not interpolating
  661. OBSERVER_INTERP_TRAVELING, // Camera moving quickly towards target, hide most 1st person effects
  662. OBSERVER_INTERP_SETTLING, // Camera very close to final position but still interpolating (to avoid a pop)... draw viewmodel/scope state but keep interpolating
  663. };
  664. virtual eObserverInterpState GetObserverInterpState( void ) const { return OBSERVER_INTERP_NONE; }
  665. virtual bool IsInObserverInterpolation( void ) const { return false; }
  666. const char *GetLastKnownPlaceName( void ) const { return m_szLastPlaceName; } // return the last nav place name the player occupied
  667. float GetLaggedMovementValue( void ){ return m_flLaggedMovementValue; }
  668. bool ShouldGoSouth( Vector vNPCForward, Vector vNPCRight ); //Such a bad name.
  669. void SetOldPlayerZ( float flOld ) { m_flOldPlayerZ = flOld; }
  670. const fogplayerparams_t& GetPlayerFog() const { return m_PlayerFog; }
  671. private:
  672. friend class CMoveHelperClient;
  673. CNetworkHandle( CPostProcessController, m_hPostProcessCtrl ); // active postprocessing controller
  674. CNetworkHandle( CColorCorrection, m_hColorCorrectionCtrl ); // active FXVolume color correction
  675. // fog params
  676. fogplayerparams_t m_PlayerFog;
  677. #if defined( DEBUG_MOTION_CONTROLLERS )
  678. public:
  679. Vector m_Debug_vPhysPosition;
  680. Vector m_Debug_vPhysVelocity;
  681. Vector m_Debug_LinearAccel;
  682. #endif
  683. float m_flTimeLastTouchedGround;
  684. public:
  685. float GetAirTime( void );
  686. virtual bool IsHoldingTaunt( void ) const { return false; }
  687. virtual bool IsHoldingLookAtWeapon( void ) const { return false; }
  688. private:
  689. void UpdateSplitScreenAndPictureInPicturePlayerList();
  690. //HACK: always contains the last origin we received through C_BasePlayer::RecvProxy_LocalOriginXY() & C_BasePlayer::RecvProxy_LocalOriginZ(). Intended to fix bug 85693 without as small a scale change as possible
  691. //only works because we receive both the local and nonlocal representations of our origin on recreation. It just happens that the nonlocal wins out by default because it comes last
  692. Vector m_vecHack_RecvProxy_LocalPlayerOrigin;
  693. private:
  694. // Eye/angle offsets - used for TrackIR and motion controllers
  695. Vector m_vecEyeOffset;
  696. QAngle m_EyeAngleOffset;
  697. Vector m_AimDirection;
  698. };
  699. EXTERN_RECV_TABLE(DT_BasePlayer);
  700. //-----------------------------------------------------------------------------
  701. // Inline methods
  702. //-----------------------------------------------------------------------------
  703. inline C_BasePlayer *ToBasePlayer( C_BaseEntity *pEntity )
  704. {
  705. if ( !pEntity || !pEntity->IsPlayer() )
  706. return NULL;
  707. #if _DEBUG
  708. Assert( dynamic_cast<C_BasePlayer *>( pEntity ) != NULL );
  709. #endif
  710. return static_cast<C_BasePlayer *>( pEntity );
  711. }
  712. inline const C_BasePlayer *ToBasePlayer( const C_BaseEntity *pEntity )
  713. {
  714. if ( !pEntity || !pEntity->IsPlayer() )
  715. return NULL;
  716. #if _DEBUG
  717. Assert( dynamic_cast<const C_BasePlayer *>( pEntity ) != NULL );
  718. #endif
  719. return static_cast<const C_BasePlayer *>( pEntity );
  720. }
  721. inline IClientVehicle *C_BasePlayer::GetVehicle()
  722. {
  723. C_BaseEntity *pVehicleEnt = m_hVehicle.Get();
  724. return pVehicleEnt ? pVehicleEnt->GetClientVehicle() : NULL;
  725. }
  726. inline bool C_BasePlayer::IsObserver() const
  727. {
  728. return (GetObserverMode() != OBS_MODE_NONE);
  729. }
  730. inline int C_BasePlayer::GetImpulse( void ) const
  731. {
  732. return m_nImpulse;
  733. }
  734. inline C_CommandContext* C_BasePlayer::GetCommandContext()
  735. {
  736. return &m_CommandContext;
  737. }
  738. inline int CBasePlayer::CurrentCommandNumber() const
  739. {
  740. Assert( m_pCurrentCommand );
  741. if ( !m_pCurrentCommand )
  742. return 0;
  743. return m_pCurrentCommand->command_number;
  744. }
  745. inline const CUserCmd *CBasePlayer::GetCurrentUserCommand() const
  746. {
  747. Assert( m_pCurrentCommand );
  748. return m_pCurrentCommand;
  749. }
  750. extern bool g_bEngineIsHLTV;
  751. inline bool C_BasePlayer::IsHLTV() const
  752. {
  753. return m_bIsLocalPlayer && g_bEngineIsHLTV;
  754. }
  755. inline bool C_BasePlayer::IsLocalPlayer( void ) const
  756. {
  757. return m_bIsLocalPlayer;
  758. }
  759. inline void CBasePlayer::SetTouchedPhysics( bool bTouch )
  760. {
  761. m_bTouchedPhysObject = bTouch;
  762. }
  763. inline bool C_BasePlayer::TouchedPhysics( void )
  764. {
  765. return m_bTouchedPhysObject;
  766. }
  767. inline CUserCmd const *C_BasePlayer::GetLastUserCommand( void )
  768. {
  769. return &m_LastCmd;
  770. }
  771. #endif // C_BASEPLAYER_H