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.

180 lines
5.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: This is a bastardization of the vehicle code for the choreography
  4. // group who want to have smooth view lerping code out of a keyframed
  5. // controlled player viewpoint.
  6. //
  7. // $NoKeywords: $
  8. //=============================================================================//
  9. #include "cbase.h"
  10. #include "vehicle_base.h"
  11. #include "hl2_player.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. //-----------------------------------------------------------------------------
  15. // Purpose:
  16. //-----------------------------------------------------------------------------
  17. class CPropVehicleViewController : public CPropVehicleDriveable
  18. {
  19. DECLARE_CLASS( CPropVehicleViewController, CPropVehicleDriveable );
  20. public:
  21. DECLARE_DATADESC();
  22. // CBaseEntity
  23. void Spawn( void );
  24. void Think(void);
  25. // CPropVehicle
  26. virtual void SetupMove( CBasePlayer *player, CUserCmd *ucmd, IMoveHelper *pHelper, CMoveData *move );
  27. virtual void EnterVehicle( CBasePlayer *pPlayer );
  28. virtual void ExitVehicle( int nRole );
  29. // Inputs to force the player in/out of the vehicle
  30. void InputForcePlayerIn( inputdata_t &inputdata );
  31. void InputForcePlayerOut( inputdata_t &inputdata );
  32. };
  33. BEGIN_DATADESC( CPropVehicleViewController )
  34. DEFINE_INPUTFUNC( FIELD_STRING, "ForcePlayerIn", InputForcePlayerIn ),
  35. DEFINE_INPUTFUNC( FIELD_VOID, "ForcePlayerOut", InputForcePlayerOut ),
  36. END_DATADESC()
  37. LINK_ENTITY_TO_CLASS( vehicle_viewcontroller, CPropVehicleViewController );
  38. //------------------------------------------------
  39. // Spawn
  40. //------------------------------------------------
  41. void CPropVehicleViewController::Spawn( void )
  42. {
  43. BaseClass::Spawn();
  44. AddSolidFlags( FSOLID_NOT_STANDABLE );
  45. }
  46. //-----------------------------------------------------------------------------
  47. // Purpose:
  48. //-----------------------------------------------------------------------------
  49. void CPropVehicleViewController::Think(void)
  50. {
  51. BaseClass::Think();
  52. SetSimulationTime( gpGlobals->curtime );
  53. SetNextThink( gpGlobals->curtime );
  54. SetAnimatedEveryTick( true );
  55. StudioFrameAdvance();
  56. // If the exit anim has finished, move the player to the right spot and stop animating
  57. if ( IsSequenceFinished() && (m_bExitAnimOn || m_bEnterAnimOn) )
  58. {
  59. // If we're exiting and have had the tau cannon removed, we don't want to reset the animation
  60. GetServerVehicle()->HandleEntryExitFinish( m_bExitAnimOn, false );
  61. m_bExitAnimOn = false;
  62. m_bEnterAnimOn = false;
  63. }
  64. }
  65. //-----------------------------------------------------------------------------
  66. // Purpose:
  67. //-----------------------------------------------------------------------------
  68. void CPropVehicleViewController::SetupMove( CBasePlayer *player, CUserCmd *ucmd, IMoveHelper *pHelper, CMoveData *move )
  69. {
  70. // Does nothing, because this vehicle doesn't drive
  71. }
  72. //-----------------------------------------------------------------------------
  73. // Purpose:
  74. // NOTE: Doesn't call the base call enter vehicle on purpose!
  75. //-----------------------------------------------------------------------------
  76. void CPropVehicleViewController::EnterVehicle( CBasePlayer *pPlayer )
  77. {
  78. if ( !pPlayer )
  79. return;
  80. m_hPlayer = pPlayer;
  81. pPlayer->SetViewOffset( vec3_origin );
  82. pPlayer->ShowCrosshair( false );
  83. m_playerOn.FireOutput( pPlayer, this, 0 );
  84. // Start Thinking
  85. SetNextThink( gpGlobals->curtime );
  86. m_VehiclePhysics.GetVehicle()->OnVehicleEnter();
  87. // Stop the player sprint and flashlight.
  88. CHL2_Player *pHL2Player = dynamic_cast<CHL2_Player*>( pPlayer );
  89. if ( pHL2Player )
  90. {
  91. if ( pHL2Player->IsSprinting() )
  92. {
  93. pHL2Player->StopSprinting();
  94. }
  95. if ( pHL2Player->FlashlightIsOn() )
  96. {
  97. pHL2Player->FlashlightTurnOff();
  98. }
  99. }
  100. }
  101. //-----------------------------------------------------------------------------
  102. // Purpose:
  103. //-----------------------------------------------------------------------------
  104. void CPropVehicleViewController::ExitVehicle( int nRole )
  105. {
  106. BaseClass::ExitVehicle( nRole );
  107. m_bEnterAnimOn = false;
  108. }
  109. //-----------------------------------------------------------------------------
  110. // Purpose:
  111. //-----------------------------------------------------------------------------
  112. void CPropVehicleViewController::InputForcePlayerIn( inputdata_t &inputdata )
  113. {
  114. CBasePlayer *pPlayer = UTIL_PlayerByIndex(1);
  115. if ( !pPlayer )
  116. return;
  117. ResetUseKey( pPlayer );
  118. // Get the entry animation from the input
  119. int iEntryAnim = ACTIVITY_NOT_AVAILABLE;
  120. if ( inputdata.value.StringID() != NULL_STRING )
  121. {
  122. iEntryAnim = LookupSequence( inputdata.value.String() );
  123. if ( iEntryAnim == ACTIVITY_NOT_AVAILABLE )
  124. {
  125. Warning("vehicle_viewcontroller %s could not find specified entry animation %s\n", STRING(GetEntityName()), inputdata.value.String() );
  126. return;
  127. }
  128. }
  129. // Make sure we successfully got in the vehicle
  130. if ( pPlayer->GetInVehicle( GetServerVehicle(), VEHICLE_ROLE_DRIVER ) == false )
  131. {
  132. // The player was unable to enter the vehicle and the output has failed
  133. Assert( 0 );
  134. return;
  135. }
  136. // Setup the "enter" vehicle sequence
  137. SetCycle( 0 );
  138. m_flAnimTime = gpGlobals->curtime;
  139. ResetSequence( iEntryAnim );
  140. ResetClientsideFrame();
  141. m_bEnterAnimOn = true;
  142. }
  143. //-----------------------------------------------------------------------------
  144. // Purpose:
  145. //-----------------------------------------------------------------------------
  146. void CPropVehicleViewController::InputForcePlayerOut( inputdata_t &inputdata )
  147. {
  148. if ( !GetDriver() )
  149. return;
  150. GetServerVehicle()->HandlePassengerExit( m_hPlayer );
  151. }