summaryrefslogtreecommitdiff
path: root/src/time_events.c
diff options
context:
space:
mode:
authorPikalaxALT <pikalaxalt@gmail.com>2018-03-31 14:37:24 -0400
committerPikalaxALT <pikalaxalt@gmail.com>2018-03-31 14:37:24 -0400
commit0015d6fe2c6a53c5f757599122ae9fd1a156a69f (patch)
tree81b7269c767da1ad4a5a9ac01e58ead5e92f0983 /src/time_events.c
parent46bc01f0dd1a3435b3c6ce71e1be0d19b7aaa5bd (diff)
parent59f81c5f2a25ec77baf4a30c3da9ccb7675d1562 (diff)
Merge branch 'master' into contest_link_80C2020
Diffstat (limited to 'src/time_events.c')
-rw-r--r--src/time_events.c118
1 files changed, 118 insertions, 0 deletions
diff --git a/src/time_events.c b/src/time_events.c
new file mode 100644
index 000000000..4bd732788
--- /dev/null
+++ b/src/time_events.c
@@ -0,0 +1,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(get_map_type_from_warp0()))
+ {
+ 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;
+}