Skip to content

Commit

Permalink
Random Pyramid Encounter fixes (rh-hideout#4326)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghoulslash authored and Pawkkie committed May 16, 2024
1 parent 0c61570 commit eb70d1c
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/battle_pyramid.c
Original file line number Diff line number Diff line change
Expand Up @@ -1401,27 +1401,32 @@ void GenerateBattlePyramidWildMon(void)

if (reqs->nMoves != 0)
moves = AllocZeroed(sizeof(u16) * reqs->nMoves);

if (reqs->nAbilities != 0)
abilities = AllocZeroed(sizeof(u16) * reqs->nAbilities);

if (round >= TOTAL_PYRAMID_ROUNDS)
round = TOTAL_PYRAMID_ROUNDS - 1;

id = GetMonData(&gEnemyParty[0], MON_DATA_SPECIES, NULL) - 1; // index in table (0-11) -> higher index is lower probability
bstLim = 450 + (25*round) + (5*id); // higher BST limit for 'rarer' wild mon rolls

while (1)
{
species = Random() % FORMS_START;
species = Random() % NUM_SPECIES;

// check if base species
if (GET_BASE_SPECIES_ID(species) != species)
continue;

// check type
if (reqs->type != TYPE_MYSTERY && gSpeciesInfo[species].types[0] != reqs->type && gSpeciesInfo[species].types[1] != reqs->type)
continue;

// check base stat total
if (GetTotalBaseStat(species) > bstLim)
continue;

// check moves
if (reqs->nMoves != 0)
{
Expand All @@ -1438,7 +1443,7 @@ void GenerateBattlePyramidWildMon(void)
if (moveCount == 0)
continue;
}

// check abilities
if (reqs->nAbilities != 0)
{
Expand All @@ -1460,9 +1465,9 @@ void GenerateBattlePyramidWildMon(void)
continue;
}
// check evos
if (reqs->evoItems[0] != 0 && !CheckBattlePyramidEvoRequirement(species, reqs->evoItems, reqs->nEvoItems))
if (reqs->evoItems != NULL && !CheckBattlePyramidEvoRequirement(species, reqs->evoItems, reqs->nEvoItems))
continue;

// we found a species we can use!
break;
}
Expand All @@ -1471,7 +1476,7 @@ void GenerateBattlePyramidWildMon(void)
SetMonData(&gEnemyParty[0], MON_DATA_SPECIES, &species);
StringCopy(name, GetSpeciesName(species));
SetMonData(&gEnemyParty[0], MON_DATA_NICKNAME, &name);

// set level
if (lvl != FRONTIER_LVL_50)
{
Expand Down Expand Up @@ -1507,7 +1512,7 @@ void GenerateBattlePyramidWildMon(void)
}
Free(moves);
}

// Initialize a random ability num
if (gSpeciesInfo[species].abilities[1])
{
Expand All @@ -1519,7 +1524,7 @@ void GenerateBattlePyramidWildMon(void)
i = 0;
SetMonData(&gEnemyParty[0], MON_DATA_ABILITY_NUM, &i);
}

// Try to replace with desired ability
if (abilities != NULL)
{
Expand All @@ -1533,12 +1538,15 @@ void GenerateBattlePyramidWildMon(void)
{
// Set this ability num
SetMonData(&gEnemyParty[0], MON_DATA_ABILITY_NUM, &id);
break;
}
}
if (id >= NUM_ABILITY_SLOTS - 1)
break;
}
Free(abilities);
}

if (gSaveBlock2Ptr->frontier.pyramidWinStreaks[gSaveBlock2Ptr->frontier.lvlMode] >= 140)
{
id = (Random() % 17) + 15;
Expand Down

0 comments on commit eb70d1c

Please sign in to comment.