diff --git a/include/battle_util.h b/include/battle_util.h index 9a78af8c9b..1dfd71ad80 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -167,6 +167,8 @@ struct DamageContext u32 weather:16; u32 fixedBasePower:8; u32 padding2:8; + u32 chosenMove:16; // May be different to 'move', e.g. for Z moves. + u32 padding3:16; uq4_12_t typeEffectivenessModifier; enum Ability abilityAtk; enum Ability abilityDef; diff --git a/src/battle_ai_util.c b/src/battle_ai_util.c index 84b18c98c9..3ba86b5c4e 100644 --- a/src/battle_ai_util.c +++ b/src/battle_ai_util.c @@ -584,7 +584,7 @@ bool32 MovesWithCategoryUnusable(u32 attacker, u32 target, enum DamageCategory c if (GetBattleMoveCategory(moves[i]) == category) { SetTypeBeforeUsingMove(moves[i], attacker); - ctx.move = moves[i]; + ctx.move = ctx.chosenMove = moves[i]; ctx.moveType = GetBattleMoveType(moves[i]); if (CalcTypeEffectivenessMultiplier(&ctx)) @@ -929,7 +929,7 @@ struct SimulatedDamage AI_CalcDamage(u32 move, u32 battlerAtk, u32 battlerDef, u struct DamageContext ctx = {0}; ctx.battlerAtk = battlerAtk; ctx.battlerDef = battlerDef; - ctx.move = move; + ctx.move = ctx.chosenMove = move; ctx.moveType = GetBattleMoveType(move); ctx.isCrit = ShouldCalcCritDamage(battlerAtk, battlerDef, move, aiData); ctx.randomFactor = FALSE; @@ -1382,7 +1382,7 @@ uq4_12_t AI_GetMoveEffectiveness(u32 move, u32 battlerAtk, u32 battlerDef) struct DamageContext ctx = {0}; ctx.battlerAtk = battlerAtk; ctx.battlerDef = battlerDef; - ctx.move = move; + ctx.move = ctx.chosenMove = move; ctx.moveType = GetBattleMoveType(move); ctx.updateFlags = FALSE; ctx.abilityAtk = gAiLogicData->abilities[battlerAtk]; diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 83c0557846..7331ea8e5e 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -1428,6 +1428,7 @@ static void AccuracyCheck(bool32 recalcDragonDarts, const u8 *nextInstr, const u ctx.battlerAtk = gBattlerAttacker; ctx.battlerDef = battlerDef; ctx.move = move; + ctx.chosenMove = gChosenMove; ctx.moveType = moveType; ctx.updateFlags = TRUE; ctx.abilityAtk = abilityAtk; @@ -1728,6 +1729,7 @@ static void Cmd_damagecalc(void) struct DamageContext ctx = {0}; ctx.battlerAtk = gBattlerAttacker; ctx.move = gCurrentMove; + ctx.chosenMove = gChosenMove; ctx.moveType = GetBattleMoveType(gCurrentMove); ctx.randomFactor = TRUE; ctx.updateFlags = TRUE; @@ -1765,6 +1767,7 @@ static void Cmd_typecalc(void) ctx.battlerAtk = gBattlerAttacker; ctx.battlerDef = gBattlerTarget; ctx.move = gCurrentMove; + ctx.chosenMove = gChosenMove; ctx.moveType = GetBattleMoveType(gCurrentMove); ctx.updateFlags = TRUE; ctx.abilityAtk = GetBattlerAbility(gBattlerAttacker); diff --git a/src/battle_tv.c b/src/battle_tv.c index 661238ae6d..3dc5ee573b 100644 --- a/src/battle_tv.c +++ b/src/battle_tv.c @@ -1271,10 +1271,10 @@ static void TrySetBattleSeminarShow(void) powerOverride = 0; if (ShouldCalculateDamage(gCurrentMove, &dmgByMove[i], &powerOverride)) { - struct DamageContext ctx; + struct DamageContext ctx = {0}; ctx.battlerAtk = gBattlerAttacker; ctx.battlerDef = gBattlerTarget; - ctx.move = gCurrentMove; + ctx.move = ctx.chosenMove = gCurrentMove; ctx.moveType = GetMoveType(gCurrentMove); ctx.isCrit = FALSE; ctx.randomFactor = FALSE; diff --git a/src/battle_util.c b/src/battle_util.c index 8c69e60006..58c787372b 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -219,7 +219,7 @@ static uq4_12_t CalcTypeEffectivenessMultiplierHelper(u32 move, enum Type moveTy struct DamageContext ctx = {0}; ctx.battlerAtk = battlerAtk; ctx.battlerDef = battlerDef; - ctx.move = move; + ctx.move = ctx.chosenMove = move; ctx.moveType = moveType; ctx.updateFlags = recordAbilities; ctx.abilityAtk = abilityAtk; @@ -2068,9 +2068,9 @@ static enum MoveCanceller CancellerObedience(struct BattleContext *ctx) return MOVE_STEP_FAILURE; case DISOBEYS_HITS_SELF: gBattlerTarget = ctx->battlerAtk; - struct DamageContext dmgCtx; + struct DamageContext dmgCtx = {0}; dmgCtx.battlerAtk = dmgCtx.battlerDef = ctx->battlerAtk; - dmgCtx.move = MOVE_NONE; + dmgCtx.move = dmgCtx.chosenMove = MOVE_NONE; dmgCtx.moveType = TYPE_MYSTERY; dmgCtx.isCrit = FALSE; dmgCtx.randomFactor = FALSE; @@ -2234,9 +2234,9 @@ static enum MoveCanceller CancellerConfused(struct BattleContext *ctx) if (RandomPercentage(RNG_CONFUSION, (GetGenConfig(GEN_CONFIG_CONFUSION_SELF_DMG_CHANCE) >= GEN_7 ? 33 : 50))) { gBattleCommunication[MULTISTRING_CHOOSER] = TRUE; - struct DamageContext dmgCtx; + struct DamageContext dmgCtx = {0}; dmgCtx.battlerAtk = dmgCtx.battlerDef = ctx->battlerAtk; - dmgCtx.move = MOVE_NONE; + dmgCtx.move = dmgCtx.chosenMove = MOVE_NONE; dmgCtx.moveType = TYPE_MYSTERY; dmgCtx.isCrit = FALSE; dmgCtx.randomFactor = FALSE; @@ -4044,7 +4044,7 @@ u32 AbilityBattleEffects(enum AbilityEffect caseID, u32 battler, enum Ability ab ctx.battlerAtk = i; ctx.battlerDef = battler; - ctx.move = move; + ctx.move = ctx.chosenMove = move; ctx.moveType = moveType; ctx.isAnticipation = TRUE; modifier = CalcTypeEffectivenessMultiplier(&ctx); @@ -7125,7 +7125,7 @@ static inline u32 CalcMoveBasePowerAfterModifiers(struct DamageContext *ctx) modifier = uq4_12_multiply(modifier, uq4_12_add(UQ_4_12(1.0), PercentToUQ4_12(gSpecialStatuses[battlerAtk].gemParam))); if (gBattleMons[battlerAtk].volatiles.charge && moveType == TYPE_ELECTRIC) modifier = uq4_12_multiply(modifier, UQ_4_12(2.0)); - if (GetMoveEffect(gChosenMove) == EFFECT_ME_FIRST) + if (GetMoveEffect(ctx->chosenMove) == EFFECT_ME_FIRST) modifier = uq4_12_multiply(modifier, UQ_4_12(1.5)); if (IsBattlerTerrainAffected(battlerAtk, ctx->abilityAtk, ctx->holdEffectAtk, STATUS_FIELD_GRASSY_TERRAIN) && moveType == TYPE_GRASS) modifier = uq4_12_multiply(modifier, (B_TERRAIN_TYPE_BOOST >= GEN_8 ? UQ_4_12(1.3) : UQ_4_12(1.5))); @@ -8483,7 +8483,7 @@ static inline void TryNoticeIllusionInTypeEffectiveness(u32 move, enum Type move struct DamageContext ctx = {0}; ctx.battlerAtk = battlerAtk; ctx.battlerDef = battlerDef; - ctx.move = move; + ctx.move = ctx.chosenMove = move; ctx.moveType = moveType; ctx.updateFlags = FALSE; ctx.abilityAtk = GetBattlerAbility(battlerAtk); @@ -8630,7 +8630,7 @@ uq4_12_t CalcPartyMonTypeEffectivenessMultiplier(u16 move, u16 speciesDef, enum if (move != MOVE_STRUGGLE && moveType != TYPE_MYSTERY) { struct DamageContext ctx = {0}; - ctx.move = move; + ctx.move = ctx.chosenMove = move; ctx.moveType = moveType; ctx.updateFlags = FALSE; ctx.abilityDef = abilityDef; @@ -8675,7 +8675,7 @@ uq4_12_t GetOverworldTypeEffectiveness(struct Pokemon *mon, enum Type moveType) return modifier; struct DamageContext ctx = {0}; - ctx.move = MOVE_POUND; + ctx.move = ctx.chosenMove = MOVE_POUND; ctx.moveType = moveType; ctx.updateFlags = FALSE;