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.

190 lines
5.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "env_lightrail_endpoint_shared.h"
  8. // memdbgon must be the last include file in a .cpp file!!!
  9. #include "tier0/memdbgon.h"
  10. LINK_ENTITY_TO_CLASS( env_lightrail_endpoint, CEnv_Lightrail_Endpoint );
  11. BEGIN_DATADESC( CEnv_Lightrail_Endpoint )
  12. DEFINE_KEYFIELD( m_flSmallScale, FIELD_FLOAT, "small_fx_scale" ),
  13. DEFINE_KEYFIELD( m_flLargeScale, FIELD_FLOAT, "large_fx_scale" ),
  14. DEFINE_FIELD( m_nState, FIELD_INTEGER ),
  15. DEFINE_FIELD( m_flDuration, FIELD_FLOAT ),
  16. DEFINE_FIELD( m_flStartTime, FIELD_TIME ),
  17. DEFINE_INPUTFUNC( FIELD_FLOAT, "StartCharge", InputStartCharge ),
  18. DEFINE_INPUTFUNC( FIELD_VOID, "StartSmallFX", InputStartSmallFX ),
  19. DEFINE_INPUTFUNC( FIELD_VOID, "StartLargeFX", InputStartLargeFX ),
  20. DEFINE_INPUTFUNC( FIELD_FLOAT, "Stop", InputStop ),
  21. END_DATADESC()
  22. IMPLEMENT_SERVERCLASS_ST( CEnv_Lightrail_Endpoint, DT_Env_Lightrail_Endpoint )
  23. SendPropFloat( SENDINFO(m_flSmallScale), 0, SPROP_NOSCALE),
  24. SendPropFloat( SENDINFO(m_flLargeScale), 0, SPROP_NOSCALE),
  25. SendPropInt( SENDINFO(m_nState), 8, SPROP_UNSIGNED),
  26. SendPropFloat( SENDINFO(m_flDuration), 0, SPROP_NOSCALE),
  27. SendPropFloat( SENDINFO(m_flStartTime), 0, SPROP_NOSCALE),
  28. SendPropInt( SENDINFO(m_spawnflags), 0, SPROP_UNSIGNED),
  29. END_SEND_TABLE()
  30. //-----------------------------------------------------------------------------
  31. // Precache:
  32. //-----------------------------------------------------------------------------
  33. void CEnv_Lightrail_Endpoint::Precache()
  34. {
  35. BaseClass::Precache();
  36. PrecacheMaterial( "effects/light_rail_endpoint" ); //Sprite used for the effects
  37. }
  38. //-----------------------------------------------------------------------------
  39. // Purpose:
  40. //-----------------------------------------------------------------------------
  41. void CEnv_Lightrail_Endpoint::Spawn( void )
  42. {
  43. Precache();
  44. UTIL_SetSize( this, Vector( -8, -8, -8 ), Vector( 8, 8, 8 ) );
  45. // See if we start active
  46. if ( HasSpawnFlags( SF_ENDPOINT_START_SMALLFX ) )
  47. {
  48. m_nState = (int)ENDPOINT_STATE_LARGEFX; //THIS NEEDS TO BE CHANGED TO SMALL FX STATE
  49. m_flStartTime = gpGlobals->curtime;
  50. }
  51. // No model but we still need to force this!
  52. AddEFlags( EFL_FORCE_CHECK_TRANSMIT );
  53. }
  54. //-----------------------------------------------------------------------------
  55. // Purpose:
  56. // Input : flWarmUpTime -
  57. //-----------------------------------------------------------------------------
  58. void CEnv_Lightrail_Endpoint::StartCharge( float flWarmUpTime )
  59. {
  60. m_nState = (int)ENDPOINT_STATE_CHARGING;
  61. m_flDuration = flWarmUpTime;
  62. m_flStartTime = gpGlobals->curtime;
  63. }
  64. //-----------------------------------------------------------------------------
  65. // Purpose:
  66. //-----------------------------------------------------------------------------
  67. void CEnv_Lightrail_Endpoint::StartLargeFX( void )
  68. {
  69. m_nState = (int)ENDPOINT_STATE_LARGEFX;
  70. m_flStartTime = gpGlobals->curtime;
  71. }
  72. //-----------------------------------------------------------------------------
  73. // Purpose:
  74. //-----------------------------------------------------------------------------
  75. void CEnv_Lightrail_Endpoint::StartSmallFX( void )
  76. {
  77. m_nState = (int)ENDPOINT_STATE_SMALLFX;
  78. m_flStartTime = gpGlobals->curtime;
  79. }
  80. //-----------------------------------------------------------------------------
  81. // Purpose:
  82. // Input : flCoolDownTime -
  83. //-----------------------------------------------------------------------------
  84. void CEnv_Lightrail_Endpoint::StopLargeFX( float flCoolDownTime )
  85. {
  86. m_nState = (int)ENDPOINT_STATE_OFF;
  87. m_flDuration = flCoolDownTime;
  88. m_flStartTime = gpGlobals->curtime;
  89. }
  90. //-----------------------------------------------------------------------------
  91. // Purpose:
  92. // Input : flCoolDownTime -
  93. //-----------------------------------------------------------------------------
  94. void CEnv_Lightrail_Endpoint::StopSmallFX( float flCoolDownTime )
  95. {
  96. m_nState = (int)ENDPOINT_STATE_OFF;
  97. m_flDuration = flCoolDownTime;
  98. m_flStartTime = gpGlobals->curtime;
  99. }
  100. //-----------------------------------------------------------------------------
  101. // Purpose:
  102. // Input : &inputdata -
  103. //-----------------------------------------------------------------------------
  104. void CEnv_Lightrail_Endpoint::InputStartCharge( inputdata_t &inputdata )
  105. {
  106. StartCharge( inputdata.value.Float() );
  107. }
  108. //-----------------------------------------------------------------------------
  109. // Purpose:
  110. // Input : &inputdata -
  111. //-----------------------------------------------------------------------------
  112. void CEnv_Lightrail_Endpoint::InputStartLargeFX( inputdata_t &inputdata )
  113. {
  114. StartLargeFX();
  115. }
  116. //-----------------------------------------------------------------------------
  117. // Purpose:
  118. // Input : &inputdata -
  119. //-----------------------------------------------------------------------------
  120. void CEnv_Lightrail_Endpoint::InputStartSmallFX( inputdata_t &inputdata )
  121. {
  122. StartSmallFX();
  123. }
  124. //-----------------------------------------------------------------------------
  125. // Purpose:
  126. // Input : &inputdata -
  127. //-----------------------------------------------------------------------------
  128. void CEnv_Lightrail_Endpoint::InputStop( inputdata_t &inputdata )
  129. {
  130. StopLargeFX( inputdata.value.Float() );
  131. }
  132. CBaseViewModel *IsViewModelMoveParent_( CBaseEntity *pEffect )
  133. {
  134. if ( pEffect->GetMoveParent() )
  135. {
  136. CBaseViewModel *pViewModel = dynamic_cast<CBaseViewModel *>( pEffect->GetMoveParent() );
  137. if ( pViewModel )
  138. {
  139. return pViewModel;
  140. }
  141. }
  142. return NULL;
  143. }
  144. int CEnv_Lightrail_Endpoint::UpdateTransmitState( void )
  145. {
  146. if ( IsViewModelMoveParent_( this ) )
  147. {
  148. return SetTransmitState( FL_EDICT_FULLCHECK );
  149. }
  150. return BaseClass::UpdateTransmitState();
  151. }
  152. int CEnv_Lightrail_Endpoint::ShouldTransmit( const CCheckTransmitInfo *pInfo )
  153. {
  154. CBaseViewModel *pViewModel = IsViewModelMoveParent_( this );
  155. if ( pViewModel )
  156. {
  157. return pViewModel->ShouldTransmit( pInfo );
  158. }
  159. return BaseClass::ShouldTransmit( pInfo );
  160. }