From b53c913558c5c454922a29c12cd864822b5da3dc Mon Sep 17 00:00:00 2001 From: Bassoonian Date: Sat, 29 Apr 2023 18:16:36 +0200 Subject: [PATCH] Manually port daycare expansion to modern standards --- include/config/pokemon.h | 13 +++-- src/daycare.c | 108 ++++++++++++++++++++++++++------------- 2 files changed, 82 insertions(+), 39 deletions(-) diff --git a/include/config/pokemon.h b/include/config/pokemon.h index 1cde573c9..624721746 100644 --- a/include/config/pokemon.h +++ b/include/config/pokemon.h @@ -8,10 +8,15 @@ #define P_UPDATED_EGG_GROUPS GEN_LATEST // Since Gen 8, certain Pokémon have gained new egg groups. // Breeding settings -#define P_NIDORAN_M_DITTO_BREED GEN_LATEST // Since Gen 5, when Nidoran♂ breeds with Ditto it can produce Nidoran♀ offspring. Before, it would only yield male offspring. This change also applies to Volbeat. -#define P_INCENSE_BREEDING GEN_LATEST // Since Gen 9, cross-generation Baby Pokémon don't require Incense being held by the parents to be obtained via breeding. -#define P_EGG_HATCH_LEVEL GEN_LATEST // Since Gen 4, Pokémon will hatch from eggs at level 1 instead of 5. -#define P_BALL_INHERITING GEN_LATEST // Since Gen 6, Eggs from the Daycare will inherit the Poké Ball from their mother. From Gen7 onwards, the father can pass it down as well, as long as it's of the same species as the mother. +#define P_NIDORAN_M_DITTO_BREED GEN_LATEST // Since Gen 5, when Nidoran♂ breeds with Ditto it can produce Nidoran♀ offspring. Before, it would only yield male offspring. This change also applies to Volbeat. +#define P_INCENSE_BREEDING GEN_LATEST // Since Gen 9, cross-generation Baby Pokémon don't require Incense being held by the parents to be obtained via breeding. +#define P_EGG_HATCH_LEVEL GEN_LATEST // Since Gen 4, Pokémon will hatch from eggs at level 1 instead of 5. +#define P_BALL_INHERITING GEN_LATEST // Since Gen 6, Eggs from the Daycare will inherit the Poké Ball from their mother. From Gen 7 onwards, the father can pass it down as well, as long as it's of the same species as the mother. +#define P_TM_INHERITANCE GEN_LATEST // Since Gen 6, the father no longer passes down TMs to the baby. +#define P_MOTHER_EGG_MOVE_INHERITANCE GEN_LATEST // Since Gen 6, the mother can also pass down Egg Moves. +#define P_NATURE_INHERITANCE GEN_LATEST // In Gen 3, Everstone grants Ditto and mothers a 50% chance to pass on Nature. Since Gen 4, anyone can pass on nature. Since Gen 5, the chance is 100%. +#define P_ABILITY_INHERITANCE GEN_LATEST // TODO: In B2W2, a female Pokémon has an 80% chance of passing down their ability if bred with a male. Since Gen 6, the chance is 80% for normal ability and 60% for Hidden Ability, and anyone can pass down their abilities if bred with Ditto. NOTE: BW's effect: 60% chance to pass down HA and random for normal ability has been omitted. +#define P_EGG_MOVE_TRANSFER GEN_LATEST // TODO: Starting in Gen 8, if two Pokémon of the same species are together in the Daycare, one knows an Egg Move, and the other has an empty slot, the other Pokémon will receive the Egg Move in the empty slot. // Species-specific settings #define P_SHEDINJA_BALL GEN_LATEST // Since Gen 4, Shedinja requires a Poké Ball for its evolution. In Gen 3, Shedinja inherits Nincada's Ball. diff --git a/src/daycare.c b/src/daycare.c index 803c0cacf..3feabe9ba 100644 --- a/src/daycare.c +++ b/src/daycare.c @@ -21,11 +21,14 @@ #include "overworld.h" #include "item.h" #include "constants/items.h" +#include "constants/hold_effects.h" #include "constants/moves.h" #include "constants/region_map_sections.h" extern const struct Evolution gEvolutionTable[][EVOS_PER_MON]; +#define IS_DITTO(species) (gBaseStats[species].eggGroup1 == EGG_GROUP_DITTO || gBaseStats[species].eggGroup2 == EGG_GROUP_DITTO) + static void ClearDaycareMonMail(struct DaycareMail *mail); static void SetInitialEggData(struct Pokemon *mon, u16 species, struct DayCare *daycare); static u8 GetDaycareCompatibilityScore(struct DayCare *daycare); @@ -425,43 +428,29 @@ static u16 GetEggSpecies(u16 species) static s32 GetParentToInheritNature(struct DayCare *daycare) { - u32 species[DAYCARE_MON_COUNT]; - s32 i; - s32 dittoCount; - s32 parent = -1; + u32 i; + u8 numWithEverstone = 0; + s32 slot = -1; - // search for female gender for (i = 0; i < DAYCARE_MON_COUNT; i++) { - if (GetBoxMonGender(&daycare->mons[i].mon) == MON_FEMALE) - parent = i; + if (ItemId_GetHoldEffect(GetBoxMonData(&daycare->mons[i].mon, MON_DATA_HELD_ITEM)) == HOLD_EFFECT_PREVENT_EVOLVE + #if P_NATURE_INHERITANCE == GEN_3 + && (GetBoxMonGender(&daycare->mons[i].mon) == MON_FEMALE || IS_DITTO(GetBoxMonData(&daycare->mons[i].mon, MON_DATA_SPECIES))) + #endif + ) { + slot = i; + numWithEverstone++; + } } - // search for ditto - for (dittoCount = 0, i = 0; i < DAYCARE_MON_COUNT; i++) - { - species[i] = GetBoxMonData(&daycare->mons[i].mon, MON_DATA_SPECIES); - if (species[i] == SPECIES_DITTO) - dittoCount++, parent = i; - } - - // coin flip on ...two Dittos - if (dittoCount == DAYCARE_MON_COUNT) - { - if (Random() >= USHRT_MAX / 2) - parent = 0; - else - parent = 1; - } - - // Don't inherit nature if not holding Everstone - if (GetBoxMonData(&daycare->mons[parent].mon, MON_DATA_HELD_ITEM) != ITEM_EVERSTONE - || Random() >= USHRT_MAX / 2) - { - return -1; - } - - return parent; + if (numWithEverstone >= DAYCARE_MON_COUNT) + return Random() & 1; +#if P_NATURE_INHERITANCE > GEN_4 + return slot; +#else + return Random() & 1 ? slot : -1; +#endif } static void _TriggerPendingDaycareEgg(struct DayCare *daycare) @@ -541,7 +530,7 @@ static void InheritIVs(struct Pokemon *egg, struct DayCare *daycare) { u16 motherItem = GetBoxMonData(&daycare->mons[0].mon, MON_DATA_HELD_ITEM); u16 fatherItem = GetBoxMonData(&daycare->mons[1].mon, MON_DATA_HELD_ITEM); - u8 i; + u8 i, start; u8 selectedIvs[5]; u8 availableIVs[NUM_STATS]; u8 whichParents[5]; @@ -557,8 +546,33 @@ static void InheritIVs(struct Pokemon *egg, struct DayCare *daycare) availableIVs[i] = i; } + start = 0; + if (ItemId_GetHoldEffect(motherItem) == HOLD_EFFECT_POWER_ITEM && + ItemId_GetHoldEffect(fatherItem) == HOLD_EFFECT_POWER_ITEM) + { + whichParents[0] = Random() % DAYCARE_MON_COUNT; + selectedIvs[0] = ItemId_GetSecondaryId( + GetBoxMonData(&daycare->mons[whichParents[0]].mon, MON_DATA_HELD_ITEM)); + RemoveIVIndexFromList(availableIVs, selectedIvs[0]); + start++; + } + else if (ItemId_GetHoldEffect(motherItem) == HOLD_EFFECT_POWER_ITEM) + { + whichParents[0] = 0; + selectedIvs[0] = ItemId_GetSecondaryId(motherItem); + RemoveIVIndexFromList(availableIVs, selectedIvs[0]); + start++; + } + else if (ItemId_GetHoldEffect(fatherItem) == HOLD_EFFECT_POWER_ITEM) + { + whichParents[0] = 1; + selectedIvs[0] = ItemId_GetSecondaryId(fatherItem); + RemoveIVIndexFromList(availableIVs, selectedIvs[0]); + start++; + } + // Select which IVs that will be inherited. - for (i = 0; i < howManyIVs; i++) + for (i = start; i < howManyIVs; i++) { // Randomly pick an IV from the available list and stop from being chosen again. // BUG: Instead of removing the IV that was just picked, this @@ -577,7 +591,7 @@ static void InheritIVs(struct Pokemon *egg, struct DayCare *daycare) } // Determine which parent each of the selected IVs should inherit from. - for (i = 0; i < howManyIVs; i++) + for (i = start; i < howManyIVs; i++) { whichParents[i] = Random() % DAYCARE_MON_COUNT; } @@ -703,6 +717,28 @@ static void BuildEggMoveset(struct Pokemon *egg, struct BoxPokemon *father, stru numEggMoves = GetEggMoves(egg, sHatchedEggEggMoves); +#if P_MOTHER_EGG_MOVE_INHERITANCE >= GEN_6 + for (i = 0; i < MAX_MON_MOVES; i++) + { + if (sHatchedEggMotherMoves[i] != MOVE_NONE) + { + for (j = 0; j < numEggMoves; j++) + { + if (sHatchedEggMotherMoves[i] == sHatchedEggEggMoves[j]) + { + if (GiveMoveToMon(egg, sHatchedEggMotherMoves[i]) == MON_HAS_MAX_MOVES) + DeleteFirstMoveAndGiveMoveToMon(egg, sHatchedEggMotherMoves[i]); + break; + } + } + } + else + { + break; + } + } +#endif + for (i = 0; i < MAX_MON_MOVES; i++) { if (sHatchedEggFatherMoves[i] != MOVE_NONE) @@ -722,6 +758,7 @@ static void BuildEggMoveset(struct Pokemon *egg, struct BoxPokemon *father, stru break; } } +#if P_TM_INHERITANCE < GEN_6 for (i = 0; i < MAX_MON_MOVES; i++) { if (sHatchedEggFatherMoves[i] != MOVE_NONE) @@ -737,6 +774,7 @@ static void BuildEggMoveset(struct Pokemon *egg, struct BoxPokemon *father, stru } } } +#endif for (i = 0; i < MAX_MON_MOVES; i++) { if (sHatchedEggFatherMoves[i] == MOVE_NONE)