diff options
Diffstat (limited to 'src/battle_ai_script_commands.c')
-rw-r--r-- | src/battle_ai_script_commands.c | 666 |
1 files changed, 320 insertions, 346 deletions
diff --git a/src/battle_ai_script_commands.c b/src/battle_ai_script_commands.c index 24377eacc..d6ccf9305 100644 --- a/src/battle_ai_script_commands.c +++ b/src/battle_ai_script_commands.c @@ -2,17 +2,18 @@ #include "battle_ai_script_commands.h" #include "pokemon.h" #include "battle.h" -#include "species.h" -#include "abilities.h" -#include "rng.h" +#include "battle_setup.h" +#include "constants/species.h" +#include "constants/abilities.h" +#include "random.h" #include "item.h" -#include "battle_move_effects.h" -#include "moves.h" +#include "constants/battle_move_effects.h" +#include "constants/moves.h" #include "util.h" +#include "constants/battle_ai.h" #define AIScriptRead32(ptr) ((ptr)[0] | (ptr)[1] << 8 | (ptr)[2] << 16 | (ptr)[3] << 24) #define AIScriptRead16(ptr) ((ptr)[0] | (ptr)[1] << 8) -#define AIScriptRead8(ptr) ((ptr)[0]) #define AIScriptReadPtr(ptr) (const u8*) AIScriptRead32(ptr) #define AI_ACTION_DONE 0x0001 @@ -27,14 +28,6 @@ #define AI_THINKING_STRUCT ((struct AI_ThinkingStruct *)(gBattleResources->ai)) #define BATTLE_HISTORY ((struct BattleHistory *)(gBattleResources->battleHistory)) -enum -{ - AI_TARGET, - AI_USER, - AI_TARGET_PARTNER, - AI_USER_PARTNER -}; - // AI states enum { @@ -52,26 +45,7 @@ in order to read the next command correctly. refer to battle_ai_scripts.s for th AI scripts. */ -extern u32 gBattleTypeFlags; -extern u8 gActiveBank; -extern struct BattlePokemon gBattleMons[BATTLE_BANKS_COUNT]; -extern u16 gCurrentMove; -extern u8 gBankTarget; -extern u8 gAbsentBankFlags; -extern u16 gLastUsedMovesByBanks[BATTLE_BANKS_COUNT]; -extern u16 gTrainerBattleOpponent_A; -extern u16 gTrainerBattleOpponent_B; -extern u32 gStatuses3[BATTLE_BANKS_COUNT]; -extern u16 gSideAffecting[2]; -extern u16 gBattlePartyID[BATTLE_BANKS_COUNT]; -extern u16 gDynamicBasePower; -extern u8 gBattleMoveFlags; -extern s32 gBattleMoveDamage; -extern u8 gCritMultiplier; -extern u16 gBattleWeather; - extern const struct BattleMove gBattleMoves[]; -extern const struct BaseStats gBaseStats[]; extern const u8 * const gBattleAI_ScriptsTable[]; extern u32 GetAiScriptsInRecordedBattle(); @@ -105,30 +79,30 @@ static void BattleAICmd_if_less_than(void); static void BattleAICmd_if_more_than(void); static void BattleAICmd_if_equal(void); static void BattleAICmd_if_not_equal(void); -static void BattleAICmd_if_less_than_32(void); -static void BattleAICmd_if_more_than_32(void); -static void BattleAICmd_if_equal_32(void); -static void BattleAICmd_if_not_equal_32(void); +static void BattleAICmd_if_less_than_ptr(void); +static void BattleAICmd_if_more_than_ptr(void); +static void BattleAICmd_if_equal_ptr(void); +static void BattleAICmd_if_not_equal_ptr(void); static void BattleAICmd_if_move(void); static void BattleAICmd_if_not_move(void); static void BattleAICmd_if_in_bytes(void); static void BattleAICmd_if_not_in_bytes(void); static void BattleAICmd_if_in_hwords(void); static void BattleAICmd_if_not_in_hwords(void); -static void BattleAICmd_if_user_can_damage(void); -static void BattleAICmd_if_user_cant_damage(void); +static void BattleAICmd_if_user_has_attacking_move(void); +static void BattleAICmd_if_user_has_no_attacking_moves(void); static void BattleAICmd_get_turn_count(void); static void BattleAICmd_get_type(void); -static void BattleAICmd_get_last_used_bank_move_power(void); -static void BattleAICmd_is_most_powerful_move(void); +static void BattleAICmd_get_considered_move_power(void); +static void BattleAICmd_get_how_powerful_move_is(void); static void BattleAICmd_get_last_used_bank_move(void); -static void BattleAICmd_if_arg_equal(void); -static void BattleAICmd_if_arg_not_equal(void); -static void BattleAICmd_if_would_go_first(void); -static void BattleAICmd_if_would_not_go_first(void); +static void BattleAICmd_if_equal_(void); +static void BattleAICmd_if_not_equal_(void); +static void BattleAICmd_if_user_goes(void); +static void BattleAICmd_if_user_doesnt_go(void); static void BattleAICmd_nullsub_2A(void); static void BattleAICmd_nullsub_2B(void); -static void BattleAICmd_count_alive_pokemon(void); +static void BattleAICmd_count_usable_party_mons(void); static void BattleAICmd_get_considered_move(void); static void BattleAICmd_get_considered_move_effect(void); static void BattleAICmd_get_ability(void); @@ -148,17 +122,17 @@ static void BattleAICmd_if_stat_level_not_equal(void); static void BattleAICmd_if_can_faint(void); static void BattleAICmd_if_cant_faint(void); static void BattleAICmd_if_has_move(void); -static void BattleAICmd_if_dont_have_move(void); -static void BattleAICmd_if_move_effect(void); -static void BattleAICmd_if_not_move_effect(void); +static void BattleAICmd_if_doesnt_have_move(void); +static void BattleAICmd_if_has_move_with_effect(void); +static void BattleAICmd_if_doesnt_have_move_with_effect(void); static void BattleAICmd_if_any_move_disabled_or_encored(void); static void BattleAICmd_if_curr_move_disabled_or_encored(void); static void BattleAICmd_flee(void); -static void BattleAICmd_if_random_100(void); +static void BattleAICmd_if_random_safari_flee(void); static void BattleAICmd_watch(void); static void BattleAICmd_get_hold_effect(void); static void BattleAICmd_get_gender(void); -static void BattleAICmd_is_first_turn(void); +static void BattleAICmd_is_first_turn_for(void); static void BattleAICmd_get_stockpile_count(void); static void BattleAICmd_is_double_battle(void); static void BattleAICmd_get_used_held_item(void); @@ -173,7 +147,7 @@ static void BattleAICmd_nullsub_55(void); static void BattleAICmd_nullsub_56(void); static void BattleAICmd_nullsub_57(void); static void BattleAICmd_call(void); -static void BattleAICmd_jump(void); +static void BattleAICmd_goto(void); static void BattleAICmd_end(void); static void BattleAICmd_if_level_cond(void); static void BattleAICmd_if_target_taunted(void); @@ -187,7 +161,7 @@ static void BattleAICmd_if_holds_item(void); // ewram EWRAM_DATA const u8 *gAIScriptPtr = NULL; -EWRAM_DATA static u8 sBank_AI = 0; +EWRAM_DATA static u8 sBattler_AI = 0; // const rom data @@ -216,30 +190,30 @@ static const BattleAICmdFunc sBattleAICmdTable[] = BattleAICmd_if_more_than, // 0x12 BattleAICmd_if_equal, // 0x13 BattleAICmd_if_not_equal, // 0x14 - BattleAICmd_if_less_than_32, // 0x15 - BattleAICmd_if_more_than_32, // 0x16 - BattleAICmd_if_equal_32, // 0x17 - BattleAICmd_if_not_equal_32, // 0x18 + BattleAICmd_if_less_than_ptr, // 0x15 + BattleAICmd_if_more_than_ptr, // 0x16 + BattleAICmd_if_equal_ptr, // 0x17 + BattleAICmd_if_not_equal_ptr, // 0x18 BattleAICmd_if_move, // 0x19 BattleAICmd_if_not_move, // 0x1A BattleAICmd_if_in_bytes, // 0x1B BattleAICmd_if_not_in_bytes, // 0x1C BattleAICmd_if_in_hwords, // 0x1D BattleAICmd_if_not_in_hwords, // 0x1E - BattleAICmd_if_user_can_damage, // 0x1F - BattleAICmd_if_user_cant_damage, // 0x20 + BattleAICmd_if_user_has_attacking_move, // 0x1F + BattleAICmd_if_user_has_no_attacking_moves, // 0x20 BattleAICmd_get_turn_count, // 0x21 BattleAICmd_get_type, // 0x22 - BattleAICmd_get_last_used_bank_move_power, // 0x23 - BattleAICmd_is_most_powerful_move, // 0x24 + BattleAICmd_get_considered_move_power, // 0x23 + BattleAICmd_get_how_powerful_move_is, // 0x24 BattleAICmd_get_last_used_bank_move, // 0x25 - BattleAICmd_if_arg_equal, // 0x26 - BattleAICmd_if_arg_not_equal, // 0x27 - BattleAICmd_if_would_go_first, // 0x28 - BattleAICmd_if_would_not_go_first, // 0x29 + BattleAICmd_if_equal_, // 0x26 + BattleAICmd_if_not_equal_, // 0x27 + BattleAICmd_if_user_goes, // 0x28 + BattleAICmd_if_user_doesnt_go, // 0x29 BattleAICmd_nullsub_2A, // 0x2A BattleAICmd_nullsub_2B, // 0x2B - BattleAICmd_count_alive_pokemon, // 0x2C + BattleAICmd_count_usable_party_mons, // 0x2C BattleAICmd_get_considered_move, // 0x2D BattleAICmd_get_considered_move_effect, // 0x2E BattleAICmd_get_ability, // 0x2F @@ -259,17 +233,17 @@ static const BattleAICmdFunc sBattleAICmdTable[] = BattleAICmd_if_can_faint, // 0x3D BattleAICmd_if_cant_faint, // 0x3E BattleAICmd_if_has_move, // 0x3F - BattleAICmd_if_dont_have_move, // 0x40 - BattleAICmd_if_move_effect, // 0x41 - BattleAICmd_if_not_move_effect, // 0x42 + BattleAICmd_if_doesnt_have_move, // 0x40 + BattleAICmd_if_has_move_with_effect, // 0x41 + BattleAICmd_if_doesnt_have_move_with_effect, // 0x42 BattleAICmd_if_any_move_disabled_or_encored, // 0x43 BattleAICmd_if_curr_move_disabled_or_encored, // 0x44 BattleAICmd_flee, // 0x45 - BattleAICmd_if_random_100, // 0x46 + BattleAICmd_if_random_safari_flee, // 0x46 BattleAICmd_watch, // 0x47 BattleAICmd_get_hold_effect, // 0x48 BattleAICmd_get_gender, // 0x49 - BattleAICmd_is_first_turn, // 0x4A + BattleAICmd_is_first_turn_for, // 0x4A BattleAICmd_get_stockpile_count, // 0x4B BattleAICmd_is_double_battle, // 0x4C BattleAICmd_get_used_held_item, // 0x4D @@ -284,7 +258,7 @@ static const BattleAICmdFunc sBattleAICmdTable[] = BattleAICmd_nullsub_56, // 0x56 BattleAICmd_nullsub_57, // 0x57 BattleAICmd_call, // 0x58 - BattleAICmd_jump, // 0x59 + BattleAICmd_goto, // 0x59 BattleAICmd_end, // 0x5A BattleAICmd_if_level_cond, // 0x5B BattleAICmd_if_target_taunted, // 0x5C @@ -360,7 +334,7 @@ void BattleAI_SetupAIData(u8 defaultScoreMoves) defaultScoreMoves >>= 1; } - moveLimitations = CheckMoveLimitations(gActiveBank, 0, 0xFF); + moveLimitations = CheckMoveLimitations(gActiveBattler, 0, 0xFF); // ignore moves that aren't possible to use for (i = 0; i < 4; i++) @@ -371,36 +345,38 @@ void BattleAI_SetupAIData(u8 defaultScoreMoves) AI_THINKING_STRUCT->simulatedRNG[i] = 100 - (Random() % 16); } gBattleResources->AI_ScriptsStack->size = 0; - sBank_AI = gActiveBank; + sBattler_AI = gActiveBattler; // decide a random target bank in doubles if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { - gBankTarget = (Random() & 2) + (GetBankSide(gActiveBank) ^ 1); - if (gAbsentBankFlags & gBitTable[gBankTarget]) - gBankTarget ^= 2; + gBattlerTarget = (Random() & BIT_FLANK) + (GetBattlerSide(gActiveBattler) ^ BIT_SIDE); + if (gAbsentBattlerFlags & gBitTable[gBattlerTarget]) + gBattlerTarget ^= BIT_FLANK; } // in singles there's only one choice else - gBankTarget = sBank_AI ^ 1; + { + gBattlerTarget = sBattler_AI ^ BIT_SIDE; + } if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) AI_THINKING_STRUCT->aiFlags = GetAiScriptsInRecordedBattle(); else if (gBattleTypeFlags & BATTLE_TYPE_SAFARI) - AI_THINKING_STRUCT->aiFlags = 0x40000000; + AI_THINKING_STRUCT->aiFlags = AI_SCRIPT_SAFARI; else if (gBattleTypeFlags & BATTLE_TYPE_ROAMER) - AI_THINKING_STRUCT->aiFlags = 0x20000000; + AI_THINKING_STRUCT->aiFlags = AI_SCRIPT_ROAMING; else if (gBattleTypeFlags & BATTLE_TYPE_FIRST_BATTLE) - AI_THINKING_STRUCT->aiFlags = 0x80000000; + AI_THINKING_STRUCT->aiFlags = AI_SCRIPT_FIRST_BATTLE; else if (gBattleTypeFlags & BATTLE_TYPE_FACTORY) AI_THINKING_STRUCT->aiFlags = GetAiScriptsInBattleFactory(); else if (gBattleTypeFlags & (BATTLE_TYPE_FRONTIER | BATTLE_TYPE_EREADER_TRAINER | BATTLE_TYPE_x4000000 | BATTLE_TYPE_SECRET_BASE)) - AI_THINKING_STRUCT->aiFlags = 7; // the smartest possible set + AI_THINKING_STRUCT->aiFlags = AI_SCRIPT_CHECK_BAD_MOVE | AI_SCRIPT_CHECK_VIABILITY | AI_SCRIPT_TRY_TO_FAINT; else if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS) AI_THINKING_STRUCT->aiFlags = gTrainers[gTrainerBattleOpponent_A].aiFlags | gTrainers[gTrainerBattleOpponent_B].aiFlags; else AI_THINKING_STRUCT->aiFlags = gTrainers[gTrainerBattleOpponent_A].aiFlags; if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) - AI_THINKING_STRUCT->aiFlags |= 0x80; // act smart in doubles and don't attack your partner + AI_THINKING_STRUCT->aiFlags |= AI_SCRIPT_DOUBLE_BATTLE; // act smart in doubles and don't attack your partner } u8 BattleAI_ChooseMoveOrAction(void) @@ -450,7 +426,7 @@ static u8 BattleAI_ChooseMoveOrAction_Singles(void) for (i = 1; i < 4; i++) { - if (gBattleMons[sBank_AI].moves[i] != 0) // emerald adds an extra move ID check for some reason. + if (gBattleMons[sBattler_AI].moves[i] != 0) // emerald adds an extra move ID check for some reason. { // in ruby, the order of these if statements are reversed. if (currentMoveArray[0] == AI_THINKING_STRUCT->score[i]) @@ -485,7 +461,7 @@ static u8 BattleAI_ChooseMoveOrAction_Doubles(void) for (i = 0; i < 4; i++) { - if (i == sBank_AI || gBattleMons[i].hp == 0) + if (i == sBattler_AI || gBattleMons[i].hp == 0) { actionOrMoveIndex[i] = -1; bestMovePointsForTarget[i] = -1; @@ -497,9 +473,9 @@ static u8 BattleAI_ChooseMoveOrAction_Doubles(void) else BattleAI_SetupAIData(0xF); - gBankTarget = i; + gBattlerTarget = i; - if ((i & BIT_SIDE) != (sBank_AI & BIT_SIDE)) + if ((i & BIT_SIDE) != (sBattler_AI & BIT_SIDE)) RecordLastUsedMoveByTarget(); AI_THINKING_STRUCT->aiLogicId = 0; @@ -527,7 +503,7 @@ static u8 BattleAI_ChooseMoveOrAction_Doubles(void) mostViableMovesNo = 1; for (j = 1; j < 4; j++) { - if (gBattleMons[sBank_AI].moves[j] != 0) + if (gBattleMons[sBattler_AI].moves[j] != 0) { if (mostViableMovesScores[0] == AI_THINKING_STRUCT->score[j]) { @@ -548,7 +524,7 @@ static u8 BattleAI_ChooseMoveOrAction_Doubles(void) bestMovePointsForTarget[i] = mostViableMovesScores[0]; // don't use a move against ally if it has less than 100 pts - if (i == (sBank_AI ^ BIT_MON) && bestMovePointsForTarget[i] < 100) + if (i == (sBattler_AI ^ BIT_FLANK) && bestMovePointsForTarget[i] < 100) { bestMovePointsForTarget[i] = -1; mostViableMovesScores[0] = mostViableMovesScores[0]; // needed to match @@ -579,8 +555,8 @@ static u8 BattleAI_ChooseMoveOrAction_Doubles(void) } } - gBankTarget = mostViableTargetsArray[Random() % mostViableTargetsNo]; - return actionOrMoveIndex[gBankTarget]; + gBattlerTarget = mostViableTargetsArray[Random() % mostViableTargetsNo]; + return actionOrMoveIndex[gBattlerTarget]; } static void BattleAI_DoAIProcessing(void) @@ -593,13 +569,13 @@ static void BattleAI_DoAIProcessing(void) break; case AIState_SettingUp: gAIScriptPtr = gBattleAI_ScriptsTable[AI_THINKING_STRUCT->aiLogicId]; // set AI ptr to logic ID. - if (gBattleMons[sBank_AI].pp[AI_THINKING_STRUCT->movesetIndex] == 0) + if (gBattleMons[sBattler_AI].pp[AI_THINKING_STRUCT->movesetIndex] == 0) { AI_THINKING_STRUCT->moveConsidered = 0; } else { - AI_THINKING_STRUCT->moveConsidered = gBattleMons[sBank_AI].moves[AI_THINKING_STRUCT->movesetIndex]; + AI_THINKING_STRUCT->moveConsidered = gBattleMons[sBattler_AI].moves[AI_THINKING_STRUCT->movesetIndex]; } AI_THINKING_STRUCT->aiState++; break; @@ -633,18 +609,18 @@ static void RecordLastUsedMoveByTarget(void) for (i = 0; i < 4; i++) { - if (gBattleResources->battleHistory->usedMoves[gBankTarget].moves[i] == gLastUsedMovesByBanks[gBankTarget]) + if (gBattleResources->battleHistory->usedMoves[gBattlerTarget].moves[i] == gLastMoves[gBattlerTarget]) break; - if (gBattleResources->battleHistory->usedMoves[gBankTarget].moves[i] != gLastUsedMovesByBanks[gBankTarget] // HACK: This redundant condition is a hack to make the asm match. - && gBattleResources->battleHistory->usedMoves[gBankTarget].moves[i] == 0) + if (gBattleResources->battleHistory->usedMoves[gBattlerTarget].moves[i] != gLastMoves[gBattlerTarget] // HACK: This redundant condition is a hack to make the asm match. + && gBattleResources->battleHistory->usedMoves[gBattlerTarget].moves[i] == 0) { - gBattleResources->battleHistory->usedMoves[gBankTarget].moves[i] = gLastUsedMovesByBanks[gBankTarget]; + gBattleResources->battleHistory->usedMoves[gBattlerTarget].moves[i] = gLastMoves[gBattlerTarget]; break; } } } -void ClearBankMoveHistory(u8 bank) +void ClearBattlerMoveHistory(u8 bank) { s32 i; @@ -657,7 +633,7 @@ void RecordAbilityBattle(u8 bank, u8 abilityId) gBattleResources->battleHistory->abilities[bank] = abilityId; } -void ClearBankAbilityHistory(u8 bank) +void ClearBattlerAbilityHistory(u8 bank) { gBattleResources->battleHistory->abilities[bank] = 0; } @@ -724,14 +700,14 @@ static void BattleAICmd_score(void) static void BattleAICmd_if_hp_less_than(void) { - u16 index; + u16 bank; if (gAIScriptPtr[1] == AI_USER) - index = sBank_AI; + bank = sBattler_AI; else - index = gBankTarget; + bank = gBattlerTarget; - if ((u32)(100 * gBattleMons[index].hp / gBattleMons[index].maxHP) < gAIScriptPtr[2]) + if ((u32)(100 * gBattleMons[bank].hp / gBattleMons[bank].maxHP) < gAIScriptPtr[2]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 3); else gAIScriptPtr += 7; @@ -739,14 +715,14 @@ static void BattleAICmd_if_hp_less_than(void) static void BattleAICmd_if_hp_more_than(void) { - u16 index; + u16 bank; if (gAIScriptPtr[1] == AI_USER) - index = sBank_AI; + bank = sBattler_AI; else - index = gBankTarget; + bank = gBattlerTarget; - if ((u32)(100 * gBattleMons[index].hp / gBattleMons[index].maxHP) > gAIScriptPtr[2]) + if ((u32)(100 * gBattleMons[bank].hp / gBattleMons[bank].maxHP) > gAIScriptPtr[2]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 3); else gAIScriptPtr += 7; @@ -754,14 +730,14 @@ static void BattleAICmd_if_hp_more_than(void) static void BattleAICmd_if_hp_equal(void) { - u16 index; + u16 bank; if (gAIScriptPtr[1] == AI_USER) - index = sBank_AI; + bank = sBattler_AI; else - index = gBankTarget; + bank = gBattlerTarget; - if ((u32)(100 * gBattleMons[index].hp / gBattleMons[index].maxHP) == gAIScriptPtr[2]) + if ((u32)(100 * gBattleMons[bank].hp / gBattleMons[bank].maxHP) == gAIScriptPtr[2]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 3); else gAIScriptPtr += 7; @@ -769,14 +745,14 @@ static void BattleAICmd_if_hp_equal(void) static void BattleAICmd_if_hp_not_equal(void) { - u16 index; + u16 bank; if (gAIScriptPtr[1] == AI_USER) - index = sBank_AI; + bank = sBattler_AI; else - index = gBankTarget; + bank = gBattlerTarget; - if ((u32)(100 * gBattleMons[index].hp / gBattleMons[index].maxHP) != gAIScriptPtr[2]) + if ((u32)(100 * gBattleMons[bank].hp / gBattleMons[bank].maxHP) != gAIScriptPtr[2]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 3); else gAIScriptPtr += 7; @@ -784,17 +760,17 @@ static void BattleAICmd_if_hp_not_equal(void) static void BattleAICmd_if_status(void) { - u16 index; - u32 arg; + u16 bank; + u32 status; if (gAIScriptPtr[1] == AI_USER) - index = sBank_AI; + bank = sBattler_AI; else - index = gBankTarget; + bank = gBattlerTarget; - arg = AIScriptRead32(gAIScriptPtr + 2); + status = AIScriptRead32(gAIScriptPtr + 2); - if ((gBattleMons[index].status1 & arg) != 0) + if ((gBattleMons[bank].status1 & status) != 0) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 6); else gAIScriptPtr += 10; @@ -802,17 +778,17 @@ static void BattleAICmd_if_status(void) static void BattleAICmd_if_not_status(void) { - u16 index; - u32 arg; + u16 bank; + u32 status; if (gAIScriptPtr[1] == AI_USER) - index = sBank_AI; + bank = sBattler_AI; else - index = gBankTarget; + bank = gBattlerTarget; - arg = AIScriptRead32(gAIScriptPtr + 2); + status = AIScriptRead32(gAIScriptPtr + 2); - if ((gBattleMons[index].status1 & arg) == 0) + if ((gBattleMons[bank].status1 & status) == 0) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 6); else gAIScriptPtr += 10; @@ -820,17 +796,17 @@ static void BattleAICmd_if_not_status(void) static void BattleAICmd_if_status2(void) { - u16 index; - u32 arg; + u16 bank; + u32 status; if (gAIScriptPtr[1] == AI_USER) - index = sBank_AI; + bank = sBattler_AI; else - index = gBankTarget; + bank = gBattlerTarget; - arg = AIScriptRead32(gAIScriptPtr + 2); + status = AIScriptRead32(gAIScriptPtr + 2); - if ((gBattleMons[index].status2 & arg) != 0) + if ((gBattleMons[bank].status2 & status) != 0) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 6); else gAIScriptPtr += 10; @@ -838,17 +814,17 @@ static void BattleAICmd_if_status2(void) static void BattleAICmd_if_not_status2(void) { - u16 index; - u32 arg; + u16 bank; + u32 status; if (gAIScriptPtr[1] == AI_USER) - index = sBank_AI; + bank = sBattler_AI; else - index = gBankTarget; + bank = gBattlerTarget; - arg = AIScriptRead32(gAIScriptPtr + 2); + status = AIScriptRead32(gAIScriptPtr + 2); - if ((gBattleMons[index].status2 & arg) == 0) + if ((gBattleMons[bank].status2 & status) == 0) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 6); else gAIScriptPtr += 10; @@ -856,17 +832,17 @@ static void BattleAICmd_if_not_status2(void) static void BattleAICmd_if_status3(void) { - u16 index; - u32 arg; + u16 bank; + u32 status; if (gAIScriptPtr[1] == AI_USER) - index = sBank_AI; + bank = sBattler_AI; else - index = gBankTarget; + bank = gBattlerTarget; - arg = AIScriptRead32(gAIScriptPtr + 2); + status = AIScriptRead32(gAIScriptPtr + 2); - if ((gStatuses3[index] & arg) != 0) + if ((gStatuses3[bank] & status) != 0) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 6); else gAIScriptPtr += 10; @@ -874,17 +850,17 @@ static void BattleAICmd_if_status3(void) static void BattleAICmd_if_not_status3(void) { - u16 index; - u32 arg; + u16 bank; + u32 status; if (gAIScriptPtr[1] == AI_USER) - index = sBank_AI; + bank = sBattler_AI; else - index = gBankTarget; + bank = gBattlerTarget; - arg = AIScriptRead32(gAIScriptPtr + 2); + status = AIScriptRead32(gAIScriptPtr + 2); - if ((gStatuses3[index] & arg) == 0) + if ((gStatuses3[bank] & status) == 0) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 6); else gAIScriptPtr += 10; @@ -892,18 +868,18 @@ static void BattleAICmd_if_not_status3(void) static void BattleAICmd_if_side_affecting(void) { - u16 index; - u32 arg1, arg2; + u16 bank; + u32 side, status; if (gAIScriptPtr[1] == AI_USER) - index = sBank_AI; + bank = sBattler_AI; else - index = gBankTarget; + bank = gBattlerTarget; - arg1 = GetBankIdentity(index) & 1; - arg2 = AIScriptRead32(gAIScriptPtr + 2); + side = GET_BATTLER_SIDE(bank); + status = AIScriptRead32(gAIScriptPtr + 2); - if ((gSideAffecting[arg1] & arg2) != 0) + if ((gSideStatuses[side] & status) != 0) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 6); else gAIScriptPtr += 10; @@ -911,18 +887,18 @@ static void BattleAICmd_if_side_affecting(void) static void BattleAICmd_if_not_side_affecting(void) { - u16 index; - u32 arg1, arg2; + u16 bank; + u32 side, status; if (gAIScriptPtr[1] == AI_USER) - index = sBank_AI; + bank = sBattler_AI; else - index = gBankTarget; + bank = gBattlerTarget; - arg1 = GetBankIdentity(index) & 1; - arg2 = AIScriptRead32(gAIScriptPtr + 2); + side = GET_BATTLER_SIDE(bank); + status = AIScriptRead32(gAIScriptPtr + 2); - if ((gSideAffecting[arg1] & arg2) == 0) + if ((gSideStatuses[side] & status) == 0) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 6); else gAIScriptPtr += 10; @@ -960,41 +936,41 @@ static void BattleAICmd_if_not_equal(void) gAIScriptPtr += 6; } -static void BattleAICmd_if_less_than_32(void) +static void BattleAICmd_if_less_than_ptr(void) { - const u8 *temp = AIScriptReadPtr(gAIScriptPtr + 1); + const u8 *value = AIScriptReadPtr(gAIScriptPtr + 1); - if (AI_THINKING_STRUCT->funcResult < *temp) + if (AI_THINKING_STRUCT->funcResult < *value) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 5); else gAIScriptPtr += 9; } -static void BattleAICmd_if_more_than_32(void) +static void BattleAICmd_if_more_than_ptr(void) { - const u8 *temp = AIScriptReadPtr(gAIScriptPtr + 1); + const u8 *value = AIScriptReadPtr(gAIScriptPtr + 1); - if (AI_THINKING_STRUCT->funcResult > *temp) + if (AI_THINKING_STRUCT->funcResult > *value) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 5); else gAIScriptPtr += 9; } -static void BattleAICmd_if_equal_32(void) +static void BattleAICmd_if_equal_ptr(void) { - const u8 *temp = AIScriptReadPtr(gAIScriptPtr + 1); + const u8 *value = AIScriptReadPtr(gAIScriptPtr + 1); - if (AI_THINKING_STRUCT->funcResult == *temp) + if (AI_THINKING_STRUCT->funcResult == *value) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 5); else gAIScriptPtr += 9; } -static void BattleAICmd_if_not_equal_32(void) +static void BattleAICmd_if_not_equal_ptr(void) { - const u8 *temp = AIScriptReadPtr(gAIScriptPtr + 1); + const u8 *value = AIScriptReadPtr(gAIScriptPtr + 1); - if (AI_THINKING_STRUCT->funcResult != *temp) + if (AI_THINKING_STRUCT->funcResult != *value) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 5); else gAIScriptPtr += 9; @@ -1084,14 +1060,14 @@ static void BattleAICmd_if_not_in_hwords(void) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 5); } -static void BattleAICmd_if_user_can_damage(void) +static void BattleAICmd_if_user_has_attacking_move(void) { s32 i; for (i = 0; i < 4; i++) { - if (gBattleMons[sBank_AI].moves[i] != 0 - && gBattleMoves[gBattleMons[sBank_AI].moves[i]].power != 0) + if (gBattleMons[sBattler_AI].moves[i] != 0 + && gBattleMoves[gBattleMons[sBattler_AI].moves[i]].power != 0) break; } if (i == 4) @@ -1100,14 +1076,14 @@ static void BattleAICmd_if_user_can_damage(void) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); } -static void BattleAICmd_if_user_cant_damage(void) +static void BattleAICmd_if_user_has_no_attacking_moves(void) { s32 i; for (i = 0; i < 4; i++) { - if (gBattleMons[sBank_AI].moves[i] != 0 - && gBattleMoves[gBattleMons[sBank_AI].moves[i]].power != 0) + if (gBattleMons[sBattler_AI].moves[i] != 0 + && gBattleMoves[gBattleMons[sBattler_AI].moves[i]].power != 0) break; } if (i != 4) @@ -1128,38 +1104,38 @@ static void BattleAICmd_get_type(void) switch (typeVar) { - case 1: // player primary type - AI_THINKING_STRUCT->funcResult = gBattleMons[sBank_AI].type1; + case AI_TYPE1_USER: // AI user primary type + AI_THINKING_STRUCT->funcResult = gBattleMons[sBattler_AI].type1; break; - case 0: // enemy primary type - AI_THINKING_STRUCT->funcResult = gBattleMons[gBankTarget].type1; + case AI_TYPE1_TARGET: // target primary type + AI_THINKING_STRUCT->funcResult = gBattleMons[gBattlerTarget].type1; break; - case 3: // player secondary type - AI_THINKING_STRUCT->funcResult = gBattleMons[sBank_AI].type2; + case AI_TYPE2_USER: // AI user secondary type + AI_THINKING_STRUCT->funcResult = gBattleMons[sBattler_AI].type2; break; - case 2: // enemy secondary type - AI_THINKING_STRUCT->funcResult = gBattleMons[gBankTarget].type2; + case AI_TYPE2_TARGET: // target secondary type + AI_THINKING_STRUCT->funcResult = gBattleMons[gBattlerTarget].type2; break; - case 4: // type of move being pointed to + case AI_TYPE_MOVE: // type of move being pointed to AI_THINKING_STRUCT->funcResult = gBattleMoves[AI_THINKING_STRUCT->moveConsidered].type; break; } gAIScriptPtr += 2; } -static u8 BattleAI_GetWantedBank(u8 index) +static u8 BattleAI_GetWantedBank(u8 bank) { - switch (index) + switch (bank) { case AI_USER: - return sBank_AI; + return sBattler_AI; case AI_TARGET: default: - return gBankTarget; + return gBattlerTarget; case AI_USER_PARTNER: - return sBank_AI ^ BIT_MON; + return sBattler_AI ^ BIT_FLANK; case AI_TARGET_PARTNER: - return gBankTarget ^ BIT_MON; + return gBattlerTarget ^ BIT_FLANK; } } @@ -1169,23 +1145,23 @@ static void BattleAICmd_is_of_type(void) if(gBattleMons[bank].type1 == gAIScriptPtr[2] || gBattleMons[bank].type2 == gAIScriptPtr[2]) { - AI_THINKING_STRUCT->funcResult = 1; + AI_THINKING_STRUCT->funcResult = TRUE; } else { - AI_THINKING_STRUCT->funcResult = 0; + AI_THINKING_STRUCT->funcResult = FALSE; } gAIScriptPtr += 3; } -static void BattleAICmd_get_last_used_bank_move_power(void) +static void BattleAICmd_get_considered_move_power(void) { AI_THINKING_STRUCT->funcResult = gBattleMoves[AI_THINKING_STRUCT->moveConsidered].power; gAIScriptPtr += 1; } -static void BattleAICmd_is_most_powerful_move(void) +static void BattleAICmd_get_how_powerful_move_is(void) { s32 i, checkedMove; s32 moveDmgs[4]; @@ -1202,24 +1178,24 @@ static void BattleAICmd_is_most_powerful_move(void) gDynamicBasePower = 0; *(&gBattleStruct->dynamicMoveType) = 0; gBattleScripting.dmgMultiplier = 1; - gBattleMoveFlags = 0; + gMoveResultFlags = 0; gCritMultiplier = 1; for (checkedMove = 0; checkedMove < 4; checkedMove++) { for (i = 0; sDiscouragedPowerfulMoveEffects[i] != 0xFFFF; i++) { - if (gBattleMoves[gBattleMons[sBank_AI].moves[checkedMove]].effect == sDiscouragedPowerfulMoveEffects[i]) + if (gBattleMoves[gBattleMons[sBattler_AI].moves[checkedMove]].effect == sDiscouragedPowerfulMoveEffects[i]) break; } - if (gBattleMons[sBank_AI].moves[checkedMove] != MOVE_NONE + if (gBattleMons[sBattler_AI].moves[checkedMove] != MOVE_NONE && sDiscouragedPowerfulMoveEffects[i] == 0xFFFF - && gBattleMoves[gBattleMons[sBank_AI].moves[checkedMove]].power > 1) + && gBattleMoves[gBattleMons[sBattler_AI].moves[checkedMove]].power > 1) { - gCurrentMove = gBattleMons[sBank_AI].moves[checkedMove]; - AI_CalcDmg(sBank_AI, gBankTarget); - TypeCalc(gCurrentMove, sBank_AI, gBankTarget); + gCurrentMove = gBattleMons[sBattler_AI].moves[checkedMove]; + AI_CalcDmg(sBattler_AI, gBattlerTarget); + TypeCalc(gCurrentMove, sBattler_AI, gBattlerTarget); moveDmgs[checkedMove] = gBattleMoveDamage * AI_THINKING_STRUCT->simulatedRNG[checkedMove] / 100; if (moveDmgs[checkedMove] == 0) moveDmgs[checkedMove] = 1; @@ -1237,13 +1213,13 @@ static void BattleAICmd_is_most_powerful_move(void) } if (checkedMove == 4) - AI_THINKING_STRUCT->funcResult = 2; // is the most powerful + AI_THINKING_STRUCT->funcResult = MOVE_MOST_POWERFUL; // is the most powerful else - AI_THINKING_STRUCT->funcResult = 1; // not most powerful + AI_THINKING_STRUCT->funcResult = MOVE_NOT_MOST_POWERFUL; // not most powerful } else { - AI_THINKING_STRUCT->funcResult = 0; // highly discouraged in terms of power + AI_THINKING_STRUCT->funcResult = MOVE_POWER_DISCOURAGED; // highly discouraged in terms of power } gAIScriptPtr++; @@ -1252,14 +1228,14 @@ static void BattleAICmd_is_most_powerful_move(void) static void BattleAICmd_get_last_used_bank_move(void) { if (gAIScriptPtr[1] == AI_USER) - AI_THINKING_STRUCT->funcResult = gLastUsedMovesByBanks[sBank_AI]; + AI_THINKING_STRUCT->funcResult = gLastMoves[sBattler_AI]; else - AI_THINKING_STRUCT->funcResult = gLastUsedMovesByBanks[gBankTarget]; + AI_THINKING_STRUCT->funcResult = gLastMoves[gBattlerTarget]; gAIScriptPtr += 2; } -static void BattleAICmd_if_arg_equal(void) +static void BattleAICmd_if_equal_(void) // same as if_equal { if (gAIScriptPtr[1] == AI_THINKING_STRUCT->funcResult) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); @@ -1267,7 +1243,7 @@ static void BattleAICmd_if_arg_equal(void) gAIScriptPtr += 6; } -static void BattleAICmd_if_arg_not_equal(void) +static void BattleAICmd_if_not_equal_(void) // same as if_not_equal { if (gAIScriptPtr[1] != AI_THINKING_STRUCT->funcResult) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); @@ -1275,17 +1251,17 @@ static void BattleAICmd_if_arg_not_equal(void) gAIScriptPtr += 6; } -static void BattleAICmd_if_would_go_first(void) +static void BattleAICmd_if_user_goes(void) { - if (GetWhoStrikesFirst(sBank_AI, gBankTarget, TRUE) == gAIScriptPtr[1]) + if (GetWhoStrikesFirst(sBattler_AI, gBattlerTarget, TRUE) == gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; } -static void BattleAICmd_if_would_not_go_first(void) +static void BattleAICmd_if_user_doesnt_go(void) { - if (GetWhoStrikesFirst(sBank_AI, gBankTarget, TRUE) != gAIScriptPtr[1]) + if (GetWhoStrikesFirst(sBattler_AI, gBattlerTarget, TRUE) != gAIScriptPtr[1]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; @@ -1299,9 +1275,9 @@ static void BattleAICmd_nullsub_2B(void) { } -static void BattleAICmd_count_alive_pokemon(void) +static void BattleAICmd_count_usable_party_mons(void) { - u8 index; + u8 bank; u8 bankOnField1, bankOnField2; struct Pokemon *party; int i; @@ -1309,29 +1285,29 @@ static void BattleAICmd_count_alive_pokemon(void) AI_THINKING_STRUCT->funcResult = 0; if (gAIScriptPtr[1] == AI_USER) - index = sBank_AI; + bank = sBattler_AI; else - index = gBankTarget; + bank = gBattlerTarget; - if (GetBankSide(index) == SIDE_PLAYER) + if (GetBattlerSide(bank) == B_SIDE_PLAYER) party = gPlayerParty; else party = gEnemyParty; if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { - u32 status; - bankOnField1 = gBattlePartyID[index]; - status = GetBankIdentity(index) ^ 2; - bankOnField2 = gBattlePartyID[GetBankByIdentity(status)]; + u32 position; + bankOnField1 = gBattlerPartyIndexes[bank]; + position = GetBattlerPosition(bank) ^ BIT_FLANK; + bankOnField2 = gBattlerPartyIndexes[GetBattlerAtPosition(position)]; } else // in singles there's only one bank by side { - bankOnField1 = gBattlePartyID[index]; - bankOnField2 = gBattlePartyID[index]; + bankOnField1 = gBattlerPartyIndexes[bank]; + bankOnField2 = gBattlerPartyIndexes[bank]; } - for (i = 0; i < 6; i++) + for (i = 0; i < PARTY_SIZE; i++) { if (i != bankOnField1 && i != bankOnField2 && GetMonData(&party[i], MON_DATA_HP) != 0 @@ -1359,60 +1335,60 @@ static void BattleAICmd_get_considered_move_effect(void) static void BattleAICmd_get_ability(void) { - u8 index; + u8 bank; if (gAIScriptPtr[1] == AI_USER) - index = sBank_AI; + bank = sBattler_AI; else - index = gBankTarget; + bank = gBattlerTarget; - if(gActiveBank != index) + if (gActiveBattler != bank) { - if(BATTLE_HISTORY->abilities[index] != 0) + if (BATTLE_HISTORY->abilities[bank] != 0) { - AI_THINKING_STRUCT->funcResult = BATTLE_HISTORY->abilities[index]; + AI_THINKING_STRUCT->funcResult = BATTLE_HISTORY->abilities[bank]; gAIScriptPtr += 2; return; } // abilities that prevent fleeing. - if (gBattleMons[index].ability == ABILITY_SHADOW_TAG - || gBattleMons[index].ability == ABILITY_MAGNET_PULL - || gBattleMons[index].ability == ABILITY_ARENA_TRAP) + if (gBattleMons[bank].ability == ABILITY_SHADOW_TAG + || gBattleMons[bank].ability == ABILITY_MAGNET_PULL + || gBattleMons[bank].ability == ABILITY_ARENA_TRAP) { - AI_THINKING_STRUCT->funcResult = gBattleMons[index].ability; + AI_THINKING_STRUCT->funcResult = gBattleMons[bank].ability; gAIScriptPtr += 2; return; } - if (gBaseStats[gBattleMons[index].species].ability1 != ABILITY_NONE) + if (gBaseStats[gBattleMons[bank].species].ability1 != ABILITY_NONE) { - if (gBaseStats[gBattleMons[index].species].ability2 != ABILITY_NONE) + if (gBaseStats[gBattleMons[bank].species].ability2 != ABILITY_NONE) { // AI has no knowledge of opponent, so it guesses which ability. if (Random() & 1) { - AI_THINKING_STRUCT->funcResult = gBaseStats[gBattleMons[index].species].ability1; + AI_THINKING_STRUCT->funcResult = gBaseStats[gBattleMons[bank].species].ability1; } else { - AI_THINKING_STRUCT->funcResult = gBaseStats[gBattleMons[index].species].ability2; + AI_THINKING_STRUCT->funcResult = gBaseStats[gBattleMons[bank].species].ability2; } } else { - AI_THINKING_STRUCT->funcResult = gBaseStats[gBattleMons[index].species].ability1; // it's definitely ability 1. + AI_THINKING_STRUCT->funcResult = gBaseStats[gBattleMons[bank].species].ability1; // it's definitely ability 1. } } else { - AI_THINKING_STRUCT->funcResult = gBaseStats[gBattleMons[index].species].ability2; // AI cant actually reach this part since every mon has at least 1 ability. + AI_THINKING_STRUCT->funcResult = gBaseStats[gBattleMons[bank].species].ability2; // AI cant actually reach this part since every mon has at least 1 ability. } } else { // The AI knows its own ability. - AI_THINKING_STRUCT->funcResult = gBattleMons[index].ability; + AI_THINKING_STRUCT->funcResult = gBattleMons[bank].ability; } gAIScriptPtr += 2; } @@ -1488,31 +1464,31 @@ static void BattleAICmd_get_highest_type_effectiveness(void) dynamicMoveType = &gBattleStruct->dynamicMoveType; *dynamicMoveType = 0; gBattleScripting.dmgMultiplier = 1; - gBattleMoveFlags = 0; + gMoveResultFlags = 0; gCritMultiplier = 1; AI_THINKING_STRUCT->funcResult = 0; for (i = 0; i < 4; i++) { - gBattleMoveDamage = 40; - gCurrentMove = gBattleMons[sBank_AI].moves[i]; + gBattleMoveDamage = AI_EFFECTIVENESS_x1; + gCurrentMove = gBattleMons[sBattler_AI].moves[i]; if (gCurrentMove) { - TypeCalc(gCurrentMove, sBank_AI, gBankTarget); + TypeCalc(gCurrentMove, sBattler_AI, gBattlerTarget); // reduce by 1/3. if (gBattleMoveDamage == 120) - gBattleMoveDamage = 80; + gBattleMoveDamage = AI_EFFECTIVENESS_x2; if (gBattleMoveDamage == 240) - gBattleMoveDamage = 160; + gBattleMoveDamage = AI_EFFECTIVENESS_x4; if (gBattleMoveDamage == 30) - gBattleMoveDamage = 20; + gBattleMoveDamage = AI_EFFECTIVENESS_x0_5; if (gBattleMoveDamage == 15) - gBattleMoveDamage = 10; + gBattleMoveDamage = AI_EFFECTIVENESS_x0_25; - if (gBattleMoveFlags & MOVESTATUS_NOTAFFECTED) - gBattleMoveDamage = 0; + if (gMoveResultFlags & MOVE_RESULT_DOESNT_AFFECT_FOE) + gBattleMoveDamage = AI_EFFECTIVENESS_x0; if (AI_THINKING_STRUCT->funcResult < gBattleMoveDamage) AI_THINKING_STRUCT->funcResult = gBattleMoveDamage; @@ -1528,25 +1504,25 @@ static void BattleAICmd_if_type_effectiveness(void) gDynamicBasePower = 0; gBattleStruct->dynamicMoveType = 0; gBattleScripting.dmgMultiplier = 1; - gBattleMoveFlags = 0; + gMoveResultFlags = 0; gCritMultiplier = 1; - gBattleMoveDamage = 40; + gBattleMoveDamage = AI_EFFECTIVENESS_x1; gCurrentMove = AI_THINKING_STRUCT->moveConsidered; - TypeCalc(gCurrentMove, sBank_AI, gBankTarget); + TypeCalc(gCurrentMove, sBattler_AI, gBattlerTarget); if (gBattleMoveDamage == 120) - gBattleMoveDamage = 80; + gBattleMoveDamage = AI_EFFECTIVENESS_x2; if (gBattleMoveDamage == 240) - gBattleMoveDamage = 160; + gBattleMoveDamage = AI_EFFECTIVENESS_x4; if (gBattleMoveDamage == 30) - gBattleMoveDamage = 20; + gBattleMoveDamage = AI_EFFECTIVENESS_x0_5; if (gBattleMoveDamage == 15) - gBattleMoveDamage = 10; + gBattleMoveDamage = AI_EFFECTIVENESS_x0_25; - if (gBattleMoveFlags & MOVESTATUS_NOTAFFECTED) - gBattleMoveDamage = 0; + if (gMoveResultFlags & MOVE_RESULT_DOESNT_AFFECT_FOE) + gBattleMoveDamage = AI_EFFECTIVENESS_x0; // store gBattleMoveDamage in a u8 variable because gAIScriptPtr[1] is a u8. damageVar = gBattleMoveDamage; @@ -1570,23 +1546,23 @@ static void BattleAICmd_if_status_in_party(void) struct Pokemon *party; int i; u32 statusToCompareTo; - u8 index; + u8 bank; switch(gAIScriptPtr[1]) { case AI_USER: - index = sBank_AI; + bank = sBattler_AI; break; default: - index = gBankTarget; + bank = gBattlerTarget; break; } - party = (GetBankSide(index) == 0) ? gPlayerParty : gEnemyParty; + party = (GetBattlerSide(bank) == B_SIDE_PLAYER) ? gPlayerParty : gEnemyParty; statusToCompareTo = AIScriptRead32(gAIScriptPtr + 2); - for (i = 0; i < 6; i++) + for (i = 0; i < PARTY_SIZE; i++) { u16 species = GetMonData(&party[i], MON_DATA_SPECIES); u16 hp = GetMonData(&party[i], MON_DATA_HP); @@ -1607,23 +1583,23 @@ static void BattleAICmd_if_status_not_in_party(void) struct Pokemon *party; int i; u32 statusToCompareTo; - u8 index; + u8 bank; switch(gAIScriptPtr[1]) { case 1: - index = sBank_AI; + bank = sBattler_AI; break; default: - index = gBankTarget; + bank = gBattlerTarget; break; } - party = (GetBankSide(index) == 0) ? gPlayerParty : gEnemyParty; + party = (GetBattlerSide(bank) == B_SIDE_PLAYER) ? gPlayerParty : gEnemyParty; statusToCompareTo = AIScriptRead32(gAIScriptPtr + 2); - for (i = 0; i < 6; i++) + for (i = 0; i < PARTY_SIZE; i++) { u16 species = GetMonData(&party[i], MON_DATA_SPECIES); u16 hp = GetMonData(&party[i], MON_DATA_HP); @@ -1641,13 +1617,13 @@ static void BattleAICmd_if_status_not_in_party(void) static void BattleAICmd_get_weather(void) { if (gBattleWeather & WEATHER_RAIN_ANY) - AI_THINKING_STRUCT->funcResult = 1; + AI_THINKING_STRUCT->funcResult = AI_WEATHER_RAIN; if (gBattleWeather & WEATHER_SANDSTORM_ANY) - AI_THINKING_STRUCT->funcResult = 2; + AI_THINKING_STRUCT->funcResult = AI_WEATHER_SANDSTORM; if (gBattleWeather & WEATHER_SUN_ANY) - AI_THINKING_STRUCT->funcResult = 0; + AI_THINKING_STRUCT->funcResult = AI_WEATHER_SUN; if (gBattleWeather & WEATHER_HAIL_ANY) - AI_THINKING_STRUCT->funcResult = 3; + AI_THINKING_STRUCT->funcResult = AI_WEATHER_HAIL; gAIScriptPtr += 1; } @@ -1673,9 +1649,9 @@ static void BattleAICmd_if_stat_level_less_than(void) u32 bank; if (gAIScriptPtr[1] == AI_USER) - bank = sBank_AI; + bank = sBattler_AI; else - bank = gBankTarget; + bank = gBattlerTarget; if (gBattleMons[bank].statStages[gAIScriptPtr[2]] < gAIScriptPtr[3]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); @@ -1688,9 +1664,9 @@ static void BattleAICmd_if_stat_level_more_than(void) u32 bank; if (gAIScriptPtr[1] == AI_USER) - bank = sBank_AI; + bank = sBattler_AI; else - bank = gBankTarget; + bank = gBattlerTarget; if (gBattleMons[bank].statStages[gAIScriptPtr[2]] > gAIScriptPtr[3]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); @@ -1703,9 +1679,9 @@ static void BattleAICmd_if_stat_level_equal(void) u32 bank; if (gAIScriptPtr[1] == AI_USER) - bank = sBank_AI; + bank = sBattler_AI; else - bank = gBankTarget; + bank = gBattlerTarget; if (gBattleMons[bank].statStages[gAIScriptPtr[2]] == gAIScriptPtr[3]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); @@ -1718,9 +1694,9 @@ static void BattleAICmd_if_stat_level_not_equal(void) u32 bank; if (gAIScriptPtr[1] == AI_USER) - bank = sBank_AI; + bank = sBattler_AI; else - bank = gBankTarget; + bank = gBattlerTarget; if (gBattleMons[bank].statStages[gAIScriptPtr[2]] != gAIScriptPtr[3]) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 4); @@ -1739,11 +1715,11 @@ static void BattleAICmd_if_can_faint(void) gDynamicBasePower = 0; gBattleStruct->dynamicMoveType = 0; gBattleScripting.dmgMultiplier = 1; - gBattleMoveFlags = 0; + gMoveResultFlags = 0; gCritMultiplier = 1; gCurrentMove = AI_THINKING_STRUCT->moveConsidered; - AI_CalcDmg(sBank_AI, gBankTarget); - TypeCalc(gCurrentMove, sBank_AI, gBankTarget); + AI_CalcDmg(sBattler_AI, gBattlerTarget); + TypeCalc(gCurrentMove, sBattler_AI, gBattlerTarget); gBattleMoveDamage = gBattleMoveDamage * AI_THINKING_STRUCT->simulatedRNG[AI_THINKING_STRUCT->movesetIndex] / 100; @@ -1751,7 +1727,7 @@ static void BattleAICmd_if_can_faint(void) if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; - if (gBattleMons[gBankTarget].hp <= gBattleMoveDamage) + if (gBattleMons[gBattlerTarget].hp <= gBattleMoveDamage) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); else gAIScriptPtr += 5; @@ -1768,17 +1744,17 @@ static void BattleAICmd_if_cant_faint(void) gDynamicBasePower = 0; gBattleStruct->dynamicMoveType = 0; gBattleScripting.dmgMultiplier = 1; - gBattleMoveFlags = 0; + gMoveResultFlags = 0; gCritMultiplier = 1; gCurrentMove = AI_THINKING_STRUCT->moveConsidered; - AI_CalcDmg(sBank_AI, gBankTarget); - TypeCalc(gCurrentMove, sBank_AI, gBankTarget); + AI_CalcDmg(sBattler_AI, gBattlerTarget); + TypeCalc(gCurrentMove, sBattler_AI, gBattlerTarget); gBattleMoveDamage = gBattleMoveDamage * AI_THINKING_STRUCT->simulatedRNG[AI_THINKING_STRUCT->movesetIndex] / 100; // this macro is missing the damage 0 = 1 assumption. - if (gBattleMons[gBankTarget].hp > gBattleMoveDamage) + if (gBattleMons[gBattlerTarget].hp > gBattleMoveDamage) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); else gAIScriptPtr += 5; @@ -1787,14 +1763,14 @@ static void BattleAICmd_if_cant_faint(void) static void BattleAICmd_if_has_move(void) { int i; - const u16 *temp_ptr = (u16 *)(gAIScriptPtr + 2); + const u16 *movePtr = (u16 *)(gAIScriptPtr + 2); - switch(gAIScriptPtr[1]) + switch (gAIScriptPtr[1]) { case AI_USER: for (i = 0; i < 4; i++) { - if (gBattleMons[sBank_AI].moves[i] == *temp_ptr) + if (gBattleMons[sBattler_AI].moves[i] == *movePtr) break; } if (i == 4) @@ -1808,7 +1784,7 @@ static void BattleAICmd_if_has_move(void) return; } case AI_USER_PARTNER: - if (gBattleMons[sBank_AI ^ 2].hp == 0) + if (gBattleMons[sBattler_AI ^ BIT_FLANK].hp == 0) { gAIScriptPtr += 8; return; @@ -1817,7 +1793,7 @@ static void BattleAICmd_if_has_move(void) { for (i = 0; i < 4; i++) { - if (gBattleMons[sBank_AI ^ 2].moves[i] == *temp_ptr) + if (gBattleMons[sBattler_AI ^ BIT_FLANK].moves[i] == *movePtr) break; } } @@ -1835,7 +1811,7 @@ static void BattleAICmd_if_has_move(void) case AI_TARGET_PARTNER: for (i = 0; i < 4; i++) { - if (BATTLE_HISTORY->usedMoves[gBankTarget].moves[i] == *temp_ptr) + if (BATTLE_HISTORY->usedMoves[gBattlerTarget].moves[i] == *movePtr) break; } if (i == 4) @@ -1851,10 +1827,10 @@ static void BattleAICmd_if_has_move(void) } } -static void BattleAICmd_if_dont_have_move(void) +static void BattleAICmd_if_doesnt_have_move(void) { int i; - const u16 *temp_ptr = (u16 *)(gAIScriptPtr + 2); + const u16 *movePtr = (u16 *)(gAIScriptPtr + 2); switch(gAIScriptPtr[1]) { @@ -1862,7 +1838,7 @@ static void BattleAICmd_if_dont_have_move(void) case AI_USER_PARTNER: // UB: no separate check for user partner for (i = 0; i < 4; i++) { - if (gBattleMons[sBank_AI].moves[i] == *temp_ptr) + if (gBattleMons[sBattler_AI].moves[i] == *movePtr) break; } if (i != 4) @@ -1879,7 +1855,7 @@ static void BattleAICmd_if_dont_have_move(void) case AI_TARGET_PARTNER: for (i = 0; i < 4; i++) { - if (BATTLE_HISTORY->usedMoves[gBankTarget].moves[i] == *temp_ptr) + if (BATTLE_HISTORY->usedMoves[gBattlerTarget].moves[i] == *movePtr) break; } if (i != 4) @@ -1895,7 +1871,7 @@ static void BattleAICmd_if_dont_have_move(void) } } -static void BattleAICmd_if_move_effect(void) +static void BattleAICmd_if_has_move_with_effect(void) { int i; @@ -1905,7 +1881,7 @@ static void BattleAICmd_if_move_effect(void) case AI_USER_PARTNER: for (i = 0; i < 4; i++) { - if(gBattleMons[sBank_AI].moves[i] != 0 && gBattleMoves[gBattleMons[sBank_AI].moves[i]].effect == gAIScriptPtr[2]) + if (gBattleMons[sBattler_AI].moves[i] != 0 && gBattleMoves[gBattleMons[sBattler_AI].moves[i]].effect == gAIScriptPtr[2]) break; } if (i == 4) @@ -1917,7 +1893,8 @@ static void BattleAICmd_if_move_effect(void) case AI_TARGET_PARTNER: for (i = 0; i < 4; i++) { - if (gBattleMons[sBank_AI].moves[i] != 0 && gBattleMoves[BATTLE_HISTORY->usedMoves[gBankTarget].moves[i]].effect == gAIScriptPtr[2]) + // UB: checks sBattler_AI instead of gBattlerTarget + if (gBattleMons[sBattler_AI].moves[i] != 0 && gBattleMoves[BATTLE_HISTORY->usedMoves[gBattlerTarget].moves[i]].effect == gAIScriptPtr[2]) break; } if (i == 4) @@ -1928,7 +1905,7 @@ static void BattleAICmd_if_move_effect(void) } } -static void BattleAICmd_if_not_move_effect(void) +static void BattleAICmd_if_doesnt_have_move_with_effect(void) { int i; @@ -1938,7 +1915,7 @@ static void BattleAICmd_if_not_move_effect(void) case AI_USER_PARTNER: for (i = 0; i < 4; i++) { - if(gBattleMons[sBank_AI].moves[i] != 0 && gBattleMoves[gBattleMons[sBank_AI].moves[i]].effect == gAIScriptPtr[2]) + if(gBattleMons[sBattler_AI].moves[i] != 0 && gBattleMoves[gBattleMons[sBattler_AI].moves[i]].effect == gAIScriptPtr[2]) break; } if (i != 4) @@ -1950,7 +1927,7 @@ static void BattleAICmd_if_not_move_effect(void) case AI_TARGET_PARTNER: for (i = 0; i < 4; i++) { - if (BATTLE_HISTORY->usedMoves[gBankTarget].moves[i] && gBattleMoves[BATTLE_HISTORY->usedMoves[gBankTarget].moves[i]].effect == gAIScriptPtr[2]) + if (BATTLE_HISTORY->usedMoves[gBattlerTarget].moves[i] && gBattleMoves[BATTLE_HISTORY->usedMoves[gBattlerTarget].moves[i]].effect == gAIScriptPtr[2]) break; } if (i != 4) @@ -1966,9 +1943,9 @@ static void BattleAICmd_if_any_move_disabled_or_encored(void) u8 bank; if (gAIScriptPtr[1] == AI_USER) - bank = sBank_AI; + bank = sBattler_AI; else - bank = gBankTarget; + bank = gBattlerTarget; if (gAIScriptPtr[2] == 0) { @@ -1998,7 +1975,7 @@ static void BattleAICmd_if_curr_move_disabled_or_encored(void) switch (gAIScriptPtr[1]) { case 0: - if (gDisableStructs[gActiveBank].disabledMove == AI_THINKING_STRUCT->moveConsidered) + if (gDisableStructs[gActiveBattler].disabledMove == AI_THINKING_STRUCT->moveConsidered) { gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); return; @@ -2006,7 +1983,7 @@ static void BattleAICmd_if_curr_move_disabled_or_encored(void) gAIScriptPtr += 6; return; case 1: - if (gDisableStructs[gActiveBank].encoredMove == AI_THINKING_STRUCT->moveConsidered) + if (gDisableStructs[gActiveBattler].encoredMove == AI_THINKING_STRUCT->moveConsidered) { gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); return; @@ -2024,7 +2001,7 @@ static void BattleAICmd_flee(void) AI_THINKING_STRUCT->aiAction |= (AI_ACTION_DONE | AI_ACTION_FLEE | AI_ACTION_DO_NOT_ATTACK); } -static void BattleAICmd_if_random_100(void) +static void BattleAICmd_if_random_safari_flee(void) { u8 safariFleeRate = gBattleStruct->field_7B * 5; // safari flee rate, from 0-20 @@ -2042,17 +2019,14 @@ static void BattleAICmd_watch(void) static void BattleAICmd_get_hold_effect(void) { u8 bank; - u16 status; if (gAIScriptPtr[1] == AI_USER) - bank = sBank_AI; + bank = sBattler_AI; else - bank = gBankTarget; + bank = gBattlerTarget; - if (gActiveBank != bank) - { + if (gActiveBattler != bank) AI_THINKING_STRUCT->funcResult = ItemId_GetHoldEffect(BATTLE_HISTORY->itemEffects[bank]); - } else AI_THINKING_STRUCT->funcResult = ItemId_GetHoldEffect(gBattleMons[bank].item); @@ -2065,7 +2039,7 @@ static void BattleAICmd_if_holds_item(void) u16 item; u8 var1, var2; - if ((bank & BIT_SIDE) == (sBank_AI & BIT_SIDE)) + if ((bank & BIT_SIDE) == (sBattler_AI & BIT_SIDE)) item = gBattleMons[bank].item; else item = BATTLE_HISTORY->itemEffects[bank]; @@ -2085,23 +2059,23 @@ static void BattleAICmd_get_gender(void) u8 bank; if (gAIScriptPtr[1] == AI_USER) - bank = sBank_AI; + bank = sBattler_AI; else - bank = gBankTarget; + bank = gBattlerTarget; AI_THINKING_STRUCT->funcResult = GetGenderFromSpeciesAndPersonality(gBattleMons[bank].species, gBattleMons[bank].personality); gAIScriptPtr += 2; } -static void BattleAICmd_is_first_turn(void) +static void BattleAICmd_is_first_turn_for(void) { u8 bank; if (gAIScriptPtr[1] == AI_USER) - bank = sBank_AI; + bank = sBattler_AI; else - bank = gBankTarget; + bank = gBattlerTarget; AI_THINKING_STRUCT->funcResult = gDisableStructs[bank].isFirstTurn; @@ -2113,9 +2087,9 @@ static void BattleAICmd_get_stockpile_count(void) u8 bank; if (gAIScriptPtr[1] == AI_USER) - bank = sBank_AI; + bank = sBattler_AI; else - bank = gBankTarget; + bank = gBattlerTarget; AI_THINKING_STRUCT->funcResult = gDisableStructs[bank].stockpileCounter; @@ -2134,9 +2108,9 @@ static void BattleAICmd_get_used_held_item(void) u8 bank; if (gAIScriptPtr[1] == AI_USER) - bank = sBank_AI; + bank = sBattler_AI; else - bank = gBankTarget; + bank = gBattlerTarget; // This is likely a leftover from Ruby's code and its ugly ewram access #ifdef NONMATCHING @@ -2174,9 +2148,9 @@ static void BattleAICmd_get_protect_count(void) u8 bank; if (gAIScriptPtr[1] == AI_USER) - bank = sBank_AI; + bank = sBattler_AI; else - bank = gBankTarget; + bank = gBattlerTarget; AI_THINKING_STRUCT->funcResult = gDisableStructs[bank].protectUses; @@ -2213,7 +2187,7 @@ static void BattleAICmd_call(void) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); } -static void BattleAICmd_jump(void) +static void BattleAICmd_goto(void) { gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); } @@ -2229,7 +2203,7 @@ static void BattleAICmd_if_level_cond(void) switch (gAIScriptPtr[1]) { case 0: // greater than - if (gBattleMons[sBank_AI].level > gBattleMons[gBankTarget].level) + if (gBattleMons[sBattler_AI].level > gBattleMons[gBattlerTarget].level) { gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); return; @@ -2237,7 +2211,7 @@ static void BattleAICmd_if_level_cond(void) gAIScriptPtr += 6; return; case 1: // less than - if (gBattleMons[sBank_AI].level < gBattleMons[gBankTarget].level) + if (gBattleMons[sBattler_AI].level < gBattleMons[gBattlerTarget].level) { gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); return; @@ -2245,7 +2219,7 @@ static void BattleAICmd_if_level_cond(void) gAIScriptPtr += 6; return; case 2: // equal - if (gBattleMons[sBank_AI].level == gBattleMons[gBankTarget].level) + if (gBattleMons[sBattler_AI].level == gBattleMons[gBattlerTarget].level) { gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); return; @@ -2257,7 +2231,7 @@ static void BattleAICmd_if_level_cond(void) static void BattleAICmd_if_target_taunted(void) { - if (gDisableStructs[gBankTarget].tauntTimer1 != 0) + if (gDisableStructs[gBattlerTarget].tauntTimer1 != 0) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); else gAIScriptPtr += 5; @@ -2265,7 +2239,7 @@ static void BattleAICmd_if_target_taunted(void) static void BattleAICmd_if_target_not_taunted(void) { - if (gDisableStructs[gBankTarget].tauntTimer1 == 0) + if (gDisableStructs[gBattlerTarget].tauntTimer1 == 0) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); else gAIScriptPtr += 5; @@ -2273,7 +2247,7 @@ static void BattleAICmd_if_target_not_taunted(void) static void BattleAICmd_if_target_is_ally(void) { - if((sBank_AI & 1) == (gBankTarget & 1)) + if ((sBattler_AI & BIT_SIDE) == (gBattlerTarget & BIT_SIDE)) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 1); else gAIScriptPtr += 5; @@ -2281,9 +2255,9 @@ static void BattleAICmd_if_target_is_ally(void) static void BattleAICmd_if_flash_fired(void) { - u8 index = BattleAI_GetWantedBank(gAIScriptPtr[1]); + u8 bank = BattleAI_GetWantedBank(gAIScriptPtr[1]); - if(gBattleResources->flags->flags[index] & UNKNOWN_FLAG_FLASH_FIRE) + if (gBattleResources->flags->flags[bank] & UNKNOWN_FLAG_FLASH_FIRE) gAIScriptPtr = AIScriptReadPtr(gAIScriptPtr + 2); else gAIScriptPtr += 6; |