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.

285 lines
6.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef DOD_PLAYER_SHARED_H
  7. #define DOD_PLAYER_SHARED_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "networkvar.h"
  12. #include "weapon_dodbase.h"
  13. #ifdef CLIENT_DLL
  14. class C_DODPlayer;
  15. #else
  16. class CDODPlayer;
  17. #endif
  18. // Entity Messages
  19. #define DOD_PLAYER_POP_HELMET 1
  20. #define DOD_PLAYER_REMOVE_DECALS 2
  21. class CViewOffsetAnimation
  22. {
  23. public:
  24. CViewOffsetAnimation( CBasePlayer *pPlayer )
  25. {
  26. m_pPlayer = pPlayer;
  27. m_vecStart = vec3_origin;
  28. m_vecDest = vec3_origin;
  29. m_flLength = 0.0;
  30. m_flEndTime = 0.0;
  31. m_eViewAnimType = VIEW_ANIM_LINEAR_Z_ONLY;
  32. m_bActive = false;
  33. }
  34. static CViewOffsetAnimation *CreateViewOffsetAnim( CBasePlayer *pPlayer )
  35. {
  36. CViewOffsetAnimation *p = new CViewOffsetAnimation( pPlayer );
  37. Assert( p );
  38. return p;
  39. }
  40. void StartAnimation( Vector vecStart, Vector vecDest, float flTime, ViewAnimationType type )
  41. {
  42. m_vecStart = vecStart;
  43. m_vecDest = vecDest;
  44. m_flLength = flTime;
  45. m_flEndTime = gpGlobals->curtime + flTime;
  46. m_eViewAnimType = type;
  47. m_bActive = true;
  48. }
  49. void Reset( void )
  50. {
  51. m_bActive = false;
  52. }
  53. void Think( void )
  54. {
  55. if ( !m_bActive )
  56. return;
  57. if ( IsFinished() )
  58. {
  59. m_bActive = false;
  60. return;
  61. }
  62. float flFraction = ( m_flEndTime - gpGlobals->curtime ) / m_flLength;
  63. Assert( m_pPlayer );
  64. if ( m_pPlayer )
  65. {
  66. Vector vecCurrentView = m_pPlayer->GetViewOffset();
  67. switch ( m_eViewAnimType )
  68. {
  69. case VIEW_ANIM_LINEAR_Z_ONLY:
  70. vecCurrentView.z = flFraction * m_vecStart.z + ( 1.0 - flFraction ) * m_vecDest.z;
  71. break;
  72. case VIEW_ANIM_SPLINE_Z_ONLY:
  73. vecCurrentView.z = SimpleSplineRemapVal( flFraction, 1.0, 0.0, m_vecStart.z, m_vecDest.z );
  74. break;
  75. case VIEW_ANIM_EXPONENTIAL_Z_ONLY:
  76. {
  77. float flBias = Bias( flFraction, 0.2 );
  78. vecCurrentView.z = flBias * m_vecStart.z + ( 1.0 - flBias ) * m_vecDest.z;
  79. }
  80. break;
  81. }
  82. m_pPlayer->SetViewOffset( vecCurrentView );
  83. }
  84. }
  85. bool IsFinished( void )
  86. {
  87. return ( gpGlobals->curtime > m_flEndTime || m_pPlayer == NULL );
  88. }
  89. private:
  90. CBasePlayer *m_pPlayer;
  91. Vector m_vecStart;
  92. Vector m_vecDest;
  93. float m_flEndTime;
  94. float m_flLength;
  95. ViewAnimationType m_eViewAnimType;
  96. bool m_bActive;
  97. };
  98. // Data in the DoD player that is accessed by shared code.
  99. // This data isn't necessarily transmitted between client and server.
  100. class CDODPlayerShared
  101. {
  102. public:
  103. #ifdef CLIENT_DLL
  104. friend class C_DODPlayer;
  105. typedef C_DODPlayer OuterClass;
  106. DECLARE_PREDICTABLE();
  107. #else
  108. friend class CDODPlayer;
  109. typedef CDODPlayer OuterClass;
  110. #endif
  111. DECLARE_EMBEDDED_NETWORKVAR()
  112. DECLARE_CLASS_NOBASE( CDODPlayerShared );
  113. CDODPlayerShared();
  114. ~CDODPlayerShared();
  115. void SetStamina( float stamina );
  116. float GetStamina( void ) { return m_flStamina; }
  117. void Init( OuterClass *pOuter );
  118. bool IsProne() const;
  119. bool IsGettingUpFromProne() const;
  120. bool IsGoingProne() const;
  121. void SetProne( bool bProne, bool bNoAnimation = false );
  122. bool IsBazookaDeployed( void ) const;
  123. bool IsBazookaOnlyDeployed( void ) const;
  124. bool IsSniperZoomed( void ) const;
  125. bool IsInMGDeploy( void ) const;
  126. bool IsProneDeployed( void ) const;
  127. bool IsSandbagDeployed( void ) const;
  128. bool IsDucking( void ) const;
  129. void SetDesiredPlayerClass( int playerclass );
  130. int DesiredPlayerClass( void );
  131. void SetPlayerClass( int playerclass );
  132. int PlayerClass( void );
  133. CWeaponDODBase* GetActiveDODWeapon() const;
  134. void SetDeployed( bool bDeployed, float flHeight = -1 );
  135. QAngle GetDeployedAngles( void ) const;
  136. float GetDeployedHeight( void ) const;
  137. void SetDeployedYawLimits( float flLeftYaw, float flRightYaw );
  138. void ClampDeployedAngles( QAngle *vecTestAngles );
  139. void SetSlowedTime( float t );
  140. float GetSlowedTime( void ) const;
  141. void StartGoingProne( void );
  142. void StandUpFromProne( void );
  143. bool CanChangePosition( void );
  144. bool IsJumping( void ) { return m_bJumping; }
  145. void SetJumping( bool bJumping );
  146. bool IsSprinting( void ) { return m_bIsSprinting; }
  147. void ForceUnzoom( void );
  148. void SetSprinting( bool bSprinting );
  149. void StartSprinting( void );
  150. void StopSprinting( void );
  151. void SetCPIndex( int index );
  152. int GetCPIndex( void ) { return m_iCPIndex; }
  153. void SetLastViewAnimTime( float flTime );
  154. float GetLastViewAnimTime( void );
  155. void ViewAnimThink( void );
  156. void ResetViewOffsetAnimation( void );
  157. void ViewOffsetAnimation( Vector vecDest, float flTime, ViewAnimationType type );
  158. void ResetSprintPenalty( void );
  159. void SetPlanting( bool bPlanting )
  160. {
  161. m_bPlanting = bPlanting;
  162. }
  163. bool IsPlanting( void ) { return m_bPlanting; }
  164. void SetDefusing( bool bDefusing )
  165. {
  166. m_bDefusing = bDefusing;
  167. }
  168. bool IsDefusing( void ) { return m_bDefusing; }
  169. void ComputeWorldSpaceSurroundingBox( Vector *pVecWorldMins, Vector *pVecWorldMaxs );
  170. void SetPlayerDominated( CDODPlayer *pPlayer, bool bDominated );
  171. bool IsPlayerDominated( int iPlayerIndex );
  172. bool IsPlayerDominatingMe( int iPlayerIndex );
  173. void SetPlayerDominatingMe( CDODPlayer *pPlayer, bool bDominated );
  174. private:
  175. CNetworkVar( bool, m_bProne );
  176. CNetworkVar( int, m_iPlayerClass );
  177. CNetworkVar( int, m_iDesiredPlayerClass );
  178. CNetworkVar( float, m_flStamina );
  179. CNetworkVar( float, m_flSlowedUntilTime );
  180. CNetworkVar( bool, m_bIsSprinting );
  181. CNetworkVar( float, m_flDeployedYawLimitLeft );
  182. CNetworkVar( float, m_flDeployedYawLimitRight );
  183. CNetworkVar( bool, m_bPlanting );
  184. CNetworkVar( bool, m_bDefusing );
  185. bool m_bGaveSprintPenalty;
  186. public:
  187. float m_flNextProneCheck; // Prevent it switching their prone state constantly.
  188. QAngle m_vecDeployedAngles;
  189. //float m_flDeployedHeight;
  190. CNetworkVar( float, m_flDeployedHeight );
  191. CNetworkVar( float, m_flUnProneTime );
  192. CNetworkVar( float, m_flGoProneTime );
  193. CNetworkVar( float, m_flDeployChangeTime );
  194. CNetworkVar( bool, m_bForceProneChange );
  195. CNetworkVar( int, m_iCPIndex );
  196. bool m_bJumping;
  197. float m_flLastViewAnimationTime;
  198. CViewOffsetAnimation *m_pViewOffsetAnim;
  199. CNetworkArray( bool, m_bPlayerDominated, MAX_PLAYERS+1 ); // array of state per other player whether player is dominating other players
  200. CNetworkArray( bool, m_bPlayerDominatingMe, MAX_PLAYERS+1 ); // array of state per other player whether other players are dominating this player
  201. private:
  202. OuterClass *m_pOuter;
  203. };
  204. #endif // DOD_PLAYER_SHARED_H