From bcccbaf073435573b832f2eeb0d57f0731839c9d Mon Sep 17 00:00:00 2001 From: Eduardo Quezada Date: Tue, 31 Dec 2024 17:14:01 -0300 Subject: [PATCH] REGION_CURRENT to inline function --- include/constants/regions.h | 3 --- include/regions.h | 12 ++++++++++++ src/daycare.c | 14 ++++++++------ test/daycare.c | 3 ++- 4 files changed, 22 insertions(+), 10 deletions(-) create mode 100644 include/regions.h diff --git a/include/constants/regions.h b/include/constants/regions.h index 9e2122b9ea9b..c81ecc5eac23 100644 --- a/include/constants/regions.h +++ b/include/constants/regions.h @@ -17,7 +17,4 @@ enum Region REGION_COUNT, }; -// TODO: Since there's no current multi-region support, we have this constant for the purposes of regional form comparisons. -#define REGION_CURRENT REGION_HOENN - #endif // GUARD_CONSTANTS_REGIONS_H diff --git a/include/regions.h b/include/regions.h new file mode 100644 index 000000000000..2f44896ea2b0 --- /dev/null +++ b/include/regions.h @@ -0,0 +1,12 @@ +#ifndef GUARD_REGIONS_H +#define GUARD_REGIONS_H + +#include "constants/regions.h" + +static inline u32 GetCurrentRegion(void) +{ + // TODO: Since there's no current multi-region support, we have this constant for the purposes of regional form comparisons. + return REGION_HOENN; +} + +#endif // GUARD_REGIONS_H diff --git a/src/daycare.c b/src/daycare.c index 7f154b96eceb..1bdca7119385 100644 --- a/src/daycare.c +++ b/src/daycare.c @@ -21,6 +21,7 @@ #include "list_menu.h" #include "overworld.h" #include "item.h" +#include "regions.h" #include "constants/form_change_types.h" #include "constants/items.h" #include "constants/hold_effects.h" @@ -979,11 +980,12 @@ STATIC_ASSERT(P_SCATTERBUG_LINE_FORM_BREED == SPECIES_SCATTERBUG_ICY_SNOW || (P_ static u16 DetermineEggSpeciesAndParentSlots(struct DayCare *daycare, u8 *parentSlots) { - u16 i; - u16 species[DAYCARE_MON_COUNT]; - u16 eggSpecies, parentSpecies; + u32 i; + u32 species[DAYCARE_MON_COUNT]; + u32 eggSpecies, parentSpecies; bool32 hasMotherEverstone, hasFatherEverstone, motherIsForeign, fatherIsForeign; bool32 motherEggSpecies, fatherEggSpecies; + u32 currentRegion = GetCurrentRegion(); for (i = 0; i < DAYCARE_MON_COUNT; i++) { @@ -1004,15 +1006,15 @@ static u16 DetermineEggSpeciesAndParentSlots(struct DayCare *daycare, u8 *parent fatherEggSpecies = GetEggSpecies(species[parentSlots[1]]); hasMotherEverstone = ItemId_GetHoldEffect(GetBoxMonData(&daycare->mons[parentSlots[0]].mon, MON_DATA_HELD_ITEM)) == HOLD_EFFECT_PREVENT_EVOLVE; hasFatherEverstone = ItemId_GetHoldEffect(GetBoxMonData(&daycare->mons[parentSlots[1]].mon, MON_DATA_HELD_ITEM)) == HOLD_EFFECT_PREVENT_EVOLVE; - motherIsForeign = IsSpeciesForeignRegionalForm(motherEggSpecies, REGION_CURRENT); - fatherIsForeign = IsSpeciesForeignRegionalForm(fatherEggSpecies, REGION_CURRENT); + motherIsForeign = IsSpeciesForeignRegionalForm(motherEggSpecies, currentRegion); + fatherIsForeign = IsSpeciesForeignRegionalForm(fatherEggSpecies, currentRegion); if (hasMotherEverstone) parentSpecies = motherEggSpecies; else if (fatherIsForeign && hasFatherEverstone) parentSpecies = fatherEggSpecies; else if (motherIsForeign) - parentSpecies = GetRegionalForm(motherEggSpecies, REGION_CURRENT); + parentSpecies = GetRegionalForm(motherEggSpecies, currentRegion); else parentSpecies = motherEggSpecies; diff --git a/test/daycare.c b/test/daycare.c index 19957e7ba700..c03a9191992b 100644 --- a/test/daycare.c +++ b/test/daycare.c @@ -3,6 +3,7 @@ #include "event_data.h" #include "malloc.h" #include "party_menu.h" +#include "regions.h" #include "test/overworld_script.h" #include "test/test.h" @@ -71,7 +72,7 @@ TEST("Daycare Pokémon with regional forms give the correct offspring") ASSUME(P_FAMILY_MEOWTH == TRUE); ASSUME(P_ALOLAN_FORMS == TRUE); ASSUME(P_GALARIAN_FORMS == TRUE); - ASSUME(REGION_CURRENT == REGION_HOENN); + ASSUME(GetCurrentRegion() == REGION_HOENN); ZeroPlayerPartyMons(); PARAMETRIZE { offspring = SPECIES_MEOWTH; RUN_OVERWORLD_SCRIPT(givemon SPECIES_MEOWTH, 1, gender=MON_MALE; givemon SPECIES_MEOWTH_ALOLA, 1, gender=MON_FEMALE;); }