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.

384 lines
13 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Player for HL2.
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef HL2_PLAYER_H
  8. #define HL2_PLAYER_H
  9. #pragma once
  10. #include "player.h"
  11. #include "hl2_playerlocaldata.h"
  12. #include "simtimer.h"
  13. #include "soundenvelope.h"
  14. class CAI_Squad;
  15. class CPropCombineBall;
  16. extern int TrainSpeed(int iSpeed, int iMax);
  17. extern void CopyToBodyQue( CBaseAnimating *pCorpse );
  18. #define ARMOR_DECAY_TIME 3.5f
  19. enum HL2PlayerPhysFlag_e
  20. {
  21. // 1 -- 5 are used by enum PlayerPhysFlag_e in player.h
  22. PFLAG_ONBARNACLE = ( 1<<6 ) // player is hangning from the barnalce
  23. };
  24. class IPhysicsPlayerController;
  25. class CLogicPlayerProxy;
  26. struct commandgoal_t
  27. {
  28. Vector m_vecGoalLocation;
  29. CBaseEntity *m_pGoalEntity;
  30. };
  31. // Time between checks to determine whether NPCs are illuminated by the flashlight
  32. #define FLASHLIGHT_NPC_CHECK_INTERVAL 0.4
  33. //----------------------------------------------------
  34. // Definitions for weapon slots
  35. //----------------------------------------------------
  36. #define WEAPON_MELEE_SLOT 0
  37. #define WEAPON_SECONDARY_SLOT 1
  38. #define WEAPON_PRIMARY_SLOT 2
  39. #define WEAPON_EXPLOSIVE_SLOT 3
  40. #define WEAPON_TOOL_SLOT 4
  41. //=============================================================================
  42. //=============================================================================
  43. class CSuitPowerDevice
  44. {
  45. public:
  46. CSuitPowerDevice( int bitsID, float flDrainRate ) { m_bitsDeviceID = bitsID; m_flDrainRate = flDrainRate; }
  47. private:
  48. int m_bitsDeviceID; // tells what the device is. DEVICE_SPRINT, DEVICE_FLASHLIGHT, etc. BITMASK!!!!!
  49. float m_flDrainRate; // how quickly does this device deplete suit power? ( percent per second )
  50. public:
  51. int GetDeviceID( void ) const { return m_bitsDeviceID; }
  52. float GetDeviceDrainRate( void ) const
  53. {
  54. if( g_pGameRules->GetSkillLevel() == SKILL_EASY && hl2_episodic.GetBool() && !(GetDeviceID()&bits_SUIT_DEVICE_SPRINT) )
  55. return m_flDrainRate * 0.5f;
  56. else
  57. return m_flDrainRate;
  58. }
  59. };
  60. //=============================================================================
  61. // >> HL2_PLAYER
  62. //=============================================================================
  63. class CHL2_Player : public CBasePlayer
  64. {
  65. public:
  66. DECLARE_CLASS( CHL2_Player, CBasePlayer );
  67. CHL2_Player();
  68. ~CHL2_Player( void );
  69. static CHL2_Player *CreatePlayer( const char *className, edict_t *ed )
  70. {
  71. CHL2_Player::s_PlayerEdict = ed;
  72. return (CHL2_Player*)CreateEntityByName( className );
  73. }
  74. DECLARE_SERVERCLASS();
  75. DECLARE_DATADESC();
  76. virtual void CreateCorpse( void ) { CopyToBodyQue( this ); };
  77. virtual void Precache( void );
  78. virtual void Spawn(void);
  79. virtual void Activate( void );
  80. virtual void CheatImpulseCommands( int iImpulse );
  81. virtual void PlayerRunCommand( CUserCmd *ucmd, IMoveHelper *moveHelper);
  82. virtual void PlayerUse ( void );
  83. virtual void SuspendUse( float flDuration ) { m_flTimeUseSuspended = gpGlobals->curtime + flDuration; }
  84. virtual void UpdateClientData( void );
  85. virtual void OnRestore();
  86. virtual void StopLoopingSounds( void );
  87. virtual void Splash( void );
  88. virtual void ModifyOrAppendPlayerCriteria( AI_CriteriaSet& set );
  89. void DrawDebugGeometryOverlays(void);
  90. virtual Vector EyeDirection2D( void );
  91. virtual Vector EyeDirection3D( void );
  92. virtual void CommanderMode();
  93. virtual bool ClientCommand( const CCommand &args );
  94. // from cbasecombatcharacter
  95. void InitVCollision( const Vector &vecAbsOrigin, const Vector &vecAbsVelocity );
  96. WeaponProficiency_t CalcWeaponProficiency( CBaseCombatWeapon *pWeapon );
  97. Class_T Classify ( void );
  98. // from CBasePlayer
  99. virtual void SetupVisibility( CBaseEntity *pViewEntity, unsigned char *pvs, int pvssize );
  100. // Suit Power Interface
  101. void SuitPower_Update( void );
  102. bool SuitPower_Drain( float flPower ); // consume some of the suit's power.
  103. void SuitPower_Charge( float flPower ); // add suit power.
  104. void SuitPower_SetCharge( float flPower ) { m_HL2Local.m_flSuitPower = flPower; }
  105. void SuitPower_Initialize( void );
  106. bool SuitPower_IsDeviceActive( const CSuitPowerDevice &device );
  107. bool SuitPower_AddDevice( const CSuitPowerDevice &device );
  108. bool SuitPower_RemoveDevice( const CSuitPowerDevice &device );
  109. bool SuitPower_ShouldRecharge( void );
  110. float SuitPower_GetCurrentPercentage( void ) { return m_HL2Local.m_flSuitPower; }
  111. void SetFlashlightEnabled( bool bState );
  112. // Apply a battery
  113. bool ApplyBattery( float powerMultiplier = 1.0 );
  114. // Commander Mode for controller NPCs
  115. enum CommanderCommand_t
  116. {
  117. CC_NONE,
  118. CC_TOGGLE,
  119. CC_FOLLOW,
  120. CC_SEND,
  121. };
  122. void CommanderUpdate();
  123. void CommanderExecute( CommanderCommand_t command = CC_TOGGLE );
  124. bool CommanderFindGoal( commandgoal_t *pGoal );
  125. void NotifyFriendsOfDamage( CBaseEntity *pAttackerEntity );
  126. CAI_BaseNPC *GetSquadCommandRepresentative();
  127. int GetNumSquadCommandables();
  128. int GetNumSquadCommandableMedics();
  129. // Locator
  130. void UpdateLocatorPosition( const Vector &vecPosition );
  131. // Sprint Device
  132. void StartAutoSprint( void );
  133. void StartSprinting( void );
  134. void StopSprinting( void );
  135. void InitSprinting( void );
  136. bool IsSprinting( void ) { return m_fIsSprinting; }
  137. bool CanSprint( void );
  138. void EnableSprint( bool bEnable);
  139. bool CanZoom( CBaseEntity *pRequester );
  140. void ToggleZoom(void);
  141. void StartZooming( void );
  142. void StopZooming( void );
  143. bool IsZooming( void );
  144. void CheckSuitZoom( void );
  145. // Walking
  146. void StartWalking( void );
  147. void StopWalking( void );
  148. bool IsWalking( void ) { return m_fIsWalking; }
  149. // Aiming heuristics accessors
  150. virtual float GetIdleTime( void ) const { return ( m_flIdleTime - m_flMoveTime ); }
  151. virtual float GetMoveTime( void ) const { return ( m_flMoveTime - m_flIdleTime ); }
  152. virtual float GetLastDamageTime( void ) const { return m_flLastDamageTime; }
  153. virtual bool IsDucking( void ) const { return !!( GetFlags() & FL_DUCKING ); }
  154. virtual bool PassesDamageFilter( const CTakeDamageInfo &info );
  155. void InputIgnoreFallDamage( inputdata_t &inputdata );
  156. void InputIgnoreFallDamageWithoutReset( inputdata_t &inputdata );
  157. void InputEnableFlashlight( inputdata_t &inputdata );
  158. void InputDisableFlashlight( inputdata_t &inputdata );
  159. const impactdamagetable_t &GetPhysicsImpactDamageTable();
  160. virtual int OnTakeDamage( const CTakeDamageInfo &info );
  161. virtual int OnTakeDamage_Alive( const CTakeDamageInfo &info );
  162. virtual void OnDamagedByExplosion( const CTakeDamageInfo &info );
  163. bool ShouldShootMissTarget( CBaseCombatCharacter *pAttacker );
  164. void CombineBallSocketed( CPropCombineBall *pCombineBall );
  165. virtual void Event_KilledOther( CBaseEntity *pVictim, const CTakeDamageInfo &info );
  166. virtual void GetAutoaimVector( autoaim_params_t &params );
  167. bool ShouldKeepLockedAutoaimTarget( EHANDLE hLockedTarget );
  168. void SetLocatorTargetEntity( CBaseEntity *pEntity ) { m_hLocatorTargetEntity.Set( pEntity ); }
  169. virtual int GiveAmmo( int nCount, int nAmmoIndex, bool bSuppressSound);
  170. virtual bool BumpWeapon( CBaseCombatWeapon *pWeapon );
  171. virtual bool Weapon_CanUse( CBaseCombatWeapon *pWeapon );
  172. virtual void Weapon_Equip( CBaseCombatWeapon *pWeapon );
  173. virtual bool Weapon_Lower( void );
  174. virtual bool Weapon_Ready( void );
  175. virtual bool Weapon_Switch( CBaseCombatWeapon *pWeapon, int viewmodelindex = 0 );
  176. virtual bool Weapon_CanSwitchTo( CBaseCombatWeapon *pWeapon );
  177. void FirePlayerProxyOutput( const char *pszOutputName, variant_t variant, CBaseEntity *pActivator, CBaseEntity *pCaller );
  178. CLogicPlayerProxy *GetPlayerProxy( void );
  179. // Flashlight Device
  180. void CheckFlashlight( void );
  181. int FlashlightIsOn( void );
  182. void FlashlightTurnOn( void );
  183. void FlashlightTurnOff( void );
  184. bool IsIlluminatedByFlashlight( CBaseEntity *pEntity, float *flReturnDot );
  185. void SetFlashlightPowerDrainScale( float flScale ) { m_flFlashlightPowerDrainScale = flScale; }
  186. // Underwater breather device
  187. virtual void SetPlayerUnderwater( bool state );
  188. virtual bool CanBreatheUnderwater() const { return m_HL2Local.m_flSuitPower > 0.0f; }
  189. // physics interactions
  190. virtual void PickupObject( CBaseEntity *pObject, bool bLimitMassAndSize );
  191. virtual bool IsHoldingEntity( CBaseEntity *pEnt );
  192. virtual void ForceDropOfCarriedPhysObjects( CBaseEntity *pOnlyIfHoldindThis );
  193. virtual float GetHeldObjectMass( IPhysicsObject *pHeldObject );
  194. virtual bool IsFollowingPhysics( void ) { return (m_afPhysicsFlags & PFLAG_ONBARNACLE) > 0; }
  195. void InputForceDropPhysObjects( inputdata_t &data );
  196. virtual void Event_Killed( const CTakeDamageInfo &info );
  197. void NotifyScriptsOfDeath( void );
  198. // override the test for getting hit
  199. virtual bool TestHitboxes( const Ray_t &ray, unsigned int fContentsMask, trace_t& tr );
  200. LadderMove_t *GetLadderMove() { return &m_HL2Local.m_LadderMove; }
  201. virtual void ExitLadder();
  202. virtual surfacedata_t *GetLadderSurface( const Vector &origin );
  203. virtual void EquipSuit( bool bPlayEffects = true );
  204. virtual void RemoveSuit( void );
  205. void HandleAdmireGlovesAnimation( void );
  206. void StartAdmireGlovesAnimation( void );
  207. void HandleSpeedChanges( void );
  208. void SetControlClass( Class_T controlClass ) { m_nControlClass = controlClass; }
  209. void StartWaterDeathSounds( void );
  210. void StopWaterDeathSounds( void );
  211. bool IsWeaponLowered( void ) { return m_HL2Local.m_bWeaponLowered; }
  212. void HandleArmorReduction( void );
  213. void StartArmorReduction( void ) { m_flArmorReductionTime = gpGlobals->curtime + ARMOR_DECAY_TIME;
  214. m_iArmorReductionFrom = ArmorValue();
  215. }
  216. void MissedAR2AltFire();
  217. inline void EnableCappedPhysicsDamage();
  218. inline void DisableCappedPhysicsDamage();
  219. // HUD HINTS
  220. void DisplayLadderHudHint();
  221. CSoundPatch *m_sndLeeches;
  222. CSoundPatch *m_sndWaterSplashes;
  223. protected:
  224. virtual void PreThink( void );
  225. virtual void PostThink( void );
  226. virtual bool HandleInteraction(int interactionType, void *data, CBaseCombatCharacter* sourceEnt);
  227. virtual void UpdateWeaponPosture( void );
  228. virtual void ItemPostFrame();
  229. virtual void PlayUseDenySound();
  230. private:
  231. bool CommanderExecuteOne( CAI_BaseNPC *pNpc, const commandgoal_t &goal, CAI_BaseNPC **Allies, int numAllies );
  232. void OnSquadMemberKilled( inputdata_t &data );
  233. Class_T m_nControlClass; // Class when player is controlling another entity
  234. // This player's HL2 specific data that should only be replicated to
  235. // the player and not to other players.
  236. CNetworkVarEmbedded( CHL2PlayerLocalData, m_HL2Local );
  237. float m_flTimeAllSuitDevicesOff;
  238. bool m_bSprintEnabled; // Used to disable sprint temporarily
  239. bool m_bIsAutoSprinting; // A proxy for holding down the sprint key.
  240. float m_fAutoSprintMinTime; // Minimum time to maintain autosprint regardless of player speed.
  241. CNetworkVar( bool, m_fIsSprinting );
  242. CNetworkVarForDerived( bool, m_fIsWalking );
  243. protected: // Jeep: Portal_Player needs access to this variable to overload PlayerUse for picking up objects through portals
  244. bool m_bPlayUseDenySound; // Signaled by PlayerUse, but can be unset by HL2 ladder code...
  245. private:
  246. CAI_Squad * m_pPlayerAISquad;
  247. CSimpleSimTimer m_CommanderUpdateTimer;
  248. float m_RealTimeLastSquadCommand;
  249. CommanderCommand_t m_QueuedCommand;
  250. Vector m_vecMissPositions[16];
  251. int m_nNumMissPositions;
  252. float m_flTimeIgnoreFallDamage;
  253. bool m_bIgnoreFallDamageResetAfterImpact;
  254. // Suit power fields
  255. float m_flSuitPowerLoad; // net suit power drain (total of all device's drainrates)
  256. float m_flAdmireGlovesAnimTime;
  257. float m_flNextFlashlightCheckTime;
  258. float m_flFlashlightPowerDrainScale;
  259. // Aiming heuristics code
  260. float m_flIdleTime; //Amount of time we've been motionless
  261. float m_flMoveTime; //Amount of time we've been in motion
  262. float m_flLastDamageTime; //Last time we took damage
  263. float m_flTargetFindTime;
  264. EHANDLE m_hPlayerProxy;
  265. bool m_bFlashlightDisabled;
  266. bool m_bUseCappedPhysicsDamageTable;
  267. float m_flArmorReductionTime;
  268. int m_iArmorReductionFrom;
  269. float m_flTimeUseSuspended;
  270. CSimpleSimTimer m_LowerWeaponTimer;
  271. CSimpleSimTimer m_AutoaimTimer;
  272. EHANDLE m_hLockedAutoAimEntity;
  273. EHANDLE m_hLocatorTargetEntity; // The entity that's being tracked by the suit locator.
  274. float m_flTimeNextLadderHint; // Next time we're eligible to display a HUD hint about a ladder.
  275. friend class CHL2GameMovement;
  276. };
  277. //-----------------------------------------------------------------------------
  278. // FIXME: find a better way to do this
  279. // Switches us to a physics damage table that caps the max damage.
  280. //-----------------------------------------------------------------------------
  281. void CHL2_Player::EnableCappedPhysicsDamage()
  282. {
  283. m_bUseCappedPhysicsDamageTable = true;
  284. }
  285. void CHL2_Player::DisableCappedPhysicsDamage()
  286. {
  287. m_bUseCappedPhysicsDamageTable = false;
  288. }
  289. #endif //HL2_PLAYER_H