From df88317a9890a23521e09632d1fc345b720210d6 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Sun, 28 Aug 2022 11:48:39 -0300 Subject: [PATCH] Introduced FORM_BATTLE form changes For species such as Xerneas and Zacian. --- include/constants/pokemon.h | 2 ++ src/battle_main.c | 14 ++++++++++ src/battle_util.c | 17 +++++++++++- src/data/pokemon/form_change_table_pointers.h | 8 +++++- src/data/pokemon/form_change_tables.h | 26 +++++++++++++++++++ src/pokemon.c | 6 +++-- 6 files changed, 69 insertions(+), 4 deletions(-) diff --git a/include/constants/pokemon.h b/include/constants/pokemon.h index 98075a942..8e8b31543 100644 --- a/include/constants/pokemon.h +++ b/include/constants/pokemon.h @@ -324,6 +324,8 @@ #define FORM_WITHDRAW 4 #define FORM_ITEM_HOLD_ABILITY 5 #define FORM_ITEM_USE_TIME 6 +#define FORM_BATTLE_BEGIN 7 +#define FORM_BATTLE_END 8 #define NUM_MALE_LINK_FACILITY_CLASSES 8 #define NUM_FEMALE_LINK_FACILITY_CLASSES 8 diff --git a/src/battle_main.c b/src/battle_main.c index 25a0b0613..f75a7ae80 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -481,6 +481,7 @@ void CB2_InitBattle(void) static void CB2_InitBattleInternal(void) { s32 i; + u16 targetSpecies; SetHBlankCallback(NULL); SetVBlankCallback(NULL); @@ -571,6 +572,19 @@ static void CB2_InitBattleInternal(void) for (i = 0; i < PARTY_SIZE; i++) AdjustFriendship(&gPlayerParty[i], FRIENDSHIP_EVENT_LEAGUE_BATTLE); + // Apply party-wide start-of-battle form changes + 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); + // Opponent's side + targetSpecies = GetFormChangeTargetSpecies(&gEnemyParty[i], FORM_BATTLE_BEGIN, 0); + if (targetSpecies != SPECIES_NONE) + SetMonData(&gEnemyParty[i], MON_DATA_SPECIES, &targetSpecies); + } + gBattleCommunication[MULTIUSE_STATE] = 0; } diff --git a/src/battle_util.c b/src/battle_util.c index f38d80a69..dff9d71da 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -9588,7 +9588,7 @@ void UndoMegaEvolution(u32 monId) void UndoFormChange(u32 monId, u32 side, bool32 isSwitchingOut) { - u32 i, currSpecies; + u32 i, currSpecies, targetSpecies; struct Pokemon *party = (side == B_SIDE_PLAYER) ? gPlayerParty : gEnemyParty; static const u16 species[][3] = { @@ -9622,6 +9622,21 @@ void UndoFormChange(u32 monId, u32 side, bool32 isSwitchingOut) break; } } + if (!isSwitchingOut) + { + // Apply party-wide end-of-battle form changes + for (i = 0; i < PARTY_SIZE; i++) + { + // Player's side + targetSpecies = GetFormChangeTargetSpecies(&gPlayerParty[i], FORM_BATTLE_END, 0); + if (targetSpecies != SPECIES_NONE) + SetMonData(&gPlayerParty[i], MON_DATA_SPECIES, &targetSpecies); + // Opponent's side + targetSpecies = GetFormChangeTargetSpecies(&gEnemyParty[i], FORM_BATTLE_END, 0); + if (targetSpecies != SPECIES_NONE) + SetMonData(&gEnemyParty[i], MON_DATA_SPECIES, &targetSpecies); + } + } } bool32 DoBattlersShareType(u32 battler1, u32 battler2) diff --git a/src/data/pokemon/form_change_table_pointers.h b/src/data/pokemon/form_change_table_pointers.h index 3fdbff7a6..58a6c899f 100644 --- a/src/data/pokemon/form_change_table_pointers.h +++ b/src/data/pokemon/form_change_table_pointers.h @@ -31,11 +31,13 @@ const struct FormChange *const gFormChangeTablePointers[NUM_SPECIES] = [SPECIES_LANDORUS_THERIAN] = sLandorusTherianFormChangeTable, [SPECIES_KELDEO] = sKeldeoFormChangeTable, [SPECIES_KELDEO_RESOLUTE] = sKeldeoResoluteFormChangeTable, - [SPECIES_GENESECT] = sGenesectFormChangeTable, + [SPECIES_GENESECT] = sGenesectFormChangeTable, [SPECIES_GENESECT_DOUSE_DRIVE] = sGenesectFormChangeTable, [SPECIES_GENESECT_SHOCK_DRIVE] = sGenesectFormChangeTable, [SPECIES_GENESECT_BURN_DRIVE] = sGenesectFormChangeTable, [SPECIES_GENESECT_CHILL_DRIVE] = sGenesectFormChangeTable, + [SPECIES_XERNEAS] = sXerneasFormChangeTable, + [SPECIES_XERNEAS_ACTIVE] = sXerneasFormChangeTable, [SPECIES_HOOPA] = sHoopaFormChangeTable, [SPECIES_HOOPA_UNBOUND] = sHoopaUnboundFormChangeTable, [SPECIES_ORICORIO] = sOricorioFormChangeTable, @@ -60,5 +62,9 @@ const struct FormChange *const gFormChangeTablePointers[NUM_SPECIES] = [SPECIES_SILVALLY_ROCK] = sSilvallyFormChangeTable, [SPECIES_SILVALLY_STEEL] = sSilvallyFormChangeTable, [SPECIES_SILVALLY_WATER] = sSilvallyFormChangeTable, + [SPECIES_ZACIAN] = sZacianFormChangeTable, + [SPECIES_ZACIAN_CROWNED_SWORD] = sZacianFormChangeTable, + [SPECIES_ZAMAZENTA] = sZamazentaFormChangeTable, + [SPECIES_ZAMAZENTA_CROWNED_SHIELD] = sZamazentaFormChangeTable, #endif }; diff --git a/src/data/pokemon/form_change_tables.h b/src/data/pokemon/form_change_tables.h index 15cb8cdec..be76cc995 100644 --- a/src/data/pokemon/form_change_tables.h +++ b/src/data/pokemon/form_change_tables.h @@ -33,6 +33,14 @@ FORM_ITEM_USE_TIME: param1 = item to use param2 = DAY if form change activates in the daytime NIGHT if form change activates at nighttime + +FORM_BATTLE_BEGIN: + Form change activates when the Pokémon is sent out at the beginning of a battle + param1 = item to hold, optional + +FORM_BATTLE_END: + Form change activates at the end of a battle + param1 = item to hold, optional */ // FORM_MOVE param2 Arguments @@ -185,5 +193,23 @@ static const struct FormChange sSilvallyFormChangeTable[] = { }; #endif +static const struct FormChange sXerneasFormChangeTable[] = { + {FORM_BATTLE_BEGIN, SPECIES_XERNEAS_ACTIVE, ITEM_NONE}, + {FORM_BATTLE_END, SPECIES_XERNEAS, ITEM_NONE}, + {FORM_CHANGE_END}, +}; + +static const struct FormChange sZacianFormChangeTable[] = { + {FORM_BATTLE_BEGIN, SPECIES_ZACIAN_CROWNED_SWORD, ITEM_RUSTED_SWORD}, + {FORM_BATTLE_END, SPECIES_ZACIAN, ITEM_RUSTED_SWORD}, + {FORM_CHANGE_END}, +}; + +static const struct FormChange sZamazentaFormChangeTable[] = { + {FORM_BATTLE_BEGIN, SPECIES_ZAMAZENTA_CROWNED_SHIELD, ITEM_RUSTED_SHIELD}, + {FORM_BATTLE_END, SPECIES_ZAMAZENTA, ITEM_RUSTED_SHIELD}, + {FORM_CHANGE_END}, +}; + #undef WHEN_LEARNED #undef WHEN_FORGOTTEN diff --git a/src/pokemon.c b/src/pokemon.c index 92bd923f0..06e75dbc3 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -8237,13 +8237,13 @@ u8 GetFormIdFromFormSpeciesId(u16 formSpeciesId) return targetFormId; } -u16 GetFormChangeTargetSpecies(struct Pokemon *mon, u16 method, u32 arg) +u16 GetFormChangeTargetSpecies(struct Pokemon *mon, u16 method, u32 arg) { return GetFormChangeTargetSpeciesBoxMon(&mon->box, method, arg); } // Returns SPECIES_NONE if no form change is possible -u16 GetFormChangeTargetSpeciesBoxMon(struct BoxPokemon *mon, u16 method, u32 arg) +u16 GetFormChangeTargetSpeciesBoxMon(struct BoxPokemon *mon, u16 method, u32 arg) { u32 i; u16 targetSpecies = SPECIES_NONE; @@ -8264,6 +8264,8 @@ u16 GetFormChangeTargetSpeciesBoxMon(struct BoxPokemon *mon, u16 method, u32 arg switch (method) { case FORM_ITEM_HOLD: + case FORM_BATTLE_BEGIN: + case FORM_BATTLE_END: if (heldItem == formChanges[i].param1 || formChanges[i].param1 == ITEM_NONE) targetSpecies = formChanges[i].targetSpecies; break;