From 922bbacd7192a98db2b2422041fcd0d5623b6111 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Fri, 26 Aug 2022 17:47:07 -0300 Subject: [PATCH 1/4] Updated GetMonFriendshipScore -Moved it to src/pokemon.c -Made a battle specific variant called GetBattlerFriendshipScore. -Made that variant return 0 for Mega Evolved 'mons and if called on link battles. --- include/battle.h | 1 + include/battle_util.h | 2 +- include/pokemon.h | 1 + src/battle_script_commands.c | 9 +++++---- src/battle_util.c | 31 +++++++++++++++---------------- src/pokemon.c | 20 ++++++++++++++++++++ 6 files changed, 43 insertions(+), 21 deletions(-) diff --git a/include/battle.h b/include/battle.h index 36ffdb6da0..82993b73e2 100644 --- a/include/battle.h +++ b/include/battle.h @@ -456,6 +456,7 @@ struct MegaEvolutionData bool8 playerSelect; u8 triggerSpriteId; bool8 isWishMegaEvo; + bool32 didMegaEvo[PARTY_SIZE][2]; // For each party member and side. }; struct Illusion diff --git a/include/battle_util.h b/include/battle_util.h index 5dbefd7e7e..9b8109c398 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -201,6 +201,6 @@ bool32 CanBeParalyzed(u8 battlerId); bool32 CanBeFrozen(u8 battlerId); bool32 CanBeConfused(u8 battlerId); bool32 IsBattlerTerrainAffected(u8 battlerId, u32 terrainFlag); -u32 GetMonFriendshipScore(struct Pokemon *pokemon); +u32 GetBattlerFriendshipScore(u8 battlerId); #endif // GUARD_BATTLE_UTIL_H diff --git a/include/pokemon.h b/include/pokemon.h index c05628a598..7a38508274 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -559,5 +559,6 @@ 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); +u32 GetMonFriendshipScore(struct Pokemon *pokemon); #endif // GUARD_POKEMON_H diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index a5a822546c..361abe2419 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -1734,7 +1734,7 @@ u32 GetTotalAccuracy(u32 battlerAtk, u32 battlerDef, u32 move, u32 atkAbility, u #if B_AFFECTION_MECHANICS == TRUE // With high affection/friendship there's a chance to evade a move by substracting 10% of its accuracy. // I can't find exact information about that chance, so I'm just gonna write it as a 20% chance for now. - if (GetMonFriendshipScore(&gPlayerParty[gBattlerPartyIndexes[battlerDef]]) >= FRIENDSHIP_150_TO_199 && (Random() % 100) <= 20) + if (GetMonFriendshipScore(battlerDef) >= FRIENDSHIP_150_TO_199 && (Random() % 100) <= 20) calc = (calc * 90) / 100; #endif @@ -1907,7 +1907,7 @@ s32 CalcCritChanceStage(u8 battlerAtk, u8 battlerDef, u32 move, bool32 recordAbi + 2 * (holdEffectAtk == HOLD_EFFECT_LUCKY_PUNCH && gBattleMons[gBattlerAttacker].species == SPECIES_CHANSEY) + 2 * BENEFITS_FROM_LEEK(battlerAtk, holdEffectAtk) #if B_AFFECTION_MECHANICS == TRUE - + 2 * (GetMonFriendshipScore(&gPlayerParty[gBattlerPartyIndexes[gBattlerAttacker]]) >= FRIENDSHIP_200_TO_254) + + 2 * (GetMonFriendshipScore(gBattlerAttacker) >= FRIENDSHIP_200_TO_254) #endif + (abilityAtk == ABILITY_SUPER_LUCK); @@ -1977,7 +1977,7 @@ static void Cmd_adjustdamage(void) { u8 holdEffect, param; u32 moveType; - u32 friendshipScore = GetMonFriendshipScore(&gPlayerParty[gBattlerPartyIndexes[gBattlerTarget]]); + u32 friendshipScore = GetBattlerFriendshipScore(gBattlerTarget); u32 rand = Random() % 100; GET_MOVE_TYPE(gCurrentMove, moveType); @@ -4063,7 +4063,7 @@ static void Cmd_getexp(void) } #endif #if B_AFFECTION_MECHANICS == TRUE - if (GetMonFriendshipScore(&gPlayerParty[gBattleStruct->expGetterMonId]) >= FRIENDSHIP_50_TO_99) + if (GetMonFriendshipScore(gBattleStruct->expGetterMonId) >= FRIENDSHIP_50_TO_99) gBattleMoveDamage = (gBattleMoveDamage * 120) / 100; #endif @@ -8652,6 +8652,7 @@ static void Cmd_various(void) gBattleMons[gActiveBattler].species = megaSpecies; PREPARE_SPECIES_BUFFER(gBattleTextBuff1, gBattleMons[gActiveBattler].species); + gBattleStruct->mega.didMegaEvo[gActiveBattler][GetBattlerSide(gActiveBattler)] = TRUE; BtlController_EmitSetMonData(BUFFER_A, REQUEST_SPECIES_BATTLE, gBitTable[gBattlerPartyIndexes[gActiveBattler]], sizeof(gBattleMons[gActiveBattler].species), &gBattleMons[gActiveBattler].species); MarkBattlerForControllerExec(gActiveBattler); diff --git a/src/battle_util.c b/src/battle_util.c index f38d80a69c..5cb2badb0e 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -2104,24 +2104,23 @@ void TryToRevertMimicry(void) } } -u32 GetMonFriendshipScore(struct Pokemon *pokemon) +u32 GetBattlerFriendshipScore(u8 battlerId) { - u32 friendshipScore = GetMonData(pokemon, MON_DATA_FRIENDSHIP); + struct MegaEvolutionData *mega = &(((struct ChooseMoveStruct *)(&gBattleResources->bufferA[battlerId][4]))->mega); + u8 side = GetBattlerSide(battlerId); + struct Pokemon *party = (side == B_SIDE_PLAYER) ? gPlayerParty : gEnemyParty; - if (friendshipScore == MAX_FRIENDSHIP) - return FRIENDSHIP_MAX; - if (friendshipScore >= 200) - return FRIENDSHIP_200_TO_254; - if (friendshipScore >= 150) - return FRIENDSHIP_150_TO_199; - if (friendshipScore >= 100) - return FRIENDSHIP_100_TO_149; - if (friendshipScore >= 50) - return FRIENDSHIP_50_TO_99; - if (friendshipScore >= 1) - return FRIENDSHIP_1_TO_49; + if (side != B_SIDE_PLAYER) + return FRIENDSHIP_NONE; + else if (gBattleStruct->mega.didMegaEvo[battlerId][side] + || (gBattleTypeFlags & (BATTLE_TYPE_EREADER_TRAINER + | BATTLE_TYPE_FRONTIER + | BATTLE_TYPE_LINK + | BATTLE_TYPE_RECORDED_LINK + | BATTLE_TYPE_SECRET_BASE))) + return FRIENDSHIP_NONE; - return FRIENDSHIP_NONE; + return GetMonFriendshipScore(&party[gBattlerPartyIndexes[battlerId]]); } enum @@ -2605,7 +2604,7 @@ u8 DoFieldEndTurnEffects(void) { #if B_AFFECTION_MECHANICS == TRUE if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER - && GetMonFriendshipScore(&gPlayerParty[gBattlerPartyIndexes[gBattlerAttacker]]) >= FRIENDSHIP_150_TO_199 + && GetBattlerFriendshipScore(gBattlerAttacker) >= FRIENDSHIP_150_TO_199 && (Random() % 100 < 20)) { gBattleCommunication[MULTISTRING_CHOOSER] = 1; diff --git a/src/pokemon.c b/src/pokemon.c index 92bd923f08..61c72c363e 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -8384,3 +8384,23 @@ bool32 ShouldShowFemaleDifferences(u16 species, u32 personality) { return (gBaseStats[species].flags & FLAG_GENDER_DIFFERENCE) && GetGenderFromSpeciesAndPersonality(species, personality) == MON_FEMALE; } + +u32 GetMonFriendshipScore(struct Pokemon *pokemon) +{ + u32 friendshipScore = GetMonData(pokemon, MON_DATA_FRIENDSHIP, NULL); + + if (friendshipScore == MAX_FRIENDSHIP) + return FRIENDSHIP_MAX; + if (friendshipScore >= 200) + return FRIENDSHIP_200_TO_254; + if (friendshipScore >= 150) + return FRIENDSHIP_150_TO_199; + if (friendshipScore >= 100) + return FRIENDSHIP_100_TO_149; + if (friendshipScore >= 50) + return FRIENDSHIP_50_TO_99; + if (friendshipScore >= 1) + return FRIENDSHIP_1_TO_49; + + return FRIENDSHIP_NONE; +} From 452b135c7f15bd7a0354f97bc51335da90090c32 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Wed, 31 Aug 2022 17:48:22 -0300 Subject: [PATCH 2/4] I forgot to replace the function calls where appropriate :P --- src/battle_anim_new.c | 3 ++- src/battle_script_commands.c | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/battle_anim_new.c b/src/battle_anim_new.c index 35c1244670..a120b69a78 100644 --- a/src/battle_anim_new.c +++ b/src/battle_anim_new.c @@ -19,6 +19,7 @@ #include "constants/hold_effects.h" #include "constants/items.h" #include "constants/pokemon.h" +#include "battle_util.h" // function declarations static void SpriteCB_SpriteToCentreOfSide(struct Sprite *sprite); @@ -7899,6 +7900,6 @@ void AnimTask_AffectionHangedOn(u8 taskId) int side = GetBattlerSide(gBattleAnimTarget); struct Pokemon *party = (side == B_SIDE_PLAYER) ? gPlayerParty : gEnemyParty; - gBattleAnimArgs[0] = GetMonFriendshipScore(&party[gBattlerPartyIndexes[gBattleAnimTarget]]); + gBattleAnimArgs[0] = GetBattlerFriendshipScore(gBattleAnimTarget); DestroyAnimVisualTask(taskId); } diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 361abe2419..52818dc38e 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -1734,7 +1734,7 @@ u32 GetTotalAccuracy(u32 battlerAtk, u32 battlerDef, u32 move, u32 atkAbility, u #if B_AFFECTION_MECHANICS == TRUE // With high affection/friendship there's a chance to evade a move by substracting 10% of its accuracy. // I can't find exact information about that chance, so I'm just gonna write it as a 20% chance for now. - if (GetMonFriendshipScore(battlerDef) >= FRIENDSHIP_150_TO_199 && (Random() % 100) <= 20) + if (GetBattlerFriendshipScore(battlerDef) >= FRIENDSHIP_150_TO_199 && (Random() % 100) <= 20) calc = (calc * 90) / 100; #endif @@ -1907,7 +1907,7 @@ s32 CalcCritChanceStage(u8 battlerAtk, u8 battlerDef, u32 move, bool32 recordAbi + 2 * (holdEffectAtk == HOLD_EFFECT_LUCKY_PUNCH && gBattleMons[gBattlerAttacker].species == SPECIES_CHANSEY) + 2 * BENEFITS_FROM_LEEK(battlerAtk, holdEffectAtk) #if B_AFFECTION_MECHANICS == TRUE - + 2 * (GetMonFriendshipScore(gBattlerAttacker) >= FRIENDSHIP_200_TO_254) + + 2 * (GetBattlerFriendshipScore(gBattlerAttacker) >= FRIENDSHIP_200_TO_254) #endif + (abilityAtk == ABILITY_SUPER_LUCK); @@ -4063,7 +4063,7 @@ static void Cmd_getexp(void) } #endif #if B_AFFECTION_MECHANICS == TRUE - if (GetMonFriendshipScore(gBattleStruct->expGetterMonId) >= FRIENDSHIP_50_TO_99) + if (GetBattlerFriendshipScore(gBattleStruct->expGetterMonId) >= FRIENDSHIP_50_TO_99) gBattleMoveDamage = (gBattleMoveDamage * 120) / 100; #endif From 50ca188cb24e507c21be34859a5186d6d6f36d44 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Fri, 7 Oct 2022 12:25:12 -0300 Subject: [PATCH 3/4] Replaced didMegaEvo with a shiny new species flag --- include/battle.h | 1 - src/battle_script_commands.c | 1 - src/battle_util.c | 3 ++- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/include/battle.h b/include/battle.h index 29cc79d36b..b328b46bb2 100644 --- a/include/battle.h +++ b/include/battle.h @@ -479,7 +479,6 @@ struct MegaEvolutionData bool8 playerSelect; u8 triggerSpriteId; bool8 isWishMegaEvo; - bool32 didMegaEvo[PARTY_SIZE][2]; // For each party member and side. }; struct Illusion diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 1232775fd0..eaa7bbde1a 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -8840,7 +8840,6 @@ static void Cmd_various(void) gBattleMons[gActiveBattler].species = megaSpecies; PREPARE_SPECIES_BUFFER(gBattleTextBuff1, gBattleMons[gActiveBattler].species); - gBattleStruct->mega.didMegaEvo[gActiveBattler][GetBattlerSide(gActiveBattler)] = TRUE; BtlController_EmitSetMonData(BUFFER_A, REQUEST_SPECIES_BATTLE, gBitTable[gBattlerPartyIndexes[gActiveBattler]], sizeof(gBattleMons[gActiveBattler].species), &gBattleMons[gActiveBattler].species); MarkBattlerForControllerExec(gActiveBattler); diff --git a/src/battle_util.c b/src/battle_util.c index 0b0ab3a040..94fb078dac 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -2110,10 +2110,11 @@ u32 GetBattlerFriendshipScore(u8 battlerId) struct MegaEvolutionData *mega = &(((struct ChooseMoveStruct *)(&gBattleResources->bufferA[battlerId][4]))->mega); u8 side = GetBattlerSide(battlerId); struct Pokemon *party = (side == B_SIDE_PLAYER) ? gPlayerParty : gEnemyParty; + u16 species = GetMonData(&party[gBattlerPartyIndexes[battlerId]], MON_DATA_SPECIES); if (side != B_SIDE_PLAYER) return FRIENDSHIP_NONE; - else if (gBattleStruct->mega.didMegaEvo[battlerId][side] + else if (gBaseStats[species].flags & SPECIES_FLAG_MEGA_EVOLUTION || (gBattleTypeFlags & (BATTLE_TYPE_EREADER_TRAINER | BATTLE_TYPE_FRONTIER | BATTLE_TYPE_LINK From 589c969e89f4979eec7097013f7d2c025e26b0a0 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Fri, 7 Oct 2022 18:20:00 -0300 Subject: [PATCH 4/4] Removed unused access to struct MegaEvolutionData in GetBattlerFriendshipScore --- src/battle_util.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/battle_util.c b/src/battle_util.c index 94fb078dac..6cfb1801cf 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -2107,7 +2107,6 @@ void TryToRevertMimicry(void) u32 GetBattlerFriendshipScore(u8 battlerId) { - struct MegaEvolutionData *mega = &(((struct ChooseMoveStruct *)(&gBattleResources->bufferA[battlerId][4]))->mega); u8 side = GetBattlerSide(battlerId); struct Pokemon *party = (side == B_SIDE_PLAYER) ? gPlayerParty : gEnemyParty; u16 species = GetMonData(&party[gBattlerPartyIndexes[battlerId]], MON_DATA_SPECIES);