Critical Hit documentation and distorted match up struct switch (#5665)

This commit is contained in:
hedara90 2024-11-13 22:30:27 +01:00 committed by GitHub
commit 3481340da8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 10 deletions

View file

@ -250,6 +250,7 @@ struct SpecialStatus
u8 emergencyExited:1; u8 emergencyExited:1;
u8 afterYou:1; u8 afterYou:1;
u8 preventLifeOrbDamage:1; // So that Life Orb doesn't activate various effects. u8 preventLifeOrbDamage:1; // So that Life Orb doesn't activate various effects.
u8 distortedTypeMatchups:1;
}; };
struct SideTimer struct SideTimer
@ -823,7 +824,6 @@ struct BattleStruct
u8 shellSideArmCategory[MAX_BATTLERS_COUNT][MAX_BATTLERS_COUNT]; u8 shellSideArmCategory[MAX_BATTLERS_COUNT][MAX_BATTLERS_COUNT];
u8 speedTieBreaks; // MAX_BATTLERS_COUNT! values. u8 speedTieBreaks; // MAX_BATTLERS_COUNT! values.
u8 boosterEnergyActivates; u8 boosterEnergyActivates;
u8 distortedTypeMatchups;
u8 categoryOverride; // for Z-Moves and Max Moves u8 categoryOverride; // for Z-Moves and Max Moves
u8 commandingDondozo; u8 commandingDondozo;
u16 commanderActive[MAX_BATTLERS_COUNT]; u16 commanderActive[MAX_BATTLERS_COUNT];

View file

