From 32044548537874b1e3352377fa704d1ae248c1ed Mon Sep 17 00:00:00 2001 From: AlexOn1ine Date: Tue, 12 Nov 2024 23:27:53 +0100 Subject: [PATCH] Critical Hit documentation and distorted match up struct switch --- include/battle.h | 2 +- src/battle_script_commands.c | 20 ++++++++++++-------- src/battle_util.c | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/include/battle.h b/include/battle.h index f7b41b3dce..8e30a34add 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[NUM_BATTLE_SIDES]; diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 9ea2920bb9..94dbc20eaa 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 CRIT_BLOCKED -1 +#define ALWAYS_CRITS -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 = CRIT_BLOCKED; } else if (gStatuses3[battlerAtk] & STATUS3_LASER_FOCUS || gMovesInfo[move].alwaysCriticalHit || (abilityAtk == ABILITY_MERCILESS && gBattleMons[battlerDef].status1 & STATUS1_PSN_ANY)) { - critChance = -2; + critChance = ALWAYS_CRITS; } 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 != CRIT_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 == ALWAYS_CRITS) RecordAbilityBattle(battlerDef, abilityDef); else if (GetCriticalHitOdds(critChance) == 1) RecordAbilityBattle(battlerDef, abilityDef); } - critChance = -1; + critChance = CRIT_BLOCKED; } return critChance; } +#undef CRIT_BLOCKED +#undef ALWAYS_CRITS s32 CalcCritChanceStage(u32 battlerAtk, u32 battlerDef, u32 move, bool32 recordAbility) { @@ -6617,6 +6621,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; @@ -6628,7 +6633,6 @@ static void Cmd_moveend(void) gBattleStruct->additionalEffectsCounter = 0; gBattleStruct->poisonPuppeteerConfusion = FALSE; gBattleStruct->fickleBeamBoosted = FALSE; - gBattleStruct->distortedTypeMatchups = 0; gBattleStruct->usedMicleBerry &= ~(1u << gBattlerAttacker); if (gHitMarker & HITMARKER_UNABLE_TO_USE_MOVE) gBattleStruct->pledgeMove = FALSE; diff --git a/src/battle_util.c b/src/battle_util.c index 1e5f809c52..24c0888942 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -10439,7 +10439,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)