From bf3ff137d57615623aecbaffa92eb0a78df6f725 Mon Sep 17 00:00:00 2001 From: cawtds <38510667+cawtds@users.noreply.github.com> Date: Sat, 22 Jun 2024 14:34:07 +0200 Subject: [PATCH] gen5 seasons --- include/rtc.h | 82 +++++++++++++++++++++++++++++++++++++++++++++--- src/rtc.c | 34 +++++++++++--------- src/start_menu.c | 2 +- 3 files changed, 98 insertions(+), 20 deletions(-) diff --git a/include/rtc.h b/include/rtc.h index cc76ca76f..7c1c357e4 100644 --- a/include/rtc.h +++ b/include/rtc.h @@ -43,8 +43,20 @@ #define NIGHT_HOUR_BEGIN 20 #define NIGHT_HOUR_END 4 -//Gen 5 currently not included as the seasons change the times of day -#elif OW_TIMES_OF_DAY <= GEN_6 +//Gen 5 seasons change the times of day +#elif OW_TIMES_OF_DAY == GEN_5 + #define MORNING_HOUR_BEGIN GetGen5MorningBegin() + #define MORNING_HOUR_END GetGen5DayBegin() + + #define DAY_HOUR_BEGIN GetGen5DayBegin() + #define DAY_HOUR_END GetGen5EveningBegin() + + #define EVENING_HOUR_BEGIN GetGen5EveningBegin() + #define EVENING_HOUR_END GetGen5NightBegin() + + #define NIGHT_HOUR_BEGIN GetGen5NightBegin() + #define NIGHT_HOUR_END GetGen5MorningBegin() +#elif OW_TIMES_OF_DAY == GEN_6 #define MORNING_HOUR_BEGIN 4 #define MORNING_HOUR_END 11 @@ -92,8 +104,6 @@ #define SEASON_SUMMER 1 #define SEASON_AUTUMN 2 #define SEASON_WINTER 3 -#define NUM_SEASONS 4 -#define DAYS_PER_SEASON 5 extern struct Time gLocalTime; @@ -130,4 +140,68 @@ u8 GetCurrentMinute(void); u8 GetSeason(void); u8 GetSeasonDay(void); +static inline s32 GetGen5MorningBegin() +{ + switch (GetSeason()) + { + case SEASON_SPRING: + default: + return 5; + case SEASON_SUMMER: + return 4; + case SEASON_AUTUMN: + return 6; + case SEASON_WINTER: + return 7; + } +} + +static inline s32 GetGen5DayBegin() +{ + switch (GetSeason()) + { + case SEASON_SPRING: + default: + return 10; + case SEASON_SUMMER: + return 9; + case SEASON_AUTUMN: + return 10; + case SEASON_WINTER: + return 11; + } +} + +static inline s32 GetGen5EveningBegin() +{ + switch (GetSeason()) + { + case SEASON_SPRING: + default: + return 17; + case SEASON_SUMMER: + return 19; + case SEASON_AUTUMN: + return 18; + case SEASON_WINTER: + return 17; + } +} + +static inline s32 GetGen5NightBegin() +{ + switch (GetSeason()) + { + case SEASON_SPRING: + default: + return 20; + case SEASON_SUMMER: + return 21; + case SEASON_AUTUMN: + return 20; + case SEASON_WINTER: + return 19; + } +} + #endif // GUARD_RTC_UTIL_H diff --git a/src/rtc.c b/src/rtc.c index a32a01bb8..c3958b9e5 100644 --- a/src/rtc.c +++ b/src/rtc.c @@ -321,30 +321,34 @@ u8 GetCurrentMinute(void) u8 GetSeason(void) { - u8 seasonIndex; - - RtcCalcLocalTime(); - seasonIndex = (gLocalTime.days / DAYS_PER_SEASON) % NUM_SEASONS; - switch (seasonIndex) + RtcGetInfo(&sRtc); + switch(ConvertBcdToBinary(sRtc.month)) { - case 0: - return SEASON_SPRING; - case 1: - return SEASON_SUMMER; - case 2: - return SEASON_AUTUMN; - case 3: - return SEASON_WINTER; + case MONTH_JAN: + case MONTH_MAY: + case MONTH_SEP: default: return SEASON_SPRING; + case MONTH_FEB: + case MONTH_JUN: + case MONTH_OCT: + return SEASON_SUMMER; + case MONTH_MAR: + case MONTH_JUL: + case MONTH_NOV: + return SEASON_AUTUMN; + case MONTH_APR: + case MONTH_AUG: + case MONTH_DEC: + return SEASON_WINTER; } } u8 GetSeasonDay(void) { - RtcCalcLocalTime(); + RtcGetInfo(&sRtc); - return (gLocalTime.days % DAYS_PER_SEASON) + 1; + return ConvertBcdToBinary(sRtc.day); } void RtcCalcLocalTime(void) diff --git a/src/start_menu.c b/src/start_menu.c index 64619a5df..a74395116 100644 --- a/src/start_menu.c +++ b/src/start_menu.c @@ -333,7 +333,7 @@ static void DrawTimeWindow(void) StringCopy(gStringVar1, gText_SeasonWinter); break; } - ConvertIntToDecimalStringN(gStringVar2, GetSeasonDay(), STR_CONV_MODE_RIGHT_ALIGN, 1); + ConvertIntToDecimalStringN(gStringVar2, GetSeasonDay(), STR_CONV_MODE_RIGHT_ALIGN, 2); StringExpandPlaceholders(gStringVar4, gText_MenuDay); AddTextPrinterParameterized(sTimeWindowId, FONT_NORMAL, gStringVar4, 4, 18, 0xFF, NULL);