Advertisement
Guest User

Untitled

a guest
Jul 25th, 2016
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.83 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) {
  275. m_flArmorReductionTime = gpGlobals->curtime + ARMOR_DECAY_TIME;
  276. m_iArmorReductionFrom = ArmorValue();
  277. }
  278.  
  279. void MissedAR2AltFire();
  280.  
  281. inline void EnableCappedPhysicsDamage();
  282. inline void DisableCappedPhysicsDamage();
  283.  
  284. // HUD HINTS
  285. void DisplayLadderHudHint();
  286.  
  287. CSoundPatch *m_sndLeeches;
  288. CSoundPatch *m_sndWaterSplashes;
  289.  
  290. protected:
  291. virtual void PreThink(void);
  292. virtual void PostThink(void);
  293. virtual bool HandleInteraction(int interactionType, void *data, CBaseCombatCharacter* sourceEnt);
  294.  
  295. virtual void UpdateWeaponPosture(void);
  296.  
  297. virtual void ItemPostFrame();
  298. virtual void PlayUseDenySound();
  299.  
  300. private:
  301. //
  302. bool AddFlashlight;
  303.  
  304. bool CommanderExecuteOne(CAI_BaseNPC *pNpc, const commandgoal_t &goal, CAI_BaseNPC **Allies, int numAllies);
  305.  
  306. void OnSquadMemberKilled(inputdata_t &data);
  307.  
  308. Class_T m_nControlClass; // Class when player is controlling another entity
  309. // This player's HL2 specific data that should only be replicated to
  310. // the player and not to other players.
  311. CNetworkVarEmbedded(CHL2PlayerLocalData, m_HL2Local);
  312.  
  313. float m_flTimeAllSuitDevicesOff;
  314.  
  315. bool m_bSprintEnabled; // Used to disable sprint temporarily
  316. bool m_bIsAutoSprinting; // A proxy for holding down the sprint key.
  317. float m_fAutoSprintMinTime; // Minimum time to maintain autosprint regardless of player speed.
  318.  
  319. CNetworkVar(bool, m_fIsSprinting);
  320. CNetworkVarForDerived(bool, m_fIsWalking);
  321.  
  322. protected: // Jeep: Portal_Player needs access to this variable to overload PlayerUse for picking up objects through portals
  323. bool m_bPlayUseDenySound; // Signaled by PlayerUse, but can be unset by HL2 ladder code...
  324.  
  325. private:
  326.  
  327. CAI_Squad * m_pPlayerAISquad;
  328. CSimpleSimTimer m_CommanderUpdateTimer;
  329. float m_RealTimeLastSquadCommand;
  330. CommanderCommand_t m_QueuedCommand;
  331.  
  332. Vector m_vecMissPositions[16];
  333. int m_nNumMissPositions;
  334.  
  335. float m_flTimeIgnoreFallDamage;
  336. bool m_bIgnoreFallDamageResetAfterImpact;
  337.  
  338. // Suit power fields
  339. float m_flSuitPowerLoad; // net suit power drain (total of all device's drainrates)
  340. float m_flAdmireGlovesAnimTime;
  341.  
  342. float m_flNextFlashlightCheckTime;
  343. float m_flFlashlightPowerDrainScale;
  344.  
  345. // Aiming heuristics code
  346. float m_flIdleTime; //Amount of time we've been motionless
  347. float m_flMoveTime; //Amount of time we've been in motion
  348. float m_flLastDamageTime; //Last time we took damage
  349. float m_flTargetFindTime;
  350.  
  351. EHANDLE m_hPlayerProxy;
  352.  
  353. bool m_bFlashlightDisabled;
  354. bool m_bUseCappedPhysicsDamageTable;
  355.  
  356. float m_flArmorReductionTime;
  357. int m_iArmorReductionFrom;
  358.  
  359. float m_flTimeUseSuspended;
  360.  
  361. CSimpleSimTimer m_LowerWeaponTimer;
  362. CSimpleSimTimer m_AutoaimTimer;
  363.  
  364. EHANDLE m_hLockedAutoAimEntity;
  365.  
  366. EHANDLE m_hLocatorTargetEntity; // The entity that's being tracked by the suit locator.
  367.  
  368. float m_flTimeNextLadderHint; // Next time we're eligible to display a HUD hint about a ladder.
  369.  
  370. friend class CHL2GameMovement;
  371. };
  372.  
  373. //-----------------------------------------------------------------------------
  374. // FIXME: find a better way to do this
  375. // Switches us to a physics damage table that caps the max damage.
  376. //-----------------------------------------------------------------------------
  377. void CHL2_Player::EnableCappedPhysicsDamage()
  378. {
  379. m_bUseCappedPhysicsDamageTable = true;
  380. }
  381.  
  382.  
  383. void CHL2_Player::DisableCappedPhysicsDamage()
  384. {
  385. m_bUseCappedPhysicsDamageTable = false;
  386. }
  387.  
  388.  
  389. #endif //HL2_PLAYER_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement