Skip to content

Commit

Permalink
Fix special evolution triggering twice in certain situations (#4553)
Browse files Browse the repository at this point in the history
  • Loading branch information
cawtds authored May 16, 2024
1 parent d235a71 commit 6f12da0
Showing 1 changed file with 17 additions and 38 deletions.
55 changes: 17 additions & 38 deletions src/battle_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ static void HandleEndTurn_MonFled(void);
static void HandleEndTurn_FinishBattle(void);
static void SpriteCB_UnusedBattleInit(struct Sprite *sprite);
static void SpriteCB_UnusedBattleInit_Main(struct Sprite *sprite);
static void TrySpecialEvolution(void);
static u32 Crc32B (const u8 *data, u32 size);
static u32 GeneratePartyHash(const struct Trainer *trainer, u32 i);

Expand Down Expand Up @@ -5808,7 +5807,7 @@ static void FreeResetData_ReturnToOvOrDoEvolutions(void)
|| gBattleOutcome == B_OUTCOME_WON
|| gBattleOutcome == B_OUTCOME_CAUGHT))
{
gBattleMainFunc = TrySpecialEvolution;
gBattleMainFunc = TryEvolvePokemon;
}
else
{
Expand All @@ -5826,61 +5825,41 @@ static void FreeResetData_ReturnToOvOrDoEvolutions(void)
}
}

static void TrySpecialEvolution(void) // Attempts to perform non-level related battle evolutions (not the script command).
static void TryEvolvePokemon(void)
{
s32 i;

for (i = 0; i < PARTY_SIZE; i++)
{
u16 species = GetEvolutionTargetSpecies(&gPlayerParty[i], EVO_MODE_BATTLE_SPECIAL, i, NULL);
if (species != SPECIES_NONE && !(sTriedEvolving & gBitTable[i]))
if (!(sTriedEvolving & gBitTable[i]))
{
u16 species = GetEvolutionTargetSpecies(&gPlayerParty[i], EVO_MODE_BATTLE_SPECIAL, i, NULL);
sTriedEvolving |= gBitTable[i];
FreeAllWindowBuffers();
gBattleMainFunc = WaitForEvoSceneToFinish;
EvolutionScene(&gPlayerParty[i], species, TRUE, i);
return;
}
}
sTriedEvolving = 0;
gBattleMainFunc = TryEvolvePokemon;
}

static void TryEvolvePokemon(void)
{
s32 i;
if (species == SPECIES_NONE && (gLeveledUpInBattle & gBitTable[i]))
{
gLeveledUpInBattle &= ~(gBitTable[i]);
species = GetEvolutionTargetSpecies(&gPlayerParty[i], EVO_MODE_NORMAL, gLeveledUpInBattle, NULL);
}

while (gLeveledUpInBattle != 0)
{
for (i = 0; i < PARTY_SIZE; i++)
{
if (gLeveledUpInBattle & gBitTable[i])
if (species != SPECIES_NONE)
{
u16 species;
u8 levelUpBits = gLeveledUpInBattle;

levelUpBits &= ~(gBitTable[i]);
gLeveledUpInBattle = levelUpBits;

species = GetEvolutionTargetSpecies(&gPlayerParty[i], EVO_MODE_NORMAL, levelUpBits, NULL);
if (species != SPECIES_NONE)
{
FreeAllWindowBuffers();
gBattleMainFunc = WaitForEvoSceneToFinish;
EvolutionScene(&gPlayerParty[i], species, TRUE, i);
return;
}
FreeAllWindowBuffers();
gBattleMainFunc = WaitForEvoSceneToFinish;
EvolutionScene(&gPlayerParty[i], species, TRUE, i);
return;
}
}
}

sTriedEvolving = 0;
gLeveledUpInBattle = 0;
gBattleMainFunc = ReturnFromBattleToOverworld;
}

static void WaitForEvoSceneToFinish(void)
{
if (gMain.callback2 == BattleMainCB2)
gBattleMainFunc = TrySpecialEvolution;
gBattleMainFunc = TryEvolvePokemon;
}

static void ReturnFromBattleToOverworld(void)
Expand Down

0 comments on commit 6f12da0

Please sign in to comment.