Counter Strike : Global Offensive Source Code
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.

97 lines
2.6 KiB

  1. //========= Copyright � 1996-2006, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Entity that propagates train data for escort gametype
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "c_team_train_watcher.h"
  9. #include "igameevents.h"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. IMPLEMENT_CLIENTCLASS_DT_NOBASE(C_TeamTrainWatcher, DT_TeamTrainWatcher, CTeamTrainWatcher)
  13. RecvPropFloat( RECVINFO( m_flTotalProgress ) ),
  14. RecvPropInt( RECVINFO( m_iTrainSpeedLevel ) ),
  15. RecvPropFloat( RECVINFO( m_flRecedeTime ) ),
  16. RecvPropInt( RECVINFO( m_nNumCappers ) ),
  17. END_RECV_TABLE()
  18. C_TeamTrainWatcher *g_pTrainWatcher = NULL;
  19. C_TeamTrainWatcher::C_TeamTrainWatcher()
  20. {
  21. g_pTrainWatcher = this;
  22. // force updates when we get our baseline
  23. m_iTrainSpeedLevel = -2;
  24. m_flTotalProgress = -1;
  25. m_flRecedeTime = -1;
  26. }
  27. //-----------------------------------------------------------------------------
  28. // Purpose:
  29. //-----------------------------------------------------------------------------
  30. C_TeamTrainWatcher::~C_TeamTrainWatcher()
  31. {
  32. if ( g_pTrainWatcher == this )
  33. {
  34. g_pTrainWatcher = NULL;
  35. }
  36. }
  37. void C_TeamTrainWatcher::OnPreDataChanged( DataUpdateType_t updateType )
  38. {
  39. BaseClass::OnPreDataChanged( updateType );
  40. m_iOldTrainSpeedLevel = m_iTrainSpeedLevel;
  41. m_flOldProgress = m_flTotalProgress;
  42. m_flOldRecedeTime = m_flRecedeTime;
  43. m_nOldNumCappers = m_nNumCappers;
  44. }
  45. //-----------------------------------------------------------------------------
  46. // Purpose:
  47. //-----------------------------------------------------------------------------
  48. void C_TeamTrainWatcher::OnDataChanged( DataUpdateType_t updateType )
  49. {
  50. if ( m_iOldTrainSpeedLevel != m_iTrainSpeedLevel || m_nOldNumCappers != m_nNumCappers )
  51. {
  52. IGameEvent *event = gameeventmanager->CreateEvent( "escort_speed" );
  53. if ( event )
  54. {
  55. event->SetInt( "speed", m_iTrainSpeedLevel );
  56. event->SetInt( "players", m_nNumCappers );
  57. gameeventmanager->FireEventClientSide( event );
  58. }
  59. }
  60. if ( m_flOldProgress != m_flTotalProgress )
  61. {
  62. IGameEvent *event = gameeventmanager->CreateEvent( "escort_progress" );
  63. if ( event )
  64. {
  65. event->SetFloat( "progress", m_flTotalProgress );
  66. if ( m_flOldProgress <= -1 )
  67. {
  68. event->SetBool( "reset", true );
  69. }
  70. gameeventmanager->FireEventClientSide( event );
  71. }
  72. }
  73. if ( m_flOldRecedeTime != m_flRecedeTime )
  74. {
  75. IGameEvent *event = gameeventmanager->CreateEvent( "escort_recede" );
  76. if ( event )
  77. {
  78. event->SetFloat( "recedetime", m_flRecedeTime );
  79. gameeventmanager->FireEventClientSide( event );
  80. }
  81. }
  82. }