2017-11-24 20:57:00 +01:00
|
|
|
#include "global.h"
|
|
|
|
#include "event_data.h"
|
|
|
|
#include "rtc.h"
|
2018-12-24 22:19:40 +01:00
|
|
|
#include "time_events.h"
|
|
|
|
#include "field_specials.h"
|
2017-11-24 20:57:00 +01:00
|
|
|
#include "lottery_corner.h"
|
|
|
|
#include "dewford_trend.h"
|
|
|
|
#include "tv.h"
|
2018-12-08 19:43:21 +01:00
|
|
|
#include "field_weather.h"
|
2017-11-24 20:57:00 +01:00
|
|
|
#include "berry.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "overworld.h"
|
|
|
|
#include "wallclock.h"
|
|
|
|
|
2017-12-16 16:23:05 +01:00
|
|
|
static void UpdatePerDay(struct Time *localTime);
|
|
|
|
static void UpdatePerMinute(struct Time *localTime);
|
2017-11-24 20:57:00 +01:00
|
|
|
|
2017-12-16 16:23:05 +01:00
|
|
|
static void InitTimeBasedEvents(void)
|
2017-11-24 20:57:00 +01:00
|
|
|
{
|
|
|
|
FlagSet(FLAG_SYS_CLOCK_SET);
|
|
|
|
RtcCalcLocalTime();
|
|
|
|
gSaveBlock2Ptr->lastBerryTreeUpdate = gLocalTime;
|
|
|
|
VarSet(VAR_DAYS, gLocalTime.days);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoTimeBasedEvents(void)
|
|
|
|
{
|
2019-09-13 20:24:07 +02:00
|
|
|
if (FlagGet(FLAG_SYS_CLOCK_SET) && !InPokemonCenter())
|
2017-11-24 20:57:00 +01:00
|
|
|
{
|
|
|
|
RtcCalcLocalTime();
|
2017-12-16 16:23:05 +01:00
|
|
|
UpdatePerDay(&gLocalTime);
|
|
|
|
UpdatePerMinute(&gLocalTime);
|
2017-11-24 20:57:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-16 16:23:05 +01:00
|
|
|
static void UpdatePerDay(struct Time *localTime)
|
2017-11-24 20:57:00 +01:00
|
|
|
{
|
|
|
|
u16 *days = GetVarPointer(VAR_DAYS);
|
|
|
|
u16 daysSince;
|
|
|
|
|
2017-12-16 16:23:05 +01:00
|
|
|
if (*days != localTime->days && *days <= localTime->days)
|
2017-11-24 20:57:00 +01:00
|
|
|
{
|
2017-12-16 16:23:05 +01:00
|
|
|
daysSince = localTime->days - *days;
|
2019-02-12 07:40:34 +01:00
|
|
|
ClearDailyFlags();
|
2017-12-16 16:23:05 +01:00
|
|
|
UpdateDewfordTrendPerDay(daysSince);
|
|
|
|
UpdateTVShowsPerDay(daysSince);
|
|
|
|
UpdateWeatherPerDay(daysSince);
|
|
|
|
UpdatePartyPokerusTime(daysSince);
|
|
|
|
UpdateMirageRnd(daysSince);
|
|
|
|
UpdateBirchState(daysSince);
|
|
|
|
UpdateFrontierManiac(daysSince);
|
|
|
|
UpdateFrontierGambler(daysSince);
|
|
|
|
SetShoalItemFlag(daysSince);
|
|
|
|
SetRandomLotteryNumber(daysSince);
|
|
|
|
*days = localTime->days;
|
2017-11-24 20:57:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-16 16:23:05 +01:00
|
|
|
static void UpdatePerMinute(struct Time *localTime)
|
2017-11-24 20:57:00 +01:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
BerryTreeTimeUpdate(minutes);
|
|
|
|
gSaveBlock2Ptr->lastBerryTreeUpdate = *localTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-16 16:23:05 +01:00
|
|
|
static void ReturnFromStartWallClock(void)
|
2017-11-24 20:57:00 +01:00
|
|
|
{
|
2017-12-16 16:23:05 +01:00
|
|
|
InitTimeBasedEvents();
|
2018-07-25 06:18:23 +02:00
|
|
|
SetMainCallback2(CB2_ReturnToFieldContinueScriptPlayMapMusic);
|
2017-11-24 20:57:00 +01:00
|
|
|
}
|
|
|
|
|
2017-12-16 16:23:05 +01:00
|
|
|
void StartWallClock(void)
|
2017-11-24 20:57:00 +01:00
|
|
|
{
|
2018-08-08 10:37:12 +02:00
|
|
|
SetMainCallback2(CB2_StartWallClock);
|
2017-12-16 16:23:05 +01:00
|
|
|
gMain.savedCallback = ReturnFromStartWallClock;
|
2017-11-24 20:57:00 +01:00
|
|
|
}
|