blob: 7eeeae20314c5b27e15b18f769f245cba5c2c5f6 (
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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================
#include "cbase.h"
#include "tf_timer.h"
static CUtlLinkedList<CTimer*,int> g_Timers;
// ------------------------------------------------------------------------------------------ //
// CTimer functions.
// ------------------------------------------------------------------------------------------ //
CTimer::CTimer()
{
m_iTeamNumber = 0;
m_flNextThink = 0;
}
int CTimer::GetTeamNumber() const
{
return m_iTeamNumber;
}
// ------------------------------------------------------------------------------------------ //
// Global timer functions.
// ------------------------------------------------------------------------------------------ //
CTimer* Timer_FindTimer( CBaseEntity *pPlayer, TFTimer_t timerType )
{
FOR_EACH_LL( g_Timers, i )
{
CTimer *pTimer = g_Timers[i];
if ( pTimer->m_hOwner == pPlayer )
{
if ( timerType == TF_TIMER_ANY || pTimer->m_Type == timerType )
return pTimer;
}
}
return NULL;
}
CTimer* Timer_CreateTimer( CBaseEntity *pPlayer, TFTimer_t timerType )
{
Assert( !Timer_FindTimer( pPlayer, timerType ) );
CTimer *pTimer = new CTimer;
pTimer->m_hOwner = pPlayer;
pTimer->m_Type = timerType;
pTimer->m_iListIndex = g_Timers.AddToTail( pTimer );
// TFTODO: Register the think functions here..
if ( pTimer->m_Type == TF_TIMER_ROTHEALTH )
{
pTimer->m_flNextThink = gpGlobals->curtime + 5;
}
else if ( pTimer->m_Type == TF_TIMER_INFECTION )
{
pTimer->m_flNextThink = gpGlobals->curtime + 2;
}
// TFTODO: hook up thinks...
// TF_TIMER_RETURNITEM -> CBaseEntity::ReturnItem -> <up to caller>
// TF_TIMER_ENDROUND -> CBaseEntity::EndRoundEnd -> <up to caller>
return pTimer;
}
void Timer_Remove( CTimer *pTimer )
{
g_Timers.Remove( pTimer->m_iListIndex );
delete pTimer;
}
void Timer_UpdateAll()
{
int iNext = 0;
int i = g_Timers.Head();
while ( i != g_Timers.InvalidIndex() )
{
iNext = g_Timers.Next( i );
CTimer *pTimer = g_Timers[i];
i = iNext;
// Get rid of invalid timers.
if ( pTimer->m_hOwner.Get() == NULL )
{
g_Timers.Remove( i );
delete pTimer;
}
else
{
// Is it time to think for this timer?
if ( gpGlobals->curtime >= pTimer->m_flNextThink )
{
// TFTODO: think here.
}
}
}
}
void Timer_RemoveAll()
{
g_Timers.PurgeAndDeleteElements();
}
|