From d2bcc2ad5b550ba1d403749d756f6440b3acb169 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Wed, 1 Sep 2021 00:14:02 -0300 Subject: [PATCH 1/4] Added configs for modern post-battle stat calcs --- include/constants/battle_config.h | 2 ++ src/battle_script_commands.c | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/include/constants/battle_config.h b/include/constants/battle_config.h index bf31c77b3b..2b83b766f7 100644 --- a/include/constants/battle_config.h +++ b/include/constants/battle_config.h @@ -93,6 +93,8 @@ #define B_RECOIL_IF_MISS_DMG GEN_7 // In Gen5+, Jump Kick and High Jump Kick will always do half of the user's max HP when missing. #define B_PSYWAVE_DMG GEN_7 // Psywave's damage formula. See Cmd_psywavedamageeffect. #define B_BADGE_BOOST GEN_7 // In Gen4+, Gym Badges no longer boost a Pokémon's stats. +#define B_MAX_LEVEL_EV_GAINS GEN_7 // In Gen5+, Lv100 Pokémon can obtain Effort Values normally. +#define B_RECALCULATE_STATS GEN_7 // In Gen5+, the stats of the Pokémon who participate in battle are recalculated at the end of each battle. // Move data settings #define B_UPDATED_MOVE_DATA GEN_8 // Updates move data in gBattleMoves, including Power, Accuracy, PP, stat changes, targets, chances of secondary effects, etc. diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 21bc7945b9..eaceb85450 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -3783,6 +3783,9 @@ static void Cmd_getexp(void) *(&gBattleStruct->sentInPokes) >>= 1; gBattleScripting.getexpState = 5; gBattleMoveDamage = 0; // used for exp + #if B_MAX_LEVEL_EV_GAINS >= GEN_5 + MonGainEVs(&gPlayerParty[gBattleStruct->expGetterMonId], gBattleMons[gBattlerFainted].species); + #endif } else { @@ -3958,6 +3961,12 @@ static void Cmd_getexp(void) case 6: // increment instruction if (gBattleControllerExecFlags == 0) { + #if B_RECALCULATE_STATS >= GEN_5 + // Recalculate the stats of every party member before the end + for (i = 0; i < PARTY_SIZE; i++) + CalculateMonStats(&gPlayerParty[i]); + #endif + // not sure why gf clears the item and ability here gBattleMons[gBattlerFainted].item = 0; gBattleMons[gBattlerFainted].ability = 0; From 9990bda7a4e4610390ab92ff0eff90f2a0c7a174 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Wed, 1 Sep 2021 02:54:44 -0300 Subject: [PATCH 2/4] Fixed `if` statement for stat recalculation Thanks to Syreldar. --- src/battle_script_commands.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index eaceb85450..a3edf689ab 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -3964,7 +3964,14 @@ static void Cmd_getexp(void) #if B_RECALCULATE_STATS >= GEN_5 // Recalculate the stats of every party member before the end for (i = 0; i < PARTY_SIZE; i++) - CalculateMonStats(&gPlayerParty[i]); + { + if (GetMonData(&gPlayerParty[i], MON_DATA_HP) != 0 + && GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2) != SPECIES_NONE + && !GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG)) + { + CalculateMonStats(&gPlayerParty[i]); + } + } #endif // not sure why gf clears the item and ability here From 46fb92c4da8de0f7166a48c77a8a74fb3ee0351a Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Wed, 1 Sep 2021 17:40:12 -0300 Subject: [PATCH 3/4] Optimized checks --- src/battle_script_commands.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index a3edf689ab..1a2d90ac2e 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -3965,9 +3965,8 @@ static void Cmd_getexp(void) // Recalculate the stats of every party member before the end for (i = 0; i < PARTY_SIZE; i++) { - if (GetMonData(&gPlayerParty[i], MON_DATA_HP) != 0 - && GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2) != SPECIES_NONE - && !GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG)) + if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2) != SPECIES_NONE + && GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2) != SPECIES_EGG) { CalculateMonStats(&gPlayerParty[i]); } From 3113e4fa125b1e3d63f6453dec9c36c932f2b1a7 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Mon, 6 Sep 2021 07:40:21 -0300 Subject: [PATCH 4/4] Moved stat recalculation to `HandleEndTurn_FinishBattle` --- src/battle_main.c | 11 +++++++++++ src/battle_script_commands.c | 12 ------------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/battle_main.c b/src/battle_main.c index 282b850351..728d33d4e8 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -4880,6 +4880,17 @@ static void HandleEndTurn_FinishBattle(void) UndoMegaEvolution(i); UndoFormChange(i, B_SIDE_PLAYER, FALSE); } + #if B_RECALCULATE_STATS >= GEN_5 + // Recalculate the stats of every party member before the end + for (i = 0; i < PARTY_SIZE; i++) + { + if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2) != SPECIES_NONE + && GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2) != SPECIES_EGG) + { + CalculateMonStats(&gPlayerParty[i]); + } + } + #endif gBattleMainFunc = FreeResetData_ReturnToOvOrDoEvolutions; gCB2_AfterEvolution = BattleMainCB2; } diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 1a2d90ac2e..2d64f77958 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -3961,18 +3961,6 @@ static void Cmd_getexp(void) case 6: // increment instruction if (gBattleControllerExecFlags == 0) { - #if B_RECALCULATE_STATS >= GEN_5 - // Recalculate the stats of every party member before the end - for (i = 0; i < PARTY_SIZE; i++) - { - if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2) != SPECIES_NONE - && GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2) != SPECIES_EGG) - { - CalculateMonStats(&gPlayerParty[i]); - } - } - #endif - // not sure why gf clears the item and ability here gBattleMons[gBattlerFainted].item = 0; gBattleMons[gBattlerFainted].ability = 0;