Fix battle tent again

This commit is contained in:
DizzyEggg 2022-10-31 13:16:48 +01:00
parent 215604f5f7
commit ea43b7732c
5 changed files with 44 additions and 47 deletions

View File

@ -234,18 +234,8 @@ u8 BattleAI_ChooseMoveOrAction(void)
// damages/other info computed in GetAIDataAndCalcDmg // damages/other info computed in GetAIDataAndCalcDmg
u8 ComputeBattleAiScores(u8 battler) u8 ComputeBattleAiScores(u8 battler)
{ {
sBattler_AI = battler; BattleAI_SetupAIData(0xF);
if (gBattleTypeFlags & BATTLE_TYPE_PALACE) return BattleAI_ChooseMoveOrAction();
{
u16 retVal = ChooseMoveAndTargetInBattlePalace(); // first byte is moveId, secondId is target
gBattleStruct->aiChosenTarget[sBattler_AI] = (retVal >> 8) & 0xFF;
return (retVal & 0xFF);
}
else
{
BattleAI_SetupAIData(0xF);
return BattleAI_ChooseMoveOrAction();
}
} }
static void CopyBattlerDataToAIParty(u32 bPosition, u32 side) static void CopyBattlerDataToAIParty(u32 bPosition, u32 side)

View File

@ -1554,42 +1554,49 @@ static void OpponentHandleChooseMove(void)
if (gBattleTypeFlags & (BATTLE_TYPE_TRAINER | BATTLE_TYPE_FIRST_BATTLE | BATTLE_TYPE_SAFARI | BATTLE_TYPE_ROAMER) if (gBattleTypeFlags & (BATTLE_TYPE_TRAINER | BATTLE_TYPE_FIRST_BATTLE | BATTLE_TYPE_SAFARI | BATTLE_TYPE_ROAMER)
|| IsWildMonSmart()) || IsWildMonSmart())
{ {
chosenMoveId = gBattleStruct->aiMoveOrAction[gActiveBattler]; if (gBattleTypeFlags & BATTLE_TYPE_PALACE)
gBattlerTarget = gBattleStruct->aiChosenTarget[gActiveBattler];
switch (chosenMoveId)
{ {
case AI_CHOICE_WATCH: BtlController_EmitTwoReturnValues(BUFFER_B, 10, ChooseMoveAndTargetInBattlePalace());
BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SAFARI_WATCH_CAREFULLY, 0); }
break; else
case AI_CHOICE_FLEE: {
BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_RUN, 0); chosenMoveId = gBattleStruct->aiMoveOrAction[gActiveBattler];
break; gBattlerTarget = gBattleStruct->aiChosenTarget[gActiveBattler];
case AI_CHOICE_SWITCH: switch (chosenMoveId)
BtlController_EmitTwoReturnValues(BUFFER_B, 10, 0xFFFF);
break;
case 6:
BtlController_EmitTwoReturnValues(BUFFER_B, 15, gBattlerTarget);
break;
default:
{ {
u16 chosenMove = moveInfo->moves[chosenMoveId]; case AI_CHOICE_WATCH:
BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SAFARI_WATCH_CAREFULLY, 0);
if (GetBattlerMoveTargetType(gActiveBattler, chosenMove) & (MOVE_TARGET_USER_OR_SELECTED | MOVE_TARGET_USER)) break;
gBattlerTarget = gActiveBattler; case AI_CHOICE_FLEE:
if (GetBattlerMoveTargetType(gActiveBattler, chosenMove) & MOVE_TARGET_BOTH) BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_RUN, 0);
break;
case AI_CHOICE_SWITCH:
BtlController_EmitTwoReturnValues(BUFFER_B, 10, 0xFFFF);
break;
case 6:
BtlController_EmitTwoReturnValues(BUFFER_B, 15, gBattlerTarget);
break;
default:
{ {
gBattlerTarget = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); u16 chosenMove = moveInfo->moves[chosenMoveId];
if (gAbsentBattlerFlags & gBitTable[gBattlerTarget])
gBattlerTarget = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT); if (GetBattlerMoveTargetType(gActiveBattler, chosenMove) & (MOVE_TARGET_USER_OR_SELECTED | MOVE_TARGET_USER))
gBattlerTarget = gActiveBattler;
if (GetBattlerMoveTargetType(gActiveBattler, chosenMove) & MOVE_TARGET_BOTH)
{
gBattlerTarget = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT);
if (gAbsentBattlerFlags & gBitTable[gBattlerTarget])
gBattlerTarget = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT);
}
if (ShouldUseZMove(gActiveBattler, gBattlerTarget, chosenMove))
QueueZMove(gActiveBattler, chosenMove);
if (CanMegaEvolve(gActiveBattler)) // If opponent can mega evolve, do it.
BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (RET_MEGA_EVOLUTION) | (gBattlerTarget << 8));
else
BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (gBattlerTarget << 8));
} }
if (ShouldUseZMove(gActiveBattler, gBattlerTarget, chosenMove)) break;
QueueZMove(gActiveBattler, chosenMove);
if (CanMegaEvolve(gActiveBattler)) // If opponent can mega evolve, do it.
BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (RET_MEGA_EVOLUTION) | (gBattlerTarget << 8));
else
BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (gBattlerTarget << 8));
} }
break;
} }
OpponentBufferExecCompleted(); OpponentBufferExecCompleted();
} }

