From f364cf9e71838f144687761317fe2af8211c3d3e Mon Sep 17 00:00:00 2001 From: Alex <93446519+AlexOn1ine@users.noreply.github.com> Date: Wed, 9 Apr 2025 11:18:07 +0200 Subject: [PATCH] Alcremie Evolution clean up follow up (#6557) --- include/constants/pokemon.h | 5 +++++ include/pokemon.h | 3 +-- src/battle_main.c | 6 ++--- src/evolution_scene.c | 1 - src/field_player_avatar.c | 2 +- src/party_menu.c | 10 ++++----- src/pokemon.c | 45 +++++++++++++++---------------------- src/trade.c | 6 ++--- 8 files changed, 36 insertions(+), 42 deletions(-) diff --git a/include/constants/pokemon.h b/include/constants/pokemon.h index 9b02548cdc..5d7c6b0a87 100644 --- a/include/constants/pokemon.h +++ b/include/constants/pokemon.h @@ -324,6 +324,11 @@ enum EvolutionMode { EVO_MODE_BATTLE_ONLY, // This mode is only used in battles to support Tandemaus' unique requirement }; +enum StartEvo +{ + CHECK_EVO, + DO_EVO, +}; enum PokemonJumpType{ PKMN_JUMP_TYPE_NONE, // Not allowed in Pokémon Jump diff --git a/include/pokemon.h b/include/pokemon.h index dcaf79eada..2a772967c1 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -725,7 +725,7 @@ u8 *UseStatIncreaseItem(u16 itemId); u8 GetNature(struct Pokemon *mon); u8 GetNatureFromPersonality(u32 personality); u32 GetGMaxTargetSpecies(u32 species); -u16 GetEvolutionTargetSpecies(struct Pokemon *mon, enum EvolutionMode mode, u16 evolutionItem, struct Pokemon *tradePartner); +u16 GetEvolutionTargetSpecies(struct Pokemon *mon, enum EvolutionMode mode, u16 evolutionItem, struct Pokemon *tradePartner, enum StartEvo prepareEvo); bool8 IsMonPastEvolutionLevel(struct Pokemon *mon); u16 NationalPokedexNumToSpecies(u16 nationalNum); u16 NationalToHoennOrder(u16 nationalNum); @@ -813,6 +813,5 @@ u32 CheckDynamicMoveType(struct Pokemon *mon, u32 move, u32 battler); uq4_12_t GetDynamaxLevelHPMultiplier(u32 dynamaxLevel, bool32 inverseMultiplier); u32 GetRegionalFormByRegion(u32 species, u32 region); bool32 IsSpeciesForeignRegionalForm(u32 species, u32 currentRegion); -void DoRemoveItems(struct Pokemon *mon); #endif // GUARD_POKEMON_H diff --git a/src/battle_main.c b/src/battle_main.c index 215ee71268..d9e811014b 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -5678,19 +5678,19 @@ static void TryEvolvePokemon(void) { if (!(sTriedEvolving & (1u << i))) { - u16 species = GetEvolutionTargetSpecies(&gPlayerParty[i], EVO_MODE_BATTLE_SPECIAL, i, NULL); + u16 species = GetEvolutionTargetSpecies(&gPlayerParty[i], EVO_MODE_BATTLE_SPECIAL, i, NULL, DO_EVO); bool32 evoModeNormal = TRUE; sTriedEvolving |= 1u << i; if (species == SPECIES_NONE && (gLeveledUpInBattle & (1u << i))) { gLeveledUpInBattle &= ~(1u << i); - species = GetEvolutionTargetSpecies(&gPlayerParty[i], EVO_MODE_BATTLE_ONLY, gLeveledUpInBattle, NULL); + species = GetEvolutionTargetSpecies(&gPlayerParty[i], EVO_MODE_BATTLE_ONLY, gLeveledUpInBattle, NULL, DO_EVO); } if (species == SPECIES_NONE) { - species = GetEvolutionTargetSpecies(&gPlayerParty[i], EVO_MODE_CANT_STOP, ITEM_NONE, NULL); + species = GetEvolutionTargetSpecies(&gPlayerParty[i], EVO_MODE_CANT_STOP, ITEM_NONE, NULL, DO_EVO); evoModeNormal = FALSE; } diff --git a/src/evolution_scene.c b/src/evolution_scene.c index 39b407f716..7de57bd53c 100644 --- a/src/evolution_scene.c +++ b/src/evolution_scene.c @@ -821,7 +821,6 @@ static void Task_EvolutionScene(u8 taskId) } if (!gTasks[taskId].tEvoWasStopped) { - DoRemoveItems(mon); CreateShedinja(gTasks[taskId].tPreEvoSpecies, mon); } diff --git a/src/field_player_avatar.c b/src/field_player_avatar.c index 5d27af481f..6452e99a9b 100644 --- a/src/field_player_avatar.c +++ b/src/field_player_avatar.c @@ -780,7 +780,7 @@ bool32 CanTriggerSpinEvolution() { for (u32 i = 0; i < PARTY_SIZE; i++) { - u16 species = GetEvolutionTargetSpecies(&gPlayerParty[i], EVO_MODE_OVERWORLD_SPECIAL, gSpecialVar_0x8000, NULL); + u16 species = GetEvolutionTargetSpecies(&gPlayerParty[i], EVO_MODE_OVERWORLD_SPECIAL, gSpecialVar_0x8000, NULL, CHECK_EVO); if (species != SPECIES_NONE) { return TRUE; diff --git a/src/party_menu.c b/src/party_menu.c index 8a3da4c1f2..2303bae000 100644 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -1154,7 +1154,7 @@ static bool8 DisplayPartyPokemonDataForMoveTutorOrEvolutionItem(u8 slot) DisplayPartyPokemonDataToTeachMove(slot, ItemIdToBattleMoveId(item)); break; case 2: // Evolution stone - if (!GetMonData(currentPokemon, MON_DATA_IS_EGG) && GetEvolutionTargetSpecies(currentPokemon, EVO_MODE_ITEM_CHECK, item, NULL) != SPECIES_NONE) + if (!GetMonData(currentPokemon, MON_DATA_IS_EGG) && GetEvolutionTargetSpecies(currentPokemon, EVO_MODE_ITEM_CHECK, item, NULL, DO_EVO) != SPECIES_NONE) return FALSE; DisplayPartyPokemonDescriptionData(slot, PARTYBOX_DESC_NO_USE); break; @@ -5634,10 +5634,10 @@ void ItemUseCB_RareCandy(u8 taskId, TaskFunc task) if (holdEffectParam == 0) { - targetSpecies = GetEvolutionTargetSpecies(mon, EVO_MODE_NORMAL, ITEM_NONE, NULL); + targetSpecies = GetEvolutionTargetSpecies(mon, EVO_MODE_NORMAL, ITEM_NONE, NULL, DO_EVO); if (targetSpecies == SPECIES_NONE) { - targetSpecies = GetEvolutionTargetSpecies(mon, EVO_MODE_CANT_STOP, ITEM_NONE, NULL); + targetSpecies = GetEvolutionTargetSpecies(mon, EVO_MODE_CANT_STOP, ITEM_NONE, NULL, DO_EVO); evoModeNormal = FALSE; } } @@ -5828,10 +5828,10 @@ static void PartyMenuTryEvolution(u8 taskId) sInitialLevel = 0; sFinalLevel = 0; - targetSpecies = GetEvolutionTargetSpecies(mon, EVO_MODE_NORMAL, ITEM_NONE, NULL); + targetSpecies = GetEvolutionTargetSpecies(mon, EVO_MODE_NORMAL, ITEM_NONE, NULL, DO_EVO); if (targetSpecies == SPECIES_NONE) { - targetSpecies = GetEvolutionTargetSpecies(mon, EVO_MODE_CANT_STOP, ITEM_NONE, NULL); + targetSpecies = GetEvolutionTargetSpecies(mon, EVO_MODE_CANT_STOP, ITEM_NONE, NULL, DO_EVO); evoModeNormal = FALSE; } diff --git a/src/pokemon.c b/src/pokemon.c index 86db9764b9..a22200bfc7 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -90,9 +90,6 @@ EWRAM_DATA struct SpriteTemplate gMultiuseSpriteTemplate = {0}; EWRAM_DATA static struct MonSpritesGfxManager *sMonSpritesGfxManagers[MON_SPR_GFX_MANAGERS_COUNT] = {NULL}; EWRAM_DATA static u8 sTriedEvolving = 0; EWRAM_DATA u16 gFollowerSteps = 0; -EWRAM_DATA bool32 removeHeldItem = 0; -EWRAM_DATA u32 removeBagItem = 0; -EWRAM_DATA u32 removeBagItemCount = 0; #include "data/abilities.h" @@ -4059,7 +4056,7 @@ bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 mov case 7: // ITEM4_EVO_STONE { - u16 targetSpecies = GetEvolutionTargetSpecies(mon, EVO_MODE_ITEM_USE, item, NULL); + u16 targetSpecies = GetEvolutionTargetSpecies(mon, EVO_MODE_ITEM_USE, item, NULL, DO_EVO); if (targetSpecies != SPECIES_NONE) { @@ -4439,18 +4436,6 @@ u8 GetNatureFromPersonality(u32 personality) return personality % NUM_NATURES; } -void DoRemoveItems(struct Pokemon *mon) -{ - if (removeHeldItem) - { - u32 heldItem = ITEM_NONE; - SetMonData(mon, MON_DATA_HELD_ITEM, &heldItem); - } - - if (removeBagItem != ITEM_NONE && removeBagItemCount != 0) - RemoveBagItem(removeBagItem, removeBagItemCount); -} - u32 GetGMaxTargetSpecies(u32 species) { const struct FormChange *formChanges = GetSpeciesFormChanges(species); @@ -4463,7 +4448,7 @@ u32 GetGMaxTargetSpecies(u32 species) return species; } -u16 GetEvolutionTargetSpecies(struct Pokemon *mon, enum EvolutionMode mode, u16 evolutionItem, struct Pokemon *tradePartner) +u16 GetEvolutionTargetSpecies(struct Pokemon *mon, enum EvolutionMode mode, u16 evolutionItem, struct Pokemon *tradePartner, enum StartEvo prepareEvo) { int i, j; u16 targetSpecies = SPECIES_NONE; @@ -4475,7 +4460,7 @@ u16 GetEvolutionTargetSpecies(struct Pokemon *mon, enum EvolutionMode mode, u16 u8 beauty = GetMonData(mon, MON_DATA_BEAUTY, 0); u16 upperPersonality = personality >> 16; u32 holdEffect, currentMap, partnerSpecies, partnerHeldItem, partnerHoldEffect; - removeHeldItem = FALSE; + bool32 consumeItem = FALSE; u16 evolutionTracker = GetMonData(mon, MON_DATA_EVOLUTION_TRACKER, 0); const struct Evolution *evolutions = GetSpeciesEvolutions(species); @@ -4556,14 +4541,14 @@ u16 GetEvolutionTargetSpecies(struct Pokemon *mon, enum EvolutionMode mode, u16 if (GetTimeOfDay() == TIME_NIGHT && heldItem == evolutions[i].param) { targetSpecies = evolutions[i].targetSpecies; - removeHeldItem = TRUE; + consumeItem = TRUE; } break; case EVO_ITEM_HOLD_DAY: if (GetTimeOfDay() != TIME_NIGHT && heldItem == evolutions[i].param) { targetSpecies = evolutions[i].targetSpecies; - removeHeldItem = TRUE; + consumeItem = TRUE; } break; case EVO_LEVEL_DUSK: @@ -4743,7 +4728,7 @@ u16 GetEvolutionTargetSpecies(struct Pokemon *mon, enum EvolutionMode mode, u16 if (heldItem == evolutions[i].param) { targetSpecies = evolutions[i].targetSpecies; - removeHeldItem = TRUE; + consumeItem = TRUE; } break; case EVO_USE_MOVE_TWENTY_TIMES: @@ -4784,8 +4769,8 @@ u16 GetEvolutionTargetSpecies(struct Pokemon *mon, enum EvolutionMode mode, u16 if (CheckBagHasItem(evolutions[i].param, 999)) { targetSpecies = evolutions[i].targetSpecies; - removeBagItem = evolutions[i].param; - removeBagItemCount = 999; + if (prepareEvo == DO_EVO) + RemoveBagItem(evolutions[i].param, 999); } break; } @@ -4806,7 +4791,7 @@ u16 GetEvolutionTargetSpecies(struct Pokemon *mon, enum EvolutionMode mode, u16 if (evolutions[i].param == heldItem) { targetSpecies = evolutions[i].targetSpecies; - removeHeldItem = TRUE; + consumeItem = TRUE; } break; case EVO_TRADE_SPECIFIC_MON: @@ -4902,9 +4887,9 @@ u16 GetEvolutionTargetSpecies(struct Pokemon *mon, enum EvolutionMode mode, u16 if (evolutions[i].param == heldItem && evolutionItem == evolutions[i].method) { targetSpecies = evolutions[i].targetSpecies; - removeHeldItem = TRUE; + consumeItem = TRUE; } - + break; } } @@ -4921,6 +4906,12 @@ u16 GetEvolutionTargetSpecies(struct Pokemon *mon, enum EvolutionMode mode, u16 return SPECIES_NONE; } + if (consumeItem && prepareEvo == DO_EVO) + { + heldItem = ITEM_NONE; + SetMonData(mon, MON_DATA_HELD_ITEM, &heldItem); + } + return targetSpecies; } @@ -6741,7 +6732,7 @@ void TrySpecialOverworldEvo(void) for (i = 0; i < PARTY_SIZE; i++) { - u16 targetSpecies = GetEvolutionTargetSpecies(&gPlayerParty[i], EVO_MODE_OVERWORLD_SPECIAL, evoMethod, SPECIES_NONE); + u16 targetSpecies = GetEvolutionTargetSpecies(&gPlayerParty[i], EVO_MODE_OVERWORLD_SPECIAL, evoMethod, SPECIES_NONE, DO_EVO); if (targetSpecies != SPECIES_NONE && !(sTriedEvolving & (1u << i))) { sTriedEvolving |= 1u << i; diff --git a/src/trade.c b/src/trade.c index 8ba22eac97..693f295e7d 100644 --- a/src/trade.c +++ b/src/trade.c @@ -3846,7 +3846,7 @@ static bool8 DoTradeAnim_Cable(void) case STATE_TRY_EVOLUTION: // Only if in-game trade, link trades use CB2_TryLinkTradeEvolution TradeMons(gSpecialVar_0x8005, 0); gCB2_AfterEvolution = CB2_InGameTrade; - evoTarget = GetEvolutionTargetSpecies(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], EVO_MODE_TRADE, ITEM_NONE, &gPlayerParty[gSelectedTradeMonPositions[TRADE_PARTNER]]); + evoTarget = GetEvolutionTargetSpecies(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], EVO_MODE_TRADE, ITEM_NONE, &gPlayerParty[gSelectedTradeMonPositions[TRADE_PARTNER]], DO_EVO); if (evoTarget != SPECIES_NONE) TradeEvolutionScene(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], evoTarget, sTradeAnim->monSpriteIds[TRADE_PARTNER], gSelectedTradeMonPositions[TRADE_PLAYER]); sTradeAnim->state++; @@ -4343,7 +4343,7 @@ static bool8 DoTradeAnim_Wireless(void) case STATE_TRY_EVOLUTION: // Only if in-game trade, link trades use CB2_TryLinkTradeEvolution TradeMons(gSpecialVar_0x8005, 0); gCB2_AfterEvolution = CB2_InGameTrade; - evoTarget = GetEvolutionTargetSpecies(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], EVO_MODE_TRADE, ITEM_NONE, &gPlayerParty[gSelectedTradeMonPositions[TRADE_PARTNER]]); + evoTarget = GetEvolutionTargetSpecies(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], EVO_MODE_TRADE, ITEM_NONE, &gPlayerParty[gSelectedTradeMonPositions[TRADE_PARTNER]], DO_EVO); if (evoTarget != SPECIES_NONE) TradeEvolutionScene(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], evoTarget, sTradeAnim->monSpriteIds[TRADE_PARTNER], gSelectedTradeMonPositions[TRADE_PLAYER]); sTradeAnim->state++; @@ -4386,7 +4386,7 @@ static void CB2_TryLinkTradeEvolution(void) break; case 4: gCB2_AfterEvolution = CB2_SaveAndEndTrade; - evoTarget = GetEvolutionTargetSpecies(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], EVO_MODE_TRADE, ITEM_NONE, &gPlayerParty[gSelectedTradeMonPositions[TRADE_PARTNER]]); + evoTarget = GetEvolutionTargetSpecies(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], EVO_MODE_TRADE, ITEM_NONE, &gPlayerParty[gSelectedTradeMonPositions[TRADE_PARTNER]], DO_EVO); if (evoTarget != SPECIES_NONE) TradeEvolutionScene(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], evoTarget, sTradeAnim->monSpriteIds[TRADE_PARTNER], gSelectedTradeMonPositions[TRADE_PLAYER]); else if (IsWirelessTrade())