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