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.

158 lines
4.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "citadel_effects_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_citadel_energy_core, CCitadelEnergyCore );
  11. BEGIN_DATADESC( CCitadelEnergyCore )
  12. DEFINE_KEYFIELD( m_flScale, FIELD_FLOAT, "scale" ),
  13. DEFINE_FIELD( m_nState, FIELD_INTEGER ),
  14. DEFINE_FIELD( m_flDuration, FIELD_FLOAT ),
  15. DEFINE_FIELD( m_flStartTime, FIELD_TIME ),
  16. DEFINE_INPUTFUNC( FIELD_FLOAT, "StartCharge", InputStartCharge ),
  17. DEFINE_INPUTFUNC( FIELD_VOID, "StartDischarge", InputStartDischarge ),
  18. DEFINE_INPUTFUNC( FIELD_FLOAT, "Stop", InputStop ),
  19. END_DATADESC()
  20. IMPLEMENT_SERVERCLASS_ST( CCitadelEnergyCore, DT_CitadelEnergyCore )
  21. SendPropFloat( SENDINFO(m_flScale), 0, SPROP_NOSCALE),
  22. SendPropInt( SENDINFO(m_nState), 8, SPROP_UNSIGNED),
  23. SendPropFloat( SENDINFO(m_flDuration), 0, SPROP_NOSCALE),
  24. SendPropFloat( SENDINFO(m_flStartTime), 0, SPROP_NOSCALE),
  25. SendPropInt( SENDINFO(m_spawnflags), 0, SPROP_UNSIGNED),
  26. END_SEND_TABLE()
  27. //-----------------------------------------------------------------------------
  28. // Precache:
  29. //-----------------------------------------------------------------------------
  30. void CCitadelEnergyCore::Precache()
  31. {
  32. BaseClass::Precache();
  33. PrecacheMaterial( "effects/combinemuzzle2_dark" );
  34. }
  35. //-----------------------------------------------------------------------------
  36. // Purpose:
  37. //-----------------------------------------------------------------------------
  38. void CCitadelEnergyCore::Spawn( void )
  39. {
  40. Precache();
  41. UTIL_SetSize( this, Vector( -8, -8, -8 ), Vector( 8, 8, 8 ) );
  42. // See if we start active
  43. if ( HasSpawnFlags( SF_ENERGYCORE_START_ON ) )
  44. {
  45. m_nState = (int)ENERGYCORE_STATE_DISCHARGING;
  46. m_flStartTime = gpGlobals->curtime;
  47. }
  48. // No model but we still need to force this!
  49. AddEFlags( EFL_FORCE_CHECK_TRANSMIT );
  50. }
  51. //-----------------------------------------------------------------------------
  52. // Purpose:
  53. // Input : flWarmUpTime -
  54. //-----------------------------------------------------------------------------
  55. void CCitadelEnergyCore::StartCharge( float flWarmUpTime )
  56. {
  57. m_nState = (int)ENERGYCORE_STATE_CHARGING;
  58. m_flDuration = flWarmUpTime;
  59. m_flStartTime = gpGlobals->curtime;
  60. }
  61. //-----------------------------------------------------------------------------
  62. // Purpose:
  63. //-----------------------------------------------------------------------------
  64. void CCitadelEnergyCore::StartDischarge( void )
  65. {
  66. m_nState = (int)ENERGYCORE_STATE_DISCHARGING;
  67. m_flStartTime = gpGlobals->curtime;
  68. }
  69. //-----------------------------------------------------------------------------
  70. // Purpose:
  71. // Input : flCoolDownTime -
  72. //-----------------------------------------------------------------------------
  73. void CCitadelEnergyCore::StopDischarge( float flCoolDownTime )
  74. {
  75. m_nState = (int)ENERGYCORE_STATE_OFF;
  76. m_flDuration = flCoolDownTime;
  77. m_flStartTime = gpGlobals->curtime;
  78. }
  79. //-----------------------------------------------------------------------------
  80. // Purpose:
  81. // Input : &inputdata -
  82. //-----------------------------------------------------------------------------
  83. void CCitadelEnergyCore::InputStartCharge( inputdata_t &inputdata )
  84. {
  85. StartCharge( inputdata.value.Float() );
  86. }
  87. //-----------------------------------------------------------------------------
  88. // Purpose:
  89. // Input : &inputdata -
  90. //-----------------------------------------------------------------------------
  91. void CCitadelEnergyCore::InputStartDischarge( inputdata_t &inputdata )
  92. {
  93. StartDischarge();
  94. }
  95. //-----------------------------------------------------------------------------
  96. // Purpose:
  97. // Input : &inputdata -
  98. //-----------------------------------------------------------------------------
  99. void CCitadelEnergyCore::InputStop( inputdata_t &inputdata )
  100. {
  101. StopDischarge( inputdata.value.Float() );
  102. }
  103. CBaseViewModel *IsViewModelMoveParent( CBaseEntity *pEffect )
  104. {
  105. if ( pEffect->GetMoveParent() )
  106. {
  107. CBaseViewModel *pViewModel = dynamic_cast<CBaseViewModel *>( pEffect->GetMoveParent() );
  108. if ( pViewModel )
  109. {
  110. return pViewModel;
  111. }
  112. }
  113. return NULL;
  114. }
  115. int CCitadelEnergyCore::UpdateTransmitState( void )
  116. {
  117. if ( IsViewModelMoveParent( this ) )
  118. {
  119. return SetTransmitState( FL_EDICT_FULLCHECK );
  120. }
  121. return BaseClass::UpdateTransmitState();
  122. }
  123. int CCitadelEnergyCore::ShouldTransmit( const CCheckTransmitInfo *pInfo )
  124. {
  125. CBaseViewModel *pViewModel = IsViewModelMoveParent( this );
  126. if ( pViewModel )
  127. {
  128. return pViewModel->ShouldTransmit( pInfo );
  129. }
  130. return BaseClass::ShouldTransmit( pInfo );
  131. }