diff --git a/dlls/3wave/threewave_gamerules.cpp b/dlls/3wave/threewave_gamerules.cpp index cf188bb0..4e553836 100644 --- a/dlls/3wave/threewave_gamerules.cpp +++ b/dlls/3wave/threewave_gamerules.cpp @@ -145,6 +145,9 @@ void CThreeWave::Think( void ) return; } + // Update HUD timer and effective time. + m_Timer.Think(); + float flTimeLimit = CVAR_GET_FLOAT("mp_timelimit") * 60; time_remaining = (int)(flTimeLimit ? ( flTimeLimit - gpGlobals->time ) : 0); diff --git a/dlls/CMakeLists.txt b/dlls/CMakeLists.txt index 35895b00..89ec378b 100644 --- a/dlls/CMakeLists.txt +++ b/dlls/CMakeLists.txt @@ -45,6 +45,7 @@ set (SVDLL_SOURCES aghl/agglobal.cpp aghl/aglms.cpp aghl/agspectator.cpp + aghl/agtimer.cpp dmc/quake_gun.cpp dmc/quake_items.cpp dmc/quake_nail.cpp diff --git a/dlls/aghl/agtimer.cpp b/dlls/aghl/agtimer.cpp new file mode 100644 index 00000000..e7d57c28 --- /dev/null +++ b/dlls/aghl/agtimer.cpp @@ -0,0 +1,84 @@ +//++ BulliT + +#include "extdll.h" +#include "util.h" +#include "cbase.h" +#include "game.h" +#include "player.h" + +#include "agtimer.h" +#include "agglobal.h" + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +AgTimer::AgTimer() +{ + m_fNextTimerUpdate = gpGlobals->time + 5.0; //Dont start timer directly. + m_fLastTimeCheck = gpGlobals->time; + m_fEffectiveTime = 0.0; + m_pmp_timelimit = CVAR_GET_POINTER("mp_timelimit"); +} + +AgTimer::~AgTimer() +{ + +} + +void AgTimer::Think() +{ + // Calculate effective time + m_fEffectiveTime += gpGlobals->time - m_fLastTimeCheck; + + m_fLastTimeCheck = gpGlobals->time; + + if( m_fNextTimerUpdate <= m_fEffectiveTime ) + { + // Sanity time check. Some dudes tends to put timelimit weird. + if( timelimit.value > 2880 ) + CVAR_SET_FLOAT( "mp_timelimit", 2880 ); //Max two days. + + // Write the time. (negative turns off timer on client) + long lTime = (m_pmp_timelimit->value * 60) - m_fEffectiveTime; + + if( lTime > 0 ) + { + char szTime[128]; + if( 86400 < lTime ) + { + //More than one day. Print days, hour, minutes and seconds + ldiv_t d1 = ldiv( lTime, 86400 ); + ldiv_t d2 = ldiv( d1.rem, 3600 ); + ldiv_t d3 = ldiv( d2.rem, 60 ); + sprintf( szTime, "%ldd %ldh %02ldm %02lds\n", d1.quot, d2.quot, d3.quot, d3.rem ); + } + else if( 3600 < lTime ) + { + // More than one hour. Print hour, minutes and seconds + ldiv_t d1 = ldiv( lTime, 3600 ); + ldiv_t d2 = ldiv( d1.rem, 60 ); + sprintf( szTime, "%ldh %02ldm %02lds\n", d1.quot, d2.quot, d2.rem ); + } + else if( 60 < lTime ) + { + // More than one minute. Print minutes and seconds. + ldiv_t d = ldiv( lTime, 60 ); + sprintf( szTime, "%ld:%02ld\n", d.quot, d.rem ); + } + else + { + // Less than a minute left. Print seconds. + sprintf( szTime,"%ld\n", lTime ); + } + + AgSay( NULL, szTime, NULL, 5, 0.5, 0.01, 1 ); + if( 120L < lTime ) + m_fNextTimerUpdate += 30; + else + m_fNextTimerUpdate += 5; + } + } +} + +//-- Martin Webrant diff --git a/dlls/aghl/agtimer.h b/dlls/aghl/agtimer.h new file mode 100644 index 00000000..8d0fcb09 --- /dev/null +++ b/dlls/aghl/agtimer.h @@ -0,0 +1,28 @@ +//++ BulliT + +#if !defined(AFX_AGTIMER_H__699E98F5_E1CB_4F41_8492_F741C0450C4D__INCLUDED_) +#define AFX_AGTIMER_H__699E98F5_E1CB_4F41_8492_F741C0450C4D__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +class AgTimer +{ + cvar_t* m_pmp_timelimit; + float m_fNextTimerUpdate; + float m_fLastTimeCheck; + float m_fEffectiveTime; + +public: + AgTimer(); + virtual ~AgTimer(); + + void Think(); +}; + + + +#endif // !defined(AFX_AGTIMER_H__699E98F5_E1CB_4F41_8492_F741C0450C4D__INCLUDED_) + +//-- Martin Webrant diff --git a/dlls/gamerules.h b/dlls/gamerules.h index 0a9ed16c..7e7cb017 100644 --- a/dlls/gamerules.h +++ b/dlls/gamerules.h @@ -25,6 +25,7 @@ #define LTS 6 //-- Martin Webrant +#include "agtimer.h" //#include "weapons.h" //#include "items.h" class CBasePlayerItem; @@ -177,6 +178,7 @@ public: //++ BulliT AgArena m_Arena; AgLMS m_LMS; + AgTimer m_Timer; int m_iGameMode; float m_fGameStart; //-- Martin Webrant diff --git a/dlls/multiplay_gamerules.cpp b/dlls/multiplay_gamerules.cpp index 8a81cc17..894c535d 100644 --- a/dlls/multiplay_gamerules.cpp +++ b/dlls/multiplay_gamerules.cpp @@ -249,15 +249,14 @@ void CHalfLifeMultiplay::Think( void ) return; } - if( !g_bIsThreeWave ) - { + // Update HUD timer and effective time. + m_Timer.Think(); //++ BulliT - if( g_pGameRules->m_iGameMode == LMS ) - m_LMS.Think(); - else if( g_pGameRules->m_iGameMode == ARENA ) - m_Arena.Think(); + if( g_pGameRules->m_iGameMode == LMS ) + m_LMS.Think(); + else if( g_pGameRules->m_iGameMode == ARENA ) + m_Arena.Think(); //-- Martin Webrant - } if( m_flGameEndTime != 0.0 && m_flGameEndTime <= gpGlobals->time ) { diff --git a/dlls/teamplay_gamerules.cpp b/dlls/teamplay_gamerules.cpp index aa707048..33c03c3d 100644 --- a/dlls/teamplay_gamerules.cpp +++ b/dlls/teamplay_gamerules.cpp @@ -92,8 +92,11 @@ void CHalfLifeTeamplay::Think( void ) return; } + // Update HUD timer and effective time. + m_Timer.Think(); + //++ BulliT - if( !g_bIsThreeWave && g_pGameRules->m_iGameMode == LTS ) + if( g_pGameRules->m_iGameMode == LTS ) m_LMS.Think(); if( m_iGameMode != CVAR_GET_FLOAT( "mp_teamplay" ) )