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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
//=======================================================================================//
#include "cbase.h"
#if defined( REPLAY_ENABLED )
#include "tf_replay.h"
#include "tf/tf_shareddefs.h"
#include "tf/c_tf_player.h"
#include "tf/c_tf_playerresource.h"
#include "tf/c_tf_gamestats.h"
#include "tf/tf_gamestats_shared.h"
#include "tf/tf_hud_statpanel.h"
#include "tf/c_obj_sentrygun.h"
#include "clientmode_shared.h"
#include "replay/ireplaymoviemanager.h"
#include "replay/ireplayfactory.h"
#include "replay/ireplayscreenshotmanager.h"
#include "replay/screenshot.h"
#include <time.h>
//----------------------------------------------------------------------------------------
extern IReplayScreenshotManager *g_pReplayScreenshotManager;
//----------------------------------------------------------------------------------------
CTFReplay::CTFReplay()
: m_flNextMedicUpdateTime( 0.0f )
{
}
CTFReplay::~CTFReplay()
{
}
void CTFReplay::OnBeginRecording()
{
BaseClass::OnBeginRecording();
// Setup the newly created replay
C_TFPlayer* pPlayer = C_TFPlayer::GetLocalTFPlayer();
if ( pPlayer )
{
if ( pPlayer->GetPlayerClass() )
{
SetPlayerClass( pPlayer->GetPlayerClass()->GetClassIndex() );
}
SetPlayerTeam( pPlayer->GetTeamNumber() );
}
}
void CTFReplay::OnEndRecording()
{
if ( gameeventmanager )
{
gameeventmanager->RemoveListener( this );
}
BaseClass::OnEndRecording();
}
void CTFReplay::OnComplete()
{
BaseClass::OnComplete();
}
void CTFReplay::Update()
{
// If local player is medic and invuln'd someone, take a screenshot
MedicUpdate();
BaseClass::Update();
}
void CTFReplay::MedicUpdate()
{
// Not ready for update?
if ( gpGlobals->curtime < m_flNextMedicUpdateTime )
return;
// Local player doesn't exist?
C_TFPlayer *pLocalPlayer = C_TFPlayer::GetLocalTFPlayer();
if ( !pLocalPlayer )
{
Assert( 0 ); // Shouldn't happen
return;
}
if ( pLocalPlayer->GetPlayerClass()->GetClassIndex() != TF_CLASS_MEDIC )
return;
// Releasing charge?
if ( pLocalPlayer->MedicIsReleasingCharge() )
{
// Take a sick screenshot
CaptureScreenshotParams_t params;
V_memset( ¶ms, 0, sizeof( params ) );
params.m_flDelay = 0.25f;
g_pReplayScreenshotManager->CaptureScreenshot( params );
// Set next update to minimum time it would be until next recharge
extern ConVar weapon_medigun_chargerelease_rate;
m_flNextMedicUpdateTime = gpGlobals->curtime + weapon_medigun_chargerelease_rate.GetFloat();
}
else
{
// Check again in a second
m_flNextMedicUpdateTime = gpGlobals->curtime + 1.0f;
}
}
float CTFReplay::GetSentryKillScreenshotDelay()
{
ConVarRef replay_screenshotsentrykilldelay( "replay_screenshotsentrykilldelay" );
return replay_screenshotsentrykilldelay.IsValid() ? replay_screenshotsentrykilldelay.GetFloat() : 0.5f;
}
void CTFReplay::FireGameEvent( IGameEvent *pEvent )
{
C_TFPlayer *pLocalPlayer = C_TFPlayer::GetLocalTFPlayer();
if ( !pLocalPlayer )
return;
CaptureScreenshotParams_t params;
V_memset( ¶ms, 0, sizeof( params ) );
if ( FStrEq( pEvent->GetName(), "player_death" ) )
{
ConVarRef replay_debug( "replay_debug" );
if ( replay_debug.IsValid() && replay_debug.GetBool() )
{
DevMsg( "%i: CTFReplay::FireGameEvent(): player_death\n", gpGlobals->tickcount );
}
int nKillerID = pEvent->GetInt( "attacker" );
int nVictimID = pEvent->GetInt( "userid" );
int nDeathFlags = pEvent->GetInt( "death_flags" );
int nAssisterID = pEvent->GetInt( "assister" );
const char *pWeaponName = pEvent->GetString( "weapon" );
// Suicide?
bool bSuicide = nKillerID == nVictimID;
// Try to get killer
C_TFPlayer *pKiller = ToTFPlayer( USERID2PLAYER( nKillerID ) );
// Try to get victim
C_TFPlayer *pVictim = ToTFPlayer( USERID2PLAYER( nVictimID ) );
// Is local player healing the killer?
bool bKillerLastHealerIsLocalPlayer = pKiller && pKiller->GetWasHealedByLocalPlayer();
// Inflictor was a sentry gun?
bool bSentry = V_strnicmp( pWeaponName, "obj_sentrygun", 13 ) == 0;
int nInflictorEntIndex = pEvent->GetInt( "inflictor_entindex" );
C_BaseEntity *pInflictor = ClientEntityList().GetEnt( nInflictorEntIndex );
C_ObjectSentrygun *pSentry = dynamic_cast< C_ObjectSentrygun * >( pInflictor );
bool bFeignDeath = pEvent->GetInt( "death_flags" ) & TF_DEATH_FEIGN_DEATH;
// Is the killer the local player?
if ( nKillerID == pLocalPlayer->GetUserID() &&
!bSuicide &&
!bSentry )
{
// Domination?
if ( nDeathFlags & TF_DEATH_DOMINATION )
{
AddDomination( nVictimID );
}
// Assister domination?
if ( ( nDeathFlags & TF_DEATH_ASSISTER_DOMINATION ) && ( nAssisterID > 0 ) )
{
AddAssisterDomination( nVictimID, nAssisterID );
}
// Revenge?
if ( pEvent->GetInt( "death_flags" ) & TF_DEATH_REVENGE )
{
AddRevenge( nVictimID );
}
// Assister revenge?
if ( pEvent->GetInt( "death_flags" ) & TF_DEATH_ASSISTER_REVENGE && ( nAssisterID > 0 ) )
{
AddAssisterRevenge( nVictimID, nAssisterID );
}
// Add victim info to kill list
if ( pVictim )
{
AddKill( pVictim->GetPlayerName(), pVictim->GetPlayerClass()->GetClassIndex() );
}
// Take a quick screenshot with some delay
ConVarRef replay_screenshotkilldelay( "replay_screenshotkilldelay" );
if ( replay_screenshotkilldelay.IsValid() )
{
params.m_flDelay = GetKillScreenshotDelay();
g_pReplayScreenshotManager->CaptureScreenshot( params );
}
}
// Player death?
else if ( pKiller &&
nVictimID == pLocalPlayer->GetUserID() )
{
// Record who killed the player if not a suicide
if ( !bSuicide && !bFeignDeath )
{
RecordPlayerDeath( pKiller->GetPlayerName(), pKiller->GetPlayerClass()->GetClassIndex() );
}
// Take screenshot - taking a screenshot during feign death is cool, too.
ConVarRef replay_deathcammaxverticaloffset( "replay_deathcammaxverticaloffset" );
ConVarRef replay_playerdeathscreenshotdelay( "replay_playerdeathscreenshotdelay" );
params.m_flDelay = replay_playerdeathscreenshotdelay.IsValid() ? replay_playerdeathscreenshotdelay.GetFloat() : 0.0f;
params.m_nEntity = pLocalPlayer->entindex();
params.m_posCamera.Init( 0,0, replay_deathcammaxverticaloffset.IsValid() ? replay_deathcammaxverticaloffset.GetFloat() : 150 );
params.m_angCamera.Init( 90, 0, 0 ); // Look straight down
params.m_bUseCameraAngles = true;
params.m_bIgnoreMinTimeBetweenScreenshots = true;
g_pReplayScreenshotManager->CaptureScreenshot( params );
}
// Killer is invuln/crit boosted and healer is local player?
else if ( bKillerLastHealerIsLocalPlayer &&
( pKiller->m_Shared.IsCritBoosted() ||
pKiller->m_Shared.InCond( TF_COND_INVULNERABLE ) ||
pKiller->m_Shared.InCond( TF_COND_INVULNERABLE_WEARINGOFF ) ) )
{
// Take a quick screenshot with some delay
params.m_flDelay = GetKillScreenshotDelay();
g_pReplayScreenshotManager->CaptureScreenshot( params );
}
// Is the inflictor a sentry belonging to the local player?
else if ( pLocalPlayer->IsAlive() &&
bSentry &&
pSentry &&
pSentry->GetOwner() == pLocalPlayer &&
pVictim )
{
ConVarRef replay_sentrycammaxverticaloffset( "replay_sentrycammaxverticaloffset" );
ConVarRef replay_sentrycamoffset_frontback( "replay_sentrycamoffset_frontback" );
ConVarRef replay_sentrycamoffset_leftright( "replay_sentrycamoffset_leftright" );
ConVarRef replay_sentrycamoffset_updown( "replay_sentrycamoffset_updown" );
// Setup screenshot params
params.m_flDelay = GetSentryKillScreenshotDelay();
params.m_nEntity = pSentry->entindex();
params.m_bUseCameraAngles = true;
// Calculate camera eye position
static float s_aSentryEyeLevels[3] = { SENTRYGUN_EYE_OFFSET_LEVEL_1[2], SENTRYGUN_EYE_OFFSET_LEVEL_2[2], SENTRYGUN_EYE_OFFSET_LEVEL_3[2] };
int iSentryUpgrade = clamp( pSentry->GetUpgradeLevel() - 1, 0, 2 );
Vector vecSentryEyeOffset = Vector( 0, 0, s_aSentryEyeLevels[ iSentryUpgrade ] );
Vector vecSentryAimDir; // Since it seems the sentry's *actual* aim direction is only available on the server, use the victim's location to calculate a general idea of one
Vector vecVictimUp = pVictim->WorldSpaceCenter() - pVictim->GetAbsOrigin(); // WorldSpaceCenter() seems to return player's eye level
Vector vecVictimCenter = pVictim->GetAbsOrigin() + 0.5f * vecVictimUp;
vecSentryAimDir = vecVictimCenter - pSentry->GetAbsOrigin() + vecSentryEyeOffset;
VectorNormalizeFast( vecSentryAimDir );
Vector vecX, vecY, vecZ; // Construct a matrix to transform the eye point
vecX = vecSentryAimDir;
vecY = CrossProduct( Vector(0,0,1), vecSentryAimDir );
vecZ = CrossProduct( vecX, vecY );
matrix3x4_t m;
m.Init( vecX, vecY, vecZ, vec3_origin );
Vector out; // Transform the point relative to the sentry's eye
Vector vecOffset;
if ( replay_sentrycamoffset_frontback.IsValid() &&
replay_sentrycamoffset_leftright.IsValid() &&
replay_sentrycamoffset_updown.IsValid() )
{
vecOffset.Init( replay_sentrycamoffset_frontback.GetFloat(), -replay_sentrycamoffset_leftright.GetFloat(), replay_sentrycamoffset_updown.GetFloat() );
}
else
{
vecOffset.Init( 0, 0, 0 );
}
VectorTransform( vecOffset, m, out );
out += Vector( 0,0, s_aSentryEyeLevels[ iSentryUpgrade ] + ( replay_sentrycammaxverticaloffset.IsValid() ? replay_sentrycammaxverticaloffset.GetFloat() : 5 ) );
params.m_posCamera = out;
// Use the aim matrix we constructed as the camera's orientation
MatrixAngles( m, params.m_angCamera );
// Take the screenshot from the sentry's point of view
g_pReplayScreenshotManager->CaptureScreenshot( params );
}
}
}
bool CTFReplay::IsValidClass( int nClass ) const
{
return IsValidTFPlayerClass( nClass );
}
bool CTFReplay::IsValidTeam( int iTeam ) const
{
return IsValidTFTeam( iTeam );
}
bool CTFReplay::GetCurrentStats( RoundStats_t &out )
{
if ( !g_TF_PR )
return false;
C_TFPlayer *pLocalPlayer = C_TFPlayer::GetLocalTFPlayer();
if ( !pLocalPlayer )
return false;
int iLocalPlayerIndex = GetLocalPlayerIndex();
out.m_iStat[ TFSTAT_POINTSSCORED ] = g_TF_PR->GetPlayerScore( iLocalPlayerIndex );
out.m_iStat[ TFSTAT_DEATHS ] = g_TF_PR->GetDeaths( iLocalPlayerIndex );
out.m_iStat[ TFSTAT_CAPTURES ] = pLocalPlayer->m_Shared.GetCaptures( iLocalPlayerIndex );
out.m_iStat[ TFSTAT_DEFENSES ] = pLocalPlayer->m_Shared.GetDefenses( iLocalPlayerIndex );
out.m_iStat[ TFSTAT_DOMINATIONS ] = pLocalPlayer->m_Shared.GetDominations( iLocalPlayerIndex );
out.m_iStat[ TFSTAT_REVENGE ] = pLocalPlayer->m_Shared.GetRevenge( iLocalPlayerIndex );
out.m_iStat[ TFSTAT_BUILDINGSDESTROYED ] = pLocalPlayer->m_Shared.GetBuildingsDestroyed( iLocalPlayerIndex );
out.m_iStat[ TFSTAT_HEADSHOTS ] = pLocalPlayer->m_Shared.GetHeadshots( iLocalPlayerIndex );
out.m_iStat[ TFSTAT_BACKSTABS ] = pLocalPlayer->m_Shared.GetBackstabs( iLocalPlayerIndex );
out.m_iStat[ TFSTAT_HEALING ] = pLocalPlayer->m_Shared.GetHealPoints( iLocalPlayerIndex );
out.m_iStat[ TFSTAT_INVULNS ] = pLocalPlayer->m_Shared.GetInvulns( iLocalPlayerIndex );
out.m_iStat[ TFSTAT_TELEPORTS ] = pLocalPlayer->m_Shared.GetTeleports( iLocalPlayerIndex );
out.m_iStat[ TFSTAT_KILLASSISTS ] = pLocalPlayer->m_Shared.GetKillAssists( iLocalPlayerIndex );
out.m_iStat[ TFSTAT_BONUS_POINTS ] = pLocalPlayer->m_Shared.GetBonusPoints( iLocalPlayerIndex );
return true;
}
const char *CTFReplay::GetStatString( int iStat ) const
{
COMPILE_TIME_ASSERT( TFSTAT_TOTAL == ARRAYSIZE( s_pStatStrings ) );
Assert( iStat >= TFSTAT_UNDEFINED && iStat < TFSTAT_TOTAL );
return ClampedArrayElement( s_pStatStrings, iStat );
}
const char *CTFReplay::GetPlayerClass( int iClass ) const
{
COMPILE_TIME_ASSERT( TF_CLASS_MENU_BUTTONS == ARRAYSIZE( g_aPlayerClassNames_NonLocalized ) );
Assert( iClass >= TF_CLASS_UNDEFINED && iClass < TF_CLASS_COUNT );
return ClampedArrayElement( g_aPlayerClassNames_NonLocalized, iClass );
}
bool CTFReplay::Read( KeyValues *pIn )
{
return BaseClass::Read( pIn );
}
void CTFReplay::Write( KeyValues *pOut )
{
BaseClass::Write( pOut );
}
const char *CTFReplay::GetMaterialFriendlyPlayerClass() const
{
const char *pPlayerClass = BaseClass::GetMaterialFriendlyPlayerClass();
if ( !V_stricmp( pPlayerClass, "heavyweapons" ) )
return "heavy";
else if ( !V_stricmp( pPlayerClass, "demoman" ) )
return "demo";
return pPlayerClass;
}
void CTFReplay::DumpGameSpecificData() const
{
BaseClass::DumpGameSpecificData();
}
//----------------------------------------------------------------------------------------
class CTFReplayFactory : public IReplayFactory
{
public:
virtual CReplay *Create()
{
return new CTFReplay();
}
};
static CTFReplayFactory s_ReplayManager;
IReplayFactory *g_pReplayFactory = &s_ReplayManager;
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CTFReplayFactory, IReplayFactory, INTERFACE_VERSION_REPLAY_FACTORY, s_ReplayManager );
#endif
|