diff options
Diffstat (limited to 'src/battle_ai_switch_items.c')
-rw-r--r-- | src/battle_ai_switch_items.c | 490 |
1 files changed, 237 insertions, 253 deletions
diff --git a/src/battle_ai_switch_items.c b/src/battle_ai_switch_items.c index 75d144c3d..a105e7edf 100644 --- a/src/battle_ai_switch_items.c +++ b/src/battle_ai_switch_items.c @@ -1,32 +1,13 @@ #include "global.h" #include "battle.h" #include "battle_controllers.h" -#include "abilities.h" -#include "moves.h" +#include "constants/abilities.h" +#include "constants/moves.h" #include "pokemon.h" -#include "species.h" -#include "rng.h" +#include "constants/species.h" +#include "random.h" #include "util.h" -#include "items.h" -#include "pokemon_item_effects.h" - -extern u8 gActiveBank; -extern u8 gAbsentBankFlags; -extern u32 gBattleTypeFlags; -extern u32 gStatuses3[BATTLE_BANKS_COUNT]; -extern struct BattlePokemon gBattleMons[BATTLE_BANKS_COUNT]; -extern u16 gBattlePartyID[BATTLE_BANKS_COUNT]; -extern u16 gUnknown_02024250[BATTLE_BANKS_COUNT]; -extern u8 gUnknown_02024270[BATTLE_BANKS_COUNT]; -extern u16 gDynamicBasePower; -extern u8 gBattleMoveFlags; -extern u8 gCritMultiplier; -extern s32 gBattleMoveDamage; - -extern const struct BattleMove gBattleMoves[]; -extern const struct BaseStats gBaseStats[]; -extern const u8 gTypeEffectiveness[]; -extern const u8 * const gItemEffectTable[]; // todo: fix once struct is declared +#include "constants/items.h" // this file's functions static bool8 HasSuperEffectiveMoveAgainstOpponents(bool8 noRng); @@ -35,21 +16,23 @@ static bool8 ShouldUseItem(void); static bool8 ShouldSwitchIfPerishSong(void) { - if (gStatuses3[gActiveBank] & STATUS3_PERISH_SONG - && gDisableStructs[gActiveBank].perishSongTimer1 == 0) + if (gStatuses3[gActiveBattler] & STATUS3_PERISH_SONG + && gDisableStructs[gActiveBattler].perishSongTimer1 == 0) { - *(gBattleStruct->AI_monToSwitchIntoId + gActiveBank) = 6; - EmitTwoReturnValues(1, ACTION_SWITCH, 0); + *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = PARTY_SIZE; + BtlController_EmitTwoReturnValues(1, B_ACTION_SWITCH, 0); return TRUE; } - - return FALSE; + else + { + return FALSE; + } } static bool8 ShouldSwitchIfWonderGuard(void) { - u8 opposingIdentity; - u8 opposingBank; + u8 opposingPosition; + u8 opposingBattler; u8 moveFlags; s32 i, j; s32 firstId; @@ -60,27 +43,27 @@ static bool8 ShouldSwitchIfWonderGuard(void) if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) return FALSE; - opposingIdentity = GetBankIdentity(gActiveBank) ^ BIT_SIDE; + opposingPosition = BATTLE_OPPOSITE(GetBattlerPosition(gActiveBattler)); - if (gBattleMons[GetBankByIdentity(opposingIdentity)].ability != ABILITY_WONDER_GUARD) + if (gBattleMons[GetBattlerAtPosition(opposingPosition)].ability != ABILITY_WONDER_GUARD) return FALSE; - // check if pokemon has a super effective move - for (opposingBank = GetBankByIdentity(opposingIdentity), i = 0; i < 4; i++) + // Check if Pokemon has a super effective move. + for (opposingBattler = GetBattlerAtPosition(opposingPosition), i = 0; i < 4; i++) { - move = gBattleMons[gActiveBank].moves[i]; + move = gBattleMons[gActiveBattler].moves[i]; if (move == MOVE_NONE) continue; - moveFlags = AI_TypeCalc(move, gBattleMons[opposingBank].species, gBattleMons[opposingBank].ability); - if (moveFlags & MOVESTATUS_SUPEREFFECTIVE) + moveFlags = AI_TypeCalc(move, gBattleMons[opposingBattler].species, gBattleMons[opposingBattler].ability); + if (moveFlags & MOVE_RESULT_SUPER_EFFECTIVE) return FALSE; } - // get party information + // Get party information. if (gBattleTypeFlags & (BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_x800000)) { - if ((gActiveBank & BIT_MON) == 0) + if ((gActiveBattler & BIT_FLANK) == B_FLANK_LEFT) firstId = 0, lastId = 3; else firstId = 3, lastId = 6; @@ -90,12 +73,12 @@ static bool8 ShouldSwitchIfWonderGuard(void) firstId = 0, lastId = 6; } - if (GetBankSide(gActiveBank) == SIDE_PLAYER) + if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) party = gPlayerParty; else party = gEnemyParty; - // find a pokemon in the party that has a super effective move + // Find a Pokemon in the party that has a super effective move. for (i = firstId; i < lastId; i++) { if (GetMonData(&party[i], MON_DATA_HP) == 0) @@ -104,35 +87,35 @@ static bool8 ShouldSwitchIfWonderGuard(void) continue; if (GetMonData(&party[i], MON_DATA_SPECIES2) == SPECIES_EGG) continue; - if (i == gBattlePartyID[gActiveBank]) + if (i == gBattlerPartyIndexes[gActiveBattler]) continue; - GetMonData(&party[i], MON_DATA_SPECIES); // unused return value - GetMonData(&party[i], MON_DATA_ALT_ABILITY); // unused return value + GetMonData(&party[i], MON_DATA_SPECIES); // Unused return value. + GetMonData(&party[i], MON_DATA_ALT_ABILITY); // Unused return value. - for (opposingBank = GetBankByIdentity(opposingIdentity), j = 0; j < 4; j++) + for (opposingBattler = GetBattlerAtPosition(opposingPosition), j = 0; j < 4; j++) { move = GetMonData(&party[i], MON_DATA_MOVE1 + j); if (move == MOVE_NONE) continue; - moveFlags = AI_TypeCalc(move, gBattleMons[opposingBank].species, gBattleMons[opposingBank].ability); - if (moveFlags & MOVESTATUS_SUPEREFFECTIVE && Random() % 3 < 2) + moveFlags = AI_TypeCalc(move, gBattleMons[opposingBattler].species, gBattleMons[opposingBattler].ability); + if (moveFlags & MOVE_RESULT_SUPER_EFFECTIVE && Random() % 3 < 2) { - // we found a mon - *(gBattleStruct->AI_monToSwitchIntoId + gActiveBank) = i; - EmitTwoReturnValues(1, ACTION_SWITCH, 0); + // We found a mon. + *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = i; + BtlController_EmitTwoReturnValues(1, B_ACTION_SWITCH, 0); return TRUE; } } } - return FALSE; // at this point there is not a single pokemon in the party that has a super effective move against a pokemon with wonder guard + return FALSE; // There is not a single Pokemon in the party that has a super effective move against a mon with Wonder Guard. } static bool8 FindMonThatAbsorbsOpponentsMove(void) { - u8 bankIn1, bankIn2; + u8 battlerIn1, battlerIn2; u8 absorbingTypeAbility; s32 firstId; s32 lastId; // + 1 @@ -141,42 +124,42 @@ static bool8 FindMonThatAbsorbsOpponentsMove(void) if (HasSuperEffectiveMoveAgainstOpponents(TRUE) && Random() % 3 != 0) return FALSE; - if (gUnknown_02024250[gActiveBank] == 0) + if (gLastLandedMoves[gActiveBattler] == 0) return FALSE; - if (gUnknown_02024250[gActiveBank] == 0xFFFF) + if (gLastLandedMoves[gActiveBattler] == 0xFFFF) return FALSE; - if (gBattleMoves[gUnknown_02024250[gActiveBank]].power == 0) + if (gBattleMoves[gLastLandedMoves[gActiveBattler]].power == 0) return FALSE; if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { - bankIn1 = gActiveBank; - if (gAbsentBankFlags & gBitTable[GetBankByIdentity(GetBankIdentity(gActiveBank) ^ BIT_MON)]) - bankIn2 = gActiveBank; + battlerIn1 = gActiveBattler; + if (gAbsentBattlerFlags & gBitTable[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))]) + battlerIn2 = gActiveBattler; else - bankIn2 = GetBankByIdentity(GetBankIdentity(gActiveBank) ^ BIT_MON); + battlerIn2 = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler))); } else { - bankIn1 = gActiveBank; - bankIn2 = gActiveBank; + battlerIn1 = gActiveBattler; + battlerIn2 = gActiveBattler; } - if (gBattleMoves[gUnknown_02024250[gActiveBank]].type == TYPE_FIRE) + if (gBattleMoves[gLastLandedMoves[gActiveBattler]].type == TYPE_FIRE) absorbingTypeAbility = ABILITY_FLASH_FIRE; - else if (gBattleMoves[gUnknown_02024250[gActiveBank]].type == TYPE_WATER) + else if (gBattleMoves[gLastLandedMoves[gActiveBattler]].type == TYPE_WATER) absorbingTypeAbility = ABILITY_WATER_ABSORB; - else if (gBattleMoves[gUnknown_02024250[gActiveBank]].type == TYPE_ELECTRIC) + else if (gBattleMoves[gLastLandedMoves[gActiveBattler]].type == TYPE_ELECTRIC) absorbingTypeAbility = ABILITY_VOLT_ABSORB; else return FALSE; - if (gBattleMons[gActiveBank].ability == absorbingTypeAbility) + if (gBattleMons[gActiveBattler].ability == absorbingTypeAbility) return FALSE; if (gBattleTypeFlags & (BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_x800000)) { - if ((gActiveBank & BIT_MON) == 0) + if ((gActiveBattler & BIT_FLANK) == B_FLANK_LEFT) firstId = 0, lastId = 3; else firstId = 3, lastId = 6; @@ -186,7 +169,7 @@ static bool8 FindMonThatAbsorbsOpponentsMove(void) firstId = 0, lastId = 6; } - if (GetBankSide(gActiveBank) == SIDE_PLAYER) + if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) party = gPlayerParty; else party = gEnemyParty; @@ -202,13 +185,13 @@ static bool8 FindMonThatAbsorbsOpponentsMove(void) continue; if (GetMonData(&party[i], MON_DATA_SPECIES2) == SPECIES_EGG) continue; - if (i == gBattlePartyID[bankIn1]) + if (i == gBattlerPartyIndexes[battlerIn1]) continue; - if (i == gBattlePartyID[bankIn2]) + if (i == gBattlerPartyIndexes[battlerIn2]) continue; - if (i == *(gBattleStruct->monToSwitchIntoId + bankIn1)) + if (i == *(gBattleStruct->monToSwitchIntoId + battlerIn1)) continue; - if (i == *(gBattleStruct->monToSwitchIntoId + bankIn2)) + if (i == *(gBattleStruct->monToSwitchIntoId + battlerIn2)) continue; species = GetMonData(&party[i], MON_DATA_SPECIES); @@ -219,9 +202,9 @@ static bool8 FindMonThatAbsorbsOpponentsMove(void) if (absorbingTypeAbility == monAbility && Random() & 1) { - // we found a mon - *(gBattleStruct->AI_monToSwitchIntoId + gActiveBank) = i; - EmitTwoReturnValues(1, ACTION_SWITCH, 0); + // we found a mon. + *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = i; + BtlController_EmitTwoReturnValues(1, B_ACTION_SWITCH, 0); return TRUE; } } @@ -231,34 +214,35 @@ static bool8 FindMonThatAbsorbsOpponentsMove(void) static bool8 ShouldSwitchIfNaturalCure(void) { - if (!(gBattleMons[gActiveBank].status1 & STATUS_SLEEP)) + if (!(gBattleMons[gActiveBattler].status1 & STATUS1_SLEEP)) return FALSE; - if (gBattleMons[gActiveBank].ability != ABILITY_NATURAL_CURE) + if (gBattleMons[gActiveBattler].ability != ABILITY_NATURAL_CURE) return FALSE; - if (gBattleMons[gActiveBank].hp < gBattleMons[gActiveBank].maxHP / 2) + if (gBattleMons[gActiveBattler].hp < gBattleMons[gActiveBattler].maxHP / 2) return FALSE; - if ((gUnknown_02024250[gActiveBank] == 0 || gUnknown_02024250[gActiveBank] == 0xFFFF) && Random() & 1) + if ((gLastLandedMoves[gActiveBattler] == 0 || gLastLandedMoves[gActiveBattler] == 0xFFFF) && Random() & 1) { - *(gBattleStruct->AI_monToSwitchIntoId + gActiveBank) = 6; - EmitTwoReturnValues(1, ACTION_SWITCH, 0); + *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = PARTY_SIZE; + BtlController_EmitTwoReturnValues(1, B_ACTION_SWITCH, 0); return TRUE; } - else if (gBattleMoves[gUnknown_02024250[gActiveBank]].power == 0 && Random() & 1) + else if (gBattleMoves[gLastLandedMoves[gActiveBattler]].power == 0 && Random() & 1) { - *(gBattleStruct->AI_monToSwitchIntoId + gActiveBank) = 6; - EmitTwoReturnValues(1, ACTION_SWITCH, 0); + *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = PARTY_SIZE; + BtlController_EmitTwoReturnValues(1, B_ACTION_SWITCH, 0); return TRUE; } - if (FindMonWithFlagsAndSuperEffective(MOVESTATUS_NOTAFFECTED, 1)) + if (FindMonWithFlagsAndSuperEffective(MOVE_RESULT_DOESNT_AFFECT_FOE, 1)) return TRUE; - if (FindMonWithFlagsAndSuperEffective(MOVESTATUS_NOTVERYEFFECTIVE, 1)) + if (FindMonWithFlagsAndSuperEffective(MOVE_RESULT_NOT_VERY_EFFECTIVE, 1)) return TRUE; + if (Random() & 1) { - *(gBattleStruct->AI_monToSwitchIntoId + gActiveBank) = 6; - EmitTwoReturnValues(1, ACTION_SWITCH, 0); + *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = PARTY_SIZE; + BtlController_EmitTwoReturnValues(1, B_ACTION_SWITCH, 0); return TRUE; } @@ -267,25 +251,25 @@ static bool8 ShouldSwitchIfNaturalCure(void) static bool8 HasSuperEffectiveMoveAgainstOpponents(bool8 noRng) { - u8 opposingIdentity; - u8 opposingBank; + u8 opposingPosition; + u8 opposingBattler; s32 i; u8 moveFlags; u16 move; - opposingIdentity = GetBankIdentity(gActiveBank) ^ BIT_SIDE; - opposingBank = GetBankByIdentity(opposingIdentity); + opposingPosition = BATTLE_OPPOSITE(GetBattlerPosition(gActiveBattler)); + opposingBattler = GetBattlerAtPosition(opposingPosition); - if (!(gAbsentBankFlags & gBitTable[opposingBank])) + if (!(gAbsentBattlerFlags & gBitTable[opposingBattler])) { for (i = 0; i < 4; i++) { - move = gBattleMons[gActiveBank].moves[i]; + move = gBattleMons[gActiveBattler].moves[i]; if (move == MOVE_NONE) continue; - moveFlags = AI_TypeCalc(move, gBattleMons[opposingBank].species, gBattleMons[opposingBank].ability); - if (moveFlags & MOVESTATUS_SUPEREFFECTIVE) + moveFlags = AI_TypeCalc(move, gBattleMons[opposingBattler].species, gBattleMons[opposingBattler].ability); + if (moveFlags & MOVE_RESULT_SUPER_EFFECTIVE) { if (noRng) return TRUE; @@ -297,18 +281,18 @@ static bool8 HasSuperEffectiveMoveAgainstOpponents(bool8 noRng) if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) return FALSE; - opposingBank = GetBankByIdentity(opposingIdentity ^ BIT_MON); + opposingBattler = GetBattlerAtPosition(BATTLE_PARTNER(opposingPosition)); - if (!(gAbsentBankFlags & gBitTable[opposingBank])) + if (!(gAbsentBattlerFlags & gBitTable[opposingBattler])) { for (i = 0; i < 4; i++) { - move = gBattleMons[gActiveBank].moves[i]; + move = gBattleMons[gActiveBattler].moves[i]; if (move == MOVE_NONE) continue; - moveFlags = AI_TypeCalc(move, gBattleMons[opposingBank].species, gBattleMons[opposingBank].ability); - if (moveFlags & MOVESTATUS_SUPEREFFECTIVE) + moveFlags = AI_TypeCalc(move, gBattleMons[opposingBattler].species, gBattleMons[opposingBattler].ability); + if (moveFlags & MOVE_RESULT_SUPER_EFFECTIVE) { if (noRng) return TRUE; @@ -328,8 +312,8 @@ static bool8 AreStatsRaised(void) for (i = 0; i < BATTLE_STATS_NO; i++) { - if (gBattleMons[gActiveBank].statStages[i] > 6) - buffedStatsValue += gBattleMons[gActiveBank].statStages[i] - 6; + if (gBattleMons[gActiveBattler].statStages[i] > 6) + buffedStatsValue += gBattleMons[gActiveBattler].statStages[i] - 6; } return (buffedStatsValue > 3); @@ -337,7 +321,7 @@ static bool8 AreStatsRaised(void) static bool8 FindMonWithFlagsAndSuperEffective(u8 flags, u8 moduloPercent) { - u8 bankIn1, bankIn2; + u8 battlerIn1, battlerIn2; s32 firstId; s32 lastId; // + 1 struct Pokemon *party; @@ -345,32 +329,32 @@ static bool8 FindMonWithFlagsAndSuperEffective(u8 flags, u8 moduloPercent) u16 move; u8 moveFlags; - if (gUnknown_02024250[gActiveBank] == 0) + if (gLastLandedMoves[gActiveBattler] == 0) return FALSE; - if (gUnknown_02024250[gActiveBank] == 0xFFFF) + if (gLastLandedMoves[gActiveBattler] == 0xFFFF) return FALSE; - if (gUnknown_02024270[gActiveBank] == 0xFF) + if (gLastHitBy[gActiveBattler] == 0xFF) return FALSE; - if (gBattleMoves[gUnknown_02024250[gActiveBank]].power == 0) + if (gBattleMoves[gLastLandedMoves[gActiveBattler]].power == 0) return FALSE; if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { - bankIn1 = gActiveBank; - if (gAbsentBankFlags & gBitTable[GetBankByIdentity(GetBankIdentity(gActiveBank) ^ BIT_MON)]) - bankIn2 = gActiveBank; + battlerIn1 = gActiveBattler; + if (gAbsentBattlerFlags & gBitTable[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))]) + battlerIn2 = gActiveBattler; else - bankIn2 = GetBankByIdentity(GetBankIdentity(gActiveBank) ^ BIT_MON); + battlerIn2 = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler))); } else { - bankIn1 = gActiveBank; - bankIn2 = gActiveBank; + battlerIn1 = gActiveBattler; + battlerIn2 = gActiveBattler; } if (gBattleTypeFlags & (BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_x800000)) { - if ((gActiveBank & BIT_MON) == 0) + if ((gActiveBattler & BIT_FLANK) == 0) firstId = 0, lastId = 3; else firstId = 3, lastId = 6; @@ -380,7 +364,7 @@ static bool8 FindMonWithFlagsAndSuperEffective(u8 flags, u8 moduloPercent) firstId = 0, lastId = 6; } - if (GetBankSide(gActiveBank) == SIDE_PLAYER) + if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) party = gPlayerParty; else party = gEnemyParty; @@ -396,13 +380,13 @@ static bool8 FindMonWithFlagsAndSuperEffective(u8 flags, u8 moduloPercent) continue; if (GetMonData(&party[i], MON_DATA_SPECIES2) == SPECIES_EGG) continue; - if (i == gBattlePartyID[bankIn1]) + if (i == gBattlerPartyIndexes[battlerIn1]) continue; - if (i == gBattlePartyID[bankIn2]) + if (i == gBattlerPartyIndexes[battlerIn2]) continue; - if (i == *(gBattleStruct->monToSwitchIntoId + bankIn1)) + if (i == *(gBattleStruct->monToSwitchIntoId + battlerIn1)) continue; - if (i == *(gBattleStruct->monToSwitchIntoId + bankIn2)) + if (i == *(gBattleStruct->monToSwitchIntoId + battlerIn2)) continue; species = GetMonData(&party[i], MON_DATA_SPECIES); @@ -411,10 +395,10 @@ static bool8 FindMonWithFlagsAndSuperEffective(u8 flags, u8 moduloPercent) else monAbility = gBaseStats[species].ability1; - moveFlags = AI_TypeCalc(gUnknown_02024250[gActiveBank], species, monAbility); + moveFlags = AI_TypeCalc(gLastLandedMoves[gActiveBattler], species, monAbility); if (moveFlags & flags) { - bankIn1 = gUnknown_02024270[gActiveBank]; + battlerIn1 = gLastHitBy[gActiveBattler]; for (j = 0; j < 4; j++) { @@ -422,11 +406,11 @@ static bool8 FindMonWithFlagsAndSuperEffective(u8 flags, u8 moduloPercent) if (move == 0) continue; - moveFlags = AI_TypeCalc(move, gBattleMons[bankIn1].species, gBattleMons[bankIn1].ability); - if (moveFlags & MOVESTATUS_SUPEREFFECTIVE && Random() % moduloPercent == 0) + moveFlags = AI_TypeCalc(move, gBattleMons[battlerIn1].species, gBattleMons[battlerIn1].ability); + if (moveFlags & MOVE_RESULT_SUPER_EFFECTIVE && Random() % moduloPercent == 0) { - *(gBattleStruct->AI_monToSwitchIntoId + gActiveBank) = i; - EmitTwoReturnValues(1, ACTION_SWITCH, 0); + *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = i; + BtlController_EmitTwoReturnValues(1, B_ACTION_SWITCH, 0); return TRUE; } } @@ -438,27 +422,27 @@ static bool8 FindMonWithFlagsAndSuperEffective(u8 flags, u8 moduloPercent) static bool8 ShouldSwitch(void) { - u8 bankIn1, bankIn2; - u8 *activeBankPtr; // needed to match + u8 battlerIn1, battlerIn2; + u8 *activeBattlerPtr; // Needed to match. s32 firstId; s32 lastId; // + 1 struct Pokemon *party; s32 i; s32 availableToSwitch; - if (gBattleMons[*(activeBankPtr = &gActiveBank)].status2 & (STATUS2_WRAPPED | STATUS2_ESCAPE_PREVENTION)) + if (gBattleMons[*(activeBattlerPtr = &gActiveBattler)].status2 & (STATUS2_WRAPPED | STATUS2_ESCAPE_PREVENTION)) + return FALSE; + if (gStatuses3[gActiveBattler] & STATUS3_ROOTED) return FALSE; - if (gStatuses3[gActiveBank] & STATUS3_ROOTED) + if (ABILITY_ON_OPPOSING_FIELD(gActiveBattler, ABILITY_SHADOW_TAG)) return FALSE; - if (AbilityBattleEffects(ABILITYEFFECT_CHECK_OTHER_SIDE, gActiveBank, ABILITY_SHADOW_TAG, 0, 0)) + if (ABILITY_ON_OPPOSING_FIELD(gActiveBattler, ABILITY_ARENA_TRAP)) // Misses the flying type and Levitate check. return FALSE; - if (AbilityBattleEffects(ABILITYEFFECT_CHECK_OTHER_SIDE, gActiveBank, ABILITY_ARENA_TRAP, 0, 0)) - return FALSE; // misses the flying or levitate check - if (AbilityBattleEffects(ABILITYEFFECT_FIELD_SPORT, 0, ABILITY_MAGNET_PULL, 0, 0)) + if (ABILITY_ON_FIELD2(ABILITY_MAGNET_PULL)) { - if (gBattleMons[gActiveBank].type1 == TYPE_STEEL) + if (gBattleMons[gActiveBattler].type1 == TYPE_STEEL) return FALSE; - if (gBattleMons[gActiveBank].type2 == TYPE_STEEL) + if (gBattleMons[gActiveBattler].type2 == TYPE_STEEL) return FALSE; } if (gBattleTypeFlags & BATTLE_TYPE_ARENA) @@ -467,21 +451,21 @@ static bool8 ShouldSwitch(void) availableToSwitch = 0; if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { - bankIn1 = *activeBankPtr; - if (gAbsentBankFlags & gBitTable[GetBankByIdentity(GetBankIdentity(*activeBankPtr) ^ BIT_MON)]) - bankIn2 = *activeBankPtr; + battlerIn1 = *activeBattlerPtr; + if (gAbsentBattlerFlags & gBitTable[GetBattlerAtPosition(GetBattlerPosition(*activeBattlerPtr) ^ BIT_FLANK)]) + battlerIn2 = *activeBattlerPtr; else - bankIn2 = GetBankByIdentity(GetBankIdentity(*activeBankPtr) ^ BIT_MON); + battlerIn2 = GetBattlerAtPosition(GetBattlerPosition(*activeBattlerPtr) ^ BIT_FLANK); } else { - bankIn1 = *activeBankPtr; - bankIn2 = *activeBankPtr; + battlerIn1 = *activeBattlerPtr; + battlerIn2 = *activeBattlerPtr; } if (gBattleTypeFlags & (BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_x800000)) { - if ((gActiveBank & BIT_MON) == 0) + if ((gActiveBattler & BIT_FLANK) == B_FLANK_LEFT) firstId = 0, lastId = 3; else firstId = 3, lastId = 6; @@ -491,7 +475,7 @@ static bool8 ShouldSwitch(void) firstId = 0, lastId = 6; } - if (GetBankSide(gActiveBank) == SIDE_PLAYER) + if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) party = gPlayerParty; else party = gEnemyParty; @@ -504,13 +488,13 @@ static bool8 ShouldSwitch(void) continue; if (GetMonData(&party[i], MON_DATA_SPECIES2) == SPECIES_EGG) continue; - if (i == gBattlePartyID[bankIn1]) + if (i == gBattlerPartyIndexes[battlerIn1]) continue; - if (i == gBattlePartyID[bankIn2]) + if (i == gBattlerPartyIndexes[battlerIn2]) continue; - if (i == *(gBattleStruct->monToSwitchIntoId + bankIn1)) + if (i == *(gBattleStruct->monToSwitchIntoId + battlerIn1)) continue; - if (i == *(gBattleStruct->monToSwitchIntoId + bankIn2)) + if (i == *(gBattleStruct->monToSwitchIntoId + battlerIn2)) continue; availableToSwitch++; @@ -530,8 +514,8 @@ static bool8 ShouldSwitch(void) return FALSE; if (AreStatsRaised()) return FALSE; - if (FindMonWithFlagsAndSuperEffective(MOVESTATUS_NOTAFFECTED, 2) - || FindMonWithFlagsAndSuperEffective(MOVESTATUS_NOTVERYEFFECTIVE, 3)) + if (FindMonWithFlagsAndSuperEffective(MOVE_RESULT_DOESNT_AFFECT_FOE, 2) + || FindMonWithFlagsAndSuperEffective(MOVE_RESULT_NOT_VERY_EFFECTIVE, 3)) return TRUE; return FALSE; @@ -540,12 +524,12 @@ static bool8 ShouldSwitch(void) void AI_TrySwitchOrUseItem(void) { struct Pokemon *party; - u8 bankIn1, bankIn2; + u8 battlerIn1, battlerIn2; s32 firstId; s32 lastId; // + 1 - u8 bankIdentity = GetBankIdentity(gActiveBank); + u8 battlerIdentity = GetBattlerPosition(gActiveBattler); - if (GetBankSide(gActiveBank) == SIDE_PLAYER) + if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) party = gPlayerParty; else party = gEnemyParty; @@ -554,25 +538,25 @@ void AI_TrySwitchOrUseItem(void) { if (ShouldSwitch()) { - if (*(gBattleStruct->AI_monToSwitchIntoId + gActiveBank) == 6) + if (*(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) == PARTY_SIZE) { s32 monToSwitchId = GetMostSuitableMonToSwitchInto(); - if (monToSwitchId == 6) + if (monToSwitchId == PARTY_SIZE) { if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) { - bankIn1 = GetBankByIdentity(bankIdentity); - bankIn2 = bankIn1; + battlerIn1 = GetBattlerAtPosition(battlerIdentity); + battlerIn2 = battlerIn1; } else { - bankIn1 = GetBankByIdentity(bankIdentity); - bankIn2 = GetBankByIdentity(bankIdentity ^ BIT_MON); + battlerIn1 = GetBattlerAtPosition(battlerIdentity); + battlerIn2 = GetBattlerAtPosition(battlerIdentity ^ BIT_FLANK); } if (gBattleTypeFlags & (BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_x800000)) { - if ((gActiveBank & BIT_MON) == 0) + if ((gActiveBattler & BIT_FLANK) == B_FLANK_LEFT) firstId = 0, lastId = 3; else firstId = 3, lastId = 6; @@ -586,23 +570,23 @@ void AI_TrySwitchOrUseItem(void) { if (GetMonData(&party[monToSwitchId], MON_DATA_HP) == 0) continue; - if (monToSwitchId == gBattlePartyID[bankIn1]) + if (monToSwitchId == gBattlerPartyIndexes[battlerIn1]) continue; - if (monToSwitchId == gBattlePartyID[bankIn2]) + if (monToSwitchId == gBattlerPartyIndexes[battlerIn2]) continue; - if (monToSwitchId == *(gBattleStruct->monToSwitchIntoId + bankIn1)) + if (monToSwitchId == *(gBattleStruct->monToSwitchIntoId + battlerIn1)) continue; - if (monToSwitchId == *(gBattleStruct->monToSwitchIntoId + bankIn2)) + if (monToSwitchId == *(gBattleStruct->monToSwitchIntoId + battlerIn2)) continue; break; } } - *(gBattleStruct->AI_monToSwitchIntoId + gActiveBank) = monToSwitchId; + *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = monToSwitchId; } - *(gBattleStruct->monToSwitchIntoId + gActiveBank) = *(gBattleStruct->AI_monToSwitchIntoId + gActiveBank); + *(gBattleStruct->monToSwitchIntoId + gActiveBattler) = *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler); return; } else if (ShouldUseItem()) @@ -611,7 +595,7 @@ void AI_TrySwitchOrUseItem(void) } } - EmitTwoReturnValues(1, ACTION_USE_MOVE, (gActiveBank ^ BIT_SIDE) << 8); + BtlController_EmitTwoReturnValues(1, B_ACTION_USE_MOVE, (gActiveBattler ^ BIT_SIDE) << 8); } static void ModulateByTypeEffectiveness(u8 atkType, u8 defType1, u8 defType2, u8 *var) @@ -627,10 +611,10 @@ static void ModulateByTypeEffectiveness(u8 atkType, u8 defType1, u8 defType2, u8 } else if (TYPE_EFFECT_ATK_TYPE(i) == atkType) { - // check type1 + // Check type1. if (TYPE_EFFECT_DEF_TYPE(i) == defType1) *var = (*var * TYPE_EFFECT_MULTIPLIER(i)) / 10; - // check type2 + // Check type2. if (TYPE_EFFECT_DEF_TYPE(i) == defType2 && defType1 != defType2) *var = (*var * TYPE_EFFECT_MULTIPLIER(i)) / 10; } @@ -640,10 +624,10 @@ static void ModulateByTypeEffectiveness(u8 atkType, u8 defType1, u8 defType2, u8 u8 GetMostSuitableMonToSwitchInto(void) { - u8 opposingBank; - u8 bestDmg; // note : should be changed to u32 for obvious reasons + u8 opposingBattler; + u8 bestDmg; // Note : should be changed to u32 for obvious reasons. u8 bestMonId; - u8 bankIn1, bankIn2; + u8 battlerIn1, battlerIn2; s32 firstId; s32 lastId; // + 1 struct Pokemon *party; @@ -651,34 +635,34 @@ u8 GetMostSuitableMonToSwitchInto(void) u8 invalidMons; u16 move; - if (*(gBattleStruct->monToSwitchIntoId + gActiveBank) != 6) - return *(gBattleStruct->monToSwitchIntoId + gActiveBank); + if (*(gBattleStruct->monToSwitchIntoId + gActiveBattler) != PARTY_SIZE) + return *(gBattleStruct->monToSwitchIntoId + gActiveBattler); if (gBattleTypeFlags & BATTLE_TYPE_ARENA) - return gBattlePartyID[gActiveBank] + 1; + return gBattlerPartyIndexes[gActiveBattler] + 1; if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { - bankIn1 = gActiveBank; - if (gAbsentBankFlags & gBitTable[GetBankByIdentity(GetBankIdentity(gActiveBank) ^ BIT_MON)]) - bankIn2 = gActiveBank; + battlerIn1 = gActiveBattler; + if (gAbsentBattlerFlags & gBitTable[GetBattlerAtPosition(GetBattlerPosition(gActiveBattler) ^ BIT_FLANK)]) + battlerIn2 = gActiveBattler; else - bankIn2 = GetBankByIdentity(GetBankIdentity(gActiveBank) ^ BIT_MON); + battlerIn2 = GetBattlerAtPosition(GetBattlerPosition(gActiveBattler) ^ BIT_FLANK); - // UB: It considers the opponent only player's side even though it can battle alongside player; - opposingBank = Random() & BIT_MON; - if (gAbsentBankFlags & gBitTable[opposingBank]) - opposingBank ^= BIT_MON; + // UB: It considers the opponent only player's side even though it can battle alongside player. + opposingBattler = Random() & BIT_FLANK; + if (gAbsentBattlerFlags & gBitTable[opposingBattler]) + opposingBattler ^= BIT_FLANK; } else { - opposingBank = GetBankByIdentity(GetBankIdentity(gActiveBank) ^ BIT_SIDE); - bankIn1 = gActiveBank; - bankIn2 = gActiveBank; + opposingBattler = GetBattlerAtPosition(GetBattlerPosition(gActiveBattler) ^ BIT_SIDE); + battlerIn1 = gActiveBattler; + battlerIn2 = gActiveBattler; } if (gBattleTypeFlags & (BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_x800000)) { - if ((gActiveBank & BIT_MON) == 0) + if ((gActiveBattler & BIT_FLANK) == B_FLANK_LEFT) firstId = 0, lastId = 3; else firstId = 3, lastId = 6; @@ -688,34 +672,34 @@ u8 GetMostSuitableMonToSwitchInto(void) firstId = 0, lastId = 6; } - if (GetBankSide(gActiveBank) == SIDE_PLAYER) + if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) party = gPlayerParty; else party = gEnemyParty; invalidMons = 0; - while (invalidMons != 0x3F) // all mons are invalid + while (invalidMons != 0x3F) // All mons are invalid. { bestDmg = 0; bestMonId = 6; - // find the mon which type is the most suitable offensively + // Find the mon whose type is the most suitable offensively. for (i = firstId; i < lastId; i++) { u16 species = GetMonData(&party[i], MON_DATA_SPECIES); if (species != SPECIES_NONE && GetMonData(&party[i], MON_DATA_HP) != 0 && !(gBitTable[i] & invalidMons) - && gBattlePartyID[bankIn1] != i - && gBattlePartyID[bankIn2] != i - && i != *(gBattleStruct->monToSwitchIntoId + bankIn1) - && i != *(gBattleStruct->monToSwitchIntoId + bankIn2)) + && gBattlerPartyIndexes[battlerIn1] != i + && gBattlerPartyIndexes[battlerIn2] != i + && i != *(gBattleStruct->monToSwitchIntoId + battlerIn1) + && i != *(gBattleStruct->monToSwitchIntoId + battlerIn2)) { u8 type1 = gBaseStats[species].type1; u8 type2 = gBaseStats[species].type2; u8 typeDmg = 10; - ModulateByTypeEffectiveness(gBattleMons[opposingBank].type1, type1, type2, &typeDmg); - ModulateByTypeEffectiveness(gBattleMons[opposingBank].type2, type1, type2, &typeDmg); + ModulateByTypeEffectiveness(gBattleMons[opposingBattler].type1, type1, type2, &typeDmg); + ModulateByTypeEffectiveness(gBattleMons[opposingBattler].type2, type1, type2, &typeDmg); if (bestDmg < typeDmg) { bestDmg = typeDmg; @@ -728,49 +712,49 @@ u8 GetMostSuitableMonToSwitchInto(void) } } - // ok, we know the mon has the right typing but does it have at least one super effective move? - if (bestMonId != 6) + // Ok, we know the mon has the right typing but does it have at least one super effective move? + if (bestMonId != PARTY_SIZE) { for (i = 0; i < 4; i++) { move = GetMonData(&party[bestMonId], MON_DATA_MOVE1 + i); - if (move != MOVE_NONE && TypeCalc(move, gActiveBank, opposingBank) & MOVESTATUS_SUPEREFFECTIVE) + if (move != MOVE_NONE && TypeCalc(move, gActiveBattler, opposingBattler) & MOVE_RESULT_SUPER_EFFECTIVE) break; } if (i != 4) - return bestMonId; // has both the typing and at least one super effective move + return bestMonId; // Has both the typing and at least one super effective move. - invalidMons |= gBitTable[bestMonId]; // sorry buddy, we want something better + invalidMons |= gBitTable[bestMonId]; // Sorry buddy, we want something better. } else { - invalidMons = 0x3F; // no viable mon to switch + invalidMons = 0x3F; // No viable mon to switch. } } gDynamicBasePower = 0; gBattleStruct->dynamicMoveType = 0; gBattleScripting.dmgMultiplier = 1; - gBattleMoveFlags = 0; + gMoveResultFlags = 0; gCritMultiplier = 1; bestDmg = 0; bestMonId = 6; - // if we couldn't find the best mon in terms of typing, find the one that deals most damage + // If we couldn't find the best mon in terms of typing, find the one that deals most damage. for (i = firstId; i < lastId; i++) { if ((u16)(GetMonData(&party[i], MON_DATA_SPECIES)) == SPECIES_NONE) continue; if (GetMonData(&party[i], MON_DATA_HP) == 0) continue; - if (gBattlePartyID[bankIn1] == i) + if (gBattlerPartyIndexes[battlerIn1] == i) continue; - if (gBattlePartyID[bankIn2] == i) + if (gBattlerPartyIndexes[battlerIn2] == i) continue; - if (i == *(gBattleStruct->monToSwitchIntoId + bankIn1)) + if (i == *(gBattleStruct->monToSwitchIntoId + battlerIn1)) continue; - if (i == *(gBattleStruct->monToSwitchIntoId + bankIn2)) + if (i == *(gBattleStruct->monToSwitchIntoId + battlerIn2)) continue; for (j = 0; j < 4; j++) @@ -779,8 +763,8 @@ u8 GetMostSuitableMonToSwitchInto(void) gBattleMoveDamage = 0; if (move != MOVE_NONE && gBattleMoves[move].power != 1) { - AI_CalcDmg(gActiveBank, opposingBank); - TypeCalc(move, gActiveBank, opposingBank); + AI_CalcDmg(gActiveBattler, opposingBattler); + TypeCalc(move, gActiveBattler, opposingBattler); } if (bestDmg < gBattleMoveDamage) { @@ -793,21 +777,21 @@ u8 GetMostSuitableMonToSwitchInto(void) return bestMonId; } -// TODO: use PokemonItemEffect struct instead of u8 once it's documented +// TODO: use PokemonItemEffect struct instead of u8 once it's documented. static u8 GetAI_ItemType(u8 itemId, const u8 *itemEffect) // NOTE: should take u16 as item Id argument { if (itemId == ITEM_FULL_RESTORE) return AI_ITEM_FULL_RESTORE; - if (itemEffect[4] & 4) + else if (itemEffect[4] & 4) return AI_ITEM_HEAL_HP; - if (itemEffect[3] & 0x3F) + else if (itemEffect[3] & 0x3F) return AI_ITEM_CURE_CONDITION; - if (itemEffect[0] & 0x3F || itemEffect[1] != 0 || itemEffect[2] != 0) + else if (itemEffect[0] & 0x3F || itemEffect[1] != 0 || itemEffect[2] != 0) return AI_ITEM_X_STAT; - if (itemEffect[3] & 0x80) + else if (itemEffect[3] & 0x80) return AI_ITEM_GUARD_SPECS; - - return AI_ITEM_NOT_RECOGNIZABLE; + else + return AI_ITEM_NOT_RECOGNIZABLE; } static bool8 ShouldUseItem(void) @@ -817,15 +801,15 @@ static bool8 ShouldUseItem(void) u8 validMons = 0; bool8 shouldUse = FALSE; - if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && GetBankIdentity(gActiveBank) == IDENTITY_PLAYER_MON2) + if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && GetBattlerPosition(gActiveBattler) == B_POSITION_PLAYER_RIGHT) return FALSE; - if (GetBankSide(gActiveBank) == SIDE_PLAYER) + if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) party = gPlayerParty; else party = gEnemyParty; - for (i = 0; i < 6; i++) + for (i = 0; i < PARTY_SIZE; i++) { if (GetMonData(&party[i], MON_DATA_HP) != 0 && GetMonData(&party[i], MON_DATA_SPECIES2) != SPECIES_NONE @@ -840,7 +824,7 @@ static bool8 ShouldUseItem(void) u16 item; const u8 *itemEffects; u8 paramOffset; - u8 bankSide; + u8 battlerSide; if (i != 0 && validMons > (gBattleResources->battleHistory->itemsNo - i) + 1) continue; @@ -855,14 +839,14 @@ static bool8 ShouldUseItem(void) else itemEffects = gItemEffectTable[item - 13]; - *(gBattleStruct->AI_itemType + gActiveBank / 2) = GetAI_ItemType(item, itemEffects); + *(gBattleStruct->AI_itemType + gActiveBattler / 2) = GetAI_ItemType(item, itemEffects); - switch (*(gBattleStruct->AI_itemType + gActiveBank / 2)) + switch (*(gBattleStruct->AI_itemType + gActiveBattler / 2)) { case AI_ITEM_FULL_RESTORE: - if (gBattleMons[gActiveBank].hp >= gBattleMons[gActiveBank].maxHP / 4) + if (gBattleMons[gActiveBattler].hp >= gBattleMons[gActiveBattler].maxHP / 4) break; - if (gBattleMons[gActiveBank].hp == 0) + if (gBattleMons[gActiveBattler].hp == 0) break; shouldUse = TRUE; break; @@ -870,65 +854,65 @@ static bool8 ShouldUseItem(void) paramOffset = GetItemEffectParamOffset(item, 4, 4); if (paramOffset == 0) break; - if (gBattleMons[gActiveBank].hp == 0) + if (gBattleMons[gActiveBattler].hp == 0) break; - if (gBattleMons[gActiveBank].hp < gBattleMons[gActiveBank].maxHP / 4 || gBattleMons[gActiveBank].maxHP - gBattleMons[gActiveBank].hp > itemEffects[paramOffset]) + if (gBattleMons[gActiveBattler].hp < gBattleMons[gActiveBattler].maxHP / 4 || gBattleMons[gActiveBattler].maxHP - gBattleMons[gActiveBattler].hp > itemEffects[paramOffset]) shouldUse = TRUE; break; case AI_ITEM_CURE_CONDITION: - *(gBattleStruct->AI_itemFlags + gActiveBank / 2) = 0; - if (itemEffects[3] & 0x20 && gBattleMons[gActiveBank].status1 & STATUS_SLEEP) + *(gBattleStruct->AI_itemFlags + gActiveBattler / 2) = 0; + if (itemEffects[3] & 0x20 && gBattleMons[gActiveBattler].status1 & STATUS1_SLEEP) { - *(gBattleStruct->AI_itemFlags + gActiveBank / 2) |= 0x20; + *(gBattleStruct->AI_itemFlags + gActiveBattler / 2) |= 0x20; shouldUse = TRUE; } - if (itemEffects[3] & 0x10 && (gBattleMons[gActiveBank].status1 & STATUS_POISON || gBattleMons[gActiveBank].status1 & STATUS_TOXIC_POISON)) + if (itemEffects[3] & 0x10 && (gBattleMons[gActiveBattler].status1 & STATUS1_POISON || gBattleMons[gActiveBattler].status1 & STATUS1_TOXIC_POISON)) { - *(gBattleStruct->AI_itemFlags + gActiveBank / 2) |= 0x10; + *(gBattleStruct->AI_itemFlags + gActiveBattler / 2) |= 0x10; shouldUse = TRUE; } - if (itemEffects[3] & 0x8 && gBattleMons[gActiveBank].status1 & STATUS_BURN) + if (itemEffects[3] & 0x8 && gBattleMons[gActiveBattler].status1 & STATUS1_BURN) { - *(gBattleStruct->AI_itemFlags + gActiveBank / 2) |= 0x8; + *(gBattleStruct->AI_itemFlags + gActiveBattler / 2) |= 0x8; shouldUse = TRUE; } - if (itemEffects[3] & 0x4 && gBattleMons[gActiveBank].status1 & STATUS_FREEZE) + if (itemEffects[3] & 0x4 && gBattleMons[gActiveBattler].status1 & STATUS1_FREEZE) { - *(gBattleStruct->AI_itemFlags + gActiveBank / 2) |= 0x4; + *(gBattleStruct->AI_itemFlags + gActiveBattler / 2) |= 0x4; shouldUse = TRUE; } - if (itemEffects[3] & 0x2 && gBattleMons[gActiveBank].status1 & STATUS_PARALYSIS) + if (itemEffects[3] & 0x2 && gBattleMons[gActiveBattler].status1 & STATUS1_PARALYSIS) { - *(gBattleStruct->AI_itemFlags + gActiveBank / 2) |= 0x2; + *(gBattleStruct->AI_itemFlags + gActiveBattler / 2) |= 0x2; shouldUse = TRUE; } - if (itemEffects[3] & 0x1 && gBattleMons[gActiveBank].status2 & STATUS2_CONFUSION) + if (itemEffects[3] & 0x1 && gBattleMons[gActiveBattler].status2 & STATUS2_CONFUSION) { - *(gBattleStruct->AI_itemFlags + gActiveBank / 2) |= 0x1; + *(gBattleStruct->AI_itemFlags + gActiveBattler / 2) |= 0x1; shouldUse = TRUE; } break; case AI_ITEM_X_STAT: - *(gBattleStruct->AI_itemFlags + gActiveBank / 2) = 0; - if (gDisableStructs[gActiveBank].isFirstTurn == 0) + *(gBattleStruct->AI_itemFlags + gActiveBattler / 2) = 0; + if (gDisableStructs[gActiveBattler].isFirstTurn == 0) break; if (itemEffects[0] & 0xF) - *(gBattleStruct->AI_itemFlags + gActiveBank / 2) |= 0x1; + *(gBattleStruct->AI_itemFlags + gActiveBattler / 2) |= 0x1; if (itemEffects[1] & 0xF0) - *(gBattleStruct->AI_itemFlags + gActiveBank / 2) |= 0x2; + *(gBattleStruct->AI_itemFlags + gActiveBattler / 2) |= 0x2; if (itemEffects[1] & 0xF) - *(gBattleStruct->AI_itemFlags + gActiveBank / 2) |= 0x4; + *(gBattleStruct->AI_itemFlags + gActiveBattler / 2) |= 0x4; if (itemEffects[2] & 0xF) - *(gBattleStruct->AI_itemFlags + gActiveBank / 2) |= 0x8; + *(gBattleStruct->AI_itemFlags + gActiveBattler / 2) |= 0x8; if (itemEffects[2] & 0xF0) - *(gBattleStruct->AI_itemFlags + gActiveBank / 2) |= 0x20; + *(gBattleStruct->AI_itemFlags + gActiveBattler / 2) |= 0x20; if (itemEffects[0] & 0x30) - *(gBattleStruct->AI_itemFlags + gActiveBank / 2) |= 0x80; + *(gBattleStruct->AI_itemFlags + gActiveBattler / 2) |= 0x80; shouldUse = TRUE; break; case AI_ITEM_GUARD_SPECS: - bankSide = GetBankSide(gActiveBank); - if (gDisableStructs[gActiveBank].isFirstTurn != 0 && gSideTimers[bankSide].mistTimer == 0) + battlerSide = GetBattlerSide(gActiveBattler); + if (gDisableStructs[gActiveBattler].isFirstTurn != 0 && gSideTimers[battlerSide].mistTimer == 0) shouldUse = TRUE; break; case AI_ITEM_NOT_RECOGNIZABLE: @@ -937,8 +921,8 @@ static bool8 ShouldUseItem(void) if (shouldUse) { - EmitTwoReturnValues(1, ACTION_USE_ITEM, 0); - *(gBattleStruct->chosenItem + (gActiveBank / 2) * 2) = item; + BtlController_EmitTwoReturnValues(1, B_ACTION_USE_ITEM, 0); + *(gBattleStruct->chosenItem + (gActiveBattler / 2) * 2) = item; gBattleResources->battleHistory->trainerItems[i] = 0; return shouldUse; } |