Browse Source

Add timer from AG mini.

dmc
Night Owl 7 years ago
parent
commit
911965c86b
  1. 3
      dlls/3wave/threewave_gamerules.cpp
  2. 1
      dlls/CMakeLists.txt
  3. 84
      dlls/aghl/agtimer.cpp
  4. 28
      dlls/aghl/agtimer.h
  5. 2
      dlls/gamerules.h
  6. 5
      dlls/multiplay_gamerules.cpp
  7. 5
      dlls/teamplay_gamerules.cpp

3
dlls/3wave/threewave_gamerules.cpp

@ -145,6 +145,9 @@ void CThreeWave::Think( void ) @@ -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);

1
dlls/CMakeLists.txt

@ -45,6 +45,7 @@ set (SVDLL_SOURCES @@ -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

84
dlls/aghl/agtimer.cpp

@ -0,0 +1,84 @@ @@ -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

28
dlls/aghl/agtimer.h

@ -0,0 +1,28 @@ @@ -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

2
dlls/gamerules.h

@ -25,6 +25,7 @@ @@ -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: @@ -177,6 +178,7 @@ public:
//++ BulliT
AgArena m_Arena;
AgLMS m_LMS;
AgTimer m_Timer;
int m_iGameMode;
float m_fGameStart;
//-- Martin Webrant

5
dlls/multiplay_gamerules.cpp

@ -249,15 +249,14 @@ void CHalfLifeMultiplay::Think( void ) @@ -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();
//-- Martin Webrant
}
if( m_flGameEndTime != 0.0 && m_flGameEndTime <= gpGlobals->time )
{

5
dlls/teamplay_gamerules.cpp

@ -92,8 +92,11 @@ void CHalfLifeTeamplay::Think( void ) @@ -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" ) )

Loading…
Cancel
Save