From 8f75844ece7546df6b06db53302685f458c1f8b9 Mon Sep 17 00:00:00 2001 From: Bassoonian Date: Sun, 30 Apr 2023 12:58:18 +0200 Subject: [PATCH] Add Ability inheritance --- include/config/pokemon.h | 2 +- src/daycare.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/include/config/pokemon.h b/include/config/pokemon.h index d6e239515..a65eddb73 100644 --- a/include/config/pokemon.h +++ b/include/config/pokemon.h @@ -15,7 +15,7 @@ #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_ABILITY_INHERITANCE GEN_LATEST // 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 // 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. In Gen 9, if a Pokémon holds a Mirror Herb, it will receive Egg Moves from the other regardless of species. // Species-specific settings diff --git a/src/daycare.c b/src/daycare.c index 2997578d5..08b9ec23f 100644 --- a/src/daycare.c +++ b/src/daycare.c @@ -712,6 +712,35 @@ static void InheritPokeball(struct Pokemon *egg, struct BoxPokemon *father, stru SetMonData(egg, MON_DATA_POKEBALL, &inheritBall); } +static void InheritAbility(struct Pokemon *egg, struct BoxPokemon *father, struct BoxPokemon *mother) +{ + u8 fatherAbility = GetBoxMonData(father, MON_DATA_ABILITY_NUM); + u8 motherAbility = GetBoxMonData(mother, MON_DATA_ABILITY_NUM); + u8 motherSpecies = GetBoxMonData(mother, MON_DATA_SPECIES); + u8 inheritAbility = motherAbility; + + if (motherSpecies == SPECIES_DITTO) + #if P_ABILITY_INHERITANCE < GEN_6 + return; + #else + inheritAbility = fatherAbility; + #endif + + if (inheritAbility < 2 && (Random() % 10 < 8)) + { + SetMonData(egg, MON_DATA_ABILITY_NUM, &inheritAbility); + } +#if P_ABILITY_INHERITANCE < GEN_6 + else if (Random() % 10 < 8) +#else + else if (Random() % 10 < 6) +#endif + { + // Hidden Abilities have a different chance of being passed down + SetMonData(egg, MON_DATA_ABILITY_NUM, &inheritAbility); + } +} + // 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) @@ -1000,6 +1029,9 @@ static void _GiveEggFromDaycare(struct DayCare *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); +#if P_ABILITY_INHERITANCE >= GEN_8 + InheritAbility(&egg, &daycare->mons[parentSlots[1]].mon, &daycare->mons[parentSlots[0]].mon); +#endif GiveMoveIfItem(&egg, daycare);