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.

125 lines
3.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. // memdbgon must be the last include file in a .cpp file!!!
  8. #include "tier0/memdbgon.h"
  9. //-----------------------------------------------------------------------------
  10. // Amount of time before breen teleports away
  11. //-----------------------------------------------------------------------------
  12. class CInfoTeleporterCountdown : public CPointEntity
  13. {
  14. DECLARE_CLASS( CInfoTeleporterCountdown, CPointEntity );
  15. DECLARE_SERVERCLASS();
  16. DECLARE_DATADESC();
  17. public:
  18. virtual int UpdateTransmitState();
  19. private:
  20. void InputDisable(inputdata_t &inputdata);
  21. void InputEnable(inputdata_t &inputdata);
  22. void InputStartCountdown(inputdata_t &inputdata);
  23. void InputStopCountdown(inputdata_t &inputdata);
  24. CNetworkVar( bool, m_bCountdownStarted );
  25. CNetworkVar( bool, m_bDisabled );
  26. CNetworkVar( float, m_flStartTime );
  27. CNetworkVar( float, m_flTimeRemaining );
  28. };
  29. //-----------------------------------------------------------------------------
  30. // Save/load
  31. //-----------------------------------------------------------------------------
  32. BEGIN_DATADESC( CInfoTeleporterCountdown )
  33. DEFINE_FIELD( m_bCountdownStarted, FIELD_BOOLEAN ),
  34. DEFINE_FIELD( m_bDisabled, FIELD_BOOLEAN ),
  35. DEFINE_FIELD( m_flStartTime, FIELD_TIME ),
  36. DEFINE_FIELD( m_flTimeRemaining, FIELD_FLOAT ),
  37. // Outputs
  38. DEFINE_INPUTFUNC( FIELD_VOID, "Enable", InputEnable ),
  39. DEFINE_INPUTFUNC( FIELD_VOID, "Disable", InputDisable ),
  40. DEFINE_INPUTFUNC( FIELD_FLOAT, "StartCountdown", InputStartCountdown ),
  41. DEFINE_INPUTFUNC( FIELD_VOID, "StopCountdown", InputStopCountdown ),
  42. END_DATADESC()
  43. LINK_ENTITY_TO_CLASS( info_teleporter_countdown, CInfoTeleporterCountdown );
  44. //-----------------------------------------------------------------------------
  45. // Networking
  46. //-----------------------------------------------------------------------------
  47. IMPLEMENT_SERVERCLASS_ST( CInfoTeleporterCountdown, DT_InfoTeleporterCountdown )
  48. SendPropInt( SENDINFO( m_bCountdownStarted ), 1, SPROP_UNSIGNED ),
  49. SendPropInt( SENDINFO( m_bDisabled ), 1, SPROP_UNSIGNED ),
  50. SendPropTime( SENDINFO( m_flStartTime ) ),
  51. SendPropFloat( SENDINFO( m_flTimeRemaining ), 0, SPROP_NOSCALE ),
  52. END_SEND_TABLE()
  53. //-----------------------------------------------------------------------------
  54. // Starts/stops countdown
  55. //-----------------------------------------------------------------------------
  56. void CInfoTeleporterCountdown::InputStartCountdown(inputdata_t &inputdata)
  57. {
  58. if (!m_bCountdownStarted)
  59. {
  60. m_bCountdownStarted = true;
  61. m_bDisabled = false;
  62. m_flStartTime = gpGlobals->curtime;
  63. m_flTimeRemaining = inputdata.value.Float();
  64. }
  65. }
  66. void CInfoTeleporterCountdown::InputStopCountdown(inputdata_t &inputdata)
  67. {
  68. m_bCountdownStarted = false;
  69. }
  70. //-----------------------------------------------------------------------------
  71. // Disables/reenables an active countdown
  72. //-----------------------------------------------------------------------------
  73. void CInfoTeleporterCountdown::InputDisable(inputdata_t &inputdata)
  74. {
  75. if ( !m_bDisabled )
  76. {
  77. m_bDisabled = true;
  78. if ( m_bCountdownStarted )
  79. {
  80. m_flTimeRemaining -= gpGlobals->curtime - m_flStartTime;
  81. }
  82. }
  83. }
  84. void CInfoTeleporterCountdown::InputEnable(inputdata_t &inputdata)
  85. {
  86. if ( m_bDisabled )
  87. {
  88. m_bDisabled = false;
  89. if ( m_bCountdownStarted )
  90. {
  91. m_flStartTime = gpGlobals->curtime;
  92. }
  93. }
  94. }
  95. //-----------------------------------------------------------------------------
  96. // Purpose: Always send the teleporter countdown
  97. //-----------------------------------------------------------------------------
  98. int CInfoTeleporterCountdown::UpdateTransmitState()
  99. {
  100. return SetTransmitState( FL_EDICT_ALWAYS );
  101. }