source-engine/game/client/c_team_train_watcher.cpp

98 lines
2.6 KiB
C++
Raw Normal View History

2023-10-03 17:23:56 +03:00
//========= Copyright <20> 1996-2006, Valve Corporation, All rights reserved. ============//
2020-04-22 12:56:21 -04:00
//
2023-10-03 17:23:56 +03:00
// Purpose: Entity that propagates train data for escort gametype
2020-04-22 12:56:21 -04:00
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "c_team_train_watcher.h"
#include "igameevents.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
2023-10-03 17:23:56 +03:00
IMPLEMENT_CLIENTCLASS_DT_NOBASE(C_TeamTrainWatcher, DT_TeamTrainWatcher, CTeamTrainWatcher)
2020-04-22 12:56:21 -04:00
RecvPropFloat( RECVINFO( m_flTotalProgress ) ),
RecvPropInt( RECVINFO( m_iTrainSpeedLevel ) ),
RecvPropFloat( RECVINFO( m_flRecedeTime ) ),
RecvPropInt( RECVINFO( m_nNumCappers ) ),
END_RECV_TABLE()
2023-10-03 17:23:56 +03:00
C_TeamTrainWatcher *g_pTrainWatcher = NULL;
2020-04-22 12:56:21 -04:00
C_TeamTrainWatcher::C_TeamTrainWatcher()
{
2023-10-03 17:23:56 +03:00
g_pTrainWatcher = this;
2020-04-22 12:56:21 -04:00
// force updates when we get our baseline
m_iTrainSpeedLevel = -2;
m_flTotalProgress = -1;
m_flRecedeTime = -1;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
C_TeamTrainWatcher::~C_TeamTrainWatcher()
{
2023-10-03 17:23:56 +03:00
if ( g_pTrainWatcher == this )
2020-04-22 12:56:21 -04:00
{
2023-10-03 17:23:56 +03:00
g_pTrainWatcher = NULL;
2020-04-22 12:56:21 -04:00
}
}
void C_TeamTrainWatcher::OnPreDataChanged( DataUpdateType_t updateType )
{
BaseClass::OnPreDataChanged( updateType );
m_iOldTrainSpeedLevel = m_iTrainSpeedLevel;
m_flOldProgress = m_flTotalProgress;
m_flOldRecedeTime = m_flRecedeTime;
m_nOldNumCappers = m_nNumCappers;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_TeamTrainWatcher::OnDataChanged( DataUpdateType_t updateType )
{
if ( m_iOldTrainSpeedLevel != m_iTrainSpeedLevel || m_nOldNumCappers != m_nNumCappers )
{
IGameEvent *event = gameeventmanager->CreateEvent( "escort_speed" );
if ( event )
{
event->SetInt( "speed", m_iTrainSpeedLevel );
event->SetInt( "players", m_nNumCappers );
gameeventmanager->FireEventClientSide( event );
}
}
if ( m_flOldProgress != m_flTotalProgress )
{
IGameEvent *event = gameeventmanager->CreateEvent( "escort_progress" );
if ( event )
{
event->SetFloat( "progress", m_flTotalProgress );
if ( m_flOldProgress <= -1 )
{
event->SetBool( "reset", true );
}
gameeventmanager->FireEventClientSide( event );
}
}
if ( m_flOldRecedeTime != m_flRecedeTime )
{
IGameEvent *event = gameeventmanager->CreateEvent( "escort_recede" );
if ( event )
{
event->SetFloat( "recedetime", m_flRecedeTime );
gameeventmanager->FireEventClientSide( event );
}
}
2023-10-03 17:23:56 +03:00
}