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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Implements the big scary boom-boom machine Antlions fear.
//
//=============================================================================//
#include "cbase.h"
#include "baseanimating.h"
#include "portal_player.h"
#include "EnvMessage.h"
#include "fmtstr.h"
#include "vguiscreen.h"
#include "point_bonusmaps_accessor.h"
#include "portal_shareddefs.h"
#define PORTAL_STATS_DISPLAY_MODEL_NAME "models/props/Round_elevator_body.mdl"
class CPropPortalStatsDisplay : public CBaseAnimating
{
public:
DECLARE_CLASS( CPropPortalStatsDisplay, CBaseAnimating );
DECLARE_DATADESC();
DECLARE_SERVERCLASS();
virtual ~CPropPortalStatsDisplay();
virtual int UpdateTransmitState();
virtual void SetTransmit( CCheckTransmitInfo *pInfo, bool bAlways );
virtual void Spawn( void );
virtual void Precache( void );
virtual void OnRestore( void );
void ScreenVisible( bool bVisible );
void Disable( void );
void Enable( void );
void InputDisable( inputdata_t &inputdata );
void InputEnable( inputdata_t &inputdata );
void InputUpdateStats( inputdata_t &inputdata );
void InputResetPlayerStats( inputdata_t &inputdata );
private:
CNetworkVar( bool, m_bEnabled );
CNetworkVar( int, m_iNumPortalsPlaced );
CNetworkVar( int, m_iNumStepsTaken );
CNetworkVar( float, m_fNumSecondsTaken );
CNetworkVar( int, m_iBronzeObjective );
CNetworkVar( int, m_iSilverObjective );
CNetworkVar( int, m_iGoldObjective );
CNetworkString( szChallengeFileName, 128 );
CNetworkString( szChallengeMapName, 32 );
CNetworkString( szChallengeName, 32 );
CNetworkVar( int, m_iDisplayObjective );
COutputEvent m_OnMetBronzeObjective;
COutputEvent m_OnMetSilverObjective;
COutputEvent m_OnMetGoldObjective;
COutputEvent m_OnFailedAllObjectives;
private:
// Control panel
void GetControlPanelInfo( int nPanelIndex, const char *&pPanelName );
void GetControlPanelClassName( int nPanelIndex, const char *&pPanelName );
void SpawnControlPanels( void );
void RestoreControlPanels( void );
typedef CHandle<CVGuiScreen> ScreenHandle_t;
CUtlVector<ScreenHandle_t> m_hScreens;
};
LINK_ENTITY_TO_CLASS( prop_portal_stats_display, CPropPortalStatsDisplay );
//-----------------------------------------------------------------------------
// Save/load
//-----------------------------------------------------------------------------
BEGIN_DATADESC( CPropPortalStatsDisplay )
DEFINE_FIELD( m_bEnabled, FIELD_BOOLEAN ),
DEFINE_FIELD( m_iNumPortalsPlaced, FIELD_INTEGER ),
DEFINE_FIELD( m_iNumStepsTaken, FIELD_INTEGER ),
DEFINE_FIELD( m_fNumSecondsTaken, FIELD_FLOAT ),
DEFINE_FIELD( m_iBronzeObjective, FIELD_INTEGER ),
DEFINE_FIELD( m_iSilverObjective, FIELD_INTEGER ),
DEFINE_FIELD( m_iGoldObjective, FIELD_INTEGER ),
DEFINE_AUTO_ARRAY( szChallengeFileName, FIELD_CHARACTER ),
DEFINE_AUTO_ARRAY( szChallengeMapName, FIELD_CHARACTER ),
DEFINE_AUTO_ARRAY( szChallengeName, FIELD_CHARACTER ),
DEFINE_FIELD( m_iDisplayObjective, FIELD_INTEGER ),
//DEFINE_UTLVECTOR( m_hScreens, FIELD_EHANDLE ),
DEFINE_INPUTFUNC( FIELD_VOID, "Disable", InputDisable ),
DEFINE_INPUTFUNC( FIELD_VOID, "Enable", InputEnable ),
DEFINE_INPUTFUNC( FIELD_VOID, "UpdateStats", InputUpdateStats ),
DEFINE_INPUTFUNC( FIELD_VOID, "ResetPlayerStats", InputResetPlayerStats ),
DEFINE_OUTPUT ( m_OnMetBronzeObjective, "OnMetBronzeObjective" ),
DEFINE_OUTPUT ( m_OnMetSilverObjective, "OnMetSilverObjective" ),
DEFINE_OUTPUT ( m_OnMetGoldObjective, "OnMetGoldObjective" ),
DEFINE_OUTPUT ( m_OnFailedAllObjectives, "OnFailedAllObjectives" ),
END_DATADESC()
IMPLEMENT_SERVERCLASS_ST( CPropPortalStatsDisplay, DT_PropPortalStatsDisplay )
SendPropBool( SENDINFO(m_bEnabled) ),
SendPropInt( SENDINFO(m_iNumPortalsPlaced) ),
SendPropInt( SENDINFO(m_iNumStepsTaken) ),
SendPropFloat( SENDINFO(m_fNumSecondsTaken) ),
SendPropInt( SENDINFO(m_iBronzeObjective) ),
SendPropInt( SENDINFO(m_iSilverObjective) ),
SendPropInt( SENDINFO(m_iGoldObjective) ),
SendPropString( SENDINFO( szChallengeFileName ) ),
SendPropString( SENDINFO( szChallengeMapName ) ),
SendPropString( SENDINFO( szChallengeName ) ),
SendPropInt( SENDINFO(m_iDisplayObjective) ),
END_SEND_TABLE()
CPropPortalStatsDisplay::~CPropPortalStatsDisplay()
{
int i;
// Kill the control panels
for ( i = m_hScreens.Count(); --i >= 0; )
{
DestroyVGuiScreen( m_hScreens[i].Get() );
}
m_hScreens.RemoveAll();
}
int CPropPortalStatsDisplay::UpdateTransmitState()
{
return SetTransmitState( FL_EDICT_FULLCHECK );
}
void CPropPortalStatsDisplay::SetTransmit( CCheckTransmitInfo *pInfo, bool bAlways )
{
// Are we already marked for transmission?
if ( pInfo->m_pTransmitEdict->Get( entindex() ) )
return;
BaseClass::SetTransmit( pInfo, bAlways );
// Force our screens to be sent too.
for ( int i=0; i < m_hScreens.Count(); i++ )
{
CVGuiScreen *pScreen = m_hScreens[i].Get();
pScreen->SetTransmit( pInfo, bAlways );
}
}
void CPropPortalStatsDisplay::Spawn( void )
{
char *szModel = (char *)STRING( GetModelName() );
if (!szModel || !*szModel)
{
szModel = PORTAL_STATS_DISPLAY_MODEL_NAME;
SetModelName( AllocPooledString(szModel) );
}
Precache();
SetModel( szModel );
SetSolid( SOLID_VPHYSICS );
VPhysicsInitStatic();
BaseClass::Spawn();
int iBronze, iSilver, iGold;
BonusMapChallengeObjectives( iBronze, iSilver, iGold );
m_iBronzeObjective = iBronze;
m_iSilverObjective = iSilver;
m_iGoldObjective = iGold;
BonusMapChallengeNames( szChallengeFileName.GetForModify(), szChallengeMapName.GetForModify(), szChallengeName.GetForModify() );
m_bEnabled = false;
int iSequence = SelectHeaviestSequence ( ACT_IDLE );
if ( iSequence != ACT_INVALID )
{
SetSequence( iSequence );
ResetSequenceInfo();
//Do this so we get the nice ramp-up effect.
m_flPlaybackRate = random->RandomFloat( 0.0f, 1.0f );
}
SpawnControlPanels();
ScreenVisible( m_bEnabled );
}
void CPropPortalStatsDisplay::Precache( void )
{
BaseClass::Precache();
PrecacheModel( STRING( GetModelName() ) );
PrecacheVGuiScreen( "portal_stats_display_screen" );
}
void CPropPortalStatsDisplay::OnRestore( void )
{
BaseClass::OnRestore();
RestoreControlPanels();
ScreenVisible( m_bEnabled );
}
void CPropPortalStatsDisplay::ScreenVisible( bool bVisible )
{
for ( int iScreen = 0; iScreen < m_hScreens.Count(); ++iScreen )
{
CVGuiScreen *pScreen = m_hScreens[ iScreen ].Get();
if ( bVisible )
pScreen->RemoveEffects( EF_NODRAW );
else
pScreen->AddEffects( EF_NODRAW );
}
}
void CPropPortalStatsDisplay::Disable( void )
{
if ( !m_bEnabled )
return;
m_bEnabled = false;
ScreenVisible( false );
}
void CPropPortalStatsDisplay::Enable( void )
{
if ( m_bEnabled )
return;
// Don't show stats display in non challenge mode!
CBasePlayer *pPlayer = UTIL_GetLocalPlayer();
if ( pPlayer && pPlayer->GetBonusChallenge() == 0 )
return;
m_bEnabled = true;
m_iDisplayObjective = pPlayer->GetBonusChallenge() - 1;
// Check if they beat objectives
if ( pPlayer->GetBonusProgress() <= m_iBronzeObjective )
m_OnMetBronzeObjective.FireOutput( this, this );
else if ( pPlayer->GetBonusProgress() <= m_iSilverObjective )
m_OnMetSilverObjective.FireOutput( this, this );
else if ( pPlayer->GetBonusProgress() <= m_iGoldObjective )
m_OnMetGoldObjective.FireOutput( this, this );
else
m_OnFailedAllObjectives.FireOutput( this, this );
ScreenVisible( true );
}
void CPropPortalStatsDisplay::InputDisable( inputdata_t &inputdata )
{
Disable();
}
void CPropPortalStatsDisplay::InputEnable( inputdata_t &inputdata )
{
Enable();
}
void CPropPortalStatsDisplay::InputUpdateStats( inputdata_t &inputdata )
{
CPortal_Player *pPlayer = (CPortal_Player *)UTIL_GetCommandClient();
if( pPlayer == NULL )
pPlayer = GetPortalPlayer( 1 ); //last ditch effort
if( pPlayer )
{
m_iNumPortalsPlaced = pPlayer->NumPortalsPlaced();
m_iNumStepsTaken = pPlayer->NumStepsTaken();
m_fNumSecondsTaken = pPlayer->NumSecondsTaken();
// Now that we've recorded it, don't let it change
pPlayer->PauseBonusProgress();
}
}
void CPropPortalStatsDisplay::InputResetPlayerStats( inputdata_t &inputdata )
{
CPortal_Player *pPlayer = (CPortal_Player *)UTIL_GetCommandClient();
if( pPlayer == NULL )
pPlayer = GetPortalPlayer( 1 ); //last ditch effort
if( pPlayer )
{
pPlayer->ResetThisLevelStats();
}
}
void CPropPortalStatsDisplay::GetControlPanelInfo( int nPanelIndex, const char *&pPanelName )
{
pPanelName = "portal_stats_display_screen";
}
void CPropPortalStatsDisplay::GetControlPanelClassName( int nPanelIndex, const char *&pPanelName )
{
pPanelName = "vgui_screen";
}
//-----------------------------------------------------------------------------
// This is called by the base object when it's time to spawn the control panels
//-----------------------------------------------------------------------------
void CPropPortalStatsDisplay::SpawnControlPanels()
{
char buf[64];
// FIXME: Deal with dynamically resizing control panels?
// If we're attached to an entity, spawn control panels on it instead of use
CBaseAnimating *pEntityToSpawnOn = this;
char *pOrgLL = "statPanel%d_bl";
char *pOrgUR = "statPanel%d_tr";
char *pAttachmentNameLL = pOrgLL;
char *pAttachmentNameUR = pOrgUR;
Assert( pEntityToSpawnOn );
// Lookup the attachment point...
int nPanel;
for ( nPanel = 0; true; ++nPanel )
{
Q_snprintf( buf, sizeof( buf ), pAttachmentNameLL, nPanel );
int nLLAttachmentIndex = pEntityToSpawnOn->LookupAttachment(buf);
if (nLLAttachmentIndex <= 0)
{
// Try and use my panels then
pEntityToSpawnOn = this;
Q_snprintf( buf, sizeof( buf ), pOrgLL, nPanel );
nLLAttachmentIndex = pEntityToSpawnOn->LookupAttachment(buf);
if (nLLAttachmentIndex <= 0)
return;
}
Q_snprintf( buf, sizeof( buf ), pAttachmentNameUR, nPanel );
int nURAttachmentIndex = pEntityToSpawnOn->LookupAttachment(buf);
if (nURAttachmentIndex <= 0)
{
// Try and use my panels then
Q_snprintf( buf, sizeof( buf ), pOrgUR, nPanel );
nURAttachmentIndex = pEntityToSpawnOn->LookupAttachment(buf);
if (nURAttachmentIndex <= 0)
return;
}
const char *pScreenName;
GetControlPanelInfo( nPanel, pScreenName );
if (!pScreenName)
continue;
const char *pScreenClassname;
GetControlPanelClassName( nPanel, pScreenClassname );
if ( !pScreenClassname )
continue;
// Compute the screen size from the attachment points...
matrix3x4_t panelToWorld;
pEntityToSpawnOn->GetAttachment( nLLAttachmentIndex, panelToWorld );
matrix3x4_t worldToPanel;
MatrixInvert( panelToWorld, worldToPanel );
// Now get the lower right position + transform into panel space
Vector lr, lrlocal;
pEntityToSpawnOn->GetAttachment( nURAttachmentIndex, panelToWorld );
MatrixGetColumn( panelToWorld, 3, lr );
VectorTransform( lr, worldToPanel, lrlocal );
float flWidth = lrlocal.x;
float flHeight = lrlocal.y;
CVGuiScreen *pScreen = CreateVGuiScreen( pScreenClassname, pScreenName, pEntityToSpawnOn, this, nLLAttachmentIndex );
pScreen->ChangeTeam( GetTeamNumber() );
pScreen->SetActualSize( flWidth, flHeight );
pScreen->SetActive( true );
pScreen->MakeVisibleOnlyToTeammates( false );
pScreen->SetTransparency( true );
int nScreen = m_hScreens.AddToTail( );
m_hScreens[nScreen].Set( pScreen );
}
}
void CPropPortalStatsDisplay::RestoreControlPanels( void )
{
char buf[64];
// FIXME: Deal with dynamically resizing control panels?
// If we're attached to an entity, spawn control panels on it instead of use
CBaseAnimating *pEntityToSpawnOn = this;
char *pOrgLL = "statPanel%d_bl";
char *pOrgUR = "statPanel%d_tr";
char *pAttachmentNameLL = pOrgLL;
char *pAttachmentNameUR = pOrgUR;
Assert( pEntityToSpawnOn );
// Lookup the attachment point...
int nPanel;
for ( nPanel = 0; true; ++nPanel )
{
Q_snprintf( buf, sizeof( buf ), pAttachmentNameLL, nPanel );
int nLLAttachmentIndex = pEntityToSpawnOn->LookupAttachment(buf);
if (nLLAttachmentIndex <= 0)
{
// Try and use my panels then
pEntityToSpawnOn = this;
Q_snprintf( buf, sizeof( buf ), pOrgLL, nPanel );
nLLAttachmentIndex = pEntityToSpawnOn->LookupAttachment(buf);
if (nLLAttachmentIndex <= 0)
return;
}
Q_snprintf( buf, sizeof( buf ), pAttachmentNameUR, nPanel );
int nURAttachmentIndex = pEntityToSpawnOn->LookupAttachment(buf);
if (nURAttachmentIndex <= 0)
{
// Try and use my panels then
Q_snprintf( buf, sizeof( buf ), pOrgUR, nPanel );
nURAttachmentIndex = pEntityToSpawnOn->LookupAttachment(buf);
if (nURAttachmentIndex <= 0)
return;
}
const char *pScreenName;
GetControlPanelInfo( nPanel, pScreenName );
if (!pScreenName)
continue;
const char *pScreenClassname;
GetControlPanelClassName( nPanel, pScreenClassname );
if ( !pScreenClassname )
continue;
CVGuiScreen *pScreen = (CVGuiScreen *)gEntList.FindEntityByClassname( NULL, pScreenClassname );
while ( pScreen && pScreen->GetOwnerEntity() != this && Q_strcmp( pScreen->GetPanelName(), pScreenName ) == 0 )
{
pScreen = (CVGuiScreen *)gEntList.FindEntityByClassname( pScreen, pScreenClassname );
}
if ( pScreen )
{
int nScreen = m_hScreens.AddToTail( );
m_hScreens[nScreen].Set( pScreen );
}
}
}
|