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
|
#include "global.h"
#include "time_events.h"
#include "event_data.h"
#include "field_weather.h"
#include "pokemon.h"
#include "random.h"
#include "overworld.h"
#include "rtc.h"
#include "script.h"
#include "task.h"
static u32 GetMirageRnd(void)
{
u32 hi = VarGet(VAR_MIRAGE_RND_H);
u32 lo = VarGet(VAR_MIRAGE_RND_L);
return (hi << 16) | lo;
}
static void SetMirageRnd(u32 rnd)
{
VarSet(VAR_MIRAGE_RND_H, rnd >> 16);
VarSet(VAR_MIRAGE_RND_L, rnd);
}
// unused
void InitMirageRnd(void)
{
SetMirageRnd((Random() << 16) | Random());
}
void UpdateMirageRnd(u16 days)
{
s32 rnd = GetMirageRnd();
while (days)
{
rnd = 1103515245 * rnd + 12345;
days--;
}
SetMirageRnd(rnd);
}
bool8 IsMirageIslandPresent(void)
{
u16 rnd = GetMirageRnd() >> 16;
int i;
for (i = 0; i < PARTY_SIZE; i++)
if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES) && (GetMonData(&gPlayerParty[i], MON_DATA_PERSONALITY) & 0xFFFF) == rnd)
return TRUE;
return FALSE;
}
void UpdateShoalTideFlag(void)
{
static const u8 tide[] =
{
1,
1,
1,
0,
0,
0,
0,
0,
0,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
1,
1,
1,
};
if (is_map_type_1_2_3_5_or_6(GetLastUsedWarpMapType()))
{
RtcCalcLocalTime();
if (tide[gLocalTime.hours])
FlagSet(FLAG_SYS_SHOAL_TIDE);
else
FlagClear(FLAG_SYS_SHOAL_TIDE);
}
}
static void Task_WaitWeather(u8 taskId)
{
if (IsWeatherChangeComplete())
{
EnableBothScriptContexts();
DestroyTask(taskId);
}
}
void WaitWeather(void)
{
CreateTask(Task_WaitWeather, 80);
}
void InitBirchState(void)
{
*(u16 *)GetVarPointer(VAR_BIRCH_STATE) = 0;
}
void UpdateBirchState(u16 days)
{
u16 *state = GetVarPointer(VAR_BIRCH_STATE);
*state += days;
*state %= 7;
}
|