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.

253 lines
8.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #ifndef PORTAL_PLAYER_H
  9. #define PORTAL_PLAYER_H
  10. #pragma once
  11. class CPortal_Player;
  12. #include "player.h"
  13. #include "portal_playeranimstate.h"
  14. #include "hl2_playerlocaldata.h"
  15. #include "hl2_player.h"
  16. #include "simtimer.h"
  17. #include "soundenvelope.h"
  18. #include "portal_player_shared.h"
  19. #include "prop_portal.h"
  20. #include "weapon_portalbase.h"
  21. #include "in_buttons.h"
  22. #include "func_liquidportal.h"
  23. #include "ai_speech.h" // For expresser host
  24. struct PortalPlayerStatistics_t
  25. {
  26. int iNumPortalsPlaced;
  27. int iNumStepsTaken;
  28. float fNumSecondsTaken;
  29. };
  30. //=============================================================================
  31. // >> Portal_Player
  32. //=============================================================================
  33. class CPortal_Player : public CAI_ExpresserHost<CHL2_Player>
  34. {
  35. public:
  36. DECLARE_CLASS( CPortal_Player, CHL2_Player );
  37. CPortal_Player();
  38. ~CPortal_Player( void );
  39. static CPortal_Player *CreatePlayer( const char *className, edict_t *ed )
  40. {
  41. CPortal_Player::s_PlayerEdict = ed;
  42. return (CPortal_Player*)CreateEntityByName( className );
  43. }
  44. DECLARE_SERVERCLASS();
  45. DECLARE_DATADESC();
  46. virtual void Precache( void );
  47. virtual void CreateSounds( void );
  48. virtual void StopLoopingSounds( void );
  49. virtual void Spawn( void );
  50. virtual void OnRestore( void );
  51. virtual void Activate( void );
  52. virtual void NotifySystemEvent( CBaseEntity *pNotify, notify_system_event_t eventType, const notify_system_event_params_t &params );
  53. virtual void PostThink( void );
  54. virtual void PreThink( void );
  55. virtual void PlayerDeathThink( void );
  56. void UpdatePortalPlaneSounds( void );
  57. void UpdateWooshSounds( void );
  58. Activity TranslateActivity( Activity ActToTranslate, bool *pRequired = NULL );
  59. virtual void Teleport( const Vector *newPosition, const QAngle *newAngles, const Vector *newVelocity );
  60. Activity TranslateTeamActivity( Activity ActToTranslate );
  61. virtual void SetAnimation( PLAYER_ANIM playerAnim );
  62. virtual CAI_Expresser* GetExpresser( void );
  63. virtual void PlayerRunCommand(CUserCmd *ucmd, IMoveHelper *moveHelper);
  64. virtual bool ClientCommand( const CCommand &args );
  65. virtual void CreateViewModel( int viewmodelindex = 0 );
  66. virtual bool BecomeRagdollOnClient( const Vector &force );
  67. virtual int OnTakeDamage( const CTakeDamageInfo &inputInfo );
  68. virtual int OnTakeDamage_Alive( const CTakeDamageInfo &info );
  69. virtual bool WantsLagCompensationOnEntity( const CBasePlayer *pPlayer, const CUserCmd *pCmd, const CBitVec<MAX_EDICTS> *pEntityTransmitBits ) const;
  70. virtual void FireBullets ( const FireBulletsInfo_t &info );
  71. virtual bool Weapon_Switch( CBaseCombatWeapon *pWeapon, int viewmodelindex = 0);
  72. virtual bool BumpWeapon( CBaseCombatWeapon *pWeapon );
  73. virtual void ShutdownUseEntity( void );
  74. virtual const Vector& WorldSpaceCenter( ) const;
  75. virtual void VPhysicsShadowUpdate( IPhysicsObject *pPhysics );
  76. //virtual bool StartReplayMode( float fDelay, float fDuration, int iEntity );
  77. //virtual void StopReplayMode();
  78. virtual void Event_Killed( const CTakeDamageInfo &info );
  79. virtual void Jump( void );
  80. bool UseFoundEntity( CBaseEntity *pUseEntity );
  81. CBaseEntity* FindUseEntity( void );
  82. CBaseEntity* FindUseEntityThroughPortal( void );
  83. virtual void PlayerUse( void );
  84. //virtual bool StartObserverMode( int mode );
  85. virtual void GetStepSoundVelocities( float *velwalk, float *velrun );
  86. virtual void PlayStepSound( Vector &vecOrigin, surfacedata_t *psurface, float fvol, bool force );
  87. virtual void UpdateOnRemove( void );
  88. virtual void SetupVisibility( CBaseEntity *pViewEntity, unsigned char *pvs, int pvssize );
  89. virtual void UpdatePortalViewAreaBits( unsigned char *pvs, int pvssize );
  90. bool ValidatePlayerModel( const char *pModel );
  91. QAngle GetAnimEyeAngles( void ) { return m_angEyeAngles.Get(); }
  92. Vector GetAttackSpread( CBaseCombatWeapon *pWeapon, CBaseEntity *pTarget = NULL );
  93. void CheatImpulseCommands( int iImpulse );
  94. void CreateRagdollEntity( const CTakeDamageInfo &info );
  95. void GiveAllItems( void );
  96. void GiveDefaultItems( void );
  97. void NoteWeaponFired( void );
  98. void ResetAnimation( void );
  99. void SetPlayerModel( void );
  100. void UpdateExpression ( void );
  101. void ClearExpression ( void );
  102. int GetPlayerModelType( void ) { return m_iPlayerSoundType; }
  103. void ForceDuckThisFrame( void );
  104. void UnDuck ( void );
  105. inline void ForceJumpThisFrame( void ) { ForceButtons( IN_JUMP ); }
  106. void DoAnimationEvent( PlayerAnimEvent_t event, int nData );
  107. void SetupBones( matrix3x4_t *pBoneToWorld, int boneMask );
  108. // physics interactions
  109. virtual void PickupObject(CBaseEntity *pObject, bool bLimitMassAndSize );
  110. virtual void ForceDropOfCarriedPhysObjects( CBaseEntity *pOnlyIfHoldingThis );
  111. void ToggleHeldObjectOnOppositeSideOfPortal( void ) { m_bHeldObjectOnOppositeSideOfPortal = !m_bHeldObjectOnOppositeSideOfPortal; }
  112. void SetHeldObjectOnOppositeSideOfPortal( bool p_bHeldObjectOnOppositeSideOfPortal ) { m_bHeldObjectOnOppositeSideOfPortal = p_bHeldObjectOnOppositeSideOfPortal; }
  113. bool IsHeldObjectOnOppositeSideOfPortal( void ) { return m_bHeldObjectOnOppositeSideOfPortal; }
  114. CProp_Portal *GetHeldObjectPortal( void ) { return m_pHeldObjectPortal; }
  115. void SetHeldObjectPortal( CProp_Portal *pPortal ) { m_pHeldObjectPortal = pPortal; }
  116. void SetStuckOnPortalCollisionObject( void ) { m_bStuckOnPortalCollisionObject = true; }
  117. CWeaponPortalBase* GetActivePortalWeapon() const;
  118. void IncrementPortalsPlaced( void );
  119. void IncrementStepsTaken( void );
  120. void UpdateSecondsTaken( void );
  121. void ResetThisLevelStats( void );
  122. int NumPortalsPlaced( void ) const { return m_StatsThisLevel.iNumPortalsPlaced; }
  123. int NumStepsTaken( void ) const { return m_StatsThisLevel.iNumStepsTaken; }
  124. float NumSecondsTaken( void ) const { return m_StatsThisLevel.fNumSecondsTaken; }
  125. void SetNeuroToxinDamageTime( float fCountdownSeconds ) { m_fNeuroToxinDamageTime = gpGlobals->curtime + fCountdownSeconds; }
  126. void IncNumCamerasDetatched( void ) { ++m_iNumCamerasDetatched; }
  127. int GetNumCamerasDetatched( void ) const { return m_iNumCamerasDetatched; }
  128. Vector m_vecTotalBulletForce; //Accumulator for bullet force in a single frame
  129. bool m_bSilentDropAndPickup;
  130. // Tracks our ragdoll entity.
  131. CNetworkHandle( CBaseEntity, m_hRagdoll ); // networked entity handle
  132. void SuppressCrosshair( bool bState ) { m_bSuppressingCrosshair = bState; }
  133. private:
  134. virtual CAI_Expresser* CreateExpresser( void );
  135. CSoundPatch *m_pWooshSound;
  136. CNetworkQAngle( m_angEyeAngles );
  137. CPortalPlayerAnimState* m_PlayerAnimState;
  138. int m_iLastWeaponFireUsercmd;
  139. CNetworkVar( int, m_iSpawnInterpCounter );
  140. CNetworkVar( int, m_iPlayerSoundType );
  141. CNetworkVar( bool, m_bSuppressingCrosshair );
  142. CNetworkVar( bool, m_bHeldObjectOnOppositeSideOfPortal );
  143. CNetworkHandle( CProp_Portal, m_pHeldObjectPortal ); // networked entity handle
  144. bool m_bIntersectingPortalPlane;
  145. bool m_bStuckOnPortalCollisionObject;
  146. float m_fTimeLastHurt;
  147. bool m_bIsRegenerating; // Is the player currently regaining health
  148. float m_fNeuroToxinDamageTime;
  149. PortalPlayerStatistics_t m_StatsThisLevel;
  150. float m_fTimeLastNumSecondsUpdate;
  151. int m_iNumCamerasDetatched;
  152. QAngle m_qPrePortalledViewAngles;
  153. bool m_bFixEyeAnglesFromPortalling;
  154. VMatrix m_matLastPortalled;
  155. CAI_Expresser *m_pExpresser;
  156. string_t m_iszExpressionScene;
  157. EHANDLE m_hExpressionSceneEnt;
  158. float m_flExpressionLoopTime;
  159. mutable Vector m_vWorldSpaceCenterHolder; //WorldSpaceCenter() returns a reference, need an actual value somewhere
  160. public:
  161. CNetworkVar( bool, m_bPitchReorientation );
  162. CNetworkHandle( CProp_Portal, m_hPortalEnvironment ); //if the player is in a portal environment, this is the associated portal
  163. CNetworkHandle( CFunc_LiquidPortal, m_hSurroundingLiquidPortal ); //if the player is standing in a liquid portal, this will point to it
  164. friend class CProp_Portal;
  165. #ifdef PORTAL_MP
  166. public:
  167. virtual CBaseEntity* EntSelectSpawnPoint( void );
  168. void PickTeam( void );
  169. #endif
  170. };
  171. inline CPortal_Player *ToPortalPlayer( CBaseEntity *pEntity )
  172. {
  173. if ( !pEntity || !pEntity->IsPlayer() )
  174. return NULL;
  175. return dynamic_cast<CPortal_Player*>( pEntity );
  176. }
  177. inline CPortal_Player *GetPortalPlayer( int iPlayerIndex )
  178. {
  179. return static_cast<CPortal_Player*>( UTIL_PlayerByIndex( iPlayerIndex ) );
  180. }
  181. #endif //PORTAL_PLAYER_H