Rewrite GiveBoxMonInitialMoveset_Fast (#4373)

* GiveBoxMonInitialMoveset_Fast rewrite

Fix duplicate move bug and change behavior to match GiveBoxMonInitialMoveset results

* Fixed issue with learnsets smaller than 4
This commit is contained in:
sneed 2024-04-13 21:55:17 +03:00 committed by GitHub
parent 3b17ce39f7
commit 2d42f72a8a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1689,25 +1689,43 @@ void GiveBoxMonInitialMoveset_Fast(struct BoxPokemon *boxMon) //Credit: Asparagu
u16 species = GetBoxMonData(boxMon, MON_DATA_SPECIES, NULL);
s32 level = GetLevelFromBoxMonExp(boxMon);
s32 i;
u16 levelMoveCount = 0;
u16 moves[MAX_MON_MOVES] = {0};
u8 addedMoves = 0;
const struct LevelUpMove *learnset = GetSpeciesLevelUpLearnset(species);
for (i = 0; learnset[i].move != LEVEL_UP_MOVE_END; i++)
levelMoveCount++;
for (i = levelMoveCount; (i >= 0 && addedMoves < MAX_MON_MOVES); i--)
{
s32 j;
bool32 alreadyKnown = FALSE;
if (learnset[i].level > level)
continue;
break;
if (learnset[i].level == 0)
continue;
if (moves[addedMoves] != learnset[i].move)
moves[addedMoves++] = learnset[i].move;
for (j = 0; j < addedMoves + 1; j++)
if (moves[j] == learnset[i].move)
{
alreadyKnown = TRUE;
break;
}
if (!alreadyKnown)
{
if (addedMoves < MAX_MON_MOVES)
{
moves[addedMoves] = learnset[i].move;
addedMoves++;
}
else
{
for (j = 0; j < MAX_MON_MOVES - 1; j++)
moves[j] = moves[j + 1];
moves[MAX_MON_MOVES - 1] = learnset[i].move;
}
}
}
for (i = MAX_MON_MOVES - 1; i >= 0; i--)
for (i = 0; i < MAX_MON_MOVES; i++)
{
SetBoxMonData(boxMon, MON_DATA_MOVE1 + i, &moves[i]);
SetBoxMonData(boxMon, MON_DATA_PP1 + i, &gMovesInfo[moves[i]].pp);