sovereignx/src/play_time.c
psf e953a809ff
Added OW_USE_FAKE_RTC and OW_ALTERED_TIME_RATIO (#4910)
* Added OW_USE_FAKE_RTC, OW_ALTERED_TIME_RATIO and src/fake_rtc.c

* Changed ALTERED_TIME_RATIO to GEN_LATEST

* Changed spaces to tabs per https://github.com/rh-hideout/pokeemerald-expansion/pull/4910/files\#r1667111624
2024-07-10 20:58:01 +02:00

75 lines
1.5 KiB
C

#include "global.h"
#include "play_time.h"
#include "fake_rtc.h"
enum
{
STOPPED,
RUNNING,
MAXED_OUT
};
static u8 sPlayTimeCounterState;
void PlayTimeCounter_Reset(void)
{
sPlayTimeCounterState = STOPPED;
gSaveBlock2Ptr->playTimeHours = 0;
gSaveBlock2Ptr->playTimeMinutes = 0;
gSaveBlock2Ptr->playTimeSeconds = 0;
gSaveBlock2Ptr->playTimeVBlanks = 0;
}
void PlayTimeCounter_Start(void)
{
sPlayTimeCounterState = RUNNING;
if (gSaveBlock2Ptr->playTimeHours > 999)
PlayTimeCounter_SetToMax();
}
void PlayTimeCounter_Stop(void)
{
sPlayTimeCounterState = STOPPED;
}
void PlayTimeCounter_Update(void)
{
if (sPlayTimeCounterState != RUNNING)
return;
gSaveBlock2Ptr->playTimeVBlanks++;
if (gSaveBlock2Ptr->playTimeVBlanks < 60)
return;
gSaveBlock2Ptr->playTimeVBlanks = 0;
gSaveBlock2Ptr->playTimeSeconds++;
FakeRtc_TickTimeForward();
if (gSaveBlock2Ptr->playTimeSeconds < 60)
return;
gSaveBlock2Ptr->playTimeSeconds = 0;
gSaveBlock2Ptr->playTimeMinutes++;
if (gSaveBlock2Ptr->playTimeMinutes < 60)
return;
gSaveBlock2Ptr->playTimeMinutes = 0;
gSaveBlock2Ptr->playTimeHours++;
if (gSaveBlock2Ptr->playTimeHours > 999)
PlayTimeCounter_SetToMax();
}
void PlayTimeCounter_SetToMax(void)
{
sPlayTimeCounterState = MAXED_OUT;
gSaveBlock2Ptr->playTimeHours = 999;
gSaveBlock2Ptr->playTimeMinutes = 59;
gSaveBlock2Ptr->playTimeSeconds = 59;
gSaveBlock2Ptr->playTimeVBlanks = 59;
}