forked from pret/pokeemerald
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathclock.c
86 lines (77 loc) · 2.17 KB
/
clock.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
76
77
78
79
80
81
82
83
84
85
86
#include "global.h"
#include "event_data.h"
#include "rtc.h"
#include "time_events.h"
#include "field_specials.h"
#include "lottery_corner.h"
#include "dewford_trend.h"
#include "tv.h"
#include "field_weather.h"
#include "berry.h"
#include "main.h"
#include "overworld.h"
#include "wallclock.h"
static void UpdatePerDay(struct Time *localTime);
static void UpdatePerMinute(struct Time *localTime);
static void InitTimeBasedEvents(void)
{
FlagSet(FLAG_SYS_CLOCK_SET);
RtcCalcLocalTime();
gSaveBlock2Ptr->lastBerryTreeUpdate = gLocalTime;
VarSet(VAR_DAYS, gLocalTime.days);
}
void DoTimeBasedEvents(void)
{
if (FlagGet(FLAG_SYS_CLOCK_SET) && !InPokemonCenter())
{
RtcCalcLocalTime();
UpdatePerDay(&gLocalTime);
UpdatePerMinute(&gLocalTime);
}
}
static void UpdatePerDay(struct Time *localTime)
{
u16 *days = GetVarPointer(VAR_DAYS);
u16 daysSince;
if (*days != localTime->days && *days <= localTime->days)
{
daysSince = localTime->days - *days;
ClearDailyFlags();
UpdateDewfordTrendPerDay(daysSince);
UpdateTVShowsPerDay(daysSince);
UpdateWeatherPerDay(daysSince);
UpdatePartyPokerusTime(daysSince);
UpdateMirageRnd(daysSince);
UpdateBirchState(daysSince);
UpdateFrontierManiac(daysSince);
UpdateFrontierGambler(daysSince);
SetShoalItemFlag(daysSince);
SetRandomLotteryNumber(daysSince);
*days = localTime->days;
}
}
static void UpdatePerMinute(struct Time *localTime)
{
struct Time difference;
int minutes;
CalcTimeDifference(&difference, &gSaveBlock2Ptr->lastBerryTreeUpdate, localTime);
minutes = 24 * 60 * difference.days + 60 * difference.hours + difference.minutes;
if (minutes != 0)
{
if (minutes >= 0)
{
BerryTreeTimeUpdate(minutes);
gSaveBlock2Ptr->lastBerryTreeUpdate = *localTime;
}
}
}
static void ReturnFromStartWallClock(void)
{
InitTimeBasedEvents();
SetMainCallback2(CB2_ReturnToFieldContinueScriptPlayMapMusic);
}
void StartWallClock(void)
{
SetMainCallback2(CB2_StartWallClock);
gMain.savedCallback = ReturnFromStartWallClock;
}