aboutsummaryrefslogtreecommitdiff
path: root/mp/src/game/shared/teamplay_round_timer.h
blob: df94a271ca284d109c5a3c140d10851443222752 (plain) (blame)
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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Round timer for team gamerules
//
//=============================================================================//

#ifndef TEAM_ROUND_TIMER_H
#define TEAM_ROUND_TIMER_H

#ifdef _WIN32
#pragma once
#endif

#ifdef CLIENT_DLL
#define CTeamRoundTimer C_TeamRoundTimer
#endif

class CTeamRoundTimer : public CBaseEntity
{
public:
	DECLARE_CLASS( CTeamRoundTimer, CBaseEntity );
	DECLARE_NETWORKCLASS();

	CTeamRoundTimer();
	virtual ~CTeamRoundTimer();

	virtual void Spawn( void );
	virtual void Precache( void );
	virtual void Activate( void );

	// Returns seconds to display.
	// When paused shows amount of time left once the timer is resumed
	virtual float GetTimeRemaining( void );
	virtual int GetTimerMaxLength( void );
	virtual bool ShowInHud( void );
	virtual bool StartPaused( void ){ return m_bStartPaused; }
	bool ShowTimeRemaining( void ) { return m_bShowTimeRemaining; }

	bool IsDisabled( void ) { return m_bIsDisabled; }
	int GetTimerState( void ){ return m_nState; }

	bool IsTimerPaused( void ) { return m_bTimerPaused; }
	
#ifdef CLIENT_DLL

	void InternalSetPaused( bool bPaused ) { m_bTimerPaused = bPaused; }

#else

	void	SetStopWatchTimeStamp( void );
	virtual void SetTimeRemaining( int iTimerSeconds ); // Set the initial length of the timer
	virtual void AddTimerSeconds( int iSecondsToAdd, int iTeamResponsible = TEAM_UNASSIGNED ); // Add time to an already running ( or paused ) timer
	virtual void PauseTimer( void );
	virtual void ResumeTimer( void );
	virtual void SetAutoCountdown( bool bAuto ){ m_bAutoCountdown = bAuto; }

	void		 SetShowInHud( bool bShowInHUD ) { m_bShowInHUD = bShowInHUD; }

	int UpdateTransmitState();

	void InputEnable( inputdata_t &input );
	void InputDisable( inputdata_t &input );
	void InputPause( inputdata_t &input );
	void InputResume( inputdata_t &input );
	void InputSetTime( inputdata_t &input );
	void InputAddTime( inputdata_t &input );
	void InputRestart( inputdata_t &input );
	void InputShowInHUD( inputdata_t &input );
	void InputRoundSpawn( inputdata_t &inputdata );
	void InputSetMaxTime( inputdata_t &input );
	void InputAutoCountdown( inputdata_t &input );
	void InputAddTeamTime( inputdata_t &input );
	void InputSetSetupTime( inputdata_t &input );

#endif

	void SetCaptureWatchState( bool bCaptureWatch );
	bool IsWatchingTimeStamps( void ) { return m_bInCaptureWatchState; }
	void SetStopWatch( bool bState ) { m_bStopWatchTimer = bState; }
	bool IsStopWatchTimer( void ) { return m_bStopWatchTimer; }
	float GetStopWatchTotalTime( void ) { return m_flTotalTime; }
	bool IsRoundMaxTimerSet( void ) { return m_nTimerMaxLength > 0; }
	int GetTimerInitialLength( void ) { return m_nTimerInitialLength; }

private:
	void CalculateOutputMessages( void );

#ifdef CLIENT_DLL
	virtual void ClientThink();
	void OnPreDataChanged( DataUpdateType_t updateType );
	void OnDataChanged( DataUpdateType_t updateType );
	void SendTimeWarning( int nWarning );
	const char *GetTimeWarningSound( int nWarning );

#else
	void SetState( int nState, bool bFireOutput = true );
	void SetTimerThink( int nType );
	void EXPORT RoundTimerThink( void );
	void EXPORT RoundTimerSetupThink( void );

	static void SetActiveTimer( CTeamRoundTimer *pNewlyActive );
#endif

private:
	CNetworkVar( bool, m_bTimerPaused );
	CNetworkVar( float, m_flTimeRemaining );
	CNetworkVar( float, m_flTimerEndTime );	
	CNetworkVar( bool, m_bIsDisabled );
	CNetworkVar( bool, m_bShowInHUD );
	CNetworkVar( int, m_nTimerLength );			// current timer's length (used in the timer panel if no max length is set)
	CNetworkVar( int, m_nTimerInitialLength );	// initial length of the timer
	CNetworkVar( int, m_nTimerMaxLength );		// max time the timer can have (0 is no max)
	CNetworkVar( bool, m_bAutoCountdown );		// automatically count down the end of a round
	CNetworkVar( int, m_nSetupTimeLength );		// current timer's setup time length (setup time is the time before the round begins)
	CNetworkVar( int, m_nState );				// RT_STATE_SETUP or RT_STATE_NORMAL
	CNetworkVar( bool, m_bStartPaused );		// start the timer paused when it spawns
	CNetworkVar( bool, m_bShowTimeRemaining );  //show how much time is left (default) instead of how much time has passed.
	CNetworkVar( bool, m_bInCaptureWatchState );
	CNetworkVar( float, m_flTotalTime );
	CNetworkVar( bool, m_bStopWatchTimer );

	bool			m_bFireFinished;
	bool			m_bFire5MinRemain;
	bool			m_bFire4MinRemain;
	bool			m_bFire3MinRemain;
	bool			m_bFire2MinRemain;
	bool			m_bFire1MinRemain;
	bool			m_bFire30SecRemain;
	bool			m_bFire10SecRemain;
	bool			m_bFire5SecRemain;
	bool			m_bFire4SecRemain;
	bool			m_bFire3SecRemain;
	bool			m_bFire2SecRemain;
	bool			m_bFire1SecRemain;

#ifdef CLIENT_DLL 

	int				m_nOldTimerLength;
	int				m_nOldTimerState;

#else
	COutputEvent	m_OnRoundStart;
	COutputEvent	m_OnFinished;
	COutputEvent	m_On5MinRemain;
	COutputEvent	m_On4MinRemain;
	COutputEvent	m_On3MinRemain;
	COutputEvent	m_On2MinRemain;
	COutputEvent	m_On1MinRemain;
	COutputEvent	m_On30SecRemain;
	COutputEvent	m_On10SecRemain;
	COutputEvent	m_On5SecRemain;
	COutputEvent	m_On4SecRemain;
	COutputEvent	m_On3SecRemain;
	COutputEvent	m_On2SecRemain;
	COutputEvent	m_On1SecRemain;

	COutputEvent	m_OnSetupStart;
	COutputEvent	m_OnSetupFinished;

	float			m_flNextOvertimeNag;
	float			m_flLastTime;

	DECLARE_DATADESC();

	bool			m_bPauseDueToWin;
	bool			m_bResetTimeOnRoundStart;
	int				m_nTimeToUseAfterSetupFinished;
#endif 
};

#ifdef CLIENT_DLL
extern CTeamRoundTimer *g_TeamRoundTimer;
#endif

#endif	//TEAM_ROUND_TIMER_H