forked from rh-hideout/pokeemerald-expansion
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplay_time.c
75 lines (57 loc) · 1.51 KB
/
play_time.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#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;
}