From 620e69945d1dea0f5429e7fd1e3330704711a10b Mon Sep 17 00:00:00 2001 From: Eduardo Quezada Date: Thu, 20 Oct 2022 13:14:32 -0300 Subject: [PATCH] Form change for starting and ending battles. Adjusted PP for Iron Head/Behemoth moves --- include/battle_util.h | 1 + include/pokemon.h | 2 +- src/battle_main.c | 20 +---- src/battle_script_commands.c | 4 +- src/battle_util.c | 20 +++-- src/data/pokemon/form_change_table_pointers.h | 33 ++++++++ src/data/pokemon/form_change_tables.h | 75 +++++++++++++++++++ src/pokemon.c | 35 ++++----- 8 files changed, 146 insertions(+), 44 deletions(-) diff --git a/include/battle_util.h b/include/battle_util.h index a456cc1e6..59ddad940 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -150,6 +150,7 @@ u16 GetWishMegaEvolutionSpecies(u16 preEvoSpecies, u16 moveId1, u16 moveId2, u16 bool32 CanMegaEvolve(u8 battlerId); void UndoMegaEvolution(u32 monId); void UndoFormChange(u32 monId, u32 side, bool32 isSwitchingOut); +void BattleFormChange(u32 monId, u32 side, u16 method); bool32 DoBattlersShareType(u32 battler1, u32 battler2); bool32 CanBattlerGetOrLoseItem(u8 battlerId, u16 itemId); struct Pokemon *GetIllusionMonPtr(u32 battlerId); diff --git a/include/pokemon.h b/include/pokemon.h index c4015d562..fa5bfc663 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -564,7 +564,7 @@ u16 GetFormChangeTargetSpecies(struct Pokemon *mon, u16 method, u32 arg); u16 GetFormChangeTargetSpeciesBoxMon(struct BoxPokemon *mon, u16 method, u32 arg); u16 MonTryLearningNewMoveEvolution(struct Pokemon *mon, bool8 firstMove); bool32 ShouldShowFemaleDifferences(u16 species, u32 personality); -void TryToSetBattleFormChangeMoves(struct Pokemon *mon); +void TryToSetBattleFormChangeMoves(struct Pokemon *mon, u16 method); u32 GetMonFriendshipScore(struct Pokemon *pokemon); #endif // GUARD_POKEMON_H diff --git a/src/battle_main.c b/src/battle_main.c index 5b6e724c9..9d75e901c 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -602,21 +602,9 @@ static void CB2_InitBattleInternal(void) for (i = 0; i < PARTY_SIZE; i++) { // Player's side - targetSpecies = GetFormChangeTargetSpecies(&gPlayerParty[i], FORM_BATTLE_BEGIN, 0); - if (targetSpecies != SPECIES_NONE) - { - SetMonData(&gPlayerParty[i], MON_DATA_SPECIES, &targetSpecies); - CalculateMonStats(&gPlayerParty[i]); - TryToSetBattleFormChangeMoves(&gPlayerParty[i]); - } + BattleFormChange(i, B_SIDE_PLAYER, FORM_BATTLE_BEGIN); // Opponent's side - targetSpecies = GetFormChangeTargetSpecies(&gEnemyParty[i], FORM_BATTLE_BEGIN, 0); - if (targetSpecies != SPECIES_NONE) - { - SetMonData(&gEnemyParty[i], MON_DATA_SPECIES, &targetSpecies); - CalculateMonStats(&gEnemyParty[i]); - TryToSetBattleFormChangeMoves(&gEnemyParty[i]); - } + BattleFormChange(i, B_SIDE_OPPONENT, FORM_BATTLE_BEGIN); } gBattleCommunication[MULTIUSE_STATE] = 0; @@ -3264,7 +3252,7 @@ void FaintClearSetData(void) UndoMegaEvolution(gBattlerPartyIndexes[gActiveBattler]); gBattleStruct->overwrittenAbilities[gActiveBattler] = ABILITY_NONE; - + // If the fainted mon was involved in a Sky Drop if (gBattleStruct->skyDropTargets[gActiveBattler] != 0xFF) { @@ -5219,7 +5207,7 @@ static void HandleEndTurn_FinishBattle(void) for (i = 0; i < PARTY_SIZE; i++) { UndoMegaEvolution(i); - UndoFormChange(i, B_SIDE_PLAYER, FALSE); + BattleFormChange(i, B_SIDE_PLAYER, FORM_BATTLE_END); DoBurmyFormChange(i); } #if B_RECALCULATE_STATS >= GEN_5 diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index eaa7bbde1..bfc9bfc42 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -14109,7 +14109,7 @@ static void Cmd_handleballthrow(void) { BtlController_EmitBallThrowAnim(BUFFER_A, BALL_3_SHAKES_SUCCESS); MarkBattlerForControllerExec(gActiveBattler); - UndoFormChange(gBattlerPartyIndexes[gBattlerTarget], GET_BATTLER_SIDE(gBattlerTarget), FALSE); + BattleFormChange(gBattlerPartyIndexes[gBattlerTarget], GET_BATTLER_SIDE(gBattlerTarget), FORM_BATTLE_END), gBattlescriptCurrInstr = BattleScript_SuccessBallThrow; SetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerTarget]], MON_DATA_POKEBALL, &gLastUsedItem); @@ -14163,7 +14163,7 @@ static void Cmd_handleballthrow(void) if (IsCriticalCapture()) gBattleSpritesDataPtr->animationData->criticalCaptureSuccess = TRUE; - UndoFormChange(gBattlerPartyIndexes[gBattlerTarget], GET_BATTLER_SIDE(gBattlerTarget), FALSE); + BattleFormChange(gBattlerPartyIndexes[gBattlerTarget], GET_BATTLER_SIDE(gBattlerTarget), FORM_BATTLE_END), gBattlescriptCurrInstr = BattleScript_SuccessBallThrow; SetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerTarget]], MON_DATA_POKEBALL, &gLastUsedItem); diff --git a/src/battle_util.c b/src/battle_util.c index 9dbdb1abf..92f79cd8d 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -9726,15 +9726,19 @@ void UndoFormChange(u32 monId, u32 side, bool32 isSwitchingOut) break; } } - if (!isSwitchingOut) +} + +void BattleFormChange(u32 monId, u32 side, u16 method) +{ + u32 targetSpecies; + struct Pokemon *party = (side == B_SIDE_PLAYER) ? gPlayerParty : gEnemyParty; + + targetSpecies = GetFormChangeTargetSpecies(&party[monId], method, 0); + if (targetSpecies != SPECIES_NONE) { - targetSpecies = GetFormChangeTargetSpecies(&party[monId], FORM_BATTLE_END, 0); - if (targetSpecies != SPECIES_NONE) - { - SetMonData(&party[monId], MON_DATA_SPECIES, &targetSpecies); - CalculateMonStats(&party[monId]); - TryToSetBattleFormChangeMoves(&party[monId]); - } + TryToSetBattleFormChangeMoves(&party[monId], method); + SetMonData(&party[monId], MON_DATA_SPECIES, &targetSpecies); + CalculateMonStats(&party[monId]); } } diff --git a/src/data/pokemon/form_change_table_pointers.h b/src/data/pokemon/form_change_table_pointers.h index 90be7112b..63971f132 100644 --- a/src/data/pokemon/form_change_table_pointers.h +++ b/src/data/pokemon/form_change_table_pointers.h @@ -25,6 +25,10 @@ const struct FormChange *const gFormChangeTablePointers[NUM_SPECIES] = [SPECIES_ARCEUS_FAIRY] = sArceusFormChangeTable, #endif #if P_GEN_5_POKEMON == TRUE + [SPECIES_DARMANITAN] = sDarmanitanFormChangeTable, + [SPECIES_DARMANITAN_ZEN_MODE] = sDarmanitanFormChangeTable, + [SPECIES_DARMANITAN_GALARIAN] = sDarmanitanGalarianFormChangeTable, + [SPECIES_DARMANITAN_ZEN_MODE_GALARIAN] = sDarmanitanGalarianFormChangeTable, [SPECIES_TORNADUS] = sTornadusFormChangeTable, [SPECIES_TORNADUS_THERIAN] = sTornadusFormChangeTable, [SPECIES_THUNDURUS] = sThundurusFormChangeTable, @@ -33,6 +37,8 @@ const struct FormChange *const gFormChangeTablePointers[NUM_SPECIES] = [SPECIES_LANDORUS_THERIAN] = sLandorusFormChangeTable, [SPECIES_KELDEO] = sKeldeoFormChangeTable, [SPECIES_KELDEO_RESOLUTE] = sKeldeoFormChangeTable, + [SPECIES_MELOETTA] = sMeloettaFormChangeTable, + [SPECIES_MELOETTA_PIROUETTE] = sMeloettaFormChangeTable, [SPECIES_GENESECT] = sGenesectFormChangeTable, [SPECIES_GENESECT_DOUSE_DRIVE] = sGenesectFormChangeTable, [SPECIES_GENESECT_SHOCK_DRIVE] = sGenesectFormChangeTable, @@ -40,6 +46,10 @@ const struct FormChange *const gFormChangeTablePointers[NUM_SPECIES] = [SPECIES_GENESECT_CHILL_DRIVE] = sGenesectFormChangeTable, #endif #if P_GEN_6_POKEMON == TRUE + [SPECIES_GRENINJA_BATTLE_BOND] = sGreninjaBattleBondFormChangeTable, + [SPECIES_GRENINJA_ASH] = sGreninjaBattleBondFormChangeTable, + [SPECIES_AEGISLASH] = sAegislashFormChangeTable, + [SPECIES_AEGISLASH_BLADE] = sAegislashFormChangeTable, [SPECIES_XERNEAS] = sXerneasFormChangeTable, [SPECIES_XERNEAS_ACTIVE] = sXerneasFormChangeTable, [SPECIES_HOOPA] = sHoopaFormChangeTable, @@ -50,6 +60,8 @@ const struct FormChange *const gFormChangeTablePointers[NUM_SPECIES] = [SPECIES_ORICORIO_POM_POM] = sOricorioFormChangeTable, [SPECIES_ORICORIO_PAU] = sOricorioFormChangeTable, [SPECIES_ORICORIO_SENSU] = sOricorioFormChangeTable, + [SPECIES_WISHIWASHI] = sWishiwashiFormChangeTable, + [SPECIES_WISHIWASHI_SCHOOL] = sWishiwashiFormChangeTable, [SPECIES_SILVALLY] = sSilvallyFormChangeTable, [SPECIES_SILVALLY_BUG] = sSilvallyFormChangeTable, [SPECIES_SILVALLY_DARK] = sSilvallyFormChangeTable, @@ -68,8 +80,29 @@ const struct FormChange *const gFormChangeTablePointers[NUM_SPECIES] = [SPECIES_SILVALLY_ROCK] = sSilvallyFormChangeTable, [SPECIES_SILVALLY_STEEL] = sSilvallyFormChangeTable, [SPECIES_SILVALLY_WATER] = sSilvallyFormChangeTable, + [SPECIES_MIMIKYU] = sMimikyuFormChangeTable, + [SPECIES_MIMIKYU_BUSTED] = sMimikyuFormChangeTable, + [SPECIES_MINIOR] = sMiniorRedFormChangeTable, + [SPECIES_MINIOR_CORE_RED] = sMiniorRedFormChangeTable, + [SPECIES_MINIOR_METEOR_BLUE] = sMiniorBlueFormChangeTable, + [SPECIES_MINIOR_CORE_BLUE] = sMiniorBlueFormChangeTable, + [SPECIES_MINIOR_METEOR_GREEN] = sMiniorGreenFormChangeTable, + [SPECIES_MINIOR_CORE_GREEN] = sMiniorGreenFormChangeTable, + [SPECIES_MINIOR_METEOR_INDIGO] = sMiniorIndigoFormChangeTable, + [SPECIES_MINIOR_CORE_INDIGO] = sMiniorIndigoFormChangeTable, + [SPECIES_MINIOR_METEOR_ORANGE] = sMiniorOrangeFormChangeTable, + [SPECIES_MINIOR_CORE_ORANGE] = sMiniorOrangeFormChangeTable, + [SPECIES_MINIOR_METEOR_VIOLET] = sMiniorVioletFormChangeTable, + [SPECIES_MINIOR_CORE_VIOLET] = sMiniorVioletFormChangeTable, + [SPECIES_MINIOR_METEOR_YELLOW] = sMiniorYellowFormChangeTable, + [SPECIES_MINIOR_CORE_YELLOW] = sMiniorYellowFormChangeTable, #endif #if P_GEN_8_POKEMON == TRUE + [SPECIES_CRAMORANT] = sCramorantFormChangeTable, + [SPECIES_CRAMORANT_GULPING] = sCramorantFormChangeTable, + [SPECIES_CRAMORANT_GORGING] = sCramorantFormChangeTable, + [SPECIES_MORPEKO] = sMorpekoFormChangeTable, + [SPECIES_MORPEKO_HANGRY] = sMorpekoFormChangeTable, [SPECIES_ZACIAN] = sZacianFormChangeTable, [SPECIES_ZACIAN_CROWNED_SWORD] = sZacianFormChangeTable, [SPECIES_ZAMAZENTA] = sZamazentaFormChangeTable, diff --git a/src/data/pokemon/form_change_tables.h b/src/data/pokemon/form_change_tables.h index 94da0add3..551b7484d 100644 --- a/src/data/pokemon/form_change_tables.h +++ b/src/data/pokemon/form_change_tables.h @@ -97,6 +97,22 @@ static const struct FormChange sArceusFormChangeTable[] = { #endif #if P_GEN_5_POKEMON == TRUE + +static const struct FormChange sDarmanitanFormChangeTable[] = { + {FORM_BATTLE_END, SPECIES_DARMANITAN}, + {FORM_CHANGE_END}, +}; + +static const struct FormChange sDarmanitanGalarianFormChangeTable[] = { + {FORM_BATTLE_END, SPECIES_DARMANITAN_GALARIAN}, + {FORM_CHANGE_END}, +}; + +static const struct FormChange sMeloettaFormChangeTable[] = { + {FORM_BATTLE_END, SPECIES_MELOETTA}, + {FORM_CHANGE_END}, +}; + static const struct FormChange sTornadusFormChangeTable[] = { {FORM_ITEM_USE, SPECIES_TORNADUS_THERIAN, ITEM_REVEAL_GLASS}, {FORM_ITEM_USE, SPECIES_TORNADUS, ITEM_REVEAL_GLASS}, @@ -132,6 +148,16 @@ static const struct FormChange sGenesectFormChangeTable[] = { #endif #if P_GEN_6_POKEMON == TRUE +static const struct FormChange sGreninjaBattleBondFormChangeTable[] = { + {FORM_BATTLE_END, SPECIES_GRENINJA_BATTLE_BOND}, + {FORM_CHANGE_END}, +}; + +static const struct FormChange sAegislashFormChangeTable[] = { + {FORM_BATTLE_END, SPECIES_AEGISLASH}, + {FORM_CHANGE_END}, +}; + static const struct FormChange sXerneasFormChangeTable[] = { {FORM_BATTLE_BEGIN, SPECIES_XERNEAS_ACTIVE}, {FORM_BATTLE_END, SPECIES_XERNEAS, }, @@ -153,6 +179,10 @@ static const struct FormChange sOricorioFormChangeTable[] = { {FORM_ITEM_USE, SPECIES_ORICORIO_SENSU, ITEM_PURPLE_NECTAR}, {FORM_CHANGE_END}, }; +static const struct FormChange sWishiwashiFormChangeTable[] = { + {FORM_BATTLE_END, SPECIES_WISHIWASHI}, + {FORM_CHANGE_END}, +}; static const struct FormChange sSilvallyFormChangeTable[] = { {FORM_ITEM_HOLD, SPECIES_SILVALLY, ITEM_NONE, ABILITY_RKS_SYSTEM}, @@ -175,9 +205,54 @@ static const struct FormChange sSilvallyFormChangeTable[] = { {FORM_ITEM_HOLD, SPECIES_SILVALLY_FAIRY, ITEM_FAIRY_MEMORY, ABILITY_RKS_SYSTEM}, {FORM_CHANGE_END}, }; + +static const struct FormChange sMimikyuFormChangeTable[] = { + {FORM_BATTLE_END, SPECIES_MIMIKYU}, + {FORM_CHANGE_END}, +}; + +static const struct FormChange sMiniorRedFormChangeTable[] = { + {FORM_BATTLE_END, SPECIES_MINIOR_CORE_RED}, + {FORM_CHANGE_END}, +}; +static const struct FormChange sMiniorBlueFormChangeTable[] = { + {FORM_BATTLE_END, SPECIES_MINIOR_CORE_BLUE}, + {FORM_CHANGE_END}, +}; +static const struct FormChange sMiniorGreenFormChangeTable[] = { + {FORM_BATTLE_END, SPECIES_MINIOR_CORE_GREEN}, + {FORM_CHANGE_END}, +}; +static const struct FormChange sMiniorIndigoFormChangeTable[] = { + {FORM_BATTLE_END, SPECIES_MINIOR_CORE_INDIGO}, + {FORM_CHANGE_END}, +}; +static const struct FormChange sMiniorOrangeFormChangeTable[] = { + {FORM_BATTLE_END, SPECIES_MINIOR_CORE_ORANGE}, + {FORM_CHANGE_END}, +}; +static const struct FormChange sMiniorVioletFormChangeTable[] = { + {FORM_BATTLE_END, SPECIES_MINIOR_CORE_VIOLET}, + {FORM_CHANGE_END}, +}; +static const struct FormChange sMiniorYellowFormChangeTable[] = { + {FORM_BATTLE_END, SPECIES_MINIOR_CORE_YELLOW}, + {FORM_CHANGE_END}, +}; + #endif #if P_GEN_8_POKEMON == TRUE +static const struct FormChange sCramorantFormChangeTable[] = { + {FORM_BATTLE_END, SPECIES_CRAMORANT}, + {FORM_CHANGE_END}, +}; + +static const struct FormChange sMorpekoFormChangeTable[] = { + {FORM_BATTLE_END, SPECIES_MORPEKO}, + {FORM_CHANGE_END}, +}; + static const struct FormChange sZacianFormChangeTable[] = { {FORM_BATTLE_BEGIN, SPECIES_ZACIAN_CROWNED_SWORD, ITEM_RUSTED_SWORD, MOVE_IRON_HEAD, MOVE_BEHEMOTH_BLADE}, {FORM_BATTLE_END, SPECIES_ZACIAN, ITEM_RUSTED_SWORD, MOVE_BEHEMOTH_BLADE, MOVE_IRON_HEAD}, diff --git a/src/pokemon.c b/src/pokemon.c index 98ac99256..1a748fb24 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -4096,6 +4096,17 @@ void SetMonMoveSlot(struct Pokemon *mon, u16 move, u8 slot) SetMonData(mon, MON_DATA_PP1 + slot, &gBattleMoves[move].pp); } +static void SetMonMoveSlot_KeepPP(struct Pokemon *mon, u16 move, u8 slot) +{ + u8 ppBonuses = GetMonData(mon, MON_DATA_PP_BONUSES, NULL); + u8 currPP = GetMonData(mon, MON_DATA_PP1 + slot, NULL); + u8 newPP = CalculatePPWithBonus(move, ppBonuses, slot); + u8 finalPP = min(currPP, newPP); + + SetMonData(mon, MON_DATA_MOVE1 + slot, &move); + SetMonData(mon, MON_DATA_PP1 + slot, &finalPP); +} + void SetBattleMonMoveSlot(struct BattlePokemon *mon, u16 move, u8 slot) { mon->moves[slot] = move; @@ -8474,20 +8485,21 @@ bool32 ShouldShowFemaleDifferences(u16 species, u32 personality) return (gBaseStats[species].flags & SPECIES_FLAG_GENDER_DIFFERENCE) && GetGenderFromSpeciesAndPersonality(species, personality) == MON_FEMALE; } -void TryToSetBattleFormChangeMoves(struct Pokemon *mon) +void TryToSetBattleFormChangeMoves(struct Pokemon *mon, u16 method) { int i, j; u16 species = GetMonData(mon, MON_DATA_SPECIES, NULL); const struct FormChange *formChanges = gFormChangeTablePointers[species]; - u8 ppBonuses = GetMonData(mon, MON_DATA_PP_BONUSES, NULL); - if (formChanges == NULL) + if (formChanges == NULL || (method != FORM_BATTLE_BEGIN && method != FORM_BATTLE_END)) return; for (i = 0; formChanges[i].method != FORM_CHANGE_END; i++) { - if ((formChanges[i].method == FORM_BATTLE_BEGIN || formChanges[i].method == FORM_BATTLE_END) - && formChanges[i].param2 && formChanges[i].param3 && formChanges[i].targetSpecies == species) + if (formChanges[i].method == method + && formChanges[i].param2 + && formChanges[i].param3 + && formChanges[i].targetSpecies != species) { u16 originalMove = formChanges[i].param2; u16 newMove = formChanges[i].param3; @@ -8495,20 +8507,9 @@ void TryToSetBattleFormChangeMoves(struct Pokemon *mon) for (j = 0; j < MAX_MON_MOVES; j++) { u16 currMove = GetMonData(mon, MON_DATA_MOVE1 + j, NULL); - u8 totalPp = gBattleMoves[currMove].pp; // Get current move's max PP - u8 currPp = GetMonData(mon, MON_DATA_PP1 + j, NULL); // Get current move's remaining PP - u8 diffPp = totalPp - currPp; // Current move's PP difference - u8 finalPp = gBattleMoves[newMove].pp - diffPp; // Apply the PP difference to the new move - if (currMove == originalMove) - { - if (finalPp > gBattleMoves[newMove].pp) - finalPp = 0; - SetMonMoveSlot(mon, newMove, j); - SetMonData(mon, MON_DATA_PP1 + j, &finalPp); - } + SetMonMoveSlot_KeepPP(mon, newMove, j); } - SetMonData(mon, MON_DATA_PP_BONUSES, &ppBonuses); break; } }