@ -1171,7 +1171,7 @@ bool32 ProteanTryChangeType(u32 battler, u32 ability, u32 move, u32 moveType)
bool32 ShouldTeraShellDistortTypeMatchups(u32 move, u32 battlerDef) bool32 ShouldTeraShellDistortTypeMatchups(u32 move, u32 battlerDef)
{ {
if (!(gBattleStruct->distortedTypeMatchups & (1u << battlerDef)) if (!gSpecialStatuses[battlerDef].distortedTypeMatchups
&& GetBattlerAbility(battlerDef) == ABILITY_TERA_SHELL && GetBattlerAbility(battlerDef) == ABILITY_TERA_SHELL
&& gBattleMons[battlerDef].species == SPECIES_TERAPAGOS_TERASTAL && gBattleMons[battlerDef].species == SPECIES_TERAPAGOS_TERASTAL
&& !IS_MOVE_STATUS(move) && !IS_MOVE_STATUS(move)
@ -1893,7 +1893,7 @@ static void Cmd_ppreduce(void)
if (ShouldTeraShellDistortTypeMatchups(gCurrentMove, gBattlerTarget)) if (ShouldTeraShellDistortTypeMatchups(gCurrentMove, gBattlerTarget))
{ {
gBattleStruct->distortedTypeMatchups |= 1u << gBattlerTarget; gSpecialStatuses[gBattlerTarget].distortedTypeMatchups = TRUE;
gBattlerAbility = gBattlerTarget; gBattlerAbility = gBattlerTarget;
BattleScriptPushCursor(); BattleScriptPushCursor();
gBattlescriptCurrInstr = BattleScript_TeraShellDistortingTypeMatchups; gBattlescriptCurrInstr = BattleScript_TeraShellDistortingTypeMatchups;
@ -1950,19 +1950,21 @@ static inline u32 GetHoldEffectCritChanceIncrease(u32 battler, u32 holdEffect)
return critStageIncrease; 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 CalcCritChanceStageArgs(u32 battlerAtk, u32 battlerDef, u32 move, bool32 recordAbility, u32 abilityAtk, u32 abilityDef, u32 holdEffectAtk)
{ {
s32 critChance = 0; s32 critChance = 0;
if (gSideStatuses[battlerDef] & SIDE_STATUS_LUCKY_CHANT) if (gSideStatuses[battlerDef] & SIDE_STATUS_LUCKY_CHANT)
{ {
critChance = -1; critChance = CRITICAL_HIT_BLOCKED;
} }
else if (gStatuses3[battlerAtk] & STATUS3_LASER_FOCUS else if (gStatuses3[battlerAtk] & STATUS3_LASER_FOCUS
|| gMovesInfo[move].alwaysCriticalHit || gMovesInfo[move].alwaysCriticalHit
|| (abilityAtk == ABILITY_MERCILESS && gBattleMons[battlerDef].status1 & STATUS1_PSN_ANY)) || (abilityAtk == ABILITY_MERCILESS && gBattleMons[battlerDef].status1 & STATUS1_PSN_ANY))
{ {
critChance = -2; critChance = CRITICAL_HIT_ALWAYS;
} }
else else
{ {
@ -1978,21 +1980,23 @@ s32 CalcCritChanceStageArgs(u32 battlerAtk, u32 battlerDef, u32 move, bool32 rec
critChance = ARRAY_COUNT(sCriticalHitOdds) - 1; 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 // Record ability only if move had 100% chance to get a crit
if (recordAbility) if (recordAbility)
{ {
if (critChance == -2) if (critChance == CRITICAL_HIT_ALWAYS)
RecordAbilityBattle(battlerDef, abilityDef); RecordAbilityBattle(battlerDef, abilityDef);
else if (GetCriticalHitOdds(critChance) == 1) else if (GetCriticalHitOdds(critChance) == 1)
RecordAbilityBattle(battlerDef, abilityDef); RecordAbilityBattle(battlerDef, abilityDef);
} }
critChance = -1; critChance = CRITICAL_HIT_BLOCKED;
} }
return critChance; return critChance;
} }
#undef CRIT_BLOCKED
#undef ALWAYS_CRITS
s32 CalcCritChanceStage(u32 battlerAtk, u32 battlerDef, u32 move, bool32 recordAbility) 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].damagedMons = 0;
gSpecialStatuses[gBattlerAttacker].preventLifeOrbDamage = 0; gSpecialStatuses[gBattlerAttacker].preventLifeOrbDamage = 0;
gSpecialStatuses[gBattlerTarget].berryReduced = FALSE; gSpecialStatuses[gBattlerTarget].berryReduced = FALSE;
gSpecialStatuses[gBattlerTarget].distortedTypeMatchups = FALSE;
gBattleScripting.moveEffect = 0; gBattleScripting.moveEffect = 0;
gBattleStruct->hitSwitchTargetFailed = FALSE; gBattleStruct->hitSwitchTargetFailed = FALSE;
gBattleStruct->isAtkCancelerForCalledMove = FALSE; gBattleStruct->isAtkCancelerForCalledMove = FALSE;
@ -6642,7 +6647,6 @@ static void Cmd_moveend(void)
gBattleStruct->additionalEffectsCounter = 0; gBattleStruct->additionalEffectsCounter = 0;
gBattleStruct->poisonPuppeteerConfusion = FALSE; gBattleStruct->poisonPuppeteerConfusion = FALSE;
gBattleStruct->fickleBeamBoosted = FALSE; gBattleStruct->fickleBeamBoosted = FALSE;
gBattleStruct->distortedTypeMatchups = 0;
gBattleStruct->redCardActivates = FALSE; gBattleStruct->redCardActivates = FALSE;
gBattleStruct->usedMicleBerry &= ~(1u << gBattlerAttacker); gBattleStruct->usedMicleBerry &= ~(1u << gBattlerAttacker);
if (gHitMarker & HITMARKER_UNABLE_TO_USE_MOVE) if (gHitMarker & HITMARKER_UNABLE_TO_USE_MOVE)

View file

@ -10428,7 +10428,7 @@ static inline void MulByTypeEffectiveness(uq4_12_t *modifier, u32 move, u32 move
mod = UQ_4_12(1.0); 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); mod = UQ_4_12(0.5);
if (recordAbilities) if (recordAbilities)