forked from rh-hideout/pokeemerald-expansion
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclock.c
151 lines (135 loc) · 4.12 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#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"
#include "constants/form_change_types.h"
#include "item.h"
#include "random.h"
static void UpdatePerDay(struct Time *localTime);
static void UpdatePerMinute(struct Time *localTime);
static void FormChangeTimeUpdate();
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);
}
}
void UpdateVarsAndFlags(void)
{
if (VarGet(VAR_DEBUG) == 0){
FlagSet(FLAG_PLACED_STEEL_SPHERE);
FlagSet(FLAG_PLACED_STONE_SPHERE);
FlagSet(FLAG_PLACED_VERDANT_SPHERE);
PlantBerryTree(BERRY_TREE_ROUTE_110_YACHE_1, ITEM_TO_BERRY(ITEM_YACHE_BERRY), BERRY_STAGE_BERRIES, FALSE);
PlantBerryTree(BERRY_TREE_ROUTE_110_YACHE_2, ITEM_TO_BERRY(ITEM_YACHE_BERRY), BERRY_STAGE_BERRIES, FALSE);
VarSet(VAR_DEBUG, 1);
}
if (CheckBagHasItem(ITEM_TM_FALSE_SWIPE, 1) && !FlagGet(FLAG_PRINCIPAL_IN_SCHOOL))
{
FlagSet(FLAG_PRINCIPAL_IN_SCHOOL);
}
if (VarGet(VAR_DEBUG) == 1)
{
u16 i;
struct BagPocket *itemPocket;
itemPocket = &gBagPockets[TMHM_POCKET];
for (i = BAG_TMHM_COUNT - 3; i < BAG_TMHM_COUNT; i++)
{
gBagPockets[TMHM_POCKET].itemSlots[i].itemId = ITEM_NONE;
SetBagItemQuantity(&itemPocket->itemSlots[i].quantity, 0);
}
for (i = 0; i < 11; i++)
{
u8 rand = Random() % 100;
gSaveBlock1Ptr->strangeSeedDrop[i] = rand;
}
gSaveBlock1Ptr->strangeSeedIndex = 0;
VarSet(VAR_DEBUG, 2);
}
}
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();
RandomizeDailyVariables();
RandomizeFanClubTrade();
SetGrottos();
// UpdateDewfordTrendPerDay(daysSince);
UpdateTVShowsPerDay(daysSince);
UpdateWeatherPerDay(daysSince);
UpdatePartyPokerusTime(daysSince);
UpdateMirageRnd(daysSince);
UpdateBirchState(daysSince);
UpdateFrontierManiac(daysSince);
UpdateFrontierGambler(daysSince);
SetShoalItemFlag(daysSince);
SetRandomLotteryNumber(daysSince);
UpdateDaysPassedSinceFormChange(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)
{
UpdateVarsAndFlags();
BerryTreeTimeUpdate(minutes);
gSaveBlock2Ptr->lastBerryTreeUpdate = *localTime;
FormChangeTimeUpdate();
}
}
}
static void FormChangeTimeUpdate()
{
s32 i;
for (i = 0; i < PARTY_SIZE; i++)
{
struct Pokemon *mon = &gPlayerParty[i];
u32 targetSpecies = GetFormChangeTargetSpecies(mon, FORM_CHANGE_TIME_OF_DAY, 0);
u32 currentSpecies = GetMonData(mon, MON_DATA_SPECIES);
if (targetSpecies != currentSpecies)
{
SetMonData(mon, MON_DATA_SPECIES, &targetSpecies);
CalculateMonStats(mon);
}
}
}
static void ReturnFromStartWallClock(void)
{
InitTimeBasedEvents();
SetMainCallback2(CB2_ReturnToFieldContinueScriptPlayMapMusic);
}
void StartWallClock(void)
{
SetMainCallback2(CB2_StartWallClock);
gMain.savedCallback = ReturnFromStartWallClock;
}