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.

187 lines
6.2 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. #include "vehicle_viewblend_shared.h"
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include "tier0/memdbgon.h"
  16. int ScreenTransform( const Vector& point, Vector& screen );
  17. //-----------------------------------------------------------------------------
  18. // Purpose:
  19. //-----------------------------------------------------------------------------
  20. class C_PropCannon : public C_BaseAnimating, public IClientVehicle
  21. {
  22. DECLARE_CLASS( C_PropCannon, C_BaseAnimating );
  23. public:
  24. DECLARE_CLIENTCLASS();
  25. DECLARE_DATADESC();
  26. C_PropCannon();
  27. void PreDataUpdate( DataUpdateType_t updateType );
  28. public:
  29. // IClientVehicle overrides.
  30. virtual void GetVehicleViewPosition( int nRole, Vector *pOrigin, QAngle *pAngles, float *pFOV = NULL );
  31. virtual void GetVehicleFOV( float &flFOV ) { flFOV = 0.0f; }
  32. virtual void DrawHudElements();
  33. virtual bool IsPassengerUsingStandardWeapons( int nRole = VEHICLE_ROLE_DRIVER ) { return false; }
  34. virtual void UpdateViewAngles( C_BasePlayer *pLocalPlayer, CUserCmd *pCmd ) {}
  35. virtual C_BaseCombatCharacter *GetPassenger( int nRole );
  36. virtual int GetPassengerRole( C_BaseCombatCharacter *pPassenger );
  37. virtual void GetVehicleClipPlanes( float &flZNear, float &flZFar ) const;
  38. virtual int GetPrimaryAmmoType() const { return -1; }
  39. virtual int GetPrimaryAmmoCount() const { return -1; }
  40. virtual int GetPrimaryAmmoClip() const { return -1; }
  41. virtual bool PrimaryAmmoUsesClips() const { return false; }
  42. virtual int GetJoystickResponseCurve() const { return 0; }
  43. public:
  44. // C_BaseEntity overrides.
  45. virtual IClientVehicle* GetClientVehicle() { return this; }
  46. virtual C_BaseEntity *GetVehicleEnt() { return this; }
  47. virtual void SetupMove( C_BasePlayer *player, CUserCmd *ucmd, IMoveHelper *pHelper, CMoveData *move ) {}
  48. virtual void ProcessMovement( C_BasePlayer *pPlayer, CMoveData *pMoveData ) {}
  49. virtual void FinishMove( C_BasePlayer *player, CUserCmd *ucmd, CMoveData *move ) {}
  50. virtual bool IsPredicted() const { return false; }
  51. virtual void ItemPostFrame( C_BasePlayer *pPlayer ) {}
  52. virtual bool IsSelfAnimating() { return false; };
  53. virtual void GetRenderBounds( Vector& theMins, Vector& theMaxs );
  54. private:
  55. CHandle<C_BasePlayer> m_hPlayer;
  56. CHandle<C_BasePlayer> m_hPrevPlayer;
  57. bool m_bEnterAnimOn;
  58. bool m_bExitAnimOn;
  59. Vector m_vecEyeExitEndpoint;
  60. Vector m_vecOldShadowDir;
  61. ViewSmoothingData_t m_ViewSmoothingData;
  62. };
  63. IMPLEMENT_CLIENTCLASS_DT(C_PropCannon, DT_PropCannon, CPropCannon)
  64. RecvPropEHandle( RECVINFO(m_hPlayer) ),
  65. RecvPropBool( RECVINFO( m_bEnterAnimOn ) ),
  66. RecvPropBool( RECVINFO( m_bExitAnimOn ) ),
  67. RecvPropVector( RECVINFO( m_vecEyeExitEndpoint ) ),
  68. END_RECV_TABLE()
  69. BEGIN_DATADESC( C_PropCannon )
  70. DEFINE_EMBEDDED( m_ViewSmoothingData ),
  71. END_DATADESC()
  72. #define ROLL_CURVE_ZERO 5 // roll less than this is clamped to zero
  73. #define ROLL_CURVE_LINEAR 45 // roll greater than this is copied out
  74. #define PITCH_CURVE_ZERO 10 // pitch less than this is clamped to zero
  75. #define PITCH_CURVE_LINEAR 45 // pitch greater than this is copied out
  76. // spline in between
  77. //-----------------------------------------------------------------------------
  78. // Purpose:
  79. //-----------------------------------------------------------------------------
  80. C_PropCannon::C_PropCannon( void )
  81. {
  82. memset( &m_ViewSmoothingData, 0, sizeof( m_ViewSmoothingData ) );
  83. m_ViewSmoothingData.pVehicle = this;
  84. }
  85. //-----------------------------------------------------------------------------
  86. // Purpose:
  87. // Input : updateType -
  88. //-----------------------------------------------------------------------------
  89. void C_PropCannon::PreDataUpdate( DataUpdateType_t updateType )
  90. {
  91. BaseClass::PreDataUpdate( updateType );
  92. m_hPrevPlayer = m_hPlayer;
  93. }
  94. //-----------------------------------------------------------------------------
  95. // Purpose:
  96. //-----------------------------------------------------------------------------
  97. C_BaseCombatCharacter *C_PropCannon::GetPassenger( int nRole )
  98. {
  99. if ( nRole == VEHICLE_ROLE_DRIVER )
  100. return m_hPlayer.Get();
  101. return NULL;
  102. }
  103. //-----------------------------------------------------------------------------
  104. // Returns the role of the passenger
  105. //-----------------------------------------------------------------------------
  106. int C_PropCannon::GetPassengerRole( C_BaseCombatCharacter *pPassenger )
  107. {
  108. if ( m_hPlayer.Get() == pPassenger )
  109. return VEHICLE_ROLE_DRIVER;
  110. return VEHICLE_ROLE_NONE;
  111. }
  112. //-----------------------------------------------------------------------------
  113. // Purpose: Modify the player view/camera while in a vehicle
  114. //-----------------------------------------------------------------------------
  115. void C_PropCannon::GetVehicleViewPosition( int nRole, Vector *pAbsOrigin, QAngle *pAbsAngles, float *pFOV /*=NULL*/ )
  116. {
  117. SharedVehicleViewSmoothing( m_hPlayer,
  118. pAbsOrigin, pAbsAngles,
  119. m_bEnterAnimOn, m_bExitAnimOn,
  120. m_vecEyeExitEndpoint,
  121. &m_ViewSmoothingData,
  122. pFOV );
  123. }
  124. //-----------------------------------------------------------------------------
  125. // Futzes with the clip planes
  126. //-----------------------------------------------------------------------------
  127. void C_PropCannon::GetVehicleClipPlanes( float &flZNear, float &flZFar ) const
  128. {
  129. // FIXME: Need something a better long-term, this fixes the buggy.
  130. flZNear = 6;
  131. }
  132. //-----------------------------------------------------------------------------
  133. // Renders hud elements
  134. //-----------------------------------------------------------------------------
  135. void C_PropCannon::DrawHudElements( )
  136. {
  137. }
  138. //-----------------------------------------------------------------------------
  139. // Purpose:
  140. // Input : theMins -
  141. // theMaxs -
  142. //-----------------------------------------------------------------------------
  143. void C_PropCannon::GetRenderBounds( Vector &theMins, Vector &theMaxs )
  144. {
  145. // This is kind of hacky:( Add 660.0 to the y coordinate of the bounding box to
  146. // allow for the full extension of the crane arm.
  147. BaseClass::GetRenderBounds( theMins, theMaxs );
  148. theMaxs.y += 660.0f;
  149. }