mirror of
https://github.com/Ninjdai1/pokeemerald.git
synced 2025-01-15 16:12:12 +01:00
fix battle palace bug
This commit is contained in:
parent
93dd8786ee
commit
215604f5f7
@ -235,8 +235,17 @@ u8 BattleAI_ChooseMoveOrAction(void)
|
|||||||
u8 ComputeBattleAiScores(u8 battler)
|
u8 ComputeBattleAiScores(u8 battler)
|
||||||
{
|
{
|
||||||
sBattler_AI = 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)
|
||||||
|
@ -1548,116 +1548,108 @@ static void OpponentHandleYesNoBox(void)
|
|||||||
|
|
||||||
static void OpponentHandleChooseMove(void)
|
static void OpponentHandleChooseMove(void)
|
||||||
{
|
{
|
||||||
if (gBattleTypeFlags & BATTLE_TYPE_PALACE)
|
u8 chosenMoveId;
|
||||||
|
struct ChooseMoveStruct *moveInfo = (struct ChooseMoveStruct *)(&gBattleResources->bufferA[gActiveBattler][4]);
|
||||||
|
|
||||||
|
if (gBattleTypeFlags & (BATTLE_TYPE_TRAINER | BATTLE_TYPE_FIRST_BATTLE | BATTLE_TYPE_SAFARI | BATTLE_TYPE_ROAMER)
|
||||||
|
|| IsWildMonSmart())
|
||||||
{
|
{
|
||||||
BtlController_EmitTwoReturnValues(BUFFER_B, 10, ChooseMoveAndTargetInBattlePalace());
|
chosenMoveId = gBattleStruct->aiMoveOrAction[gActiveBattler];
|
||||||
|
gBattlerTarget = gBattleStruct->aiChosenTarget[gActiveBattler];
|
||||||
|
switch (chosenMoveId)
|
||||||
|
{
|
||||||
|
case AI_CHOICE_WATCH:
|
||||||
|
BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SAFARI_WATCH_CAREFULLY, 0);
|
||||||
|
break;
|
||||||
|
case AI_CHOICE_FLEE:
|
||||||
|
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:
|
||||||
|
{
|
||||||
|
u16 chosenMove = moveInfo->moves[chosenMoveId];
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
OpponentBufferExecCompleted();
|
OpponentBufferExecCompleted();
|
||||||
}
|
}
|
||||||
else
|
else // Wild pokemon - use random move
|
||||||
{
|
{
|
||||||
u8 chosenMoveId;
|
u16 move;
|
||||||
struct ChooseMoveStruct *moveInfo = (struct ChooseMoveStruct *)(&gBattleResources->bufferA[gActiveBattler][4]);
|
u8 target;
|
||||||
|
do
|
||||||
if (gBattleTypeFlags & (BATTLE_TYPE_TRAINER | BATTLE_TYPE_FIRST_BATTLE | BATTLE_TYPE_SAFARI | BATTLE_TYPE_ROAMER)
|
|
||||||
|| IsWildMonSmart())
|
|
||||||
{
|
{
|
||||||
chosenMoveId = gBattleStruct->aiMoveOrAction[gActiveBattler];
|
chosenMoveId = Random() & 3;
|
||||||
gBattlerTarget = gBattleStruct->aiChosenTarget[gActiveBattler];
|
move = moveInfo->moves[chosenMoveId];
|
||||||
switch (chosenMoveId)
|
} while (move == MOVE_NONE);
|
||||||
{
|
|
||||||
case AI_CHOICE_WATCH:
|
|
||||||
BtlController_EmitTwoReturnValues(BUFFER_B, B_ACTION_SAFARI_WATCH_CAREFULLY, 0);
|
|
||||||
break;
|
|
||||||
case AI_CHOICE_FLEE:
|
|
||||||
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:
|
|
||||||
{
|
|
||||||
u16 chosenMove = moveInfo->moves[chosenMoveId];
|
|
||||||
|
|
||||||
if (GetBattlerMoveTargetType(gActiveBattler, chosenMove) & (MOVE_TARGET_USER_OR_SELECTED | MOVE_TARGET_USER))
|
if (GetBattlerMoveTargetType(gActiveBattler, move) & (MOVE_TARGET_USER_OR_SELECTED | MOVE_TARGET_USER))
|
||||||
gBattlerTarget = gActiveBattler;
|
BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (gActiveBattler << 8));
|
||||||
if (GetBattlerMoveTargetType(gActiveBattler, chosenMove) & MOVE_TARGET_BOTH)
|
else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE)
|
||||||
{
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
OpponentBufferExecCompleted();
|
|
||||||
}
|
|
||||||
else // Wild pokemon - use random move
|
|
||||||
{
|
{
|
||||||
u16 move;
|
do {
|
||||||
u8 target;
|
target = GetBattlerAtPosition(Random() & 2);
|
||||||
do
|
} while (!CanTargetBattler(gActiveBattler, target, move));
|
||||||
{
|
|
||||||
chosenMoveId = Random() & 3;
|
|
||||||
move = moveInfo->moves[chosenMoveId];
|
|
||||||
} while (move == MOVE_NONE);
|
|
||||||
|
|
||||||
if (GetBattlerMoveTargetType(gActiveBattler, move) & (MOVE_TARGET_USER_OR_SELECTED | MOVE_TARGET_USER))
|
#if B_WILD_NATURAL_ENEMIES == TRUE
|
||||||
BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (gActiveBattler << 8));
|
// Don't bother to loop through table if the move can't attack ally
|
||||||
else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE)
|
if (!(gBattleMoves[move].target & MOVE_TARGET_BOTH))
|
||||||
{
|
{
|
||||||
do {
|
u16 i, speciesAttacker, speciesTarget, isPartnerEnemy = FALSE;
|
||||||
target = GetBattlerAtPosition(Random() & 2);
|
static const u16 naturalEnemies[][2] =
|
||||||
} while (!CanTargetBattler(gActiveBattler, target, move));
|
|
||||||
|
|
||||||
#if B_WILD_NATURAL_ENEMIES == TRUE
|
|
||||||
// Don't bother to loop through table if the move can't attack ally
|
|
||||||
if (!(gBattleMoves[move].target & MOVE_TARGET_BOTH))
|
|
||||||
{
|
{
|
||||||
u16 i, speciesAttacker, speciesTarget, isPartnerEnemy = FALSE;
|
// Attacker Target
|
||||||
static const u16 naturalEnemies[][2] =
|
{SPECIES_ZANGOOSE, SPECIES_SEVIPER},
|
||||||
{
|
{SPECIES_SEVIPER, SPECIES_ZANGOOSE},
|
||||||
// Attacker Target
|
{SPECIES_HEATMOR, SPECIES_DURANT},
|
||||||
{SPECIES_ZANGOOSE, SPECIES_SEVIPER},
|
{SPECIES_DURANT, SPECIES_HEATMOR},
|
||||||
{SPECIES_SEVIPER, SPECIES_ZANGOOSE},
|
{SPECIES_SABLEYE, SPECIES_CARBINK},
|
||||||
{SPECIES_HEATMOR, SPECIES_DURANT},
|
{SPECIES_MAREANIE, SPECIES_CORSOLA},
|
||||||
{SPECIES_DURANT, SPECIES_HEATMOR},
|
};
|
||||||
{SPECIES_SABLEYE, SPECIES_CARBINK},
|
speciesAttacker = gBattleMons[gActiveBattler].species;
|
||||||
{SPECIES_MAREANIE, SPECIES_CORSOLA},
|
speciesTarget = gBattleMons[GetBattlerAtPosition(BATTLE_PARTNER(gActiveBattler))].species;
|
||||||
};
|
|
||||||
speciesAttacker = gBattleMons[gActiveBattler].species;
|
|
||||||
speciesTarget = gBattleMons[GetBattlerAtPosition(BATTLE_PARTNER(gActiveBattler))].species;
|
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_COUNT(naturalEnemies); i++)
|
for (i = 0; i < ARRAY_COUNT(naturalEnemies); i++)
|
||||||
|
{
|
||||||
|
if (speciesAttacker == naturalEnemies[i][0] && speciesTarget == naturalEnemies[i][1])
|
||||||
{
|
{
|
||||||
if (speciesAttacker == naturalEnemies[i][0] && speciesTarget == naturalEnemies[i][1])
|
isPartnerEnemy = TRUE;
|
||||||
{
|
break;
|
||||||
isPartnerEnemy = TRUE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (isPartnerEnemy && CanTargetBattler(gActiveBattler, target, move))
|
|
||||||
BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (GetBattlerAtPosition(BATTLE_PARTNER(gActiveBattler)) << 8));
|
|
||||||
else
|
|
||||||
BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (target << 8));
|
|
||||||
}
|
}
|
||||||
|
if (isPartnerEnemy && CanTargetBattler(gActiveBattler, target, move))
|
||||||
|
BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (GetBattlerAtPosition(BATTLE_PARTNER(gActiveBattler)) << 8));
|
||||||
else
|
else
|
||||||
#endif
|
|
||||||
BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (target << 8));
|
BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (target << 8));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (GetBattlerAtPosition(B_POSITION_PLAYER_LEFT) << 8));
|
#endif
|
||||||
|
BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (target << 8));
|
||||||
OpponentBufferExecCompleted();
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (GetBattlerAtPosition(B_POSITION_PLAYER_LEFT) << 8));
|
||||||
|
|
||||||
|
OpponentBufferExecCompleted();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2843,8 +2843,10 @@ 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, ChooseMoveAndTargetInBattlePalace());
|
BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (gBattlerTarget << 8));
|
||||||
PlayerBufferExecCompleted();
|
PlayerBufferExecCompleted();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ u16 ChooseMoveAndTargetInBattlePalace(void)
|
|||||||
// If no moves matched the selected group, pick a new move from groups the pokemon has
|
// If no moves matched the selected group, pick a new move from groups the pokemon has
|
||||||
// In this case the AI is not checked again, so the choice may be worse
|
// In this case the AI is not checked again, so the choice may be worse
|
||||||
// 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)
|
if (chosenMoveId == -1 || chosenMoveId >= MAX_MON_MOVES)
|
||||||
{
|
{
|
||||||
if (unusableMovesBits != 0xF)
|
if (unusableMovesBits != 0xF)
|
||||||
{
|
{
|
||||||
|
@ -3973,7 +3973,8 @@ static void HandleTurnActionSelectionState(void)
|
|||||||
gBattleCommunication[gActiveBattler] = STATE_BEFORE_ACTION_CHOSEN;
|
gBattleCommunication[gActiveBattler] = STATE_BEFORE_ACTION_CHOSEN;
|
||||||
|
|
||||||
// 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()) && IsBattlerAIControlled(gActiveBattler)) {
|
if ((gBattleTypeFlags & BATTLE_TYPE_HAS_AI || IsWildMonSmart())
|
||||||
|
&& (IsBattlerAIControlled(gActiveBattler) || gBattleTypeFlags & BATTLE_TYPE_PALACE)) {
|
||||||
gBattleStruct->aiMoveOrAction[gActiveBattler] = ComputeBattleAiScores(gActiveBattler);
|
gBattleStruct->aiMoveOrAction[gActiveBattler] = ComputeBattleAiScores(gActiveBattler);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user