mirror of
https://github.com/Ninjdai1/pokeemerald.git
synced 2024-12-27 04:04:17 +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)
|
||||
{
|
||||
sBattler_AI = battler;
|
||||
BattleAI_SetupAIData(0xF);
|
||||
return BattleAI_ChooseMoveOrAction();
|
||||
if (gBattleTypeFlags & BATTLE_TYPE_PALACE)
|
||||
{
|
||||
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)
|
||||
|
@ -1548,116 +1548,108 @@ static void OpponentHandleYesNoBox(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();
|
||||
}
|
||||
else
|
||||
else // Wild pokemon - use random move
|
||||
{
|
||||
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())
|
||||
u16 move;
|
||||
u8 target;
|
||||
do
|
||||
{
|
||||
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];
|
||||
chosenMoveId = Random() & 3;
|
||||
move = moveInfo->moves[chosenMoveId];
|
||||
} while (move == MOVE_NONE);
|
||||
|
||||
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();
|
||||
}
|
||||
else // Wild pokemon - use random move
|
||||
if (GetBattlerMoveTargetType(gActiveBattler, move) & (MOVE_TARGET_USER_OR_SELECTED | MOVE_TARGET_USER))
|
||||
BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (gActiveBattler << 8));
|
||||
else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE)
|
||||
{
|
||||
u16 move;
|
||||
u8 target;
|
||||
do
|
||||
{
|
||||
chosenMoveId = Random() & 3;
|
||||
move = moveInfo->moves[chosenMoveId];
|
||||
} while (move == MOVE_NONE);
|
||||
do {
|
||||
target = GetBattlerAtPosition(Random() & 2);
|
||||
} while (!CanTargetBattler(gActiveBattler, target, move));
|
||||
|
||||
if (GetBattlerMoveTargetType(gActiveBattler, move) & (MOVE_TARGET_USER_OR_SELECTED | MOVE_TARGET_USER))
|
||||
BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (gActiveBattler << 8));
|
||||
else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE)
|
||||
#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))
|
||||
{
|
||||
do {
|
||||
target = GetBattlerAtPosition(Random() & 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;
|
||||
static const u16 naturalEnemies[][2] =
|
||||
{
|
||||
u16 i, speciesAttacker, speciesTarget, isPartnerEnemy = FALSE;
|
||||
static const u16 naturalEnemies[][2] =
|
||||
{
|
||||
// Attacker Target
|
||||
{SPECIES_ZANGOOSE, SPECIES_SEVIPER},
|
||||
{SPECIES_SEVIPER, SPECIES_ZANGOOSE},
|
||||
{SPECIES_HEATMOR, SPECIES_DURANT},
|
||||
{SPECIES_DURANT, SPECIES_HEATMOR},
|
||||
{SPECIES_SABLEYE, SPECIES_CARBINK},
|
||||
{SPECIES_MAREANIE, SPECIES_CORSOLA},
|
||||
};
|
||||
speciesAttacker = gBattleMons[gActiveBattler].species;
|
||||
speciesTarget = gBattleMons[GetBattlerAtPosition(BATTLE_PARTNER(gActiveBattler))].species;
|
||||
// Attacker Target
|
||||
{SPECIES_ZANGOOSE, SPECIES_SEVIPER},
|
||||
{SPECIES_SEVIPER, SPECIES_ZANGOOSE},
|
||||
{SPECIES_HEATMOR, SPECIES_DURANT},
|
||||
{SPECIES_DURANT, SPECIES_HEATMOR},
|
||||
{SPECIES_SABLEYE, SPECIES_CARBINK},
|
||||
{SPECIES_MAREANIE, SPECIES_CORSOLA},
|
||||
};
|
||||
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
|
||||
#endif
|
||||
BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (target << 8));
|
||||
}
|
||||
else
|
||||
BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (GetBattlerAtPosition(B_POSITION_PLAYER_LEFT) << 8));
|
||||
|
||||
OpponentBufferExecCompleted();
|
||||
#endif
|
||||
BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (target << 8));
|
||||
}
|
||||
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)
|
||||
{
|
||||
u32 chosenMoveId = gBattleStruct->aiMoveOrAction[gActiveBattler];
|
||||
gBattlerTarget = gBattleStruct->aiChosenTarget[gActiveBattler];
|
||||
gBattlePalaceMoveSelectionRngValue = gRngValue;
|
||||
BtlController_EmitTwoReturnValues(BUFFER_B, 10, ChooseMoveAndTargetInBattlePalace());
|
||||
BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (gBattlerTarget << 8));
|
||||
PlayerBufferExecCompleted();
|
||||
}
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ u16 ChooseMoveAndTargetInBattlePalace(void)
|
||||
// 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
|
||||
// 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)
|
||||
{
|
||||
|
@ -3159,7 +3159,7 @@ void SwitchInClearSetData(void)
|
||||
// Reset damage to prevent things like red card activating if the switched-in mon is holding it
|
||||
gSpecialStatuses[gActiveBattler].physicalDmg = 0;
|
||||
gSpecialStatuses[gActiveBattler].specialDmg = 0;
|
||||
|
||||
|
||||
gBattleStruct->overwrittenAbilities[gActiveBattler] = ABILITY_NONE;
|
||||
|
||||
Ai_UpdateSwitchInData(gActiveBattler);
|
||||
@ -3264,7 +3264,7 @@ void FaintClearSetData(void)
|
||||
UndoMegaEvolution(gBattlerPartyIndexes[gActiveBattler]);
|
||||
|
||||
gBattleStruct->overwrittenAbilities[gActiveBattler] = ABILITY_NONE;
|
||||
|
||||
|
||||
// If the fainted mon was involved in a Sky Drop
|
||||
if (gBattleStruct->skyDropTargets[gActiveBattler] != 0xFF)
|
||||
{
|
||||
@ -3303,7 +3303,7 @@ void FaintClearSetData(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Clear Z-Move data
|
||||
gBattleStruct->zmove.active = FALSE;
|
||||
gBattleStruct->zmove.toBeUsed[gActiveBattler] = MOVE_NONE;
|
||||
@ -3973,7 +3973,8 @@ static void HandleTurnActionSelectionState(void)
|
||||
gBattleCommunication[gActiveBattler] = STATE_BEFORE_ACTION_CHOSEN;
|
||||
|
||||
// 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);
|
||||
}
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user