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.

151 lines
4.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "hud.h"
  9. #include <vgui_controls/Controls.h>
  10. #include <Color.h>
  11. #include "c_vehicle_crane.h"
  12. #include "view.h"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. int ScreenTransform( const Vector& point, Vector& screen );
  16. IMPLEMENT_CLIENTCLASS_DT(C_PropCrane, DT_PropCrane, CPropCrane)
  17. RecvPropEHandle( RECVINFO(m_hPlayer) ),
  18. RecvPropBool( RECVINFO(m_bMagnetOn) ),
  19. RecvPropBool( RECVINFO( m_bEnterAnimOn ) ),
  20. RecvPropBool( RECVINFO( m_bExitAnimOn ) ),
  21. RecvPropVector( RECVINFO( m_vecEyeExitEndpoint ) ),
  22. END_RECV_TABLE()
  23. BEGIN_DATADESC( C_PropCrane )
  24. DEFINE_EMBEDDED( m_ViewSmoothingData ),
  25. END_DATADESC()
  26. #define ROLL_CURVE_ZERO 5 // roll less than this is clamped to zero
  27. #define ROLL_CURVE_LINEAR 45 // roll greater than this is copied out
  28. #define PITCH_CURVE_ZERO 10 // pitch less than this is clamped to zero
  29. #define PITCH_CURVE_LINEAR 45 // pitch greater than this is copied out
  30. // spline in between
  31. #define CRANE_FOV 75
  32. //-----------------------------------------------------------------------------
  33. // Purpose:
  34. //-----------------------------------------------------------------------------
  35. C_PropCrane::C_PropCrane( void )
  36. {
  37. memset( &m_ViewSmoothingData, 0, sizeof( m_ViewSmoothingData ) );
  38. m_ViewSmoothingData.pVehicle = this;
  39. m_ViewSmoothingData.flFOV = CRANE_FOV;
  40. }
  41. //-----------------------------------------------------------------------------
  42. // Purpose:
  43. // Input : updateType -
  44. //-----------------------------------------------------------------------------
  45. void C_PropCrane::PreDataUpdate( DataUpdateType_t updateType )
  46. {
  47. BaseClass::PreDataUpdate( updateType );
  48. m_hPrevPlayer = m_hPlayer;
  49. }
  50. //-----------------------------------------------------------------------------
  51. // Purpose:
  52. //-----------------------------------------------------------------------------
  53. void C_PropCrane::PostDataUpdate( DataUpdateType_t updateType )
  54. {
  55. BaseClass::PostDataUpdate( updateType );
  56. // Store off the old shadow direction
  57. if ( m_hPlayer && !m_hPrevPlayer )
  58. {
  59. m_vecOldShadowDir = g_pClientShadowMgr->GetShadowDirection();
  60. //Vector vecDown = m_vecOldShadowDir - Vector(0,0,0.5);
  61. //VectorNormalize( vecDown );
  62. Vector vecDown = Vector(0,0,-1);
  63. g_pClientShadowMgr->SetShadowDirection( vecDown );
  64. }
  65. else if ( !m_hPlayer && m_hPrevPlayer )
  66. {
  67. g_pClientShadowMgr->SetShadowDirection( m_vecOldShadowDir );
  68. }
  69. }
  70. //-----------------------------------------------------------------------------
  71. // Purpose:
  72. //-----------------------------------------------------------------------------
  73. C_BaseCombatCharacter *C_PropCrane::GetPassenger( int nRole )
  74. {
  75. if ( nRole == VEHICLE_ROLE_DRIVER )
  76. return m_hPlayer.Get();
  77. return NULL;
  78. }
  79. //-----------------------------------------------------------------------------
  80. // Returns the role of the passenger
  81. //-----------------------------------------------------------------------------
  82. int C_PropCrane::GetPassengerRole( C_BaseCombatCharacter *pPassenger )
  83. {
  84. if ( m_hPlayer.Get() == pPassenger )
  85. return VEHICLE_ROLE_DRIVER;
  86. return VEHICLE_ROLE_NONE;
  87. }
  88. //-----------------------------------------------------------------------------
  89. // Purpose: Modify the player view/camera while in a vehicle
  90. //-----------------------------------------------------------------------------
  91. void C_PropCrane::GetVehicleViewPosition( int nRole, Vector *pAbsOrigin, QAngle *pAbsAngles, float *pFOV /*=NULL*/ )
  92. {
  93. SharedVehicleViewSmoothing( m_hPlayer,
  94. pAbsOrigin, pAbsAngles,
  95. m_bEnterAnimOn, m_bExitAnimOn,
  96. m_vecEyeExitEndpoint,
  97. &m_ViewSmoothingData,
  98. pFOV );
  99. }
  100. //-----------------------------------------------------------------------------
  101. // Futzes with the clip planes
  102. //-----------------------------------------------------------------------------
  103. void C_PropCrane::GetVehicleClipPlanes( float &flZNear, float &flZFar ) const
  104. {
  105. // FIXME: Need something a better long-term, this fixes the buggy.
  106. flZNear = 6;
  107. }
  108. //-----------------------------------------------------------------------------
  109. // Renders hud elements
  110. //-----------------------------------------------------------------------------
  111. void C_PropCrane::DrawHudElements( )
  112. {
  113. }
  114. //-----------------------------------------------------------------------------
  115. // Purpose:
  116. // Input : theMins -
  117. // theMaxs -
  118. //-----------------------------------------------------------------------------
  119. void C_PropCrane::GetRenderBounds( Vector &theMins, Vector &theMaxs )
  120. {
  121. // This is kind of hacky:( Add 660.0 to the y coordinate of the bounding box to
  122. // allow for the full extension of the crane arm.
  123. BaseClass::GetRenderBounds( theMins, theMaxs );
  124. theMaxs.y += 660.0f;
  125. }