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.

167 lines
5.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Player for HL1.
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef HL1_PLAYER_H
  8. #define HL1_PLAYER_H
  9. #pragma once
  10. #include "player.h"
  11. extern int TrainSpeed(int iSpeed, int iMax);
  12. extern void CopyToBodyQue( CBaseAnimating *pCorpse );
  13. enum HL1PlayerPhysFlag_e
  14. {
  15. // 1 -- 5 are used by enum PlayerPhysFlag_e in player.h
  16. PFLAG_ONBARNACLE = ( 1<<6 ) // player is hangning from the barnalce
  17. };
  18. class IPhysicsPlayerController;
  19. //=============================================================================
  20. //=============================================================================
  21. class CSuitPowerDevice
  22. {
  23. public:
  24. CSuitPowerDevice( int bitsID, float flDrainRate ) { m_bitsDeviceID = bitsID; m_flDrainRate = flDrainRate; }
  25. private:
  26. int m_bitsDeviceID; // tells what the device is. DEVICE_SPRINT, DEVICE_FLASHLIGHT, etc. BITMASK!!!!!
  27. float m_flDrainRate; // how quickly does this device deplete suit power? ( percent per second )
  28. public:
  29. int GetDeviceID( void ) const { return m_bitsDeviceID; }
  30. float GetDeviceDrainRate( void ) const { return m_flDrainRate; }
  31. };
  32. //=============================================================================
  33. // >> HL1_PLAYER
  34. //=============================================================================
  35. class CHL1_Player : public CBasePlayer
  36. {
  37. DECLARE_CLASS( CHL1_Player, CBasePlayer );
  38. DECLARE_SERVERCLASS();
  39. public:
  40. DECLARE_DATADESC();
  41. CHL1_Player();
  42. ~CHL1_Player( void );
  43. static CHL1_Player *CreatePlayer( const char *className, edict_t *ed )
  44. {
  45. CHL1_Player::s_PlayerEdict = ed;
  46. return (CHL1_Player*)CreateEntityByName( className );
  47. }
  48. void CreateCorpse( void ) { CopyToBodyQue( this ); };
  49. void Precache( void );
  50. void Spawn(void);
  51. void Event_Killed( const CTakeDamageInfo &info );
  52. void CheatImpulseCommands( int iImpulse );
  53. void PlayerRunCommand( CUserCmd *ucmd, IMoveHelper *moveHelper );
  54. void UpdateClientData( void );
  55. void OnSave( IEntitySaveUtils *pUtils );
  56. void CheckTimeBasedDamage( void );
  57. // from cbasecombatcharacter
  58. void InitVCollision( const Vector &vecAbsOrigin, const Vector &vecAbsVelocity );
  59. Class_T Classify ( void );
  60. Class_T m_nControlClass; // Class when player is controlling another entity
  61. // from CBasePlayer
  62. void SetupVisibility( CBaseEntity *pViewEntity, unsigned char *pvs, int pvssize );
  63. // Aiming heuristics accessors
  64. float GetIdleTime( void ) const { return ( m_flIdleTime - m_flMoveTime ); }
  65. float GetMoveTime( void ) const { return ( m_flMoveTime - m_flIdleTime ); }
  66. float GetLastDamageTime( void ) const { return m_flLastDamageTime; }
  67. bool IsDucking( void ) const { return !!( GetFlags() & FL_DUCKING ); }
  68. int OnTakeDamage( const CTakeDamageInfo &info );
  69. int OnTakeDamage_Alive( const CTakeDamageInfo &info );
  70. void FindMissTargets( void );
  71. bool GetMissPosition( Vector *position );
  72. void OnDamagedByExplosion( const CTakeDamageInfo &info ) { };
  73. void PlayerPickupObject( CBasePlayer *pPlayer, CBaseEntity *pObject );
  74. virtual void CreateViewModel( int index /*=0*/ );
  75. virtual CBaseEntity *GiveNamedItem( const char *pszName, int iSubType = 0 );
  76. virtual void OnRestore( void );
  77. bool IsPullingObject() { return m_bIsPullingObject; }
  78. void StartPullingObject( CBaseEntity *pObject );
  79. void StopPullingObject();
  80. void UpdatePullingObject();
  81. protected:
  82. void PreThink( void );
  83. bool HandleInteraction(int interactionType, void *data, CBaseCombatCharacter* sourceEnt);
  84. private:
  85. Vector m_vecMissPositions[16];
  86. int m_nNumMissPositions;
  87. // Aiming heuristics code
  88. float m_flIdleTime; //Amount of time we've been motionless
  89. float m_flMoveTime; //Amount of time we've been in motion
  90. float m_flLastDamageTime; //Last time we took damage
  91. float m_flTargetFindTime;
  92. EHANDLE m_hPullObject;
  93. IPhysicsConstraint *m_pPullConstraint;
  94. public:
  95. // Flashlight Device
  96. int FlashlightIsOn( void );
  97. void FlashlightTurnOn( void );
  98. void FlashlightTurnOff( void );
  99. float m_flFlashLightTime; // Time until next battery draw/Recharge
  100. CNetworkVar( int, m_nFlashBattery ); // Flashlight Battery Draw
  101. // For gauss weapon
  102. // float m_flStartCharge;
  103. // float m_flAmmoStartCharge;
  104. // float m_flPlayAftershock;
  105. // float m_flNextAmmoBurn; // while charging, when to absorb another unit of player's ammo?
  106. CNetworkVar( float, m_flStartCharge );
  107. CNetworkVar( float, m_flAmmoStartCharge );
  108. CNetworkVar( float, m_flPlayAftershock );
  109. CNetworkVar( float, m_flNextAmmoBurn ); // while charging, when to absorb another unit of player's ammo?
  110. CNetworkVar( bool, m_bHasLongJump );
  111. CNetworkVar( bool, m_bIsPullingObject );
  112. };
  113. //-----------------------------------------------------------------------------
  114. // Converts an entity to a HL1 player
  115. //-----------------------------------------------------------------------------
  116. inline CHL1_Player *ToHL1Player( CBaseEntity *pEntity )
  117. {
  118. if ( !pEntity || !pEntity->IsPlayer() )
  119. return NULL;
  120. #if _DEBUG
  121. return dynamic_cast<CHL1_Player *>( pEntity );
  122. #else
  123. return static_cast<CHL1_Player *>( pEntity );
  124. #endif
  125. }
  126. #endif //HL1_PLAYER_H