From 0c4fc862acf9f00bcec311c44911746526ae84af Mon Sep 17 00:00:00 2001 From: Scyrous <74797764+Scyrous@users.noreply.github.com> Date: Sun, 28 Jul 2024 12:43:18 +0200 Subject: [PATCH] Revised section #2, list now excludes already learned moves --- ...e-Relearner-Teach-Egg-Moves-With-A-Flag.md | 58 +++++++++++++++++-- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/Make-Move-Relearner-Teach-Egg-Moves-With-A-Flag.md b/Make-Move-Relearner-Teach-Egg-Moves-With-A-Flag.md index fea5f26..0a522d9 100644 --- a/Make-Move-Relearner-Teach-Egg-Moves-With-A-Flag.md +++ b/Make-Move-Relearner-Teach-Egg-Moves-With-A-Flag.md @@ -33,7 +33,7 @@ Naturally, you can use any flag you want here. Just make sure it's unused and yo ## 2. Change static function and GetEggMoves -We want to use `GetEggMoves` in an upcoming step, but the function is a static one. This means it's only accessible within the file it's defined in (`src/daycare.c`). We'll remove the static part so that it can be used anywhere, and also adjust a line of code. +We want to use `GetEggMoves` in an upcoming step, but the function is a static one. This means it's only accessible within the file it's defined in (`src/daycare.c`). We'll remove the static part so that it can be used anywhere, and also make it so that egg moves already learned are excluded from the list. Edit `src/daycare.c`: @@ -42,19 +42,69 @@ Edit `src/daycare.c`: // the given array. -static u8 GetEggMoves(struct Pokemon *pokemon, u16 *eggMoves) +u8 GetEggMoves(struct Pokemon *pokemon, u16 *eggMoves) - { +{ ++ u16 learnedMoves[MAX_MON_MOVES]; u16 eggMoveIdx; u16 numEggMoves; u16 species; - u16 i; +- u16 i; ++ u16 i, j, k; numEggMoves = 0; eggMoveIdx = 0; - species = GetMonData(pokemon, MON_DATA_SPECIES); + species = GetEggSpecies(GetMonData(pokemon, MON_DATA_SPECIES)); + for (i = 0; i < ARRAY_COUNT(gEggMoves) - 1; i++) + { + if (gEggMoves[i] == species + EGG_MOVES_SPECIES_OFFSET) + { + eggMoveIdx = i + 1; + break; + } + } + ++ if (FlagGet(FLAG_EGG_MOVES_TUTOR)) ++ { ++ for (i = 0; i < MAX_MON_MOVES; i++) ++ learnedMoves[i] = GetMonData(pokemon, MON_DATA_MOVE1 + i, 0); ++ } ++ + for (i = 0; i < EGG_MOVES_ARRAY_COUNT; i++) + { +- if (gEggMoves[eggMoveIdx + i] > EGG_MOVES_SPECIES_OFFSET) ++ u16 eggMoveId = gEggMoves[eggMoveIdx + i]; ++ ++ if (eggMoveId > EGG_MOVES_SPECIES_OFFSET) + break; + +- eggMoves[i] = gEggMoves[eggMoveIdx + i]; +- numEggMoves++; ++ if (FlagGet(FLAG_EGG_MOVES_TUTOR)) ++ { ++ for (j = 0; j < MAX_MON_MOVES && learnedMoves[j] != eggMoveId; j++); ++ ++ if (j == MAX_MON_MOVES) ++ { ++ for (k = 0; k < numEggMoves && eggMoves[k] != eggMoveId; k++); ++ ++ if (k == numEggMoves) ++ eggMoves[numEggMoves++] = eggMoveId; ++ } ++ } ++ else ++ { ++ for (k = 0; k < numEggMoves && eggMoves[k] != eggMoveId; k++); ++ ++ if (k == numEggMoves) ++ eggMoves[numEggMoves++] = eggMoveId; ++ } + } + + return numEggMoves; + } ``` -We have now made it so that `species` looks at the evolutionary family as a whole, rather than individual Pokémon. +We have now made it so that `species` looks at the evolutionary family as a whole, rather than individual Pokémon. Additionally, egg moves already learned by the chosen Pokemon are now excluded from the list. ***