From 4794c63066dd6318827eb95e954137c98910d0e2 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Wed, 21 Oct 2020 11:44:03 -0300 Subject: [PATCH] Reincorporated badge based stat boosts --- include/battle_util.h | 1 + include/constants/battle_config.h | 1 + src/battle_main.c | 3 ++- src/battle_util.c | 33 +++++++++++++++++++++++++++++++ src/pokemon.c | 15 -------------- 5 files changed, 37 insertions(+), 16 deletions(-) diff --git a/include/battle_util.h b/include/battle_util.h index 2bd6c8cb13..330c0bfb96 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -127,5 +127,6 @@ bool32 CanBattlerGetOrLoseItem(u8 battlerId, u16 itemId); struct Pokemon *GetIllusionMonPtr(u32 battlerId); void ClearIllusionMon(u32 battlerId); bool32 SetIllusionMon(struct Pokemon *mon, u32 battlerId); +static bool8 ShouldGetStatBadgeBoost(u16 flagId, u8 battlerId); #endif // GUARD_BATTLE_UTIL_H diff --git a/include/constants/battle_config.h b/include/constants/battle_config.h index dd2fd4186e..74e5f24fcf 100644 --- a/include/constants/battle_config.h +++ b/include/constants/battle_config.h @@ -70,6 +70,7 @@ #define B_MULTI_HIT_CHANCE GEN_6 // In Gen5+, multi-hit moves have different %. See Cmd_setmultihitcounter for values. #define B_RECOIL_IF_MISS_DMG GEN_6 // In Gen5+, Jump Kick and Hi Jump Kick will always do half of the user's max HP when missing. #define B_PSYWAVE_DMG GEN_6 // Psywave's damage formula. See Cmd_psywavedamageeffect. +#define B_BADGE_BOOST GEN_4 // In Gen4+, Gym Badges no longer boost a Pokémon's stats // Move settings #define B_FELL_STINGER_STAT_RAISE GEN_6 // In Gen7+, it raises Atk by 3 stages instead of 2 if it causes the target to faint. diff --git a/src/battle_main.c b/src/battle_main.c index 3617978efa..830ea0c7a7 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -4236,7 +4236,8 @@ u32 GetBattlerTotalSpeedStat(u8 battlerId) // player's badge boost if (!(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000 | BATTLE_TYPE_FRONTIER)) && FlagGet(FLAG_BADGE03_GET) - && GetBattlerSide(battlerId) == B_SIDE_PLAYER) + && GetBattlerSide(battlerId) == B_SIDE_PLAYER + && B_BADGE_BOOST == GEN_3) { speed = (speed * 110) / 100; } diff --git a/src/battle_util.c b/src/battle_util.c index c31c2c9d9c..c5aae0db83 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -40,6 +40,7 @@ #include "trig.h" #include "window.h" #include "constants/songs.h" +#include "constants/trainers.h" extern const u8 *const gBattleScriptsForMoveEffects[]; extern const u8 *const gBattlescriptsForBallThrow[]; @@ -6936,6 +6937,15 @@ static u32 CalcAttackStat(u16 move, u8 battlerAtk, u8 battlerDef, u8 moveType, b break; } + // The attack stat of a Player's Pokémon is boosted by x1.1 (+10%) if they have the 1st and 7th Badges + if (B_BADGE_BOOST == GEN_3) + { + if (ShouldGetStatBadgeBoost(FLAG_BADGE01_GET, battlerAtk) && !(IS_MOVE_SPECIAL(move))) + MulModifier(&modifier, UQ_4_12(1.1)); + if (ShouldGetStatBadgeBoost(FLAG_BADGE07_GET, battlerAtk) && IS_MOVE_SPECIAL(move)) + MulModifier(&modifier, UQ_4_12(1.1)); + } + return ApplyModifier(modifier, atkStat); } @@ -7068,6 +7078,15 @@ static u32 CalcDefenseStat(u16 move, u8 battlerAtk, u8 battlerDef, u8 moveType, if (IS_BATTLER_OF_TYPE(battlerDef, TYPE_ROCK) && WEATHER_HAS_EFFECT && gBattleWeather & WEATHER_SANDSTORM_ANY && !usesDefStat) MulModifier(&modifier, UQ_4_12(1.5)); + // The defense stat of a Player's Pokémon is boosted by x1.1 (+10%) if they have the 5th and 7th Badges + if (B_BADGE_BOOST == GEN_3) + { + if (ShouldGetStatBadgeBoost(FLAG_BADGE05_GET, battlerDef) && IS_MOVE_PHYSICAL(move)) + MulModifier(&modifier, UQ_4_12(1.1)); + if (ShouldGetStatBadgeBoost(FLAG_BADGE07_GET, battlerDef) && !(IS_MOVE_PHYSICAL(move))) + MulModifier(&modifier, UQ_4_12(1.1)); + } + return ApplyModifier(modifier, defStat); } @@ -7664,3 +7683,17 @@ bool32 SetIllusionMon(struct Pokemon *mon, u32 battlerId) return FALSE; } + +static bool8 ShouldGetStatBadgeBoost(u16 badgeFlag, u8 battlerId) +{ + if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_EREADER_TRAINER | BATTLE_TYPE_x2000000 | BATTLE_TYPE_FRONTIER)) + return FALSE; + else if (GetBattlerSide(battlerId) != B_SIDE_PLAYER) + return FALSE; + else if (gBattleTypeFlags & BATTLE_TYPE_TRAINER && gTrainerBattleOpponent_A == TRAINER_SECRET_BASE) + return FALSE; + else if (FlagGet(badgeFlag)) + return TRUE; + else + return FALSE; +} diff --git a/src/pokemon.c b/src/pokemon.c index ed890c7df2..79310e1b2d 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -58,7 +58,6 @@ static union PokemonSubstruct *GetSubstruct(struct BoxPokemon *boxMon, u32 perso static void EncryptBoxMon(struct BoxPokemon *boxMon); static void DecryptBoxMon(struct BoxPokemon *boxMon); static void sub_806E6CC(u8 taskId); -static bool8 ShouldGetStatBadgeBoost(u16 flagId, u8 battlerId); static u16 GiveMoveToBoxMon(struct BoxPokemon *boxMon, u16 move); static bool8 ShouldSkipFriendshipChange(void); @@ -3076,20 +3075,6 @@ u8 CountAliveMonsInBattle(u8 caseId) return retVal; } -static bool8 ShouldGetStatBadgeBoost(u16 badgeFlag, u8 battlerId) -{ - if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_EREADER_TRAINER | BATTLE_TYPE_x2000000 | BATTLE_TYPE_FRONTIER)) - return FALSE; - else if (GetBattlerSide(battlerId) != B_SIDE_PLAYER) - return FALSE; - else if (gBattleTypeFlags & BATTLE_TYPE_TRAINER && gTrainerBattleOpponent_A == TRAINER_SECRET_BASE) - return FALSE; - else if (FlagGet(badgeFlag)) - return TRUE; - else - return FALSE; -} - u8 GetDefaultMoveTarget(u8 battlerId) { u8 opposing = BATTLE_OPPOSITE(GetBattlerPosition(battlerId) & BIT_SIDE);