mirror of
https://github.com/Ninjdai1/pokeemerald.git
synced 2025-01-13 23:23:43 +01:00
Merge pull request #2660 from DizzyEggg/ace_voltswitch
Fix Volt Switch / Roar with ace pokemon
This commit is contained in:
commit
827bf11307
@ -645,6 +645,7 @@ struct BattleStruct
|
|||||||
struct StolenItem itemStolen[PARTY_SIZE]; // Player's team that had items stolen (two bytes per party member)
|
struct StolenItem itemStolen[PARTY_SIZE]; // Player's team that had items stolen (two bytes per party member)
|
||||||
u8 blunderPolicy:1; // should blunder policy activate
|
u8 blunderPolicy:1; // should blunder policy activate
|
||||||
u8 swapDamageCategory:1; // Photon Geyser, Shell Side Arm, Light That Burns the Sky
|
u8 swapDamageCategory:1; // Photon Geyser, Shell Side Arm, Light That Burns the Sky
|
||||||
|
u8 forcedSwitch:4; // For each battler
|
||||||
u8 switchInAbilityPostponed:4; // To not activate against an empty field, each bit for battler
|
u8 switchInAbilityPostponed:4; // To not activate against an empty field, each bit for battler
|
||||||
u8 ballSpriteIds[2]; // item gfx, window gfx
|
u8 ballSpriteIds[2]; // item gfx, window gfx
|
||||||
u8 stickyWebUser;
|
u8 stickyWebUser;
|
||||||
|
@ -27,6 +27,15 @@ static bool32 AiExpectsToFaintPlayer(void);
|
|||||||
static bool32 AI_ShouldHeal(u32 healAmount);
|
static bool32 AI_ShouldHeal(u32 healAmount);
|
||||||
static bool32 AI_OpponentCanFaintAiWithMod(u32 healAmount);
|
static bool32 AI_OpponentCanFaintAiWithMod(u32 healAmount);
|
||||||
|
|
||||||
|
static bool32 IsAceMon(u32 battlerId, u32 monPartyId)
|
||||||
|
{
|
||||||
|
if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON
|
||||||
|
&& !(gBattleStruct->forcedSwitch & gBitTable[battlerId])
|
||||||
|
&& monPartyId == CalculateEnemyPartyCount()-1)
|
||||||
|
return TRUE;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
void GetAIPartyIndexes(u32 battlerId, s32 *firstId, s32 *lastId)
|
void GetAIPartyIndexes(u32 battlerId, s32 *firstId, s32 *lastId)
|
||||||
{
|
{
|
||||||
if (BATTLE_TWO_VS_ONE_OPPONENT && (battlerId & BIT_SIDE) == B_SIDE_OPPONENT)
|
if (BATTLE_TWO_VS_ONE_OPPONENT && (battlerId & BIT_SIDE) == B_SIDE_OPPONENT)
|
||||||
@ -109,8 +118,7 @@ static bool8 ShouldSwitchIfWonderGuard(void)
|
|||||||
continue;
|
continue;
|
||||||
if (i == gBattlerPartyIndexes[gActiveBattler])
|
if (i == gBattlerPartyIndexes[gActiveBattler])
|
||||||
continue;
|
continue;
|
||||||
if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON
|
if (IsAceMon(gActiveBattler, i))
|
||||||
&& i == (CalculateEnemyPartyCount()-1))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (opposingBattler = GetBattlerAtPosition(opposingPosition), j = 0; j < MAX_MON_MOVES; j++)
|
for (opposingBattler = GetBattlerAtPosition(opposingPosition), j = 0; j < MAX_MON_MOVES; j++)
|
||||||
@ -202,8 +210,7 @@ static bool8 FindMonThatAbsorbsOpponentsMove(void)
|
|||||||
continue;
|
continue;
|
||||||
if (i == *(gBattleStruct->monToSwitchIntoId + battlerIn2))
|
if (i == *(gBattleStruct->monToSwitchIntoId + battlerIn2))
|
||||||
continue;
|
continue;
|
||||||
if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON
|
if (IsAceMon(gActiveBattler, i))
|
||||||
&& i == (CalculateEnemyPartyCount()-1))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
||||||
@ -283,9 +290,8 @@ static bool8 ShouldSwitchIfGameStatePrompt(void)
|
|||||||
|
|
||||||
for (i = firstId; i < lastId; i++)
|
for (i = firstId; i < lastId; i++)
|
||||||
{
|
{
|
||||||
if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON
|
if (IsAceMon(gActiveBattler, i))
|
||||||
&& i == (CalculateEnemyPartyCount()-1))
|
continue;
|
||||||
break;
|
|
||||||
|
|
||||||
//Look for mon in party that is able to be switched into and has ability that sets terrain
|
//Look for mon in party that is able to be switched into and has ability that sets terrain
|
||||||
if (GetMonData(&party[i], MON_DATA_HP) != 0
|
if (GetMonData(&party[i], MON_DATA_HP) != 0
|
||||||
@ -576,8 +582,7 @@ static bool8 FindMonWithFlagsAndSuperEffective(u16 flags, u8 moduloPercent)
|
|||||||
continue;
|
continue;
|
||||||
if (i == *(gBattleStruct->monToSwitchIntoId + battlerIn2))
|
if (i == *(gBattleStruct->monToSwitchIntoId + battlerIn2))
|
||||||
continue;
|
continue;
|
||||||
if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON
|
if (IsAceMon(gActiveBattler, i))
|
||||||
&& i == (CalculateEnemyPartyCount()-1))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
||||||
@ -619,6 +624,7 @@ bool32 ShouldSwitch(void)
|
|||||||
struct Pokemon *party;
|
struct Pokemon *party;
|
||||||
s32 i;
|
s32 i;
|
||||||
s32 availableToSwitch;
|
s32 availableToSwitch;
|
||||||
|
bool32 hasAceMon = FALSE;
|
||||||
|
|
||||||
if (gBattleMons[gActiveBattler].status2 & (STATUS2_WRAPPED | STATUS2_ESCAPE_PREVENTION))
|
if (gBattleMons[gActiveBattler].status2 & (STATUS2_WRAPPED | STATUS2_ESCAPE_PREVENTION))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -668,15 +674,22 @@ bool32 ShouldSwitch(void)
|
|||||||
continue;
|
continue;
|
||||||
if (i == *(gBattleStruct->monToSwitchIntoId + battlerIn2))
|
if (i == *(gBattleStruct->monToSwitchIntoId + battlerIn2))
|
||||||
continue;
|
continue;
|
||||||
if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON
|
if (IsAceMon(gActiveBattler, i))
|
||||||
&& i == (CalculateEnemyPartyCount()-1))
|
{
|
||||||
|
hasAceMon = TRUE;
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
availableToSwitch++;
|
availableToSwitch++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (availableToSwitch == 0)
|
if (availableToSwitch == 0)
|
||||||
|
{
|
||||||
|
if (hasAceMon) // If the ace mon is the only available mon, use it
|
||||||
|
availableToSwitch++;
|
||||||
|
else
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
//NOTE: The sequence of the below functions matter! Do not change unless you have carefully considered the outcome.
|
//NOTE: The sequence of the below functions matter! Do not change unless you have carefully considered the outcome.
|
||||||
//Since the order is sequencial, and some of these functions prompt switch to specific party members.
|
//Since the order is sequencial, and some of these functions prompt switch to specific party members.
|
||||||
@ -758,8 +771,7 @@ void AI_TrySwitchOrUseItem(void)
|
|||||||
continue;
|
continue;
|
||||||
if (monToSwitchId == *(gBattleStruct->monToSwitchIntoId + battlerIn2))
|
if (monToSwitchId == *(gBattleStruct->monToSwitchIntoId + battlerIn2))
|
||||||
continue;
|
continue;
|
||||||
if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON
|
if (IsAceMon(gActiveBattler, monToSwitchId))
|
||||||
&& monToSwitchId == (CalculateEnemyPartyCount()-1))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -916,7 +928,7 @@ u8 GetMostSuitableMonToSwitchInto(void)
|
|||||||
s32 lastId = 0; // + 1
|
s32 lastId = 0; // + 1
|
||||||
struct Pokemon *party;
|
struct Pokemon *party;
|
||||||
s32 i, j, aliveCount = 0;
|
s32 i, j, aliveCount = 0;
|
||||||
u8 invalidMons = 0;
|
u32 invalidMons = 0, aceMonId = PARTY_SIZE;
|
||||||
|
|
||||||
if (*(gBattleStruct->monToSwitchIntoId + gActiveBattler) != PARTY_SIZE)
|
if (*(gBattleStruct->monToSwitchIntoId + gActiveBattler) != PARTY_SIZE)
|
||||||
return *(gBattleStruct->monToSwitchIntoId + gActiveBattler);
|
return *(gBattleStruct->monToSwitchIntoId + gActiveBattler);
|
||||||
@ -958,13 +970,20 @@ u8 GetMostSuitableMonToSwitchInto(void)
|
|||||||
|| gBattlerPartyIndexes[battlerIn2] == i
|
|| gBattlerPartyIndexes[battlerIn2] == i
|
||||||
|| i == *(gBattleStruct->monToSwitchIntoId + battlerIn1)
|
|| i == *(gBattleStruct->monToSwitchIntoId + battlerIn1)
|
||||||
|| i == *(gBattleStruct->monToSwitchIntoId + battlerIn2)
|
|| i == *(gBattleStruct->monToSwitchIntoId + battlerIn2)
|
||||||
|| (GetMonAbility(&party[i]) == ABILITY_TRUANT && IsTruantMonVulnerable(gActiveBattler, opposingBattler)) // While not really invalid per say, not really wise to switch into this mon.
|
|| (GetMonAbility(&party[i]) == ABILITY_TRUANT && IsTruantMonVulnerable(gActiveBattler, opposingBattler))) // While not really invalid per say, not really wise to switch into this mon.)
|
||||||
|| ((AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON)
|
{
|
||||||
&& i == (CalculateEnemyPartyCount() - 1))) //Save Ace Pokemon for last
|
|
||||||
invalidMons |= gBitTable[i];
|
invalidMons |= gBitTable[i];
|
||||||
|
}
|
||||||
|
else if (IsAceMon(gActiveBattler, i))// Save Ace Pokemon for last.
|
||||||
|
{
|
||||||
|
aceMonId = i;
|
||||||
|
invalidMons |= gBitTable[i];
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
aliveCount++;
|
aliveCount++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bestMonId = GetBestMonBatonPass(party, firstId, lastId, invalidMons, aliveCount);
|
bestMonId = GetBestMonBatonPass(party, firstId, lastId, invalidMons, aliveCount);
|
||||||
if (bestMonId != PARTY_SIZE)
|
if (bestMonId != PARTY_SIZE)
|
||||||
@ -978,6 +997,11 @@ u8 GetMostSuitableMonToSwitchInto(void)
|
|||||||
if (bestMonId != PARTY_SIZE)
|
if (bestMonId != PARTY_SIZE)
|
||||||
return bestMonId;
|
return bestMonId;
|
||||||
|
|
||||||
|
// If ace mon is the last available Pokemon and U-Turn/Volt Switch was used - switch to the mon.
|
||||||
|
if (aceMonId != PARTY_SIZE
|
||||||
|
&& (gBattleMoves[gLastUsedMove].effect == EFFECT_HIT_ESCAPE || gBattleMoves[gLastUsedMove].effect == EFFECT_PARTING_SHOT))
|
||||||
|
return aceMonId;
|
||||||
|
|
||||||
return PARTY_SIZE;
|
return PARTY_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7125,6 +7125,7 @@ static void Cmd_switchineffects(void)
|
|||||||
gBattlerFainted++;
|
gBattlerFainted++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
gBattleStruct->forcedSwitch &= ~(gBitTable[gActiveBattler]);
|
||||||
gBattlescriptCurrInstr = cmd->nextInstr;
|
gBattlescriptCurrInstr = cmd->nextInstr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -12312,6 +12313,7 @@ static void Cmd_forcerandomswitch(void)
|
|||||||
{
|
{
|
||||||
*(gBattleStruct->battlerPartyIndexes + gBattlerTarget) = gBattlerPartyIndexes[gBattlerTarget];
|
*(gBattleStruct->battlerPartyIndexes + gBattlerTarget) = gBattlerPartyIndexes[gBattlerTarget];
|
||||||
gBattlescriptCurrInstr = BattleScript_RoarSuccessSwitch;
|
gBattlescriptCurrInstr = BattleScript_RoarSuccessSwitch;
|
||||||
|
gBattleStruct->forcedSwitch |= gBitTable[gBattlerTarget];
|
||||||
*(gBattleStruct->monToSwitchIntoId + gBattlerTarget) = validMons[Random() % validMonsCount];
|
*(gBattleStruct->monToSwitchIntoId + gBattlerTarget) = validMons[Random() % validMonsCount];
|
||||||
|
|
||||||
if (!IsMultiBattle())
|
if (!IsMultiBattle())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user