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.

139 lines
3.1 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. class CDODHLTVDirector : public CHLTVDirector
  11. {
  12. public:
  13. DECLARE_CLASS( CDODHLTVDirector, CHLTVDirector );
  14. const char** GetModEvents();
  15. void SetHLTVServer( IHLTVServer *hltv );
  16. void CreateShotFromEvent( CHLTVGameEvent *event );
  17. };
  18. void CDODHLTVDirector::SetHLTVServer( IHLTVServer *hltv )
  19. {
  20. BaseClass::SetHLTVServer( hltv );
  21. if ( m_pHLTVServer )
  22. {
  23. // mod specific events the director uses to find interesting shots
  24. ListenForGameEvent( "dod_point_captured" );
  25. ListenForGameEvent( "dod_capture_blocked" );
  26. }
  27. }
  28. void CDODHLTVDirector::CreateShotFromEvent( CHLTVGameEvent *event )
  29. {
  30. // show event at least for 2 more seconds after it occured
  31. const char *name = event->m_Event->GetName();
  32. IGameEvent *shot = NULL;
  33. if ( !Q_strcmp( "dod_point_captured", name ) ||
  34. !Q_strcmp( "dod_capture_blocked", name ) )
  35. {
  36. // try to find a capper or blocker
  37. const char *text = event->m_Event->GetString("blocker");
  38. int playerIndex = text[0];
  39. if ( playerIndex < 1 )
  40. {
  41. // maybe its a capper ?
  42. text = event->m_Event->GetString("cappers");
  43. playerIndex = text[0];
  44. }
  45. // if we found one, show him
  46. if ( playerIndex > 0 )
  47. {
  48. // shot player as primary, hostage as secondary target
  49. shot = gameeventmanager->CreateEvent( "hltv_chase", true );
  50. shot->SetInt( "target1", playerIndex );
  51. shot->SetInt( "target2", 0 );
  52. shot->SetFloat( "distance", 96.0f );
  53. shot->SetInt( "theta", 0 );
  54. shot->SetInt( "phi", 20 );
  55. // shot 2 seconds after event
  56. m_nNextShotTick = MIN( m_nNextShotTick, (event->m_Tick+TIME_TO_TICKS(2.0)) );
  57. m_iPVSEntity = playerIndex;
  58. }
  59. }
  60. else
  61. {
  62. // let baseclass create a shot
  63. BaseClass::CreateShotFromEvent( event );
  64. return;
  65. }
  66. if ( shot )
  67. {
  68. m_pHLTVServer->BroadcastEvent( shot );
  69. gameeventmanager->FreeEvent( shot );
  70. DevMsg("DrcCmd: %s\n", name );
  71. }
  72. }
  73. const char** CDODHLTVDirector::GetModEvents()
  74. {
  75. // game events relayed to spectator clients
  76. static const char *s_modevents[] =
  77. {
  78. "hltv_status",
  79. "hltv_chat",
  80. "player_connect",
  81. "player_disconnect",
  82. "player_team",
  83. "player_info",
  84. "server_cvar",
  85. "player_death",
  86. "player_chat",
  87. "round_start",
  88. "round_end",
  89. // additional DoD:S events:
  90. "player_changeclass",
  91. "dod_warmup_begins",
  92. "dod_warmup_ends",
  93. "dod_round_start",
  94. "dod_restart_round",
  95. "dod_ready_restart",
  96. "dod_allies_ready",
  97. "dod_axis_ready",
  98. "dod_round_restart_seconds",
  99. "dod_team_scores",
  100. "dod_round_win",
  101. "dod_tick_points",
  102. "dod_game_over",
  103. "dod_broadcast_audio",
  104. "dod_point_captured",
  105. "dod_capture_blocked",
  106. "dod_top_cappers",
  107. "dod_timer_flash",
  108. "dod_bomb_planted",
  109. NULL
  110. };
  111. return s_modevents;
  112. }
  113. static CDODHLTVDirector s_HLTVDirector; // singleton
  114. EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CHLTVDirector, IHLTVDirector, INTERFACEVERSION_HLTVDIRECTOR, s_HLTVDirector );
  115. CHLTVDirector* HLTVDirector()
  116. {
  117. return &s_HLTVDirector;
  118. }
  119. IGameSystem* HLTVDirectorSystem()
  120. {
  121. return &s_HLTVDirector;
  122. }