From 1d630d29f9eff6f443a8068407607fcb254cc09f Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Sun, 10 Mar 2024 10:23:31 -0400 Subject: [PATCH 1/2] fix repeated quick claw/quick draw checks --- include/battle.h | 2 ++ src/battle_main.c | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/battle.h b/include/battle.h index 3a7a9071b4bd..fa818fb62233 100644 --- a/include/battle.h +++ b/include/battle.h @@ -742,6 +742,8 @@ struct BattleStruct u8 intrepidSwordBoost[NUM_BATTLE_SIDES]; u8 dauntlessShieldBoost[NUM_BATTLE_SIDES]; u8 stickySyrupdBy[MAX_BATTLERS_COUNT]; + u8 quickClawRandom[MAX_BATTLERS_COUNT]; + u8 quickDrawRandom[MAX_BATTLERS_COUNT]; }; // The palaceFlags member of struct BattleStruct contains 1 flag per move to indicate which moves the AI should consider, diff --git a/src/battle_main.c b/src/battle_main.c index 19ee70f162de..a56273626083 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -4867,6 +4867,8 @@ static void SetActionsAndBattlersTurnOrder(void) { gActionsByTurnOrder[turnOrderId] = gChosenActionByBattler[battler]; gBattlerByTurnOrder[turnOrderId] = battler; + gBattleStruct->quickClawChance[battler] = RandomPercentage(RNG_QUICK_CLAW, GetBattlerHoldEffectParam(battler)); + gBattleStruct->quickDrawChance[battler] = RandomPercentage(RNG_QUICK_DRAW, 30); turnOrderId++; } } @@ -5073,21 +5075,21 @@ static void TryChangingTurnOrderEffects(u32 battler1, u32 battler2) // Battler 1 // Quick Draw - if (ability1 == ABILITY_QUICK_DRAW && !IS_MOVE_STATUS(gChosenMoveByBattler[battler1]) && RandomPercentage(RNG_QUICK_DRAW, 30)) + if (ability1 == ABILITY_QUICK_DRAW && !IS_MOVE_STATUS(gChosenMoveByBattler[battler1]) && gBattleStruct->quickDrawChance[battler1]) gProtectStructs[battler1].quickDraw = TRUE; // Quick Claw and Custap Berry if (!gProtectStructs[battler1].quickDraw - && ((holdEffectBattler1 == HOLD_EFFECT_QUICK_CLAW && RandomPercentage(RNG_QUICK_CLAW, GetBattlerHoldEffectParam(battler1))) + && ((holdEffectBattler1 == HOLD_EFFECT_QUICK_CLAW && gBattleStruct->quickClawChance[battler1]) || (holdEffectBattler1 == HOLD_EFFECT_CUSTAP_BERRY && HasEnoughHpToEatBerry(battler1, 4, gBattleMons[battler1].item)))) gProtectStructs[battler1].usedCustapBerry = TRUE; // Battler 2 // Quick Draw - if (ability2 == ABILITY_QUICK_DRAW && !IS_MOVE_STATUS(gChosenMoveByBattler[battler2]) && RandomPercentage(RNG_QUICK_DRAW, 30)) + if (ability2 == ABILITY_QUICK_DRAW && !IS_MOVE_STATUS(gChosenMoveByBattler[battler2]) && gBattleStruct->quickDrawChance[battler2]) gProtectStructs[battler2].quickDraw = TRUE; // Quick Claw and Custap Berry if (!gProtectStructs[battler2].quickDraw - && ((holdEffectBattler2 == HOLD_EFFECT_QUICK_CLAW && RandomPercentage(RNG_QUICK_CLAW, GetBattlerHoldEffectParam(battler2))) + && ((holdEffectBattler2 == HOLD_EFFECT_QUICK_CLAW && gBattleStruct->quickClawChance[battler2]) || (holdEffectBattler2 == HOLD_EFFECT_CUSTAP_BERRY && HasEnoughHpToEatBerry(battler2, 4, gBattleMons[battler2].item)))) gProtectStructs[battler2].usedCustapBerry = TRUE; } From a59ccc65c708657a89d210023a59e7f2427a3821 Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Sun, 10 Mar 2024 10:31:15 -0400 Subject: [PATCH 2/2] fix field names --- src/battle_main.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/battle_main.c b/src/battle_main.c index a56273626083..e3f28127538c 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -4867,8 +4867,8 @@ static void SetActionsAndBattlersTurnOrder(void) { gActionsByTurnOrder[turnOrderId] = gChosenActionByBattler[battler]; gBattlerByTurnOrder[turnOrderId] = battler; - gBattleStruct->quickClawChance[battler] = RandomPercentage(RNG_QUICK_CLAW, GetBattlerHoldEffectParam(battler)); - gBattleStruct->quickDrawChance[battler] = RandomPercentage(RNG_QUICK_DRAW, 30); + gBattleStruct->quickClawRandom[battler] = RandomPercentage(RNG_QUICK_CLAW, GetBattlerHoldEffectParam(battler)); + gBattleStruct->quickDrawRandom[battler] = RandomPercentage(RNG_QUICK_DRAW, 30); turnOrderId++; } } @@ -5075,21 +5075,21 @@ static void TryChangingTurnOrderEffects(u32 battler1, u32 battler2) // Battler 1 // Quick Draw - if (ability1 == ABILITY_QUICK_DRAW && !IS_MOVE_STATUS(gChosenMoveByBattler[battler1]) && gBattleStruct->quickDrawChance[battler1]) + if (ability1 == ABILITY_QUICK_DRAW && !IS_MOVE_STATUS(gChosenMoveByBattler[battler1]) && gBattleStruct->quickDrawRandom[battler1]) gProtectStructs[battler1].quickDraw = TRUE; // Quick Claw and Custap Berry if (!gProtectStructs[battler1].quickDraw - && ((holdEffectBattler1 == HOLD_EFFECT_QUICK_CLAW && gBattleStruct->quickClawChance[battler1]) + && ((holdEffectBattler1 == HOLD_EFFECT_QUICK_CLAW && gBattleStruct->quickClawRandom[battler1]) || (holdEffectBattler1 == HOLD_EFFECT_CUSTAP_BERRY && HasEnoughHpToEatBerry(battler1, 4, gBattleMons[battler1].item)))) gProtectStructs[battler1].usedCustapBerry = TRUE; // Battler 2 // Quick Draw - if (ability2 == ABILITY_QUICK_DRAW && !IS_MOVE_STATUS(gChosenMoveByBattler[battler2]) && gBattleStruct->quickDrawChance[battler2]) + if (ability2 == ABILITY_QUICK_DRAW && !IS_MOVE_STATUS(gChosenMoveByBattler[battler2]) && gBattleStruct->quickDrawRandom[battler2]) gProtectStructs[battler2].quickDraw = TRUE; // Quick Claw and Custap Berry if (!gProtectStructs[battler2].quickDraw - && ((holdEffectBattler2 == HOLD_EFFECT_QUICK_CLAW && gBattleStruct->quickClawChance[battler2]) + && ((holdEffectBattler2 == HOLD_EFFECT_QUICK_CLAW && gBattleStruct->quickClawRandom[battler2]) || (holdEffectBattler2 == HOLD_EFFECT_CUSTAP_BERRY && HasEnoughHpToEatBerry(battler2, 4, gBattleMons[battler2].item)))) gProtectStructs[battler2].usedCustapBerry = TRUE; }