From 6235970722ad9eab298deaf3b66580f9a78dd2d9 Mon Sep 17 00:00:00 2001 From: AgustinGDLV Date: Thu, 5 May 2022 11:41:27 -0700 Subject: [PATCH 1/6] added special battle evo changes --- include/constants/pokemon.h | 2 ++ src/battle_main.c | 37 +++++++++++++++++++++++++++++++++--- src/battle_script_commands.c | 7 +++++++ src/pokemon.c | 13 +++++++++++++ 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/include/constants/pokemon.h b/include/constants/pokemon.h index c375bbdd10..a7f0e3e4ed 100644 --- a/include/constants/pokemon.h +++ b/include/constants/pokemon.h @@ -379,6 +379,7 @@ #define EVO_SPECIFIC_MAP 32 // Pokémon levels up on specified map #define EVO_LEVEL_NATURE_AMPED 33 // Pokémon reaches the specified level, it has a Hardy, Brave, Adamant, Naughty, Docile, Impish, Lax, Hasty, Jolly, Naive, Rash, Sassy, or Quirky nature. #define EVO_LEVEL_NATURE_LOW_KEY 34 // Pokémon reaches the specified level, it has a Lonely, Bold, Relaxed, Timid, Serious, Modest, Mild, Quiet, Bashful, Calm, Gentle, or Careful nature. +#define EVO_CRITICAL_HITS 35 // Pokémon performs specified number of critical hits in one battle #define EVOS_PER_MON 10 @@ -387,6 +388,7 @@ #define EVO_MODE_TRADE 1 #define EVO_MODE_ITEM_USE 2 #define EVO_MODE_ITEM_CHECK 3 // If an Everstone is being held, still want to show that the stone *could* be used on that Pokémon to evolve +#define EVO_MODE_BATTLE_SPECIAL 4 #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 479cafae6a..ca59ff86ef 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -115,6 +115,7 @@ 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); EWRAM_DATA u16 gBattle_BG0_X = 0; EWRAM_DATA u16 gBattle_BG0_Y = 0; @@ -237,6 +238,8 @@ EWRAM_DATA bool8 gHasFetchedBall = FALSE; EWRAM_DATA u8 gLastUsedBall = 0; EWRAM_DATA u16 gLastThrownBall = 0; EWRAM_DATA bool8 gSwapDamageCategory = FALSE; // Photon Geyser, Shell Side Arm, Light That Burns the Sky +EWRAM_DATA u8 gPartyCriticalHits[PARTY_SIZE] = {0}; +EWRAM_DATA static u8 sTriedEvolving = 0; void (*gPreBattleCallback1)(void); void (*gBattleMainFunc)(void); @@ -2999,6 +3002,7 @@ static void BattleStartClearSetData(void) gBattleStruct->usedHeldItems[i][0] = 0; gBattleStruct->usedHeldItems[i][1] = 0; gBattleStruct->itemStolen[i].originalItem = GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM); + gPartyCriticalHits[i] = 0; } gSwapDamageCategory = FALSE; // Photon Geyser, Shell Side Arm, Light That Burns the Sky @@ -5154,9 +5158,16 @@ static void FreeResetData_ReturnToOvOrDoEvolutions(void) gIsFishingEncounter = FALSE; gIsSurfingEncounter = FALSE; ResetSpriteData(); - if (gLeveledUpInBattle && (gBattleOutcome == B_OUTCOME_WON || gBattleOutcome == B_OUTCOME_CAUGHT)) + if (!(gBattleTypeFlags & (BATTLE_TYPE_LINK + | BATTLE_TYPE_RECORDED_LINK + | BATTLE_TYPE_FIRST_BATTLE + | BATTLE_TYPE_SAFARI + | BATTLE_TYPE_FRONTIER + | BATTLE_TYPE_EREADER_TRAINER + | BATTLE_TYPE_WALLY_TUTORIAL)) + && (gBattleOutcome == B_OUTCOME_WON || gBattleOutcome == B_OUTCOME_CAUGHT)) { - gBattleMainFunc = TryEvolvePokemon; + gBattleMainFunc = TrySpecialEvolution; } else { @@ -5174,6 +5185,26 @@ static void FreeResetData_ReturnToOvOrDoEvolutions(void) } } +static void TrySpecialEvolution(void) // Attempts to perform non-level related battle evolutions (not the script command). +{ + s32 i; + + for (i = 0; i < PARTY_SIZE; i++) + { + u16 species = GetEvolutionTargetSpecies(&gPlayerParty[i], EVO_MODE_BATTLE_SPECIAL, i, SPECIES_NONE); + if (species != SPECIES_NONE && !(sTriedEvolving & gBitTable[i])) + { + sTriedEvolving |= gBitTable[i]; + FreeAllWindowBuffers(); + gBattleMainFunc = WaitForEvoSceneToFinish; + EvolutionScene(&gPlayerParty[i], species, TRUE, i); + return; + } + } + sTriedEvolving = 0; + gBattleMainFunc = TryEvolvePokemon; +} + static void TryEvolvePokemon(void) { s32 i; @@ -5208,7 +5239,7 @@ static void TryEvolvePokemon(void) static void WaitForEvoSceneToFinish(void) { if (gMain.callback2 == BattleMainCB2) - gBattleMainFunc = TryEvolvePokemon; + gBattleMainFunc = TrySpecialEvolution; } static void ReturnFromBattleToOverworld(void) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index d6edb0ab2d..4ae67d1a28 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -1914,6 +1914,7 @@ s8 GetInverseCritChance(u8 battlerAtk, u8 battlerDef, u32 move) static void Cmd_critcalc(void) { + u16 partySlot; s32 critChance = CalcCritChanceStage(gBattlerAttacker, gBattlerTarget, gCurrentMove, TRUE); gPotentialItemEffectBattler = gBattlerAttacker; @@ -1928,6 +1929,12 @@ static void Cmd_critcalc(void) else gIsCriticalHit = FALSE; + // Counter for EVO_CRITICAL_HITS. + partySlot = gBattlerPartyIndexes[gBattlerAttacker]; + if (gIsCriticalHit && GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER + && !(gBattleTypeFlags & BATTLE_TYPE_MULTI && GetBattlerPosition(gBattlerAttacker) == B_POSITION_PLAYER_LEFT)) + gPartyCriticalHits[partySlot]++; + gBattlescriptCurrInstr++; } diff --git a/src/pokemon.c b/src/pokemon.c index 71176d2eb6..ff2dcbe510 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -5394,6 +5394,19 @@ u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 mode, u16 evolutionItem) } } break; + // Battle evolution without leveling; party slot is being passed into the evolutionItem arg. + case EVO_MODE_BATTLE_SPECIAL: + for (i = 0; i < EVOS_PER_MON; i++) + { + switch (gEvolutionTable[species][i].method) + { + case EVO_CRITICAL_HITS: + if (gPartyCriticalHits[evolutionItem] >= gEvolutionTable[species][i].param) + targetSpecies = gEvolutionTable[species][i].targetSpecies; + break; + } + } + break; } return targetSpecies; From e343c73cd8cd3ad16bd045f9cf8b48b00f05f638 Mon Sep 17 00:00:00 2001 From: AgustinGDLV Date: Thu, 5 May 2022 15:17:31 -0700 Subject: [PATCH 2/6] fixed compile error + small tweaks --- src/battle_main.c | 6 +++++- src/pokemon.c | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/battle_main.c b/src/battle_main.c index ca59ff86ef..ee61660622 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -5191,7 +5191,11 @@ static void TrySpecialEvolution(void) // Attempts to perform non-level related b for (i = 0; i < PARTY_SIZE; i++) { - u16 species = GetEvolutionTargetSpecies(&gPlayerParty[i], EVO_MODE_BATTLE_SPECIAL, i, SPECIES_NONE); + #ifndef POKEMON_EXPANSION + u16 species = GetEvolutionTargetSpecies(&gPlayerParty[i], EVO_MODE_BATTLE_SPECIAL, i); + #else + u16 species = GetEvolutionTargetSpecies(&gPlayerParty[i], EVO_MODE_BATTLE_SPECIAL, i, SPECIES_NONE); + #endif if (species != SPECIES_NONE && !(sTriedEvolving & gBitTable[i])) { sTriedEvolving |= gBitTable[i]; diff --git a/src/pokemon.c b/src/pokemon.c index ff2dcbe510..fe2bcf9dd7 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -5394,6 +5394,7 @@ u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 mode, u16 evolutionItem) } } break; + #ifdef BATTLE_ENGINE // Battle evolution without leveling; party slot is being passed into the evolutionItem arg. case EVO_MODE_BATTLE_SPECIAL: for (i = 0; i < EVOS_PER_MON; i++) @@ -5407,6 +5408,7 @@ u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 mode, u16 evolutionItem) } } break; + #endif } return targetSpecies; From e730d64945b95aba49eaf924ef29c553abd2e433 Mon Sep 17 00:00:00 2001 From: AgustinGDLV Date: Thu, 5 May 2022 15:54:33 -0700 Subject: [PATCH 3/6] corrections --- include/battle.h | 1 + src/pokemon.c | 15 --------------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/include/battle.h b/include/battle.h index 4068454bf4..fde4162c73 100644 --- a/include/battle.h +++ b/include/battle.h @@ -932,5 +932,6 @@ extern bool8 gHasFetchedBall; extern u8 gLastUsedBall; extern u16 gLastThrownBall; extern bool8 gSwapDamageCategory; // Photon Geyser, Shell Side Arm, Light That Burns the Sky +extern u8 gPartyCriticalHits[PARTY_SIZE]; #endif // GUARD_BATTLE_H diff --git a/src/pokemon.c b/src/pokemon.c index fe2bcf9dd7..71176d2eb6 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -5394,21 +5394,6 @@ u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 mode, u16 evolutionItem) } } break; - #ifdef BATTLE_ENGINE - // Battle evolution without leveling; party slot is being passed into the evolutionItem arg. - case EVO_MODE_BATTLE_SPECIAL: - for (i = 0; i < EVOS_PER_MON; i++) - { - switch (gEvolutionTable[species][i].method) - { - case EVO_CRITICAL_HITS: - if (gPartyCriticalHits[evolutionItem] >= gEvolutionTable[species][i].param) - targetSpecies = gEvolutionTable[species][i].targetSpecies; - break; - } - } - break; - #endif } return targetSpecies; From 017f44f5ac2ec86cc5d9182bfa6cedd02d8da489 Mon Sep 17 00:00:00 2001 From: AgustinGDLV <103095241+AgustinGDLV@users.noreply.github.com> Date: Sat, 7 May 2022 09:35:00 -0700 Subject: [PATCH 4/6] Apply suggestions from code review Co-authored-by: Eduardo Quezada D'Ottone --- include/constants/pokemon.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/include/constants/pokemon.h b/include/constants/pokemon.h index a7f0e3e4ed..b1aea3334e 100644 --- a/include/constants/pokemon.h +++ b/include/constants/pokemon.h @@ -380,15 +380,20 @@ #define EVO_LEVEL_NATURE_AMPED 33 // Pokémon reaches the specified level, it has a Hardy, Brave, Adamant, Naughty, Docile, Impish, Lax, Hasty, Jolly, Naive, Rash, Sassy, or Quirky nature. #define EVO_LEVEL_NATURE_LOW_KEY 34 // Pokémon reaches the specified level, it has a Lonely, Bold, Relaxed, Timid, Serious, Modest, Mild, Quiet, Bashful, Calm, Gentle, or Careful nature. #define EVO_CRITICAL_HITS 35 // Pokémon performs specified number of critical hits in one battle +#define EVO_SCRIPT_TRIGGER_DMG 36 // Pokémon has specified HP below max, then player interacts trigger +#define EVO_DARK_SCROLL 37 // interacts with Scroll of Darkness +#define EVO_WATER_SCROLL 38 // interacts with Scroll of Waters #define EVOS_PER_MON 10 // Evolution 'modes,' for GetEvolutionTargetSpecies #define EVO_MODE_NORMAL 0 -#define EVO_MODE_TRADE 1 -#define EVO_MODE_ITEM_USE 2 -#define EVO_MODE_ITEM_CHECK 3 // If an Everstone is being held, still want to show that the stone *could* be used on that Pokémon to evolve -#define EVO_MODE_BATTLE_SPECIAL 4 +#define EVO_MODE_NORMAL 0 +#define EVO_MODE_TRADE 1 +#define EVO_MODE_ITEM_USE 2 +#define EVO_MODE_ITEM_CHECK 3 // If an Everstone is being held, still want to show that the stone *could* be used on that Pokémon to evolve +#define EVO_MODE_BATTLE_SPECIAL 4 +#define EVO_MODE_OVERWORLD_SPECIAL 5 #define NUM_MALE_LINK_FACILITY_CLASSES 8 #define NUM_FEMALE_LINK_FACILITY_CLASSES 8 From 277f4a37511495a567b2f671e9b0ac64eb69db70 Mon Sep 17 00:00:00 2001 From: AgustinGDLV <103095241+AgustinGDLV@users.noreply.github.com> Date: Sun, 8 May 2022 21:23:06 -0700 Subject: [PATCH 5/6] niceties Co-authored-by: Eduardo Quezada D'Ottone --- src/battle_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/battle_main.c b/src/battle_main.c index ee61660622..fbe132eaef 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -5194,7 +5194,7 @@ static void TrySpecialEvolution(void) // Attempts to perform non-level related b #ifndef POKEMON_EXPANSION u16 species = GetEvolutionTargetSpecies(&gPlayerParty[i], EVO_MODE_BATTLE_SPECIAL, i); #else - u16 species = GetEvolutionTargetSpecies(&gPlayerParty[i], EVO_MODE_BATTLE_SPECIAL, i, SPECIES_NONE); + u16 species = GetEvolutionTargetSpecies(&gPlayerParty[i], EVO_MODE_BATTLE_SPECIAL, i, NULL); #endif if (species != SPECIES_NONE && !(sTriedEvolving & gBitTable[i])) { From 9bb5db2275e42ace6bb34b384659e4f8136505c5 Mon Sep 17 00:00:00 2001 From: AgustinGDLV Date: Sun, 8 May 2022 21:23:51 -0700 Subject: [PATCH 6/6] removed duplicate define --- include/constants/pokemon.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/constants/pokemon.h b/include/constants/pokemon.h index b1aea3334e..13db5644ef 100644 --- a/include/constants/pokemon.h +++ b/include/constants/pokemon.h @@ -387,7 +387,6 @@ #define EVOS_PER_MON 10 // Evolution 'modes,' for GetEvolutionTargetSpecies -#define EVO_MODE_NORMAL 0 #define EVO_MODE_NORMAL 0 #define EVO_MODE_TRADE 1 #define EVO_MODE_ITEM_USE 2