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.

1763 lines
62 KiB

  1. //========= Copyright (c) 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 "simtimer.h"
  19. #include "vprof.h"
  20. #include "iclient.h"
  21. #include "input_device.h"
  22. #include "vote_controller.h"
  23. class CLogicPlayerProxy;
  24. // For queuing and processing usercmds
  25. class CCommandContext
  26. {
  27. public:
  28. CUtlVector< CUserCmd > cmds;
  29. int numcmds;
  30. int totalcmds;
  31. int dropped_packets;
  32. bool paused;
  33. };
  34. // Info about last 20 or so updates to the
  35. class CPlayerCmdInfo
  36. {
  37. public:
  38. CPlayerCmdInfo() :
  39. m_flTime( 0.0f ), m_nNumCmds( 0 ), m_nDroppedPackets( 0 )
  40. {
  41. }
  42. // realtime of sample
  43. float m_flTime;
  44. // # of CUserCmds in this update
  45. int m_nNumCmds;
  46. // # of dropped packets on the link
  47. int m_nDroppedPackets;
  48. };
  49. class CPlayerSimInfo
  50. {
  51. public:
  52. CPlayerSimInfo() :
  53. 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 )
  54. {
  55. }
  56. // realtime of sample
  57. float m_flTime;
  58. // # of CUserCmds in this update
  59. int m_nNumCmds;
  60. // If clock needed correction, # of ticks added/removed
  61. int m_nTicksCorrected; // +ve or -ve
  62. // player's m_flSimulationTime at end of frame
  63. float m_flFinalSimulationTime;
  64. float m_flGameSimulationTime;
  65. // estimate of server perf
  66. float m_flServerFrameTime;
  67. Vector m_vecAbsOrigin;
  68. };
  69. //-----------------------------------------------------------------------------
  70. // Forward declarations:
  71. //-----------------------------------------------------------------------------
  72. class CBaseCombatWeapon;
  73. class CBaseViewModel;
  74. class CTeam;
  75. class IPhysicsPlayerController;
  76. class IServerVehicle;
  77. class CUserCmd;
  78. class CFuncLadder;
  79. class CNavArea;
  80. class CHintSystem;
  81. class CAI_Expresser;
  82. class CAI_Node;
  83. class CAI_Link;
  84. class CTonemapTrigger;
  85. // for step sounds
  86. struct surfacedata_t;
  87. // !!!set this bit on guns and stuff that should never respawn.
  88. #define SF_NORESPAWN ( 1 << 30 )
  89. //
  90. // generic player
  91. //
  92. //-----------------------------------------------------
  93. //This is Half-Life player entity
  94. //-----------------------------------------------------
  95. #define CSUITPLAYLIST 4 // max of 4 suit sentences queued up at any time
  96. #define SUIT_REPEAT_OK 0
  97. #define SUIT_NEXT_IN_30SEC 30
  98. #define SUIT_NEXT_IN_1MIN 60
  99. #define SUIT_NEXT_IN_5MIN 300
  100. #define SUIT_NEXT_IN_10MIN 600
  101. #define SUIT_NEXT_IN_30MIN 1800
  102. #define SUIT_NEXT_IN_1HOUR 3600
  103. #define CSUITNOREPEAT 32
  104. #define TEAM_NAME_LENGTH 16
  105. // constant items
  106. #define ITEM_HEALTHKIT 1
  107. #define ITEM_BATTERY 4
  108. #define AUTOAIM_2DEGREES 0.0348994967025
  109. #define AUTOAIM_5DEGREES 0.08715574274766
  110. #define AUTOAIM_8DEGREES 0.1391731009601
  111. #define AUTOAIM_10DEGREES 0.1736481776669
  112. #define AUTOAIM_20DEGREES 0.3490658503989
  113. enum PlayerConnectedState
  114. {
  115. PlayerConnected,
  116. PlayerDisconnecting,
  117. PlayerDisconnected,
  118. };
  119. enum AimResults
  120. {
  121. AIMRESULTS_NONE,
  122. AIMRESULTS_ONTARGET,
  123. AIMRESULTS_ASSISTED,
  124. };
  125. extern bool gInitHUD;
  126. extern ConVar *sv_cheats;
  127. class CBasePlayer;
  128. class CPlayerInfo : public IBotController, public IPlayerInfo
  129. {
  130. public:
  131. CPlayerInfo () { m_pParent = NULL; }
  132. ~CPlayerInfo () {}
  133. void SetParent( CBasePlayer *parent ) { m_pParent = parent; }
  134. // IPlayerInfo interface
  135. virtual const char *GetName();
  136. virtual int GetUserID();
  137. virtual const char *GetNetworkIDString();
  138. virtual int GetTeamIndex();
  139. virtual void ChangeTeam( int iTeamNum );
  140. virtual int GetFragCount();
  141. virtual int GetAssistsCount();
  142. virtual int GetDeathCount();
  143. virtual bool IsConnected();
  144. virtual int GetArmorValue();
  145. virtual bool IsHLTV();
  146. #if defined( REPLAY_ENABLED )
  147. virtual bool IsReplay();
  148. #endif
  149. virtual bool IsPlayer();
  150. virtual bool IsFakeClient();
  151. virtual bool IsDead();
  152. virtual bool IsInAVehicle();
  153. virtual bool IsObserver();
  154. virtual const Vector GetAbsOrigin();
  155. virtual const QAngle GetAbsAngles();
  156. virtual const Vector GetPlayerMins();
  157. virtual const Vector GetPlayerMaxs();
  158. virtual const char *GetWeaponName();
  159. virtual const char *GetModelName();
  160. virtual const int GetHealth();
  161. virtual const int GetMaxHealth();
  162. // bot specific functions
  163. virtual void SetAbsOrigin( Vector & vec );
  164. virtual void SetAbsAngles( QAngle & ang );
  165. virtual void RemoveAllItems( bool removeSuit );
  166. virtual void SetActiveWeapon( const char *WeaponName );
  167. virtual void SetLocalOrigin( const Vector& origin );
  168. virtual const Vector GetLocalOrigin( void );
  169. virtual void SetLocalAngles( const QAngle& angles );
  170. virtual const QAngle GetLocalAngles( void );
  171. virtual void PostClientMessagesSent( void );
  172. virtual bool IsEFlagSet( int nEFlagMask );
  173. virtual void RunPlayerMove( CBotCmd *ucmd );
  174. virtual void SetLastUserCommand( const CBotCmd &cmd );
  175. virtual CBotCmd GetLastUserCommand();
  176. private:
  177. CBasePlayer *m_pParent;
  178. };
  179. class CBasePlayer : public CBaseCombatCharacter
  180. {
  181. public:
  182. DECLARE_CLASS( CBasePlayer, CBaseCombatCharacter );
  183. protected:
  184. // HACK FOR BOTS
  185. friend class CBotManager;
  186. static edict_t *s_PlayerEdict; // must be set before calling constructor
  187. public:
  188. DECLARE_DATADESC();
  189. DECLARE_SERVERCLASS();
  190. // script description
  191. DECLARE_ENT_SCRIPTDESC();
  192. CBasePlayer();
  193. ~CBasePlayer();
  194. void StartUserMessageThrottling( char const *pchMessageNames[], int nNumMessageNames );
  195. void FinishUserMessageThrottling();
  196. bool ShouldThrottleUserMessage( char const *pchMessageName );
  197. // IPlayerInfo passthrough (because we can't do multiple inheritance)
  198. IPlayerInfo *GetPlayerInfo() { return &m_PlayerInfo; }
  199. IBotController *GetBotController() { return &m_PlayerInfo; }
  200. virtual void SetModel( const char *szModelName );
  201. void SetBodyPitch( float flPitch );
  202. virtual void UpdateOnRemove( void );
  203. static CBasePlayer *CreatePlayer( const char *className, edict_t *ed );
  204. virtual void CreateViewModel( int viewmodelindex = 0 );
  205. CBaseViewModel *GetViewModel( int viewmodelindex = 0 );
  206. void HideViewModels( void );
  207. void DestroyViewModels( void );
  208. CPlayerState *PlayerData( void ) { return pl.Get(); }
  209. const CPlayerState *PlayerData( void ) const { return pl.Get(); }
  210. int RequiredEdictIndex( void ) { return ENTINDEX(edict()); }
  211. void LockPlayerInPlace( void );
  212. void UnlockPlayer( void );
  213. virtual void DrawDebugGeometryOverlays(void);
  214. // Networking is about to update this entity, let it override and specify it's own pvs
  215. virtual void SetupVisibility( CBaseEntity *pViewEntity, unsigned char *pvs, int pvssize );
  216. virtual int UpdateTransmitState();
  217. virtual int ShouldTransmit( const CCheckTransmitInfo *pInfo );
  218. virtual bool ShouldCheckOcclusion( CBasePlayer *pOtherPlayer ) { return false; }
  219. // Returns true if this player wants pPlayer to be moved back in time when this player runs usercmds.
  220. // Saves a lot of overhead on the server if we can cull out entities that don't need to lag compensate
  221. // (like team members, entities out of our PVS, etc).
  222. virtual bool WantsLagCompensationOnEntity( const CBaseEntity *entity, const CUserCmd *pCmd, const CBitVec<MAX_EDICTS> *pEntityTransmitBits ) const;
  223. virtual void Spawn( void );
  224. virtual void Activate( void );
  225. virtual void SharedSpawn(); // Shared between client and server.
  226. virtual void ForceRespawn( void );
  227. virtual void PostSpawnPointSelection( void );
  228. virtual void InitialSpawn( void );
  229. virtual void InitHUD( void ) {}
  230. virtual void ShowViewPortPanel( const char * name, bool bShow = true, KeyValues *data = NULL );
  231. virtual const char * GetPlayerModelName( void );
  232. virtual void PlayerDeathThink( void );
  233. virtual void PlayerForceTeamThink( void );
  234. virtual void Jump( void );
  235. virtual void Duck( void );
  236. const char *GetTracerType( void );
  237. void MakeTracer( const Vector &vecTracerSrc, const trace_t &tr, int iTracerType );
  238. void DoImpactEffect( trace_t &tr, int nDamageType );
  239. // If a map clean up has been done after a respawn, this function will reassign the entity pointers to those map entities that were deleted.
  240. void UpdateMapEntityPointers( void );
  241. #if !defined( NO_ENTITY_PREDICTION )
  242. void AddToPlayerSimulationList( CBaseEntity *other );
  243. void RemoveFromPlayerSimulationList( CBaseEntity *other );
  244. void SimulatePlayerSimulatedEntities( void );
  245. void ClearPlayerSimulationList( void );
  246. #endif
  247. // Physics simulation (player executes it's usercmd's here)
  248. virtual void PhysicsSimulate( void );
  249. // Forces processing of usercmds (e.g., even if game is paused, etc.)
  250. void ForceSimulation();
  251. virtual unsigned int PhysicsSolidMaskForEntity( void ) const;
  252. // Move us a bit to ensure we're spawning somewhere we can actually move around.
  253. void EnsureValidSpawnLocation();
  254. virtual void PreThink( void );
  255. virtual void PostThink( void );
  256. virtual int TakeHealth( float flHealth, int bitsDamageType );
  257. virtual void TraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr );
  258. bool ShouldTakeDamageInCommentaryMode( const CTakeDamageInfo &inputInfo );
  259. virtual int OnTakeDamage( const CTakeDamageInfo &info );
  260. virtual void DamageEffect(float flDamage, int fDamageType);
  261. virtual void OnSwitchWeapons( CBaseCombatWeapon* pWeapon ){}
  262. virtual void OnDamagedByExplosion( const CTakeDamageInfo &info );
  263. virtual bool CanKickFromTeam( int kickTeam ) { return GetTeamNumber() == kickTeam; }
  264. void PauseBonusProgress( bool bPause = true );
  265. void SetBonusProgress( int iBonusProgress );
  266. void SetBonusChallenge( int iBonusChallenge );
  267. int GetBonusProgress() const { return m_iBonusProgress; }
  268. int GetBonusChallenge() const { return m_iBonusChallenge; }
  269. virtual Vector EyePosition( ); // position of eyes
  270. const QAngle &EyeAngles( );
  271. void EyePositionAndVectors( Vector *pPosition, Vector *pForward, Vector *pRight, Vector *pUp );
  272. virtual const QAngle &LocalEyeAngles(); // Direction of eyes
  273. void EyeVectors( Vector *pForward, Vector *pRight = NULL, Vector *pUp = NULL );
  274. void CacheVehicleView( void ); // Calculate and cache the position of the player in the vehicle
  275. // Sets the view angles
  276. void SnapEyeAngles( const QAngle &viewAngles );
  277. virtual QAngle BodyAngles();
  278. virtual Vector BodyTarget( const Vector &posSrc, bool bNoisy);
  279. virtual bool ShouldFadeOnDeath( void ) { return FALSE; }
  280. virtual const impactdamagetable_t &GetPhysicsImpactDamageTable();
  281. virtual int OnTakeDamage_Alive( const CTakeDamageInfo &info );
  282. virtual void Event_Killed( const CTakeDamageInfo &info );
  283. // Notifier that I've killed some other entity. (called from Victim's Event_Killed).
  284. virtual void Event_KilledOther( CBaseEntity *pVictim, const CTakeDamageInfo &info );
  285. void Event_Dying( void );
  286. bool IsHLTV( void ) const { return pl.hltv; }
  287. bool IsReplay( void ) const { return pl.replay; }
  288. virtual bool IsPlayer( void ) const { return true; } // Spectators return TRUE for this, use IsObserver to seperate cases
  289. virtual bool IsNetClient( void ) const { return true; } // Bots should return FALSE for this, they can't receive NET messages
  290. // Spectators should return TRUE for this
  291. virtual bool IsFakeClient( void ) const;
  292. // Get the client index (entindex-1).
  293. int GetClientIndex() { return ENTINDEX( edict() ) - 1; }
  294. // returns the player name
  295. #ifdef _PS3
  296. const char * GetPlayerName() const
  297. {
  298. if (!strcmp(m_szNetname, ""))
  299. {
  300. return "empty";
  301. }
  302. else
  303. {
  304. return m_szNetname;
  305. }
  306. }
  307. #else
  308. const char * GetPlayerName() const { return m_szNetname; }
  309. #endif
  310. void SetPlayerName( const char *name );
  311. virtual const char * GetCharacterDisplayName() { return GetPlayerName(); }
  312. int GetUserID() const { return engine->GetPlayerUserId( edict() ); }
  313. const char * GetNetworkIDString();
  314. virtual const Vector GetPlayerMins( void ) const; // uses local player
  315. virtual const Vector GetPlayerMaxs( void ) const; // uses local player
  316. virtual void UpdateCollisionBounds( void );
  317. void VelocityPunch( const Vector &vecForce );
  318. void ViewPunch( const QAngle &angleOffset );
  319. void ViewPunchReset( float tolerance = 0 );
  320. void ShowViewModel( bool bShow );
  321. void ShowCrosshair( bool bShow );
  322. bool ScriptIsPlayerNoclipping( void );
  323. virtual void NoClipStateChanged( void ) { };
  324. // View model prediction setup
  325. void CalcView( Vector &eyeOrigin, QAngle &eyeAngles, float &zNear, float &zFar, float &fov );
  326. // Handle view smoothing when going up stairs
  327. void SmoothViewOnStairs( Vector& eyeOrigin );
  328. virtual float CalcRoll (const QAngle& angles, const Vector& velocity, float rollangle, float rollspeed);
  329. void CalcViewRoll( QAngle& eyeAngles );
  330. virtual void CalcViewBob( Vector& eyeOrigin );
  331. virtual void CalcAddViewmodelCameraAnimation( Vector& eyeOrigin, QAngle& eyeAngles );
  332. virtual int Save( ISave &save );
  333. virtual int Restore( IRestore &restore );
  334. virtual bool ShouldSavePhysics();
  335. virtual void OnRestore( void );
  336. virtual void PackDeadPlayerItems( void );
  337. virtual void RemoveAllItems( bool removeSuit );
  338. bool IsDead() const;
  339. #ifdef CSTRIKE_DLL
  340. virtual bool IsRunning( void ) const { return false; } // bot support under cstrike (AR)
  341. #endif
  342. bool HasPhysicsFlag( unsigned int flag ) { return (m_afPhysicsFlags & flag) != 0; }
  343. virtual CBaseCombatCharacter *ActivePlayerCombatCharacter( void ) { return this; }
  344. // Weapon stuff
  345. virtual Vector Weapon_ShootPosition( );
  346. virtual bool Weapon_CanUse( CBaseCombatWeapon *pWeapon );
  347. virtual void Weapon_Equip( CBaseCombatWeapon *pWeapon );
  348. virtual void Weapon_Drop( CBaseCombatWeapon *pWeapon, const Vector *pvecTarget /* = NULL */, const Vector *pVelocity /* = NULL */ );
  349. virtual bool Weapon_Switch( CBaseCombatWeapon *pWeapon, int viewmodelindex = 0 ); // Switch to given weapon if has ammo (false if failed)
  350. virtual void Weapon_SetLast( CBaseCombatWeapon *pWeapon );
  351. virtual bool Weapon_ShouldSetLast( CBaseCombatWeapon *pOldWeapon, CBaseCombatWeapon *pNewWeapon ) { return true; }
  352. virtual bool Weapon_ShouldSelectItem( CBaseCombatWeapon *pWeapon );
  353. void Weapon_DropSlot( int weaponSlot );
  354. CBaseCombatWeapon *Weapon_GetLast( void ) { return m_hLastWeapon.Get(); }
  355. virtual bool HasUnlockableWeapons( int iUnlockedableIndex ) { return false; }
  356. bool HasUnlockedWpn( int iIndex ) { return false; }
  357. bool HasAnyAmmoOfType( int nAmmoIndex );
  358. // JOHN: sends custom messages if player HUD data has changed (eg health, ammo)
  359. virtual void UpdateClientData( void );
  360. virtual void UpdateBattery( void );
  361. virtual void RumbleEffect( unsigned char index, unsigned char rumbleData, unsigned char rumbleFlags );
  362. // Player is moved across the transition by other means
  363. virtual int ObjectCaps( void ) { return BaseClass::ObjectCaps() & ~FCAP_ACROSS_TRANSITION; }
  364. virtual void Precache( void );
  365. bool IsOnLadder( void );
  366. virtual void ExitLadder() {}
  367. virtual surfacedata_t *GetLadderSurface( const Vector &origin );
  368. #define PLAY_FLASHLIGHT_SOUND true
  369. virtual void SetFlashlightEnabled( bool bState ) { };
  370. virtual int FlashlightIsOn( void ) { return false; }
  371. virtual bool FlashlightTurnOn( bool playSound = false ) { return false; }; // Skip sounds when not necessary
  372. virtual void FlashlightTurnOff( bool playSound = false ) { }; // Skip sounds when not necessary
  373. virtual bool IsIlluminatedByFlashlight( CBaseEntity *pEntity, float *flReturnDot ) {return false; }
  374. virtual void UpdatePlayerSound ( void );
  375. virtual void UpdateStepSound( surfacedata_t *psurface, const Vector &vecOrigin, const Vector &vecVelocity );
  376. virtual void PlayStepSound( Vector &vecOrigin, surfacedata_t *psurface, float fvol, bool force );
  377. virtual void GetStepSoundVelocities( float *velwalk, float *velrun );
  378. virtual void SetStepSoundTime( stepsoundtimes_t iStepSoundTime, bool bWalking );
  379. virtual void DeathSound( const CTakeDamageInfo &info );
  380. const Vector & GetMovementCollisionNormal( void ) const; // return the normal of the surface we last collided with
  381. const Vector & GetGroundNormal( void ) const;
  382. virtual void SetFogController( CFogController *pFogController );
  383. // return the entity used for soundscape radius checks
  384. virtual CBaseEntity *GetSoundscapeListener();
  385. Class_T Classify ( void );
  386. virtual void SetAnimation( PLAYER_ANIM playerAnim );
  387. virtual void OnMainActivityComplete( Activity newActivity, Activity oldActivity ) {}
  388. virtual void OnMainActivityInterrupted( Activity newActivity, Activity oldActivity ) {}
  389. void SetWeaponAnimType( const char *szExtention );
  390. // custom player functions
  391. virtual void ImpulseCommands( void );
  392. virtual void CheatImpulseCommands( int iImpulse );
  393. virtual bool ClientCommand( const CCommand &args );
  394. static CBasePlayer* GetPlayerBySteamID( const CSteamID &steamID );
  395. void NotifySinglePlayerGameEnding() { m_bSinglePlayerGameEnding = true; }
  396. bool IsSinglePlayerGameEnding() { return m_bSinglePlayerGameEnding == true; }
  397. bool HandleVoteCommands( const CCommand &args );
  398. IntervalTimer & GetLastHeldVoteTimer(){ return m_lastHeldVoteTimer; }
  399. CVoteController * GetTeamVoteController( void ); // returns one of the two team vote controllers, g_voteControllerT or g_voteControllerCT
  400. // Observer functions
  401. virtual bool StartObserverMode(int mode); // true, if successful
  402. virtual void StopObserverMode( void ); // stop spectator mode
  403. virtual bool ModeWantsSpectatorGUI( int iMode ) { return true; }
  404. virtual bool SetObserverMode(int mode); // sets new observer mode, returns true if successful
  405. virtual int GetObserverMode( void ); // returns observer mode or OBS_NONE
  406. virtual bool SetObserverTarget(CBaseEntity * target);
  407. virtual void ObserverUse( bool bIsPressed ); // observer pressed use
  408. virtual CBaseEntity *GetObserverTarget( void ); // returns players targer or NULL
  409. virtual CBaseEntity *FindNextObserverTarget( bool bReverse ); // returns next/prev player to follow or NULL
  410. virtual int GetNextObserverSearchStartPoint( bool bReverse ); // Where we should start looping the player list in a FindNextObserverTarget call
  411. virtual bool PassesObserverFilter( const CBaseEntity *entity ); // returns true if the entity passes the specified filter
  412. virtual bool IsValidObserverTarget(CBaseEntity * target); // true, if player is allowed to see this target
  413. virtual void CheckObserverSettings(); // checks, if target still valid (didn't die etc)
  414. virtual void JumptoPosition(const Vector &origin, const QAngle &angles);
  415. virtual void SpecLerptoPosition(const Vector &origin, const QAngle &angles, float flTime);
  416. virtual void ForceObserverMode(int mode); // sets a temporary mode, force because of invalid targets
  417. virtual void ResetObserverMode(); // resets all observer related settings
  418. virtual void ValidateCurrentObserverTarget( void ); // Checks the current observer target, and moves on if it's not valid anymore
  419. virtual void AttemptToExitFreezeCam( void );
  420. virtual bool StartReplayMode( float fDelay, float fDuration, int iEntity );
  421. virtual void StopReplayMode();
  422. virtual int GetDelayTicks();
  423. virtual int GetReplayEntity();
  424. CLogicPlayerProxy *GetPlayerProxy( void );
  425. void FirePlayerProxyOutput( const char *pszOutputName, variant_t variant, CBaseEntity *pActivator, CBaseEntity *pCaller );
  426. virtual void CreateCorpse( void ) { }
  427. virtual CBaseEntity *EntSelectSpawnPoint( void );
  428. // Vehicles
  429. virtual bool IsInAVehicle( void ) const;
  430. bool CanEnterVehicle( IServerVehicle *pVehicle, int nRole );
  431. virtual bool GetInVehicle( IServerVehicle *pVehicle, int nRole );
  432. virtual void LeaveVehicle( const Vector &vecExitPoint = vec3_origin, const QAngle &vecExitAngles = vec3_angle );
  433. int GetVehicleAnalogControlBias() { return m_iVehicleAnalogBias; }
  434. void SetVehicleAnalogControlBias( int bias ) { m_iVehicleAnalogBias = bias; }
  435. // override these for
  436. virtual void OnVehicleStart() {}
  437. virtual void OnVehicleEnd( Vector &playerDestPosition ) {}
  438. IServerVehicle *GetVehicle();
  439. CBaseEntity *GetVehicleEntity( void );
  440. bool UsingStandardWeaponsInVehicle( void );
  441. void AddPoints( int score, bool bAllowNegativeScore );
  442. void AddPointsToTeam( int score, bool bAllowNegativeScore );
  443. virtual bool BumpWeapon( CBaseCombatWeapon *pWeapon );
  444. bool RemovePlayerItem( CBaseCombatWeapon *pItem );
  445. CBaseEntity *HasNamedPlayerItem( const char *pszItemName );
  446. bool HasWeapons( void );// do I have ANY weapons?
  447. virtual void SelectLastItem(void);
  448. virtual void SelectItem( const char *pstr, int iSubType = 0 );
  449. void ItemPreFrame( void );
  450. virtual void ItemPostFrame( void );
  451. virtual CBaseEntity *GiveNamedItem( const char *pchName, int iSubType = 0, CEconItemView *pScriptItem = NULL, bool bForce = false );
  452. void EnableControl(bool fControl);
  453. virtual void CheckTrainUpdate( void );
  454. void AbortReload( void );
  455. void SendAmmoUpdate(void);
  456. void WaterMove( void );
  457. float GetWaterJumpTime() const;
  458. void SetWaterJumpTime( float flWaterJumpTime );
  459. float GetSwimSoundTime( void ) const;
  460. void SetSwimSoundTime( float flSwimSoundTime );
  461. virtual void SetPlayerUnderwater( bool state );
  462. void UpdateUnderwaterState( void );
  463. bool IsPlayerUnderwater( void ) { return m_bPlayerUnderwater; }
  464. virtual bool CanBreatheUnderwater() const { return false; }
  465. virtual bool CanRecoverCurrentDrowningDamage( void ) const { return true; }// Are we allowed to later recover the drowning damage we are taking right now? (Not, can we right now recover drowning damage.)
  466. virtual void PlayerUse( void );
  467. virtual void PlayUseDenySound() {}
  468. virtual CBaseEntity *FindUseEntity( void );
  469. virtual bool IsUseableEntity( CBaseEntity *pEntity, unsigned int requiredCaps );
  470. bool ClearUseEntity();
  471. CBaseEntity *DoubleCheckUseNPC( CBaseEntity *pNPC, const Vector &vecSrc, const Vector &vecDir );
  472. // physics interactions
  473. // mass/size limit set to zero for none
  474. static bool CanPickupObject( CBaseEntity *pObject, float massLimit, float sizeLimit );
  475. virtual void PickupObject( CBaseEntity *pObject, bool bLimitMassAndSize = true ) {}
  476. virtual void ForceDropOfCarriedPhysObjects( CBaseEntity *pOnlyIfHoldindThis = NULL ) {}
  477. virtual float GetHeldObjectMass( IPhysicsObject *pHeldObject );
  478. void CheckSuitUpdate();
  479. void SetSuitUpdate(char *name, int fgroup, int iNoRepeat);
  480. virtual void UpdateGeigerCounter( void );
  481. void CheckTimeBasedDamage( void );
  482. void ResetAutoaim( void );
  483. virtual Vector GetAutoaimVector( float flScale );
  484. virtual Vector GetAutoaimVector( float flScale, float flMaxDist );
  485. virtual Vector GetAutoaimVector( float flScale, float flMaxDist, float flMaxDeflection, AimResults *pAimResults );
  486. virtual void GetAutoaimVector( autoaim_params_t &params );
  487. virtual bool ShouldAutoaim( void );
  488. void SetViewEntity( CBaseEntity *pEntity, bool bShouldDrawPlayer = true );
  489. CBaseEntity *GetViewEntity( void ) { return m_hViewEntity; }
  490. virtual void ForceClientDllUpdate( void ); // Forces all client .dll specific data to be resent to client.
  491. void DeathMessage( CBaseEntity *pKiller );
  492. virtual void ProcessUsercmds( CUserCmd *cmds, int numcmds, int totalcmds,
  493. int dropped_packets, bool paused );
  494. bool HasQueuedUsercmds( void ) const;
  495. void AvoidPhysicsProps( CUserCmd *pCmd );
  496. // Run a user command. The default implementation calls ::PlayerRunCommand. In TF, this controls a vehicle if
  497. // the player is in one.
  498. virtual void PlayerRunCommand(CUserCmd *ucmd, IMoveHelper *moveHelper);
  499. void RunNullCommand();
  500. // Team Handling
  501. virtual void ChangeTeam( int iTeamNum ) { ChangeTeam(iTeamNum,false, false); }
  502. virtual void ChangeTeam( int iTeamNum, bool bAutoTeam, bool bSilent );
  503. // say/sayteam allowed?
  504. virtual bool CanHearAndReadChatFrom( CBasePlayer *pPlayer ) { return true; }
  505. virtual bool CanSpeak( void ) { return true; }
  506. audioparams_t &GetAudioParams() { return *m_Local.m_audio.Get(); }
  507. virtual void ModifyOrAppendPlayerCriteria( AI_CriteriaSet& set );
  508. virtual QAngle GetViewPunchAngle();
  509. void SetViewPunchAngle( const QAngle &punchAngle );
  510. void SetViewPunchAngle( int axis, float value );
  511. virtual QAngle GetAimPunchAngle();
  512. void SetAimPunchAngle( const QAngle &angle );
  513. void SetAimPunchAngleVelocity( const QAngle &punchAngleVelocity );
  514. // TrackIR
  515. const Vector& GetEyeOffset() const;
  516. void SetEyeOffset( const Vector& v );
  517. const QAngle & GetEyeAngleOffset() const;
  518. void SetEyeAngleOffset( const QAngle & qa );
  519. // TrackIR
  520. const Vector & GetAimDirection() const;
  521. void SetAimDirection( const Vector & v );
  522. bool IsCoach( void ) const;
  523. int GetCoachingTeam( void ) const;
  524. int GetAssociatedTeamNumber( void ) const; // Returns coaching team if player is a coach. Otherwise returns GetTeamNumber.
  525. bool IsSpectator( void ) const; // is TEAM_SPECTATOR and is not a coach.
  526. // Returns the eye or pointer angle plus the punch angle.
  527. QAngle GetFinalAimAngle();
  528. void PropagatePunchAnglesToObservers( void );
  529. virtual void DoMuzzleFlash();
  530. CNavArea *GetLastKnownArea( void ) const { return m_lastNavArea; } // return the last nav area the player occupied - NULL if unknown
  531. const char *GetLastKnownPlaceName( void ) const { return m_szLastPlaceName; } // return the last nav place name the player occupied
  532. virtual void CheckChatText( char *p, int bufsize ) {}
  533. virtual void CreateRagdollEntity( void ) { return; }
  534. virtual void HandleAnimEvent( animevent_t *pEvent );
  535. CBaseEntity *GetTonemapController( void ) const
  536. {
  537. return m_hTonemapController.Get();
  538. }
  539. virtual bool ShouldAnnounceAchievement( void ){ return true; }
  540. bool IsSplitScreenPartner( CBasePlayer *pPlayer );
  541. void SetSplitScreenPlayer( bool bSplitScreenPlayer, CBasePlayer *pOwner );
  542. bool IsSplitScreenPlayer() const;
  543. CBasePlayer *GetSplitScreenPlayerOwner();
  544. bool IsSplitScreenUserOnEdict( edict_t *edict );
  545. int GetSplitScreenPlayerSlot();
  546. void AddSplitScreenPlayer( CBasePlayer *pOther );
  547. void RemoveSplitScreenPlayer( CBasePlayer *pOther );
  548. CUtlVector< CHandle< CBasePlayer > >& GetSplitScreenPlayers();
  549. bool HasAttachedSplitScreenPlayers() const;
  550. void AddPictureInPicturePlayer( CBasePlayer *pOther );
  551. void RemovePictureInPicturePlayer( CBasePlayer *pOther );
  552. CUtlVector< CHandle< CBasePlayer > >& GetSplitScreenAndPictureInPicturePlayers();
  553. CUtlVector< CHandle< CBasePlayer > >& GetPictureInPicturePlayers( void );
  554. void SetCrossPlayPlatform( CrossPlayPlatform_t clientPlatform );
  555. CrossPlayPlatform_t GetCrossPlayPlatform( void ) const;
  556. // Returns true if team was changed
  557. virtual bool EnsureSplitScreenTeam();
  558. virtual void ForceChangeTeam( int iTeamNum ) { }
  559. void UpdateFXVolume( void );
  560. // ===============================================================
  561. // player's client platform and input device selection
  562. void SetPlayerInputDevice( InputDevice_t controller ) { m_PlayerInputDevice = controller; }
  563. InputDevice_t GetPlayerInputDevice( void ) { return m_PlayerInputDevice; }
  564. void SetPlayerPlatform( InputDevicePlatform_t platform ) { m_PlayerPlatform = platform; }
  565. InputDevicePlatform_t GetPlayerPlatform( void ) { return m_PlayerPlatform; }
  566. void SetLastRequestedClientInfoTime( float newTime ) { m_lastRequestedClientInfoTime = newTime; }
  567. float GetLastRequestedClientInfoTime( void ) { return m_lastRequestedClientInfoTime; }
  568. public:
  569. // Player Physics Shadow
  570. void SetupVPhysicsShadow( const Vector &vecAbsOrigin, const Vector &vecAbsVelocity, CPhysCollide *pStandModel, const char *pStandHullName, CPhysCollide *pCrouchModel, const char *pCrouchHullName );
  571. IPhysicsPlayerController* GetPhysicsController() { return m_pPhysicsController; }
  572. virtual void VPhysicsCollision( int index, gamevcollisionevent_t *pEvent );
  573. void VPhysicsUpdate( IPhysicsObject *pPhysics );
  574. virtual void VPhysicsShadowUpdate( IPhysicsObject *pPhysics );
  575. virtual bool IsFollowingPhysics( void ) { return false; }
  576. bool IsRideablePhysics( IPhysicsObject *pPhysics );
  577. IPhysicsObject *GetGroundVPhysics();
  578. virtual void Touch( CBaseEntity *pOther );
  579. void SetTouchedPhysics( bool bTouch );
  580. bool TouchedPhysics( void );
  581. Vector GetSmoothedVelocity( void );
  582. virtual void InitVCollision( const Vector &vecAbsOrigin, const Vector &vecAbsVelocity );
  583. virtual void VPhysicsDestroyObject();
  584. void SetVCollisionState( const Vector &vecAbsOrigin, const Vector &vecAbsVelocity, int collisionState );
  585. void PostThinkVPhysics( void );
  586. virtual void UpdatePhysicsShadowToCurrentPosition();
  587. void UpdatePhysicsShadowToPosition( const Vector &vecAbsOrigin );
  588. void UpdateVPhysicsPosition( const Vector &position, const Vector &velocity, float secondsToArrival );
  589. // Hint system
  590. virtual CHintSystem *Hints( void ) { return NULL; }
  591. bool ShouldShowHints( void ) { return Hints() ? Hints()->ShouldShowHints() : false; }
  592. void SetShowHints( bool bShowHints ) { if (Hints()) Hints()->SetShowHints( bShowHints ); }
  593. bool HintMessage( int hint, bool bForce = false ) { return Hints() ? Hints()->HintMessage( hint, bForce ) : false; }
  594. void HintMessage( const char *pMessage ) { if (Hints()) Hints()->HintMessage( pMessage ); }
  595. void StartHintTimer( int iHintID ) { if (Hints()) Hints()->StartHintTimer( iHintID ); }
  596. void StopHintTimer( int iHintID ) { if (Hints()) Hints()->StopHintTimer( iHintID ); }
  597. void RemoveHintTimer( int iHintID ) { if (Hints()) Hints()->RemoveHintTimer( iHintID ); }
  598. // Accessor methods
  599. int FragCount() const { return m_iFrags; }
  600. int AssistsCount() const { return m_iAssists; }
  601. int DeathCount() const { return m_iDeaths;}
  602. bool IsConnected() const { return m_iConnected != PlayerDisconnected; }
  603. bool IsDisconnecting() const { return m_iConnected == PlayerDisconnecting; }
  604. bool IsSuitEquipped() const { return m_Local.m_bWearingSuit; }
  605. int ArmorValue() const { return m_ArmorValue; }
  606. bool HUDNeedsRestart() const { return m_fInitHUD; }
  607. float MaxSpeed() const { return m_flMaxspeed; }
  608. Activity GetActivity( ) const { return m_Activity; }
  609. inline void SetActivity( Activity eActivity ) { m_Activity = eActivity; }
  610. bool IsPlayerLockedInPlace() const { return m_iPlayerLocked != 0; }
  611. bool IsObserver() const { return (m_afPhysicsFlags & PFLAG_OBSERVER) != 0; }
  612. bool IsOnTarget() const { return m_fOnTarget; }
  613. float MuzzleFlashTime() const { return m_flFlashTime; }
  614. float PlayerDrownTime() const { return m_AirFinished; }
  615. void SetPlayerLocked( int nLock ) { m_iPlayerLocked = nLock; }
  616. int GetPlayerLocked( void ) { return m_iPlayerLocked; }
  617. int GetObserverMode() const { return m_iObserverMode; }
  618. CBaseEntity *GetObserverTarget() const { return m_hObserverTarget; }
  619. bool IsActiveCameraMan() const { return m_bActiveCameraMan; }
  620. void SetActiveCameraMan( bool bState ) { m_bActiveCameraMan = bState; }
  621. // Round gamerules
  622. virtual bool IsReadyToPlay( void ) { return true; }
  623. virtual bool IsReadyToSpawn( void ) { return true; }
  624. virtual bool ShouldGainInstantSpawn( void ) { return false; }
  625. virtual void ResetPerRoundStats( void ) { return; }
  626. void AllowInstantSpawn( void ) { m_bAllowInstantSpawn = true; }
  627. virtual void ResetScores( void ) { ResetFragCount(); ResetAssistsCount(); ResetDeathCount(); }
  628. void ResetFragCount();
  629. virtual void IncrementFragCount( int nCount, int nHeadshots = 0 );
  630. void ResetAssistsCount();
  631. virtual void IncrementAssistsCount( int nCount );
  632. void ResetDeathCount();
  633. virtual void IncrementDeathCount( int nCount );
  634. void SetArmorValue( int value );
  635. void IncrementArmorValue( int nCount, int nMaxValue = -1 );
  636. void SetConnected( PlayerConnectedState iConnected ) { m_iConnected = iConnected; }
  637. virtual void EquipSuit( bool bPlayEffects = true );
  638. virtual void RemoveSuit( void );
  639. void SetMaxSpeed( float flMaxSpeed ) { m_flMaxspeed = flMaxSpeed; }
  640. void NotifyNearbyRadiationSource( float flRange );
  641. void SetAnimationExtension( const char *pExtension );
  642. void SetAdditionalPVSOrigin( const Vector &vecOrigin );
  643. void SetCameraPVSOrigin( const Vector &vecOrigin );
  644. void SetMuzzleFlashTime( float flTime );
  645. void SetDropEnabled( bool bEnabled );
  646. void SetDuckEnabled( bool bEnabled );
  647. void SetUseEntity( CBaseEntity *pUseEntity );
  648. virtual CBaseEntity* GetUseEntity( void );
  649. virtual CBaseEntity* GetPotentialUseEntity( void );
  650. virtual float GetPlayerMaxSpeed();
  651. // Used to set private physics flags PFLAG_*
  652. void SetPhysicsFlag( int nFlag, bool bSet );
  653. void AllowImmediateDecalPainting();
  654. void PushAwayDecalPaintingTime( float flTime );
  655. // Suicide...
  656. virtual void CommitSuicide( bool bExplode = false, bool bForce = false );
  657. virtual void CommitSuicide( const Vector &vecForce, bool bExplode = false, bool bForce = false );
  658. // For debugging...
  659. void ForceOrigin( const Vector &vecOrigin );
  660. // Bot accessors...
  661. void SetTimeBase( float flTimeBase );
  662. float GetTimeBase() const;
  663. void SetLastUserCommand( const CUserCmd &cmd );
  664. const CUserCmd *GetLastUserCommand( void );
  665. virtual bool IsBot() const;
  666. bool IsPredictingWeapons( void ) const;
  667. int CurrentCommandNumber() const;
  668. const CUserCmd *GetCurrentUserCommand() const;
  669. int GetLockViewanglesTickNumber() const { return m_iLockViewanglesTickNumber; }
  670. QAngle GetLockViewanglesData() const { return m_qangLockViewangles; }
  671. int GetFOV( void ); // Get the current FOV value
  672. int GetDefaultFOV( void ) const; // Default FOV if not specified otherwise
  673. int GetFOVForNetworking( void ); // Get the current FOV used for network computations
  674. 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)
  675. void SetDefaultFOV( int FOV ); // Sets the base FOV if nothing else is affecting it by zooming
  676. CBaseEntity *GetFOVOwner( void ) { return m_hZoomOwner; }
  677. float GetFOVDistanceAdjustFactor(); // shared between client and server
  678. float GetFOVDistanceAdjustFactorForNetworking();
  679. int GetImpulse( void ) const { return m_nImpulse; }
  680. // Movement constraints
  681. void ActivateMovementConstraint( CBaseEntity *pEntity, const Vector &vecCenter, float flRadius, float flConstraintWidth, float flSpeedFactor, bool constraintPastRadius = false );
  682. void DeactivateMovementConstraint( );
  683. // talk control
  684. void NotePlayerTalked() { m_fLastPlayerTalkTime = gpGlobals->curtime; }
  685. float LastTimePlayerTalked() { return m_fLastPlayerTalkTime; }
  686. void DisableButtons( int nButtons );
  687. void EnableButtons( int nButtons );
  688. void ForceButtons( int nButtons );
  689. void UnforceButtons( int nButtons );
  690. //---------------------------------
  691. // Inputs
  692. //---------------------------------
  693. void InputSetHealth( inputdata_t &inputdata );
  694. void InputSetHUDVisibility( inputdata_t &inputdata );
  695. surfacedata_t *GetSurfaceData( void ) const { return m_pSurfaceData; }
  696. void SetLadderNormal( Vector vecLadderNormal ) { m_vecLadderNormal = vecLadderNormal; }
  697. const Vector &GetLadderNormal( void ) const { return m_vecLadderNormal; }
  698. // If a derived class extends ImpulseCommands() and changes an existing impulse, it'll need to clear out the impulse.
  699. void ClearImpulse( void ) { m_nImpulse = 0; }
  700. // Here so that derived classes can use the expresser
  701. virtual CAI_Expresser *GetExpresser() { return NULL; };
  702. #if !defined(NO_STEAM)
  703. //----------------------------
  704. // Steam handling
  705. bool GetSteamID( CSteamID *pID, bool bRequireFullyAuthenticated = false );
  706. uint64 GetSteamIDAsUInt64( void );
  707. #endif
  708. void IncrementEFNoInterpParity();
  709. int GetEFNoInterpParity() const;
  710. private:
  711. // For queueing up CUserCmds and running them from PhysicsSimulate
  712. int GetCommandContextCount( void ) const;
  713. CCommandContext *GetCommandContext( int index );
  714. CCommandContext *AllocCommandContext( void );
  715. void RemoveCommandContext( int index );
  716. void RemoveAllCommandContexts( void );
  717. CCommandContext *RemoveAllCommandContextsExceptNewest( void );
  718. void ReplaceContextCommands( CCommandContext *ctx, CUserCmd *pCommands, int nCommands );
  719. int DetermineSimulationTicks( void );
  720. void AdjustPlayerTimeBase( int simulation_ticks );
  721. void UpdateSplitScreenAndPictureInPicturePlayerList();
  722. public:
  723. // Used by gamemovement to check if the entity is stuck.
  724. int m_StuckLast;
  725. // FIXME: Make these protected or private!
  726. CNetworkVar( float, m_flDuckAmount );
  727. CNetworkVar( float, m_flDuckSpeed );
  728. Vector2D m_vecLastPositionAtFullCrouchSpeed;
  729. int m_nSuicides;
  730. // This player's data that should only be replicated to
  731. // the player and not to other players.
  732. CNetworkVarEmbedded( CPlayerLocalData, m_Local );
  733. CNetworkVarEmbedded( fogplayerparams_t, m_PlayerFog );
  734. void InitFogController( void );
  735. void InputSetFogController( inputdata_t &inputdata );
  736. void OnTonemapTriggerStartTouch( CTonemapTrigger *pTonemapTrigger );
  737. void OnTonemapTriggerEndTouch( CTonemapTrigger *pTonemapTrigger );
  738. CUtlVector< CHandle< CTonemapTrigger > > m_hTriggerTonemapList;
  739. CNetworkHandle( CPostProcessController, m_hPostProcessCtrl ); // active postprocessing controller
  740. CNetworkHandle( CColorCorrection, m_hColorCorrectionCtrl ); // active FXVolume color correction
  741. void InitPostProcessController( void );
  742. void InputSetPostProcessController( inputdata_t &inputdata );
  743. void InitColorCorrectionController( void );
  744. void InputSetColorCorrectionController( inputdata_t &inputdata );
  745. // Used by env_soundscape_triggerable to manage when the player is touching multiple
  746. // soundscape triggers simultaneously.
  747. // The one at the HEAD of the list is always the current soundscape for the player.
  748. CUtlVector<EHANDLE> m_hTriggerSoundscapeList;
  749. // Player data that's sometimes needed by the engine
  750. CNetworkVarEmbedded( CPlayerState, pl );
  751. IMPLEMENT_NETWORK_VAR_FOR_DERIVED( m_fFlags );
  752. IMPLEMENT_NETWORK_VAR_FOR_DERIVED( m_vecViewOffset );
  753. IMPLEMENT_NETWORK_VAR_FOR_DERIVED( m_flFriction );
  754. IMPLEMENT_NETWORK_VAR_FOR_DERIVED( m_iAmmo );
  755. IMPLEMENT_NETWORK_VAR_FOR_DERIVED( m_hGroundEntity );
  756. IMPLEMENT_NETWORK_VAR_FOR_DERIVED( m_lifeState );
  757. IMPLEMENT_NETWORK_VAR_FOR_DERIVED( m_iHealth );
  758. IMPLEMENT_NETWORK_VAR_FOR_DERIVED( m_vecBaseVelocity );
  759. IMPLEMENT_NETWORK_VAR_FOR_DERIVED( m_nNextThinkTick );
  760. IMPLEMENT_NETWORK_VAR_FOR_DERIVED( m_vecVelocity );
  761. IMPLEMENT_NETWORK_VAR_FOR_DERIVED( m_nWaterLevel );
  762. CNetworkVar( int, m_iCoachingTeam ); // When on TEAM_SPECTATOR, is this player restricted to a team, aka 'coaching' a team
  763. int m_nButtons;
  764. int m_afButtonPressed;
  765. int m_afButtonReleased;
  766. int m_afButtonLast;
  767. int m_afButtonDisabled; // A mask of input flags that are cleared automatically
  768. int m_afButtonForced; // These are forced onto the player's inputs
  769. CNetworkVar( bool, m_fOnTarget ); //Is the crosshair on a target?
  770. char m_szAnimExtension[32];
  771. int m_nUpdateRate; // user snapshot rate cl_updaterate
  772. float m_fLerpTime; // users cl_interp
  773. bool m_bLagCompensation; // user wants lag compenstation
  774. bool m_bPredictWeapons; // user has client side predicted weapons
  775. bool m_bPredictionEnabled; // user has prediction enabled
  776. float GetDeathTime( void ) { return m_flDeathTime; }
  777. void ClearZoomOwner( void );
  778. void SetPreviouslyPredictedOrigin( const Vector &vecAbsOrigin );
  779. const Vector &GetPreviouslyPredictedOrigin() const;
  780. float GetFOVTime( void ){ return m_flFOVTime; }
  781. void AdjustDrownDmg( int nAmount );
  782. private:
  783. Activity m_Activity;
  784. protected:
  785. virtual void CalcPlayerView( Vector& eyeOrigin, QAngle& eyeAngles, float& fov );
  786. void CalcVehicleView( IServerVehicle *pVehicle, Vector& eyeOrigin, QAngle& eyeAngles,
  787. float& zNear, float& zFar, float& fov );
  788. void CalcObserverView( Vector& eyeOrigin, QAngle& eyeAngles, float& fov );
  789. void CalcViewModelView( const Vector& eyeOrigin, const QAngle& eyeAngles);
  790. // FIXME: Make these private! (tf_player uses them)
  791. // Secondary point to derive PVS from when zoomed in with binoculars/sniper rifle. The PVS is
  792. // a merge of the standing origin and this additional origin
  793. Vector m_vecAdditionalPVSOrigin;
  794. // Extra PVS origin if we are using a camera object
  795. Vector m_vecCameraPVSOrigin;
  796. bool m_bIsSpecLerping;
  797. float m_flSpecLerpTime;
  798. float m_flSpecLerpEndTime;
  799. Vector m_vecSpecLerpIdealPos;
  800. QAngle m_angSpecLerpIdealAng;
  801. Vector m_vecSpecLerpOldPos;
  802. QAngle m_angSpecLerpOldAng;
  803. bool m_bDropEnabled;
  804. bool m_bDuckEnabled;
  805. CNetworkHandle( CBaseEntity, m_hUseEntity ); // the player is currently controlling this entity because of +USE latched, NULL if no entity
  806. int m_iTrain; // Train control position
  807. float m_iRespawnFrames; // used in PlayerDeathThink() to make sure players can always respawn
  808. CNetworkVar( unsigned int, m_afPhysicsFlags ); // physics flags - set when 'normal' physics should be revisited or overriden
  809. // Vehicles
  810. CNetworkHandle( CBaseEntity, m_hVehicle );
  811. int m_iVehicleAnalogBias;
  812. void UpdateButtonState( int nUserCmdButtonMask );
  813. bool m_bPauseBonusProgress;
  814. CNetworkVar( int, m_iBonusProgress );
  815. CNetworkVar( int, m_iBonusChallenge );
  816. float m_flTimeLastTouchedGround;
  817. int m_lastDamageAmount; // Last damage taken
  818. float m_fTimeLastHurt;
  819. Vector m_DmgOrigin;
  820. float m_DmgTake;
  821. float m_DmgSave;
  822. int m_bitsDamageType; // what types of damage has player taken
  823. int m_bitsHUDDamage; // Damage bits for the current fame. These get sent to the hud via gmsgDamage
  824. CNetworkVar( float, m_flDeathTime ); // the time at which the player died (used in PlayerDeathThink())
  825. float m_flDeathAnimTime; // the time at which the player finished their death anim (used in PlayerDeathThink() and ShouldTransmit())
  826. CNetworkVar( float, m_fForceTeam ); // the time at which the player will be forced onto a team ( use in PlayerForceTeamThink())
  827. CNetworkVar( int, m_iObserverMode ); // if in spectator mode != 0
  828. CNetworkVar( bool, m_bActiveCameraMan ); // the player is an active cameraman for gotv viewers.
  829. CNetworkVar( bool, m_bCameraManXRay ); // XRay state for cameraman
  830. CNetworkVar( bool, m_bCameraManOverview ); // Overview state for cameraman
  831. CNetworkVar( bool, m_bCameraManScoreBoard ); // ScoreBoard state for cameraman
  832. CNetworkVar( uint8, m_uCameraManGraphs ); // Graphs state for cameraman
  833. CNetworkVar( int, m_iFOV ); // field of view
  834. CNetworkVar( int, m_iDefaultFOV ); // default field of view
  835. CNetworkVar( int, m_iFOVStart ); // What our FOV started at
  836. CNetworkVar( float, m_flFOVTime ); // Time our FOV change started
  837. int m_iObserverLastMode; // last used observer mode
  838. CNetworkHandle( CBaseEntity, m_hObserverTarget ); // entity handle to m_iObserverTarget
  839. bool m_bForcedObserverMode; // true, player was forced by invalid targets to switch mode
  840. CNetworkHandle( CBaseEntity, m_hZoomOwner ); //This is a pointer to the entity currently controlling the player's zoom
  841. //Only this entity can change the zoom state once it has ownership
  842. float m_tbdPrev; // Time-based damage timer
  843. int m_idrowndmg; // track drowning damage taken
  844. int m_idrownrestored; // track drowning damage restored
  845. int m_nPoisonDmg; // track recoverable poison damage taken
  846. int m_nPoisonRestored; // track poison damage restored
  847. // NOTE: bits damage type appears to only be used for time-based damage
  848. BYTE m_rgbTimeBasedDamage[CDMG_TIMEBASED];
  849. // Player Physics Shadow
  850. CNetworkVar( int, m_vphysicsCollisionState );
  851. virtual int SpawnArmorValue( void ) const { return 0; }
  852. float m_fNextSuicideTime; // the time after which the player can next use the suicide command
  853. int m_iSuicideCustomKillFlags;
  854. // Replay mode
  855. float m_fDelay; // replay delay in seconds
  856. float m_fReplayEnd; // time to stop replay mode
  857. int m_iReplayEntity; // follow this entity in replay
  858. virtual void UpdateTonemapController( void );
  859. CNetworkHandle( CBaseEntity, m_hTonemapController );
  860. bool m_bKilledByHeadshot;
  861. public:
  862. CNetworkVar( int, m_iDeathPostEffect ); // which deathcam post effect to use
  863. private:
  864. void HandleFuncTrain();
  865. // DATA
  866. private:
  867. CUtlVector< CCommandContext > m_CommandContext;
  868. // Player Physics Shadow
  869. protected: //used to be private, but need access for portal mod (Dave Kircher)
  870. IPhysicsPlayerController *m_pPhysicsController;
  871. IPhysicsObject *m_pShadowStand;
  872. IPhysicsObject *m_pShadowCrouch;
  873. Vector m_oldOrigin;
  874. Vector m_vecSmoothedVelocity;
  875. bool m_bTouchedPhysObject;
  876. bool m_bPhysicsWasFrozen;
  877. CNetworkVar( float, m_flNextDecalTime ); // next time this player can spray a decal
  878. bool m_bNextDecalTimeExpedited; // whether decal time was shortened already
  879. private:
  880. int m_iPlayerSound;// the index of the sound list slot reserved for this player
  881. int m_iTargetVolume;// ideal sound volume.
  882. int m_rgItems[MAX_ITEMS];
  883. // Voting info
  884. IntervalTimer m_lastHeldVoteTimer; ///< How long since we last created a vote. Prevents vote spam.
  885. // these are time-sensitive things that we keep track of
  886. float m_flSwimTime; // how long player has been underwater
  887. float m_flDuckTime; // how long we've been ducking
  888. float m_flDuckJumpTime;
  889. float m_flSuitUpdate; // when to play next suit update
  890. int m_rgSuitPlayList[CSUITPLAYLIST];// next sentencenum to play for suit update
  891. int m_iSuitPlayNext; // next sentence slot for queue storage;
  892. int m_rgiSuitNoRepeat[CSUITNOREPEAT]; // suit sentence no repeat list
  893. float m_rgflSuitNoRepeatTime[CSUITNOREPEAT]; // how long to wait before allowing repeat
  894. float m_flgeigerRange; // range to nearest radiation source
  895. float m_flgeigerDelay; // delay per update of range msg to client
  896. int m_igeigerRangePrev;
  897. bool m_fInitHUD; // True when deferred HUD restart msg needs to be sent
  898. bool m_fGameHUDInitialized;
  899. bool m_fWeapon; // Set this to FALSE to force a reset of the current weapon HUD info
  900. int m_iUpdateTime; // stores the number of frame ticks before sending HUD update messages
  901. int m_iClientBattery; // the Battery currently known by the client. If this changes, send a new
  902. // Autoaim data
  903. QAngle m_vecAutoAim;
  904. // Team Handling
  905. // char m_szTeamName[TEAM_NAME_LENGTH];
  906. // Multiplayer handling
  907. PlayerConnectedState m_iConnected;
  908. // from edict_t
  909. // CBasePlayer doesn't send this but CCSPlayer does.
  910. CNetworkVarForDerived( int, m_ArmorValue );
  911. float m_AirFinished;
  912. float m_PainFinished;
  913. // player locking
  914. int m_iPlayerLocked;
  915. CSimpleSimTimer m_AutoaimTimer;
  916. protected:
  917. int m_iFrags;
  918. int m_iAssists;
  919. int m_iDeaths;
  920. // the player's personal view model
  921. typedef CHandle<CBaseViewModel> CBaseViewModelHandle;
  922. CNetworkArray( CBaseViewModelHandle, m_hViewModel, MAX_VIEWMODELS );
  923. // Last received usercmd (in case we drop a lot of packets )
  924. CUserCmd m_LastCmd;
  925. CUserCmd *m_pCurrentCommand;
  926. int m_iLockViewanglesTickNumber;
  927. QAngle m_qangLockViewangles;
  928. float m_flStepSoundTime; // time to check for next footstep sound
  929. bool m_bAllowInstantSpawn;
  930. // Input device info
  931. InputDevice_t m_PlayerInputDevice;
  932. InputDevicePlatform_t m_PlayerPlatform;
  933. float m_lastRequestedClientInfoTime;
  934. private:
  935. // Replicated to all clients
  936. CNetworkVar( float, m_flMaxspeed );
  937. CNetworkVar( int, m_ladderSurfaceProps );
  938. CNetworkVector( m_vecLadderNormal ); // Clients may need this for climbing anims
  939. protected:
  940. // Not transmitted
  941. float m_flWaterJumpTime; // used to be called teleport_time
  942. Vector m_vecWaterJumpVel;
  943. int m_nImpulse;
  944. float m_flSwimSoundTime;
  945. float m_ignoreLadderJumpTime;
  946. bool m_bHasWalkMovedSinceLastJump;
  947. private:
  948. float m_flFlashTime;
  949. int m_nDrownDmgRate; // Drowning damage in points per second without air.
  950. int m_nNumCrouches; // Number of times we've crouched (for hinting)
  951. bool m_bDuckToggled; // If true, the player is crouching via a toggle
  952. public:
  953. bool GetToggledDuckState( void ) { return m_bDuckToggled; }
  954. void ToggleDuck( void );
  955. float GetStickDist( void );
  956. float m_flForwardMove;
  957. float m_flSideMove;
  958. int m_nNumCrateHudHints;
  959. private:
  960. // Used in test code to teleport the player to random locations in the map.
  961. Vector m_vForcedOrigin;
  962. bool m_bForceOrigin;
  963. // Clients try to run on their own realtime clock, this is this client's clock
  964. CNetworkVar( int, m_nTickBase );
  965. bool m_bGamePaused;
  966. float m_fLastPlayerTalkTime;
  967. CNetworkVar( CBaseCombatWeaponHandle, m_hLastWeapon );
  968. #if !defined( NO_ENTITY_PREDICTION )
  969. CUtlVector< CHandle< CBaseEntity > > m_SimulatedByThisPlayer;
  970. #endif
  971. float m_flOldPlayerZ;
  972. float m_flOldPlayerViewOffsetZ;
  973. bool m_bPlayerUnderwater;
  974. CNetworkHandle( CBaseEntity, m_hViewEntity );
  975. CNetworkVar( bool, m_bShouldDrawPlayerWhileUsingViewEntity );
  976. // Movement constraints
  977. CNetworkHandle( CBaseEntity, m_hConstraintEntity );
  978. CNetworkVector( m_vecConstraintCenter );
  979. CNetworkVar( float, m_flConstraintRadius );
  980. CNetworkVar( float, m_flConstraintWidth );
  981. CNetworkVar( float, m_flConstraintSpeedFactor );
  982. CNetworkVar( bool, m_bConstraintPastRadius );
  983. friend class CPlayerMove;
  984. friend class CPlayerClass;
  985. friend class CASW_PlayerMove;
  986. friend class CDOTAPlayerMove;
  987. friend class CPaintPlayerMove;
  988. // Player name
  989. char m_szNetname[MAX_PLAYER_NAME_LENGTH];
  990. protected:
  991. // HACK FOR TF2 Prediction
  992. friend class CTFGameMovementRecon;
  993. friend class CGameMovement;
  994. friend class CTFGameMovement;
  995. friend class CHL1GameMovement;
  996. friend class CCSGameMovement;
  997. friend class CHL2GameMovement;
  998. friend class CPortalGameMovement;
  999. friend class CASW_MarineGameMovement;
  1000. // Accessors for gamemovement
  1001. bool IsDucked( void ) const { return m_Local.m_bDucked; }
  1002. bool IsDucking( void ) const { return m_Local.m_bDucking; }
  1003. float GetStepSize( void ) const { return m_Local.m_flStepSize; }
  1004. CNetworkVar( float, m_flLaggedMovementValue );
  1005. // These are generated while running usercmds, then given to UpdateVPhysicsPosition after running all queued commands.
  1006. #if defined( DEBUG_MOTION_CONTROLLERS )
  1007. CNetworkVector( m_vNewVPhysicsPosition );
  1008. CNetworkVector( m_vNewVPhysicsVelocity );
  1009. #else
  1010. Vector m_vNewVPhysicsPosition;
  1011. Vector m_vNewVPhysicsVelocity;
  1012. #endif
  1013. Vector m_vecVehicleViewOrigin; // Used to store the calculated view of the player while riding in a vehicle
  1014. QAngle m_vecVehicleViewAngles; // Vehicle angles
  1015. float m_flVehicleViewFOV; // FOV of the vehicle driver
  1016. int m_nVehicleViewSavedFrame; // Used to mark which frame was the last one the view was calculated for
  1017. Vector m_vecPreviouslyPredictedOrigin; // Used to determine if non-gamemovement game code has teleported, or tweaked the player's origin
  1018. int m_nBodyPitchPoseParam;
  1019. CNetworkString( m_szLastPlaceName, MAX_PLACE_NAME_LENGTH );
  1020. unsigned int m_nTicksSinceLastPlaceUpdate;
  1021. char m_szNetworkIDString[MAX_NETWORKID_LENGTH];
  1022. CPlayerInfo m_PlayerInfo;
  1023. // Texture names and surface data, used by CGameMovement
  1024. int m_surfaceProps;
  1025. surfacedata_t* m_pSurfaceData;
  1026. float m_surfaceFriction;
  1027. char m_chTextureType;
  1028. char m_chPreviousTextureType; // Separate from m_chTextureType. This is cleared if the player's not on the ground.
  1029. bool m_bSinglePlayerGameEnding;
  1030. CNetworkVar( int, m_ubEFNoInterpParity );
  1031. EHANDLE m_hPlayerProxy; // Handle to a player proxy entity for quicker reference
  1032. public:
  1033. float GetLaggedMovementValue( void ){ return m_flLaggedMovementValue; }
  1034. void SetLaggedMovementValue( float flValue ) { m_flLaggedMovementValue = flValue; }
  1035. inline bool IsAutoKickDisabled( void ) const;
  1036. inline void DisableAutoKick( bool disabled );
  1037. void DumpPerfToRecipient( CBasePlayer *pRecipient, int nMaxRecords );
  1038. // picker debug utility functions
  1039. virtual CBaseEntity* FindEntityClassForward( char *classname );
  1040. virtual CBaseEntity* FindEntityForward( bool fHull );
  1041. virtual CBaseEntity* FindPickerEntityClass( char *classname );
  1042. virtual CBaseEntity* FindPickerEntity();
  1043. virtual CAI_Node* FindPickerAINode( int nNodeType );
  1044. virtual CAI_Link* FindPickerAILink();
  1045. void PrepareForFullUpdate( void );
  1046. virtual void OnSpeak( CBasePlayer *actor, const char *sound, float duration ) {}
  1047. // A voice packet from this client was received by the server
  1048. virtual void OnVoiceTransmit( void ) {}
  1049. float GetRemainingMovementTimeForUserCmdProcessing() const { return m_flMovementTimeForUserCmdProcessingRemaining; }
  1050. float ConsumeMovementTimeForUserCmdProcessing( float flTimeNeeded )
  1051. {
  1052. if ( m_flMovementTimeForUserCmdProcessingRemaining <= 0.0f )
  1053. {
  1054. return 0.0f;
  1055. }
  1056. else if ( flTimeNeeded > m_flMovementTimeForUserCmdProcessingRemaining + FLT_EPSILON )
  1057. {
  1058. float flResult = m_flMovementTimeForUserCmdProcessingRemaining;
  1059. m_flMovementTimeForUserCmdProcessingRemaining = 0.0f;
  1060. return flResult;
  1061. }
  1062. else
  1063. {
  1064. m_flMovementTimeForUserCmdProcessingRemaining -= flTimeNeeded;
  1065. if ( m_flMovementTimeForUserCmdProcessingRemaining < 0.0f )
  1066. m_flMovementTimeForUserCmdProcessingRemaining = 0.0f;
  1067. return flTimeNeeded;
  1068. }
  1069. }
  1070. private:
  1071. // How much of a movement time buffer can we process from this user?
  1072. float m_flMovementTimeForUserCmdProcessingRemaining;
  1073. public:
  1074. float GetInitialSpawnTime() const { return m_flInitialSpawnTime; }
  1075. private:
  1076. float m_flInitialSpawnTime;
  1077. bool m_autoKickDisabled;
  1078. struct StepSoundCache_t
  1079. {
  1080. StepSoundCache_t() : m_usSoundNameIndex( 0 ) {}
  1081. CSoundParameters m_SoundParameters;
  1082. unsigned short m_usSoundNameIndex;
  1083. };
  1084. // One for left and one for right side of step
  1085. StepSoundCache_t m_StepSoundCache[ 2 ];
  1086. CUtlLinkedList< CPlayerSimInfo > m_vecPlayerSimInfo;
  1087. CUtlLinkedList< CPlayerCmdInfo > m_vecPlayerCmdInfo;
  1088. friend class CMoveHelperServer;
  1089. Vector m_movementCollisionNormal;
  1090. Vector m_groundNormal;
  1091. CHandle< CBaseCombatCharacter > m_stuckCharacter;
  1092. // If true, the m_hSplitOwner points to who owns us
  1093. bool m_bSplitScreenPlayer;
  1094. CHandle< CBasePlayer > m_hSplitOwner;
  1095. // If we have any attached split users, this is the list of them
  1096. CUtlVector< CHandle< CBasePlayer > > m_hSplitScreenPlayers;
  1097. CUtlVector< CHandle< CBasePlayer > > m_hSplitScreenAndPipPlayers;
  1098. CUtlVector< CHandle< CBasePlayer > > m_hPipPlayers;
  1099. CrossPlayPlatform_t m_ClientPlatform;
  1100. public:
  1101. float GetAirTime( void );
  1102. private:
  1103. float GetAutoaimScore( const Vector &eyePosition, const Vector &viewDir, const Vector &vecTarget, CBaseEntity *pTarget, float fScale, CBaseCombatWeapon *pActiveWeapon );
  1104. QAngle AutoaimDeflection( Vector &vecSrc, autoaim_params_t &params );
  1105. public:
  1106. virtual unsigned int PlayerSolidMask( bool brushOnly = false ) const; // returns the solid mask for the given player, so bots can have a more-restrictive set
  1107. #if defined( DEBUG_MOTION_CONTROLLERS )
  1108. CNetworkVector( m_Debug_vPhysPosition );
  1109. CNetworkVector( m_Debug_vPhysVelocity );
  1110. CNetworkVector( m_Debug_LinearAccel );
  1111. #endif
  1112. private:
  1113. // Eye/angle offsets - used for TrackIR and motion controllers
  1114. Vector m_vecEyeOffset;
  1115. QAngle m_EyeAngleOffset;
  1116. Vector m_AimDirection;
  1117. };
  1118. typedef CHandle<CBasePlayer> CBasePlayerHandle;
  1119. EXTERN_SEND_TABLE(DT_BasePlayer)
  1120. //-----------------------------------------------------------------------------
  1121. // Inline methods
  1122. //-----------------------------------------------------------------------------
  1123. inline const Vector &CBasePlayer::GetMovementCollisionNormal( void ) const
  1124. {
  1125. return m_movementCollisionNormal;
  1126. }
  1127. inline const Vector &CBasePlayer::GetGroundNormal( void ) const
  1128. {
  1129. return m_groundNormal;
  1130. }
  1131. inline bool CBasePlayer::IsAutoKickDisabled( void ) const
  1132. {
  1133. return m_autoKickDisabled;
  1134. }
  1135. inline void CBasePlayer::DisableAutoKick( bool disabled )
  1136. {
  1137. m_autoKickDisabled = disabled;
  1138. }
  1139. inline void CBasePlayer::SetAdditionalPVSOrigin( const Vector &vecOrigin )
  1140. {
  1141. m_vecAdditionalPVSOrigin = vecOrigin;
  1142. }
  1143. inline void CBasePlayer::SetCameraPVSOrigin( const Vector &vecOrigin )
  1144. {
  1145. m_vecCameraPVSOrigin = vecOrigin;
  1146. }
  1147. inline void CBasePlayer::SetMuzzleFlashTime( float flTime )
  1148. {
  1149. m_flFlashTime = flTime;
  1150. }
  1151. inline void CBasePlayer::SetDropEnabled( bool bEnabled )
  1152. {
  1153. m_bDropEnabled = bEnabled;
  1154. }
  1155. inline void CBasePlayer::SetDuckEnabled( bool bEnabled )
  1156. {
  1157. m_bDuckEnabled = bEnabled;
  1158. }
  1159. // Bot accessors...
  1160. inline void CBasePlayer::SetTimeBase( float flTimeBase )
  1161. {
  1162. m_nTickBase = TIME_TO_TICKS( flTimeBase );
  1163. }
  1164. inline void CBasePlayer::SetLastUserCommand( const CUserCmd &cmd )
  1165. {
  1166. m_LastCmd = cmd;
  1167. }
  1168. inline CUserCmd const *CBasePlayer::GetLastUserCommand( void )
  1169. {
  1170. return &m_LastCmd;
  1171. }
  1172. inline bool CBasePlayer::IsPredictingWeapons( void ) const
  1173. {
  1174. return m_bPredictWeapons;
  1175. }
  1176. inline int CBasePlayer::CurrentCommandNumber() const
  1177. {
  1178. Assert( m_pCurrentCommand );
  1179. if ( !m_pCurrentCommand )
  1180. return 0;
  1181. return m_pCurrentCommand->command_number;
  1182. }
  1183. inline const CUserCmd *CBasePlayer::GetCurrentUserCommand() const
  1184. {
  1185. Assert( m_pCurrentCommand );
  1186. return m_pCurrentCommand;
  1187. }
  1188. inline IServerVehicle *CBasePlayer::GetVehicle()
  1189. {
  1190. CBaseEntity *pVehicleEnt = m_hVehicle.Get();
  1191. return pVehicleEnt ? pVehicleEnt->GetServerVehicle() : NULL;
  1192. }
  1193. inline CBaseEntity *CBasePlayer::GetVehicleEntity()
  1194. {
  1195. return m_hVehicle.Get();
  1196. }
  1197. inline bool CBasePlayer::IsInAVehicle( void ) const
  1198. {
  1199. return ( NULL != m_hVehicle.Get() ) ? true : false;
  1200. }
  1201. inline void CBasePlayer::SetTouchedPhysics( bool bTouch )
  1202. {
  1203. m_bTouchedPhysObject = bTouch;
  1204. }
  1205. inline bool CBasePlayer::TouchedPhysics( void )
  1206. {
  1207. return m_bTouchedPhysObject;
  1208. }
  1209. //-----------------------------------------------------------------------------
  1210. // Converts an entity to a player
  1211. //-----------------------------------------------------------------------------
  1212. inline CBasePlayer *ToBasePlayer( CBaseEntity *pEntity )
  1213. {
  1214. if ( !pEntity || !pEntity->IsPlayer() )
  1215. return NULL;
  1216. #if _DEBUG
  1217. Assert( static_cast< CBasePlayer* >( pEntity ) == dynamic_cast< CBasePlayer* >( pEntity ) );
  1218. #endif
  1219. return static_cast<CBasePlayer *>( pEntity );
  1220. }
  1221. inline const CBasePlayer *ToBasePlayer( const CBaseEntity *pEntity )
  1222. {
  1223. if ( !pEntity || !pEntity->IsPlayer() )
  1224. return NULL;
  1225. #if _DEBUG
  1226. Assert( static_cast< const CBasePlayer* >( pEntity ) == dynamic_cast< const CBasePlayer* >( pEntity ) );
  1227. #endif
  1228. return static_cast< const CBasePlayer * >( pEntity );
  1229. }
  1230. //--------------------------------------------------------------------------------------------------------------
  1231. /**
  1232. * DEPRECATED: Use CollectPlayers() instead.
  1233. * Iterate over all active players in the game, invoking functor on each.
  1234. * If functor returns false, stop iteration and return false.
  1235. */
  1236. template < typename Functor >
  1237. bool ForEachPlayer( Functor &func )
  1238. {
  1239. VPROF("ForEachPlayer");
  1240. for( int i=1; i<=gpGlobals->maxClients; ++i )
  1241. {
  1242. CBasePlayer *player = static_cast<CBasePlayer *>( UTIL_PlayerByIndex( i ) );
  1243. if (player == NULL)
  1244. continue;
  1245. if (FNullEnt( player->edict() ))
  1246. continue;
  1247. if (!player->IsPlayer())
  1248. continue;
  1249. if( !player->IsConnected() )
  1250. continue;
  1251. if (func( player ) == false)
  1252. return false;
  1253. }
  1254. return true;
  1255. }
  1256. //-----------------------------------------------------------------------------------------------
  1257. /**
  1258. * The interface for an iterative player functor
  1259. */
  1260. class IPlayerFunctor
  1261. {
  1262. public:
  1263. virtual void OnBeginIteration( void ) { } // invoked once before iteration begins
  1264. virtual bool operator() ( CBasePlayer *player ) = 0;
  1265. virtual void OnEndIteration( bool allElementsIterated ) { } // invoked once after iteration is complete whether successful or not
  1266. };
  1267. //--------------------------------------------------------------------------------------------------------------
  1268. /**
  1269. * DEPRECATED: Use CollectPlayers() instead.
  1270. * Specialization of ForEachPlayer template for IPlayerFunctors
  1271. */
  1272. template <>
  1273. inline bool ForEachPlayer( IPlayerFunctor &func )
  1274. {
  1275. VPROF("ForEachPlayer");
  1276. func.OnBeginIteration();
  1277. bool isComplete = true;
  1278. for( int i=1; i<=gpGlobals->maxClients; ++i )
  1279. {
  1280. CBasePlayer *player = static_cast<CBasePlayer *>( UTIL_PlayerByIndex( i ) );
  1281. if (player == NULL)
  1282. continue;
  1283. if (FNullEnt( player->edict() ))
  1284. continue;
  1285. if (!player->IsPlayer())
  1286. continue;
  1287. if( !player->IsConnected() )
  1288. continue;
  1289. if (func( player ) == false)
  1290. {
  1291. isComplete = false;
  1292. break;
  1293. }
  1294. }
  1295. func.OnEndIteration( isComplete );
  1296. return isComplete;
  1297. }
  1298. //--------------------------------------------------------------------------------------------------------------
  1299. //
  1300. // Collect all valid, connected players into given vector.
  1301. // Returns number of players collected.
  1302. //
  1303. #define COLLECT_ONLY_LIVING_PLAYERS true
  1304. #define APPEND_PLAYERS true
  1305. template < typename T >
  1306. int CollectPlayers( CUtlVector< T * > *playerVector, int team = TEAM_ANY, bool isAlive = false, bool shouldAppend = false )
  1307. {
  1308. if ( !shouldAppend )
  1309. {
  1310. playerVector->RemoveAll();
  1311. }
  1312. for( int i=1; i<=gpGlobals->maxClients; ++i )
  1313. {
  1314. T *player = static_cast< T * >( UTIL_PlayerByIndex( i ) );
  1315. if ( player == NULL )
  1316. continue;
  1317. if ( FNullEnt( player->edict() ) )
  1318. continue;
  1319. if ( !player->IsPlayer() )
  1320. continue;
  1321. if ( !player->IsConnected() )
  1322. continue;
  1323. if ( team != TEAM_ANY && player->GetTeamNumber() != team )
  1324. continue;
  1325. if ( isAlive && !player->IsAlive() )
  1326. continue;
  1327. playerVector->AddToTail( player );
  1328. }
  1329. return playerVector->Count();
  1330. }
  1331. enum
  1332. {
  1333. VEHICLE_ANALOG_BIAS_NONE = 0,
  1334. VEHICLE_ANALOG_BIAS_FORWARD,
  1335. VEHICLE_ANALOG_BIAS_REVERSE,
  1336. };
  1337. // Used on player entities - only sends the data to the local player (objectID-1).
  1338. void* SendProxy_SendLocalDataTable( const SendProp *pProp, const void *pStruct, const void *pVarData, CSendProxyRecipients *pRecipients, int objectID );
  1339. void* SendProxy_SendNonLocalDataTable( const SendProp *pProp, const void *pStruct, const void *pVarData, CSendProxyRecipients *pRecipients, int objectID );
  1340. // Helper class
  1341. class CAutoUserMessageThrottle
  1342. {
  1343. public:
  1344. CAutoUserMessageThrottle( CBasePlayer *pPlayer, char const *pchMessages[], int nNumMessage ) :
  1345. m_pPlayer( pPlayer )
  1346. {
  1347. if ( m_pPlayer )
  1348. {
  1349. m_pPlayer->StartUserMessageThrottling( pchMessages, nNumMessage );
  1350. }
  1351. }
  1352. ~CAutoUserMessageThrottle()
  1353. {
  1354. if ( m_pPlayer )
  1355. {
  1356. m_pPlayer->FinishUserMessageThrottling();
  1357. }
  1358. }
  1359. private:
  1360. CBasePlayer *m_pPlayer;
  1361. };
  1362. #endif // PLAYER_H