diff --git a/include/pokemon.h b/include/pokemon.h index af36217739..1dc3ed461b 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -456,5 +456,6 @@ u16 GetFormSpeciesId(u16 speciesId, u8 formId); u8 GetFormIdFromFormSpeciesId(u16 formSpeciesId); u16 GetFormChangeTargetSpecies(struct Pokemon *mon, u16 method, u32 arg); u16 GetFormChangeTargetSpeciesBoxMon(struct BoxPokemon *mon, u16 method, u32 arg); +u16 MonTryLearningNewMoveEvolution(struct Pokemon *mon, bool8 firstMove); #endif // GUARD_POKEMON_H diff --git a/src/evolution_scene.c b/src/evolution_scene.c index e5d628140e..a0adb4b465 100644 --- a/src/evolution_scene.c +++ b/src/evolution_scene.c @@ -780,7 +780,7 @@ static void Task_EvolutionScene(u8 taskId) case EVOSTATE_TRY_LEARN_MOVE: if (!IsTextPrinterActive(0)) { - var = MonTryLearningNewMove(mon, gTasks[taskId].tLearnsFirstMove); + var = MonTryLearningNewMoveEvolution(mon, gTasks[taskId].tLearnsFirstMove); if (var != MOVE_NONE && !gTasks[taskId].tEvoWasStopped) { u8 text[20]; @@ -1201,7 +1201,7 @@ static void Task_TradeEvolutionScene(u8 taskId) case T_EVOSTATE_TRY_LEARN_MOVE: if (!IsTextPrinterActive(0) && IsFanfareTaskInactive() == TRUE) { - var = MonTryLearningNewMove(mon, gTasks[taskId].tLearnsFirstMove); + var = MonTryLearningNewMoveEvolution(mon, gTasks[taskId].tLearnsFirstMove); if (var != MOVE_NONE && !gTasks[taskId].tEvoWasStopped) { u8 text[20]; diff --git a/src/pokemon.c b/src/pokemon.c index 0a0b837eac..7108c3d235 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -8259,3 +8259,29 @@ u16 GetFormChangeTargetSpeciesBoxMon(struct BoxPokemon *mon, u16 method, u32 arg return species != targetSpecies ? targetSpecies : SPECIES_NONE; } + +u16 MonTryLearningNewMoveEvolution(struct Pokemon *mon, bool8 firstMove) +{ + u16 species = GetMonData(mon, MON_DATA_SPECIES, NULL); + u8 level = GetMonData(mon, MON_DATA_LEVEL, NULL); + + // since you can learn more than one move per level + // the game needs to know whether you decided to + // learn it or keep the old set to avoid asking + // you to learn the same move over and over again + if (firstMove) + { + sLearningMoveTableID = 0; + } + while(gLevelUpLearnsets[species][sLearningMoveTableID].move != LEVEL_UP_END) + { + while (!gLevelUpLearnsets[species][sLearningMoveTableID].level || gLevelUpLearnsets[species][sLearningMoveTableID].level == level) + { + gMoveToLearn = gLevelUpLearnsets[species][sLearningMoveTableID].move; + sLearningMoveTableID++; + return GiveMoveToMon(mon, gMoveToLearn); + } + sLearningMoveTableID++; + } + return 0; +}