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.

1564 lines
54 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //===========================================================================//
  6. #ifndef PLAYER_H
  7. #define PLAYER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "basecombatcharacter.h"
  12. #include "usercmd.h"
  13. #include "playerlocaldata.h"
  14. #include "PlayerState.h"
  15. #include "game/server/iplayerinfo.h"
  16. #include "hintsystem.h"
  17. #include "SoundEmitterSystem/isoundemittersystembase.h"
  18. #include "util_shared.h"
  19. #if defined USES_ECON_ITEMS
  20. #include "game_item_schema.h"
  21. #include "econ_item_view.h"
  22. #endif
  23. // For queuing and processing usercmds
  24. class CCommandContext
  25. {
  26. public:
  27. CUtlVector< CUserCmd > cmds;
  28. int numcmds;
  29. int totalcmds;
  30. int dropped_packets;
  31. bool paused;
  32. };
  33. // Info about last 20 or so updates to the
  34. class CPlayerCmdInfo
  35. {
  36. public:
  37. CPlayerCmdInfo() :
  38. m_flTime( 0.0f ), m_nNumCmds( 0 ), m_nDroppedPackets( 0 )
  39. {
  40. }
  41. // realtime of sample
  42. float m_flTime;
  43. // # of CUserCmds in this update
  44. int m_nNumCmds;
  45. // # of dropped packets on the link
  46. int m_nDroppedPackets;
  47. };
  48. class CPlayerSimInfo
  49. {
  50. public:
  51. CPlayerSimInfo() :
  52. m_flTime( 0.0f ), m_nNumCmds( 0 ), m_nTicksCorrected( 0 ), m_flFinalSimulationTime( 0.0f ), m_flGameSimulationTime( 0.0f ), m_flServerFrameTime( 0.0f ), m_vecAbsOrigin( 0, 0, 0 )
  53. {
  54. }
  55. // realtime of sample
  56. float m_flTime;
  57. // # of CUserCmds in this update
  58. int m_nNumCmds;
  59. // If clock needed correction, # of ticks added/removed
  60. int m_nTicksCorrected; // +ve or -ve
  61. // player's m_flSimulationTime at end of frame
  62. float m_flFinalSimulationTime;
  63. float m_flGameSimulationTime;
  64. // estimate of server perf
  65. float m_flServerFrameTime;
  66. Vector m_vecAbsOrigin;
  67. };
  68. //-----------------------------------------------------------------------------
  69. // Forward declarations:
  70. //-----------------------------------------------------------------------------
  71. class CBaseCombatWeapon;
  72. class CBaseViewModel;
  73. class CTeam;
  74. class IPhysicsPlayerController;
  75. class IServerVehicle;
  76. class CUserCmd;
  77. class CFuncLadder;
  78. class CNavArea;
  79. class CHintSystem;
  80. class CAI_Expresser;
  81. #if defined USES_ECON_ITEMS
  82. class CEconWearable;
  83. #endif // USES_ECON_ITEMS
  84. // for step sounds
  85. struct surfacedata_t;
  86. // !!!set this bit on guns and stuff that should never respawn.
  87. #define SF_NORESPAWN ( 1 << 30 )
  88. //
  89. // Player PHYSICS FLAGS bits
  90. //
  91. enum PlayerPhysFlag_e
  92. {
  93. PFLAG_DIROVERRIDE = ( 1<<0 ), // override the player's directional control (trains, physics gun, etc.)
  94. PFLAG_DUCKING = ( 1<<1 ), // In the process of ducking, but totally squatted yet
  95. PFLAG_USING = ( 1<<2 ), // Using a continuous entity
  96. PFLAG_OBSERVER = ( 1<<3 ), // player is locked in stationary cam mode. Spectators can move, observers can't.
  97. PFLAG_VPHYSICS_MOTIONCONTROLLER = ( 1<<4 ), // player is physically attached to a motion controller
  98. PFLAG_GAMEPHYSICS_ROTPUSH = (1<<5), // game physics did a rotating push that we may want to override with vphysics
  99. // If you add another flag here check that you aren't
  100. // overwriting phys flags in the HL2 of TF2 player classes
  101. };
  102. //
  103. // generic player
  104. //
  105. //-----------------------------------------------------
  106. //This is Half-Life player entity
  107. //-----------------------------------------------------
  108. #define CSUITPLAYLIST 4 // max of 4 suit sentences queued up at any time
  109. #define SUIT_REPEAT_OK 0
  110. #define SUIT_NEXT_IN_30SEC 30
  111. #define SUIT_NEXT_IN_1MIN 60
  112. #define SUIT_NEXT_IN_5MIN 300
  113. #define SUIT_NEXT_IN_10MIN 600
  114. #define SUIT_NEXT_IN_30MIN 1800
  115. #define SUIT_NEXT_IN_1HOUR 3600
  116. #define CSUITNOREPEAT 32
  117. #define TEAM_NAME_LENGTH 16
  118. // constant items
  119. #define ITEM_HEALTHKIT 1
  120. #define ITEM_BATTERY 4
  121. #define AUTOAIM_2DEGREES 0.0348994967025
  122. #define AUTOAIM_5DEGREES 0.08715574274766
  123. #define AUTOAIM_8DEGREES 0.1391731009601
  124. #define AUTOAIM_10DEGREES 0.1736481776669
  125. #define AUTOAIM_20DEGREES 0.3490658503989
  126. // useful cosines
  127. #define DOT_1DEGREE 0.9998476951564
  128. #define DOT_2DEGREE 0.9993908270191
  129. #define DOT_3DEGREE 0.9986295347546
  130. #define DOT_4DEGREE 0.9975640502598
  131. #define DOT_5DEGREE 0.9961946980917
  132. #define DOT_6DEGREE 0.9945218953683
  133. #define DOT_7DEGREE 0.9925461516413
  134. #define DOT_8DEGREE 0.9902680687416
  135. #define DOT_9DEGREE 0.9876883405951
  136. #define DOT_10DEGREE 0.9848077530122
  137. #define DOT_15DEGREE 0.9659258262891
  138. #define DOT_20DEGREE 0.9396926207859
  139. #define DOT_25DEGREE 0.9063077870367
  140. #define DOT_30DEGREE 0.866025403784
  141. #define DOT_45DEGREE 0.707106781187
  142. enum
  143. {
  144. VPHYS_WALK = 0,
  145. VPHYS_CROUCH,
  146. VPHYS_NOCLIP,
  147. };
  148. enum PlayerConnectedState
  149. {
  150. PlayerConnected,
  151. PlayerDisconnecting,
  152. PlayerDisconnected,
  153. };
  154. extern bool gInitHUD;
  155. extern ConVar *sv_cheats;
  156. class CBasePlayer;
  157. class CPlayerInfo : public IBotController, public IPlayerInfo
  158. {
  159. public:
  160. CPlayerInfo () { m_pParent = NULL; }
  161. ~CPlayerInfo () {}
  162. void SetParent( CBasePlayer *parent ) { m_pParent = parent; }
  163. // IPlayerInfo interface
  164. virtual const char *GetName();
  165. virtual int GetUserID();
  166. virtual const char *GetNetworkIDString();
  167. virtual int GetTeamIndex();
  168. virtual void ChangeTeam( int iTeamNum );
  169. virtual int GetFragCount();
  170. virtual int GetDeathCount();
  171. virtual bool IsConnected();
  172. virtual int GetArmorValue();
  173. virtual bool IsHLTV();
  174. virtual bool IsReplay();
  175. virtual bool IsPlayer();
  176. virtual bool IsFakeClient();
  177. virtual bool IsDead();
  178. virtual bool IsInAVehicle();
  179. virtual bool IsObserver();
  180. virtual const Vector GetAbsOrigin();
  181. virtual const QAngle GetAbsAngles();
  182. virtual const Vector GetPlayerMins();
  183. virtual const Vector GetPlayerMaxs();
  184. virtual const char *GetWeaponName();
  185. virtual const char *GetModelName();
  186. virtual const int GetHealth();
  187. virtual const int GetMaxHealth();
  188. // bot specific functions
  189. virtual void SetAbsOrigin( Vector & vec );
  190. virtual void SetAbsAngles( QAngle & ang );
  191. virtual void RemoveAllItems( bool removeSuit );
  192. virtual void SetActiveWeapon( const char *WeaponName );
  193. virtual void SetLocalOrigin( const Vector& origin );
  194. virtual const Vector GetLocalOrigin( void );
  195. virtual void SetLocalAngles( const QAngle& angles );
  196. virtual const QAngle GetLocalAngles( void );
  197. virtual bool IsEFlagSet( int nEFlagMask );
  198. virtual void RunPlayerMove( CBotCmd *ucmd );
  199. virtual void SetLastUserCommand( const CBotCmd &cmd );
  200. virtual CBotCmd GetLastUserCommand();
  201. private:
  202. CBasePlayer *m_pParent;
  203. };
  204. class CBasePlayer : public CBaseCombatCharacter
  205. {
  206. public:
  207. DECLARE_CLASS( CBasePlayer, CBaseCombatCharacter );
  208. protected:
  209. // HACK FOR BOTS
  210. friend class CBotManager;
  211. static edict_t *s_PlayerEdict; // must be set before calling constructor
  212. public:
  213. DECLARE_DATADESC();
  214. DECLARE_SERVERCLASS();
  215. CBasePlayer();
  216. ~CBasePlayer();
  217. // IPlayerInfo passthrough (because we can't do multiple inheritance)
  218. IPlayerInfo *GetPlayerInfo() { return &m_PlayerInfo; }
  219. IBotController *GetBotController() { return &m_PlayerInfo; }
  220. virtual void SetModel( const char *szModelName );
  221. void SetBodyPitch( float flPitch );
  222. virtual void UpdateOnRemove( void );
  223. static CBasePlayer *CreatePlayer( const char *className, edict_t *ed );
  224. virtual void CreateViewModel( int viewmodelindex = 0 );
  225. CBaseViewModel *GetViewModel( int viewmodelindex = 0, bool bObserverOK = true );
  226. void HideViewModels( void );
  227. void DestroyViewModels( void );
  228. CPlayerState *PlayerData( void ) { return &pl; }
  229. int RequiredEdictIndex( void ) { return ENTINDEX(edict()); }
  230. void LockPlayerInPlace( void );
  231. void UnlockPlayer( void );
  232. virtual void DrawDebugGeometryOverlays(void);
  233. // Networking is about to update this entity, let it override and specify it's own pvs
  234. virtual void SetupVisibility( CBaseEntity *pViewEntity, unsigned char *pvs, int pvssize );
  235. virtual int UpdateTransmitState();
  236. virtual int ShouldTransmit( const CCheckTransmitInfo *pInfo );
  237. // Returns true if this player wants pPlayer to be moved back in time when this player runs usercmds.
  238. // Saves a lot of overhead on the server if we can cull out entities that don't need to lag compensate
  239. // (like team members, entities out of our PVS, etc).
  240. virtual bool WantsLagCompensationOnEntity( const CBasePlayer *pPlayer, const CUserCmd *pCmd, const CBitVec<MAX_EDICTS> *pEntityTransmitBits ) const;
  241. virtual void Spawn( void );
  242. virtual void Activate( void );
  243. virtual void SharedSpawn(); // Shared between client and server.
  244. virtual void ForceRespawn( void );
  245. virtual void InitialSpawn( void );
  246. virtual void InitHUD( void ) {}
  247. virtual void ShowViewPortPanel( const char * name, bool bShow = true, KeyValues *data = NULL );
  248. virtual void PlayerDeathThink( void );
  249. virtual void Jump( void );
  250. virtual void Duck( void );
  251. const char *GetTracerType( void );
  252. void MakeTracer( const Vector &vecTracerSrc, const trace_t &tr, int iTracerType );
  253. void DoImpactEffect( trace_t &tr, int nDamageType );
  254. #if !defined( NO_ENTITY_PREDICTION )
  255. void AddToPlayerSimulationList( CBaseEntity *other );
  256. void RemoveFromPlayerSimulationList( CBaseEntity *other );
  257. void SimulatePlayerSimulatedEntities( void );
  258. void ClearPlayerSimulationList( void );
  259. #endif
  260. // Physics simulation (player executes it's usercmd's here)
  261. virtual void PhysicsSimulate( void );
  262. // Forces processing of usercmds (e.g., even if game is paused, etc.)
  263. void ForceSimulation();
  264. virtual unsigned int PhysicsSolidMaskForEntity( void ) const;
  265. virtual void PreThink( void );
  266. virtual void PostThink( void );
  267. virtual int TakeHealth( float flHealth, int bitsDamageType );
  268. virtual void TraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator );
  269. bool ShouldTakeDamageInCommentaryMode( const CTakeDamageInfo &inputInfo );
  270. virtual int OnTakeDamage( const CTakeDamageInfo &info );
  271. virtual void DamageEffect(float flDamage, int fDamageType);
  272. virtual void OnDamagedByExplosion( const CTakeDamageInfo &info );
  273. void PauseBonusProgress( bool bPause = true );
  274. void SetBonusProgress( int iBonusProgress );
  275. void SetBonusChallenge( int iBonusChallenge );
  276. int GetBonusProgress() const { return m_iBonusProgress; }
  277. int GetBonusChallenge() const { return m_iBonusChallenge; }
  278. virtual Vector EyePosition( ); // position of eyes
  279. const QAngle &EyeAngles( );
  280. void EyePositionAndVectors( Vector *pPosition, Vector *pForward, Vector *pRight, Vector *pUp );
  281. virtual const QAngle &LocalEyeAngles(); // Direction of eyes
  282. void EyeVectors( Vector *pForward, Vector *pRight = NULL, Vector *pUp = NULL );
  283. void CacheVehicleView( void ); // Calculate and cache the position of the player in the vehicle
  284. // Sets the view angles
  285. void SnapEyeAngles( const QAngle &viewAngles );
  286. virtual QAngle BodyAngles();
  287. virtual Vector BodyTarget( const Vector &posSrc, bool bNoisy);
  288. virtual bool ShouldFadeOnDeath( void ) { return FALSE; }
  289. virtual const impactdamagetable_t &GetPhysicsImpactDamageTable();
  290. virtual int OnTakeDamage_Alive( const CTakeDamageInfo &info );
  291. virtual void Event_Killed( const CTakeDamageInfo &info );
  292. // Notifier that I've killed some other entity. (called from Victim's Event_Killed).
  293. virtual void Event_KilledOther( CBaseEntity *pVictim, const CTakeDamageInfo &info );
  294. virtual void Event_Dying( const CTakeDamageInfo &info );
  295. bool IsHLTV( void ) const { return pl.hltv; }
  296. bool IsReplay( void ) const { return pl.replay; }
  297. virtual bool IsPlayer( void ) const { return true; } // Spectators return TRUE for this, use IsObserver to separate cases
  298. virtual bool IsNetClient( void ) const { return true; } // Bots should return FALSE for this, they can't receive NET messages
  299. // Spectators should return TRUE for this
  300. virtual bool IsFakeClient( void ) const;
  301. // Get the client index (entindex-1).
  302. int GetClientIndex() { return ENTINDEX( edict() ) - 1; }
  303. // returns the player name
  304. const char * GetPlayerName() { return m_szNetname; }
  305. void SetPlayerName( const char *name );
  306. int GetUserID() const { return engine->GetPlayerUserId( edict() ); }
  307. const char * GetNetworkIDString();
  308. virtual const Vector GetPlayerMins( void ) const; // uses local player
  309. virtual const Vector GetPlayerMaxs( void ) const; // uses local player
  310. void VelocityPunch( const Vector &vecForce );
  311. void ViewPunch( const QAngle &angleOffset );
  312. void ViewPunchReset( float tolerance = 0 );
  313. void ShowViewModel( bool bShow );
  314. void ShowCrosshair( bool bShow );
  315. // View model prediction setup
  316. void CalcView( Vector &eyeOrigin, QAngle &eyeAngles, float &zNear, float &zFar, float &fov );
  317. // Handle view smoothing when going up stairs
  318. void SmoothViewOnStairs( Vector& eyeOrigin );
  319. virtual float CalcRoll (const QAngle& angles, const Vector& velocity, float rollangle, float rollspeed);
  320. void CalcViewRoll( QAngle& eyeAngles );
  321. virtual int Save( ISave &save );
  322. virtual int Restore( IRestore &restore );
  323. virtual bool ShouldSavePhysics();
  324. virtual void OnRestore( void );
  325. virtual void PackDeadPlayerItems( void );
  326. virtual void RemoveAllItems( bool removeSuit );
  327. bool IsDead() const;
  328. #ifdef CSTRIKE_DLL
  329. virtual bool IsRunning( void ) const { return false; } // bot support under cstrike (AR)
  330. #endif
  331. bool HasPhysicsFlag( unsigned int flag ) { return (m_afPhysicsFlags & flag) != 0; }
  332. // Weapon stuff
  333. virtual Vector Weapon_ShootPosition( );
  334. virtual bool Weapon_CanUse( CBaseCombatWeapon *pWeapon );
  335. virtual void Weapon_Equip( CBaseCombatWeapon *pWeapon );
  336. virtual void Weapon_Drop( CBaseCombatWeapon *pWeapon, const Vector *pvecTarget /* = NULL */, const Vector *pVelocity /* = NULL */ );
  337. virtual bool Weapon_Switch( CBaseCombatWeapon *pWeapon, int viewmodelindex = 0 ); // Switch to given weapon if has ammo (false if failed)
  338. virtual void Weapon_SetLast( CBaseCombatWeapon *pWeapon );
  339. virtual bool Weapon_ShouldSetLast( CBaseCombatWeapon *pOldWeapon, CBaseCombatWeapon *pNewWeapon ) { return true; }
  340. virtual bool Weapon_ShouldSelectItem( CBaseCombatWeapon *pWeapon );
  341. void Weapon_DropSlot( int weaponSlot );
  342. CBaseCombatWeapon *GetLastWeapon( void ) { return m_hLastWeapon.Get(); }
  343. virtual void OnMyWeaponFired( CBaseCombatWeapon *weapon ); // call this when this player fires a weapon to allow other systems to react
  344. virtual float GetTimeSinceWeaponFired( void ) const; // returns the time, in seconds, since this player fired a weapon
  345. virtual bool IsFiringWeapon( void ) const; // return true if this player is currently firing their weapon
  346. bool HasAnyAmmoOfType( int nAmmoIndex );
  347. // JOHN: sends custom messages if player HUD data has changed (eg health, ammo)
  348. virtual void UpdateClientData( void );
  349. void RumbleEffect( unsigned char index, unsigned char rumbleData, unsigned char rumbleFlags );
  350. // Player is moved across the transition by other means
  351. virtual int ObjectCaps( void ) { return BaseClass::ObjectCaps() & ~FCAP_ACROSS_TRANSITION; }
  352. virtual void Precache( void );
  353. bool IsOnLadder( void );
  354. virtual void ExitLadder() {}
  355. virtual surfacedata_t *GetLadderSurface( const Vector &origin );
  356. virtual void SetFlashlightEnabled( bool bState ) { };
  357. virtual int FlashlightIsOn( void ) { return false; }
  358. virtual void FlashlightTurnOn( void ) { };
  359. virtual void FlashlightTurnOff( void ) { };
  360. virtual bool IsIlluminatedByFlashlight( CBaseEntity *pEntity, float *flReturnDot ) {return false; }
  361. void UpdatePlayerSound ( void );
  362. virtual void UpdateStepSound( surfacedata_t *psurface, const Vector &vecOrigin, const Vector &vecVelocity );
  363. virtual void PlayStepSound( Vector &vecOrigin, surfacedata_t *psurface, float fvol, bool force );
  364. virtual const char *GetOverrideStepSound( const char *pszBaseStepSoundName ) { return pszBaseStepSoundName; }
  365. virtual void GetStepSoundVelocities( float *velwalk, float *velrun );
  366. virtual void SetStepSoundTime( stepsoundtimes_t iStepSoundTime, bool bWalking );
  367. virtual void DeathSound( const CTakeDamageInfo &info );
  368. virtual const char* GetSceneSoundToken( void ) { return ""; }
  369. virtual void OnEmitFootstepSound( const CSoundParameters& params, const Vector& vecOrigin, float fVolume ) {}
  370. Class_T Classify ( void );
  371. virtual void SetAnimation( PLAYER_ANIM playerAnim );
  372. void SetWeaponAnimType( const char *szExtention );
  373. // custom player functions
  374. virtual void ImpulseCommands( void );
  375. virtual void CheatImpulseCommands( int iImpulse );
  376. virtual bool ClientCommand( const CCommand &args );
  377. void NotifySinglePlayerGameEnding() { m_bSinglePlayerGameEnding = true; }
  378. bool IsSinglePlayerGameEnding() { return m_bSinglePlayerGameEnding == true; }
  379. bool HandleVoteCommands( const CCommand &args );
  380. // Observer functions
  381. virtual bool StartObserverMode(int mode); // true, if successful
  382. virtual void StopObserverMode( void ); // stop spectator mode
  383. virtual bool ModeWantsSpectatorGUI( int iMode ) { return true; }
  384. virtual bool SetObserverMode(int mode); // sets new observer mode, returns true if successful
  385. virtual int GetObserverMode( void ); // returns observer mode or OBS_NONE
  386. virtual bool SetObserverTarget(CBaseEntity * target);
  387. virtual void ObserverUse( bool bIsPressed ); // observer pressed use
  388. virtual CBaseEntity *GetObserverTarget( void ); // returns players targer or NULL
  389. virtual CBaseEntity *FindNextObserverTarget( bool bReverse ); // returns next/prev player to follow or NULL
  390. virtual int GetNextObserverSearchStartPoint( bool bReverse ); // Where we should start looping the player list in a FindNextObserverTarget call
  391. virtual bool IsValidObserverTarget(CBaseEntity * target); // true, if player is allowed to see this target
  392. virtual void CheckObserverSettings(); // checks, if target still valid (didn't die etc)
  393. virtual void JumptoPosition(const Vector &origin, const QAngle &angles);
  394. virtual void ForceObserverMode(int mode); // sets a temporary mode, force because of invalid targets
  395. virtual void ResetObserverMode(); // resets all observer related settings
  396. virtual void ValidateCurrentObserverTarget( void ); // Checks the current observer target, and moves on if it's not valid anymore
  397. virtual void AttemptToExitFreezeCam( void );
  398. virtual bool StartReplayMode( float fDelay, float fDuration, int iEntity );
  399. virtual void StopReplayMode();
  400. virtual int GetDelayTicks();
  401. virtual int GetReplayEntity();
  402. virtual void CreateCorpse( void ) { }
  403. virtual CBaseEntity *EntSelectSpawnPoint( void );
  404. // Vehicles
  405. virtual bool IsInAVehicle( void ) const;
  406. bool CanEnterVehicle( IServerVehicle *pVehicle, int nRole );
  407. virtual bool GetInVehicle( IServerVehicle *pVehicle, int nRole );
  408. virtual void LeaveVehicle( const Vector &vecExitPoint = vec3_origin, const QAngle &vecExitAngles = vec3_angle );
  409. int GetVehicleAnalogControlBias() { return m_iVehicleAnalogBias; }
  410. void SetVehicleAnalogControlBias( int bias ) { m_iVehicleAnalogBias = bias; }
  411. // override these for
  412. virtual void OnVehicleStart() {}
  413. virtual void OnVehicleEnd( Vector &playerDestPosition ) {}
  414. IServerVehicle *GetVehicle();
  415. CBaseEntity *GetVehicleEntity( void );
  416. bool UsingStandardWeaponsInVehicle( void );
  417. void AddPoints( int score, bool bAllowNegativeScore );
  418. void AddPointsToTeam( int score, bool bAllowNegativeScore );
  419. virtual bool BumpWeapon( CBaseCombatWeapon *pWeapon );
  420. bool RemovePlayerItem( CBaseCombatWeapon *pItem );
  421. CBaseEntity *HasNamedPlayerItem( const char *pszItemName );
  422. bool HasWeapons( void );// do I have ANY weapons?
  423. virtual void SelectLastItem(void);
  424. virtual void SelectItem( const char *pstr, int iSubType = 0 );
  425. void ItemPreFrame( void );
  426. virtual void ItemPostFrame( void );
  427. virtual CBaseEntity *GiveNamedItem( const char *szName, int iSubType = 0 );
  428. void EnableControl(bool fControl);
  429. virtual void CheckTrainUpdate( void );
  430. void AbortReload( void );
  431. void SendAmmoUpdate(void);
  432. void WaterMove( void );
  433. float GetWaterJumpTime() const;
  434. void SetWaterJumpTime( float flWaterJumpTime );
  435. float GetSwimSoundTime( void ) const;
  436. void SetSwimSoundTime( float flSwimSoundTime );
  437. virtual void SetPlayerUnderwater( bool state );
  438. void UpdateUnderwaterState( void );
  439. bool IsPlayerUnderwater( void ) { return m_bPlayerUnderwater; }
  440. virtual bool CanBreatheUnderwater() const { return false; }
  441. virtual void PlayerUse( void );
  442. virtual void PlayUseDenySound() {}
  443. virtual CBaseEntity *FindUseEntity( void );
  444. virtual bool IsUseableEntity( CBaseEntity *pEntity, unsigned int requiredCaps );
  445. bool ClearUseEntity();
  446. CBaseEntity *DoubleCheckUseNPC( CBaseEntity *pNPC, const Vector &vecSrc, const Vector &vecDir );
  447. // physics interactions
  448. // mass/size limit set to zero for none
  449. static bool CanPickupObject( CBaseEntity *pObject, float massLimit, float sizeLimit );
  450. virtual void PickupObject( CBaseEntity *pObject, bool bLimitMassAndSize = true ) {}
  451. virtual void ForceDropOfCarriedPhysObjects( CBaseEntity *pOnlyIfHoldindThis = NULL ) {}
  452. virtual float GetHeldObjectMass( IPhysicsObject *pHeldObject );
  453. void CheckSuitUpdate();
  454. void SetSuitUpdate(const char *name, int fgroup, int iNoRepeat);
  455. virtual void UpdateGeigerCounter( void );
  456. void CheckTimeBasedDamage( void );
  457. void ResetAutoaim( void );
  458. virtual Vector GetAutoaimVector( float flScale );
  459. virtual Vector GetAutoaimVector( float flScale, float flMaxDist );
  460. virtual void GetAutoaimVector( autoaim_params_t &params );
  461. float GetAutoaimScore( const Vector &eyePosition, const Vector &viewDir, const Vector &vecTarget, CBaseEntity *pTarget, float fScale, CBaseCombatWeapon *pActiveWeapon );
  462. QAngle AutoaimDeflection( Vector &vecSrc, autoaim_params_t &params );
  463. virtual bool ShouldAutoaim( void );
  464. void SetTargetInfo( Vector &vecSrc, float flDist );
  465. void SetViewEntity( CBaseEntity *pEntity );
  466. CBaseEntity *GetViewEntity( void ) { return m_hViewEntity; }
  467. virtual void ForceClientDllUpdate( void ); // Forces all client .dll specific data to be resent to client.
  468. void DeathMessage( CBaseEntity *pKiller );
  469. virtual void ProcessUsercmds( CUserCmd *cmds, int numcmds, int totalcmds,
  470. int dropped_packets, bool paused );
  471. bool IsUserCmdDataValid( CUserCmd *pCmd );
  472. void AvoidPhysicsProps( CUserCmd *pCmd );
  473. // Run a user command. The default implementation calls ::PlayerRunCommand. In TF, this controls a vehicle if
  474. // the player is in one.
  475. virtual void PlayerRunCommand(CUserCmd *ucmd, IMoveHelper *moveHelper);
  476. void RunNullCommand();
  477. CUserCmd * GetCurrentCommand( void ) { return m_pCurrentCommand; }
  478. float GetTimeSinceLastUserCommand( void ) { return ( !IsConnected() || IsFakeClient() || IsBot() ) ? 0.f : gpGlobals->curtime - m_flLastUserCommandTime; }
  479. // Team Handling
  480. virtual void ChangeTeam( int iTeamNum ) OVERRIDE { ChangeTeam( iTeamNum, false, false ); }
  481. virtual void ChangeTeam( int iTeamNum, bool bAutoTeam, bool bSilent, bool bAutoBalance = false );
  482. // say/sayteam allowed?
  483. virtual bool CanHearAndReadChatFrom( CBasePlayer *pPlayer ) { return true; }
  484. virtual bool CanSpeak( void ) { return true; }
  485. audioparams_t &GetAudioParams() { return m_Local.m_audio; }
  486. virtual void ModifyOrAppendPlayerCriteria( AI_CriteriaSet& set );
  487. const QAngle& GetPunchAngle();
  488. void SetPunchAngle( const QAngle &punchAngle );
  489. virtual void DoMuzzleFlash();
  490. const char *GetLastKnownPlaceName( void ) const { return m_szLastPlaceName; } // return the last nav place name the player occupied
  491. virtual void CheckChatText( char *p, int bufsize ) {}
  492. virtual void CreateRagdollEntity( void ) { return; }
  493. virtual void HandleAnimEvent( animevent_t *pEvent );
  494. virtual bool ShouldAnnounceAchievement( void );
  495. #if defined USES_ECON_ITEMS
  496. // Wearables
  497. virtual void EquipWearable( CEconWearable *pItem );
  498. virtual void RemoveWearable( CEconWearable *pItem );
  499. void PlayWearableAnimsForPlaybackEvent( wearableanimplayback_t iPlayback );
  500. #endif
  501. public:
  502. // Player Physics Shadow
  503. void SetupVPhysicsShadow( const Vector &vecAbsOrigin, const Vector &vecAbsVelocity, CPhysCollide *pStandModel, const char *pStandHullName, CPhysCollide *pCrouchModel, const char *pCrouchHullName );
  504. IPhysicsPlayerController* GetPhysicsController() { return m_pPhysicsController; }
  505. virtual void VPhysicsCollision( int index, gamevcollisionevent_t *pEvent );
  506. void VPhysicsUpdate( IPhysicsObject *pPhysics );
  507. virtual void VPhysicsShadowUpdate( IPhysicsObject *pPhysics );
  508. virtual bool IsFollowingPhysics( void ) { return false; }
  509. bool IsRideablePhysics( IPhysicsObject *pPhysics );
  510. IPhysicsObject *GetGroundVPhysics();
  511. virtual void Touch( CBaseEntity *pOther );
  512. void SetTouchedPhysics( bool bTouch );
  513. bool TouchedPhysics( void );
  514. Vector GetSmoothedVelocity( void );
  515. virtual void RefreshCollisionBounds( void );
  516. virtual void InitVCollision( const Vector &vecAbsOrigin, const Vector &vecAbsVelocity );
  517. virtual void VPhysicsDestroyObject();
  518. void SetVCollisionState( const Vector &vecAbsOrigin, const Vector &vecAbsVelocity, int collisionState );
  519. void PostThinkVPhysics( void );
  520. virtual void UpdatePhysicsShadowToCurrentPosition();
  521. void UpdatePhysicsShadowToPosition( const Vector &vecAbsOrigin );
  522. void UpdateVPhysicsPosition( const Vector &position, const Vector &velocity, float secondsToArrival );
  523. // Hint system
  524. virtual CHintSystem *Hints( void ) { return NULL; }
  525. bool ShouldShowHints( void ) { return Hints() ? Hints()->ShouldShowHints() : false; }
  526. void SetShowHints( bool bShowHints ) { if (Hints()) Hints()->SetShowHints( bShowHints ); }
  527. bool HintMessage( int hint, bool bForce = false ) { return Hints() ? Hints()->HintMessage( hint, bForce ) : false; }
  528. void HintMessage( const char *pMessage ) { if (Hints()) Hints()->HintMessage( pMessage ); }
  529. void StartHintTimer( int iHintID ) { if (Hints()) Hints()->StartHintTimer( iHintID ); }
  530. void StopHintTimer( int iHintID ) { if (Hints()) Hints()->StopHintTimer( iHintID ); }
  531. void RemoveHintTimer( int iHintID ) { if (Hints()) Hints()->RemoveHintTimer( iHintID ); }
  532. // Accessor methods
  533. int FragCount() const { return m_iFrags; }
  534. int DeathCount() const { return m_iDeaths;}
  535. bool IsConnected() const { return m_iConnected != PlayerDisconnected; }
  536. bool IsDisconnecting() const { return m_iConnected == PlayerDisconnecting; }
  537. bool IsSuitEquipped() const { return m_Local.m_bWearingSuit; }
  538. int ArmorValue() const { return m_ArmorValue; }
  539. bool HUDNeedsRestart() const { return m_fInitHUD; }
  540. float MaxSpeed() const { return m_flMaxspeed; }
  541. Activity GetActivity( ) const { return m_Activity; }
  542. inline void SetActivity( Activity eActivity ) { m_Activity = eActivity; }
  543. bool IsPlayerLockedInPlace() const { return m_iPlayerLocked != 0; }
  544. bool IsObserver() const { return (m_afPhysicsFlags & PFLAG_OBSERVER) != 0; }
  545. bool IsOnTarget() const { return m_fOnTarget; }
  546. float MuzzleFlashTime() const { return m_flFlashTime; }
  547. float PlayerDrownTime() const { return m_AirFinished; }
  548. int GetObserverMode() const { return m_iObserverMode; }
  549. CBaseEntity *GetObserverTarget() const { return m_hObserverTarget; }
  550. // Round gamerules
  551. virtual bool IsReadyToPlay( void ) { return true; }
  552. virtual bool IsReadyToSpawn( void ) { return true; }
  553. virtual bool ShouldGainInstantSpawn( void ) { return false; }
  554. virtual void ResetPerRoundStats( void ) { return; }
  555. void AllowInstantSpawn( void ) { m_bAllowInstantSpawn = true; }
  556. virtual void ResetScores( void ) { ResetFragCount(); ResetDeathCount(); }
  557. void ResetFragCount();
  558. void IncrementFragCount( int nCount );
  559. void ResetDeathCount();
  560. void IncrementDeathCount( int nCount );
  561. void SetArmorValue( int value );
  562. void IncrementArmorValue( int nCount, int nMaxValue = -1 );
  563. void SetConnected( PlayerConnectedState iConnected ) { m_iConnected = iConnected; }
  564. virtual void EquipSuit( bool bPlayEffects = true );
  565. virtual void RemoveSuit( void );
  566. void SetMaxSpeed( float flMaxSpeed ) { m_flMaxspeed = flMaxSpeed; }
  567. void NotifyNearbyRadiationSource( float flRange );
  568. void SetAnimationExtension( const char *pExtension );
  569. void SetAdditionalPVSOrigin( const Vector &vecOrigin );
  570. void SetCameraPVSOrigin( const Vector &vecOrigin );
  571. void SetMuzzleFlashTime( float flTime );
  572. void SetUseEntity( CBaseEntity *pUseEntity );
  573. CBaseEntity *GetUseEntity();
  574. virtual float GetPlayerMaxSpeed();
  575. // Used to set private physics flags PFLAG_*
  576. void SetPhysicsFlag( int nFlag, bool bSet );
  577. void AllowImmediateDecalPainting();
  578. // Suicide...
  579. virtual void CommitSuicide( bool bExplode = false, bool bForce = false );
  580. virtual void CommitSuicide( const Vector &vecForce, bool bExplode = false, bool bForce = false );
  581. // For debugging...
  582. void ForceOrigin( const Vector &vecOrigin );
  583. // Bot accessors...
  584. void SetTimeBase( float flTimeBase );
  585. float GetTimeBase() const;
  586. void SetLastUserCommand( const CUserCmd &cmd );
  587. const CUserCmd *GetLastUserCommand( void );
  588. virtual bool IsBot() const; // IMPORTANT: This returns true for ANY type of bot. If your game uses different, incompatible types of bots check your specific bot type before casting
  589. virtual bool IsBotOfType( int botType ) const; // return true if this player is a bot of the specific type (zero is invalid)
  590. virtual int GetBotType( void ) const; // return a unique int representing the type of bot instance this is
  591. bool IsPredictingWeapons( void ) const;
  592. int CurrentCommandNumber() const;
  593. const CUserCmd *GetCurrentUserCommand() const;
  594. int GetLockViewanglesTickNumber() const { return m_iLockViewanglesTickNumber; }
  595. QAngle GetLockViewanglesData() const { return m_qangLockViewangles; }
  596. bool IsLerpingFOV( void ) const;
  597. int GetFOV( void ); // Get the current FOV value
  598. int GetDefaultFOV( void ) const; // Default FOV if not specified otherwise
  599. int GetFOVForNetworking( void ); // Get the current FOV used for network computations
  600. bool SetFOV( CBaseEntity *pRequester, int FOV, float zoomRate = 0.0f, int iZoomStart = 0 ); // Alters the base FOV of the player (must have a valid requester)
  601. void SetDefaultFOV( int FOV ); // Sets the base FOV if nothing else is affecting it by zooming
  602. CBaseEntity *GetFOVOwner( void ) { return m_hZoomOwner; }
  603. float GetFOVDistanceAdjustFactor(); // shared between client and server
  604. float GetFOVDistanceAdjustFactorForNetworking();
  605. int GetImpulse( void ) const { return m_nImpulse; }
  606. // Movement constraints
  607. void ActivateMovementConstraint( CBaseEntity *pEntity, const Vector &vecCenter, float flRadius, float flConstraintWidth, float flSpeedFactor );
  608. void DeactivateMovementConstraint( );
  609. // talk control
  610. void NotePlayerTalked() { m_fLastPlayerTalkTime = gpGlobals->curtime; }
  611. float LastTimePlayerTalked() { return m_fLastPlayerTalkTime; }
  612. void DisableButtons( int nButtons );
  613. void EnableButtons( int nButtons );
  614. void ForceButtons( int nButtons );
  615. void UnforceButtons( int nButtons );
  616. //---------------------------------
  617. // Inputs
  618. //---------------------------------
  619. void InputSetHealth( inputdata_t &inputdata );
  620. void InputSetHUDVisibility( inputdata_t &inputdata );
  621. void InputHandleMapEvent( inputdata_t &inputdata );
  622. surfacedata_t *GetSurfaceData( void ) { return m_pSurfaceData; }
  623. void SetLadderNormal( Vector vecLadderNormal ) { m_vecLadderNormal = vecLadderNormal; }
  624. // Here so that derived classes can use the expresser
  625. virtual CAI_Expresser *GetExpresser() { return NULL; };
  626. #if !defined(NO_STEAM)
  627. //----------------------------
  628. // Steam handling
  629. bool GetSteamID( CSteamID *pID );
  630. uint64 GetSteamIDAsUInt64( void );
  631. #endif
  632. float GetRemainingMovementTimeForUserCmdProcessing() const { return m_flMovementTimeForUserCmdProcessingRemaining; }
  633. float ConsumeMovementTimeForUserCmdProcessing( float flTimeNeeded )
  634. {
  635. if ( m_flMovementTimeForUserCmdProcessingRemaining <= 0.0f )
  636. {
  637. return 0.0f;
  638. }
  639. else if ( flTimeNeeded > m_flMovementTimeForUserCmdProcessingRemaining + FLT_EPSILON )
  640. {
  641. float flResult = m_flMovementTimeForUserCmdProcessingRemaining;
  642. m_flMovementTimeForUserCmdProcessingRemaining = 0.0f;
  643. return flResult;
  644. }
  645. else
  646. {
  647. m_flMovementTimeForUserCmdProcessingRemaining -= flTimeNeeded;
  648. if ( m_flMovementTimeForUserCmdProcessingRemaining < 0.0f )
  649. m_flMovementTimeForUserCmdProcessingRemaining = 0.0f;
  650. return flTimeNeeded;
  651. }
  652. }
  653. private:
  654. // How much of a movement time buffer can we process from this user?
  655. float m_flMovementTimeForUserCmdProcessingRemaining;
  656. // For queueing up CUserCmds and running them from PhysicsSimulate
  657. int GetCommandContextCount( void ) const;
  658. CCommandContext *GetCommandContext( int index );
  659. CCommandContext *AllocCommandContext( void );
  660. void RemoveCommandContext( int index );
  661. void RemoveAllCommandContexts( void );
  662. CCommandContext *RemoveAllCommandContextsExceptNewest( void );
  663. void ReplaceContextCommands( CCommandContext *ctx, CUserCmd *pCommands, int nCommands );
  664. int DetermineSimulationTicks( void );
  665. void AdjustPlayerTimeBase( int simulation_ticks );
  666. public:
  667. // How long since this player last interacted with something the game considers an objective/target/goal
  668. float GetTimeSinceLastObjective( void ) const { return ( m_flLastObjectiveTime == -1.f ) ? 999.f : gpGlobals->curtime - m_flLastObjectiveTime; }
  669. void SetLastObjectiveTime( float flTime ) { m_flLastObjectiveTime = flTime; }
  670. // Used by gamemovement to check if the entity is stuck.
  671. int m_StuckLast;
  672. // FIXME: Make these protected or private!
  673. // This player's data that should only be replicated to
  674. // the player and not to other players.
  675. CNetworkVarEmbedded( CPlayerLocalData, m_Local );
  676. #if defined USES_ECON_ITEMS
  677. CNetworkVarEmbedded( CAttributeList, m_AttributeList );
  678. #endif
  679. void InitFogController( void );
  680. void InputSetFogController( inputdata_t &inputdata );
  681. // Used by env_soundscape_triggerable to manage when the player is touching multiple
  682. // soundscape triggers simultaneously.
  683. // The one at the HEAD of the list is always the current soundscape for the player.
  684. CUtlVector<EHANDLE> m_hTriggerSoundscapeList;
  685. // Player data that's sometimes needed by the engine
  686. CNetworkVarEmbedded( CPlayerState, pl );
  687. IMPLEMENT_NETWORK_VAR_FOR_DERIVED( m_fFlags );
  688. IMPLEMENT_NETWORK_VAR_FOR_DERIVED( m_vecViewOffset );
  689. IMPLEMENT_NETWORK_VAR_FOR_DERIVED( m_flFriction );
  690. IMPLEMENT_NETWORK_VAR_FOR_DERIVED( m_iAmmo );
  691. IMPLEMENT_NETWORK_VAR_FOR_DERIVED( m_hGroundEntity );
  692. IMPLEMENT_NETWORK_VAR_FOR_DERIVED( m_lifeState );
  693. IMPLEMENT_NETWORK_VAR_FOR_DERIVED( m_iHealth );
  694. IMPLEMENT_NETWORK_VAR_FOR_DERIVED( m_vecBaseVelocity );
  695. IMPLEMENT_NETWORK_VAR_FOR_DERIVED( m_nNextThinkTick );
  696. IMPLEMENT_NETWORK_VAR_FOR_DERIVED( m_vecVelocity );
  697. IMPLEMENT_NETWORK_VAR_FOR_DERIVED( m_nWaterLevel );
  698. int m_nButtons;
  699. int m_afButtonPressed;
  700. int m_afButtonReleased;
  701. int m_afButtonLast;
  702. int m_afButtonDisabled; // A mask of input flags that are cleared automatically
  703. int m_afButtonForced; // These are forced onto the player's inputs
  704. CNetworkVar( bool, m_fOnTarget ); //Is the crosshair on a target?
  705. char m_szAnimExtension[32];
  706. int m_nUpdateRate; // user snapshot rate cl_updaterate
  707. float m_fLerpTime; // users cl_interp
  708. bool m_bLagCompensation; // user wants lag compenstation
  709. bool m_bPredictWeapons; // user has client side predicted weapons
  710. float GetDeathTime( void ) { return m_flDeathTime; }
  711. void ClearZoomOwner( void );
  712. void SetPreviouslyPredictedOrigin( const Vector &vecAbsOrigin );
  713. const Vector &GetPreviouslyPredictedOrigin() const;
  714. float GetFOVTime( void ){ return m_flFOVTime; }
  715. void AdjustDrownDmg( int nAmount );
  716. #if defined USES_ECON_ITEMS
  717. CEconWearable *GetWearable( int i ) { return m_hMyWearables[i]; }
  718. const CEconWearable *GetWearable( int i ) const { return m_hMyWearables[i]; }
  719. int GetNumWearables( void ) const { return m_hMyWearables.Count(); }
  720. #endif
  721. private:
  722. Activity m_Activity;
  723. float m_flLastObjectiveTime; // Last curtime player touched/killed something the gamemode considers an objective
  724. protected:
  725. void CalcPlayerView( Vector& eyeOrigin, QAngle& eyeAngles, float& fov );
  726. void CalcVehicleView( IServerVehicle *pVehicle, Vector& eyeOrigin, QAngle& eyeAngles,
  727. float& zNear, float& zFar, float& fov );
  728. void CalcObserverView( Vector& eyeOrigin, QAngle& eyeAngles, float& fov );
  729. void CalcViewModelView( const Vector& eyeOrigin, const QAngle& eyeAngles);
  730. virtual void Internal_HandleMapEvent( inputdata_t &inputdata ){}
  731. // FIXME: Make these private! (tf_player uses them)
  732. // Secondary point to derive PVS from when zoomed in with binoculars/sniper rifle. The PVS is
  733. // a merge of the standing origin and this additional origin
  734. Vector m_vecAdditionalPVSOrigin;
  735. // Extra PVS origin if we are using a camera object
  736. Vector m_vecCameraPVSOrigin;
  737. CNetworkHandle( CBaseEntity, m_hUseEntity ); // the player is currently controlling this entity because of +USE latched, NULL if no entity
  738. int m_iTrain; // Train control position
  739. float m_iRespawnFrames; // used in PlayerDeathThink() to make sure players can always respawn
  740. unsigned int m_afPhysicsFlags; // physics flags - set when 'normal' physics should be revisited or overriden
  741. // Vehicles
  742. CNetworkHandle( CBaseEntity, m_hVehicle );
  743. int m_iVehicleAnalogBias;
  744. void UpdateButtonState( int nUserCmdButtonMask );
  745. bool m_bPauseBonusProgress;
  746. CNetworkVar( int, m_iBonusProgress );
  747. CNetworkVar( int, m_iBonusChallenge );
  748. int m_lastDamageAmount; // Last damage taken
  749. Vector m_DmgOrigin;
  750. float m_DmgTake;
  751. float m_DmgSave;
  752. int m_bitsDamageType; // what types of damage has player taken
  753. int m_bitsHUDDamage; // Damage bits for the current fame. These get sent to the hud via gmsgDamage
  754. CNetworkVar( float, m_flDeathTime ); // the time at which the player died (used in PlayerDeathThink())
  755. float m_flDeathAnimTime; // the time at which the player finished their death anim (used in PlayerDeathThink() and ShouldTransmit())
  756. CNetworkVar( int, m_iObserverMode ); // if in spectator mode != 0
  757. CNetworkVar( int, m_iFOV ); // field of view
  758. CNetworkVar( int, m_iDefaultFOV ); // default field of view
  759. CNetworkVar( int, m_iFOVStart ); // What our FOV started at
  760. CNetworkVar( float, m_flFOVTime ); // Time our FOV change started
  761. int m_iObserverLastMode; // last used observer mode
  762. CNetworkHandle( CBaseEntity, m_hObserverTarget ); // entity handle to m_iObserverTarget
  763. bool m_bForcedObserverMode; // true, player was forced by invalid targets to switch mode
  764. CNetworkHandle( CBaseEntity, m_hZoomOwner ); //This is a pointer to the entity currently controlling the player's zoom
  765. //Only this entity can change the zoom state once it has ownership
  766. float m_tbdPrev; // Time-based damage timer
  767. int m_idrowndmg; // track drowning damage taken
  768. int m_idrownrestored; // track drowning damage restored
  769. int m_nPoisonDmg; // track recoverable poison damage taken
  770. int m_nPoisonRestored; // track poison damage restored
  771. // NOTE: bits damage type appears to only be used for time-based damage
  772. BYTE m_rgbTimeBasedDamage[CDMG_TIMEBASED];
  773. // Player Physics Shadow
  774. int m_vphysicsCollisionState;
  775. virtual int SpawnArmorValue( void ) const { return 0; }
  776. float m_fNextSuicideTime; // the time after which the player can next use the suicide command
  777. int m_iSuicideCustomKillFlags;
  778. // Replay mode
  779. float m_fDelay; // replay delay in seconds
  780. float m_fReplayEnd; // time to stop replay mode
  781. int m_iReplayEntity; // follow this entity in replay
  782. private:
  783. void HandleFuncTrain();
  784. // DATA
  785. private:
  786. CUtlVector< CCommandContext > m_CommandContext;
  787. // Player Physics Shadow
  788. protected: //used to be private, but need access for portal mod (Dave Kircher)
  789. IPhysicsPlayerController *m_pPhysicsController;
  790. IPhysicsObject *m_pShadowStand;
  791. IPhysicsObject *m_pShadowCrouch;
  792. Vector m_oldOrigin;
  793. Vector m_vecSmoothedVelocity;
  794. bool m_touchedPhysObject;
  795. bool m_bPhysicsWasFrozen;
  796. private:
  797. int m_iPlayerSound;// the index of the sound list slot reserved for this player
  798. int m_iTargetVolume;// ideal sound volume.
  799. int m_rgItems[MAX_ITEMS];
  800. // these are time-sensitive things that we keep track of
  801. float m_flSwimTime; // how long player has been underwater
  802. float m_flDuckTime; // how long we've been ducking
  803. float m_flDuckJumpTime;
  804. float m_flSuitUpdate; // when to play next suit update
  805. int m_rgSuitPlayList[CSUITPLAYLIST];// next sentencenum to play for suit update
  806. int m_iSuitPlayNext; // next sentence slot for queue storage;
  807. int m_rgiSuitNoRepeat[CSUITNOREPEAT]; // suit sentence no repeat list
  808. float m_rgflSuitNoRepeatTime[CSUITNOREPEAT]; // how long to wait before allowing repeat
  809. float m_flgeigerRange; // range to nearest radiation source
  810. float m_flgeigerDelay; // delay per update of range msg to client
  811. int m_igeigerRangePrev;
  812. bool m_fInitHUD; // True when deferred HUD restart msg needs to be sent
  813. bool m_fGameHUDInitialized;
  814. bool m_fWeapon; // Set this to FALSE to force a reset of the current weapon HUD info
  815. int m_iUpdateTime; // stores the number of frame ticks before sending HUD update messages
  816. int m_iClientBattery; // the Battery currently known by the client. If this changes, send a new
  817. // Autoaim data
  818. QAngle m_vecAutoAim;
  819. int m_lastx, m_lasty; // These are the previous update's crosshair angles, DON"T SAVE/RESTORE
  820. int m_iFrags;
  821. int m_iDeaths;
  822. float m_flNextDecalTime;// next time this player can spray a decal
  823. // Team Handling
  824. // char m_szTeamName[TEAM_NAME_LENGTH];
  825. // Multiplayer handling
  826. PlayerConnectedState m_iConnected;
  827. // from edict_t
  828. // CBasePlayer doesn't send this but CCSPlayer does.
  829. CNetworkVarForDerived( int, m_ArmorValue );
  830. float m_AirFinished;
  831. float m_PainFinished;
  832. // player locking
  833. int m_iPlayerLocked;
  834. protected:
  835. // the player's personal view model
  836. typedef CHandle<CBaseViewModel> CBaseViewModelHandle;
  837. CNetworkArray( CBaseViewModelHandle, m_hViewModel, MAX_VIEWMODELS );
  838. // Last received usercmd (in case we drop a lot of packets )
  839. CUserCmd m_LastCmd;
  840. CUserCmd *m_pCurrentCommand;
  841. int m_iLockViewanglesTickNumber;
  842. QAngle m_qangLockViewangles;
  843. float m_flStepSoundTime; // time to check for next footstep sound
  844. bool m_bAllowInstantSpawn;
  845. #if defined USES_ECON_ITEMS
  846. // Wearables
  847. CUtlVector<CHandle<CEconWearable > > m_hMyWearables;
  848. #endif
  849. private:
  850. // Replicated to all clients
  851. CNetworkVar( float, m_flMaxspeed );
  852. // Not transmitted
  853. float m_flWaterJumpTime; // used to be called teleport_time
  854. Vector m_vecWaterJumpVel;
  855. int m_nImpulse;
  856. float m_flSwimSoundTime;
  857. Vector m_vecLadderNormal;
  858. float m_flFlashTime;
  859. int m_nDrownDmgRate; // Drowning damage in points per second without air.
  860. int m_nNumCrouches; // Number of times we've crouched (for hinting)
  861. bool m_bDuckToggled; // If true, the player is crouching via a toggle
  862. public:
  863. bool GetToggledDuckState( void ) { return m_bDuckToggled; }
  864. void ToggleDuck( void );
  865. float GetStickDist( void );
  866. float m_flForwardMove;
  867. float m_flSideMove;
  868. int m_nNumCrateHudHints;
  869. private:
  870. // Used in test code to teleport the player to random locations in the map.
  871. Vector m_vForcedOrigin;
  872. bool m_bForceOrigin;
  873. // Clients try to run on their own realtime clock, this is this client's clock
  874. CNetworkVar( int, m_nTickBase );
  875. bool m_bGamePaused;
  876. float m_fLastPlayerTalkTime;
  877. CNetworkVar( CBaseCombatWeaponHandle, m_hLastWeapon );
  878. #if !defined( NO_ENTITY_PREDICTION )
  879. CUtlVector< CHandle< CBaseEntity > > m_SimulatedByThisPlayer;
  880. #endif
  881. float m_flOldPlayerZ;
  882. float m_flOldPlayerViewOffsetZ;
  883. bool m_bPlayerUnderwater;
  884. EHANDLE m_hViewEntity;
  885. // Movement constraints
  886. CNetworkHandle( CBaseEntity, m_hConstraintEntity );
  887. CNetworkVector( m_vecConstraintCenter );
  888. CNetworkVar( float, m_flConstraintRadius );
  889. CNetworkVar( float, m_flConstraintWidth );
  890. CNetworkVar( float, m_flConstraintSpeedFactor );
  891. friend class CPlayerMove;
  892. friend class CPlayerClass;
  893. // Player name
  894. char m_szNetname[MAX_PLAYER_NAME_LENGTH];
  895. protected:
  896. // HACK FOR TF2 Prediction
  897. friend class CTFGameMovementRecon;
  898. friend class CGameMovement;
  899. friend class CTFGameMovement;
  900. friend class CHL1GameMovement;
  901. friend class CCSGameMovement;
  902. friend class CHL2GameMovement;
  903. friend class CDODGameMovement;
  904. friend class CPortalGameMovement;
  905. // Accessors for gamemovement
  906. bool IsDucked( void ) const { return m_Local.m_bDucked; }
  907. bool IsDucking( void ) const { return m_Local.m_bDucking; }
  908. float GetStepSize( void ) const { return m_Local.m_flStepSize; }
  909. CNetworkVar( float, m_flLaggedMovementValue );
  910. // These are generated while running usercmds, then given to UpdateVPhysicsPosition after running all queued commands.
  911. Vector m_vNewVPhysicsPosition;
  912. Vector m_vNewVPhysicsVelocity;
  913. Vector m_vecVehicleViewOrigin; // Used to store the calculated view of the player while riding in a vehicle
  914. QAngle m_vecVehicleViewAngles; // Vehicle angles
  915. float m_flVehicleViewFOV; // FOV of the vehicle driver
  916. int m_nVehicleViewSavedFrame; // Used to mark which frame was the last one the view was calculated for
  917. Vector m_vecPreviouslyPredictedOrigin; // Used to determine if non-gamemovement game code has teleported, or tweaked the player's origin
  918. int m_nBodyPitchPoseParam;
  919. CNetworkString( m_szLastPlaceName, MAX_PLACE_NAME_LENGTH );
  920. char m_szNetworkIDString[MAX_NETWORKID_LENGTH];
  921. CPlayerInfo m_PlayerInfo;
  922. // Texture names and surface data, used by CGameMovement
  923. int m_surfaceProps;
  924. surfacedata_t* m_pSurfaceData;
  925. float m_surfaceFriction;
  926. char m_chTextureType;
  927. char m_chPreviousTextureType; // Separate from m_chTextureType. This is cleared if the player's not on the ground.
  928. bool m_bSinglePlayerGameEnding;
  929. public:
  930. float GetLaggedMovementValue( void ){ return m_flLaggedMovementValue; }
  931. void SetLaggedMovementValue( float flValue ) { m_flLaggedMovementValue = flValue; }
  932. inline bool IsAutoKickDisabled( void ) const;
  933. inline void DisableAutoKick( bool disabled );
  934. void DumpPerfToRecipient( CBasePlayer *pRecipient, int nMaxRecords );
  935. // NVNT returns true if user has a haptic device
  936. virtual bool HasHaptics(){return m_bhasHaptics;}
  937. // NVNT sets weather a user should receive haptic device messages.
  938. virtual void SetHaptics(bool has) { m_bhasHaptics = has;}
  939. private:
  940. // NVNT member variable holding if this user is using a haptic device.
  941. bool m_bhasHaptics;
  942. bool m_autoKickDisabled;
  943. struct StepSoundCache_t
  944. {
  945. StepSoundCache_t() : m_usSoundNameIndex( 0 ) {}
  946. CSoundParameters m_SoundParameters;
  947. unsigned short m_usSoundNameIndex;
  948. };
  949. // One for left and one for right side of step
  950. StepSoundCache_t m_StepSoundCache[ 2 ];
  951. CUtlLinkedList< CPlayerSimInfo > m_vecPlayerSimInfo;
  952. CUtlLinkedList< CPlayerCmdInfo > m_vecPlayerCmdInfo;
  953. IntervalTimer m_weaponFiredTimer;
  954. // Store the last time we successfully processed a usercommand
  955. float m_flLastUserCommandTime;
  956. // used to prevent achievement announcement spam
  957. CUtlVector< float > m_flAchievementTimes;
  958. public:
  959. virtual unsigned int PlayerSolidMask( bool brushOnly = false ) const; // returns the solid mask for the given player, so bots can have a more-restrictive set
  960. };
  961. typedef CHandle<CBasePlayer> CBasePlayerHandle;
  962. EXTERN_SEND_TABLE(DT_BasePlayer)
  963. //-----------------------------------------------------------------------------
  964. // Inline methods
  965. //-----------------------------------------------------------------------------
  966. inline bool CBasePlayer::IsBotOfType( int botType ) const
  967. {
  968. // bot type of zero is invalid
  969. return ( GetBotType() != 0 ) && ( GetBotType() == botType );
  970. }
  971. inline int CBasePlayer::GetBotType( void ) const
  972. {
  973. return 0;
  974. }
  975. inline bool CBasePlayer::IsAutoKickDisabled( void ) const
  976. {
  977. return m_autoKickDisabled;
  978. }
  979. inline void CBasePlayer::DisableAutoKick( bool disabled )
  980. {
  981. m_autoKickDisabled = disabled;
  982. }
  983. inline void CBasePlayer::SetAdditionalPVSOrigin( const Vector &vecOrigin )
  984. {
  985. m_vecAdditionalPVSOrigin = vecOrigin;
  986. }
  987. inline void CBasePlayer::SetCameraPVSOrigin( const Vector &vecOrigin )
  988. {
  989. m_vecCameraPVSOrigin = vecOrigin;
  990. }
  991. inline void CBasePlayer::SetMuzzleFlashTime( float flTime )
  992. {
  993. m_flFlashTime = flTime;
  994. }
  995. inline void CBasePlayer::SetUseEntity( CBaseEntity *pUseEntity )
  996. {
  997. m_hUseEntity = pUseEntity;
  998. }
  999. inline CBaseEntity *CBasePlayer::GetUseEntity()
  1000. {
  1001. return m_hUseEntity;
  1002. }
  1003. // Bot accessors...
  1004. inline void CBasePlayer::SetTimeBase( float flTimeBase )
  1005. {
  1006. m_nTickBase = TIME_TO_TICKS( flTimeBase );
  1007. }
  1008. inline void CBasePlayer::SetLastUserCommand( const CUserCmd &cmd )
  1009. {
  1010. m_LastCmd = cmd;
  1011. }
  1012. inline CUserCmd const *CBasePlayer::GetLastUserCommand( void )
  1013. {
  1014. return &m_LastCmd;
  1015. }
  1016. inline bool CBasePlayer::IsPredictingWeapons( void ) const
  1017. {
  1018. return m_bPredictWeapons;
  1019. }
  1020. inline int CBasePlayer::CurrentCommandNumber() const
  1021. {
  1022. Assert( m_pCurrentCommand );
  1023. return m_pCurrentCommand->command_number;
  1024. }
  1025. inline const CUserCmd *CBasePlayer::GetCurrentUserCommand() const
  1026. {
  1027. Assert( m_pCurrentCommand );
  1028. return m_pCurrentCommand;
  1029. }
  1030. inline IServerVehicle *CBasePlayer::GetVehicle()
  1031. {
  1032. CBaseEntity *pVehicleEnt = m_hVehicle.Get();
  1033. return pVehicleEnt ? pVehicleEnt->GetServerVehicle() : NULL;
  1034. }
  1035. inline CBaseEntity *CBasePlayer::GetVehicleEntity()
  1036. {
  1037. return m_hVehicle.Get();
  1038. }
  1039. inline bool CBasePlayer::IsInAVehicle( void ) const
  1040. {
  1041. return ( NULL != m_hVehicle.Get() ) ? true : false;
  1042. }
  1043. inline void CBasePlayer::SetTouchedPhysics( bool bTouch )
  1044. {
  1045. m_touchedPhysObject = bTouch;
  1046. }
  1047. inline bool CBasePlayer::TouchedPhysics( void )
  1048. {
  1049. return m_touchedPhysObject;
  1050. }
  1051. inline void CBasePlayer::OnMyWeaponFired( CBaseCombatWeapon *weapon )
  1052. {
  1053. m_weaponFiredTimer.Start();
  1054. }
  1055. inline float CBasePlayer::GetTimeSinceWeaponFired( void ) const
  1056. {
  1057. return m_weaponFiredTimer.GetElapsedTime();
  1058. }
  1059. inline bool CBasePlayer::IsFiringWeapon( void ) const
  1060. {
  1061. return m_weaponFiredTimer.HasStarted() && m_weaponFiredTimer.IsLessThen( 1.0f );
  1062. }
  1063. //-----------------------------------------------------------------------------
  1064. // Converts an entity to a player
  1065. //-----------------------------------------------------------------------------
  1066. inline CBasePlayer *ToBasePlayer( CBaseEntity *pEntity )
  1067. {
  1068. if ( !pEntity || !pEntity->IsPlayer() )
  1069. return NULL;
  1070. #if _DEBUG
  1071. return dynamic_cast<CBasePlayer *>( pEntity );
  1072. #else
  1073. return static_cast<CBasePlayer *>( pEntity );
  1074. #endif
  1075. }
  1076. inline const CBasePlayer *ToBasePlayer( const CBaseEntity *pEntity )
  1077. {
  1078. if ( !pEntity || !pEntity->IsPlayer() )
  1079. return NULL;
  1080. #if _DEBUG
  1081. return dynamic_cast<const CBasePlayer *>( pEntity );
  1082. #else
  1083. return static_cast<const CBasePlayer *>( pEntity );
  1084. #endif
  1085. }
  1086. //--------------------------------------------------------------------------------------------------------------
  1087. /**
  1088. * DEPRECATED: Use CollectPlayers() instead.
  1089. * Iterate over all active players in the game, invoking functor on each.
  1090. * If functor returns false, stop iteration and return false.
  1091. */
  1092. template < typename Functor >
  1093. bool ForEachPlayer( Functor &func )
  1094. {
  1095. for( int i=1; i<=gpGlobals->maxClients; ++i )
  1096. {
  1097. CBasePlayer *player = static_cast<CBasePlayer *>( UTIL_PlayerByIndex( i ) );
  1098. if (player == NULL)
  1099. continue;
  1100. if (FNullEnt( player->edict() ))
  1101. continue;
  1102. if (!player->IsPlayer())
  1103. continue;
  1104. if( !player->IsConnected() )
  1105. continue;
  1106. if (func( player ) == false)
  1107. return false;
  1108. }
  1109. return true;
  1110. }
  1111. //-----------------------------------------------------------------------------------------------
  1112. /**
  1113. * The interface for an iterative player functor
  1114. */
  1115. class IPlayerFunctor
  1116. {
  1117. public:
  1118. virtual void OnBeginIteration( void ) { } // invoked once before iteration begins
  1119. virtual bool operator() ( CBasePlayer *player ) = 0;
  1120. virtual void OnEndIteration( bool allElementsIterated ) { } // invoked once after iteration is complete whether successful or not
  1121. };
  1122. //--------------------------------------------------------------------------------------------------------------
  1123. /**
  1124. * DEPRECATED: Use CollectPlayers() instead.
  1125. * Specialization of ForEachPlayer template for IPlayerFunctors
  1126. */
  1127. template <>
  1128. inline bool ForEachPlayer( IPlayerFunctor &func )
  1129. {
  1130. func.OnBeginIteration();
  1131. bool isComplete = true;
  1132. for( int i=1; i<=gpGlobals->maxClients; ++i )
  1133. {
  1134. CBasePlayer *player = static_cast<CBasePlayer *>( UTIL_PlayerByIndex( i ) );
  1135. if (player == NULL)
  1136. continue;
  1137. if (FNullEnt( player->edict() ))
  1138. continue;
  1139. if (!player->IsPlayer())
  1140. continue;
  1141. if( !player->IsConnected() )
  1142. continue;
  1143. if (func( player ) == false)
  1144. {
  1145. isComplete = false;
  1146. break;
  1147. }
  1148. }
  1149. func.OnEndIteration( isComplete );
  1150. return isComplete;
  1151. }
  1152. //--------------------------------------------------------------------------------------------------------------
  1153. //
  1154. // Collect all valid, connected players into given vector.
  1155. // Returns number of players collected.
  1156. //
  1157. #define COLLECT_ONLY_LIVING_PLAYERS true
  1158. #define APPEND_PLAYERS true
  1159. template < typename T >
  1160. int CollectPlayers( CUtlVector< T * > *playerVector, int team = TEAM_ANY, bool isAlive = false, bool shouldAppend = false )
  1161. {
  1162. if ( !shouldAppend )
  1163. {
  1164. playerVector->RemoveAll();
  1165. }
  1166. for( int i=1; i<=gpGlobals->maxClients; ++i )
  1167. {
  1168. CBasePlayer *player = UTIL_PlayerByIndex( i );
  1169. if ( player == NULL )
  1170. continue;
  1171. if ( FNullEnt( player->edict() ) )
  1172. continue;
  1173. if ( !player->IsPlayer() )
  1174. continue;
  1175. if ( !player->IsConnected() )
  1176. continue;
  1177. if ( team != TEAM_ANY && player->GetTeamNumber() != team )
  1178. continue;
  1179. if ( isAlive && !player->IsAlive() )
  1180. continue;
  1181. playerVector->AddToTail( assert_cast< T * >( player ) );
  1182. }
  1183. return playerVector->Count();
  1184. }
  1185. template < typename T >
  1186. int CollectHumanPlayers( CUtlVector< T * > *playerVector, int team = TEAM_ANY, bool isAlive = false, bool shouldAppend = false )
  1187. {
  1188. if ( !shouldAppend )
  1189. {
  1190. playerVector->RemoveAll();
  1191. }
  1192. for( int i=1; i<=gpGlobals->maxClients; ++i )
  1193. {
  1194. CBasePlayer *player = UTIL_PlayerByIndex( i );
  1195. if ( player == NULL )
  1196. continue;
  1197. if ( FNullEnt( player->edict() ) )
  1198. continue;
  1199. if ( !player->IsPlayer() )
  1200. continue;
  1201. if ( player->IsBot() )
  1202. continue;
  1203. if ( !player->IsConnected() )
  1204. continue;
  1205. if ( team != TEAM_ANY && player->GetTeamNumber() != team )
  1206. continue;
  1207. if ( isAlive && !player->IsAlive() )
  1208. continue;
  1209. playerVector->AddToTail( assert_cast< T * >( player ) );
  1210. }
  1211. return playerVector->Count();
  1212. }
  1213. enum
  1214. {
  1215. VEHICLE_ANALOG_BIAS_NONE = 0,
  1216. VEHICLE_ANALOG_BIAS_FORWARD,
  1217. VEHICLE_ANALOG_BIAS_REVERSE,
  1218. };
  1219. #endif // PLAYER_H