View File

@ -2843,10 +2843,8 @@ static void PlayerChooseMoveInBattlePalace(void)
{ {
if (--*(gBattleStruct->arenaMindPoints + gActiveBattler) == 0) if (--*(gBattleStruct->arenaMindPoints + gActiveBattler) == 0)
{ {
u32 chosenMoveId = gBattleStruct->aiMoveOrAction[gActiveBattler];
gBattlerTarget = gBattleStruct->aiChosenTarget[gActiveBattler];
gBattlePalaceMoveSelectionRngValue = gRngValue; gBattlePalaceMoveSelectionRngValue = gRngValue;
BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (gBattlerTarget << 8)); BtlController_EmitTwoReturnValues(BUFFER_B, 10, ChooseMoveAndTargetInBattlePalace());
PlayerBufferExecCompleted(); PlayerBufferExecCompleted();
} }
} }

View File

@ -164,6 +164,7 @@ u16 ChooseMoveAndTargetInBattlePalace(void)
{ {
gBattleStruct->palaceFlags &= 0xF; gBattleStruct->palaceFlags &= 0xF;
gBattleStruct->palaceFlags |= (selectedMoves << 4); gBattleStruct->palaceFlags |= (selectedMoves << 4);
sBattler_AI = gActiveBattler;
BattleAI_SetupAIData(selectedMoves); BattleAI_SetupAIData(selectedMoves);
chosenMoveId = BattleAI_ChooseMoveOrAction(); chosenMoveId = BattleAI_ChooseMoveOrAction();
} }
@ -173,6 +174,7 @@ u16 ChooseMoveAndTargetInBattlePalace(void)
// If a move is chosen this way, there's a 50% chance that it will be unable to use it anyway // If a move is chosen this way, there's a 50% chance that it will be unable to use it anyway
if (chosenMoveId == -1 || chosenMoveId >= MAX_MON_MOVES) if (chosenMoveId == -1 || chosenMoveId >= MAX_MON_MOVES)
{ {
chosenMoveId = -1;
if (unusableMovesBits != 0xF) if (unusableMovesBits != 0xF)
{ {
validMoveFlags = 0, numValidMoveGroups = 0; validMoveFlags = 0, numValidMoveGroups = 0;

View File

@ -3974,7 +3974,7 @@ static void HandleTurnActionSelectionState(void)
// Do AI score computations here so we can use them in AI_TrySwitchOrUseItem // Do AI score computations here so we can use them in AI_TrySwitchOrUseItem
if ((gBattleTypeFlags & BATTLE_TYPE_HAS_AI || IsWildMonSmart()) if ((gBattleTypeFlags & BATTLE_TYPE_HAS_AI || IsWildMonSmart())
&& (IsBattlerAIControlled(gActiveBattler) || gBattleTypeFlags & BATTLE_TYPE_PALACE)) { && (IsBattlerAIControlled(gActiveBattler) && !(gBattleTypeFlags & BATTLE_TYPE_PALACE))) {
gBattleStruct->aiMoveOrAction[gActiveBattler] = ComputeBattleAiScores(gActiveBattler); gBattleStruct->aiMoveOrAction[gActiveBattler] = ComputeBattleAiScores(gActiveBattler);
} }
break; break;