Made function for time-based evolutions (#3369)

* Made function for time-based evolutions

* Incorporated Edu's comments and time variables

* Moved time of day begin/end variables to rtc.h

* Fixed if/else statement to pass building with modern

* Added morning

* Added ability to check if end time > beginning time

* Updated times to match SwSh

---------

Co-authored-by: Bassoonian <iasperbassoonian@gmail.com>
This commit is contained in:
Frank DeBlasio 2023-11-18 10:53:56 -05:00 committed by GitHub
parent 5fa1bffa8d
commit 42076897d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 31 deletions

View file

@ -17,6 +17,23 @@
#define RTC_ERR_FLAG_MASK 0x0FF0
#define MORNING_EVO_HOUR_BEGIN 6
#define MORNING_EVO_HOUR_END 10
#define DAY_EVO_HOUR_BEGIN 10
#define DAY_EVO_HOUR_END 19
#define DUSK_EVO_HOUR_BEGIN 19
#define DUSK_EVO_HOUR_END 20
#define NIGHT_EVO_HOUR_BEGIN 20
#define NIGHT_EVO_HOUR_END 6
#define TIME_MORNING 0
#define TIME_DAY 1
#define TIME_DUSK 2
#define TIME_NIGHT 3
extern struct Time gLocalTime;
void RtcDisableInterrupts(void);
@ -40,6 +57,8 @@ void FormatDecimalDate(u8 *dest, s32 year, s32 month, s32 day);
void FormatHexDate(u8 *dest, s32 year, s32 month, s32 day);
void RtcCalcTimeDifference(struct SiiRtcInfo *rtc, struct Time *result, struct Time *t);
void RtcCalcLocalTime(void);
bool8 IsBetweenHours(s32 hours, s32 begin, s32 end);
u8 GetTimeOfDay(void);
void RtcInitLocalTimeOffset(s32 hour, s32 minute);
void RtcCalcLocalTimeOffset(s32 days, s32 hours, s32 minutes, s32 seconds);
void CalcTimeDifference(struct Time *result, struct Time *t1, struct Time *t2);

View file

@ -53,15 +53,6 @@
#include "constants/union_room.h"
#include "constants/weather.h"
#define DAY_EVO_HOUR_BEGIN 12
#define DAY_EVO_HOUR_END HOURS_PER_DAY
#define DUSK_EVO_HOUR_BEGIN 17
#define DUSK_EVO_HOUR_END 18
#define NIGHT_EVO_HOUR_BEGIN 0
#define NIGHT_EVO_HOUR_END 12
#if P_FRIENDSHIP_EVO_THRESHOLD >= GEN_9
#define FRIENDSHIP_EVO_THRESHOLD 160
#else
@ -7053,28 +7044,23 @@ u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 mode, u16 evolutionItem, s
targetSpecies = gEvolutionTable[species][i].targetSpecies;
break;
case EVO_FRIENDSHIP_DAY:
RtcCalcLocalTime();
if (gLocalTime.hours >= DAY_EVO_HOUR_BEGIN && gLocalTime.hours < DAY_EVO_HOUR_END && friendship >= FRIENDSHIP_EVO_THRESHOLD)
if (GetTimeOfDay() != TIME_NIGHT && friendship >= FRIENDSHIP_EVO_THRESHOLD)
targetSpecies = gEvolutionTable[species][i].targetSpecies;
break;
case EVO_LEVEL_DAY:
RtcCalcLocalTime();
if (gLocalTime.hours >= DAY_EVO_HOUR_BEGIN && gLocalTime.hours < DAY_EVO_HOUR_END && gEvolutionTable[species][i].param <= level)
if (GetTimeOfDay() != TIME_NIGHT && gEvolutionTable[species][i].param <= level)
targetSpecies = gEvolutionTable[species][i].targetSpecies;
break;
case EVO_FRIENDSHIP_NIGHT:
RtcCalcLocalTime();
if (gLocalTime.hours >= NIGHT_EVO_HOUR_BEGIN && gLocalTime.hours < NIGHT_EVO_HOUR_END && friendship >= FRIENDSHIP_EVO_THRESHOLD)
if (GetTimeOfDay() == TIME_NIGHT && friendship >= FRIENDSHIP_EVO_THRESHOLD)
targetSpecies = gEvolutionTable[species][i].targetSpecies;
break;
case EVO_LEVEL_NIGHT:
RtcCalcLocalTime();
if (gLocalTime.hours >= NIGHT_EVO_HOUR_BEGIN && gLocalTime.hours < NIGHT_EVO_HOUR_END && gEvolutionTable[species][i].param <= level)
if (GetTimeOfDay() == TIME_NIGHT && gEvolutionTable[species][i].param <= level)
targetSpecies = gEvolutionTable[species][i].targetSpecies;
break;
case EVO_ITEM_HOLD_NIGHT:
RtcCalcLocalTime();
if (gLocalTime.hours >= NIGHT_EVO_HOUR_BEGIN && gLocalTime.hours < NIGHT_EVO_HOUR_END && heldItem == gEvolutionTable[species][i].param)
if (GetTimeOfDay() == TIME_NIGHT && heldItem == gEvolutionTable[species][i].param)
{
heldItem = ITEM_NONE;
SetMonData(mon, MON_DATA_HELD_ITEM, &heldItem);
@ -7082,8 +7068,7 @@ u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 mode, u16 evolutionItem, s
}
break;
case EVO_ITEM_HOLD_DAY:
RtcCalcLocalTime();
if (gLocalTime.hours >= DAY_EVO_HOUR_BEGIN && gLocalTime.hours < DAY_EVO_HOUR_END && heldItem == gEvolutionTable[species][i].param)
if (GetTimeOfDay() != TIME_NIGHT && heldItem == gEvolutionTable[species][i].param)
{
heldItem = ITEM_NONE;
SetMonData(mon, MON_DATA_HELD_ITEM, &heldItem);
@ -7091,8 +7076,7 @@ u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 mode, u16 evolutionItem, s
}
break;
case EVO_LEVEL_DUSK:
RtcCalcLocalTime();
if (gLocalTime.hours >= DUSK_EVO_HOUR_BEGIN && gLocalTime.hours < DUSK_EVO_HOUR_END && gEvolutionTable[species][i].param <= level)
if (GetTimeOfDay() == TIME_DUSK && gEvolutionTable[species][i].param <= level)
targetSpecies = gEvolutionTable[species][i].targetSpecies;
break;
case EVO_LEVEL:
@ -7317,13 +7301,11 @@ u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 mode, u16 evolutionItem, s
targetSpecies = gEvolutionTable[species][i].targetSpecies;
break;
case EVO_ITEM_NIGHT:
RtcCalcLocalTime();
if (gLocalTime.hours >= NIGHT_EVO_HOUR_BEGIN && gLocalTime.hours < NIGHT_EVO_HOUR_END && gEvolutionTable[species][i].param == evolutionItem)
if (GetTimeOfDay() == TIME_NIGHT && gEvolutionTable[species][i].param == evolutionItem)
targetSpecies = gEvolutionTable[species][i].targetSpecies;
break;
case EVO_ITEM_DAY:
RtcCalcLocalTime();
if (gLocalTime.hours >= DAY_EVO_HOUR_BEGIN && gLocalTime.hours < DAY_EVO_HOUR_END && gEvolutionTable[species][i].param == evolutionItem)
if (GetTimeOfDay() != TIME_NIGHT && gEvolutionTable[species][i].param == evolutionItem)
targetSpecies = gEvolutionTable[species][i].targetSpecies;
break;
}
@ -9049,13 +9031,11 @@ u16 GetFormChangeTargetSpeciesBoxMon(struct BoxPokemon *boxMon, u16 method, u32
switch (formChanges[i].param2)
{
case DAY:
RtcCalcLocalTime();
if (gLocalTime.hours >= DAY_EVO_HOUR_BEGIN && gLocalTime.hours < DAY_EVO_HOUR_END)
if (GetTimeOfDay() != TIME_NIGHT)
targetSpecies = formChanges[i].targetSpecies;
break;
case NIGHT:
RtcCalcLocalTime();
if (gLocalTime.hours >= NIGHT_EVO_HOUR_BEGIN && gLocalTime.hours < NIGHT_EVO_HOUR_END)
if (GetTimeOfDay() == TIME_NIGHT)
targetSpecies = formChanges[i].targetSpecies;
break;
default:

View file

@ -293,6 +293,27 @@ void RtcCalcLocalTime(void)
RtcCalcTimeDifference(&sRtc, &gLocalTime, &gSaveBlock2Ptr->localTimeOffset);
}
bool8 IsBetweenHours(s32 hours, s32 begin, s32 end)
{
if (end < begin)
return hours > begin || hours < end;
else
return hours >= begin && hours < end;
}
u8 GetTimeOfDay(void)
{
RtcCalcLocalTime();
if (IsBetweenHours(gLocalTime.hours, MORNING_EVO_HOUR_BEGIN, MORNING_EVO_HOUR_END))
return TIME_MORNING;
else if (IsBetweenHours(gLocalTime.hours, DUSK_EVO_HOUR_BEGIN, DUSK_EVO_HOUR_END))
return TIME_DUSK;
else if (IsBetweenHours(gLocalTime.hours, NIGHT_EVO_HOUR_BEGIN, NIGHT_EVO_HOUR_END))
return TIME_NIGHT;
else
return TIME_DAY;
}
void RtcInitLocalTimeOffset(s32 hour, s32 minute)
{
RtcCalcLocalTimeOffset(0, hour, minute, 0);