From 62f01e89d779abd60b79aa87211636bffb773a38 Mon Sep 17 00:00:00 2001 From: BuffelSaft Date: Tue, 23 Nov 2021 00:46:43 +1300 Subject: [PATCH] Fix Burmy form change Wasn't properly tracking if Burmy had appeared in battle; gSentPokesToOpponent is used only for exp calculation and is cleared when an opponent faints, so a new var was needed. --- include/battle.h | 1 + src/battle_main.c | 4 ++++ src/battle_script_commands.c | 5 ++++- src/battle_util.c | 6 +++--- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/battle.h b/include/battle.h index 5658f603cf..9c04a24eb5 100644 --- a/include/battle.h +++ b/include/battle.h @@ -616,6 +616,7 @@ struct BattleStruct u8 blunderPolicy:1; // should blunder policy activate u8 ballSpriteIds[2]; // item gfx, window gfx u8 stickyWebUser; + u8 appearedInBattle; // Bitfield to track which Pokemon appeared in battle. Used for Burmy's form change }; #define GET_MOVE_TYPE(move, typeArg) \ diff --git a/src/battle_main.c b/src/battle_main.c index 84f66d6ded..1a4117d4fe 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -2937,6 +2937,7 @@ static void BattleStartClearSetData(void) gBattleStruct->mega.triggerSpriteId = 0xFF; gBattleStruct->stickyWebUser = 0xFF; + gBattleStruct->appearedInBattle = 0; for (i = 0; i < PARTY_SIZE; i++) { @@ -3577,6 +3578,9 @@ static void TryDoEventsBeforeFirstTurn(void) *(gBattleStruct->monToSwitchIntoId + i) = PARTY_SIZE; gChosenActionByBattler[i] = B_ACTION_NONE; gChosenMoveByBattler[i] = MOVE_NONE; + // Record party slots of player's mons that appeared in battle + if (!IsBattlerAIControlled(i)) + gBattleStruct->appearedInBattle |= gBitTable[gBattlerPartyIndexes[i]]; } TurnValuesCleanUp(FALSE); SpecialStatusesClear(); diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 4ae42cb487..116316b16f 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -6176,7 +6176,10 @@ static void Cmd_switchineffects(void) gHitMarker &= ~(HITMARKER_FAINTED(gActiveBattler)); gSpecialStatuses[gActiveBattler].flag40 = 0; - + + if (!IsBattlerAIControlled(gActiveBattler)) + gBattleStruct->appearedInBattle |= gBitTable[gBattlerPartyIndexes[gActiveBattler]]; + // Neutralizing Gas announces itself before hazards if (gBattleMons[gActiveBattler].ability == ABILITY_NEUTRALIZING_GAS && gSpecialStatuses[gActiveBattler].announceNeutralizingGas == 0) { diff --git a/src/battle_util.c b/src/battle_util.c index 7e2320500c..f7e72ae404 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -9769,13 +9769,13 @@ bool32 TryRoomService(u8 battlerId) void DoBurmyFormChange(u32 monId) { u16 newSpecies, currSpecies; - s32 sentIn; struct Pokemon *party = gPlayerParty; - sentIn = gSentPokesToOpponent[(gBattlerFainted & 2) >> 1]; currSpecies = GetMonData(&party[monId], MON_DATA_SPECIES, NULL); - if ((GET_BASE_SPECIES_ID(currSpecies) == SPECIES_BURMY) && (gBitTable[monId] & sentIn)) + if ((GET_BASE_SPECIES_ID(currSpecies) == SPECIES_BURMY) + && (gBattleStruct->appearedInBattle & gBitTable[monId]) // Burmy appeared in battle + && GetMonData(&party[monId], MON_DATA_HP, NULL) != 0) // Burmy isn't fainted { switch (gBattleTerrain) {