Advertisement
Guest User

Untitled

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