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.

148 lines
3.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "cbase.h"
  9. #include "hltvdirector.h"
  10. #include "igameevents.h"
  11. class CCSHLTVDirector : public CHLTVDirector
  12. {
  13. public:
  14. DECLARE_CLASS( CCSHLTVDirector, CHLTVDirector );
  15. const char** GetModEvents();
  16. void SetHLTVServer( IHLTVServer *hltv );
  17. void CreateShotFromEvent( CHLTVGameEvent *event );
  18. };
  19. void CCSHLTVDirector::SetHLTVServer( IHLTVServer *hltv )
  20. {
  21. BaseClass::SetHLTVServer( hltv );
  22. if ( m_pHLTVServer )
  23. {
  24. // mod specific events the director uses to find interesting shots
  25. ListenForGameEvent( "hostage_rescued" );
  26. ListenForGameEvent( "hostage_killed" );
  27. ListenForGameEvent( "hostage_hurt" );
  28. ListenForGameEvent( "hostage_follows" );
  29. ListenForGameEvent( "bomb_pickup" );
  30. ListenForGameEvent( "bomb_dropped" );
  31. ListenForGameEvent( "bomb_exploded" );
  32. ListenForGameEvent( "bomb_defused" );
  33. ListenForGameEvent( "bomb_planted" );
  34. ListenForGameEvent( "vip_escaped" );
  35. ListenForGameEvent( "vip_killed" );
  36. }
  37. }
  38. void CCSHLTVDirector::CreateShotFromEvent( CHLTVGameEvent *event )
  39. {
  40. // show event at least for 2 more seconds after it occured
  41. const char *name = event->m_Event->GetName();
  42. IGameEvent *shot = NULL;
  43. if ( !Q_strcmp( "hostage_rescued", name ) ||
  44. !Q_strcmp( "hostage_hurt", name ) ||
  45. !Q_strcmp( "hostage_follows", name ) ||
  46. !Q_strcmp( "hostage_killed", name ) )
  47. {
  48. CBaseEntity *player = UTIL_PlayerByUserId( event->m_Event->GetInt("userid") );
  49. if ( !player )
  50. return;
  51. // shot player as primary, hostage as secondary target
  52. shot = gameeventmanager->CreateEvent( "hltv_chase", true );
  53. shot->SetInt( "target1", player->entindex() );
  54. shot->SetInt( "target2", event->m_Event->GetInt("hostage") );
  55. shot->SetFloat( "distance", 96.0f );
  56. shot->SetInt( "theta", 40 );
  57. shot->SetInt( "phi", 20 );
  58. // shot 2 seconds after event
  59. m_nNextShotTick = MIN( m_nNextShotTick, (event->m_Tick+TIME_TO_TICKS(2.0)) );
  60. m_iPVSEntity = player->entindex();
  61. }
  62. else if ( !Q_strcmp( "bomb_pickup", name ) ||
  63. !Q_strcmp( "bomb_dropped", name ) ||
  64. !Q_strcmp( "bomb_planted", name ) ||
  65. !Q_strcmp( "bomb_defused", name ) )
  66. {
  67. CBaseEntity *player = UTIL_PlayerByUserId( event->m_Event->GetInt("userid") );
  68. if ( !player )
  69. return;
  70. shot = gameeventmanager->CreateEvent( "hltv_chase", true );
  71. shot->SetInt( "target1", player->entindex() );
  72. shot->SetInt( "target2", 0 );
  73. shot->SetFloat( "distance", 64.0f );
  74. shot->SetInt( "theta", 200 );
  75. shot->SetInt( "phi", 10 );
  76. // shot 2 seconds after pickup
  77. m_nNextShotTick = MIN( m_nNextShotTick, (event->m_Tick+TIME_TO_TICKS(2.0)) );
  78. m_iPVSEntity = player->entindex();
  79. }
  80. else
  81. {
  82. // let baseclass create a shot
  83. BaseClass::CreateShotFromEvent( event );
  84. return;
  85. }
  86. if ( shot )
  87. {
  88. m_pHLTVServer->BroadcastEvent( shot );
  89. gameeventmanager->FreeEvent( shot );
  90. DevMsg("DrcCmd: %s\n", name );
  91. }
  92. }
  93. const char** CCSHLTVDirector::GetModEvents()
  94. {
  95. // game events relayed to spectator clients
  96. static const char *s_modevents[] =
  97. {
  98. "hltv_status",
  99. "hltv_chat",
  100. "player_connect",
  101. "player_disconnect",
  102. "player_team",
  103. "player_info",
  104. "server_cvar",
  105. "player_death",
  106. "player_chat",
  107. "round_start",
  108. "round_end",
  109. // additional CS:S events:
  110. "bomb_planted",
  111. "bomb_defused",
  112. "hostage_killed",
  113. "hostage_hurt",
  114. NULL
  115. };
  116. return s_modevents;
  117. }
  118. static CCSHLTVDirector s_HLTVDirector; // singleton
  119. EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CHLTVDirector, IHLTVDirector, INTERFACEVERSION_HLTVDIRECTOR, s_HLTVDirector );
  120. CHLTVDirector* HLTVDirector()
  121. {
  122. return &s_HLTVDirector;
  123. }
  124. IGameSystem* HLTVDirectorSystem()
  125. {
  126. return &s_HLTVDirector;
  127. }