- 14
- Posts
- 6
- Years
- Seen today
Hi, I've been trying to add something in battle_ai_switch_items.c which will cause the AI to switch out if their pokemon is locked into a move the opponent is immune to. In normal Emerald, the AI will just sit in repeatedly selecting an ineffective move, which can be game breaking if you want trainers in your game to use choice bands regularly.
So far what I have is:
and a little further down, in ShouldSwitch, I have changed it to:
In game, I have been testing it in a battle where the opponent has a banded Armaldo. Basically I bait the Armaldo to use Earthquake with Jolteon, then switch to Gengar which is immune to it. However, as soon as I select a move the following turn, the game freezes. It does not freeze under any other circumstances involving choice banders. The fact that it freezes at this specific point and only this point seems to suggest that the code is at least partially working, but I just can't figure out what's causing it to freeze instead of switching out.
Hoping this is just some amateur error which will be easily spotted by someone else.
So far what I have is:
Code:
static bool8 ShouldSwitchIfLockedIntoBadMove (void)
{
u8 holdEffect;
u8 moveFlags;
u16 *choicedMove = &gBattleStruct->choicedMove[gActiveBattler];
u8 notveryeffectivemove;
u8 nvemovedamage;
u8 opposingPosition;
u8 opposingBattler;
opposingPosition = BATTLE_OPPOSITE(GetBattlerPosition(gActiveBattler));
opposingBattler = GetBattlerAtPosition(opposingPosition);
holdEffect = ItemId_GetHoldEffect(gBattleMons[gActiveBattler].item);
moveFlags = AI_TypeCalc(*choicedMove, gBattleMons[opposingBattler].species, gBattleMons[opposingBattler].ability);
if (holdEffect == HOLD_EFFECT_CHOICE_BAND && moveFlags & MOVE_RESULT_DOESNT_AFFECT_FOE)
{
return TRUE;
}
else
{
return FALSE;
}
}
and a little further down, in ShouldSwitch, I have changed it to:
Code:
if (availableToSwitch == 0)
return FALSE;
if (ShouldSwitchIfPerishSong())
return TRUE;
if (ShouldSwitchIfLockedIntoBadMove())
return TRUE;
if (ShouldSwitchIfWonderGuard())
return TRUE;
if (FindMonThatAbsorbsOpponentsMove())
return TRUE;
if (ShouldSwitchIfNaturalCure())
return TRUE;
if (HasSuperEffectiveMoveAgainstOpponents(FALSE))
return FALSE;
if (AreStatsRaised())
return FALSE;
if (FindMonWithFlagsAndSuperEffective(MOVE_RESULT_DOESNT_AFFECT_FOE, 2)
|| FindMonWithFlagsAndSuperEffective(MOVE_RESULT_NOT_VERY_EFFECTIVE, 3))
return TRUE;
In game, I have been testing it in a battle where the opponent has a banded Armaldo. Basically I bait the Armaldo to use Earthquake with Jolteon, then switch to Gengar which is immune to it. However, as soon as I select a move the following turn, the game freezes. It does not freeze under any other circumstances involving choice banders. The fact that it freezes at this specific point and only this point seems to suggest that the code is at least partially working, but I just can't figure out what's causing it to freeze instead of switching out.
Hoping this is just some amateur error which will be easily spotted by someone else.