Skip to content

Commit

Permalink
Rewrite GiveBoxMonInitialMoveset_Fast (#4373)
Browse files Browse the repository at this point in the history
* GiveBoxMonInitialMoveset_Fast rewrite

Fix duplicate move bug and change behavior to match GiveBoxMonInitialMoveset results

* Fixed issue with learnsets smaller than 4
  • Loading branch information
Sneed69 authored Apr 13, 2024
1 parent 3b17ce3 commit 2d42f72
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions src/pokemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2d42f72

Please sign in to comment.