mirror of
https://github.com/Ninjdai1/pokeemerald.git
synced 2024-12-26 03:34:15 +01:00
1cb659df8c
- Determined how the various script contexts were used and renamed accordingly. - ScriptContext2_Enable/Disable => Lock/UnlockPlayerFieldControls - The sole purpose of the flag is to make sure the player can't move around in the overworld. It has nothing to do with script contexts. - ScriptContext1 => ScriptContext - It is the global script context used to set up scripts which run over many frames. - ScriptContext2_RunNewScript => RunScriptImmediately - ScriptContext2's sole purpose was to run scripts immediately and in a separate context, usually while the global context is waiting for things like map loads or screen changes.
119 lines
2.1 KiB
C
119 lines
2.1 KiB
C
#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 = ISO_RANDOMIZE2(rnd);
|
|
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, // 00
|
|
1, // 01
|
|
1, // 02
|
|
0, // 03
|
|
0, // 04
|
|
0, // 05
|
|
0, // 06
|
|
0, // 07
|
|
0, // 08
|
|
1, // 09
|
|
1, // 10
|
|
1, // 11
|
|
1, // 12
|
|
1, // 13
|
|
1, // 14
|
|
0, // 15
|
|
0, // 16
|
|
0, // 17
|
|
0, // 18
|
|
0, // 19
|
|
0, // 20
|
|
1, // 21
|
|
1, // 22
|
|
1, // 23
|
|
};
|
|
|
|
if (IsMapTypeOutdoors(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())
|
|
{
|
|
ScriptContext_Enable();
|
|
DestroyTask(taskId);
|
|
}
|
|
}
|
|
|
|
void WaitWeather(void)
|
|
{
|
|
CreateTask(Task_WaitWeather, 80);
|
|
}
|
|
|
|
void InitBirchState(void)
|
|
{
|
|
*GetVarPointer(VAR_BIRCH_STATE) = 0;
|
|
}
|
|
|
|
void UpdateBirchState(u16 days)
|
|
{
|
|
u16 *state = GetVarPointer(VAR_BIRCH_STATE);
|
|
*state += days;
|
|
*state %= 7;
|
|
}
|