diff --git a/include/pokemon.h b/include/pokemon.h index 0d27d5cb1b..40de3f023e 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -911,7 +911,7 @@ const u8 *GetMoveAnimationScript(u16 moveId); void UpdateDaysPassedSinceFormChange(u16 days); void TrySetDayLimitToFormChange(struct Pokemon *mon); u32 CheckDynamicMoveType(struct Pokemon *mon, u32 move, u32 battler); -u16 GetRegionalForm(u32 species, u32 region); +u32 GetRegionalForm(u32 species, u32 region); bool32 IsSpeciesForeignRegionalForm(u32 species, u32 currentRegion); #endif // GUARD_POKEMON_H diff --git a/src/daycare.c b/src/daycare.c index 2fdbe3c7ef..d479954aa0 100644 --- a/src/daycare.c +++ b/src/daycare.c @@ -1002,8 +1002,8 @@ static u16 DetermineEggSpeciesAndParentSlots(struct DayCare *daycare, u8 *parent motherEggSpecies = GetEggSpecies(species[parentSlots[0]]); fatherEggSpecies = GetEggSpecies(species[parentSlots[1]]); - hasMotherEverstone = ItemId_GetHoldEffect(GetBoxMonData(&daycare->mons[0].mon, MON_DATA_HELD_ITEM)) == HOLD_EFFECT_PREVENT_EVOLVE; - hasFatherEverstone = ItemId_GetHoldEffect(GetBoxMonData(&daycare->mons[1].mon, MON_DATA_HELD_ITEM)) == HOLD_EFFECT_PREVENT_EVOLVE; + 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); diff --git a/src/pokemon.c b/src/pokemon.c index ab6a397be7..ac54593407 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -6979,22 +6979,29 @@ u32 CheckDynamicMoveType(struct Pokemon *mon, u32 move, u32 battler) return gMovesInfo[move].type; } -u16 GetRegionalForm(u32 species, u32 region) +u32 GetRegionalForm(u32 species, u32 region) { u32 formId = 0; - u32 foundSpecies = 0; + u32 firstFoundSpecies = 0; + const u16 *formTable = GetSpeciesFormTable(species); - if (GetSpeciesFormTable(species) != NULL) + if (formTable != NULL) { - for (formId = 0; GetSpeciesFormTable(species)[formId] != FORM_SPECIES_END; formId++) + for (formId = 0; formTable[formId] != FORM_SPECIES_END; formId++) { - foundSpecies = GetSpeciesFormTable(species)[formId]; - if ((gSpeciesInfo[foundSpecies].isAlolanForm && region == REGION_ALOLA) - || (gSpeciesInfo[foundSpecies].isGalarianForm && region == REGION_GALAR) - || (gSpeciesInfo[foundSpecies].isHisuianForm && region == REGION_HISUI) - || (gSpeciesInfo[foundSpecies].isPaldeanForm && region == REGION_PALDEA)) - return foundSpecies; + if (firstFoundSpecies == 0) + firstFoundSpecies = formTable[formId]; + + if ((gSpeciesInfo[formTable[formId]].isAlolanForm && region == REGION_ALOLA) + || (gSpeciesInfo[formTable[formId]].isGalarianForm && region == REGION_GALAR) + || (gSpeciesInfo[formTable[formId]].isHisuianForm && region == REGION_HISUI) + || (gSpeciesInfo[formTable[formId]].isPaldeanForm && region == REGION_PALDEA)) + { + return formTable[formId]; + } } + if (firstFoundSpecies != 0) + return firstFoundSpecies; } return species; } diff --git a/test/daycare.c b/test/daycare.c index 20af0fb501..7dc6a6d789 100644 --- a/test/daycare.c +++ b/test/daycare.c @@ -64,3 +64,26 @@ TEST("Daycare Pokémon can breed with Ditto if they don't belong to the Ditto or EXPECT_EQ(GetMonData(&gPlayerParty[0], MON_DATA_SPECIES), SPECIES_NONE); } + +TEST("Daycare Pokémon with regional forms give the correct offspring") +{ + u32 offspring = 0; + ASSUME(P_FAMILY_MEOWTH == TRUE); + ASSUME(P_ALOLAN_FORMS == TRUE); + ASSUME(P_GALARIAN_FORMS == TRUE); + ASSUME(REGION_CURRENT == 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;); } + PARAMETRIZE { offspring = SPECIES_MEOWTH_ALOLA; RUN_OVERWORLD_SCRIPT(givemon SPECIES_MEOWTH, 1, gender=MON_MALE; givemon SPECIES_MEOWTH_ALOLA, 1, gender=MON_FEMALE, item=ITEM_EVERSTONE;); } + PARAMETRIZE { offspring = SPECIES_MEOWTH; RUN_OVERWORLD_SCRIPT(givemon SPECIES_MEOWTH, 1, gender=MON_MALE; givemon SPECIES_MEOWTH_GALAR, 1, gender=MON_FEMALE;); } + PARAMETRIZE { offspring = SPECIES_MEOWTH_GALAR; RUN_OVERWORLD_SCRIPT(givemon SPECIES_MEOWTH, 1, gender=MON_MALE; givemon SPECIES_MEOWTH_GALAR, 1, gender=MON_FEMALE, item=ITEM_EVERSTONE;); } + // Cases provided by cawtds + PARAMETRIZE { offspring = SPECIES_MEOWTH; RUN_OVERWORLD_SCRIPT(givemon SPECIES_DIGLETT, 1, gender=MON_MALE; givemon SPECIES_MEOWTH_GALAR, 1, gender=MON_FEMALE;); } + PARAMETRIZE { offspring = SPECIES_MEOWTH_GALAR; RUN_OVERWORLD_SCRIPT(givemon SPECIES_DIGLETT, 1, gender=MON_MALE; givemon SPECIES_MEOWTH_GALAR, 1, gender=MON_FEMALE, item=ITEM_EVERSTONE;); } + PARAMETRIZE { offspring = SPECIES_MEOWTH_GALAR; RUN_OVERWORLD_SCRIPT(givemon SPECIES_PERRSERKER, 1, gender=MON_MALE, item=ITEM_EVERSTONE; givemon SPECIES_PERSIAN, 1, gender=MON_FEMALE;); } + //PARAMETRIZE { offspring = SPECIES_MEOWTH; RUN_OVERWORLD_SCRIPT(givemon SPECIES_PERRSERKER, 1, gender=MON_MALE, item=ITEM_EVERSTONE; givemon SPECIES_PERSIAN, 1, gender=MON_FEMALE, item=ITEM_EVERSTONE;); } + STORE_IN_DAYCARE_AND_GET_EGG(); + + EXPECT_EQ(GetMonData(&gPlayerParty[0], MON_DATA_SPECIES), offspring); +}