diff --git a/asm/battle_frontier_2.s b/asm/battle_frontier_2.s index b2b454278..02bfe8b3b 100644 --- a/asm/battle_frontier_2.s +++ b/asm/battle_frontier_2.s @@ -20646,29 +20646,29 @@ _081A5328: ldr r4, =gDisplayedStringBattle adds r0, r4, 0 movs r1, 0xF - bl BattleHandleAddTextPrinter + bl BattlePutTextOnWindow ldr r0, =gText_Vs movs r1, 0x10 - bl BattleHandleAddTextPrinter + bl BattlePutTextOnWindow ldr r0, =gText_OpponentMon1Name bl BattleStringExpandPlaceholdersToDisplayedString adds r0, r4, 0 movs r1, 0x11 - bl BattleHandleAddTextPrinter + bl BattlePutTextOnWindow ldr r0, =gText_Mind movs r1, 0x12 - bl BattleHandleAddTextPrinter + bl BattlePutTextOnWindow ldr r0, =gText_Skill movs r1, 0x13 - bl BattleHandleAddTextPrinter + bl BattlePutTextOnWindow ldr r0, =gText_Body movs r1, 0x14 - bl BattleHandleAddTextPrinter + bl BattlePutTextOnWindow ldr r0, =gText_Judgement bl BattleStringExpandPlaceholdersToDisplayedString adds r0, r4, 0 movs r1, 0x15 - bl BattleHandleAddTextPrinter + bl BattlePutTextOnWindow b _081A553E .pool _081A53B4: @@ -20752,7 +20752,7 @@ _081A5464: bl BattleStringExpandPlaceholdersToDisplayedString ldr r0, =gDisplayedStringBattle movs r1, 0x15 - bl BattleHandleAddTextPrinter + bl BattlePutTextOnWindow ldrb r0, [r5] adds r0, 0x1 strb r0, [r5] diff --git a/asm/easy_chat.s b/asm/easy_chat.s index eb423cf4c..a6b522a7e 100644 --- a/asm/easy_chat.s +++ b/asm/easy_chat.s @@ -5988,7 +5988,7 @@ sub_811D0BC: @ 811D0BC movs r0, 0x1 movs r1, 0x1 movs r2, 0xE0 - bl sub_809882C + bl LoadSav2WindowGfx movs r0, 0x1 movs r1, 0x1 movs r2, 0xE diff --git a/asm/party_menu.s b/asm/party_menu.s index 4001b7144..6e2b1e55a 100644 --- a/asm/party_menu.s +++ b/asm/party_menu.s @@ -4396,7 +4396,7 @@ _081B23E8: movs r0, 0 movs r1, 0x4F movs r2, 0xD0 - bl sub_809882C + bl LoadSav2WindowGfx bl GetOverworldTextboxPalettePtr movs r1, 0xE0 movs r2, 0x20 diff --git a/asm/pokemon_storage_system.s b/asm/pokemon_storage_system.s index 5988eb732..f2b9a5563 100644 --- a/asm/pokemon_storage_system.s +++ b/asm/pokemon_storage_system.s @@ -1837,7 +1837,7 @@ _080C805E: movs r0, 0x1 movs r1, 0xB movs r2, 0xE0 - bl sub_809882C + bl LoadSav2WindowGfx b _080C8198 .pool _080C808C: @@ -6712,7 +6712,7 @@ sub_80CAC1C: @ 80CAC1C movs r0, 0x1 movs r1, 0x2 movs r2, 0xD0 - bl sub_809882C + bl LoadSav2WindowGfx movs r0, 0x20 str r0, [sp] movs r0, 0x14 diff --git a/asm/pokemon_summary_screen.s b/asm/pokemon_summary_screen.s index c7f2ad085..901669715 100644 --- a/asm/pokemon_summary_screen.s +++ b/asm/pokemon_summary_screen.s @@ -5293,11 +5293,11 @@ sub_81C6BD8: @ 81C6BD8 movs r0, 0 movs r1, 0x1 movs r2, 0xE0 - bl sub_809882C + bl LoadSav2WindowGfx movs r0, 0 movs r1, 0xA movs r2, 0xD0 - bl copy_textbox_border_tile_patterns_to_vram + bl LoadMessageBoxGfx ldr r0, =gUnknown_0860F074 movs r1, 0xF0 movs r2, 0x20 diff --git a/asm/pokenav.s b/asm/pokenav.s index 00c8c8448..a9c1ec7e6 100644 --- a/asm/pokenav.s +++ b/asm/pokenav.s @@ -10101,7 +10101,7 @@ sub_81CC09C: @ 81CC09C ldrb r0, [r4, 0x14] movs r1, 0x1 movs r2, 0x40 - bl sub_809882C + bl LoadSav2WindowGfx ldrb r0, [r4, 0x14] movs r1, 0x1 movs r2, 0x4 @@ -11351,7 +11351,7 @@ sub_81CCA1C: @ 81CCA1C lsrs r0, 24 movs r1, 0x42 movs r2, 0x40 - bl box_border_load_tiles_and_pal + bl LoadSav2WindowGfx_ ldrb r0, [r5, 0x8] movs r1, 0x42 movs r2, 0x4 @@ -22282,7 +22282,7 @@ sub_81D2824: @ 81D2824 movs r0, 0 movs r1, 0x1 movs r2, 0xE0 - bl sub_809882C + bl LoadSav2WindowGfx ldr r0, =gUnknown_0860F074 movs r1, 0xF0 movs r2, 0x20 diff --git a/asm/rom_8011DC0.s b/asm/rom_8011DC0.s index f906304ca..b43978f84 100644 --- a/asm/rom_8011DC0.s +++ b/asm/rom_8011DC0.s @@ -10972,11 +10972,11 @@ _08018574: movs r0, 0 movs r1, 0xA movs r2, 0xE0 - bl sub_809882C + bl LoadSav2WindowGfx movs r0, 0 movs r1, 0x1 movs r2, 0xF0 - bl box_border_load_tiles_and_pal + bl LoadSav2WindowGfx_ movs r4, 0x20 str r4, [sp] str r4, [sp, 0x4] @@ -15907,11 +15907,11 @@ _0801AD8C: movs r0, 0 movs r1, 0x1 movs r2, 0xD0 - bl sub_809882C + bl LoadSav2WindowGfx movs r0, 0 movs r1, 0x1 movs r2, 0xD0 - bl box_border_load_tiles_and_pal + bl LoadSav2WindowGfx_ bl sub_819789C ldr r0, =sub_801AC40 bl SetVBlankCallback @@ -27081,11 +27081,11 @@ sub_8020740: @ 8020740 movs r0, 0x3 movs r1, 0x1 movs r2, 0xD0 - bl sub_809882C + bl LoadSav2WindowGfx movs r0, 0x3 movs r1, 0xA movs r2, 0x20 - bl box_border_load_tiles_and_pal + bl LoadSav2WindowGfx_ ldr r0, =gUnknown_0860F074 movs r1, 0xE0 movs r2, 0x20 @@ -30171,7 +30171,7 @@ _0802210C: ldr r4, =0x0000021d adds r1, r4, 0 movs r2, 0xD0 - bl box_border_load_tiles_and_pal + bl LoadSav2WindowGfx_ ldrb r0, [r5] movs r1, 0 adds r2, r4, 0 @@ -30370,7 +30370,7 @@ _08022296: ldr r4, =0x0000021d adds r1, r4, 0 movs r2, 0xD0 - bl box_border_load_tiles_and_pal + bl LoadSav2WindowGfx_ ldrb r0, [r6, 0x2] movs r1, 0 adds r2, r4, 0 @@ -35221,7 +35221,7 @@ sub_80248B0: @ 80248B0 ldr r5, =0x0000021d adds r1, r5, 0 movs r2, 0xD0 - bl box_border_load_tiles_and_pal + bl LoadSav2WindowGfx_ ldrb r4, [r4] bl sub_80247BC adds r3, r0, 0 @@ -41645,7 +41645,7 @@ sub_8027BEC: @ 8027BEC adds r0, r7, 0 adds r1, r4, 0 movs r2, 0xD0 - bl box_border_load_tiles_and_pal + bl LoadSav2WindowGfx_ adds r0, r7, 0 adds r1, r4, 0 movs r2, 0xD @@ -44214,7 +44214,7 @@ sub_802902C: @ 802902C movs r0, 0 movs r1, 0xA movs r2, 0xB0 - bl box_border_load_tiles_and_pal + bl LoadSav2WindowGfx_ pop {r0} bx r0 thumb_func_end sub_802902C @@ -54638,7 +54638,7 @@ sub_802E500: @ 802E500 adds r0, r4, 0 adds r1, r5, 0 movs r2, 0xD0 - bl box_border_load_tiles_and_pal + bl LoadSav2WindowGfx_ adds r0, r4, 0 adds r1, r5, 0 movs r2, 0xD diff --git a/asm/shop.s b/asm/shop.s index b498da70d..515174151 100644 --- a/asm/shop.s +++ b/asm/shop.s @@ -1157,11 +1157,11 @@ BuyMenuInitWindows: @ 80E0468 movs r0, 0 movs r1, 0x1 movs r2, 0xD0 - bl sub_809882C + bl LoadSav2WindowGfx movs r0, 0 movs r1, 0xA movs r2, 0xE0 - bl copy_textbox_border_tile_patterns_to_vram + bl LoadMessageBoxGfx movs r0, 0 bl PutWindowTilemap movs r0, 0x1 diff --git a/asm/slot_machine.s b/asm/slot_machine.s index fc475c2e3..1719833a5 100644 --- a/asm/slot_machine.s +++ b/asm/slot_machine.s @@ -634,12 +634,12 @@ sub_812AA48: @ 812AA48 lsls r1, 2 movs r0, 0 movs r2, 0xF0 - bl copy_textbox_border_tile_patterns_to_vram + bl LoadMessageBoxGfx movs r1, 0x85 lsls r1, 2 movs r0, 0 movs r2, 0xE0 - bl sub_809882C + bl LoadSav2WindowGfx movs r0, 0 bl PutWindowTilemap pop {r0} diff --git a/asm/trade.s b/asm/trade.s index b96fb8ca9..0d7353938 100644 --- a/asm/trade.s +++ b/asm/trade.s @@ -241,11 +241,11 @@ _08077310: movs r0, 0 movs r1, 0x14 movs r2, 0xC0 - bl box_border_load_tiles_and_pal + bl LoadSav2WindowGfx_ movs r0, 0x2 movs r1, 0x1 movs r2, 0xE0 - bl sub_809882C + bl LoadSav2WindowGfx bl LoadMonIconPalettes ldr r2, =gUnknown_0203229C ldr r0, [r2] diff --git a/data/data2b.s b/data/data2b.s index 8d759b0b2..17a44ecbc 100644 --- a/data/data2b.s +++ b/data/data2b.s @@ -4684,7 +4684,7 @@ gUnknown_0831AA00:: @ 831AA00 obj_tiles gUnknown_08D77B0C, 0x1000, 0x2710 .align 2 -gUnknown_0831AA08:: @ 831AA08 +gBattleBgTemplates:: @ 831AA08 .4byte 0x00000580, 0x000005c5, 0x000013e6, 0x000033ab .align 2 @@ -4743,7 +4743,7 @@ gUnknown_0831AAE0:: @ 831AAE0 null_window_template .align 2 -gUnknown_0831ABA0:: @ 831ABA0 +gBattleWindowTemplates:: @ 831ABA0 .4byte gUnknown_0831AA18 .4byte gUnknown_0831AAE0 diff --git a/include/battle.h b/include/battle.h index ae8a1c98a..bf875ad9d 100644 --- a/include/battle.h +++ b/include/battle.h @@ -606,7 +606,7 @@ struct BattleScripting u8 reshowMainState; u8 reshowHelperState; u8 field_23; - u8 field_24; + u8 windowsType; // 0 - normal, 1 - battle arena u8 multiplayerId; }; diff --git a/include/battle_ai_script_commands.h b/include/battle_ai_script_commands.h index 316f76de6..d23ad048a 100644 --- a/include/battle_ai_script_commands.h +++ b/include/battle_ai_script_commands.h @@ -1,13 +1,18 @@ #ifndef GUARD_BATTLE_AI_SCRIPT_COMMANDS_H #define GUARD_BATTLE_AI_SCRIPT_COMMANDS_H +// return values for BattleAI_ChooseMoveOrAction +// 0 - 3 are move idx +#define AI_CHOICE_FLEE 4 +#define AI_CHOICE_WATCH 5 + void BattleAI_HandleItemUseBeforeAISetup(u8 defaultScoreMoves); void BattleAI_SetupAIData(u8 defaultScoreMoves); u8 BattleAI_ChooseMoveOrAction(void); -void ClearBattlerMoveHistory(u8 bank); -void RecordAbilityBattle(u8 bank, u8 abilityId); -void ClearBattlerAbilityHistory(u8 bank); -void RecordItemEffectBattle(u8 bank, u8 itemEffect); -void ClearBankItemEffectHistory(u8 bank); +void ClearBattlerMoveHistory(u8 battlerId); +void RecordAbilityBattle(u8 battlerId, u8 abilityId); +void ClearBattlerAbilityHistory(u8 battlerId); +void RecordItemEffectBattle(u8 battlerId, u8 itemEffect); +void ClearBattlerItemEffectHistory(u8 battlerId); #endif // GUARD_BATTLE_AI_SCRIPT_COMMANDS_H diff --git a/include/battle_bg.h b/include/battle_bg.h index 7fc09fbf7..dac41c992 100644 --- a/include/battle_bg.h +++ b/include/battle_bg.h @@ -1,13 +1,13 @@ #ifndef GUARD_BATTLE_BG_H #define GUARD_BATTLE_BG_H -void sub_8035658(void); +void BattleInitBgsAndWindows(void); void sub_80356D0(void); -void ApplyPlayerChosenFrameToBattleMenu(void); +void LoadBattleMenuWindowGfx(void); void DrawMainBattleBackground(void); void LoadBattleTextboxAndBackground(void); void sub_8035D74(u8 taskId); -void LoadBattleEntryBackground(void); +void DrawBattleEntryBackground(void); bool8 LoadChosenBattleElement(u8 caseId); #endif // GUARD_BATTLE_BG_H diff --git a/include/battle_message.h b/include/battle_message.h index bf9b590af..f792ff7b0 100644 --- a/include/battle_message.h +++ b/include/battle_message.h @@ -212,7 +212,7 @@ struct StringInfoBattle void BufferStringBattle(u16 stringID); u32 BattleStringExpandPlaceholdersToDisplayedString(const u8* src); u32 BattleStringExpandPlaceholders(const u8* src, u8* dst); -void BattleHandleAddTextPrinter(const u8* text, u8 arg1); +void BattlePutTextOnWindow(const u8* text, u8 arg1); void SetPpNumbersPaletteInMoveSelection(void); u8 GetCurrentPpToMaxPpState(u8 currentPp, u8 maxPp); diff --git a/include/battle_util.h b/include/battle_util.h index e5c1aaf18..0b5590011 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -30,10 +30,14 @@ #define ABILITYEFFECT_CHECK_ON_FIELD 0x13 #define ABILITYEFFECT_SWITCH_IN_WEATHER 0xFF +#define ABILITY_ON_OPPOSING_FIELD(battlerId, abilityId)(AbilityBattleEffects(ABILITYEFFECT_CHECK_OTHER_SIDE, battlerId, abilityId, 0, 0)) +#define ABILITY_ON_FIELD(abilityId)(AbilityBattleEffects(ABILITYEFFECT_CHECK_ON_FIELD, 0, abilityId, 0, 0)) +#define ABILITY_ON_FIELD2(abilityId)(AbilityBattleEffects(ABILITYEFFECT_FIELD_SPORT, 0, abilityId, 0, 0)) + #define ITEMEFFECT_ON_SWITCH_IN 0x0 -#define WEATHER_HAS_EFFECT ((!AbilityBattleEffects(ABILITYEFFECT_CHECK_ON_FIELD, 0, ABILITY_CLOUD_NINE, 0, 0) && !AbilityBattleEffects(ABILITYEFFECT_CHECK_ON_FIELD, 0, ABILITY_AIR_LOCK, 0, 0))) -#define WEATHER_HAS_EFFECT2 ((!AbilityBattleEffects(ABILITYEFFECT_FIELD_SPORT, 0, ABILITY_CLOUD_NINE, 0, 0) && !AbilityBattleEffects(ABILITYEFFECT_FIELD_SPORT, 0, ABILITY_AIR_LOCK, 0, 0))) +#define WEATHER_HAS_EFFECT ((!ABILITY_ON_FIELD(ABILITY_CLOUD_NINE) && !ABILITY_ON_FIELD(ABILITY_AIR_LOCK))) +#define WEATHER_HAS_EFFECT2 ((!ABILITY_ON_FIELD2(ABILITY_CLOUD_NINE) && !ABILITY_ON_FIELD2(ABILITY_AIR_LOCK))) #define BS_GET_TARGET 0 #define BS_GET_ATTACKER 1 diff --git a/include/text_window.h b/include/text_window.h index 2ac13fab7..3d2b8692f 100644 --- a/include/text_window.h +++ b/include/text_window.h @@ -13,10 +13,10 @@ extern const u8 gTextWindowFrame1_Gfx[]; extern const u16 gTextWindowFrame1_Pal[]; const struct TilesPal* GetWindowFrameTilesPal(u8 id); -void copy_textbox_border_tile_patterns_to_vram(u8 windowId, u16 destOffset, u8 palOffset); -void sub_809882C(u8 windowId, u16 destOffset, u8 palOffset); -void sub_80987D4(u8 windowId, u8 frameId, u16 destOffset, u8 palOffset); -void box_border_load_tiles_and_pal(u8 windowId, u16 destOffset, u8 palOffset); +void LoadMessageBoxGfx(u8 windowId, u16 destOffset, u8 palOffset); +void LoadSav2WindowGfx(u8 windowId, u16 destOffset, u8 palOffset); +void LoadWindowGfx(u8 windowId, u8 frameId, u16 destOffset, u8 palOffset); +void LoadSav2WindowGfx_(u8 windowId, u16 destOffset, u8 palOffset); void sub_8098858(u8 windowId, u16 tileNum, u8 palNum); void sub_80989E0(u8 windowId, u16 tileNum, u8 palNum); void rbox_fill_rectangle(u8 windowId); diff --git a/src/battle_ai_script_commands.c b/src/battle_ai_script_commands.c index e1a9168a9..131598985 100644 --- a/src/battle_ai_script_commands.c +++ b/src/battle_ai_script_commands.c @@ -3,6 +3,7 @@ #include "pokemon.h" #include "battle.h" #include "battle_setup.h" +#include "recorded_battle.h" #include "constants/species.h" #include "constants/abilities.h" #include "random.h" @@ -41,13 +42,12 @@ in order to read the next command correctly. refer to battle_ai_scripts.s for th AI scripts. */ -extern const u8 * const gBattleAI_ScriptsTable[]; +extern const u8 *const gBattleAI_ScriptsTable[]; -extern u32 GetAiScriptsInRecordedBattle(); extern u32 GetAiScriptsInBattleFactory(); -static u8 BattleAI_ChooseMoveOrAction_Singles(void); -static u8 BattleAI_ChooseMoveOrAction_Doubles(void); +static u8 ChooseMoveOrAction_Singles(void); +static u8 ChooseMoveOrAction_Doubles(void); static void RecordLastUsedMoveByTarget(void); static void BattleAI_DoAIProcessing(void); static void AIStackPushVar(const u8 *); @@ -90,7 +90,7 @@ static void BattleAICmd_get_turn_count(void); static void BattleAICmd_get_type(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_get_last_used_battler_move(void); static void BattleAICmd_if_equal_(void); static void BattleAICmd_if_not_equal_(void); static void BattleAICmd_if_user_goes(void); @@ -154,115 +154,113 @@ static void BattleAICmd_if_flash_fired(void); static void BattleAICmd_if_holds_item(void); // ewram - EWRAM_DATA const u8 *gAIScriptPtr = NULL; EWRAM_DATA static u8 sBattler_AI = 0; // const rom data - typedef void (*BattleAICmdFunc)(void); static const BattleAICmdFunc sBattleAICmdTable[] = { - BattleAICmd_if_random_less_than, // 0x0 - BattleAICmd_if_random_greater_than, // 0x1 - BattleAICmd_if_random_equal, // 0x2 - BattleAICmd_if_random_not_equal, // 0x3 - BattleAICmd_score, // 0x4 - BattleAICmd_if_hp_less_than, // 0x5 - BattleAICmd_if_hp_more_than, // 0x6 - BattleAICmd_if_hp_equal, // 0x7 - BattleAICmd_if_hp_not_equal, // 0x8 - BattleAICmd_if_status, // 0x9 - BattleAICmd_if_not_status, // 0xA - BattleAICmd_if_status2, // 0xB - BattleAICmd_if_not_status2, // 0xC - BattleAICmd_if_status3, // 0xD - BattleAICmd_if_not_status3, // 0xE - BattleAICmd_if_side_affecting, // 0xF - BattleAICmd_if_not_side_affecting, // 0x10 - BattleAICmd_if_less_than, // 0x11 - BattleAICmd_if_more_than, // 0x12 - BattleAICmd_if_equal, // 0x13 - BattleAICmd_if_not_equal, // 0x14 - 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_has_attacking_move, // 0x1F - BattleAICmd_if_user_has_no_attacking_moves, // 0x20 - BattleAICmd_get_turn_count, // 0x21 - BattleAICmd_get_type, // 0x22 - BattleAICmd_get_considered_move_power, // 0x23 - BattleAICmd_get_how_powerful_move_is, // 0x24 - BattleAICmd_get_last_used_bank_move, // 0x25 - 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_usable_party_mons, // 0x2C - BattleAICmd_get_considered_move, // 0x2D - BattleAICmd_get_considered_move_effect, // 0x2E - BattleAICmd_get_ability, // 0x2F - BattleAICmd_get_highest_type_effectiveness, // 0x30 - BattleAICmd_if_type_effectiveness, // 0x31 - BattleAICmd_nullsub_32, // 0x32 - BattleAICmd_nullsub_33, // 0x33 - BattleAICmd_if_status_in_party, // 0x34 - BattleAICmd_if_status_not_in_party, // 0x35 - BattleAICmd_get_weather, // 0x36 - BattleAICmd_if_effect, // 0x37 - BattleAICmd_if_not_effect, // 0x38 - BattleAICmd_if_stat_level_less_than, // 0x39 - BattleAICmd_if_stat_level_more_than, // 0x3A - BattleAICmd_if_stat_level_equal, // 0x3B - BattleAICmd_if_stat_level_not_equal, // 0x3C - BattleAICmd_if_can_faint, // 0x3D - BattleAICmd_if_cant_faint, // 0x3E - BattleAICmd_if_has_move, // 0x3F - BattleAICmd_if_doesnt_have_move, // 0x40 - BattleAICmd_if_has_move_with_effect, // 0x41 - BattleAICmd_if_doesnt_have_move_with_effect, // 0x42 + BattleAICmd_if_random_less_than, // 0x0 + BattleAICmd_if_random_greater_than, // 0x1 + BattleAICmd_if_random_equal, // 0x2 + BattleAICmd_if_random_not_equal, // 0x3 + BattleAICmd_score, // 0x4 + BattleAICmd_if_hp_less_than, // 0x5 + BattleAICmd_if_hp_more_than, // 0x6 + BattleAICmd_if_hp_equal, // 0x7 + BattleAICmd_if_hp_not_equal, // 0x8 + BattleAICmd_if_status, // 0x9 + BattleAICmd_if_not_status, // 0xA + BattleAICmd_if_status2, // 0xB + BattleAICmd_if_not_status2, // 0xC + BattleAICmd_if_status3, // 0xD + BattleAICmd_if_not_status3, // 0xE + BattleAICmd_if_side_affecting, // 0xF + BattleAICmd_if_not_side_affecting, // 0x10 + BattleAICmd_if_less_than, // 0x11 + BattleAICmd_if_more_than, // 0x12 + BattleAICmd_if_equal, // 0x13 + BattleAICmd_if_not_equal, // 0x14 + 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_has_attacking_move, // 0x1F + BattleAICmd_if_user_has_no_attacking_moves, // 0x20 + BattleAICmd_get_turn_count, // 0x21 + BattleAICmd_get_type, // 0x22 + BattleAICmd_get_considered_move_power, // 0x23 + BattleAICmd_get_how_powerful_move_is, // 0x24 + BattleAICmd_get_last_used_battler_move, // 0x25 + 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_usable_party_mons, // 0x2C + BattleAICmd_get_considered_move, // 0x2D + BattleAICmd_get_considered_move_effect, // 0x2E + BattleAICmd_get_ability, // 0x2F + BattleAICmd_get_highest_type_effectiveness, // 0x30 + BattleAICmd_if_type_effectiveness, // 0x31 + BattleAICmd_nullsub_32, // 0x32 + BattleAICmd_nullsub_33, // 0x33 + BattleAICmd_if_status_in_party, // 0x34 + BattleAICmd_if_status_not_in_party, // 0x35 + BattleAICmd_get_weather, // 0x36 + BattleAICmd_if_effect, // 0x37 + BattleAICmd_if_not_effect, // 0x38 + BattleAICmd_if_stat_level_less_than, // 0x39 + BattleAICmd_if_stat_level_more_than, // 0x3A + BattleAICmd_if_stat_level_equal, // 0x3B + BattleAICmd_if_stat_level_not_equal, // 0x3C + BattleAICmd_if_can_faint, // 0x3D + BattleAICmd_if_cant_faint, // 0x3E + BattleAICmd_if_has_move, // 0x3F + 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_safari_flee, // 0x46 - BattleAICmd_watch, // 0x47 - BattleAICmd_get_hold_effect, // 0x48 - BattleAICmd_get_gender, // 0x49 - BattleAICmd_is_first_turn_for, // 0x4A - BattleAICmd_get_stockpile_count, // 0x4B - BattleAICmd_is_double_battle, // 0x4C - BattleAICmd_get_used_held_item, // 0x4D - BattleAICmd_get_move_type_from_result, // 0x4E - BattleAICmd_get_move_power_from_result, // 0x4F - BattleAICmd_get_move_effect_from_result, // 0x50 - BattleAICmd_get_protect_count, // 0x51 - BattleAICmd_nullsub_52, // 0x52 - BattleAICmd_nullsub_53, // 0x53 - BattleAICmd_nullsub_54, // 0x54 - BattleAICmd_nullsub_55, // 0x55 - BattleAICmd_nullsub_56, // 0x56 - BattleAICmd_nullsub_57, // 0x57 - BattleAICmd_call, // 0x58 - BattleAICmd_goto, // 0x59 - BattleAICmd_end, // 0x5A - BattleAICmd_if_level_cond, // 0x5B - BattleAICmd_if_target_taunted, // 0x5C - BattleAICmd_if_target_not_taunted, // 0x5D - BattleAICmd_if_target_is_ally, // 0x5E - BattleAICmd_is_of_type, // 0x5F - BattleAICmd_check_ability, // 0x60 - BattleAICmd_if_flash_fired, // 0x61 - BattleAICmd_if_holds_item, // 0x62 + BattleAICmd_flee, // 0x45 + BattleAICmd_if_random_safari_flee, // 0x46 + BattleAICmd_watch, // 0x47 + BattleAICmd_get_hold_effect, // 0x48 + BattleAICmd_get_gender, // 0x49 + BattleAICmd_is_first_turn_for, // 0x4A + BattleAICmd_get_stockpile_count, // 0x4B + BattleAICmd_is_double_battle, // 0x4C + BattleAICmd_get_used_held_item, // 0x4D + BattleAICmd_get_move_type_from_result, // 0x4E + BattleAICmd_get_move_power_from_result, // 0x4F + BattleAICmd_get_move_effect_from_result, // 0x50 + BattleAICmd_get_protect_count, // 0x51 + BattleAICmd_nullsub_52, // 0x52 + BattleAICmd_nullsub_53, // 0x53 + BattleAICmd_nullsub_54, // 0x54 + BattleAICmd_nullsub_55, // 0x55 + BattleAICmd_nullsub_56, // 0x56 + BattleAICmd_nullsub_57, // 0x57 + BattleAICmd_call, // 0x58 + BattleAICmd_goto, // 0x59 + BattleAICmd_end, // 0x5A + BattleAICmd_if_level_cond, // 0x5B + BattleAICmd_if_target_taunted, // 0x5C + BattleAICmd_if_target_not_taunted, // 0x5D + BattleAICmd_if_target_is_ally, // 0x5E + BattleAICmd_is_of_type, // 0x5F + BattleAICmd_check_ability, // 0x60 + BattleAICmd_if_flash_fired, // 0x61 + BattleAICmd_if_holds_item, // 0x62 }; static const u16 sDiscouragedPowerfulMoveEffects[] = @@ -282,26 +280,29 @@ static const u16 sDiscouragedPowerfulMoveEffects[] = 0xFFFF }; +// code void BattleAI_HandleItemUseBeforeAISetup(u8 defaultScoreMoves) { s32 i; - u8 *data = (u8 *)gBattleResources->battleHistory; + u8 *data = (u8 *)BATTLE_HISTORY; for (i = 0; i < sizeof(struct BattleHistory); i++) data[i] = 0; - // items are allowed to use in ONLY trainer battles - if ((gBattleTypeFlags & - (BATTLE_TYPE_LINK | BATTLE_TYPE_SAFARI | BATTLE_TYPE_BATTLE_TOWER | - BATTLE_TYPE_EREADER_TRAINER | BATTLE_TYPE_TRAINER | BATTLE_TYPE_FRONTIER - | BATTLE_TYPE_INGAME_PARTNER | BATTLE_TYPE_x2000000 | BATTLE_TYPE_SECRET_BASE)) - == BATTLE_TYPE_TRAINER) + + // Items are allowed to use in ONLY trainer battles. + if ((gBattleTypeFlags & BATTLE_TYPE_TRAINER) + && !(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_SAFARI | BATTLE_TYPE_BATTLE_TOWER + | BATTLE_TYPE_EREADER_TRAINER | BATTLE_TYPE_SECRET_BASE | BATTLE_TYPE_FRONTIER + | BATTLE_TYPE_INGAME_PARTNER | BATTLE_TYPE_x2000000) + ) + ) { for (i = 0; i < 4; i++) { if (gTrainers[gTrainerBattleOpponent_A].items[i] != 0) { - gBattleResources->battleHistory->trainerItems[gBattleResources->battleHistory->itemsNo] = gTrainers[gTrainerBattleOpponent_A].items[i]; - gBattleResources->battleHistory->itemsNo++; + BATTLE_HISTORY->trainerItems[BATTLE_HISTORY->itemsNo] = gTrainers[gTrainerBattleOpponent_A].items[i]; + BATTLE_HISTORY->itemsNo++; } } } @@ -315,23 +316,24 @@ void BattleAI_SetupAIData(u8 defaultScoreMoves) u8 *data = (u8 *)AI_THINKING_STRUCT; u8 moveLimitations; - // clear AI data. + // Clear AI data. for (i = 0; i < sizeof(struct AI_ThinkingStruct); i++) data[i] = 0; - // conditional score reset, unlike Ruby. + // Conditional score reset, unlike Ruby. for (i = 0; i < 4; i++) { if (defaultScoreMoves & 1) AI_THINKING_STRUCT->score[i] = 100; else AI_THINKING_STRUCT->score[i] = 0; + defaultScoreMoves >>= 1; } moveLimitations = CheckMoveLimitations(gActiveBattler, 0, 0xFF); - // ignore moves that aren't possible to use + // Ignore moves that aren't possible to use. for (i = 0; i < 4; i++) { if (gBitTable[i] & moveLimitations) @@ -339,21 +341,24 @@ void BattleAI_SetupAIData(u8 defaultScoreMoves) AI_THINKING_STRUCT->simulatedRNG[i] = 100 - (Random() % 16); } + gBattleResources->AI_ScriptsStack->size = 0; sBattler_AI = gActiveBattler; - // decide a random target battlerId in doubles + + // Decide a random target battlerId in doubles. if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { gBattlerTarget = (Random() & BIT_FLANK) + (GetBattlerSide(gActiveBattler) ^ BIT_SIDE); if (gAbsentBattlerFlags & gBitTable[gBattlerTarget]) gBattlerTarget ^= BIT_FLANK; } - // in singles there's only one choice + // There's only one choice in signle battles. else { gBattlerTarget = sBattler_AI ^ BIT_SIDE; } + // Choose proper trainer ai scripts. if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) AI_THINKING_STRUCT->aiFlags = GetAiScriptsInRecordedBattle(); else if (gBattleTypeFlags & BATTLE_TYPE_SAFARI) @@ -370,6 +375,7 @@ void BattleAI_SetupAIData(u8 defaultScoreMoves) 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 |= AI_SCRIPT_DOUBLE_BATTLE; // act smart in doubles and don't attack your partner } @@ -380,15 +386,15 @@ u8 BattleAI_ChooseMoveOrAction(void) u8 ret; if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) - ret = BattleAI_ChooseMoveOrAction_Singles(); + ret = ChooseMoveOrAction_Singles(); else - ret = BattleAI_ChooseMoveOrAction_Doubles(); + ret = ChooseMoveOrAction_Doubles(); gCurrentMove = savedCurrentMove; return ret; } -static u8 BattleAI_ChooseMoveOrAction_Singles(void) +static u8 ChooseMoveOrAction_Singles(void) { u8 currentMoveArray[4]; u8 consideredMoveArray[4]; @@ -409,11 +415,11 @@ static u8 BattleAI_ChooseMoveOrAction_Singles(void) AI_THINKING_STRUCT->movesetIndex = 0; } - // special flags for safari + // Check special AI actions. if (AI_THINKING_STRUCT->aiAction & AI_ACTION_FLEE) - return 4; + return AI_CHOICE_FLEE; if (AI_THINKING_STRUCT->aiAction & AI_ACTION_WATCH) - return 5; + return AI_CHOICE_WATCH; numOfBestMoves = 1; currentMoveArray[0] = AI_THINKING_STRUCT->score[0]; @@ -421,9 +427,9 @@ static u8 BattleAI_ChooseMoveOrAction_Singles(void) for (i = 1; i < 4; i++) { - if (gBattleMons[sBattler_AI].moves[i] != 0) // emerald adds an extra move ID check for some reason. + if (gBattleMons[sBattler_AI].moves[i] != MOVE_NONE) { - // in ruby, the order of these if statements are reversed. + // In ruby, the order of these if statements is reversed. if (currentMoveArray[0] == AI_THINKING_STRUCT->score[i]) { currentMoveArray[numOfBestMoves] = AI_THINKING_STRUCT->score[i]; @@ -440,7 +446,7 @@ static u8 BattleAI_ChooseMoveOrAction_Singles(void) return consideredMoveArray[Random() % numOfBestMoves]; } -static u8 BattleAI_ChooseMoveOrAction_Doubles(void) +static u8 ChooseMoveOrAction_Doubles(void) { s32 i; s32 j; @@ -487,10 +493,15 @@ static u8 BattleAI_ChooseMoveOrAction_Doubles(void) AI_THINKING_STRUCT->aiLogicId++; AI_THINKING_STRUCT->movesetIndex = 0; } + if (AI_THINKING_STRUCT->aiAction & AI_ACTION_FLEE) - actionOrMoveIndex[i] = 4; + { + actionOrMoveIndex[i] = AI_CHOICE_FLEE; + } else if (AI_THINKING_STRUCT->aiAction & AI_ACTION_WATCH) - actionOrMoveIndex[i] = 5; + { + actionOrMoveIndex[i] = AI_CHOICE_WATCH; + } else { mostViableMovesScores[0] = AI_THINKING_STRUCT->score[0]; @@ -513,18 +524,16 @@ static u8 BattleAI_ChooseMoveOrAction_Doubles(void) mostViableMovesNo = 1; } } - //_08130E72 } actionOrMoveIndex[i] = mostViableMovesIndices[Random() % mostViableMovesNo]; bestMovePointsForTarget[i] = mostViableMovesScores[0]; - // don't use a move against ally if it has less than 100 pts + // Don't use a move against ally if it has less than 100 points. if (i == (sBattler_AI ^ BIT_FLANK) && bestMovePointsForTarget[i] < 100) { bestMovePointsForTarget[i] = -1; - mostViableMovesScores[0] = mostViableMovesScores[0]; // needed to match + mostViableMovesScores[0] = mostViableMovesScores[0]; // Needed to match. } - } } } @@ -535,13 +544,11 @@ static u8 BattleAI_ChooseMoveOrAction_Doubles(void) for (i = 1; i < 4; i++) { - //_08130EDA if (mostMovePoints == bestMovePointsForTarget[i]) { mostViableTargetsArray[mostViableTargetsNo] = i; mostViableTargetsNo++; } - //_08130EEE if (mostMovePoints < bestMovePointsForTarget[i]) { mostMovePoints = bestMovePointsForTarget[i]; @@ -576,7 +583,9 @@ static void BattleAI_DoAIProcessing(void) break; case AIState_Processing: if (AI_THINKING_STRUCT->moveConsidered != 0) + { sBattleAICmdTable[*gAIScriptPtr](); // Run AI command. + } else { AI_THINKING_STRUCT->score[AI_THINKING_STRUCT->movesetIndex] = 0; @@ -604,12 +613,12 @@ static void RecordLastUsedMoveByTarget(void) for (i = 0; i < 4; i++) { - if (gBattleResources->battleHistory->usedMoves[gBattlerTarget].moves[i] == gLastMoves[gBattlerTarget]) + if (BATTLE_HISTORY->usedMoves[gBattlerTarget].moves[i] == gLastMoves[gBattlerTarget]) break; - 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) + if (BATTLE_HISTORY->usedMoves[gBattlerTarget].moves[i] != gLastMoves[gBattlerTarget] // HACK: This redundant condition is a hack to make the asm match. + && BATTLE_HISTORY->usedMoves[gBattlerTarget].moves[i] == MOVE_NONE) { - gBattleResources->battleHistory->usedMoves[gBattlerTarget].moves[i] = gLastMoves[gBattlerTarget]; + BATTLE_HISTORY->usedMoves[gBattlerTarget].moves[i] = gLastMoves[gBattlerTarget]; break; } } @@ -620,27 +629,27 @@ void ClearBattlerMoveHistory(u8 battlerId) s32 i; for (i = 0; i < 4; i++) - gBattleResources->battleHistory->usedMoves[battlerId].moves[i] = 0; + BATTLE_HISTORY->usedMoves[battlerId].moves[i] = MOVE_NONE; } void RecordAbilityBattle(u8 battlerId, u8 abilityId) { - gBattleResources->battleHistory->abilities[battlerId] = abilityId; + BATTLE_HISTORY->abilities[battlerId] = abilityId; } void ClearBattlerAbilityHistory(u8 battlerId) { - gBattleResources->battleHistory->abilities[battlerId] = 0; + BATTLE_HISTORY->abilities[battlerId] = ABILITY_NONE; } void RecordItemEffectBattle(u8 battlerId, u8 itemEffect) { - gBattleResources->battleHistory->itemEffects[battlerId] = itemEffect; + BATTLE_HISTORY->itemEffects[battlerId] = itemEffect; } -void ClearBankItemEffectHistory(u8 battlerId) +void ClearBattlerItemEffectHistory(u8 battlerId) { - gBattleResources->battleHistory->itemEffects[battlerId] = 0; + BATTLE_HISTORY->itemEffects[battlerId] = 0; } static void BattleAICmd_if_random_less_than(void) @@ -685,9 +694,9 @@ static void BattleAICmd_if_random_not_equal(void) static void BattleAICmd_score(void) { - AI_THINKING_STRUCT->score[AI_THINKING_STRUCT->movesetIndex] += gAIScriptPtr[1]; // add the result to the array of the move consider's score. + AI_THINKING_STRUCT->score[AI_THINKING_STRUCT->movesetIndex] += gAIScriptPtr[1]; // Add the result to the array of the move consider's score. - if (AI_THINKING_STRUCT->score[AI_THINKING_STRUCT->movesetIndex] < 0) // if the score is negative, flatten it to 0. + if (AI_THINKING_STRUCT->score[AI_THINKING_STRUCT->movesetIndex] < 0) // If the score is negative, flatten it to 0. AI_THINKING_STRUCT->score[AI_THINKING_STRUCT->movesetIndex] = 0; gAIScriptPtr += 2; // AI return. @@ -765,7 +774,7 @@ static void BattleAICmd_if_status(void) status = T1_READ_32(gAIScriptPtr + 2); - if ((gBattleMons[battlerId].status1 & status) != 0) + if ((gBattleMons[battlerId].status1 & status)) gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 6); else gAIScriptPtr += 10; @@ -783,7 +792,7 @@ static void BattleAICmd_if_not_status(void) status = T1_READ_32(gAIScriptPtr + 2); - if ((gBattleMons[battlerId].status1 & status) == 0) + if (!(gBattleMons[battlerId].status1 & status)) gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 6); else gAIScriptPtr += 10; @@ -801,7 +810,7 @@ static void BattleAICmd_if_status2(void) status = T1_READ_32(gAIScriptPtr + 2); - if ((gBattleMons[battlerId].status2 & status) != 0) + if ((gBattleMons[battlerId].status2 & status)) gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 6); else gAIScriptPtr += 10; @@ -819,7 +828,7 @@ static void BattleAICmd_if_not_status2(void) status = T1_READ_32(gAIScriptPtr + 2); - if ((gBattleMons[battlerId].status2 & status) == 0) + if (!(gBattleMons[battlerId].status2 & status)) gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 6); else gAIScriptPtr += 10; @@ -837,7 +846,7 @@ static void BattleAICmd_if_status3(void) status = T1_READ_32(gAIScriptPtr + 2); - if ((gStatuses3[battlerId] & status) != 0) + if ((gStatuses3[battlerId] & status)) gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 6); else gAIScriptPtr += 10; @@ -855,7 +864,7 @@ static void BattleAICmd_if_not_status3(void) status = T1_READ_32(gAIScriptPtr + 2); - if ((gStatuses3[battlerId] & status) == 0) + if (!(gStatuses3[battlerId] & status)) gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 6); else gAIScriptPtr += 10; @@ -874,7 +883,7 @@ static void BattleAICmd_if_side_affecting(void) side = GET_BATTLER_SIDE(battlerId); status = T1_READ_32(gAIScriptPtr + 2); - if ((gSideStatuses[side] & status) != 0) + if ((gSideStatuses[side] & status)) gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 6); else gAIScriptPtr += 10; @@ -893,7 +902,7 @@ static void BattleAICmd_if_not_side_affecting(void) side = GET_BATTLER_SIDE(battlerId); status = T1_READ_32(gAIScriptPtr + 2); - if ((gSideStatuses[side] & status) == 0) + if (!(gSideStatuses[side] & status)) gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 6); else gAIScriptPtr += 10; @@ -1041,7 +1050,7 @@ static void BattleAICmd_if_in_hwords(void) static void BattleAICmd_if_not_in_hwords(void) { - const u16 *ptr = (u16 *)T1_READ_PTR(gAIScriptPtr + 1); + const u16 *ptr = (const u16 *)T1_READ_PTR(gAIScriptPtr + 1); while (*ptr != 0xFFFF) { @@ -1065,6 +1074,7 @@ static void BattleAICmd_if_user_has_attacking_move(void) && gBattleMoves[gBattleMons[sBattler_AI].moves[i]].power != 0) break; } + if (i == 4) gAIScriptPtr += 5; else @@ -1081,6 +1091,7 @@ static void BattleAICmd_if_user_has_no_attacking_moves(void) && gBattleMoves[gBattleMons[sBattler_AI].moves[i]].power != 0) break; } + if (i != 4) gAIScriptPtr += 5; else @@ -1118,34 +1129,30 @@ static void BattleAICmd_get_type(void) gAIScriptPtr += 2; } -static u8 BattleAI_GetWantedBank(u8 battlerId) +static u8 BattleAI_GetWantedBattler(u8 wantedBattler) { - switch (battlerId) + switch (wantedBattler) { - case AI_USER: - return sBattler_AI; - case AI_TARGET: - default: - return gBattlerTarget; - case AI_USER_PARTNER: - return sBattler_AI ^ BIT_FLANK; - case AI_TARGET_PARTNER: - return gBattlerTarget ^ BIT_FLANK; + case AI_USER: + return sBattler_AI; + case AI_TARGET: + default: + return gBattlerTarget; + case AI_USER_PARTNER: + return sBattler_AI ^ BIT_FLANK; + case AI_TARGET_PARTNER: + return gBattlerTarget ^ BIT_FLANK; } } static void BattleAICmd_is_of_type(void) { - u8 battlerId = BattleAI_GetWantedBank(gAIScriptPtr[1]); + u8 battlerId = BattleAI_GetWantedBattler(gAIScriptPtr[1]); - if(gBattleMons[battlerId].type1 == gAIScriptPtr[2] || gBattleMons[battlerId].type2 == gAIScriptPtr[2]) - { + if (IS_BATTLER_OF_TYPE(battlerId, gAIScriptPtr[2])) AI_THINKING_STRUCT->funcResult = TRUE; - } else - { AI_THINKING_STRUCT->funcResult = FALSE; - } gAIScriptPtr += 3; } @@ -1208,19 +1215,19 @@ static void BattleAICmd_get_how_powerful_move_is(void) } if (checkedMove == 4) - AI_THINKING_STRUCT->funcResult = MOVE_MOST_POWERFUL; // is the most powerful + AI_THINKING_STRUCT->funcResult = MOVE_MOST_POWERFUL; // Is the most powerful. else - AI_THINKING_STRUCT->funcResult = MOVE_NOT_MOST_POWERFUL; // not most powerful + AI_THINKING_STRUCT->funcResult = MOVE_NOT_MOST_POWERFUL; // Not the most powerful. } else { - AI_THINKING_STRUCT->funcResult = MOVE_POWER_DISCOURAGED; // highly discouraged in terms of power + AI_THINKING_STRUCT->funcResult = MOVE_POWER_DISCOURAGED; // Highly discouraged in terms of power. } gAIScriptPtr++; } -static void BattleAICmd_get_last_used_bank_move(void) +static void BattleAICmd_get_last_used_battler_move(void) { if (gAIScriptPtr[1] == AI_USER) AI_THINKING_STRUCT->funcResult = gLastMoves[sBattler_AI]; @@ -1230,7 +1237,7 @@ static void BattleAICmd_get_last_used_bank_move(void) gAIScriptPtr += 2; } -static void BattleAICmd_if_equal_(void) // same as if_equal +static void BattleAICmd_if_equal_(void) // Same as if_equal. { if (gAIScriptPtr[1] == AI_THINKING_STRUCT->funcResult) gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 2); @@ -1238,7 +1245,7 @@ static void BattleAICmd_if_equal_(void) // same as if_equal gAIScriptPtr += 6; } -static void BattleAICmd_if_not_equal_(void) // same as if_not_equal +static void BattleAICmd_if_not_equal_(void) // Same as if_not_equal. { if (gAIScriptPtr[1] != AI_THINKING_STRUCT->funcResult) gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 2); @@ -1273,9 +1280,9 @@ static void BattleAICmd_nullsub_2B(void) static void BattleAICmd_count_usable_party_mons(void) { u8 battlerId; - u8 bankOnField1, bankOnField2; + u8 battlerOnField1, battlerOnField2; struct Pokemon *party; - int i; + s32 i; AI_THINKING_STRUCT->funcResult = 0; @@ -1292,19 +1299,19 @@ static void BattleAICmd_count_usable_party_mons(void) if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { u32 position; - bankOnField1 = gBattlerPartyIndexes[battlerId]; + battlerOnField1 = gBattlerPartyIndexes[battlerId]; position = GetBattlerPosition(battlerId) ^ BIT_FLANK; - bankOnField2 = gBattlerPartyIndexes[GetBattlerAtPosition(position)]; + battlerOnField2 = gBattlerPartyIndexes[GetBattlerAtPosition(position)]; } - else // in singles there's only one battlerId by side + else // In singles there's only one battlerId by side. { - bankOnField1 = gBattlerPartyIndexes[battlerId]; - bankOnField2 = gBattlerPartyIndexes[battlerId]; + battlerOnField1 = gBattlerPartyIndexes[battlerId]; + battlerOnField2 = gBattlerPartyIndexes[battlerId]; } for (i = 0; i < PARTY_SIZE; i++) { - if (i != bankOnField1 && i != bankOnField2 + if (i != battlerOnField1 && i != battlerOnField2 && GetMonData(&party[i], MON_DATA_HP) != 0 && GetMonData(&party[i], MON_DATA_SPECIES2) != SPECIES_NONE && GetMonData(&party[i], MON_DATA_SPECIES2) != SPECIES_EGG) @@ -1362,22 +1369,18 @@ static void BattleAICmd_get_ability(void) { // AI has no knowledge of opponent, so it guesses which ability. if (Random() & 1) - { AI_THINKING_STRUCT->funcResult = gBaseStats[gBattleMons[battlerId].species].ability1; - } else - { AI_THINKING_STRUCT->funcResult = gBaseStats[gBattleMons[battlerId].species].ability2; - } } else { - AI_THINKING_STRUCT->funcResult = gBaseStats[gBattleMons[battlerId].species].ability1; // it's definitely ability 1. + AI_THINKING_STRUCT->funcResult = gBaseStats[gBattleMons[battlerId].species].ability1; // It's definitely ability 1. } } else { - AI_THINKING_STRUCT->funcResult = gBaseStats[gBattleMons[battlerId].species].ability2; // AI cant actually reach this part since every mon has at least 1 ability. + AI_THINKING_STRUCT->funcResult = gBaseStats[gBattleMons[battlerId].species].ability2; // AI can't actually reach this part since no pokemon has ability 2 and no ability 1. } } else @@ -1385,22 +1388,23 @@ static void BattleAICmd_get_ability(void) // The AI knows its own ability. AI_THINKING_STRUCT->funcResult = gBattleMons[battlerId].ability; } + gAIScriptPtr += 2; } static void BattleAICmd_check_ability(void) { - u32 battlerId = BattleAI_GetWantedBank(gAIScriptPtr[1]); + u32 battlerId = BattleAI_GetWantedBattler(gAIScriptPtr[1]); u32 ability = gAIScriptPtr[2]; if (gAIScriptPtr[1] == AI_TARGET || gAIScriptPtr[1] == AI_TARGET_PARTNER) { - if (BATTLE_HISTORY->abilities[battlerId] != 0) + if (BATTLE_HISTORY->abilities[battlerId] != ABILITY_NONE) { ability = BATTLE_HISTORY->abilities[battlerId]; AI_THINKING_STRUCT->funcResult = ability; } - // abilities that prevent fleeing. + // Abilities that prevent fleeing. else if (gBattleMons[battlerId].ability == ABILITY_SHADOW_TAG || gBattleMons[battlerId].ability == ABILITY_MAGNET_PULL || gBattleMons[battlerId].ability == ABILITY_ARENA_TRAP) @@ -1411,14 +1415,16 @@ static void BattleAICmd_check_ability(void) { if (gBaseStats[gBattleMons[battlerId].species].ability2 != ABILITY_NONE) { - u8 abilityDummyVariable = ability; // needed to match + u8 abilityDummyVariable = ability; // Needed to match. if (gBaseStats[gBattleMons[battlerId].species].ability1 != abilityDummyVariable && gBaseStats[gBattleMons[battlerId].species].ability2 != abilityDummyVariable) { ability = gBaseStats[gBattleMons[battlerId].species].ability1; } else - ability = 0; + { + ability = ABILITY_NONE; + } } else { @@ -1427,7 +1433,7 @@ static void BattleAICmd_check_ability(void) } else { - ability = gBaseStats[gBattleMons[battlerId].species].ability2; // AI cant actually reach this part since every mon has at least 1 ability. + ability = gBaseStats[gBattleMons[battlerId].species].ability2; // AI can't actually reach this part since no pokemon has ability 2 and no ability 1. } } else @@ -1435,25 +1441,21 @@ static void BattleAICmd_check_ability(void) // The AI knows its own or partner's ability. ability = gBattleMons[battlerId].ability; } + if (ability == 0) - { - AI_THINKING_STRUCT->funcResult = 2; // unable to answer - } + AI_THINKING_STRUCT->funcResult = 2; // Unable to answer. else if (ability == gAIScriptPtr[2]) - { - AI_THINKING_STRUCT->funcResult = 1; // pokemon has the ability we wanted to check - } + AI_THINKING_STRUCT->funcResult = 1; // Pokemon has the ability we wanted to check. else - { - AI_THINKING_STRUCT->funcResult = 0; // pokemon doesn't have the ability we wanted to check - } + AI_THINKING_STRUCT->funcResult = 0; // Pokemon doesn't have the ability we wanted to check. + gAIScriptPtr += 3; } static void BattleAICmd_get_highest_type_effectiveness(void) { s32 i; - u8* dynamicMoveType; + u8 *dynamicMoveType; gDynamicBasePower = 0; dynamicMoveType = &gBattleStruct->dynamicMoveType; @@ -1465,19 +1467,18 @@ static void BattleAICmd_get_highest_type_effectiveness(void) for (i = 0; i < 4; i++) { - gBattleMoveDamage = AI_EFFECTIVENESS_x1; + gBattleMoveDamage = 40; gCurrentMove = gBattleMons[sBattler_AI].moves[i]; - if (gCurrentMove) + if (gCurrentMove != MOVE_NONE) { TypeCalc(gCurrentMove, sBattler_AI, gBattlerTarget); - // reduce by 1/3. - if (gBattleMoveDamage == 120) + if (gBattleMoveDamage == 120) // Super effective STAB. gBattleMoveDamage = AI_EFFECTIVENESS_x2; if (gBattleMoveDamage == 240) gBattleMoveDamage = AI_EFFECTIVENESS_x4; - if (gBattleMoveDamage == 30) + if (gBattleMoveDamage == 30) // Not very effective STAB. gBattleMoveDamage = AI_EFFECTIVENESS_x0_5; if (gBattleMoveDamage == 15) gBattleMoveDamage = AI_EFFECTIVENESS_x0_25; @@ -1489,6 +1490,7 @@ static void BattleAICmd_get_highest_type_effectiveness(void) AI_THINKING_STRUCT->funcResult = gBattleMoveDamage; } } + gAIScriptPtr += 1; } @@ -1507,11 +1509,11 @@ static void BattleAICmd_if_type_effectiveness(void) TypeCalc(gCurrentMove, sBattler_AI, gBattlerTarget); - if (gBattleMoveDamage == 120) + if (gBattleMoveDamage == 120) // Super effective STAB. gBattleMoveDamage = AI_EFFECTIVENESS_x2; if (gBattleMoveDamage == 240) gBattleMoveDamage = AI_EFFECTIVENESS_x4; - if (gBattleMoveDamage == 30) + if (gBattleMoveDamage == 30) // Not very effective STAB. gBattleMoveDamage = AI_EFFECTIVENESS_x0_5; if (gBattleMoveDamage == 15) gBattleMoveDamage = AI_EFFECTIVENESS_x0_25; @@ -1519,7 +1521,7 @@ static void BattleAICmd_if_type_effectiveness(void) if (gMoveResultFlags & MOVE_RESULT_DOESNT_AFFECT_FOE) gBattleMoveDamage = AI_EFFECTIVENESS_x0; - // store gBattleMoveDamage in a u8 variable because gAIScriptPtr[1] is a u8. + // Store gBattleMoveDamage in a u8 variable because gAIScriptPtr[1] is a u8. damageVar = gBattleMoveDamage; if (damageVar == gAIScriptPtr[1]) @@ -1539,18 +1541,18 @@ static void BattleAICmd_nullsub_33(void) static void BattleAICmd_if_status_in_party(void) { struct Pokemon *party; - int i; + s32 i; u32 statusToCompareTo; u8 battlerId; - switch(gAIScriptPtr[1]) + switch (gAIScriptPtr[1]) { - case AI_USER: - battlerId = sBattler_AI; - break; - default: - battlerId = gBattlerTarget; - break; + case AI_USER: + battlerId = sBattler_AI; + break; + default: + battlerId = gBattlerTarget; + break; } party = (GetBattlerSide(battlerId) == B_SIDE_PLAYER) ? gPlayerParty : gEnemyParty; @@ -1576,18 +1578,18 @@ static void BattleAICmd_if_status_in_party(void) static void BattleAICmd_if_status_not_in_party(void) { struct Pokemon *party; - int i; + s32 i; u32 statusToCompareTo; u8 battlerId; switch(gAIScriptPtr[1]) { - case 1: - battlerId = sBattler_AI; - break; - default: - battlerId = gBattlerTarget; - break; + case 1: + battlerId = sBattler_AI; + break; + default: + battlerId = gBattlerTarget; + break; } party = (GetBattlerSide(battlerId) == B_SIDE_PLAYER) ? gPlayerParty : gEnemyParty; @@ -1602,7 +1604,8 @@ static void BattleAICmd_if_status_not_in_party(void) if (species != SPECIES_NONE && species != SPECIES_EGG && hp != 0 && status == statusToCompareTo) { - gAIScriptPtr += 10; // still bugged in Emerald + gAIScriptPtr += 10; // UB: Still bugged in Emerald. Uncomment the return statement to fix. + // return; } } @@ -1718,7 +1721,7 @@ static void BattleAICmd_if_can_faint(void) gBattleMoveDamage = gBattleMoveDamage * AI_THINKING_STRUCT->simulatedRNG[AI_THINKING_STRUCT->movesetIndex] / 100; - // moves always do at least 1 damage. + // Moves always do at least 1 damage. if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; @@ -1747,7 +1750,7 @@ static void BattleAICmd_if_cant_faint(void) gBattleMoveDamage = gBattleMoveDamage * AI_THINKING_STRUCT->simulatedRNG[AI_THINKING_STRUCT->movesetIndex] / 100; - // this macro is missing the damage 0 = 1 assumption. + // This macro is missing the damage 0 = 1 assumption. if (gBattleMons[gBattlerTarget].hp > gBattleMoveDamage) gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 1); @@ -1757,118 +1760,93 @@ static void BattleAICmd_if_cant_faint(void) static void BattleAICmd_if_has_move(void) { - int i; + s32 i; const u16 *movePtr = (u16 *)(gAIScriptPtr + 2); switch (gAIScriptPtr[1]) { - case AI_USER: + case AI_USER: + for (i = 0; i < 4; i++) + { + if (gBattleMons[sBattler_AI].moves[i] == *movePtr) + break; + } + if (i == 4) + gAIScriptPtr += 8; + else + gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 4); + break; + case AI_USER_PARTNER: + if (gBattleMons[sBattler_AI ^ BIT_FLANK].hp == 0) + { + gAIScriptPtr += 8; + break; + } + else + { for (i = 0; i < 4; i++) { - if (gBattleMons[sBattler_AI].moves[i] == *movePtr) + if (gBattleMons[sBattler_AI ^ BIT_FLANK].moves[i] == *movePtr) break; } - if (i == 4) - { - gAIScriptPtr += 8; - return; - } - else - { - gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 4); - return; - } - case AI_USER_PARTNER: - if (gBattleMons[sBattler_AI ^ BIT_FLANK].hp == 0) - { - gAIScriptPtr += 8; - return; - } - else - { - for (i = 0; i < 4; i++) - { - if (gBattleMons[sBattler_AI ^ BIT_FLANK].moves[i] == *movePtr) - break; - } - } - if (i == 4) - { - gAIScriptPtr += 8; - return; - } - else - { - gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 4); - return; - } - case AI_TARGET: - case AI_TARGET_PARTNER: - for (i = 0; i < 4; i++) - { - if (BATTLE_HISTORY->usedMoves[gBattlerTarget].moves[i] == *movePtr) - break; - } - if (i == 4) - { - gAIScriptPtr += 8; - return; - } - else - { - gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 4); - return; - } + } + if (i == 4) + gAIScriptPtr += 8; + else + gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 4); + break; + case AI_TARGET: + case AI_TARGET_PARTNER: + for (i = 0; i < 4; i++) + { + if (BATTLE_HISTORY->usedMoves[gBattlerTarget].moves[i] == *movePtr) + break; + } + if (i == 4) + gAIScriptPtr += 8; + else + gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 4); + break; } } static void BattleAICmd_if_doesnt_have_move(void) { - int i; + s32 i; const u16 *movePtr = (u16 *)(gAIScriptPtr + 2); switch(gAIScriptPtr[1]) { - case AI_USER: - case AI_USER_PARTNER: // UB: no separate check for user partner - for (i = 0; i < 4; i++) - { - if (gBattleMons[sBattler_AI].moves[i] == *movePtr) - break; - } - if (i != 4) - { - gAIScriptPtr += 8; - return; - } - else - { - gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 4); - return; - } - case AI_TARGET: - case AI_TARGET_PARTNER: - for (i = 0; i < 4; i++) - { - if (BATTLE_HISTORY->usedMoves[gBattlerTarget].moves[i] == *movePtr) - break; - } - if (i != 4) - { - gAIScriptPtr += 8; - return; - } - else - { - gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 4); - return; - } + case AI_USER: + case AI_USER_PARTNER: // UB: no separate check for user partner. + for (i = 0; i < 4; i++) + { + if (gBattleMons[sBattler_AI].moves[i] == *movePtr) + break; + } + if (i != 4) + gAIScriptPtr += 8; + else + gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 4); + break; + case AI_TARGET: + case AI_TARGET_PARTNER: + for (i = 0; i < 4; i++) + { + if (BATTLE_HISTORY->usedMoves[gBattlerTarget].moves[i] == *movePtr) + break; + } + if (i != 4) + gAIScriptPtr += 8; + else + gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 4); + break; } } static void BattleAICmd_if_has_move_with_effect(void) { - int i; + s32 i; switch (gAIScriptPtr[1]) { @@ -1888,7 +1866,7 @@ static void BattleAICmd_if_has_move_with_effect(void) case AI_TARGET_PARTNER: for (i = 0; i < 4; i++) { - // UB: checks sBattler_AI instead of gBattlerTarget + // 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; } @@ -1902,7 +1880,7 @@ static void BattleAICmd_if_has_move_with_effect(void) static void BattleAICmd_if_doesnt_have_move_with_effect(void) { - int i; + s32 i; switch (gAIScriptPtr[1]) { @@ -1944,25 +1922,22 @@ static void BattleAICmd_if_any_move_disabled_or_encored(void) if (gAIScriptPtr[2] == 0) { - if (gDisableStructs[battlerId].disabledMove == 0) - { + if (gDisableStructs[battlerId].disabledMove == MOVE_NONE) gAIScriptPtr += 7; - return; - } - gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 3); - return; + else + gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 3); } - else if (gAIScriptPtr[2] != 1) // ignore the macro if its not 0 or 1. + else if (gAIScriptPtr[2] != 1) { gAIScriptPtr += 7; - return; } - else if (gDisableStructs[battlerId].encoredMove != 0) + else { - gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 3); - return; + if (gDisableStructs[battlerId].encoredMove != MOVE_NONE) + gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 3); + else + gAIScriptPtr += 7; } - gAIScriptPtr += 7; } static void BattleAICmd_if_curr_move_disabled_or_encored(void) @@ -1971,23 +1946,19 @@ static void BattleAICmd_if_curr_move_disabled_or_encored(void) { case 0: if (gDisableStructs[gActiveBattler].disabledMove == AI_THINKING_STRUCT->moveConsidered) - { gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 2); - return; - } - gAIScriptPtr += 6; - return; + else + gAIScriptPtr += 6; + break;; case 1: if (gDisableStructs[gActiveBattler].encoredMove == AI_THINKING_STRUCT->moveConsidered) - { gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 2); - return; - } - gAIScriptPtr += 6; - return; + else + gAIScriptPtr += 6; + break; default: gAIScriptPtr += 6; - return; + break; } } @@ -1998,7 +1969,7 @@ static void BattleAICmd_flee(void) static void BattleAICmd_if_random_safari_flee(void) { - u8 safariFleeRate = gBattleStruct->field_7B * 5; // safari flee rate, from 0-20 + u8 safariFleeRate = gBattleStruct->field_7B * 5; // Safari flee rate, from 0-20. if ((u8)(Random() % 100) < safariFleeRate) gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 1); @@ -2030,7 +2001,7 @@ static void BattleAICmd_get_hold_effect(void) static void BattleAICmd_if_holds_item(void) { - u8 battlerId = BattleAI_GetWantedBank(gAIScriptPtr[1]); + u8 battlerId = BattleAI_GetWantedBattler(gAIScriptPtr[1]); u16 item; u8 var1, var2; @@ -2107,7 +2078,7 @@ static void BattleAICmd_get_used_held_item(void) else battlerId = gBattlerTarget; - // This is likely a leftover from Ruby's code and its ugly ewram access + // This is likely a leftover from Ruby's code and its ugly ewram access. #ifdef NONMATCHING AI_THINKING_STRUCT->funcResult = gBattleStruct->usedHeldItems[battlerId]; #else @@ -2199,28 +2170,22 @@ static void BattleAICmd_if_level_cond(void) { case 0: // greater than if (gBattleMons[sBattler_AI].level > gBattleMons[gBattlerTarget].level) - { gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 2); - return; - } - gAIScriptPtr += 6; - return; + else + gAIScriptPtr += 6; + break; case 1: // less than if (gBattleMons[sBattler_AI].level < gBattleMons[gBattlerTarget].level) - { gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 2); - return; - } - gAIScriptPtr += 6; - return; + else + gAIScriptPtr += 6; + break; case 2: // equal if (gBattleMons[sBattler_AI].level == gBattleMons[gBattlerTarget].level) - { gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 2); - return; - } - gAIScriptPtr += 6; - return; + else + gAIScriptPtr += 6; + break; } } @@ -2250,7 +2215,7 @@ static void BattleAICmd_if_target_is_ally(void) static void BattleAICmd_if_flash_fired(void) { - u8 battlerId = BattleAI_GetWantedBank(gAIScriptPtr[1]); + u8 battlerId = BattleAI_GetWantedBattler(gAIScriptPtr[1]); if (gBattleResources->flags->flags[battlerId] & UNKNOWN_FLAG_FLASH_FIRE) gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 2); @@ -2277,5 +2242,7 @@ static bool8 AIStackPop(void) return TRUE; } else + { return FALSE; + } } diff --git a/src/battle_ai_switch_items.c b/src/battle_ai_switch_items.c index 83ad2b4fd..a105e7edf 100644 --- a/src/battle_ai_switch_items.c +++ b/src/battle_ai_switch_items.c @@ -19,18 +19,20 @@ static bool8 ShouldSwitchIfPerishSong(void) if (gStatuses3[gActiveBattler] & STATUS3_PERISH_SONG && gDisableStructs[gActiveBattler].perishSongTimer1 == 0) { - *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = 6; + *(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 opposingPosition; - u8 opposingBank; + u8 opposingBattler; u8 moveFlags; s32 i, j; s32 firstId; @@ -46,22 +48,22 @@ static bool8 ShouldSwitchIfWonderGuard(void) if (gBattleMons[GetBattlerAtPosition(opposingPosition)].ability != ABILITY_WONDER_GUARD) return FALSE; - // check if pokemon has a super effective move - for (opposingBank = GetBattlerAtPosition(opposingPosition), i = 0; i < 4; i++) + // Check if Pokemon has a super effective move. + for (opposingBattler = GetBattlerAtPosition(opposingPosition), i = 0; i < 4; i++) { move = gBattleMons[gActiveBattler].moves[i]; if (move == MOVE_NONE) continue; - moveFlags = AI_TypeCalc(move, gBattleMons[opposingBank].species, gBattleMons[opposingBank].ability); + 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 ((gActiveBattler & BIT_FLANK) == 0) + if ((gActiveBattler & BIT_FLANK) == B_FLANK_LEFT) firstId = 0, lastId = 3; else firstId = 3, lastId = 6; @@ -76,7 +78,7 @@ static bool8 ShouldSwitchIfWonderGuard(void) 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) @@ -88,19 +90,19 @@ static bool8 ShouldSwitchIfWonderGuard(void) 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 = GetBattlerAtPosition(opposingPosition), 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); + moveFlags = AI_TypeCalc(move, gBattleMons[opposingBattler].species, gBattleMons[opposingBattler].ability); if (moveFlags & MOVE_RESULT_SUPER_EFFECTIVE && Random() % 3 < 2) { - // we found a mon + // We found a mon. *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = i; BtlController_EmitTwoReturnValues(1, B_ACTION_SWITCH, 0); return TRUE; @@ -108,12 +110,12 @@ static bool8 ShouldSwitchIfWonderGuard(void) } } - 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 @@ -131,16 +133,16 @@ static bool8 FindMonThatAbsorbsOpponentsMove(void) if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { - bankIn1 = gActiveBattler; + battlerIn1 = gActiveBattler; if (gAbsentBattlerFlags & gBitTable[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))]) - bankIn2 = gActiveBattler; + battlerIn2 = gActiveBattler; else - bankIn2 = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler))); + battlerIn2 = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler))); } else { - bankIn1 = gActiveBattler; - bankIn2 = gActiveBattler; + battlerIn1 = gActiveBattler; + battlerIn2 = gActiveBattler; } if (gBattleMoves[gLastLandedMoves[gActiveBattler]].type == TYPE_FIRE) @@ -157,7 +159,7 @@ static bool8 FindMonThatAbsorbsOpponentsMove(void) if (gBattleTypeFlags & (BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_x800000)) { - if ((gActiveBattler & BIT_FLANK) == 0) + if ((gActiveBattler & BIT_FLANK) == B_FLANK_LEFT) firstId = 0, lastId = 3; else firstId = 3, lastId = 6; @@ -183,13 +185,13 @@ static bool8 FindMonThatAbsorbsOpponentsMove(void) continue; if (GetMonData(&party[i], MON_DATA_SPECIES2) == SPECIES_EGG) continue; - if (i == gBattlerPartyIndexes[bankIn1]) + if (i == gBattlerPartyIndexes[battlerIn1]) continue; - if (i == gBattlerPartyIndexes[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); @@ -200,7 +202,7 @@ static bool8 FindMonThatAbsorbsOpponentsMove(void) if (absorbingTypeAbility == monAbility && Random() & 1) { - // we found a mon + // we found a mon. *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = i; BtlController_EmitTwoReturnValues(1, B_ACTION_SWITCH, 0); return TRUE; @@ -221,13 +223,13 @@ static bool8 ShouldSwitchIfNaturalCure(void) if ((gLastLandedMoves[gActiveBattler] == 0 || gLastLandedMoves[gActiveBattler] == 0xFFFF) && Random() & 1) { - *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = 6; + *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = PARTY_SIZE; BtlController_EmitTwoReturnValues(1, B_ACTION_SWITCH, 0); return TRUE; } else if (gBattleMoves[gLastLandedMoves[gActiveBattler]].power == 0 && Random() & 1) { - *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = 6; + *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = PARTY_SIZE; BtlController_EmitTwoReturnValues(1, B_ACTION_SWITCH, 0); return TRUE; } @@ -236,9 +238,10 @@ static bool8 ShouldSwitchIfNaturalCure(void) return TRUE; if (FindMonWithFlagsAndSuperEffective(MOVE_RESULT_NOT_VERY_EFFECTIVE, 1)) return TRUE; + if (Random() & 1) { - *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = 6; + *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = PARTY_SIZE; BtlController_EmitTwoReturnValues(1, B_ACTION_SWITCH, 0); return TRUE; } @@ -249,15 +252,15 @@ static bool8 ShouldSwitchIfNaturalCure(void) static bool8 HasSuperEffectiveMoveAgainstOpponents(bool8 noRng) { u8 opposingPosition; - u8 opposingBank; + u8 opposingBattler; s32 i; u8 moveFlags; u16 move; opposingPosition = BATTLE_OPPOSITE(GetBattlerPosition(gActiveBattler)); - opposingBank = GetBattlerAtPosition(opposingPosition); + opposingBattler = GetBattlerAtPosition(opposingPosition); - if (!(gAbsentBattlerFlags & gBitTable[opposingBank])) + if (!(gAbsentBattlerFlags & gBitTable[opposingBattler])) { for (i = 0; i < 4; i++) { @@ -265,7 +268,7 @@ static bool8 HasSuperEffectiveMoveAgainstOpponents(bool8 noRng) if (move == MOVE_NONE) continue; - moveFlags = AI_TypeCalc(move, gBattleMons[opposingBank].species, gBattleMons[opposingBank].ability); + moveFlags = AI_TypeCalc(move, gBattleMons[opposingBattler].species, gBattleMons[opposingBattler].ability); if (moveFlags & MOVE_RESULT_SUPER_EFFECTIVE) { if (noRng) @@ -278,9 +281,9 @@ static bool8 HasSuperEffectiveMoveAgainstOpponents(bool8 noRng) if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) return FALSE; - opposingBank = GetBattlerAtPosition(BATTLE_PARTNER(opposingPosition)); + opposingBattler = GetBattlerAtPosition(BATTLE_PARTNER(opposingPosition)); - if (!(gAbsentBattlerFlags & gBitTable[opposingBank])) + if (!(gAbsentBattlerFlags & gBitTable[opposingBattler])) { for (i = 0; i < 4; i++) { @@ -288,7 +291,7 @@ static bool8 HasSuperEffectiveMoveAgainstOpponents(bool8 noRng) if (move == MOVE_NONE) continue; - moveFlags = AI_TypeCalc(move, gBattleMons[opposingBank].species, gBattleMons[opposingBank].ability); + moveFlags = AI_TypeCalc(move, gBattleMons[opposingBattler].species, gBattleMons[opposingBattler].ability); if (moveFlags & MOVE_RESULT_SUPER_EFFECTIVE) { if (noRng) @@ -318,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; @@ -337,16 +340,16 @@ static bool8 FindMonWithFlagsAndSuperEffective(u8 flags, u8 moduloPercent) if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { - bankIn1 = gActiveBattler; + battlerIn1 = gActiveBattler; if (gAbsentBattlerFlags & gBitTable[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))]) - bankIn2 = gActiveBattler; + battlerIn2 = gActiveBattler; else - bankIn2 = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler))); + battlerIn2 = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler))); } else { - bankIn1 = gActiveBattler; - bankIn2 = gActiveBattler; + battlerIn1 = gActiveBattler; + battlerIn2 = gActiveBattler; } if (gBattleTypeFlags & (BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_x800000)) @@ -377,13 +380,13 @@ static bool8 FindMonWithFlagsAndSuperEffective(u8 flags, u8 moduloPercent) continue; if (GetMonData(&party[i], MON_DATA_SPECIES2) == SPECIES_EGG) continue; - if (i == gBattlerPartyIndexes[bankIn1]) + if (i == gBattlerPartyIndexes[battlerIn1]) continue; - if (i == gBattlerPartyIndexes[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); @@ -395,7 +398,7 @@ static bool8 FindMonWithFlagsAndSuperEffective(u8 flags, u8 moduloPercent) moveFlags = AI_TypeCalc(gLastLandedMoves[gActiveBattler], species, monAbility); if (moveFlags & flags) { - bankIn1 = gLastHitBy[gActiveBattler]; + battlerIn1 = gLastHitBy[gActiveBattler]; for (j = 0; j < 4; j++) { @@ -403,7 +406,7 @@ static bool8 FindMonWithFlagsAndSuperEffective(u8 flags, u8 moduloPercent) if (move == 0) continue; - moveFlags = AI_TypeCalc(move, gBattleMons[bankIn1].species, gBattleMons[bankIn1].ability); + moveFlags = AI_TypeCalc(move, gBattleMons[battlerIn1].species, gBattleMons[battlerIn1].ability); if (moveFlags & MOVE_RESULT_SUPER_EFFECTIVE && Random() % moduloPercent == 0) { *(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) = i; @@ -419,23 +422,23 @@ 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 = &gActiveBattler)].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 (AbilityBattleEffects(ABILITYEFFECT_CHECK_OTHER_SIDE, gActiveBattler, ABILITY_SHADOW_TAG, 0, 0)) + if (ABILITY_ON_OPPOSING_FIELD(gActiveBattler, ABILITY_SHADOW_TAG)) return FALSE; - if (AbilityBattleEffects(ABILITYEFFECT_CHECK_OTHER_SIDE, gActiveBattler, 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_OPPOSING_FIELD(gActiveBattler, ABILITY_ARENA_TRAP)) // Misses the flying type and Levitate check. + return FALSE; + if (ABILITY_ON_FIELD2(ABILITY_MAGNET_PULL)) { if (gBattleMons[gActiveBattler].type1 == TYPE_STEEL) return FALSE; @@ -448,21 +451,21 @@ static bool8 ShouldSwitch(void) availableToSwitch = 0; if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { - bankIn1 = *activeBankPtr; - if (gAbsentBattlerFlags & gBitTable[GetBattlerAtPosition(GetBattlerPosition(*activeBankPtr) ^ BIT_FLANK)]) - bankIn2 = *activeBankPtr; + battlerIn1 = *activeBattlerPtr; + if (gAbsentBattlerFlags & gBitTable[GetBattlerAtPosition(GetBattlerPosition(*activeBattlerPtr) ^ BIT_FLANK)]) + battlerIn2 = *activeBattlerPtr; else - bankIn2 = GetBattlerAtPosition(GetBattlerPosition(*activeBankPtr) ^ BIT_FLANK); + 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 ((gActiveBattler & BIT_FLANK) == 0) + if ((gActiveBattler & BIT_FLANK) == B_FLANK_LEFT) firstId = 0, lastId = 3; else firstId = 3, lastId = 6; @@ -485,13 +488,13 @@ static bool8 ShouldSwitch(void) continue; if (GetMonData(&party[i], MON_DATA_SPECIES2) == SPECIES_EGG) continue; - if (i == gBattlerPartyIndexes[bankIn1]) + if (i == gBattlerPartyIndexes[battlerIn1]) continue; - if (i == gBattlerPartyIndexes[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++; @@ -521,10 +524,10 @@ static bool8 ShouldSwitch(void) void AI_TrySwitchOrUseItem(void) { struct Pokemon *party; - u8 bankIn1, bankIn2; + u8 battlerIn1, battlerIn2; s32 firstId; s32 lastId; // + 1 - u8 bankIdentity = GetBattlerPosition(gActiveBattler); + u8 battlerIdentity = GetBattlerPosition(gActiveBattler); if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) party = gPlayerParty; @@ -535,25 +538,25 @@ void AI_TrySwitchOrUseItem(void) { if (ShouldSwitch()) { - if (*(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) == 6) + if (*(gBattleStruct->AI_monToSwitchIntoId + gActiveBattler) == PARTY_SIZE) { s32 monToSwitchId = GetMostSuitableMonToSwitchInto(); - if (monToSwitchId == 6) + if (monToSwitchId == PARTY_SIZE) { if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) { - bankIn1 = GetBattlerAtPosition(bankIdentity); - bankIn2 = bankIn1; + battlerIn1 = GetBattlerAtPosition(battlerIdentity); + battlerIn2 = battlerIn1; } else { - bankIn1 = GetBattlerAtPosition(bankIdentity); - bankIn2 = GetBattlerAtPosition(bankIdentity ^ BIT_FLANK); + battlerIn1 = GetBattlerAtPosition(battlerIdentity); + battlerIn2 = GetBattlerAtPosition(battlerIdentity ^ BIT_FLANK); } if (gBattleTypeFlags & (BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_x800000)) { - if ((gActiveBattler & BIT_FLANK) == 0) + if ((gActiveBattler & BIT_FLANK) == B_FLANK_LEFT) firstId = 0, lastId = 3; else firstId = 3, lastId = 6; @@ -567,13 +570,13 @@ void AI_TrySwitchOrUseItem(void) { if (GetMonData(&party[monToSwitchId], MON_DATA_HP) == 0) continue; - if (monToSwitchId == gBattlerPartyIndexes[bankIn1]) + if (monToSwitchId == gBattlerPartyIndexes[battlerIn1]) continue; - if (monToSwitchId == gBattlerPartyIndexes[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; @@ -608,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; } @@ -621,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; @@ -632,34 +635,34 @@ u8 GetMostSuitableMonToSwitchInto(void) u8 invalidMons; u16 move; - if (*(gBattleStruct->monToSwitchIntoId + gActiveBattler) != 6) + if (*(gBattleStruct->monToSwitchIntoId + gActiveBattler) != PARTY_SIZE) return *(gBattleStruct->monToSwitchIntoId + gActiveBattler); if (gBattleTypeFlags & BATTLE_TYPE_ARENA) return gBattlerPartyIndexes[gActiveBattler] + 1; if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { - bankIn1 = gActiveBattler; + battlerIn1 = gActiveBattler; if (gAbsentBattlerFlags & gBitTable[GetBattlerAtPosition(GetBattlerPosition(gActiveBattler) ^ BIT_FLANK)]) - bankIn2 = gActiveBattler; + battlerIn2 = gActiveBattler; else - bankIn2 = GetBattlerAtPosition(GetBattlerPosition(gActiveBattler) ^ BIT_FLANK); + 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_FLANK; - if (gAbsentBattlerFlags & gBitTable[opposingBank]) - opposingBank ^= BIT_FLANK; + // 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 = GetBattlerAtPosition(GetBattlerPosition(gActiveBattler) ^ BIT_SIDE); - bankIn1 = gActiveBattler; - bankIn2 = gActiveBattler; + opposingBattler = GetBattlerAtPosition(GetBattlerPosition(gActiveBattler) ^ BIT_SIDE); + battlerIn1 = gActiveBattler; + battlerIn2 = gActiveBattler; } if (gBattleTypeFlags & (BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_x800000)) { - if ((gActiveBattler & BIT_FLANK) == 0) + if ((gActiveBattler & BIT_FLANK) == B_FLANK_LEFT) firstId = 0, lastId = 3; else firstId = 3, lastId = 6; @@ -676,27 +679,27 @@ u8 GetMostSuitableMonToSwitchInto(void) 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) - && gBattlerPartyIndexes[bankIn1] != i - && gBattlerPartyIndexes[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; @@ -709,24 +712,24 @@ 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, gActiveBattler, opposingBank) & MOVE_RESULT_SUPER_EFFECTIVE) + 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. } } @@ -738,20 +741,20 @@ u8 GetMostSuitableMonToSwitchInto(void) 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 (gBattlerPartyIndexes[bankIn1] == i) + if (gBattlerPartyIndexes[battlerIn1] == i) continue; - if (gBattlerPartyIndexes[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++) @@ -760,8 +763,8 @@ u8 GetMostSuitableMonToSwitchInto(void) gBattleMoveDamage = 0; if (move != MOVE_NONE && gBattleMoves[move].power != 1) { - AI_CalcDmg(gActiveBattler, opposingBank); - TypeCalc(move, gActiveBattler, opposingBank); + AI_CalcDmg(gActiveBattler, opposingBattler); + TypeCalc(move, gActiveBattler, opposingBattler); } if (bestDmg < gBattleMoveDamage) { @@ -774,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) @@ -806,7 +809,7 @@ static bool8 ShouldUseItem(void) 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 @@ -821,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; @@ -908,8 +911,8 @@ static bool8 ShouldUseItem(void) shouldUse = TRUE; break; case AI_ITEM_GUARD_SPECS: - bankSide = GetBattlerSide(gActiveBattler); - if (gDisableStructs[gActiveBattler].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: diff --git a/src/battle_anim.c b/src/battle_anim.c index 8071736e6..b6f726897 100644 --- a/src/battle_anim.c +++ b/src/battle_anim.c @@ -120,7 +120,7 @@ EWRAM_DATA static u16 sSoundAnimFramesToWait = 0; EWRAM_DATA static u8 sMonAnimTaskIdArray[2] = {0}; EWRAM_DATA u8 gAnimMoveTurn = 0; EWRAM_DATA static u8 sAnimBackgroundFadeState = 0; -EWRAM_DATA static u16 sAnimMoveIndex = 0; // set but unused. +EWRAM_DATA static u16 sAnimMoveIndex = 0; // Set but unused. EWRAM_DATA u8 gBattleAnimAttacker = 0; EWRAM_DATA u8 gBattleAnimTarget = 0; EWRAM_DATA u16 gAnimBattlerSpecies[MAX_BATTLERS_COUNT] = {0}; @@ -179,6 +179,7 @@ static void (* const sScriptCmdTable[])(void) = ScriptCmd_stopsound }; +// code void ClearBattleAnimationVars(void) { s32 i; @@ -192,11 +193,11 @@ void ClearBattleAnimationVars(void) gAnimMovePower = 0; gAnimFriendship = 0; - // clear index array. + // Clear index array. for (i = 0; i < ANIM_SPRITE_INDEX_COUNT; i++) sAnimSpriteIndexArray[i] |= 0xFFFF; - // clear anim args. + // Clear anim args. for (i = 0; i < ANIM_ARGS_COUNT; i++) gBattleAnimArgs[i] = 0; @@ -459,7 +460,7 @@ static void ScriptCmd_delay(void) gAnimScriptCallback = WaitAnimFrameCount; } -// wait for visual tasks to finish. +// Wait for visual tasks to finish. static void ScriptCmd_waitforvisualfinish(void) { if (gAnimVisualTaskCount == 0) @@ -486,7 +487,7 @@ static void ScriptCmd_end(void) s32 i; bool32 continuousAnim = FALSE; - // keep waiting as long as there is animations to be done. + // Keep waiting as long as there are animations to be done. if (gAnimVisualTaskCount != 0 || gAnimSoundTaskCount != 0 || sMonAnimTaskIdArray[0] != 0xFF || sMonAnimTaskIdArray[1] != 0xFF) { @@ -495,10 +496,10 @@ static void ScriptCmd_end(void) return; } - // finish the sound effects. + // Finish the sound effects. if (IsSEPlaying()) { - if (++sSoundAnimFramesToWait <= 90) // wait 90 frames, then halt the sound effect. + if (++sSoundAnimFramesToWait <= 90) // Wait 90 frames, then halt the sound effect. { gAnimFramesToWait = 1; return; @@ -510,7 +511,7 @@ static void ScriptCmd_end(void) } } - // the SE has halted, so set the SE Frame Counter to 0 and continue. + // The SE has halted, so set the SE Frame Counter to 0 and continue. sSoundAnimFramesToWait = 0; for (i = 0; i < ANIM_SPRITE_INDEX_COUNT; i++) @@ -523,7 +524,7 @@ static void ScriptCmd_end(void) } } - if (!continuousAnim) // may have been used for debug? + if (!continuousAnim) // May have been used for debug? { m4aMPlayVolumeControl(&gMPlayInfo_BGM, 0xFFFF, 256); if (!IsContest()) @@ -592,12 +593,12 @@ static void ScriptCmd_monbg(void) bool8 toBG_2; u8 taskId; u8 battlerId; - u8 animBank; + u8 animBattler; sBattleAnimScriptPtr++; - animBank = sBattleAnimScriptPtr[0]; - if (animBank & ANIM_TARGET) + animBattler = sBattleAnimScriptPtr[0]; + if (animBattler & ANIM_TARGET) battlerId = gBattleAnimTarget; else battlerId = gBattleAnimAttacker; @@ -655,7 +656,7 @@ bool8 IsBattlerSpriteVisible(u8 battlerId) if (!IsBattlerSpritePresent(battlerId)) return FALSE; if (IsContest()) - return TRUE; // this line wont ever be reached. + return TRUE; // This line won't ever be reached. if (!gBattleSpritesDataPtr->battlerData[battlerId].invisible || !gSprites[gBattlerSpriteIds[battlerId]].invisible) return TRUE; @@ -847,32 +848,32 @@ static void task_pA_ma0A_obj_to_bg_pal(u8 taskId) static void ScriptCmd_clearmonbg(void) { - u8 animBankId; + u8 animBattlerId; u8 battlerId; u8 taskId; sBattleAnimScriptPtr++; - animBankId = sBattleAnimScriptPtr[0]; + animBattlerId = sBattleAnimScriptPtr[0]; - if (animBankId == ANIM_ATTACKER) - animBankId = ANIM_ATK_PARTNER; - else if (animBankId == ANIM_TARGET) - animBankId = ANIM_DEF_PARTNER; + if (animBattlerId == ANIM_ATTACKER) + animBattlerId = ANIM_ATK_PARTNER; + else if (animBattlerId == ANIM_TARGET) + animBattlerId = ANIM_DEF_PARTNER; - if (animBankId == ANIM_ATTACKER || animBankId == ANIM_ATK_PARTNER) + if (animBattlerId == ANIM_ATTACKER || animBattlerId == ANIM_ATK_PARTNER) battlerId = gBattleAnimAttacker; else battlerId = gBattleAnimTarget; if (sMonAnimTaskIdArray[0] != 0xFF) gSprites[gBattlerSpriteIds[battlerId]].invisible = 0; - if (animBankId > 1 && sMonAnimTaskIdArray[1] != 0xFF) + if (animBattlerId > 1 && sMonAnimTaskIdArray[1] != 0xFF) gSprites[gBattlerSpriteIds[battlerId ^ BIT_FLANK]].invisible = 0; else - animBankId = 0; + animBattlerId = 0; taskId = CreateTask(sub_80A4980, 5); - gTasks[taskId].data[0] = animBankId; + gTasks[taskId].data[0] = animBattlerId; gTasks[taskId].data[2] = battlerId; sBattleAnimScriptPtr++; @@ -910,18 +911,18 @@ static void ScriptCmd_monbg_22(void) { bool8 toBG_2; u8 battlerId; - u8 animBankId; + u8 animBattlerId; sBattleAnimScriptPtr++; - animBankId = sBattleAnimScriptPtr[0]; + animBattlerId = sBattleAnimScriptPtr[0]; - if (animBankId == ANIM_ATTACKER) - animBankId = ANIM_ATK_PARTNER; - else if (animBankId == ANIM_TARGET) - animBankId = ANIM_DEF_PARTNER; + if (animBattlerId == ANIM_ATTACKER) + animBattlerId = ANIM_ATK_PARTNER; + else if (animBattlerId == ANIM_TARGET) + animBattlerId = ANIM_DEF_PARTNER; - if (animBankId == ANIM_ATTACKER || animBankId == ANIM_ATK_PARTNER) + if (animBattlerId == ANIM_ATTACKER || animBattlerId == ANIM_ATK_PARTNER) battlerId = gBattleAnimAttacker; else battlerId = gBattleAnimTarget; @@ -938,7 +939,7 @@ static void ScriptCmd_monbg_22(void) } battlerId ^= BIT_FLANK; - if (animBankId > 1 && IsBattlerSpriteVisible(battlerId)) + if (animBattlerId > 1 && IsBattlerSpriteVisible(battlerId)) { u8 position = GetBattlerPosition(battlerId); if (position == B_POSITION_OPPONENT_LEFT || position == B_POSITION_PLAYER_RIGHT || IsContest()) @@ -954,32 +955,32 @@ static void ScriptCmd_monbg_22(void) static void ScriptCmd_clearmonbg_23(void) { - u8 animBankId; + u8 animBattlerId; u8 battlerId; u8 taskId; sBattleAnimScriptPtr++; - animBankId = sBattleAnimScriptPtr[0]; + animBattlerId = sBattleAnimScriptPtr[0]; - if (animBankId == ANIM_ATTACKER) - animBankId = ANIM_ATK_PARTNER; - else if (animBankId == ANIM_TARGET) - animBankId = ANIM_DEF_PARTNER; + if (animBattlerId == ANIM_ATTACKER) + animBattlerId = ANIM_ATK_PARTNER; + else if (animBattlerId == ANIM_TARGET) + animBattlerId = ANIM_DEF_PARTNER; - if (animBankId == ANIM_ATTACKER || animBankId == ANIM_ATK_PARTNER) + if (animBattlerId == ANIM_ATTACKER || animBattlerId == ANIM_ATK_PARTNER) battlerId = gBattleAnimAttacker; else battlerId = gBattleAnimTarget; if (IsBattlerSpriteVisible(battlerId)) gSprites[gBattlerSpriteIds[battlerId]].invisible = 0; - if (animBankId > 1 && IsBattlerSpriteVisible(battlerId ^ BIT_FLANK)) + if (animBattlerId > 1 && IsBattlerSpriteVisible(battlerId ^ BIT_FLANK)) gSprites[gBattlerSpriteIds[battlerId ^ BIT_FLANK]].invisible = 0; else - animBankId = 0; + animBattlerId = 0; taskId = CreateTask(sub_80A4BB0, 5); - gTasks[taskId].data[0] = animBankId; + gTasks[taskId].data[0] = animBattlerId; gTasks[taskId].data[2] = battlerId; sBattleAnimScriptPtr++; @@ -1419,18 +1420,18 @@ void Task_PanFromInitialToTarget(u8 taskId) pan = currentPan + incrementPan; gTasks[taskId].tCurrentPan = pan; - if (incrementPan == 0) // If we're not incrementing, just cancel the task immediately + if (incrementPan == 0) // If we're not incrementing, just cancel the task immediately. { destroyTask = TRUE; } - else if (initialPanning < targetPanning) // Panning increasing + else if (initialPanning < targetPanning) // Panning increasing. { - if (pan >= targetPanning) // Target reached + if (pan >= targetPanning) // Target reached. destroyTask = TRUE; } - else // Panning decreasing + else // Panning decreasing. { - if (pan <= targetPanning) // Target reached + if (pan <= targetPanning) // Target reached. destroyTask = TRUE; } @@ -1684,14 +1685,14 @@ static void ScriptCmd_jumpifcontest(void) static void ScriptCmd_monbgprio_28(void) { - u8 wantedBank; + u8 wantedBattler; u8 battlerId; u8 battlerPosition; - wantedBank = sBattleAnimScriptPtr[1]; + wantedBattler = sBattleAnimScriptPtr[1]; sBattleAnimScriptPtr += 2; - if (wantedBank != ANIM_ATTACKER) + if (wantedBattler != ANIM_ATTACKER) battlerId = gBattleAnimTarget; else battlerId = gBattleAnimAttacker; @@ -1716,15 +1717,15 @@ static void ScriptCmd_monbgprio_29(void) static void ScriptCmd_monbgprio_2A(void) { - u8 wantedBank; + u8 wantedBattler; u8 battlerPosition; u8 battlerId; - wantedBank = sBattleAnimScriptPtr[1]; + wantedBattler = sBattleAnimScriptPtr[1]; sBattleAnimScriptPtr += 2; if (GetBattlerSide(gBattleAnimAttacker) != GetBattlerSide(gBattleAnimTarget)) { - if (wantedBank != ANIM_ATTACKER) + if (wantedBattler != ANIM_ATTACKER) battlerId = gBattleAnimTarget; else battlerId = gBattleAnimAttacker; @@ -1762,16 +1763,16 @@ static void ScriptCmd_visible(void) static void ScriptCmd_doublebattle_2D(void) { - u8 wantedBank; + u8 wantedBattler; u8 r4; u8 spriteId; - wantedBank = sBattleAnimScriptPtr[1]; + wantedBattler = sBattleAnimScriptPtr[1]; sBattleAnimScriptPtr += 2; if (!IsContest() && IsDoubleBattle() && GetBattlerSide(gBattleAnimAttacker) == GetBattlerSide(gBattleAnimTarget)) { - if (wantedBank == ANIM_ATTACKER) + if (wantedBattler == ANIM_ATTACKER) { r4 = sub_80A8364(gBattleAnimAttacker); spriteId = GetAnimBattlerSpriteId(ANIM_ATTACKER); @@ -1797,16 +1798,16 @@ static void ScriptCmd_doublebattle_2D(void) static void ScriptCmd_doublebattle_2E(void) { - u8 wantedBank; + u8 wantedBattler; u8 r4; u8 spriteId; - wantedBank = sBattleAnimScriptPtr[1]; + wantedBattler = sBattleAnimScriptPtr[1]; sBattleAnimScriptPtr += 2; if (!IsContest() && IsDoubleBattle() && GetBattlerSide(gBattleAnimAttacker) == GetBattlerSide(gBattleAnimTarget)) { - if (wantedBank == ANIM_ATTACKER) + if (wantedBattler == ANIM_ATTACKER) { r4 = sub_80A8364(gBattleAnimAttacker); spriteId = GetAnimBattlerSpriteId(ANIM_ATTACKER); diff --git a/src/battle_anim_sound_tasks.c b/src/battle_anim_sound_tasks.c index 2316b9759..5a829171e 100644 --- a/src/battle_anim_sound_tasks.c +++ b/src/battle_anim_sound_tasks.c @@ -133,13 +133,13 @@ void sub_8158D8C(u8 taskId) if (gBattleAnimArgs[0] == ANIM_ATTACKER) species = gContestResources->field_18->field_0; else - DestroyAnimVisualTask(taskId); // UB: function should return upon destroying task + DestroyAnimVisualTask(taskId); // UB: function should return upon destroying task. } else { u8 battlerId; - // get wanted battler + // Get wanted battler. if (gBattleAnimArgs[0] == ANIM_ATTACKER) battlerId = gBattleAnimAttacker; else if (gBattleAnimArgs[0] == ANIM_TARGET) @@ -149,7 +149,7 @@ void sub_8158D8C(u8 taskId) else battlerId = BATTLE_PARTNER(gBattleAnimTarget); - // check if battler is visible + // Check if battler is visible. if ((gBattleAnimArgs[0] == ANIM_TARGET || gBattleAnimArgs[0] == ANIM_DEF_PARTNER) && !IsBattlerSpriteVisible(battlerId)) { DestroyAnimVisualTask(taskId); @@ -179,13 +179,13 @@ void sub_8158E9C(u8 taskId) if (gBattleAnimArgs[0] == ANIM_ATTACKER) species = gContestResources->field_18->field_0; else - DestroyAnimVisualTask(taskId); // UB: function should return upon destroying task + DestroyAnimVisualTask(taskId); // UB: function should return upon destroying task. } else { u8 battlerId; - // get wanted battler + // Get wanted battler. if (gBattleAnimArgs[0] == ANIM_ATTACKER) battlerId = gBattleAnimAttacker; else if (gBattleAnimArgs[0] == ANIM_TARGET) @@ -195,7 +195,7 @@ void sub_8158E9C(u8 taskId) else battlerId = BATTLE_PARTNER(gBattleAnimTarget); - // check if battler is visible + // Check if battler is visible. if ((gBattleAnimArgs[0] == ANIM_TARGET || gBattleAnimArgs[0] == ANIM_DEF_PARTNER) && !IsBattlerSpriteVisible(battlerId)) { DestroyAnimVisualTask(taskId); diff --git a/src/battle_bg.c b/src/battle_bg.c index d4bfd297a..4895e9643 100644 --- a/src/battle_bg.c +++ b/src/battle_bg.c @@ -31,8 +31,8 @@ struct BattleBackground extern const struct SpriteTemplate gUnknown_0831A9D0; extern const struct SpriteTemplate gUnknown_0831A9E8; extern const struct CompressedSpriteSheet gUnknown_0831AA00; -extern const struct BgTemplate gUnknown_0831AA08[4]; -extern const struct WindowTemplate *gUnknown_0831ABA0[]; +extern const struct BgTemplate gBattleBgTemplates[4]; +extern const struct WindowTemplate *const gBattleWindowTemplates[]; extern const struct BattleBackground gBattleTerrainTable[]; extern u16 gBattle_BG1_X; @@ -42,23 +42,23 @@ extern u16 gBattle_BG2_Y; extern u8 GetCurrentMapBattleScene(void); -void sub_8035658(void) +void BattleInitBgsAndWindows(void) { ResetBgsAndClearDma3BusyFlags(0); - InitBgsFromTemplates(0, gUnknown_0831AA08, ARRAY_COUNT(gUnknown_0831AA08)); + InitBgsFromTemplates(0, gBattleBgTemplates, ARRAY_COUNT(gBattleBgTemplates)); if (gBattleTypeFlags & BATTLE_TYPE_ARENA) { - gBattleScripting.field_24 = 1; + gBattleScripting.windowsType = 1; SetBgTilemapBuffer(1, gUnknown_02023060); SetBgTilemapBuffer(2, gUnknown_02023060); } else { - gBattleScripting.field_24 = 0; + gBattleScripting.windowsType = 0; } - InitWindows(gUnknown_0831ABA0[gBattleScripting.field_24]); + InitWindows(gBattleWindowTemplates[gBattleScripting.windowsType]); DeactivateAllTextPrinters(); } @@ -66,23 +66,23 @@ void sub_80356D0(void) { DisableInterrupts(INTR_FLAG_HBLANK); EnableInterrupts(INTR_FLAG_VBLANK | INTR_FLAG_VCOUNT | INTR_FLAG_TIMER3 | INTR_FLAG_SERIAL); - sub_8035658(); + BattleInitBgsAndWindows(); SetGpuReg(REG_OFFSET_BLDCNT, 0); SetGpuReg(REG_OFFSET_BLDALPHA, 0); SetGpuReg(REG_OFFSET_BLDY, 0); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJWIN_ON | DISPCNT_WIN0_ON | DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); } -void ApplyPlayerChosenFrameToBattleMenu(void) +void LoadBattleMenuWindowGfx(void) { - sub_809882C(2, 0x12, 0x10); - sub_809882C(2, 0x22, 0x10); + LoadSav2WindowGfx(2, 0x12, 0x10); + LoadSav2WindowGfx(2, 0x22, 0x10); LoadCompressedPalette(gUnknown_08D85600, 0x50, 0x20); if (gBattleTypeFlags & BATTLE_TYPE_ARENA) { sub_81978B0(0x70); - copy_textbox_border_tile_patterns_to_vram(0, 0x30, 0x70); + LoadMessageBoxGfx(0, 0x30, 0x70); gPlttBufferUnfaded[0x76] = 0; CpuCopy16(&gPlttBufferUnfaded[0x76], &gPlttBufferFaded[0x76], 2); } @@ -193,12 +193,12 @@ void LoadBattleTextboxAndBackground(void) CopyToBgTilemapBuffer(0, gBattleTextboxTilemap, 0, 0); CopyBgTilemapBufferToVram(0); LoadCompressedPalette(gBattleTextboxPalette, 0, 0x40); - ApplyPlayerChosenFrameToBattleMenu(); + LoadBattleMenuWindowGfx(); DrawMainBattleBackground(); } -static void sub_8035AE4(u8 taskId, u8 bank, u8 bgId, u8 destX, u8 destY) +static void sub_8035AE4(u8 taskId, u8 battlerId, u8 bgId, u8 destX, u8 destY) { s32 i; u16 var = 0; @@ -208,7 +208,7 @@ static void sub_8035AE4(u8 taskId, u8 bank, u8 bgId, u8 destX, u8 destY) { if (gTasks[taskId].data[5] != 0) { - switch (bank) + switch (battlerId) { case 0: var = 0x3F & gTasks[taskId].data[3]; @@ -226,7 +226,7 @@ static void sub_8035AE4(u8 taskId, u8 bank, u8 bgId, u8 destX, u8 destY) } else { - switch (bank) + switch (battlerId) { case 0: var = 0x3F & gTasks[taskId].data[3]; @@ -253,7 +253,7 @@ static void sub_8035AE4(u8 taskId, u8 bank, u8 bgId, u8 destX, u8 destY) } else { - if (bank == gBattleScripting.multiplayerId) + if (battlerId == gBattleScripting.multiplayerId) var = gTasks[taskId].data[3]; else var = gTasks[taskId].data[4]; @@ -272,7 +272,7 @@ static void sub_8035C4C(void) { if (gBattleOutcome == B_OUTCOME_DREW) { - BattleHandleAddTextPrinter(gText_Draw, 0x15); + BattlePutTextOnWindow(gText_Draw, 0x15); } else if (gBattleTypeFlags & BATTLE_TYPE_MULTI) { @@ -281,20 +281,20 @@ static void sub_8035C4C(void) switch (gLinkPlayers[gBattleScripting.multiplayerId].lp_field_18) { case 0: - BattleHandleAddTextPrinter(gText_Win, 0x16); - BattleHandleAddTextPrinter(gText_Loss, 0x17); + BattlePutTextOnWindow(gText_Win, 0x16); + BattlePutTextOnWindow(gText_Loss, 0x17); break; case 1: - BattleHandleAddTextPrinter(gText_Win, 0x17); - BattleHandleAddTextPrinter(gText_Loss, 0x16); + BattlePutTextOnWindow(gText_Win, 0x17); + BattlePutTextOnWindow(gText_Loss, 0x16); break; case 2: - BattleHandleAddTextPrinter(gText_Win, 0x16); - BattleHandleAddTextPrinter(gText_Loss, 0x17); + BattlePutTextOnWindow(gText_Win, 0x16); + BattlePutTextOnWindow(gText_Loss, 0x17); break; case 3: - BattleHandleAddTextPrinter(gText_Win, 0x17); - BattleHandleAddTextPrinter(gText_Loss, 0x16); + BattlePutTextOnWindow(gText_Win, 0x17); + BattlePutTextOnWindow(gText_Loss, 0x16); break; } } @@ -303,20 +303,20 @@ static void sub_8035C4C(void) switch (gLinkPlayers[gBattleScripting.multiplayerId].lp_field_18) { case 0: - BattleHandleAddTextPrinter(gText_Win, 0x17); - BattleHandleAddTextPrinter(gText_Loss, 0x16); + BattlePutTextOnWindow(gText_Win, 0x17); + BattlePutTextOnWindow(gText_Loss, 0x16); break; case 1: - BattleHandleAddTextPrinter(gText_Win, 0x16); - BattleHandleAddTextPrinter(gText_Loss, 0x17); + BattlePutTextOnWindow(gText_Win, 0x16); + BattlePutTextOnWindow(gText_Loss, 0x17); break; case 2: - BattleHandleAddTextPrinter(gText_Win, 0x17); - BattleHandleAddTextPrinter(gText_Loss, 0x16); + BattlePutTextOnWindow(gText_Win, 0x17); + BattlePutTextOnWindow(gText_Loss, 0x16); break; case 3: - BattleHandleAddTextPrinter(gText_Win, 0x16); - BattleHandleAddTextPrinter(gText_Loss, 0x17); + BattlePutTextOnWindow(gText_Win, 0x16); + BattlePutTextOnWindow(gText_Loss, 0x17); break; } } @@ -325,26 +325,26 @@ static void sub_8035C4C(void) { if (gLinkPlayers[gBattleScripting.multiplayerId].lp_field_18 != 0) { - BattleHandleAddTextPrinter(gText_Win, 0x17); - BattleHandleAddTextPrinter(gText_Loss, 0x16); + BattlePutTextOnWindow(gText_Win, 0x17); + BattlePutTextOnWindow(gText_Loss, 0x16); } else { - BattleHandleAddTextPrinter(gText_Win, 0x16); - BattleHandleAddTextPrinter(gText_Loss, 0x17); + BattlePutTextOnWindow(gText_Win, 0x16); + BattlePutTextOnWindow(gText_Loss, 0x17); } } else { if (gLinkPlayers[gBattleScripting.multiplayerId].lp_field_18 != 0) { - BattleHandleAddTextPrinter(gText_Win, 0x16); - BattleHandleAddTextPrinter(gText_Loss, 0x17); + BattlePutTextOnWindow(gText_Win, 0x16); + BattlePutTextOnWindow(gText_Loss, 0x17); } else { - BattleHandleAddTextPrinter(gText_Win, 0x17); - BattleHandleAddTextPrinter(gText_Loss, 0x16); + BattlePutTextOnWindow(gText_Win, 0x17); + BattlePutTextOnWindow(gText_Loss, 0x16); } } } @@ -368,19 +368,19 @@ void sub_8035D74(u8 taskId) switch (linkPlayer->lp_field_18) { case 0: - BattleHandleAddTextPrinter(name, 0x11); + BattlePutTextOnWindow(name, 0x11); sub_8035AE4(taskId, linkPlayer->lp_field_18, 1, 2, 4); break; case 1: - BattleHandleAddTextPrinter(name, 0x12); + BattlePutTextOnWindow(name, 0x12); sub_8035AE4(taskId, linkPlayer->lp_field_18, 2, 2, 4); break; case 2: - BattleHandleAddTextPrinter(name, 0x13); + BattlePutTextOnWindow(name, 0x13); sub_8035AE4(taskId, linkPlayer->lp_field_18, 1, 2, 8); break; case 3: - BattleHandleAddTextPrinter(name, 0x14); + BattlePutTextOnWindow(name, 0x14); sub_8035AE4(taskId, linkPlayer->lp_field_18, 2, 2, 8); break; } @@ -396,10 +396,10 @@ void sub_8035D74(u8 taskId) opponentId = playerId, playerId = opponentId_copy; name = gLinkPlayers[playerId].name; - BattleHandleAddTextPrinter(name, 0xF); + BattlePutTextOnWindow(name, 0xF); name = gLinkPlayers[opponentId].name; - BattleHandleAddTextPrinter(name, 0x10); + BattlePutTextOnWindow(name, 0x10); sub_8035AE4(taskId, playerId, 1, 2, 7); sub_8035AE4(taskId, opponentId, 2, 2, 7); @@ -457,7 +457,7 @@ void sub_8035D74(u8 taskId) } } -void LoadBattleEntryBackground(void) +void DrawBattleEntryBackground(void) { if (gBattleTypeFlags & BATTLE_TYPE_LINK) { @@ -740,7 +740,7 @@ bool8 LoadChosenBattleElement(u8 caseId) } break; case 6: - ApplyPlayerChosenFrameToBattleMenu(); + LoadBattleMenuWindowGfx(); break; default: ret = TRUE; diff --git a/src/battle_controller_link_opponent.c b/src/battle_controller_link_opponent.c index a4aac55e2..905e957ea 100644 --- a/src/battle_controller_link_opponent.c +++ b/src/battle_controller_link_opponent.c @@ -1475,7 +1475,7 @@ static void LinkOpponentHandlePrintString(void) gBattle_BG0_Y = 0; stringId = (u16*)(&gBattleBufferA[gActiveBattler][2]); BufferStringBattle(*stringId); - BattleHandleAddTextPrinter(gDisplayedStringBattle, 0); + BattlePutTextOnWindow(gDisplayedStringBattle, 0); gBattlerControllerFuncs[gActiveBattler] = CompleteOnInactiveTextPrinter; BattleTv_SetDataBasedOnString(*stringId); } diff --git a/src/battle_controller_link_partner.c b/src/battle_controller_link_partner.c index d742d5df2..3178bad0e 100644 --- a/src/battle_controller_link_partner.c +++ b/src/battle_controller_link_partner.c @@ -1299,7 +1299,7 @@ static void LinkPartnerHandlePrintString(void) gBattle_BG0_Y = 0; stringId = (u16*)(&gBattleBufferA[gActiveBattler][2]); BufferStringBattle(*stringId); - BattleHandleAddTextPrinter(gDisplayedStringBattle, 0); + BattlePutTextOnWindow(gDisplayedStringBattle, 0); gBattlerControllerFuncs[gActiveBattler] = CompleteOnInactiveTextPrinter; BattleTv_SetDataBasedOnString(*stringId); } diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index 64cf16b86..ae407af24 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -1511,7 +1511,7 @@ static void OpponentHandlePrintString(void) gBattle_BG0_Y = 0; stringId = (u16*)(&gBattleBufferA[gActiveBattler][2]); BufferStringBattle(*stringId); - BattleHandleAddTextPrinter(gDisplayedStringBattle, 0); + BattlePutTextOnWindow(gDisplayedStringBattle, 0); gBattlerControllerFuncs[gActiveBattler] = CompleteOnInactiveTextPrinter; sub_81A57E4(gActiveBattler, *stringId); } diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index e0694029a..627b13e22 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -620,7 +620,7 @@ static void HandleInputChooseMove(void) gMultiUsePlayerCursor = gMoveSelectionCursor[gActiveBattler] + 1; MoveSelectionCreateCursorAt(gMultiUsePlayerCursor, 27); - BattleHandleAddTextPrinter(gText_BattleSwitchWhich, 0xB); + BattlePutTextOnWindow(gText_BattleSwitchWhich, 0xB); gBattlerControllerFuncs[gActiveBattler] = HandleMoveSwitchting; } } @@ -1458,7 +1458,7 @@ static void MoveSelectionDisplayMoveNames(void) { MoveSelectionDestroyCursorAt(i); StringCopy(gDisplayedStringBattle, gMoveNames[moveInfo->moves[i]]); - BattleHandleAddTextPrinter(gDisplayedStringBattle, i + 3); + BattlePutTextOnWindow(gDisplayedStringBattle, i + 3); if (moveInfo->moves[i] != MOVE_NONE) gNumberOfMovesToChoose++; } @@ -1467,7 +1467,7 @@ static void MoveSelectionDisplayMoveNames(void) static void MoveSelectionDisplayPpString(void) { StringCopy(gDisplayedStringBattle, gText_MoveInterfacePP); - BattleHandleAddTextPrinter(gDisplayedStringBattle, 7); + BattlePutTextOnWindow(gDisplayedStringBattle, 7); } static void MoveSelectionDisplayPpNumber(void) @@ -1485,7 +1485,7 @@ static void MoveSelectionDisplayPpNumber(void) txtPtr++; ConvertIntToDecimalStringN(txtPtr, moveInfo->maxPp[gMoveSelectionCursor[gActiveBattler]], STR_CONV_MODE_RIGHT_ALIGN, 2); - BattleHandleAddTextPrinter(gDisplayedStringBattle, 9); + BattlePutTextOnWindow(gDisplayedStringBattle, 9); } static void MoveSelectionDisplayMoveType(void) @@ -1502,7 +1502,7 @@ static void MoveSelectionDisplayMoveType(void) txtPtr++; StringCopy(txtPtr, gTypeNames[gBattleMoves[moveInfo->moves[gMoveSelectionCursor[gActiveBattler]]].type]); - BattleHandleAddTextPrinter(gDisplayedStringBattle, 10); + BattlePutTextOnWindow(gDisplayedStringBattle, 10); } static void MoveSelectionCreateCursorAt(u8 cursorPosition, u8 arg1) @@ -1573,7 +1573,7 @@ static void PrintLinkStandbyMsg(void) { gBattle_BG0_X = 0; gBattle_BG0_Y = 0; - BattleHandleAddTextPrinter(gText_LinkStandby, 0); + BattlePutTextOnWindow(gText_LinkStandby, 0); } } @@ -2536,7 +2536,7 @@ static void PlayerHandlePrintString(void) gBattle_BG0_Y = 0; stringId = (u16*)(&gBattleBufferA[gActiveBattler][2]); BufferStringBattle(*stringId); - BattleHandleAddTextPrinter(gDisplayedStringBattle, 0); + BattlePutTextOnWindow(gDisplayedStringBattle, 0); gBattlerControllerFuncs[gActiveBattler] = CompleteOnInactiveTextPrinter2; BattleTv_SetDataBasedOnString(*stringId); sub_81A57E4(gActiveBattler, *stringId); @@ -2566,14 +2566,14 @@ static void PlayerHandleChooseAction(void) gBattlerControllerFuncs[gActiveBattler] = HandleChooseActionAfterDma3; BattleTv_ClearExplosionFaintCause(); - BattleHandleAddTextPrinter(gText_BattleMenu, 2); + BattlePutTextOnWindow(gText_BattleMenu, 2); for (i = 0; i < 4; i++) ActionSelectionDestroyCursorAt(i); ActionSelectionCreateCursorAt(gActionSelectionCursor[gActiveBattler], 0); BattleStringExpandPlaceholdersToDisplayedString(gText_WhatWillPkmnDo); - BattleHandleAddTextPrinter(gDisplayedStringBattle, 1); + BattlePutTextOnWindow(gDisplayedStringBattle, 1); } static void PlayerHandleUnknownYesNoBox(void) @@ -2581,7 +2581,7 @@ static void PlayerHandleUnknownYesNoBox(void) if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) { HandleBattleWindow(0x18, 8, 0x1D, 0xD, 0); - BattleHandleAddTextPrinter(gText_BattleYesNoChoice, 12); + BattlePutTextOnWindow(gText_BattleYesNoChoice, 12); gMultiUsePlayerCursor = 1; BattleCreateYesNoCursorAt(1); gBattlerControllerFuncs[gActiveBattler] = PlayerHandleUnknownYesNoInput; diff --git a/src/battle_controller_player_partner.c b/src/battle_controller_player_partner.c index f18f582f7..25eef4c5c 100644 --- a/src/battle_controller_player_partner.c +++ b/src/battle_controller_player_partner.c @@ -1492,7 +1492,7 @@ static void PlayerPartnerHandlePrintString(void) gBattle_BG0_Y = 0; stringId = (u16*)(&gBattleBufferA[gActiveBattler][2]); BufferStringBattle(*stringId); - BattleHandleAddTextPrinter(gDisplayedStringBattle, 0); + BattlePutTextOnWindow(gDisplayedStringBattle, 0); gBattlerControllerFuncs[gActiveBattler] = CompleteOnInactiveTextPrinter2; } diff --git a/src/battle_controller_recorded_opponent.c b/src/battle_controller_recorded_opponent.c index 4d1ccbaca..b4bdfaa4e 100644 --- a/src/battle_controller_recorded_opponent.c +++ b/src/battle_controller_recorded_opponent.c @@ -1404,7 +1404,7 @@ static void RecordedOpponentHandlePrintString(void) gBattle_BG0_Y = 0; stringId = (u16*)(&gBattleBufferA[gActiveBattler][2]); BufferStringBattle(*stringId); - BattleHandleAddTextPrinter(gDisplayedStringBattle, 0); + BattlePutTextOnWindow(gDisplayedStringBattle, 0); gBattlerControllerFuncs[gActiveBattler] = CompleteOnInactiveTextPrinter; } diff --git a/src/battle_controller_recorded_player.c b/src/battle_controller_recorded_player.c index b16c3f307..24cb58ea4 100644 --- a/src/battle_controller_recorded_player.c +++ b/src/battle_controller_recorded_player.c @@ -1409,7 +1409,7 @@ static void RecordedPlayerHandlePrintString(void) gBattle_BG0_Y = 0; stringId = (u16*)(&gBattleBufferA[gActiveBattler][2]); BufferStringBattle(*stringId); - BattleHandleAddTextPrinter(gDisplayedStringBattle, 0); + BattlePutTextOnWindow(gDisplayedStringBattle, 0); gBattlerControllerFuncs[gActiveBattler] = CompleteOnInactiveTextPrinter; } diff --git a/src/battle_controller_safari.c b/src/battle_controller_safari.c index 09776f150..245447d8d 100644 --- a/src/battle_controller_safari.c +++ b/src/battle_controller_safari.c @@ -427,7 +427,7 @@ static void SafariHandlePrintString(void) gBattle_BG0_Y = 0; stringId = (u16*)(&gBattleBufferA[gActiveBattler][2]); BufferStringBattle(*stringId); - BattleHandleAddTextPrinter(gDisplayedStringBattle, 0); + BattlePutTextOnWindow(gDisplayedStringBattle, 0); gBattlerControllerFuncs[gActiveBattler] = CompleteOnInactiveTextPrinter; } @@ -454,14 +454,14 @@ static void SafariHandleChooseAction(void) s32 i; gBattlerControllerFuncs[gActiveBattler] = HandleChooseActionAfterDma3; - BattleHandleAddTextPrinter(gText_SafariZoneMenu, 2); + BattlePutTextOnWindow(gText_SafariZoneMenu, 2); for (i = 0; i < 4; i++) ActionSelectionDestroyCursorAt(i); ActionSelectionCreateCursorAt(gActionSelectionCursor[gActiveBattler], 0); BattleStringExpandPlaceholdersToDisplayedString(gText_WhatWillPkmnDo2); - BattleHandleAddTextPrinter(gDisplayedStringBattle, 1); + BattlePutTextOnWindow(gDisplayedStringBattle, 1); } static void SafariHandleUnknownYesNoBox(void) diff --git a/src/battle_controller_wally.c b/src/battle_controller_wally.c index ca7b2fd44..e8efb404f 100644 --- a/src/battle_controller_wally.c +++ b/src/battle_controller_wally.c @@ -1179,7 +1179,7 @@ static void WallyHandlePrintString(void) gBattle_BG0_Y = 0; stringId = (u16*)(&gBattleBufferA[gActiveBattler][2]); BufferStringBattle(*stringId); - BattleHandleAddTextPrinter(gDisplayedStringBattle, 0); + BattlePutTextOnWindow(gDisplayedStringBattle, 0); gBattlerControllerFuncs[gActiveBattler] = CompleteOnInactiveTextPrinter; } @@ -1206,14 +1206,14 @@ static void WallyHandleChooseAction(void) s32 i; gBattlerControllerFuncs[gActiveBattler] = HandleChooseActionAfterDma3; - BattleHandleAddTextPrinter(gText_BattleMenu, 2); + BattlePutTextOnWindow(gText_BattleMenu, 2); for (i = 0; i < 4; i++) ActionSelectionDestroyCursorAt(i); ActionSelectionCreateCursorAt(gActionSelectionCursor[gActiveBattler], 0); BattleStringExpandPlaceholdersToDisplayedString(gText_WhatWillWallyDo); - BattleHandleAddTextPrinter(gDisplayedStringBattle, 1); + BattlePutTextOnWindow(gDisplayedStringBattle, 1); } static void WallyHandleUnknownYesNoBox(void) diff --git a/src/battle_main.c b/src/battle_main.c index 8649209c0..2d24d0dab 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -82,8 +82,8 @@ extern struct MusicPlayerInfo gMPlayInfo_SE2; extern u8 gUnknown_0203CF00[]; extern const u16 gBattleTextboxPalette[]; // battle textbox palette -extern const struct BgTemplate gUnknown_0831AA08[]; -extern const struct WindowTemplate * const gUnknown_0831ABA0[]; +extern const struct BgTemplate gBattleBgTemplates[]; +extern const struct WindowTemplate * const gBattleWindowTemplates[]; extern const u8 gUnknown_0831ACE0[]; extern const u8 * const gBattleScriptsForMoveEffects[]; extern const u8 * const gBattlescriptsForBallThrow[]; @@ -652,7 +652,7 @@ static void CB2_InitBattleInternal(void) LoadBattleTextboxAndBackground(); ResetSpriteData(); ResetTasks(); - LoadBattleEntryBackground(); + DrawBattleEntryBackground(); FreeAllSpritePalettes(); gReservedSpritePaletteCount = 4; SetVBlankCallback(VBlankCB_Battle); @@ -2210,10 +2210,10 @@ void sub_8038D64(void) sub_80356D0(); LoadCompressedPalette(gBattleTextboxPalette, 0, 64); - ApplyPlayerChosenFrameToBattleMenu(); + LoadBattleMenuWindowGfx(); ResetSpriteData(); ResetTasks(); - LoadBattleEntryBackground(); + DrawBattleEntryBackground(); SetGpuReg(REG_OFFSET_WINOUT, 0x37); FreeAllSpritePalettes(); gReservedSpritePaletteCount = 4; @@ -2327,7 +2327,7 @@ static void sub_8038F34(void) if (sub_800A520() == TRUE) { sub_800ADF8(); - BattleHandleAddTextPrinter(gText_LinkStandby3, 0); + BattlePutTextOnWindow(gText_LinkStandby3, 0); gBattleCommunication[MULTIUSE_STATE]++; } break; @@ -2363,25 +2363,25 @@ u32 sub_80391E0(u8 arrayId, u8 caseId) switch (caseId) { case 0: - ret = gUnknown_0831AA08[arrayId].bg; + ret = gBattleBgTemplates[arrayId].bg; break; case 1: - ret = gUnknown_0831AA08[arrayId].charBaseIndex; + ret = gBattleBgTemplates[arrayId].charBaseIndex; break; case 2: - ret = gUnknown_0831AA08[arrayId].mapBaseIndex; + ret = gBattleBgTemplates[arrayId].mapBaseIndex; break; case 3: - ret = gUnknown_0831AA08[arrayId].screenSize; + ret = gBattleBgTemplates[arrayId].screenSize; break; case 4: - ret = gUnknown_0831AA08[arrayId].paletteMode; + ret = gBattleBgTemplates[arrayId].paletteMode; break; case 5: - ret = gUnknown_0831AA08[arrayId].priority; + ret = gBattleBgTemplates[arrayId].priority; break; case 6: - ret = gUnknown_0831AA08[arrayId].baseTile; + ret = gBattleBgTemplates[arrayId].baseTile; break; } @@ -2406,7 +2406,7 @@ static void sub_80392A8(void) gBattle_BG3_Y = 0; sub_80356D0(); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); - ApplyPlayerChosenFrameToBattleMenu(); + LoadBattleMenuWindowGfx(); for (i = 0; i < 2; i++) LoadChosenBattleElement(i); @@ -2453,7 +2453,7 @@ static void sub_803939C(void) case 3: if (!gPaletteFade.active) { - BattleHandleAddTextPrinter(gText_RecordBattleToPass, 0); + BattlePutTextOnWindow(gText_RecordBattleToPass, 0); gBattleCommunication[MULTIUSE_STATE]++; } break; @@ -2461,7 +2461,7 @@ static void sub_803939C(void) if (!IsTextPrinterActive(0)) { HandleBattleWindow(0x18, 8, 0x1D, 0xD, 0); - BattleHandleAddTextPrinter(gText_BattleYesNoChoice, 0xC); + BattlePutTextOnWindow(gText_BattleYesNoChoice, 0xC); gBattleCommunication[CURSOR_POSITION] = 1; BattleCreateYesNoCursorAt(1); gBattleCommunication[MULTIUSE_STATE]++; @@ -2515,7 +2515,7 @@ static void sub_803939C(void) if (gMain.field_439_x4) { sub_800ADF8(); - BattleHandleAddTextPrinter(gText_LinkStandby3, 0); + BattlePutTextOnWindow(gText_LinkStandby3, 0); } gBattleCommunication[MULTIUSE_STATE]++; } @@ -2546,14 +2546,14 @@ static void sub_803939C(void) { PlaySE(SE_SAVE); BattleStringExpandPlaceholdersToDisplayedString(gText_BattleRecordedOnPass); - BattleHandleAddTextPrinter(gDisplayedStringBattle, 0); + BattlePutTextOnWindow(gDisplayedStringBattle, 0); gBattleCommunication[1] = 0x80; gBattleCommunication[MULTIUSE_STATE]++; } else { BattleStringExpandPlaceholdersToDisplayedString(gText_BattleRecordCouldntBeSaved); - BattleHandleAddTextPrinter(gDisplayedStringBattle, 0); + BattlePutTextOnWindow(gDisplayedStringBattle, 0); gBattleCommunication[1] = 0x80; gBattleCommunication[MULTIUSE_STATE]++; } @@ -2564,7 +2564,7 @@ static void sub_803939C(void) if (gMain.field_439_x4) { sub_800ADF8(); - BattleHandleAddTextPrinter(gText_LinkStandby3, 0); + BattlePutTextOnWindow(gText_LinkStandby3, 0); } gBattleCommunication[MULTIUSE_STATE]++; } @@ -2610,7 +2610,7 @@ static void TryCorrectShedinjaLanguage(struct Pokemon *mon) u32 sub_80397C4(u32 setId, u32 tableId) { - return gUnknown_0831ABA0[setId][tableId].width * 8; + return gBattleWindowTemplates[setId][tableId].width * 8; } #define sBattler data[0] @@ -3885,7 +3885,7 @@ static void TryDoEventsBeforeFirstTurn(void) TurnValuesCleanUp(FALSE); SpecialStatusesClear(); *(&gBattleStruct->field_91) = gAbsentBattlerFlags; - BattleHandleAddTextPrinter(gText_EmptyString3, 0); + BattlePutTextOnWindow(gText_EmptyString3, 0); gBattleMainFunc = HandleTurnActionSelectionState; ResetSentPokesToOpponentValue(); @@ -3992,7 +3992,7 @@ void BattleTurnPassed(void) *(gBattleStruct->monToSwitchIntoId + i) = 6; *(&gBattleStruct->field_91) = gAbsentBattlerFlags; - BattleHandleAddTextPrinter(gText_EmptyString3, 0); + BattlePutTextOnWindow(gText_EmptyString3, 0); gBattleMainFunc = HandleTurnActionSelectionState; gRandomTurnNumber = Random(); diff --git a/src/battle_message.c b/src/battle_message.c index 1f338db92..896b2197e 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -17,6 +17,20 @@ #include "recorded_battle.h" #include "international_string_util.h" +struct BattleWindowText +{ + u8 fillValue; + u8 fontId; + u8 x; + u8 y; + u8 letterSpacing; + u8 lineSpacing; + u8 speed; + u8 fgColor; + u8 bgColor; + u8 shadowColor; +}; + extern u8 gBattlerAbilities[MAX_BATTLERS_COUNT]; extern u8 gUnknown_0203C7B4; extern struct StringInfoBattle *gStringInfo; @@ -1351,67 +1365,590 @@ static const u16 sUnknownMoveTable[] = static const u8 sDummyWeirdStatusString[] = {EOS, EOS, EOS, EOS, EOS, EOS, EOS, EOS, 0, 0}; -static const u8 sUnknown_085CD42C[] = +static const struct BattleWindowText sTextOnWindowsInfo_Normal[] = { - 0xFF, 0x1, 0x0, 0x1, 0x0, 0x0, 0x1, 0x1, 0xF, 0x6, 0x0, 0x0, 0xFF, 0x1, - 0x1, 0x1, 0x0, 0x0, 0x0, 0x1, 0xF, 0x6, 0x0, 0x0, 0xEE, 0x1, 0x0, 0x1, 0x0, - 0x0, 0x0, 0xD, 0xE, 0xF, 0x0, 0x0, 0xEE, 0x7, 0x0, 0x1, 0x0, 0x0, 0x0, - 0xD, 0xE, 0xF, 0x0, 0x0, 0xEE, 0x7, 0x0, 0x1, 0x0, 0x0, 0x0, 0xD, - 0xE, 0xF, 0x0, 0x0, 0xEE, 0x7, 0x0, 0x1, 0x0, 0x0, 0x0, 0xD, 0xE, - 0xF, 0x0, 0x0, 0xEE, 0x7, 0x0, 0x1, 0x0, 0x0, 0x0, 0xD, 0xE, 0xF, - 0x0, 0x0, 0xEE, 0x7, 0x0, 0x1, 0x0, 0x0, 0x0, 0xC, 0xE, 0xB, 0x0, 0x0, - 0xEE, 0x1, 0x0, 0x1, 0x0, 0x0, 0x0, 0xD, 0xE, 0xF, 0x0, 0x0, 0xEE, - 0x1, 0x2, 0x1, 0x0, 0x0, 0x0, 0xC, 0xE, 0xB, 0x0, 0x0, 0xEE, 0x7, 0x0, - 0x1, 0x0, 0x0, 0x0, 0xD, 0xE, 0xF, 0x0, 0x0, 0xEE, 0x7, 0x0, 0x1, 0x0, - 0x0, 0x0, 0xD, 0xE, 0xF, 0x0, 0x0, 0xEE, 0x1, 0x0, 0x1, 0x0, 0x0, 0x0, - 0xD, 0xE, 0xF, 0x0, 0x0, 0xEE, 0x1, 0x0, 0x1, 0x0, 0x0, 0x0, 0xD, - 0xE, 0xF, 0x0, 0x0, 0x0, 0x1, 0x20, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x2, - 0x0, 0x0, 0xEE, 0x1, 0xFF, 0x1, 0x0, 0x0, 0x0, 0xD, 0xE, 0xF, 0x0, - 0x0, 0xEE, 0x1, 0xFF, 0x1, 0x0, 0x0, 0x0, 0xD, 0xE, 0xF, 0x0, 0x0, - 0xEE, 0x1, 0xFF, 0x1, 0x0, 0x0, 0x0, 0xD, 0xE, 0xF, 0x0, 0x0, 0xEE, - 0x1, 0xFF, 0x1, 0x0, 0x0, 0x0, 0xD, 0xE, 0xF, 0x0, 0x0, 0xEE, 0x1, - 0xFF, 0x1, 0x0, 0x0, 0x0, 0xD, 0xE, 0xF, 0x0, 0x0, 0xEE, 0x1, 0xFF, - 0x1, 0x0, 0x0, 0x0, 0xD, 0xE, 0xF, 0x0, 0x0, 0x0, 0x1, 0xFF, 0x1, 0x0, - 0x0, 0x0, 0x1, 0x0, 0x6, 0x0, 0x0, 0x0, 0x1, 0xFF, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, - 0x6, 0x0, 0x0, 0x0, 0x1, 0xFF, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x6, 0x0, 0x0 + { // 0 + .fillValue = 0xFF, + .fontId = 1, + .x = 0, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 1, + .fgColor = 1, + .bgColor = 15, + .shadowColor = 6, + }, + { // 1 + .fillValue = 0xFF, + .fontId = 1, + .x = 1, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 1, + .bgColor = 15, + .shadowColor = 6, + }, + { // 2 + .fillValue = 0xEE, + .fontId = 1, + .x = 0, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 3 + .fillValue = 0xEE, + .fontId = 7, + .x = 0, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 4 + .fillValue = 0xEE, + .fontId = 7, + .x = 0, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 5 + .fillValue = 0xEE, + .fontId = 7, + .x = 0, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 6 + .fillValue = 0xEE, + .fontId = 7, + .x = 0, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 7 + .fillValue = 0xEE, + .fontId = 7, + .x = 0, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 12, + .bgColor = 14, + .shadowColor = 11, + }, + { // 8 + .fillValue = 0xEE, + .fontId = 1, + .x = 0, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 9 + .fillValue = 0xEE, + .fontId = 1, + .x = 2, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 12, + .bgColor = 14, + .shadowColor = 11, + }, + { // 10 + .fillValue = 0xEE, + .fontId = 7, + .x = 0, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 11 + .fillValue = 0xEE, + .fontId = 7, + .x = 0, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 12 + .fillValue = 0xEE, + .fontId = 1, + .x = 0, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 13 + .fillValue = 0xEE, + .fontId = 1, + .x = 0, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 14 + .fillValue = 0x0, + .fontId = 1, + .x = 32, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 1, + .bgColor = 0, + .shadowColor = 2, + }, + { // 15 + .fillValue = 0xEE, + .fontId = 1, + .x = -1, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 16 + .fillValue = 0xEE, + .fontId = 1, + .x = -1, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 17 + .fillValue = 0xEE, + .fontId = 1, + .x = -1, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 18 + .fillValue = 0xEE, + .fontId = 1, + .x = -1, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 19 + .fillValue = 0xEE, + .fontId = 1, + .x = -1, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 20 + .fillValue = 0xEE, + .fontId = 1, + .x = -1, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 21 + .fillValue = 0x0, + .fontId = 1, + .x = -1, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 1, + .bgColor = 0, + .shadowColor = 6, + }, + { // 22 + .fillValue = 0x0, + .fontId = 1, + .x = -1, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 1, + .bgColor = 0, + .shadowColor = 6, + }, + { // 23 + .fillValue = 0x0, + .fontId = 1, + .x = -1, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 1, + .bgColor = 0, + .shadowColor = 6, + }, }; -static const u8 sUnknown_085CD54C[] = +static const struct BattleWindowText sTextOnWindowsInfo_Arena[] = { - 0xFF, 0x1, 0x0, 0x1, 0x0, 0x0, 0x1, 0x1, 0xF, 0x6, 0x0, 0x0, 0xFF, 0x1, - 0x1, 0x1, 0x0, 0x0, 0x0, 0x1, 0xF, 0x6, 0x0, 0x0, 0xEE, 0x1, 0x0, 0x1, 0x0, - 0x0, 0x0, 0xD, 0xE, 0xF, 0x0, 0x0, 0xEE, 0x7, 0x0, 0x1, 0x0, 0x0, 0x0, - 0xD, 0xE, 0xF, 0x0, 0x0, 0xEE, 0x7, 0x0, 0x1, 0x0, 0x0, 0x0, 0xD, - 0xE, 0xF, 0x0, 0x0, 0xEE, 0x7, 0x0, 0x1, 0x0, 0x0, 0x0, 0xD, 0xE, - 0xF, 0x0, 0x0, 0xEE, 0x7, 0x0, 0x1, 0x0, 0x0, 0x0, 0xD, 0xE, 0xF, - 0x0, 0x0, 0xEE, 0x7, 0x0, 0x1, 0x0, 0x0, 0x0, 0xC, 0xE, 0xB, 0x0, 0x0, - 0xEE, 0x1, 0x0, 0x1, 0x0, 0x0, 0x0, 0xD, 0xE, 0xF, 0x0, 0x0, 0xEE, - 0x1, 0x2, 0x1, 0x0, 0x0, 0x0, 0xC, 0xE, 0xB, 0x0, 0x0, 0xEE, 0x7, 0x0, - 0x1, 0x0, 0x0, 0x0, 0xD, 0xE, 0xF, 0x0, 0x0, 0xEE, 0x7, 0x0, 0x1, 0x0, - 0x0, 0x0, 0xD, 0xE, 0xF, 0x0, 0x0, 0xEE, 0x1, 0x0, 0x1, 0x0, 0x0, 0x0, - 0xD, 0xE, 0xF, 0x0, 0x0, 0xEE, 0x1, 0x0, 0x1, 0x0, 0x0, 0x0, 0xD, - 0xE, 0xF, 0x0, 0x0, 0x0, 0x1, 0x20, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x2, - 0x0, 0x0, 0xEE, 0x1, 0xFF, 0x1, 0x0, 0x0, 0x0, 0x1, 0xE, 0xF, 0x0, - 0x0, 0xEE, 0x1, 0xFF, 0x1, 0x0, 0x0, 0x0, 0xD, 0xE, 0xF, 0x0, 0x0, - 0xEE, 0x1, 0xFF, 0x1, 0x0, 0x0, 0x0, 0xD, 0xE, 0xF, 0x0, 0x0, 0xEE, - 0x1, 0xFF, 0x1, 0x0, 0x0, 0x0, 0xD, 0xE, 0xF, 0x0, 0x0, 0xEE, 0x1, - 0xFF, 0x1, 0x0, 0x0, 0x0, 0xD, 0xE, 0xF, 0x0, 0x0, 0xEE, 0x1, 0xFF, - 0x1, 0x0, 0x0, 0x0, 0xD, 0xE, 0xF, 0x0, 0x0, 0xEE, 0x1, 0xFF, 0x1, - 0x0, 0x0, 0x0, 0xD, 0xE, 0xF, 0x0, 0x0, 0x11, 0x1, 0x0, 0x1, 0x0, 0x0, - 0x1, 0x2, 0x1, 0x3, 0x0, 0x0 + { // 0 + .fillValue = 0xFF, + .fontId = 1, + .x = 0, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 1, + .fgColor = 1, + .bgColor = 15, + .shadowColor = 6, + }, + { // 1 + .fillValue = 0xFF, + .fontId = 1, + .x = 1, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 1, + .bgColor = 15, + .shadowColor = 6, + }, + { // 2 + .fillValue = 0xEE, + .fontId = 1, + .x = 0, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 3 + .fillValue = 0xEE, + .fontId = 7, + .x = 0, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 4 + .fillValue = 0xEE, + .fontId = 7, + .x = 0, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 5 + .fillValue = 0xEE, + .fontId = 7, + .x = 0, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 6 + .fillValue = 0xEE, + .fontId = 7, + .x = 0, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 7 + .fillValue = 0xEE, + .fontId = 7, + .x = 0, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 12, + .bgColor = 14, + .shadowColor = 11, + }, + { // 8 + .fillValue = 0xEE, + .fontId = 1, + .x = 0, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 9 + .fillValue = 0xEE, + .fontId = 1, + .x = 2, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 12, + .bgColor = 14, + .shadowColor = 11, + }, + { // 10 + .fillValue = 0xEE, + .fontId = 7, + .x = 0, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 11 + .fillValue = 0xEE, + .fontId = 7, + .x = 0, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 12 + .fillValue = 0xEE, + .fontId = 1, + .x = 0, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 13 + .fillValue = 0xEE, + .fontId = 1, + .x = 0, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 14 + .fillValue = 0x0, + .fontId = 1, + .x = 32, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 1, + .bgColor = 0, + .shadowColor = 2, + }, + { // 15 + .fillValue = 0xEE, + .fontId = 1, + .x = -1, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 1, + .bgColor = 14, + .shadowColor = 15, + }, + { // 16 + .fillValue = 0xEE, + .fontId = 1, + .x = -1, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 17 + .fillValue = 0xEE, + .fontId = 1, + .x = -1, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 18 + .fillValue = 0xEE, + .fontId = 1, + .x = -1, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 19 + .fillValue = 0xEE, + .fontId = 1, + .x = -1, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 20 + .fillValue = 0xEE, + .fontId = 1, + .x = -1, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 21 + .fillValue = 0xEE, + .fontId = 1, + .x = -1, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 0, + .fgColor = 13, + .bgColor = 14, + .shadowColor = 15, + }, + { // 22 + .fillValue = 0x11, + .fontId = 1, + .x = 0, + .y = 1, + .letterSpacing = 0, + .lineSpacing = 0, + .speed = 1, + .fgColor = 2, + .bgColor = 1, + .shadowColor = 3, + }, }; -static const u8 * const gUnknown_085CD660[] = +static const struct BattleWindowText *const sBattleTextOnWindowsInfo[] = { - sUnknown_085CD42C, sUnknown_085CD54C + sTextOnWindowsInfo_Normal, sTextOnWindowsInfo_Arena }; static const u8 sRecordedBattleTextSpeeds[] = {8, 4, 1, 0}; +// code void BufferStringBattle(u16 stringID) { s32 i; - const u8* stringPtr = NULL; + const u8 *stringPtr = NULL; gStringInfo = (struct StringInfoBattle*)(&gBattleBufferA[gActiveBattler][4]); gLastUsedItem = gStringInfo->lastItem; @@ -2395,47 +2932,46 @@ static void sub_814F950(u8* dst) } } -void BattleHandleAddTextPrinter(const u8 *text, u8 arg1) +void BattlePutTextOnWindow(const u8 *text, u8 windowId) { - const u8 *r8 = gUnknown_085CD660[gBattleScripting.field_24]; - bool32 r9; + const struct BattleWindowText *textInfo = sBattleTextOnWindowsInfo[gBattleScripting.windowsType]; + bool32 toVram; struct TextSubPrinter textSubPrinter; u8 speed; - if (arg1 & 0x80) + if (windowId & 0x80) { - arg1 &= ~(0x80); - r9 = FALSE; + windowId &= ~(0x80); + toVram = FALSE; } else { - FillWindowPixelBuffer(arg1, r8[12 * arg1]); - r9 = TRUE; + FillWindowPixelBuffer(windowId, textInfo[windowId].fillValue); + toVram = TRUE; } textSubPrinter.current_text_offset = text; - textSubPrinter.windowId = arg1; - textSubPrinter.fontId = r8[(12 * arg1) + 1]; - textSubPrinter.x = r8[(12 * arg1) + 2]; - textSubPrinter.y = r8[(12 * arg1) + 3]; + textSubPrinter.windowId = windowId; + textSubPrinter.fontId = textInfo[windowId].fontId; + textSubPrinter.x = textInfo[windowId].x; + textSubPrinter.y = textInfo[windowId].y; textSubPrinter.currentX = textSubPrinter.x; textSubPrinter.currentY = textSubPrinter.y; - textSubPrinter.letterSpacing = r8[(12 * arg1) + 4]; - textSubPrinter.lineSpacing = r8[(12 * arg1) + 5]; + textSubPrinter.letterSpacing = textInfo[windowId].letterSpacing; + textSubPrinter.lineSpacing = textInfo[windowId].lineSpacing; textSubPrinter.fontColor_l = 0; - textSubPrinter.fgColor = r8[(12 * arg1) + 7]; - textSubPrinter.bgColor = r8[(12 * arg1) + 8]; - textSubPrinter.shadowColor = r8[(12 * arg1) + 9]; + textSubPrinter.fgColor = textInfo[windowId].fgColor; + textSubPrinter.bgColor = textInfo[windowId].bgColor; + textSubPrinter.shadowColor = textInfo[windowId].shadowColor; if (textSubPrinter.x == 0xFF) { - s32 var2; - u32 var = sub_80397C4(gBattleScripting.field_24, arg1); - var2 = GetStringCenterAlignXOffsetWithLetterSpacing(textSubPrinter.fontId, textSubPrinter.current_text_offset, var, textSubPrinter.letterSpacing); - textSubPrinter.x = textSubPrinter.currentX = var2; + u32 width = sub_80397C4(gBattleScripting.windowsType, windowId); + s32 alignX = GetStringCenterAlignXOffsetWithLetterSpacing(textSubPrinter.fontId, textSubPrinter.current_text_offset, width, textSubPrinter.letterSpacing); + textSubPrinter.x = textSubPrinter.currentX = alignX; } - if (arg1 == 0x16) + if (windowId == 0x16) gTextFlags.flag_1 = 0; else gTextFlags.flag_1 = 1; @@ -2445,7 +2981,7 @@ void BattleHandleAddTextPrinter(const u8 *text, u8 arg1) else gTextFlags.flag_2 = 0; - if (arg1 == 0 || arg1 == 0x16) + if (windowId == 0 || windowId == 0x16) { if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000)) speed = 1; @@ -2458,16 +2994,16 @@ void BattleHandleAddTextPrinter(const u8 *text, u8 arg1) } else { - speed = r8[(12 * arg1) + 6]; + speed = textInfo[windowId].speed; gTextFlags.flag_0 = 0; } AddTextPrinter(&textSubPrinter, speed, NULL); - if (r9) + if (toVram) { - PutWindowTilemap(arg1); - CopyWindowToVram(arg1, 3); + PutWindowTilemap(windowId); + CopyWindowToVram(windowId, 3); } } diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 811aba128..c26e5ac11 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -5687,7 +5687,7 @@ static void atk5A_yesnoboxlearnmove(void) { case 0: HandleBattleWindow(0x18, 8, 0x1D, 0xD, 0); - BattleHandleAddTextPrinter(gText_BattleYesNoChoice, 0xC); + BattlePutTextOnWindow(gText_BattleYesNoChoice, 0xC); gBattleScripting.learnMoveState++; gBattleCommunication[CURSOR_POSITION] = 0; BattleCreateYesNoCursorAt(0); @@ -5804,7 +5804,7 @@ static void atk5B_yesnoboxstoplearningmove(void) { case 0: HandleBattleWindow(0x18, 8, 0x1D, 0xD, 0); - BattleHandleAddTextPrinter(gText_BattleYesNoChoice, 0xC); + BattlePutTextOnWindow(gText_BattleYesNoChoice, 0xC); gBattleScripting.learnMoveState++; gBattleCommunication[CURSOR_POSITION] = 0; BattleCreateYesNoCursorAt(0); @@ -6100,7 +6100,7 @@ static void atk67_yesnobox(void) { case 0: HandleBattleWindow(0x18, 8, 0x1D, 0xD, 0); - BattleHandleAddTextPrinter(gText_BattleYesNoChoice, 0xC); + BattlePutTextOnWindow(gText_BattleYesNoChoice, 0xC); gBattleCommunication[0]++; gBattleCommunication[CURSOR_POSITION] = 0; BattleCreateYesNoCursorAt(0); @@ -6720,7 +6720,7 @@ static void atk76_various(void) break; case 16: BattleStringExpandPlaceholdersToDisplayedString(gRefereeStringsTable[gBattlescriptCurrInstr[1]]); - BattleHandleAddTextPrinter(gDisplayedStringBattle, 0x16); + BattlePutTextOnWindow(gDisplayedStringBattle, 0x16); break; case 17: if (IsTextPrinterActive(0x16)) @@ -10406,7 +10406,7 @@ static void atkF3_trygivecaughtmonnick(void) { case 0: HandleBattleWindow(0x18, 8, 0x1D, 0xD, 0); - BattleHandleAddTextPrinter(gText_BattleYesNoChoice, 0xC); + BattlePutTextOnWindow(gText_BattleYesNoChoice, 0xC); gBattleCommunication[MULTIUSE_STATE]++; gBattleCommunication[CURSOR_POSITION] = 0; BattleCreateYesNoCursorAt(0); diff --git a/src/berry_blender.c b/src/berry_blender.c index 2edb14748..55431af72 100644 --- a/src/berry_blender.c +++ b/src/berry_blender.c @@ -153,8 +153,8 @@ extern const u8 gText_234Players[]; extern void sub_800A418(void); extern u8 sub_800A9D8(void); -extern void sub_809882C(u8, u16, u8); -extern void copy_textbox_border_tile_patterns_to_vram(u8, u16, u8); +extern void LoadSav2WindowGfx(u8, u16, u8); +extern void LoadMessageBoxGfx(u8, u16, u8); extern void sub_81AABF0(void (*callback)(void)); extern void sub_800B4C0(void); extern void ClearLinkCallback(void); @@ -927,8 +927,8 @@ static void sub_807FAC8(void) InitBgsFromTemplates(1, sBerryBlenderBgTemplates, ARRAY_COUNT(sBerryBlenderBgTemplates)); SetBgTilemapBuffer(1, sBerryBlenderData->tilemapBuffers[0]); SetBgTilemapBuffer(2, sBerryBlenderData->tilemapBuffers[1]); - sub_809882C(0, 1, 0xD0); - copy_textbox_border_tile_patterns_to_vram(0, 0x14, 0xF0); + LoadSav2WindowGfx(0, 1, 0xD0); + LoadMessageBoxGfx(0, 0x14, 0xF0); InitBerryBlenderWindows(); sBerryBlenderData->mainState++; @@ -1331,8 +1331,8 @@ static void sub_8080588(void) SetBgTilemapBuffer(1, sBerryBlenderData->tilemapBuffers[0]); SetBgTilemapBuffer(2, sBerryBlenderData->tilemapBuffers[1]); - sub_809882C(0, 1, 0xD0); - copy_textbox_border_tile_patterns_to_vram(0, 0x14, 0xF0); + LoadSav2WindowGfx(0, 1, 0xD0); + LoadMessageBoxGfx(0, 0x14, 0xF0); InitBerryBlenderWindows(); sBerryBlenderData->field_44 = 0; diff --git a/src/clear_save_data_screen.c b/src/clear_save_data_screen.c index ca2037d2f..266ea8250 100644 --- a/src/clear_save_data_screen.c +++ b/src/clear_save_data_screen.c @@ -202,6 +202,6 @@ static void InitClearSaveDataScreenWindows(void) InitWindows(sClearSaveTextWindow); DeactivateAllTextPrinters(); FillWindowPixelBuffer(0, 0); - sub_80987D4(0, 0, 2, 224); + LoadWindowGfx(0, 0, 2, 224); LoadPalette(gUnknown_0860F074, 0xF0, 0x20); } diff --git a/src/egg_hatch.c b/src/egg_hatch.c index 1ed38c67e..00e6236fe 100644 --- a/src/egg_hatch.c +++ b/src/egg_hatch.c @@ -655,7 +655,7 @@ static void CB2_EggHatch_1(void) case 9: if (!IsTextPrinterActive(sEggHatchData->windowId)) { - sub_809882C(sEggHatchData->windowId, 0x140, 0xE0); + LoadSav2WindowGfx(sEggHatchData->windowId, 0x140, 0xE0); CreateYesNoMenu(&sYesNoWinTemplate, 0x140, 0xE, 0); sEggHatchData->CB2_state++; } diff --git a/src/evolution_scene.c b/src/evolution_scene.c index 74eac32de..84f00418c 100644 --- a/src/evolution_scene.c +++ b/src/evolution_scene.c @@ -635,7 +635,7 @@ static void Task_EvolutionScene(u8 taskID) if (!gPaletteFade.active) { StringExpandPlaceholders(gStringVar4, gText_PkmnIsEvolving); - BattleHandleAddTextPrinter(gStringVar4, 0); + BattlePutTextOnWindow(gStringVar4, 0); gTasks[taskID].tState++; } break; @@ -731,7 +731,7 @@ static void Task_EvolutionScene(u8 taskID) if (IsCryFinished()) { StringExpandPlaceholders(gStringVar4, gText_CongratsPkmnEvolved); - BattleHandleAddTextPrinter(gStringVar4, 0); + BattlePutTextOnWindow(gStringVar4, 0); PlayBGM(MUS_FANFA5); gTasks[taskID].tState++; SetMonData(mon, MON_DATA_SPECIES, (void*)(&gTasks[taskID].tPostEvoSpecies)); @@ -818,7 +818,7 @@ static void Task_EvolutionScene(u8 taskID) else // Fire Red leftover probably StringExpandPlaceholders(gStringVar4, gText_PkmnStoppedEvolving); - BattleHandleAddTextPrinter(gStringVar4, 0); + BattlePutTextOnWindow(gStringVar4, 0); gTasks[taskID].tEvoWasStopped = TRUE; gTasks[taskID].tState = 15; } @@ -829,7 +829,7 @@ static void Task_EvolutionScene(u8 taskID) BufferMoveToLearnIntoBattleTextBuff2(); PlayFanfare(MUS_FANFA1); BattleStringExpandPlaceholdersToDisplayedString(gBattleStringsTable[STRINGID_PKMNLEARNEDMOVE - BATTLESTRINGS_ID_ADDER]); - BattleHandleAddTextPrinter(gDisplayedStringBattle, 0); + BattlePutTextOnWindow(gDisplayedStringBattle, 0); gTasks[taskID].tLearnsFirstMove = 0x40; // re-used as a counter gTasks[taskID].tState++; } @@ -846,7 +846,7 @@ static void Task_EvolutionScene(u8 taskID) { BufferMoveToLearnIntoBattleTextBuff2(); BattleStringExpandPlaceholdersToDisplayedString(gBattleStringsTable[STRINGID_TRYTOLEARNMOVE1 - BATTLESTRINGS_ID_ADDER]); - BattleHandleAddTextPrinter(gDisplayedStringBattle, 0); + BattlePutTextOnWindow(gDisplayedStringBattle, 0); gTasks[taskID].tLearnMoveState++; } break; @@ -854,7 +854,7 @@ static void Task_EvolutionScene(u8 taskID) if (!IsTextPrinterActive(0) && !IsSEPlaying()) { BattleStringExpandPlaceholdersToDisplayedString(gBattleStringsTable[STRINGID_TRYTOLEARNMOVE2 - BATTLESTRINGS_ID_ADDER]); - BattleHandleAddTextPrinter(gDisplayedStringBattle, 0); + BattlePutTextOnWindow(gDisplayedStringBattle, 0); gTasks[taskID].tLearnMoveState++; } break; @@ -862,7 +862,7 @@ static void Task_EvolutionScene(u8 taskID) if (!IsTextPrinterActive(0) && !IsSEPlaying()) { BattleStringExpandPlaceholdersToDisplayedString(gBattleStringsTable[STRINGID_TRYTOLEARNMOVE3 - BATTLESTRINGS_ID_ADDER]); - BattleHandleAddTextPrinter(gDisplayedStringBattle, 0); + BattlePutTextOnWindow(gDisplayedStringBattle, 0); gTasks[taskID].tData7 = 5; gTasks[taskID].tData8 = 10; gTasks[taskID].tLearnMoveState++; @@ -871,7 +871,7 @@ static void Task_EvolutionScene(u8 taskID) if (!IsTextPrinterActive(0) && !IsSEPlaying()) { HandleBattleWindow(0x18, 8, 0x1D, 0xD, 0); - BattleHandleAddTextPrinter(gText_BattleYesNoChoice, 0xC); + BattlePutTextOnWindow(gText_BattleYesNoChoice, 0xC); gTasks[taskID].tLearnMoveState++; sEvoCursorPos = 0; BattleCreateYesNoCursorAt(0); @@ -939,7 +939,7 @@ static void Task_EvolutionScene(u8 taskID) if (IsHMMove2(move)) { BattleStringExpandPlaceholdersToDisplayedString(gBattleStringsTable[STRINGID_HMMOVESCANTBEFORGOTTEN - BATTLESTRINGS_ID_ADDER]); - BattleHandleAddTextPrinter(gDisplayedStringBattle, 0); + BattlePutTextOnWindow(gDisplayedStringBattle, 0); gTasks[taskID].tLearnMoveState = 12; } else @@ -955,14 +955,14 @@ static void Task_EvolutionScene(u8 taskID) break; case 7: BattleStringExpandPlaceholdersToDisplayedString(gBattleStringsTable[STRINGID_123POOF - BATTLESTRINGS_ID_ADDER]); - BattleHandleAddTextPrinter(gDisplayedStringBattle, 0); + BattlePutTextOnWindow(gDisplayedStringBattle, 0); gTasks[taskID].tLearnMoveState++; break; case 8: if (!IsTextPrinterActive(0) && !IsSEPlaying()) { BattleStringExpandPlaceholdersToDisplayedString(gBattleStringsTable[STRINGID_PKMNFORGOTMOVE - BATTLESTRINGS_ID_ADDER]); - BattleHandleAddTextPrinter(gDisplayedStringBattle, 0); + BattlePutTextOnWindow(gDisplayedStringBattle, 0); gTasks[taskID].tLearnMoveState++; } break; @@ -970,20 +970,20 @@ static void Task_EvolutionScene(u8 taskID) if (!IsTextPrinterActive(0) && !IsSEPlaying()) { BattleStringExpandPlaceholdersToDisplayedString(gBattleStringsTable[STRINGID_ANDELLIPSIS - BATTLESTRINGS_ID_ADDER]); - BattleHandleAddTextPrinter(gDisplayedStringBattle, 0); + BattlePutTextOnWindow(gDisplayedStringBattle, 0); gTasks[taskID].tState = 20; } break; case 10: BattleStringExpandPlaceholdersToDisplayedString(gBattleStringsTable[STRINGID_STOPLEARNINGMOVE - BATTLESTRINGS_ID_ADDER]); - BattleHandleAddTextPrinter(gDisplayedStringBattle, 0); + BattlePutTextOnWindow(gDisplayedStringBattle, 0); gTasks[taskID].tData7 = 11; gTasks[taskID].tData8 = 0; gTasks[taskID].tLearnMoveState = 3; break; case 11: BattleStringExpandPlaceholdersToDisplayedString(gBattleStringsTable[STRINGID_DIDNOTLEARNMOVE - BATTLESTRINGS_ID_ADDER]); - BattleHandleAddTextPrinter(gDisplayedStringBattle, 0); + BattlePutTextOnWindow(gDisplayedStringBattle, 0); gTasks[taskID].tState = 15; break; case 12: @@ -1215,7 +1215,7 @@ static void Task_TradeEvolutionScene(u8 taskID) case 3: if (!IsTextPrinterActive(0) && !IsSEPlaying()) { - sub_809882C(0, 0xA8, 0xE0); + LoadSav2WindowGfx(0, 0xA8, 0xE0); CreateYesNoMenu(&gUnknown_0833900C, 0xA8, 0xE, 0); sEvoCursorPos = 0; gTasks[taskID].tLearnMoveState++; diff --git a/src/field_region_map.c b/src/field_region_map.c index b7d677c90..1edf1ab51 100644 --- a/src/field_region_map.c +++ b/src/field_region_map.c @@ -89,7 +89,7 @@ static void MCB2_InitRegionMapRegisters(void) InitBgsFromTemplates(1, gUnknown_085E5068, 2); InitWindows(gUnknown_085E5070); DeactivateAllTextPrinters(); - sub_809882C(0, 0x27, 0xd0); + LoadSav2WindowGfx(0, 0x27, 0xd0); clear_scheduled_bg_copies_to_vram(); SetMainCallback2(MCB2_FieldUpdateRegionMap); SetVBlankCallback(VBCB_FieldUpdateRegionMap); diff --git a/src/hall_of_fame.c b/src/hall_of_fame.c index 83df30d05..b0388e971 100644 --- a/src/hall_of_fame.c +++ b/src/hall_of_fame.c @@ -89,7 +89,7 @@ extern void sub_8197434(u8, u8); extern u16 sub_818D97C(u8 playerGender, u8); extern u16 sub_818D8AC(u16, u8, s16, s16, u8, u16); extern const void* stdpal_get(u8); -extern void sub_80987D4(u8, u8, u16, u8); +extern void LoadWindowGfx(u8, u8, u16, u8); extern u16 sub_818D820(u16); extern u16 sub_818D8F0(u16); extern u16 sub_818D7D8(u16 species, u32 trainerId, u32 personality, u8 arg3, s16 sp0, s16 sp1, u8 sp2, u16 sp3); @@ -725,7 +725,7 @@ static void sub_8173EE4(u8 taskId) ShowBg(3); gTasks[taskId].tPlayerSpriteID = sub_818D8AC(sub_818D97C(gSaveBlock2Ptr->playerGender, 1), 1, 120, 72, 6, 0xFFFF); AddWindow(&sHof_WindowTemplate); - sub_80987D4(1, gSaveBlock2Ptr->optionsWindowFrameType, 0x21D, 0xD0); + LoadWindowGfx(1, gSaveBlock2Ptr->optionsWindowFrameType, 0x21D, 0xD0); LoadPalette(stdpal_get(1), 0xE0, 0x20); gTasks[taskId].tFrameCount = 120; gTasks[taskId].func = Task_Hof_WaitAndPrintPlayerInfo; diff --git a/src/item_menu.c b/src/item_menu.c index 0642c771e..5a0929a7c 100755 --- a/src/item_menu.c +++ b/src/item_menu.c @@ -2103,8 +2103,8 @@ void setup_bag_menu_textboxes(void) InitWindows(gUnknown_08614174); DeactivateAllTextPrinters(); - sub_809882C(0, 1, -32); - copy_textbox_border_tile_patterns_to_vram(0, 10, -48); + LoadSav2WindowGfx(0, 1, -32); + LoadMessageBoxGfx(0, 10, -48); sub_819A2BC(-64, 1); LoadPalette(&gUnknown_0860F074, 0xF0, 0x20); for (i = 0; i < 3; i++) diff --git a/src/list_menu.c b/src/list_menu.c index de7de8269..d4a8976a5 100644 --- a/src/list_menu.c +++ b/src/list_menu.c @@ -337,7 +337,7 @@ s32 DoMysteryGiftListMenu(struct WindowTemplate *windowTemplate, struct ListMenu switch (arg2) { case 2: - sub_809882C(gUnknown_0203CE84.field_5, tileNum, palNum); + LoadSav2WindowGfx(gUnknown_0203CE84.field_5, tileNum, palNum); case 1: sub_8098858(gUnknown_0203CE84.field_5, tileNum, palNum / 16); break; diff --git a/src/main_menu.c b/src/main_menu.c index 3490424af..0f703a014 100644 --- a/src/main_menu.c +++ b/src/main_menu.c @@ -1038,7 +1038,7 @@ void task_new_game_prof_birch_speech_3(u8 taskId) { InitWindows(gUnknown_082FF080); LoadMainMenuWindowFrameTiles(0, 0xF3); - copy_textbox_border_tile_patterns_to_vram(0, 0xFC, 0xF0); + LoadMessageBoxGfx(0, 0xFC, 0xF0); unknown_rbox_to_vram(0, 1); PutWindowTilemap(0); CopyWindowToVram(0, 2); @@ -1565,7 +1565,7 @@ void new_game_prof_birch_speech_part2_start(void) SetMainCallback2(CB2_MainMenu); InitWindows(gUnknown_082FF080); LoadMainMenuWindowFrameTiles(0, 0xF3); - copy_textbox_border_tile_patterns_to_vram(0, 0xFC, 0xF0); + LoadMessageBoxGfx(0, 0xFC, 0xF0); PutWindowTilemap(0); CopyWindowToVram(0, 3); } diff --git a/src/menu.c b/src/menu.c index dedfcc3be..79c70e619 100644 --- a/src/menu.c +++ b/src/menu.c @@ -193,8 +193,8 @@ void AddTextPrinterWithCustomSpeedForMessage(bool8 allowSkippingDelayWithButtonP void sub_81973A4(void) { - copy_textbox_border_tile_patterns_to_vram(0, DLG_WINDOW_BASE_TILE_NUM, DLG_WINDOW_PALETTE_NUM * 0x10); - sub_809882C(0, STD_WINDOW_BASE_TILE_NUM, STD_WINDOW_PALETTE_NUM * 0x10); + LoadMessageBoxGfx(0, DLG_WINDOW_BASE_TILE_NUM, DLG_WINDOW_PALETTE_NUM * 0x10); + LoadSav2WindowGfx(0, STD_WINDOW_BASE_TILE_NUM, STD_WINDOW_PALETTE_NUM * 0x10); } void NewMenuHelpers_DrawDialogueFrame(u8 windowId, bool8 copyToVram) @@ -412,7 +412,7 @@ void SetStandardWindowBorderStyle(u8 windowId, bool8 copyToVram) void sub_819786C(u8 windowId, bool8 copyToVram) { - copy_textbox_border_tile_patterns_to_vram(windowId, DLG_WINDOW_BASE_TILE_NUM, DLG_WINDOW_PALETTE_NUM * 0x10); + LoadMessageBoxGfx(windowId, DLG_WINDOW_BASE_TILE_NUM, DLG_WINDOW_PALETTE_NUM * 0x10); sub_8197B1C(windowId, copyToVram, DLG_WINDOW_BASE_TILE_NUM, 0xF); } diff --git a/src/mystery_event_menu.c b/src/mystery_event_menu.c index 8a7671c5b..c7247b696 100644 --- a/src/mystery_event_menu.c +++ b/src/mystery_event_menu.c @@ -77,7 +77,7 @@ void CB2_InitMysteryEventMenu(void) FillWindowPixelBuffer(i, 0); FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 0x1E, 0x14); - sub_809882C(0, 1u, 0xD0u); + LoadSav2WindowGfx(0, 1u, 0xD0u); sub_81978B0(0xE0); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG0_ON); SetGpuReg(REG_OFFSET_BLDCNT, 0); diff --git a/src/pokeblock.c b/src/pokeblock.c index 216c9e2c5..518acd792 100644 --- a/src/pokeblock.c +++ b/src/pokeblock.c @@ -75,8 +75,8 @@ extern const u16 gUnknown_0860F074[]; extern void CB2_ReturnToField(void); extern bool8 sub_81221EC(void); -extern void sub_809882C(u8, u16, u8); -extern void copy_textbox_border_tile_patterns_to_vram(u8, u16, u8); +extern void LoadSav2WindowGfx(u8, u16, u8); +extern void LoadMessageBoxGfx(u8, u16, u8); extern void sub_80AF168(void); // this file's functions @@ -566,8 +566,8 @@ static void HandleInitWindows(void) InitWindows(sWindowTemplatesForPokeblockMenu); DeactivateAllTextPrinters(); - sub_809882C(0, 1, 0xE0); - copy_textbox_border_tile_patterns_to_vram(0, 0xA, 0xD0); + LoadSav2WindowGfx(0, 1, 0xE0); + LoadMessageBoxGfx(0, 0xA, 0xD0); LoadPalette(gUnknown_0860F074, 0xF0, 0x20); for (i = 0; i < ARRAY_COUNT(sWindowTemplatesForPokeblockMenu) - 1; i++) diff --git a/src/pokeblock_feed.c b/src/pokeblock_feed.c index db92d56a8..d3fdbd355 100644 --- a/src/pokeblock_feed.c +++ b/src/pokeblock_feed.c @@ -59,7 +59,7 @@ extern const u16 gUnknown_0860F074[]; extern bool8 sub_81221EC(void); extern void sub_806A068(u16, u8); -extern void sub_809882C(u8, u16, u8); +extern void LoadSav2WindowGfx(u8, u16, u8); // this file's functions static void HandleInitBackgrounds(void); @@ -706,7 +706,7 @@ static void HandleInitWindows(void) { InitWindows(sWindowTemplates); DeactivateAllTextPrinters(); - sub_809882C(0, 1, 0xE0); + LoadSav2WindowGfx(0, 1, 0xE0); LoadPalette(gUnknown_0860F074, 0xF0, 0x20); FillWindowPixelBuffer(0, 0); PutWindowTilemap(0); diff --git a/src/region_map.c b/src/region_map.c index f16787fc9..0a6c08234 100644 --- a/src/region_map.c +++ b/src/region_map.c @@ -1603,7 +1603,7 @@ void MCB2_FlyMap(void) gMain.state++; break; case 3: - sub_809882C(0, 0x65, 0xd0); + LoadSav2WindowGfx(0, 0x65, 0xd0); clear_scheduled_bg_copies_to_vram(); gMain.state++; break; diff --git a/src/reshow_battle_screen.c b/src/reshow_battle_screen.c index 45f0f5a9e..4456e450c 100644 --- a/src/reshow_battle_screen.c +++ b/src/reshow_battle_screen.c @@ -58,7 +58,7 @@ static void CB2_ReshowBattleScreenAfterMenu(void) { case 0: ScanlineEffect_Clear(); - sub_8035658(); + BattleInitBgsAndWindows(); SetBgAttribute(1, BG_CTRL_ATTR_VISIBLE, 0); SetBgAttribute(2, BG_CTRL_ATTR_VISIBLE, 0); ShowBg(0); diff --git a/src/scrcmd.c b/src/scrcmd.c index 4e3fceb10..a09e911f0 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -1517,7 +1517,7 @@ bool8 ScrCmd_braillemessage(struct ScriptContext *ctx) winTemplate = sub_8198A50(0, xWindow, yWindow + 1, width, height, 0xF, 0x1); gUnknown_03000F30 = AddWindow(&winTemplate); - sub_809882C(gUnknown_03000F30, 0x214, 0xE0); + LoadSav2WindowGfx(gUnknown_03000F30, 0x214, 0xE0); NewMenuHelpers_DrawStdWindowFrame(gUnknown_03000F30, 0); PutWindowTilemap(gUnknown_03000F30); FillWindowPixelBuffer(gUnknown_03000F30, 0x11); diff --git a/src/start_menu.c b/src/start_menu.c index 7080ae6a8..43b4f85f2 100644 --- a/src/start_menu.c +++ b/src/start_menu.c @@ -1212,7 +1212,7 @@ static bool32 sub_80A03E4(u8 *par1) ResetBgsAndClearDma3BusyFlags(0); InitBgsFromTemplates(0, sUnknown_085105A8, ARRAY_COUNT(sUnknown_085105A8)); InitWindows(sUnknown_085105AC); - box_border_load_tiles_and_pal(0, 8, 224); + LoadSav2WindowGfx_(0, 8, 224); sub_81978B0(240); break; case 3: diff --git a/src/starter_choose.c b/src/starter_choose.c index 480edbcb7..b2160a5a6 100644 --- a/src/starter_choose.c +++ b/src/starter_choose.c @@ -46,7 +46,7 @@ extern const u8 gStarterChoose_LabelCoords[][2]; extern const u8 gUnknown_085B1E0C[]; extern const u8 gUnknown_085B1E28[][2]; -extern void sub_809882C(u8, u16, u8); +extern void LoadSav2WindowGfx(u8, u16, u8); extern void ScanlineEffect_Stop(void); extern void clear_scheduled_bg_copies_to_vram(void); extern void dp13_810BB8C(void); @@ -126,7 +126,7 @@ void CB2_ChooseStarter(void) InitWindows(gUnknown_085B1DCC); DeactivateAllTextPrinters(); - sub_809882C(0, 0x2A8, 0xD0); + LoadSav2WindowGfx(0, 0x2A8, 0xD0); clear_scheduled_bg_copies_to_vram(); ScanlineEffect_Stop(); ResetTasks(); diff --git a/src/text_window.c b/src/text_window.c index c3b9f7197..35afc2004 100644 --- a/src/text_window.c +++ b/src/text_window.c @@ -91,26 +91,26 @@ const struct TilesPal *GetWindowFrameTilesPal(u8 id) return &sWindowFrames[id]; } -void copy_textbox_border_tile_patterns_to_vram(u8 windowId, u16 destOffset, u8 palOffset) +void LoadMessageBoxGfx(u8 windowId, u16 destOffset, u8 palOffset) { LoadBgTiles(GetWindowAttribute(windowId, WINDOW_PRIORITY), gMessageBox_Gfx, 0x1C0, destOffset); LoadPalette(GetOverworldTextboxPalettePtr(), palOffset, 0x20); } -void box_border_load_tiles_and_pal(u8 windowId, u16 destOffset, u8 palOffset) +void LoadSav2WindowGfx_(u8 windowId, u16 destOffset, u8 palOffset) { - sub_809882C(windowId, destOffset, palOffset); + LoadSav2WindowGfx(windowId, destOffset, palOffset); } -void sub_80987D4(u8 windowId, u8 frameId, u16 destOffset, u8 palOffset) +void LoadWindowGfx(u8 windowId, u8 frameId, u16 destOffset, u8 palOffset) { LoadBgTiles(GetWindowAttribute(windowId, WINDOW_PRIORITY), sWindowFrames[frameId].tiles, 0x120, destOffset); LoadPalette(sWindowFrames[frameId].pal, palOffset, 0x20); } -void sub_809882C(u8 windowId, u16 destOffset, u8 palOffset) +void LoadSav2WindowGfx(u8 windowId, u16 destOffset, u8 palOffset) { - sub_80987D4(windowId, gSaveBlock2Ptr->optionsWindowFrameType, destOffset, palOffset); + LoadWindowGfx(windowId, gSaveBlock2Ptr->optionsWindowFrameType, destOffset, palOffset); } void sub_8098858(u8 windowId, u16 tileNum, u8 palNum) diff --git a/src/use_pokeblock.c b/src/use_pokeblock.c index c8898d08f..1fb4c411f 100644 --- a/src/use_pokeblock.c +++ b/src/use_pokeblock.c @@ -164,7 +164,7 @@ void sub_8166380(void) InitBgsFromTemplates(0, gUnknown_085DFCCC, ARRAY_COUNT(gUnknown_085DFCCC)); InitWindows(gUnknown_085DFCDC); DeactivateAllTextPrinters(); - sub_809882C(0, 0x97, 0xE0); + LoadSav2WindowGfx(0, 0x97, 0xE0); gUnknown_0203BC90->field_50++; break; case 4: diff --git a/src/wallclock.c b/src/wallclock.c index f15bbbc27..80383c26d 100644 --- a/src/wallclock.c +++ b/src/wallclock.c @@ -576,7 +576,7 @@ static void LoadWallClockGraphics(void) InitBgsFromTemplates(0, gUnknown_085B21FC, 3); InitWindows(gUnknown_085B21DC); DeactivateAllTextPrinters(); - sub_809882C(0, 0x250, 0xd0); + LoadSav2WindowGfx(0, 0x250, 0xd0); clear_scheduled_bg_copies_to_vram(); ScanlineEffect_Stop(); ResetTasks();