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.

225 lines
5.4 KiB

  1. //========= Copyright � 1996-2005, 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. // NOTE: This has to be the last file included!
  12. #include "tier0/memdbgon.h"
  13. class CCSHLTVDirector : public CHLTVDirector
  14. {
  15. public:
  16. DECLARE_CLASS( CCSHLTVDirector, CHLTVDirector );
  17. const char** GetModEvents();
  18. void AddHLTVServer( IHLTVServer *hltv );
  19. void CreateShotFromEvent( CHLTVGameEvent *event );
  20. };
  21. void CCSHLTVDirector::AddHLTVServer( IHLTVServer *hltv )
  22. {
  23. BaseClass::AddHLTVServer( hltv );
  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( "bomb_begindefuse" );
  35. ListenForGameEvent( "bomb_beginplant" );
  36. ListenForGameEvent( "vip_escaped" );
  37. ListenForGameEvent( "vip_killed" );
  38. }
  39. void CCSHLTVDirector::CreateShotFromEvent( CHLTVGameEvent *event )
  40. {
  41. // show event at least for 2 more seconds after it occured
  42. const char *name = event->m_Event->GetName();
  43. IGameEvent *shot = NULL;
  44. CBaseEntity *player = NULL;
  45. if ( !Q_strcmp( "hostage_rescued", name ) ||
  46. !Q_strcmp( "hostage_hurt", name ) ||
  47. !Q_strcmp( "hostage_follows", name ) ||
  48. !Q_strcmp( "hostage_killed", name ) )
  49. {
  50. player = UTIL_PlayerByUserId( event->m_Event->GetInt("userid") );
  51. if ( !player )
  52. return;
  53. // shot player as primary, hostage as secondary target
  54. shot = gameeventmanager->CreateEvent( "hltv_chase", true );
  55. shot->SetInt( "target1", player->entindex() );
  56. shot->SetInt( "target2", event->m_Event->GetInt("hostage") );
  57. shot->SetFloat( "distance", 96.0f );
  58. shot->SetInt( "theta", 40 );
  59. shot->SetInt( "phi", 20 );
  60. // shot 2 seconds after event
  61. m_nNextShotTick = MIN( m_nNextShotTick, (event->m_Tick+TIME_TO_TICKS(2.0)) );
  62. m_iPVSEntity = player->entindex();
  63. }
  64. else if ( !Q_strcmp( "bomb_beginplant", name ) ||
  65. !Q_strcmp( "bomb_begindefuse", name ) )
  66. {
  67. player = UTIL_PlayerByUserId( event->m_Event->GetInt("userid") );
  68. if ( !player )
  69. return;
  70. // chasecam
  71. shot = gameeventmanager->CreateEvent( "hltv_chase", true );
  72. if ( shot )
  73. {
  74. shot->SetInt( "target1", player->entindex() );
  75. shot->SetInt( "target2", 0 );
  76. shot->SetFloat( "distance", 500.0f );
  77. shot->SetInt( "theta", 180 );
  78. shot->SetInt( "phi", 45 );
  79. shot->SetBool( "ineye", true );
  80. // shot 3 seconds after pickup
  81. m_nNextShotTick = MIN( m_nNextShotTick, (event->m_Tick+TIME_TO_TICKS(3.0)) );
  82. m_iPVSEntity = player->entindex();
  83. for ( int i = 0; i < m_HltvServers.Count(); ++i )
  84. {
  85. m_HltvServers[ i ].m_pHLTVServer->BroadcastEvent( shot );
  86. }
  87. gameeventmanager->FreeEvent( shot );
  88. DevMsg("DrcCmd: %s\n", name );
  89. return;
  90. }
  91. }
  92. // let baseclass create a shot
  93. BaseClass::CreateShotFromEvent( event );
  94. }
  95. const char** CCSHLTVDirector::GetModEvents()
  96. {
  97. // game events relayed to spectator clients
  98. static const char *s_modevents[] =
  99. {
  100. "hltv_status",
  101. "hltv_chat",
  102. "player_connect",
  103. "player_connect_full",
  104. "player_disconnect",
  105. "player_team",
  106. "player_info",
  107. "server_cvar",
  108. "player_changename",
  109. "teamplay_broadcast_audio",
  110. "player_death",
  111. "other_death",
  112. "player_hurt",
  113. "player_chat",
  114. "round_start",
  115. "round_end",
  116. // additional CS:S events:
  117. "bomb_planted",
  118. "bomb_defused",
  119. "bomb_beginplant",
  120. "bomb_begindefuse",
  121. "hostage_killed",
  122. "hostage_hurt",
  123. "begin_new_match",
  124. // UI events
  125. "cs_match_end_restart",
  126. "cs_game_disconnected",
  127. "announce_phase_end",
  128. "round_mvp",
  129. "server_spawn",
  130. "player_spawn",
  131. "hltv_status",
  132. "cs_win_panel_round",
  133. "endmatch_cmm_start_reveal_items",
  134. "game_newmap",
  135. "hostage_rescued",
  136. "bomb_exploded",
  137. "bomb_pickup",
  138. "bomb_dropped",
  139. "defuser_pickup",
  140. "defuser_dropped",
  141. "decoy_started",
  142. "decoy_detonate",
  143. "hegrenade_detonate",
  144. "flashbang_detonate",
  145. "smokegrenade_detonate",
  146. "smokegrenade_expired",
  147. "inferno_startburn",
  148. "inferno_expire",
  149. "bot_takeover",
  150. "bomb_beep",
  151. "weapon_fire",
  152. "weapon_fire_on_empty",
  153. "weapon_outofammo",
  154. "weapon_reload",
  155. "weapon_zoom",
  156. "player_footstep",
  157. "player_jump",
  158. "player_blind",
  159. "round_freeze_end",
  160. "cs_win_panel_match",
  161. "cs_pre_restart",
  162. "tournament_reward",
  163. "item_found",
  164. "items_gifted",
  165. "achievement_earned",
  166. "round_announce_warmup",
  167. "round_announce_last_round_half",
  168. "round_announce_final",
  169. "round_announce_match_point",
  170. "round_poststart",
  171. "buytime_ended",
  172. "round_time_warning",
  173. "dm_bonus_weapon_start",
  174. "endmatch_mapvote_selecting_map",
  175. "cs_round_start_beep",
  176. "cs_round_final_beep",
  177. "round_announce_match_start",
  178. "seasoncoin_levelup",
  179. "player_falldamage",
  180. "hostage_rescued_all",
  181. "round_officially_ended",
  182. "round_prestart",
  183. NULL
  184. };
  185. return s_modevents;
  186. }
  187. static CCSHLTVDirector s_HLTVDirector; // singleton
  188. EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CHLTVDirector, IHLTVDirector, INTERFACEVERSION_HLTVDIRECTOR, s_HLTVDirector );
  189. CHLTVDirector* HLTVDirector()
  190. {
  191. return &s_HLTVDirector;
  192. }
  193. IGameSystem* HLTVDirectorSystem()
  194. {
  195. return &s_HLTVDirector;
  196. }