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.

176 lines
5.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #ifndef HL2MP_PLAYER_H
  9. #define HL2MP_PLAYER_H
  10. #pragma once
  11. class CHL2MP_Player;
  12. #include "basemultiplayerplayer.h"
  13. #include "hl2_playerlocaldata.h"
  14. #include "hl2_player.h"
  15. #include "simtimer.h"
  16. #include "soundenvelope.h"
  17. #include "hl2mp_player_shared.h"
  18. #include "hl2mp_gamerules.h"
  19. #include "utldict.h"
  20. //=============================================================================
  21. // >> HL2MP_Player
  22. //=============================================================================
  23. class CHL2MPPlayerStateInfo
  24. {
  25. public:
  26. HL2MPPlayerState m_iPlayerState;
  27. const char *m_pStateName;
  28. void (CHL2MP_Player::*pfnEnterState)(); // Init and deinit the state.
  29. void (CHL2MP_Player::*pfnLeaveState)();
  30. void (CHL2MP_Player::*pfnPreThink)(); // Do a PreThink() in this state.
  31. };
  32. class CHL2MP_Player : public CHL2_Player
  33. {
  34. public:
  35. DECLARE_CLASS( CHL2MP_Player, CHL2_Player );
  36. CHL2MP_Player();
  37. ~CHL2MP_Player( void );
  38. static CHL2MP_Player *CreatePlayer( const char *className, edict_t *ed )
  39. {
  40. CHL2MP_Player::s_PlayerEdict = ed;
  41. return (CHL2MP_Player*)CreateEntityByName( className );
  42. }
  43. DECLARE_SERVERCLASS();
  44. DECLARE_DATADESC();
  45. virtual void Precache( void );
  46. virtual void Spawn( void );
  47. virtual void PostThink( void );
  48. virtual void PreThink( void );
  49. virtual void PlayerDeathThink( void );
  50. virtual void SetAnimation( PLAYER_ANIM playerAnim );
  51. virtual bool HandleCommand_JoinTeam( int team );
  52. virtual bool ClientCommand( const CCommand &args );
  53. virtual void CreateViewModel( int viewmodelindex = 0 );
  54. virtual bool BecomeRagdollOnClient( const Vector &force );
  55. virtual void Event_Killed( const CTakeDamageInfo &info );
  56. virtual int OnTakeDamage( const CTakeDamageInfo &inputInfo );
  57. virtual bool WantsLagCompensationOnEntity( const CBasePlayer *pPlayer, const CUserCmd *pCmd, const CBitVec<MAX_EDICTS> *pEntityTransmitBits ) const;
  58. virtual void FireBullets ( const FireBulletsInfo_t &info );
  59. virtual bool Weapon_Switch( CBaseCombatWeapon *pWeapon, int viewmodelindex = 0);
  60. virtual bool BumpWeapon( CBaseCombatWeapon *pWeapon );
  61. virtual void ChangeTeam( int iTeam ) OVERRIDE;
  62. virtual void PickupObject ( CBaseEntity *pObject, bool bLimitMassAndSize );
  63. virtual void PlayStepSound( Vector &vecOrigin, surfacedata_t *psurface, float fvol, bool force );
  64. virtual void Weapon_Drop( CBaseCombatWeapon *pWeapon, const Vector *pvecTarget = NULL, const Vector *pVelocity = NULL );
  65. virtual void UpdateOnRemove( void );
  66. virtual void DeathSound( const CTakeDamageInfo &info );
  67. virtual CBaseEntity* EntSelectSpawnPoint( void );
  68. int FlashlightIsOn( void );
  69. void FlashlightTurnOn( void );
  70. void FlashlightTurnOff( void );
  71. void PrecacheFootStepSounds( void );
  72. bool ValidatePlayerModel( const char *pModel );
  73. QAngle GetAnimEyeAngles( void ) { return m_angEyeAngles.Get(); }
  74. Vector GetAttackSpread( CBaseCombatWeapon *pWeapon, CBaseEntity *pTarget = NULL );
  75. void CheatImpulseCommands( int iImpulse );
  76. void CreateRagdollEntity( void );
  77. void GiveAllItems( void );
  78. void GiveDefaultItems( void );
  79. void NoteWeaponFired( void );
  80. void ResetAnimation( void );
  81. void SetPlayerModel( void );
  82. void SetPlayerTeamModel( void );
  83. Activity TranslateTeamActivity( Activity ActToTranslate );
  84. float GetNextModelChangeTime( void ) { return m_flNextModelChangeTime; }
  85. float GetNextTeamChangeTime( void ) { return m_flNextTeamChangeTime; }
  86. void PickDefaultSpawnTeam( void );
  87. void SetupPlayerSoundsByModel( const char *pModelName );
  88. const char *GetPlayerModelSoundPrefix( void );
  89. int GetPlayerModelType( void ) { return m_iPlayerSoundType; }
  90. void DetonateTripmines( void );
  91. void Reset();
  92. bool IsReady();
  93. void SetReady( bool bReady );
  94. void CheckChatText( char *p, int bufsize );
  95. void State_Transition( HL2MPPlayerState newState );
  96. void State_Enter( HL2MPPlayerState newState );
  97. void State_Leave();
  98. void State_PreThink();
  99. CHL2MPPlayerStateInfo *State_LookupInfo( HL2MPPlayerState state );
  100. void State_Enter_ACTIVE();
  101. void State_PreThink_ACTIVE();
  102. void State_Enter_OBSERVER_MODE();
  103. void State_PreThink_OBSERVER_MODE();
  104. virtual bool StartObserverMode( int mode );
  105. virtual void StopObserverMode( void );
  106. Vector m_vecTotalBulletForce; //Accumulator for bullet force in a single frame
  107. // Tracks our ragdoll entity.
  108. CNetworkHandle( CBaseEntity, m_hRagdoll ); // networked entity handle
  109. virtual bool CanHearAndReadChatFrom( CBasePlayer *pPlayer );
  110. private:
  111. CNetworkQAngle( m_angEyeAngles );
  112. CPlayerAnimState m_PlayerAnimState;
  113. int m_iLastWeaponFireUsercmd;
  114. int m_iModelType;
  115. CNetworkVar( int, m_iSpawnInterpCounter );
  116. CNetworkVar( int, m_iPlayerSoundType );
  117. float m_flNextModelChangeTime;
  118. float m_flNextTeamChangeTime;
  119. float m_flSlamProtectTime;
  120. HL2MPPlayerState m_iPlayerState;
  121. CHL2MPPlayerStateInfo *m_pCurStateInfo;
  122. bool ShouldRunRateLimitedCommand( const CCommand &args );
  123. // This lets us rate limit the commands the players can execute so they don't overflow things like reliable buffers.
  124. CUtlDict<float,int> m_RateLimitLastCommandTimes;
  125. bool m_bEnterObserver;
  126. bool m_bReady;
  127. };
  128. inline CHL2MP_Player *ToHL2MPPlayer( CBaseEntity *pEntity )
  129. {
  130. if ( !pEntity || !pEntity->IsPlayer() )
  131. return NULL;
  132. return dynamic_cast<CHL2MP_Player*>( pEntity );
  133. }
  134. #endif //HL2MP_PLAYER_H