diff --git a/include/battle.h b/include/battle.h index 1251239d1e..0a73bd79a5 100644 --- a/include/battle.h +++ b/include/battle.h @@ -250,6 +250,7 @@ struct SpecialStatus u8 emergencyExited:1; u8 afterYou:1; u8 preventLifeOrbDamage:1; // So that Life Orb doesn't activate various effects. + u8 distortedTypeMatchups:1; }; struct SideTimer @@ -823,7 +824,6 @@ struct BattleStruct u8 shellSideArmCategory[MAX_BATTLERS_COUNT][MAX_BATTLERS_COUNT]; u8 speedTieBreaks; // MAX_BATTLERS_COUNT! values. u8 boosterEnergyActivates; - u8 distortedTypeMatchups; u8 categoryOverride; // for Z-Moves and Max Moves u8 commandingDondozo; u16 commanderActive[MAX_BATTLERS_COUNT]; diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index f7823f1ff7..0293e00f34 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -1171,7 +1171,7 @@ bool32 ProteanTryChangeType(u32 battler, u32 ability, u32 move, u32 moveType) bool32 ShouldTeraShellDistortTypeMatchups(u32 move, u32 battlerDef) { - if (!(gBattleStruct->distortedTypeMatchups & (1u << battlerDef)) + if (!gSpecialStatuses[battlerDef].distortedTypeMatchups && GetBattlerAbility(battlerDef) == ABILITY_TERA_SHELL && gBattleMons[battlerDef].species == SPECIES_TERAPAGOS_TERASTAL && !IS_MOVE_STATUS(move) @@ -1893,7 +1893,7 @@ static void Cmd_ppreduce(void) if (ShouldTeraShellDistortTypeMatchups(gCurrentMove, gBattlerTarget)) { - gBattleStruct->distortedTypeMatchups |= 1u << gBattlerTarget; + gSpecialStatuses[gBattlerTarget].distortedTypeMatchups = TRUE; gBattlerAbility = gBattlerTarget; BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_TeraShellDistortingTypeMatchups; @@ -1950,19 +1950,21 @@ static inline u32 GetHoldEffectCritChanceIncrease(u32 battler, u32 holdEffect) return critStageIncrease; } +#define CRITICAL_HIT_BLOCKED -1 +#define CRITICAL_HIT_ALWAYS -2 s32 CalcCritChanceStageArgs(u32 battlerAtk, u32 battlerDef, u32 move, bool32 recordAbility, u32 abilityAtk, u32 abilityDef, u32 holdEffectAtk) { s32 critChance = 0; if (gSideStatuses[battlerDef] & SIDE_STATUS_LUCKY_CHANT) { - critChance = -1; + critChance = CRITICAL_HIT_BLOCKED; } else if (gStatuses3[battlerAtk] & STATUS3_LASER_FOCUS || gMovesInfo[move].alwaysCriticalHit || (abilityAtk == ABILITY_MERCILESS && gBattleMons[battlerDef].status1 & STATUS1_PSN_ANY)) { - critChance = -2; + critChance = CRITICAL_HIT_ALWAYS; } else { @@ -1978,21 +1980,23 @@ s32 CalcCritChanceStageArgs(u32 battlerAtk, u32 battlerDef, u32 move, bool32 rec critChance = ARRAY_COUNT(sCriticalHitOdds) - 1; } - if (critChance != -1 && (abilityDef == ABILITY_BATTLE_ARMOR || abilityDef == ABILITY_SHELL_ARMOR)) + if (critChance != CRITICAL_HIT_BLOCKED && (abilityDef == ABILITY_BATTLE_ARMOR || abilityDef == ABILITY_SHELL_ARMOR)) { // Record ability only if move had 100% chance to get a crit if (recordAbility) { - if (critChance == -2) + if (critChance == CRITICAL_HIT_ALWAYS) RecordAbilityBattle(battlerDef, abilityDef); else if (GetCriticalHitOdds(critChance) == 1) RecordAbilityBattle(battlerDef, abilityDef); } - critChance = -1; + critChance = CRITICAL_HIT_BLOCKED; } return critChance; } +#undef CRIT_BLOCKED +#undef ALWAYS_CRITS s32 CalcCritChanceStage(u32 battlerAtk, u32 battlerDef, u32 move, bool32 recordAbility) { @@ -6631,6 +6635,7 @@ static void Cmd_moveend(void) gSpecialStatuses[gBattlerAttacker].damagedMons = 0; gSpecialStatuses[gBattlerAttacker].preventLifeOrbDamage = 0; gSpecialStatuses[gBattlerTarget].berryReduced = FALSE; + gSpecialStatuses[gBattlerTarget].distortedTypeMatchups = FALSE; gBattleScripting.moveEffect = 0; gBattleStruct->hitSwitchTargetFailed = FALSE; gBattleStruct->isAtkCancelerForCalledMove = FALSE; @@ -6642,7 +6647,6 @@ static void Cmd_moveend(void) gBattleStruct->additionalEffectsCounter = 0; gBattleStruct->poisonPuppeteerConfusion = FALSE; gBattleStruct->fickleBeamBoosted = FALSE; - gBattleStruct->distortedTypeMatchups = 0; gBattleStruct->redCardActivates = FALSE; gBattleStruct->usedMicleBerry &= ~(1u << gBattlerAttacker); if (gHitMarker & HITMARKER_UNABLE_TO_USE_MOVE) diff --git a/src/battle_util.c b/src/battle_util.c index da38c78772..827218bee0 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -10428,7 +10428,7 @@ static inline void MulByTypeEffectiveness(uq4_12_t *modifier, u32 move, u32 move mod = UQ_4_12(1.0); } - if (gBattleStruct->distortedTypeMatchups & (1u << battlerDef) || (AI_DATA->aiCalcInProgress && ShouldTeraShellDistortTypeMatchups(move, battlerDef))) + if (gSpecialStatuses[battlerDef].distortedTypeMatchups || (AI_DATA->aiCalcInProgress && ShouldTeraShellDistortTypeMatchups(move, battlerDef))) { mod = UQ_4_12(0.5); if (recordAbilities)