From abebf479a6cfebc68260a6aacd3726bb3de23dd9 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 17 Sep 2018 20:37:33 +0200 Subject: [PATCH] Tweak mega evo to hopefully be compatibile with recorded battles. --- include/constants/moves.h | 2 +- src/battle_controller_opponent.c | 2 +- src/battle_controller_player.c | 4 ++-- src/battle_main.c | 7 ++----- src/battle_util.c | 5 +++-- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/include/constants/moves.h b/include/constants/moves.h index e9e43627ad..9fdc00c429 100644 --- a/include/constants/moves.h +++ b/include/constants/moves.h @@ -640,4 +640,4 @@ #define MOVES_COUNT MOVES_COUNT_GEN6 -#endif // GUARD_CONSTANTS_MOVES_H \ No newline at end of file +#endif // GUARD_CONSTANTS_MOVES_H diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index 4c43c74c5e..5db5f4e135 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -1572,7 +1572,7 @@ static void OpponentHandleChooseMove(void) gBattlerTarget = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT); } if (CanMegaEvolve(gActiveBattler)) // If opponent can mega evolve, do it. - BtlController_EmitTwoReturnValues(1, 10 | RET_MEGA_EVOLUTION, (chosenMoveId) | (gBattlerTarget << 8)); + BtlController_EmitTwoReturnValues(1, 10, (chosenMoveId) | (RET_MEGA_EVOLUTION) | (gBattlerTarget << 8)); else BtlController_EmitTwoReturnValues(1, 10, (chosenMoveId) | (gBattlerTarget << 8)); break; diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index 1e417194dc..cf5b266d27 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -387,7 +387,7 @@ static void HandleInputChooseTarget(void) PlaySE(SE_SELECT); gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = sub_8039B2C; if (gBattleStruct->playerMegaEvoSelect) - BtlController_EmitTwoReturnValues(1, 10 | RET_MEGA_EVOLUTION, gMoveSelectionCursor[gActiveBattler] | (gMultiUsePlayerCursor << 8)); + BtlController_EmitTwoReturnValues(1, 10, gMoveSelectionCursor[gActiveBattler] | RET_MEGA_EVOLUTION | (gMultiUsePlayerCursor << 8)); else BtlController_EmitTwoReturnValues(1, 10, gMoveSelectionCursor[gActiveBattler] | (gMultiUsePlayerCursor << 8)); EndBounceEffect(gMultiUsePlayerCursor, BOUNCE_HEALTHBOX); @@ -544,7 +544,7 @@ static void HandleInputChooseMove(void) if (!canSelectTarget) { if (gBattleStruct->playerMegaEvoSelect) - BtlController_EmitTwoReturnValues(1, 10 | RET_MEGA_EVOLUTION, gMoveSelectionCursor[gActiveBattler] | (gMultiUsePlayerCursor << 8)); + BtlController_EmitTwoReturnValues(1, 10, gMoveSelectionCursor[gActiveBattler] | RET_MEGA_EVOLUTION | (gMultiUsePlayerCursor << 8)); else BtlController_EmitTwoReturnValues(1, 10, gMoveSelectionCursor[gActiveBattler] | (gMultiUsePlayerCursor << 8)); PlayerBufferExecCompleted(); diff --git a/src/battle_main.c b/src/battle_main.c index 50a69ec872..4e79f7ad16 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -4382,12 +4382,9 @@ static void HandleTurnActionSelectionState(void) case STATE_WAIT_ACTION_CASE_CHOSEN: if (!(gBattleControllerExecFlags & ((gBitTable[gActiveBattler]) | (0xF0000000) | (gBitTable[gActiveBattler] << 4) | (gBitTable[gActiveBattler] << 8) | (gBitTable[gActiveBattler] << 0xC)))) { - bool32 shouldMegaEvolve; switch (gChosenActionByBattler[gActiveBattler]) { case B_ACTION_USE_MOVE: - shouldMegaEvolve = gBattleBufferB[gActiveBattler][1] & RET_MEGA_EVOLUTION; - gBattleBufferB[gActiveBattler][1] &= ~(RET_MEGA_EVOLUTION); switch (gBattleBufferB[gActiveBattler][1]) { case 3: @@ -4426,10 +4423,10 @@ static void HandleTurnActionSelectionState(void) RecordedBattle_SetBattlerAction(gActiveBattler, gBattleBufferB[gActiveBattler][2]); RecordedBattle_SetBattlerAction(gActiveBattler, gBattleBufferB[gActiveBattler][3]); } - *(gBattleStruct->chosenMovePositions + gActiveBattler) = gBattleBufferB[gActiveBattler][2]; + *(gBattleStruct->chosenMovePositions + gActiveBattler) = gBattleBufferB[gActiveBattler][2] & ~(RET_MEGA_EVOLUTION); gChosenMoveByBattler[gActiveBattler] = gBattleMons[gActiveBattler].moves[*(gBattleStruct->chosenMovePositions + gActiveBattler)]; *(gBattleStruct->moveTarget + gActiveBattler) = gBattleBufferB[gActiveBattler][3]; - if (shouldMegaEvolve) + if (gBattleBufferB[gActiveBattler][2] & RET_MEGA_EVOLUTION) gBattleStruct->toMegaEvolve |= gBitTable[gActiveBattler]; gBattleCommunication[gActiveBattler]++; } diff --git a/src/battle_util.c b/src/battle_util.c index 2cf0d88ac1..4af0d24bc4 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -604,7 +604,8 @@ static bool32 IsHealBlockPreventingMove(u8 battler, u32 move) u8 TrySetCantSelectMoveBattleScript(void) { u8 limitations = 0; - u32 move = gBattleMons[gActiveBattler].moves[gBattleBufferB[gActiveBattler][2]]; + u8 moveId = gBattleBufferB[gActiveBattler][2] & ~(RET_MEGA_EVOLUTION); + u32 move = gBattleMons[gActiveBattler].moves[moveId]; u32 holdEffect = GetBattlerHoldEffect(gActiveBattler, TRUE); u16* choicedMove = &gBattleStruct->choicedMove[gActiveBattler]; @@ -729,7 +730,7 @@ u8 TrySetCantSelectMoveBattleScript(void) } } - if (gBattleMons[gActiveBattler].pp[gBattleBufferB[gActiveBattler][2]] == 0) + if (gBattleMons[gActiveBattler].pp[moveId] == 0) { if (gBattleTypeFlags & BATTLE_TYPE_PALACE) {