Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slight RTC documentation + Evolution times constants #1925

Merged
merged 2 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion include/siirtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#define SIIRTCINFO_24HOUR 0x40 // 0: 12-hour mode, 1: 24-hour mode
#define SIIRTCINFO_POWER 0x80 // power on or power failure occurred

#define DAY_HOURS 24
#define HOUR_MINUTES 60
#define MINUTE_SECONDS 60
AsparagusEduardo marked this conversation as resolved.
Show resolved Hide resolved

enum
{
MONTH_JAN = 1,
Expand All @@ -22,7 +26,8 @@ enum
MONTH_SEP,
MONTH_OCT,
MONTH_NOV,
MONTH_DEC
MONTH_DEC,
MONTH_COUNT = MONTH_DEC
};

struct SiiRtcInfo
Expand Down
10 changes: 8 additions & 2 deletions src/pokemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
#include "constants/trainers.h"
#include "constants/union_room.h"

#define DAY_EVO_HOUR_BEGIN 12
#define DAY_EVO_HOUR_END DAY_HOURS

#define NIGHT_EVO_HOUR_BEGIN 0
#define NIGHT_EVO_HOUR_END 12

struct SpeciesItem
{
u16 species;
Expand Down Expand Up @@ -5498,12 +5504,12 @@ u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 mode, u16 evolutionItem)
break;
case EVO_FRIENDSHIP_DAY:
RtcCalcLocalTime();
if (gLocalTime.hours >= 12 && gLocalTime.hours < 24 && friendship >= 220)
if (gLocalTime.hours >= DAY_EVO_HOUR_BEGIN && gLocalTime.hours < DAY_EVO_HOUR_END && friendship >= 220)
targetSpecies = gEvolutionTable[species][i].targetSpecies;
break;
case EVO_FRIENDSHIP_NIGHT:
RtcCalcLocalTime();
if (gLocalTime.hours >= 0 && gLocalTime.hours < 12 && friendship >= 220)
if (gLocalTime.hours >= NIGHT_EVO_HOUR_BEGIN && gLocalTime.hours < NIGHT_EVO_HOUR_END && friendship >= 220)
targetSpecies = gEvolutionTable[species][i].targetSpecies;
break;
case EVO_LEVEL:
Expand Down
48 changes: 24 additions & 24 deletions src/rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ struct Time gLocalTime;

static const struct SiiRtcInfo sRtcDummy = {0, MONTH_JAN, 1}; // 2000 Jan 1

static const s32 sNumDaysInMonths[12] =
static const s32 sNumDaysInMonths[MONTH_COUNT] =
{
31,
28,
31,
30,
31,
30,
31,
31,
30,
31,
30,
31,
[MONTH_JAN - 1] = 31,
[MONTH_FEB - 1] = 28,
[MONTH_MAR - 1] = 31,
[MONTH_APR - 1] = 30,
[MONTH_MAY - 1] = 31,
[MONTH_JUN - 1] = 30,
[MONTH_JUL - 1] = 31,
[MONTH_AUG - 1] = 31,
[MONTH_SEP - 1] = 30,
[MONTH_OCT - 1] = 31,
[MONTH_NOV - 1] = 30,
[MONTH_DEC - 1] = 31,
};

void RtcDisableInterrupts(void)
Expand Down Expand Up @@ -171,7 +171,7 @@ u16 RtcCheckInfo(struct SiiRtcInfo *rtc)

month = ConvertBcdToBinary(rtc->month);

if (month == 0xFF || month == 0 || month > 12)
if (month == 0xFF || month == 0 || month > MONTH_COUNT)
errorFlags |= RTC_ERR_INVALID_MONTH;

value = ConvertBcdToBinary(rtc->day);
Expand All @@ -192,17 +192,17 @@ u16 RtcCheckInfo(struct SiiRtcInfo *rtc)

value = ConvertBcdToBinary(rtc->hour);

if (value > 24)
if (value > DAY_HOURS)
errorFlags |= RTC_ERR_INVALID_HOUR;

value = ConvertBcdToBinary(rtc->minute);

if (value > 60)
if (value > HOUR_MINUTES)
errorFlags |= RTC_ERR_INVALID_MINUTE;

value = ConvertBcdToBinary(rtc->second);

if (value > 60)
if (value > MINUTE_SECONDS)
errorFlags |= RTC_ERR_INVALID_SECOND;

return errorFlags;
Expand Down Expand Up @@ -270,19 +270,19 @@ void RtcCalcTimeDifference(struct SiiRtcInfo *rtc, struct Time *result, struct T

if (result->seconds < 0)
{
result->seconds += 60;
result->seconds += MINUTE_SECONDS;
--result->minutes;
}

if (result->minutes < 0)
{
result->minutes += 60;
result->minutes += HOUR_MINUTES;
--result->hours;
}

if (result->hours < 0)
{
result->hours += 24;
result->hours += DAY_HOURS;
--result->days;
}
}
Expand Down Expand Up @@ -317,27 +317,27 @@ void CalcTimeDifference(struct Time *result, struct Time *t1, struct Time *t2)

if (result->seconds < 0)
{
result->seconds += 60;
result->seconds += MINUTE_SECONDS;
--result->minutes;
}

if (result->minutes < 0)
{
result->minutes += 60;
result->minutes += HOUR_MINUTES;
--result->hours;
}

if (result->hours < 0)
{
result->hours += 24;
result->hours += DAY_HOURS;
--result->days;
}
}

u32 RtcGetMinuteCount(void)
{
RtcGetInfo(&sRtc);
return (24 * 60) * RtcGetDayCount(&sRtc) + 60 * sRtc.hour + sRtc.minute;
return (DAY_HOURS * HOUR_MINUTES) * RtcGetDayCount(&sRtc) + HOUR_MINUTES * sRtc.hour + sRtc.minute;
}

u32 RtcGetLocalDayCount(void)
Expand Down