* First concept * Fixed config file and added static assert * Reset debug scripts * Cleaned up overworld config * Renamed new Rtc pausing functions per https://github.com/rh-hideout/pokeemerald-expansion/pull/4954\#discussion_r1675393121 * Added tabs instead of spaces per https://github.com/rh-hideout/pokeemerald-expansion/pull/4954\#discussion_r1676791279 * Update include/config/overworld.h --------- Co-authored-by: Bassoonian <iasperbassoonian@gmail.com>
105 lines
2.1 KiB
C
105 lines
2.1 KiB
C
#include "global.h"
|
|
#include "string_util.h"
|
|
#include "strings.h"
|
|
#include "text.h"
|
|
#include "rtc.h"
|
|
#include "fake_rtc.h"
|
|
#include "event_data.h"
|
|
|
|
struct Time *FakeRtc_GetCurrentTime(void)
|
|
{
|
|
#if OW_USE_FAKE_RTC
|
|
return &gSaveBlock3Ptr->fakeRTC;
|
|
#else
|
|
return NULL;
|
|
#endif
|
|
}
|
|
|
|
void FakeRtc_GetRawInfo(struct SiiRtcInfo *rtc)
|
|
{
|
|
struct Time* time = FakeRtc_GetCurrentTime();
|
|
rtc->second = time->seconds;
|
|
rtc->minute = time->minutes;
|
|
rtc->hour = time->hours;
|
|
rtc->day = time->days;
|
|
}
|
|
|
|
void FakeRtc_TickTimeForward(void)
|
|
{
|
|
if (!OW_USE_FAKE_RTC)
|
|
return;
|
|
|
|
if (FlagGet(OW_FLAG_PAUSE_TIME))
|
|
return;
|
|
|
|
FakeRtc_AdvanceTimeBy(0, 0, FakeRtc_GetSecondsRatio());
|
|
}
|
|
|
|
void FakeRtc_AdvanceTimeBy(u32 hours, u32 minutes, u32 seconds)
|
|
{
|
|
struct Time* time = FakeRtc_GetCurrentTime();
|
|
seconds += time->seconds;
|
|
minutes += time->minutes;
|
|
hours += time->hours;
|
|
|
|
while(seconds >= SECONDS_PER_MINUTE)
|
|
{
|
|
minutes++;
|
|
seconds -= SECONDS_PER_MINUTE;
|
|
}
|
|
|
|
while(minutes >= MINUTES_PER_HOUR)
|
|
{
|
|
hours++;
|
|
minutes -= MINUTES_PER_HOUR;
|
|
}
|
|
|
|
while(hours >= HOURS_PER_DAY)
|
|
{
|
|
time->days++;
|
|
hours -= HOURS_PER_DAY;
|
|
}
|
|
|
|
time->seconds = seconds;
|
|
time->minutes = minutes;
|
|
time->hours = hours;
|
|
}
|
|
|
|
void FakeRtc_ManuallySetTime(u32 hour, u32 minute, u32 second)
|
|
{
|
|
struct Time diff, target;
|
|
RtcCalcLocalTime();
|
|
|
|
target.hours = hour;
|
|
target.minutes = minute;
|
|
target.seconds = second;
|
|
target.days = gLocalTime.days;
|
|
|
|
CalcTimeDifference(&diff, &gLocalTime, &target);
|
|
FakeRtc_AdvanceTimeBy(diff.hours, diff.minutes, diff.seconds);
|
|
}
|
|
|
|
u32 FakeRtc_GetSecondsRatio(void)
|
|
{
|
|
return (OW_ALTERED_TIME_RATIO == GEN_8_PLA) ? 60 :
|
|
(OW_ALTERED_TIME_RATIO == GEN_9) ? 20 :
|
|
1;
|
|
}
|
|
|
|
STATIC_ASSERT((OW_FLAG_PAUSE_TIME == 0 || OW_USE_FAKE_RTC == TRUE), FakeRtcMustBeTrueToPauseTime);
|
|
|
|
void Script_PauseFakeRtc(void)
|
|
{
|
|
FlagSet(OW_FLAG_PAUSE_TIME);
|
|
}
|
|
|
|
void Script_ResumeFakeRtc(void)
|
|
{
|
|
FlagClear(OW_FLAG_PAUSE_TIME);
|
|
}
|
|
|
|
void Script_ToggleFakeRtc(void)
|
|
{
|
|
FlagToggle(OW_FLAG_PAUSE_TIME);
|
|
}
|