diff options
author | YamaArashi <shadow962@live.com> | 2017-05-04 00:10:25 -0700 |
---|---|---|
committer | YamaArashi <shadow962@live.com> | 2017-05-04 00:21:04 -0700 |
commit | d7284694ec3543b84074f52938ea5e6666e17599 (patch) | |
tree | f401f21a422181f09bc7ff7f1c24025543823009 /src | |
parent | f492004cb605a45b0b43e94121a0f504d7fb10cc (diff) |
decompile time_events
Diffstat (limited to 'src')
-rw-r--r-- | src/clock.c | 4 | ||||
-rw-r--r-- | src/rom4.c | 2 | ||||
-rw-r--r-- | src/time_events.c | 118 |
3 files changed, 121 insertions, 3 deletions
diff --git a/src/clock.c b/src/clock.c index ceb140774..4ec49807c 100644 --- a/src/clock.c +++ b/src/clock.c @@ -12,7 +12,7 @@ extern void sub_80FA220(u16); extern void sub_80BE8C4(u16); extern void sub_8080834(u16); extern void UpdatePartyPokerusTime(u16); -extern void sub_810D2F4(u16); +extern void UpdateMirageRnd(u16); extern void UpdateBirchState(u16); extern void sub_810F618(u16); @@ -53,7 +53,7 @@ static void UpdatePerDay(struct Time *time) sub_80BE8C4(newDays); sub_8080834(newDays); UpdatePartyPokerusTime(newDays); - sub_810D2F4(newDays); + UpdateMirageRnd(newDays); UpdateBirchState(newDays); sub_810F618(newDays); SetRandomLotteryNumber(newDays); diff --git a/src/rom4.c b/src/rom4.c index ba1b31348..3d388fd6d 100644 --- a/src/rom4.c +++ b/src/rom4.c @@ -932,7 +932,7 @@ void sub_80540D0(s16 *a1, u16 *a2) void sub_8054164(void) { - if ((gSaveBlock1.location.mapGroup == 0 && gSaveBlock1.location.mapNum == 45) && !sub_810D32C()) + if ((gSaveBlock1.location.mapGroup == 0 && gSaveBlock1.location.mapNum == 45) && !IsMirageIslandPresent()) { gUnknown_02029816 = TRUE; gUnknown_02029814 = GetMirageIslandMon(); diff --git a/src/time_events.c b/src/time_events.c new file mode 100644 index 000000000..8cbf52a1a --- /dev/null +++ b/src/time_events.c @@ -0,0 +1,118 @@ +#include "global.h" +#include "event_data.h" +#include "pokemon.h" +#include "rng.h" +#include "rom4.h" +#include "rtc.h" +#include "script.h" +#include "task.h" + +extern bool8 sub_807DDFC(void); + +u32 GetMirageRnd(void) +{ + u32 hi = VarGet(VAR_MIRAGE_RND_H); + u32 lo = VarGet(VAR_MIRAGE_RND_L); + return (hi << 16) | lo; +} + +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_light_level_1_2_3_5_or_6(get_map_light_from_warp0())) + { + RtcCalcLocalTime(); + if (tide[gLocalTime.hours]) + FlagSet(SYS_SHOAL_TIDE); + else + FlagReset(SYS_SHOAL_TIDE); + } +} + +static void Task_WaitWeather(u8 taskId) +{ + if (sub_807DDFC()) + { + 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; +} |