#include "global.h" /* ----------------------------------------------------------------------------- Class: Bookkeeper Desc: See header. Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved. Chris Danford ----------------------------------------------------------------------------- */ #include "Bookkeeper.h" #include "RageUtil.h" #include "arch/arch.h" #include "PrefsManager.h" #include "RageLog.h" #include "IniFile.h" #include "GameConstantsAndTypes.h" #include "SongManager.h" #include #include Bookkeeper* BOOKKEEPER = NULL; // global and accessable from anywhere in our program static const CString BOOKKEEPING_INI = BASE_PATH "Data" SLASH "Bookkeeping.ini"; static const CString COINS_DAT = BASE_PATH "Data" SLASH "Coins.dat"; tm GetDaysAgo( tm start, int iDaysAgo ) { start.tm_mday -= iDaysAgo; time_t seconds = mktime( &start ); ASSERT( seconds != (time_t)-1 ); tm time = *localtime( &seconds ); return time; } tm GetYesterday( tm start ) { return GetDaysAgo( start, -1 ); } int GetDayOfWeek( tm time ) { return time.tm_wday; } tm GetLastSunday( tm start ) { return GetDaysAgo( start, -GetDayOfWeek(start) ); } Bookkeeper::Bookkeeper() { int i, j; m_iLastSeenTime = time(NULL); m_iTotalCoins = 0; m_iTotalUptimeSeconds = 0; m_iTotalPlaySeconds = 0; m_iTotalPlays = 0; for( i=0; iWarn( "The new time is older than the last seen time. Is someone fiddling with the system clock?" ); m_iLastSeenTime = lNewTime; return; } tm tOld = *localtime( &lOldTime ); tm tNew = *localtime( &lNewTime ); CLAMP( tOld.tm_year, tNew.tm_year-1, tNew.tm_year ); while( tOld.tm_year != tNew.tm_year || tOld.tm_yday != tNew.tm_yday || tOld.tm_hour != tNew.tm_hour ) { tOld.tm_hour++; if( tOld.tm_hour == HOURS_PER_DAY ) { tOld.tm_hour = 0; tOld.tm_yday++; } if( tOld.tm_yday == DAYS_PER_YEAR ) { tOld.tm_yday = 0; tOld.tm_year++; } m_iCoinsByHourForYear[tOld.tm_yday][tOld.tm_hour] = 0; } } void Bookkeeper::CoinInserted() { UpdateLastSeenTime(); long lOldTime = m_iLastSeenTime; tm *pNewTime = localtime( &lOldTime ); m_iCoinsByHourForYear[pNewTime->tm_yday][pNewTime->tm_hour]++; } int Bookkeeper::GetCoinsForDay( int iDayOfYear ) { int iCoins = 0; for( int i=0; i