Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
2.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "tfc_timer.h"
  8. static CUtlLinkedList<CTimer*,int> g_Timers;
  9. // ------------------------------------------------------------------------------------------ //
  10. // CTimer functions.
  11. // ------------------------------------------------------------------------------------------ //
  12. CTimer::CTimer()
  13. {
  14. m_iTeamNumber = 0;
  15. m_flNextThink = 0;
  16. }
  17. int CTimer::GetTeamNumber() const
  18. {
  19. return m_iTeamNumber;
  20. }
  21. // ------------------------------------------------------------------------------------------ //
  22. // Global timer functions.
  23. // ------------------------------------------------------------------------------------------ //
  24. CTimer* Timer_FindTimer( CBaseEntity *pPlayer, TFCTimer_t timerType )
  25. {
  26. FOR_EACH_LL( g_Timers, i )
  27. {
  28. CTimer *pTimer = g_Timers[i];
  29. if ( pTimer->m_hOwner == pPlayer )
  30. {
  31. if ( timerType == TF_TIMER_ANY || pTimer->m_Type == timerType )
  32. return pTimer;
  33. }
  34. }
  35. return NULL;
  36. }
  37. CTimer* Timer_CreateTimer( CBaseEntity *pPlayer, TFCTimer_t timerType )
  38. {
  39. Assert( !Timer_FindTimer( pPlayer, timerType ) );
  40. CTimer *pTimer = new CTimer;
  41. pTimer->m_hOwner = pPlayer;
  42. pTimer->m_Type = timerType;
  43. pTimer->m_iListIndex = g_Timers.AddToTail( pTimer );
  44. // TFCTODO: Register the think functions here..
  45. if ( pTimer->m_Type == TF_TIMER_ROTHEALTH )
  46. {
  47. pTimer->m_flNextThink = gpGlobals->curtime + 5;
  48. }
  49. else if ( pTimer->m_Type == TF_TIMER_INFECTION )
  50. {
  51. pTimer->m_flNextThink = gpGlobals->curtime + 2;
  52. }
  53. // TFCTODO: hook up thinks...
  54. // TF_TIMER_RETURNITEM -> CBaseEntity::ReturnItem -> <up to caller>
  55. // TF_TIMER_ENDROUND -> CBaseEntity::EndRoundEnd -> <up to caller>
  56. return pTimer;
  57. }
  58. void Timer_Remove( CTimer *pTimer )
  59. {
  60. g_Timers.Remove( pTimer->m_iListIndex );
  61. delete pTimer;
  62. }
  63. void Timer_UpdateAll()
  64. {
  65. int iNext = 0;
  66. int i = g_Timers.Head();
  67. while ( i != g_Timers.InvalidIndex() )
  68. {
  69. iNext = g_Timers.Next( i );
  70. CTimer *pTimer = g_Timers[i];
  71. i = iNext;
  72. // Get rid of invalid timers.
  73. if ( pTimer->m_hOwner.Get() == NULL )
  74. {
  75. g_Timers.Remove( i );
  76. delete pTimer;
  77. }
  78. else
  79. {
  80. // Is it time to think for this timer?
  81. if ( gpGlobals->curtime >= pTimer->m_flNextThink )
  82. {
  83. // TFCTODO: think here.
  84. }
  85. }
  86. }
  87. }
  88. void Timer_RemoveAll()
  89. {
  90. g_Timers.PurgeAndDeleteElements();
  91. }