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.

237 lines
8.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "hud.h"
  8. #include "c_physicsprop.h"
  9. #include "iclientvehicle.h"
  10. #include <vgui_controls/Controls.h>
  11. #include <Color.h>
  12. #include "vehicle_viewblend_shared.h"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. extern float RemapAngleRange( float startInterval, float endInterval, float value );
  16. #define ROLL_CURVE_ZERO 5 // roll less than this is clamped to zero
  17. #define ROLL_CURVE_LINEAR 45 // roll greater than this is copied out
  18. #define PITCH_CURVE_ZERO 10 // pitch less than this is clamped to zero
  19. #define PITCH_CURVE_LINEAR 45 // pitch greater than this is copied out
  20. // spline in between
  21. #define POD_VIEW_FOV 90
  22. #define POD_VIEW_YAW_MIN -60
  23. #define POD_VIEW_YAW_MAX 60
  24. #define POD_VIEW_PITCH_MIN -90
  25. #define POD_VIEW_PITCH_MAX 38 // Don't let players look down and see that the pod is empty
  26. //-----------------------------------------------------------------------------
  27. // Purpose:
  28. //-----------------------------------------------------------------------------
  29. class C_PropVehiclePrisonerPod : public C_PhysicsProp, public IClientVehicle
  30. {
  31. DECLARE_CLASS( C_PropVehiclePrisonerPod, C_PhysicsProp );
  32. public:
  33. DECLARE_CLIENTCLASS();
  34. DECLARE_DATADESC();
  35. C_PropVehiclePrisonerPod();
  36. void PreDataUpdate( DataUpdateType_t updateType );
  37. void PostDataUpdate( DataUpdateType_t updateType );
  38. public:
  39. // IClientVehicle overrides.
  40. virtual void GetVehicleViewPosition( int nRole, Vector *pOrigin, QAngle *pAngles, float *pFOV = NULL );
  41. virtual void GetVehicleFOV( float &flFOV )
  42. {
  43. flFOV = m_flFOV;
  44. }
  45. virtual void DrawHudElements();
  46. virtual bool IsPassengerUsingStandardWeapons( int nRole = VEHICLE_ROLE_DRIVER ) { return false; }
  47. virtual void UpdateViewAngles( C_BasePlayer *pLocalPlayer, CUserCmd *pCmd );
  48. virtual C_BaseCombatCharacter* GetPassenger( int nRole );
  49. virtual int GetPassengerRole( C_BaseCombatCharacter *pEnt );
  50. virtual void GetVehicleClipPlanes( float &flZNear, float &flZFar ) const;
  51. virtual int GetPrimaryAmmoType() const { return -1; }
  52. virtual int GetPrimaryAmmoCount() const { return -1; }
  53. virtual int GetPrimaryAmmoClip() const { return -1; }
  54. virtual bool PrimaryAmmoUsesClips() const { return false; }
  55. virtual int GetJoystickResponseCurve() const { return 0; }
  56. public:
  57. // C_BaseEntity overrides.
  58. virtual IClientVehicle* GetClientVehicle() { return this; }
  59. virtual C_BaseEntity *GetVehicleEnt() { return this; }
  60. virtual void SetupMove( C_BasePlayer *player, CUserCmd *ucmd, IMoveHelper *pHelper, CMoveData *move ) {}
  61. virtual void ProcessMovement( C_BasePlayer *pPlayer, CMoveData *pMoveData ) {}
  62. virtual void FinishMove( C_BasePlayer *player, CUserCmd *ucmd, CMoveData *move ) {}
  63. virtual bool IsPredicted() const { return false; }
  64. virtual void ItemPostFrame( C_BasePlayer *pPlayer ) {}
  65. virtual bool IsSelfAnimating() { return false; };
  66. private:
  67. CHandle<C_BasePlayer> m_hPlayer;
  68. CHandle<C_BasePlayer> m_hPrevPlayer;
  69. bool m_bEnterAnimOn;
  70. bool m_bExitAnimOn;
  71. Vector m_vecEyeExitEndpoint;
  72. float m_flFOV; // The current FOV (changes during entry/exit anims).
  73. ViewSmoothingData_t m_ViewSmoothingData;
  74. };
  75. IMPLEMENT_CLIENTCLASS_DT(C_PropVehiclePrisonerPod, DT_PropVehiclePrisonerPod, CPropVehiclePrisonerPod)
  76. RecvPropEHandle( RECVINFO(m_hPlayer) ),
  77. RecvPropBool( RECVINFO( m_bEnterAnimOn ) ),
  78. RecvPropBool( RECVINFO( m_bExitAnimOn ) ),
  79. RecvPropVector( RECVINFO( m_vecEyeExitEndpoint ) ),
  80. END_RECV_TABLE()
  81. BEGIN_DATADESC( C_PropVehiclePrisonerPod )
  82. DEFINE_EMBEDDED( m_ViewSmoothingData ),
  83. END_DATADESC()
  84. //-----------------------------------------------------------------------------
  85. // Purpose:
  86. //-----------------------------------------------------------------------------
  87. C_PropVehiclePrisonerPod::C_PropVehiclePrisonerPod( void )
  88. {
  89. memset( &m_ViewSmoothingData, 0, sizeof( m_ViewSmoothingData ) );
  90. m_ViewSmoothingData.pVehicle = this;
  91. m_ViewSmoothingData.bClampEyeAngles = true;
  92. m_ViewSmoothingData.flPitchCurveZero = PITCH_CURVE_ZERO;
  93. m_ViewSmoothingData.flPitchCurveLinear = PITCH_CURVE_LINEAR;
  94. m_ViewSmoothingData.flRollCurveZero = ROLL_CURVE_ZERO;
  95. m_ViewSmoothingData.flRollCurveLinear = ROLL_CURVE_LINEAR;
  96. m_ViewSmoothingData.flFOV = POD_VIEW_FOV;
  97. m_flFOV = 0;
  98. }
  99. //-----------------------------------------------------------------------------
  100. // Purpose:
  101. // Input : updateType -
  102. //-----------------------------------------------------------------------------
  103. void C_PropVehiclePrisonerPod::PreDataUpdate( DataUpdateType_t updateType )
  104. {
  105. BaseClass::PreDataUpdate( updateType );
  106. m_hPrevPlayer = m_hPlayer;
  107. }
  108. //-----------------------------------------------------------------------------
  109. // Purpose:
  110. //-----------------------------------------------------------------------------
  111. void C_PropVehiclePrisonerPod::PostDataUpdate( DataUpdateType_t updateType )
  112. {
  113. BaseClass::PostDataUpdate( updateType );
  114. if ( !m_hPlayer && m_hPrevPlayer )
  115. {
  116. // They have just exited the vehicle.
  117. // Sometimes we never reach the end of our exit anim, such as if the
  118. // animation doesn't have fadeout 0 specified in the QC, so we fail to
  119. // catch it in VehicleViewSmoothing. Catch it here instead.
  120. m_ViewSmoothingData.bWasRunningAnim = false;
  121. }
  122. }
  123. //-----------------------------------------------------------------------------
  124. // Purpose:
  125. //-----------------------------------------------------------------------------
  126. C_BaseCombatCharacter *C_PropVehiclePrisonerPod::GetPassenger( int nRole )
  127. {
  128. if ( nRole == VEHICLE_ROLE_DRIVER )
  129. return m_hPlayer.Get();
  130. return NULL;
  131. }
  132. //-----------------------------------------------------------------------------
  133. // Returns the role of the passenger
  134. //-----------------------------------------------------------------------------
  135. int C_PropVehiclePrisonerPod::GetPassengerRole( C_BaseCombatCharacter *pPassenger )
  136. {
  137. if ( m_hPlayer.Get() == pPassenger )
  138. return VEHICLE_ROLE_DRIVER;
  139. return VEHICLE_ROLE_NONE;
  140. }
  141. //-----------------------------------------------------------------------------
  142. // Purpose: Modify the player view/camera while in a vehicle
  143. //-----------------------------------------------------------------------------
  144. void C_PropVehiclePrisonerPod::GetVehicleViewPosition( int nRole, Vector *pAbsOrigin, QAngle *pAbsAngles, float *pFOV /*=NULL*/ )
  145. {
  146. SharedVehicleViewSmoothing( m_hPlayer,
  147. pAbsOrigin, pAbsAngles,
  148. m_bEnterAnimOn, m_bExitAnimOn,
  149. m_vecEyeExitEndpoint,
  150. &m_ViewSmoothingData,
  151. pFOV );
  152. }
  153. //-----------------------------------------------------------------------------
  154. // Purpose:
  155. // Input : pLocalPlayer -
  156. // pCmd -
  157. //-----------------------------------------------------------------------------
  158. void C_PropVehiclePrisonerPod::UpdateViewAngles( C_BasePlayer *pLocalPlayer, CUserCmd *pCmd )
  159. {
  160. int eyeAttachmentIndex = LookupAttachment( "vehicle_driver_eyes" );
  161. Vector vehicleEyeOrigin;
  162. QAngle vehicleEyeAngles;
  163. GetAttachmentLocal( eyeAttachmentIndex, vehicleEyeOrigin, vehicleEyeAngles );
  164. // Limit the yaw.
  165. float flAngleDiff = AngleDiff( pCmd->viewangles.y, vehicleEyeAngles.y );
  166. flAngleDiff = clamp( flAngleDiff, POD_VIEW_YAW_MIN, POD_VIEW_YAW_MAX );
  167. pCmd->viewangles.y = vehicleEyeAngles.y + flAngleDiff;
  168. // Limit the pitch -- don't let them look down into the empty pod!
  169. flAngleDiff = AngleDiff( pCmd->viewangles.x, vehicleEyeAngles.x );
  170. flAngleDiff = clamp( flAngleDiff, POD_VIEW_PITCH_MIN, POD_VIEW_PITCH_MAX );
  171. pCmd->viewangles.x = vehicleEyeAngles.x + flAngleDiff;
  172. }
  173. //-----------------------------------------------------------------------------
  174. // Futzes with the clip planes
  175. //-----------------------------------------------------------------------------
  176. void C_PropVehiclePrisonerPod::GetVehicleClipPlanes( float &flZNear, float &flZFar ) const
  177. {
  178. // Pod doesn't need to adjust the clip planes.
  179. //flZNear = 6;
  180. }
  181. //-----------------------------------------------------------------------------
  182. // Renders hud elements
  183. //-----------------------------------------------------------------------------
  184. void C_PropVehiclePrisonerPod::DrawHudElements( )
  185. {
  186. }