From 1b0ce96e12f876821333f43ce555552e0ff3f65d Mon Sep 17 00:00:00 2001 From: Eduardo Quezada Date: Mon, 9 Jan 2023 02:16:29 -0300 Subject: [PATCH] Config for ball inheritence when breeding --- include/config/pokemon.h | 1 + src/daycare.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/config/pokemon.h b/include/config/pokemon.h index a44a7c8e0a..f406da7e0f 100644 --- a/include/config/pokemon.h +++ b/include/config/pokemon.h @@ -11,6 +11,7 @@ #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 evolution family as the offspring. // Other 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 06f11ba9cf..08ca31da0c 100644 --- a/src/daycare.c +++ b/src/daycare.c @@ -609,6 +609,33 @@ static void InheritIVs(struct Pokemon *egg, struct DayCare *daycare) } } +static void InheritPokeball(struct Pokemon *egg, struct BoxPokemon *father, struct BoxPokemon *mother) +{ + u16 inheritBall = ITEM_POKE_BALL; + u16 fatherBall = GetBoxMonData(father, MON_DATA_POKEBALL); + u16 motherBall = GetBoxMonData(mother, MON_DATA_POKEBALL); + u16 fatherSpecies = GetBoxMonData(father, MON_DATA_SPECIES); + u16 motherSpecies = GetBoxMonData(mother, MON_DATA_SPECIES); + + if (fatherBall == ITEM_MASTER_BALL || fatherBall == ITEM_CHERISH_BALL) + fatherBall = ITEM_POKE_BALL; + + if (motherBall == ITEM_MASTER_BALL || motherBall == ITEM_CHERISH_BALL) + motherBall = ITEM_POKE_BALL; + +#if P_BALL_INHERITING >= GEN_7 + if (fatherSpecies == motherSpecies) + inheritBall = (Random32() % 2 == 0 ? motherBall : fatherBall); + else if (motherSpecies != SPECIES_DITTO) + inheritBall = motherBall; + else + inheritBall = fatherBall; +#elif P_BALL_INHERITING == GEN_6 + inheritBall = motherBall; +#endif + SetMonData(egg, MON_DATA_POKEBALL, &inheritBall); +} + // Counts the number of egg moves a pokemon learns and stores the moves in // the given array. static u8 GetEggMoves(struct Pokemon *pokemon, u16 *eggMoves) @@ -872,6 +899,7 @@ static void _GiveEggFromDaycare(struct DayCare *daycare) #endif SetInitialEggData(&egg, species, daycare); InheritIVs(&egg, daycare); + InheritPokeball(&egg, &daycare->mons[parentSlots[1]].mon, &daycare->mons[parentSlots[0]].mon); BuildEggMoveset(&egg, &daycare->mons[parentSlots[1]].mon, &daycare->mons[parentSlots[0]].mon); GiveMoveIfItem(&egg, daycare);