From caa36b530a93dc51727822abf6c4c31fa8cbaf63 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 17 Jun 2018 16:48:58 +0200 Subject: [PATCH 01/15] label and document battle windows --- asm/battle_frontier_2.s | 16 +- asm/easy_chat.s | 2 +- asm/party_menu.s | 2 +- asm/pokemon_storage_system.s | 4 +- asm/pokemon_summary_screen.s | 4 +- asm/pokenav.s | 6 +- asm/rom_8011DC0.s | 24 +- asm/shop.s | 4 +- asm/slot_machine.s | 4 +- asm/trade.s | 4 +- data/data2b.s | 4 +- include/battle.h | 2 +- include/battle_ai_script_commands.h | 15 +- include/battle_bg.h | 6 +- include/battle_message.h | 2 +- include/battle_util.h | 8 +- include/text_window.h | 8 +- src/battle_ai_script_commands.c | 705 +++++++++++----------- src/battle_ai_switch_items.c | 263 ++++---- src/battle_anim.c | 117 ++-- src/battle_anim_sound_tasks.c | 12 +- src/battle_bg.c | 100 +-- src/battle_controller_link_opponent.c | 2 +- src/battle_controller_link_partner.c | 2 +- src/battle_controller_opponent.c | 2 +- src/battle_controller_player.c | 20 +- src/battle_controller_player_partner.c | 2 +- src/battle_controller_recorded_opponent.c | 2 +- src/battle_controller_recorded_player.c | 2 +- src/battle_controller_safari.c | 6 +- src/battle_controller_wally.c | 6 +- src/battle_main.c | 46 +- src/battle_message.c | 684 ++++++++++++++++++--- src/battle_script_commands.c | 10 +- src/berry_blender.c | 12 +- src/clear_save_data_screen.c | 2 +- src/egg_hatch.c | 2 +- src/evolution_scene.c | 30 +- src/field_region_map.c | 2 +- src/hall_of_fame.c | 4 +- src/item_menu.c | 4 +- src/list_menu.c | 2 +- src/main_menu.c | 4 +- src/menu.c | 6 +- src/mystery_event_menu.c | 2 +- src/pokeblock.c | 8 +- src/pokeblock_feed.c | 4 +- src/region_map.c | 2 +- src/reshow_battle_screen.c | 2 +- src/scrcmd.c | 2 +- src/start_menu.c | 2 +- src/starter_choose.c | 4 +- src/text_window.c | 12 +- src/use_pokeblock.c | 2 +- src/wallclock.c | 2 +- 55 files changed, 1361 insertions(+), 845 deletions(-) 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(); From 94752d420769dfc205b3f717c660f33a6eb2b6fb Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Tue, 19 Jun 2018 00:43:15 +0200 Subject: [PATCH 02/15] document battle bars --- include/battle.h | 4 +- include/battle_gfx_sfx_util.h | 4 +- include/battle_interface.h | 8 +- src/battle_controller_link_opponent.c | 2 +- src/battle_controller_link_partner.c | 2 +- src/battle_controller_opponent.c | 2 +- src/battle_controller_player.c | 4 +- src/battle_controller_player_partner.c | 4 +- src/battle_controller_recorded_opponent.c | 2 +- src/battle_controller_recorded_player.c | 2 +- src/battle_controller_wally.c | 2 +- src/battle_controllers.c | 2 +- src/battle_gfx_sfx_util.c | 130 ++-- src/battle_interface.c | 740 +++++++++++----------- src/pokeball.c | 6 +- 15 files changed, 468 insertions(+), 446 deletions(-) diff --git a/include/battle.h b/include/battle.h index bf875ad9d..62caa2cfe 100644 --- a/include/battle.h +++ b/include/battle.h @@ -692,9 +692,9 @@ struct BattleBarInfo { u8 healthboxSpriteId; s32 maxValue; - s32 currentValue; + s32 oldValue; s32 receivedValue; - s32 field_10; + s32 currValue; }; struct BattleSpriteData diff --git a/include/battle_gfx_sfx_util.h b/include/battle_gfx_sfx_util.h index e1c6325b6..16253e760 100644 --- a/include/battle_gfx_sfx_util.h +++ b/include/battle_gfx_sfx_util.h @@ -35,7 +35,7 @@ void ClearBehindSubstituteBit(u8 battlerId); void HandleLowHpMusicChange(struct Pokemon *mon, u8 battlerId); void BattleStopLowHpSound(void); u8 GetMonHPBarLevel(struct Pokemon *mon); -void sub_805EAE8(void); +void HandleBattleLowHpMusicChange(void); void sub_805EB9C(u8 affineMode); void LoadAndCreateEnemyShadowSprites(void); void SpriteCB_SetInvisible(struct Sprite *sprite); @@ -45,6 +45,6 @@ void sub_805EF14(void); void ClearTemporarySpeciesSpriteData(u8 battlerId, bool8 dontClearSubstitute); void AllocateMonSpritesGfx(void); void FreeMonSpritesGfx(void); -bool32 ShouldPlayNormalPokeCry(struct Pokemon *mon); +bool32 ShouldPlayNormalMonCry(struct Pokemon *mon); #endif // GUARD_BATTLE_GFX_SFX_UTIL diff --git a/include/battle_interface.h b/include/battle_interface.h index fe8c03f70..b917d2cb3 100644 --- a/include/battle_interface.h +++ b/include/battle_interface.h @@ -29,12 +29,18 @@ enum #define TAG_HEALTHBOX_OPPONENT1_TILE 0xD701 #define TAG_HEALTHBOX_OPPONENT2_TILE 0xD702 +#define TAG_HEALTHBAR_PLAYER1_TILE 0xD704 +#define TAG_HEALTHBAR_OPPONENT1_TILE 0xD705 +#define TAG_HEALTHBAR_PLAYER2_TILE 0xD706 +#define TAG_HEALTHBAR_OPPONENT2_TILE 0xD707 + #define TAG_HEALTHBOX_SAFARI_TILE 0xD70B #define TAG_STATUS_SUMMARY_BAR_TILE 0xD70C #define TAG_STATUS_SUMMARY_BALLS_TILE 0xD714 #define TAG_HEALTHBOX_PAL 0xD6FF +#define TAG_HEALTHBAR_PAL 0xD704 #define TAG_STATUS_SUMMARY_BAR_PAL 0xD710 #define TAG_STATUS_SUMMARY_BALLS_PAL 0xD712 @@ -68,7 +74,7 @@ void SwapHpBarsWithHpText(void); u8 CreatePartyStatusSummarySprites(u8 bank, struct HpAndStatus *partyInfo, u8 arg2, bool8 isBattleStart); void sub_8073C30(u8 taskId); void UpdateHealthboxAttribute(u8 healthboxSpriteId, struct Pokemon *mon, u8 elementId); -s32 sub_8074AA0(u8 bank, u8 healthboxSpriteId, u8 whichBar, u8 arg3); +s32 MoveBattleBar(u8 bank, u8 healthboxSpriteId, u8 whichBar, u8 arg3); u8 GetScaledHPFraction(s16 hp, s16 maxhp, u8 scale); u8 GetHPBarLevel(s16 hp, s16 maxhp); diff --git a/src/battle_controller_link_opponent.c b/src/battle_controller_link_opponent.c index 905e957ea..b2c05664b 100644 --- a/src/battle_controller_link_opponent.c +++ b/src/battle_controller_link_opponent.c @@ -395,7 +395,7 @@ static void sub_8064B04(void) static void CompleteOnHealthbarDone(void) { - s16 hpValue = sub_8074AA0(gActiveBattler, gHealthboxSpriteIds[gActiveBattler], HEALTH_BAR, 0); + s16 hpValue = MoveBattleBar(gActiveBattler, gHealthboxSpriteIds[gActiveBattler], HEALTH_BAR, 0); SetHealthboxSpriteVisible(gHealthboxSpriteIds[gActiveBattler]); diff --git a/src/battle_controller_link_partner.c b/src/battle_controller_link_partner.c index 3178bad0e..f7abe589a 100644 --- a/src/battle_controller_link_partner.c +++ b/src/battle_controller_link_partner.c @@ -279,7 +279,7 @@ static void sub_814B290(void) static void CompleteOnHealthbarDone(void) { - s16 hpValue = sub_8074AA0(gActiveBattler, gHealthboxSpriteIds[gActiveBattler], HEALTH_BAR, 0); + s16 hpValue = MoveBattleBar(gActiveBattler, gHealthboxSpriteIds[gActiveBattler], HEALTH_BAR, 0); SetHealthboxSpriteVisible(gHealthboxSpriteIds[gActiveBattler]); diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index ae407af24..21b45dabf 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -391,7 +391,7 @@ static void sub_805F994(void) static void CompleteOnHealthbarDone(void) { - s16 hpValue = sub_8074AA0(gActiveBattler, gHealthboxSpriteIds[gActiveBattler], HEALTH_BAR, 0); + s16 hpValue = MoveBattleBar(gActiveBattler, gHealthboxSpriteIds[gActiveBattler], HEALTH_BAR, 0); SetHealthboxSpriteVisible(gHealthboxSpriteIds[gActiveBattler]); if (hpValue != -1) { diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index 627b13e22..599ebfee4 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -1120,7 +1120,7 @@ void c3_0802FDF4(u8 taskId) static void CompleteOnHealthbarDone(void) { - s16 hpValue = sub_8074AA0(gActiveBattler, gHealthboxSpriteIds[gActiveBattler], HEALTH_BAR, 0); + s16 hpValue = MoveBattleBar(gActiveBattler, gHealthboxSpriteIds[gActiveBattler], HEALTH_BAR, 0); SetHealthboxSpriteVisible(gHealthboxSpriteIds[gActiveBattler]); @@ -1224,7 +1224,7 @@ static void sub_8059400(u8 taskId) u8 battlerId = gTasks[taskId].tExpTask_bank; s16 r4; - r4 = sub_8074AA0(battlerId, gHealthboxSpriteIds[battlerId], EXP_BAR, 0); + r4 = MoveBattleBar(battlerId, gHealthboxSpriteIds[battlerId], EXP_BAR, 0); SetHealthboxSpriteVisible(gHealthboxSpriteIds[battlerId]); if (r4 == -1) { diff --git a/src/battle_controller_player_partner.c b/src/battle_controller_player_partner.c index 25eef4c5c..df075522e 100644 --- a/src/battle_controller_player_partner.c +++ b/src/battle_controller_player_partner.c @@ -294,7 +294,7 @@ static void sub_81BB1D4(void) static void CompleteOnHealthbarDone(void) { - s16 hpValue = sub_8074AA0(gActiveBattler, gHealthboxSpriteIds[gActiveBattler], HEALTH_BAR, 0); + s16 hpValue = MoveBattleBar(gActiveBattler, gHealthboxSpriteIds[gActiveBattler], HEALTH_BAR, 0); SetHealthboxSpriteVisible(gHealthboxSpriteIds[gActiveBattler]); @@ -399,7 +399,7 @@ static void sub_81BB4E4(u8 taskId) u8 battlerId = gTasks[taskId].tExpTask_bank; s16 r4; - r4 = sub_8074AA0(battlerId, gHealthboxSpriteIds[battlerId], EXP_BAR, 0); + r4 = MoveBattleBar(battlerId, gHealthboxSpriteIds[battlerId], EXP_BAR, 0); SetHealthboxSpriteVisible(gHealthboxSpriteIds[battlerId]); if (r4 == -1) { diff --git a/src/battle_controller_recorded_opponent.c b/src/battle_controller_recorded_opponent.c index b4bdfaa4e..69f93d7e2 100644 --- a/src/battle_controller_recorded_opponent.c +++ b/src/battle_controller_recorded_opponent.c @@ -377,7 +377,7 @@ static void sub_8186C48(void) static void CompleteOnHealthbarDone(void) { - s16 hpValue = sub_8074AA0(gActiveBattler, gHealthboxSpriteIds[gActiveBattler], HEALTH_BAR, 0); + s16 hpValue = MoveBattleBar(gActiveBattler, gHealthboxSpriteIds[gActiveBattler], HEALTH_BAR, 0); SetHealthboxSpriteVisible(gHealthboxSpriteIds[gActiveBattler]); diff --git a/src/battle_controller_recorded_player.c b/src/battle_controller_recorded_player.c index 24cb58ea4..54ca4578b 100644 --- a/src/battle_controller_recorded_player.c +++ b/src/battle_controller_recorded_player.c @@ -363,7 +363,7 @@ static void sub_818A064(void) static void CompleteOnHealthbarDone(void) { - s16 hpValue = sub_8074AA0(gActiveBattler, gHealthboxSpriteIds[gActiveBattler], HEALTH_BAR, 0); + s16 hpValue = MoveBattleBar(gActiveBattler, gHealthboxSpriteIds[gActiveBattler], HEALTH_BAR, 0); SetHealthboxSpriteVisible(gHealthboxSpriteIds[gActiveBattler]); diff --git a/src/battle_controller_wally.c b/src/battle_controller_wally.c index e8efb404f..955799ee3 100644 --- a/src/battle_controller_wally.c +++ b/src/battle_controller_wally.c @@ -349,7 +349,7 @@ static void sub_8168818(void) static void CompleteOnHealthbarDone(void) { - s16 hpValue = sub_8074AA0(gActiveBattler, gHealthboxSpriteIds[gActiveBattler], HEALTH_BAR, 0); + s16 hpValue = MoveBattleBar(gActiveBattler, gHealthboxSpriteIds[gActiveBattler], HEALTH_BAR, 0); SetHealthboxSpriteVisible(gHealthboxSpriteIds[gActiveBattler]); diff --git a/src/battle_controllers.c b/src/battle_controllers.c index 2b918d018..8a7ff7b5d 100644 --- a/src/battle_controllers.c +++ b/src/battle_controllers.c @@ -587,7 +587,7 @@ static void SetBattlePartyIds(void) { for (i = 0; i < gBattlersCount; i++) { - for (j = 0; j < 6; j++) + for (j = 0; j < PARTY_SIZE; j++) { if (i < 2) { diff --git a/src/battle_gfx_sfx_util.c b/src/battle_gfx_sfx_util.c index d2c242553..47af1b9dd 100644 --- a/src/battle_gfx_sfx_util.c +++ b/src/battle_gfx_sfx_util.c @@ -67,7 +67,7 @@ static void sub_805D7EC(struct Sprite *sprite); static bool8 ShouldAnimBeDoneRegardlessOfSubsitute(u8 animId); static void Task_ClearBitWhenBattleTableAnimDone(u8 taskId); static void Task_ClearBitWhenSpecialAnimDone(u8 taskId); -static void ClearSpritesBankHealthboxAnimData(void); +static void ClearSpritesBattlerHealthboxAnimData(void); // const rom data static const struct CompressedSpriteSheet gUnknown_0832C0D0 = @@ -411,35 +411,35 @@ void InitAndLaunchChosenStatusAnimation(bool8 isStatus2, u32 status) #define tBattlerId data[0] -bool8 TryHandleLaunchBattleTableAnimation(u8 activeBank, u8 atkBank, u8 defBank, u8 tableId, u16 argument) +bool8 TryHandleLaunchBattleTableAnimation(u8 activeBattler, u8 atkBattler, u8 defBattler, u8 tableId, u16 argument) { u8 taskId; if (tableId == B_ANIM_CASTFORM_CHANGE && (argument & 0x80)) { - gBattleMonForms[activeBank] = (argument & ~(0x80)); + gBattleMonForms[activeBattler] = (argument & ~(0x80)); return TRUE; } - if (gBattleSpritesDataPtr->battlerData[activeBank].behindSubstitute + if (gBattleSpritesDataPtr->battlerData[activeBattler].behindSubstitute && !ShouldAnimBeDoneRegardlessOfSubsitute(tableId)) { return TRUE; } - if (gBattleSpritesDataPtr->battlerData[activeBank].behindSubstitute + if (gBattleSpritesDataPtr->battlerData[activeBattler].behindSubstitute && tableId == B_ANIM_SUBSTITUTE_FADE - && gSprites[gBattlerSpriteIds[activeBank]].invisible) + && gSprites[gBattlerSpriteIds[activeBattler]].invisible) { - LoadBattleMonGfxAndAnimate(activeBank, TRUE, gBattlerSpriteIds[activeBank]); - ClearBehindSubstituteBit(activeBank); + LoadBattleMonGfxAndAnimate(activeBattler, TRUE, gBattlerSpriteIds[activeBattler]); + ClearBehindSubstituteBit(activeBattler); return TRUE; } - gBattleAnimAttacker = atkBank; - gBattleAnimTarget = defBank; + gBattleAnimAttacker = atkBattler; + gBattleAnimTarget = defBattler; gBattleSpritesDataPtr->animationData->animArg = argument; LaunchBattleAnimation(gBattleAnims_VariousTable, tableId, FALSE); taskId = CreateTask(Task_ClearBitWhenBattleTableAnimDone, 10); - gTasks[taskId].tBattlerId = activeBank; + gTasks[taskId].tBattlerId = activeBattler; gBattleSpritesDataPtr->healthBoxesData[gTasks[taskId].tBattlerId].animFromTableActive = 1; return FALSE; @@ -475,15 +475,15 @@ static bool8 ShouldAnimBeDoneRegardlessOfSubsitute(u8 animId) #define tBattlerId data[0] -void InitAndLaunchSpecialAnimation(u8 activeBank, u8 atkBank, u8 defBank, u8 tableId) +void InitAndLaunchSpecialAnimation(u8 activeBattler, u8 atkBattler, u8 defBattler, u8 tableId) { u8 taskId; - gBattleAnimAttacker = atkBank; - gBattleAnimTarget = defBank; + gBattleAnimAttacker = atkBattler; + gBattleAnimTarget = defBattler; LaunchBattleAnimation(gBattleAnims_Special, tableId, FALSE); taskId = CreateTask(Task_ClearBitWhenSpecialAnimDone, 10); - gTasks[taskId].tBattlerId = activeBank; + gTasks[taskId].tBattlerId = activeBattler; gBattleSpritesDataPtr->healthBoxesData[gTasks[taskId].tBattlerId].specialAnimActive = 1; } @@ -681,7 +681,7 @@ void FreeTrainerFrontPicPalette(u16 frontPicId) void sub_805DFFC(void) { - u8 numberOfBanks = 0; + u8 numberOfBattlers = 0; u8 i; LoadSpritePalette(&gUnknown_0832C128[0]); @@ -690,7 +690,7 @@ void sub_805DFFC(void) { LoadCompressedObjectPic(&gUnknown_0832C0D0); LoadCompressedObjectPic(&gUnknown_0832C0D8); - numberOfBanks = 2; + numberOfBattlers = 2; } else { @@ -698,9 +698,9 @@ void sub_805DFFC(void) LoadCompressedObjectPic(&gUnknown_0832C0E0[1]); LoadCompressedObjectPic(&gUnknown_0832C0F0[0]); LoadCompressedObjectPic(&gUnknown_0832C0F0[1]); - numberOfBanks = 4; + numberOfBattlers = 4; } - for (i = 0; i < numberOfBanks; i++) + for (i = 0; i < numberOfBattlers; i++) LoadCompressedObjectPic(&gUnknown_0832C108[gBattlerPositions[i]]); } @@ -771,7 +771,7 @@ bool8 BattleInitAllSprites(u8 *state1, u8 *battlerId) switch (*state1) { case 0: - ClearSpritesBankHealthboxAnimData(); + ClearSpritesBattlerHealthboxAnimData(); (*state1)++; break; case 1: @@ -849,7 +849,7 @@ void ClearSpritesHealthboxAnimData(void) memset(gBattleSpritesDataPtr->animationData, 0, sizeof(struct BattleAnimationInfo)); } -static void ClearSpritesBankHealthboxAnimData(void) +static void ClearSpritesBattlerHealthboxAnimData(void) { ClearSpritesHealthboxAnimData(); memset(gBattleSpritesDataPtr->battlerData, 0, sizeof(struct BattleSpriteInfo) * MAX_BATTLERS_COUNT); @@ -868,7 +868,7 @@ void CopyBattleSpriteInvisibility(u8 battlerId) gBattleSpritesDataPtr->battlerData[battlerId].invisible = gSprites[gBattlerSpriteIds[battlerId]].invisible; } -void HandleSpeciesGfxDataChange(u8 bankAtk, u8 bankDef, bool8 notTransform) +void HandleSpeciesGfxDataChange(u8 battlerAtk, u8 battlerDef, bool8 notTransform) { u16 paletteOffset; u32 personalityValue; @@ -878,16 +878,16 @@ void HandleSpeciesGfxDataChange(u8 bankAtk, u8 bankDef, bool8 notTransform) if (notTransform) { - StartSpriteAnim(&gSprites[gBattlerSpriteIds[bankAtk]], gBattleSpritesDataPtr->animationData->animArg); - paletteOffset = 0x100 + bankAtk * 16; + StartSpriteAnim(&gSprites[gBattlerSpriteIds[battlerAtk]], gBattleSpritesDataPtr->animationData->animArg); + paletteOffset = 0x100 + battlerAtk * 16; LoadPalette(gBattleStruct->castformPalette[gBattleSpritesDataPtr->animationData->animArg], paletteOffset, 32); - gBattleMonForms[bankAtk] = gBattleSpritesDataPtr->animationData->animArg; - if (gBattleSpritesDataPtr->battlerData[bankAtk].transformSpecies != SPECIES_NONE) + gBattleMonForms[battlerAtk] = gBattleSpritesDataPtr->animationData->animArg; + if (gBattleSpritesDataPtr->battlerData[battlerAtk].transformSpecies != SPECIES_NONE) { BlendPalette(paletteOffset, 16, 6, RGB_WHITE); CpuCopy32(gPlttBufferFaded + paletteOffset, gPlttBufferUnfaded + paletteOffset, 32); } - gSprites[gBattlerSpriteIds[bankAtk]].pos1.y = GetBattlerSpriteDefault_Y(bankAtk); + gSprites[gBattlerSpriteIds[battlerAtk]].pos1.y = GetBattlerSpriteDefault_Y(battlerAtk); } else { @@ -909,48 +909,48 @@ void HandleSpeciesGfxDataChange(u8 bankAtk, u8 bankDef, bool8 notTransform) } else { - position = GetBattlerPosition(bankAtk); + position = GetBattlerPosition(battlerAtk); - if (GetBattlerSide(bankDef) == B_SIDE_OPPONENT) - targetSpecies = GetMonData(&gEnemyParty[gBattlerPartyIndexes[bankDef]], MON_DATA_SPECIES); + if (GetBattlerSide(battlerDef) == B_SIDE_OPPONENT) + targetSpecies = GetMonData(&gEnemyParty[gBattlerPartyIndexes[battlerDef]], MON_DATA_SPECIES); else - targetSpecies = GetMonData(&gPlayerParty[gBattlerPartyIndexes[bankDef]], MON_DATA_SPECIES); + targetSpecies = GetMonData(&gPlayerParty[gBattlerPartyIndexes[battlerDef]], MON_DATA_SPECIES); - if (GetBattlerSide(bankAtk) == B_SIDE_PLAYER) + if (GetBattlerSide(battlerAtk) == B_SIDE_PLAYER) { - personalityValue = GetMonData(&gPlayerParty[gBattlerPartyIndexes[bankAtk]], MON_DATA_PERSONALITY); - otId = GetMonData(&gPlayerParty[gBattlerPartyIndexes[bankAtk]], MON_DATA_OT_ID); + personalityValue = GetMonData(&gPlayerParty[gBattlerPartyIndexes[battlerAtk]], MON_DATA_PERSONALITY); + otId = GetMonData(&gPlayerParty[gBattlerPartyIndexes[battlerAtk]], MON_DATA_OT_ID); HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonBackPicTable[targetSpecies], gMonSpritesGfxPtr->sprites[position], targetSpecies, - gTransformedPersonalities[bankAtk]); + gTransformedPersonalities[battlerAtk]); } else { - personalityValue = GetMonData(&gEnemyParty[gBattlerPartyIndexes[bankAtk]], MON_DATA_PERSONALITY); - otId = GetMonData(&gEnemyParty[gBattlerPartyIndexes[bankAtk]], MON_DATA_OT_ID); + personalityValue = GetMonData(&gEnemyParty[gBattlerPartyIndexes[battlerAtk]], MON_DATA_PERSONALITY); + otId = GetMonData(&gEnemyParty[gBattlerPartyIndexes[battlerAtk]], MON_DATA_OT_ID); HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[targetSpecies], gMonSpritesGfxPtr->sprites[position], targetSpecies, - gTransformedPersonalities[bankAtk]); + gTransformedPersonalities[battlerAtk]); } } src = gMonSpritesGfxPtr->sprites[position]; - dst = (void *)(VRAM + 0x10000 + gSprites[gBattlerSpriteIds[bankAtk]].oam.tileNum * 32); + dst = (void *)(VRAM + 0x10000 + gSprites[gBattlerSpriteIds[battlerAtk]].oam.tileNum * 32); DmaCopy32(3, src, dst, 0x800); - paletteOffset = 0x100 + bankAtk * 16; + paletteOffset = 0x100 + battlerAtk * 16; lzPaletteData = GetFrontSpritePalFromSpeciesAndPersonality(targetSpecies, otId, personalityValue); LZDecompressWram(lzPaletteData, gDecompressionBuffer); LoadPalette(gDecompressionBuffer, paletteOffset, 32); if (targetSpecies == SPECIES_CASTFORM) { - gSprites[gBattlerSpriteIds[bankAtk]].anims = gMonAnimationsSpriteAnimsPtrTable[targetSpecies]; + gSprites[gBattlerSpriteIds[battlerAtk]].anims = gMonAnimationsSpriteAnimsPtrTable[targetSpecies]; LZDecompressWram(lzPaletteData, gBattleStruct->castformPalette[0]); - LoadPalette(gBattleStruct->castformPalette[0] + gBattleMonForms[bankDef] * 16, paletteOffset, 32); + LoadPalette(gBattleStruct->castformPalette[0] + gBattleMonForms[battlerDef] * 16, paletteOffset, 32); } BlendPalette(paletteOffset, 16, 6, RGB_WHITE); @@ -958,12 +958,12 @@ void HandleSpeciesGfxDataChange(u8 bankAtk, u8 bankDef, bool8 notTransform) if (!IsContest()) { - gBattleSpritesDataPtr->battlerData[bankAtk].transformSpecies = targetSpecies; - gBattleMonForms[bankAtk] = gBattleMonForms[bankDef]; + gBattleSpritesDataPtr->battlerData[battlerAtk].transformSpecies = targetSpecies; + gBattleMonForms[battlerAtk] = gBattleMonForms[battlerDef]; } - gSprites[gBattlerSpriteIds[bankAtk]].pos1.y = GetBattlerSpriteDefault_Y(bankAtk); - StartSpriteAnim(&gSprites[gBattlerSpriteIds[bankAtk]], gBattleMonForms[bankAtk]); + gSprites[gBattlerSpriteIds[battlerAtk]].pos1.y = GetBattlerSpriteDefault_Y(battlerAtk); + StartSpriteAnim(&gSprites[gBattlerSpriteIds[battlerAtk]], gBattleMonForms[battlerAtk]); } } @@ -1068,11 +1068,11 @@ void HandleLowHpMusicChange(struct Pokemon *mon, u8 battlerId) void BattleStopLowHpSound(void) { - u8 playerBank = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); + u8 playerBattler = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); - gBattleSpritesDataPtr->battlerData[playerBank].lowHpSong = 0; + gBattleSpritesDataPtr->battlerData[playerBattler].lowHpSong = 0; if (IsDoubleBattle()) - gBattleSpritesDataPtr->battlerData[playerBank ^ BIT_FLANK].lowHpSong = 0; + gBattleSpritesDataPtr->battlerData[playerBattler ^ BIT_FLANK].lowHpSong = 0; m4aSongNumStop(SE_HINSI); } @@ -1085,19 +1085,19 @@ u8 GetMonHPBarLevel(struct Pokemon *mon) return GetHPBarLevel(hp, maxHP); } -void sub_805EAE8(void) +void HandleBattleLowHpMusicChange(void) { if (gMain.inBattle) { - u8 playerBank1 = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); - u8 playerBank2 = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT); - u8 bank1PartyId = pokemon_order_func(gBattlerPartyIndexes[playerBank1]); - u8 bank2PartyId = pokemon_order_func(gBattlerPartyIndexes[playerBank2]); + u8 playerBattler1 = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); + u8 playerBattler2 = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT); + u8 battler1PartyId = pokemon_order_func(gBattlerPartyIndexes[playerBattler1]); + u8 battler2PartyId = pokemon_order_func(gBattlerPartyIndexes[playerBattler2]); - if (GetMonData(&gPlayerParty[bank1PartyId], MON_DATA_HP) != 0) - HandleLowHpMusicChange(&gPlayerParty[bank1PartyId], playerBank1); - if (IsDoubleBattle() && GetMonData(&gPlayerParty[bank2PartyId], MON_DATA_HP) != 0) - HandleLowHpMusicChange(&gPlayerParty[bank2PartyId], playerBank2); + if (GetMonData(&gPlayerParty[battler1PartyId], MON_DATA_HP) != 0) + HandleLowHpMusicChange(&gPlayerParty[battler1PartyId], playerBattler1); + if (IsDoubleBattle() && GetMonData(&gPlayerParty[battler2PartyId], MON_DATA_HP) != 0) + HandleLowHpMusicChange(&gPlayerParty[battler2PartyId], playerBattler2); } } @@ -1147,14 +1147,14 @@ void SpriteCB_EnemyShadow(struct Sprite *shadowSprite) { bool8 invisible = FALSE; u8 battlerId = shadowSprite->tBattlerId; - struct Sprite *bankSprite = &gSprites[gBattlerSpriteIds[battlerId]]; + struct Sprite *battlerSprite = &gSprites[gBattlerSpriteIds[battlerId]]; - if (!bankSprite->inUse || !IsBattlerSpritePresent(battlerId)) + if (!battlerSprite->inUse || !IsBattlerSpritePresent(battlerId)) { shadowSprite->callback = SpriteCB_SetInvisible; return; } - if (gAnimScriptActive || bankSprite->invisible) + if (gAnimScriptActive || battlerSprite->invisible) invisible = TRUE; else if (gBattleSpritesDataPtr->battlerData[battlerId].transformSpecies != SPECIES_NONE && gEnemyMonElevation[gBattleSpritesDataPtr->battlerData[battlerId].transformSpecies] == 0) @@ -1163,8 +1163,8 @@ void SpriteCB_EnemyShadow(struct Sprite *shadowSprite) if (gBattleSpritesDataPtr->battlerData[battlerId].behindSubstitute) invisible = TRUE; - shadowSprite->pos1.x = bankSprite->pos1.x; - shadowSprite->pos2.x = bankSprite->pos2.x; + shadowSprite->pos1.x = battlerSprite->pos1.x; + shadowSprite->pos2.x = battlerSprite->pos2.x; shadowSprite->invisible = invisible; } @@ -1177,7 +1177,7 @@ void SpriteCB_SetInvisible(struct Sprite *sprite) void SetBattlerShadowSpriteCallback(u8 battlerId, u16 species) { - // The player's shadow is never seen + // The player's shadow is never seen. if (GetBattlerSide(battlerId) == B_SIDE_PLAYER) return; @@ -1270,7 +1270,7 @@ void FreeMonSpritesGfx(void) FREE_AND_SET_NULL(gMonSpritesGfxPtr); } -bool32 ShouldPlayNormalPokeCry(struct Pokemon *mon) +bool32 ShouldPlayNormalMonCry(struct Pokemon *mon) { s16 hp, maxHP; s32 barLevel; diff --git a/src/battle_interface.c b/src/battle_interface.c index 9ef45020d..94b5a2be9 100644 --- a/src/battle_interface.c +++ b/src/battle_interface.c @@ -26,7 +26,7 @@ struct TestingBar { s32 maxValue; - s32 currValue; + s32 oldValue; s32 receivedValue; u32 unkC_0:5; u32 unk10; @@ -37,7 +37,7 @@ enum HEALTHBOX_GFX_0, HEALTHBOX_GFX_1, HEALTHBOX_GFX_2, - HEALTHBOX_GFX_3, + HEALTHBOX_GFX_HP_BAR_GREEN, HEALTHBOX_GFX_4, HEALTHBOX_GFX_5, HEALTHBOX_GFX_6, @@ -55,19 +55,19 @@ enum HEALTHBOX_GFX_18, HEALTHBOX_GFX_19, HEALTHBOX_GFX_20, - HEALTHBOX_GFX_STATUS_PSN_BANK0, + HEALTHBOX_GFX_STATUS_PSN_BATTLER0, HEALTHBOX_GFX_22, HEALTHBOX_GFX_23, - HEALTHBOX_GFX_STATUS_PRZ_BANK0, + HEALTHBOX_GFX_STATUS_PRZ_BATTLER0, HEALTHBOX_GFX_25, HEALTHBOX_GFX_26, - HEALTHBOX_GFX_STATUS_SLP_BANK0, + HEALTHBOX_GFX_STATUS_SLP_BATTLER0, HEALTHBOX_GFX_28, HEALTHBOX_GFX_29, - HEALTHBOX_GFX_STATUS_FRZ_BANK0, + HEALTHBOX_GFX_STATUS_FRZ_BATTLER0, HEALTHBOX_GFX_31, HEALTHBOX_GFX_32, - HEALTHBOX_GFX_STATUS_BRN_BANK0, + HEALTHBOX_GFX_STATUS_BRN_BATTLER0, HEALTHBOX_GFX_34, HEALTHBOX_GFX_35, HEALTHBOX_GFX_36, @@ -81,7 +81,7 @@ enum HEALTHBOX_GFX_44, HEALTHBOX_GFX_45, HEALTHBOX_GFX_46, - HEALTHBOX_GFX_47, + HEALTHBOX_GFX_HP_BAR_YELLOW, HEALTHBOX_GFX_48, HEALTHBOX_GFX_49, HEALTHBOX_GFX_50, @@ -90,7 +90,7 @@ enum HEALTHBOX_GFX_53, HEALTHBOX_GFX_54, HEALTHBOX_GFX_55, - HEALTHBOX_GFX_56, + HEALTHBOX_GFX_HP_BAR_RED, HEALTHBOX_GFX_57, HEALTHBOX_GFX_58, HEALTHBOX_GFX_59, @@ -105,56 +105,56 @@ enum HEALTHBOX_GFX_68, HEALTHBOX_GFX_69, HEALTHBOX_GFX_70, - HEALTHBOX_GFX_STATUS_PSN_BANK1, + HEALTHBOX_GFX_STATUS_PSN_BATTLER1, HEALTHBOX_GFX_72, HEALTHBOX_GFX_73, - HEALTHBOX_GFX_STATUS_PRZ_BANK1, + HEALTHBOX_GFX_STATUS_PRZ_BATTLER1, HEALTHBOX_GFX_75, HEALTHBOX_GFX_76, - HEALTHBOX_GFX_STATUS_SLP_BANK1, + HEALTHBOX_GFX_STATUS_SLP_BATTLER1, HEALTHBOX_GFX_78, HEALTHBOX_GFX_79, - HEALTHBOX_GFX_STATUS_FRZ_BANK1, + HEALTHBOX_GFX_STATUS_FRZ_BATTLER1, HEALTHBOX_GFX_81, HEALTHBOX_GFX_82, - HEALTHBOX_GFX_STATUS_BRN_BANK1, + HEALTHBOX_GFX_STATUS_BRN_BATTLER1, HEALTHBOX_GFX_84, HEALTHBOX_GFX_85, - HEALTHBOX_GFX_STATUS_PSN_BANK2, + HEALTHBOX_GFX_STATUS_PSN_BATTLER2, HEALTHBOX_GFX_87, HEALTHBOX_GFX_88, - HEALTHBOX_GFX_STATUS_PRZ_BANK2, + HEALTHBOX_GFX_STATUS_PRZ_BATTLER2, HEALTHBOX_GFX_90, HEALTHBOX_GFX_91, - HEALTHBOX_GFX_STATUS_SLP_BANK2, + HEALTHBOX_GFX_STATUS_SLP_BATTLER2, HEALTHBOX_GFX_93, HEALTHBOX_GFX_94, - HEALTHBOX_GFX_STATUS_FRZ_BANK2, + HEALTHBOX_GFX_STATUS_FRZ_BATTLER2, HEALTHBOX_GFX_96, HEALTHBOX_GFX_97, - HEALTHBOX_GFX_STATUS_BRN_BANK2, + HEALTHBOX_GFX_STATUS_BRN_BATTLER2, HEALTHBOX_GFX_99, HEALTHBOX_GFX_100, - HEALTHBOX_GFX_STATUS_PSN_BANK3, + HEALTHBOX_GFX_STATUS_PSN_BATTLER3, HEALTHBOX_GFX_102, HEALTHBOX_GFX_103, - HEALTHBOX_GFX_STATUS_PRZ_BANK3, + HEALTHBOX_GFX_STATUS_PRZ_BATTLER3, HEALTHBOX_GFX_105, HEALTHBOX_GFX_106, - HEALTHBOX_GFX_STATUS_SLP_BANK3, + HEALTHBOX_GFX_STATUS_SLP_BATTLER3, HEALTHBOX_GFX_108, HEALTHBOX_GFX_109, - HEALTHBOX_GFX_STATUS_FRZ_BANK3, + HEALTHBOX_GFX_STATUS_FRZ_BATTLER3, HEALTHBOX_GFX_111, HEALTHBOX_GFX_112, - HEALTHBOX_GFX_STATUS_BRN_BANK3, + HEALTHBOX_GFX_STATUS_BRN_BATTLER3, HEALTHBOX_GFX_114, HEALTHBOX_GFX_115, HEALTHBOX_GFX_116, HEALTHBOX_GFX_117, }; -extern const u8 * const gNatureNamePointers[]; +extern const u8 *const gNatureNamePointers[]; // strings extern const u8 gText_Slash[]; @@ -179,28 +179,28 @@ static void RemoveWindowOnHealthbox(u32 windowId); static void UpdateHpTextInHealthboxInDoubles(u8 healthboxSpriteId, s16 value, u8 maxOrCurrent); static void UpdateStatusIconInHealthbox(u8 healthboxSpriteId); -static void sub_8075198(void *dest, u8 *windowTileData, s32 arg2); -static void sub_80751E4(void *dest, u8 *windowTileData, u32 arg2); -static void sub_8075170(void *dest, u8 *windowTileData, u32 arg2); -static void sub_807513C(void *dest, u32 arg1, u32 arg2); +static void TextIntoHealthboxObject(void *dest, u8 *windowTileData, s32 arg2); +static void SafariTextIntoHealthboxObject(void *dest, u8 *windowTileData, u32 arg2); +static void HpTextIntoHealthboxObject(void *dest, u8 *windowTileData, u32 arg2); +static void FillHealthboxObject(void *dest, u32 arg1, u32 arg2); static void sub_8073E08(u8 taskId); static void sub_8073F98(u8 taskId); static void sub_8073E64(u8 taskId); -static void sub_8072924(struct Sprite *sprite); -static void sub_80728B4(struct Sprite *sprite); +static void SpriteCB_HealthBoxOther(struct Sprite *sprite); +static void SpriteCB_HealthBar(struct Sprite *sprite); static void sub_8074158(struct Sprite *sprite); static void sub_8074090(struct Sprite *sprite); static void SpriteCB_StatusSummaryBar(struct Sprite *sprite); static void SpriteCB_StatusSummaryBallsOnBattleStart(struct Sprite *sprite); static void SpriteCB_StatusSummaryBallsOnSwitchout(struct Sprite *sprite); -static u8 GetStatusIconForBankId(u8 statusElementId, u8 battlerId); -static s32 sub_8074DB8(s32 maxValue, s32 currValue, s32 receivedValue, s32 *arg3, u8 arg4, u16 arg5); +static u8 GetStatusIconForBattlerId(u8 statusElementId, u8 battlerId); +static s32 CalcNewBarValue(s32 maxValue, s32 currValue, s32 receivedValue, s32 *arg3, u8 arg4, u16 arg5); static u8 GetScaledExpFraction(s32 currValue, s32 receivedValue, s32 maxValue, u8 scale); -static void sub_8074B9C(u8 battlerId, u8 whichBar); -static u8 sub_8074E8C(s32 maxValue, s32 currValue, s32 receivedValue, s32 *arg3, u8 *arg4, u8 arg5); +static void MoveBattleBarGraphically(u8 battlerId, u8 whichBar); +static u8 CalcBarFilledPixels(s32 maxValue, s32 oldValue, s32 receivedValue, s32 *currValue, u8 *arg4, u8 scale); static void sub_8074F88(struct TestingBar *barInfo, s32 *arg1, u16 *arg2); // const rom data @@ -276,7 +276,7 @@ static const struct SpriteTemplate sHealthboxSafariSpriteTemplate = .callback = SpriteCallbackDummy }; -static const struct OamData sUnknown_0832C1B8 = +static const struct OamData sOamData_Healthbar = { .y = 0, .affineMode = 0, @@ -293,43 +293,43 @@ static const struct OamData sUnknown_0832C1B8 = .affineParam = 0, }; -static const struct SpriteTemplate sUnknown_0832C1C0[4] = +static const struct SpriteTemplate sHealthbarSpriteTemplates[MAX_BATTLERS_COUNT] = { { - .tileTag = 0xd704, - .paletteTag = 0xd704, - .oam = &sUnknown_0832C1B8, + .tileTag = TAG_HEALTHBAR_PLAYER1_TILE, + .paletteTag = TAG_HEALTHBAR_PAL, + .oam = &sOamData_Healthbar, .anims = gDummySpriteAnimTable, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = sub_80728B4 + .callback = SpriteCB_HealthBar }, { - .tileTag = 0xd705, - .paletteTag = 0xd704, - .oam = &sUnknown_0832C1B8, + .tileTag = TAG_HEALTHBAR_OPPONENT1_TILE, + .paletteTag = TAG_HEALTHBAR_PAL, + .oam = &sOamData_Healthbar, .anims = gDummySpriteAnimTable, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = sub_80728B4 + .callback = SpriteCB_HealthBar }, { - .tileTag = 0xd706, - .paletteTag = 0xd704, - .oam = &sUnknown_0832C1B8, + .tileTag = TAG_HEALTHBAR_PLAYER2_TILE, + .paletteTag = TAG_HEALTHBAR_PAL, + .oam = &sOamData_Healthbar, .anims = gDummySpriteAnimTable, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = sub_80728B4 + .callback = SpriteCB_HealthBar }, { - .tileTag = 0xd707, - .paletteTag = 0xd704, - .oam = &sUnknown_0832C1B8, + .tileTag = TAG_HEALTHBAR_OPPONENT2_TILE, + .paletteTag = TAG_HEALTHBAR_PAL, + .oam = &sOamData_Healthbar, .anims = gDummySpriteAnimTable, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = sub_80728B4 + .callback = SpriteCB_HealthBar } }; @@ -883,112 +883,126 @@ void sub_80724A8(s16 arg0, s16 arg1, u16 *arg2) sub_8072308(arg0, arg2 + 5, 1); } -// because the healthbox is too large to fit into one sprite, it is divided into two sprites -// healthboxSpriteId_1 or healthboxSpriteId refers to the 'main' healthbox -// healthboxSpriteId_2 refers to the other part -// there's also one other sprite that appears to be a black square? dont fully understand its role +// Because the healthbox is too large to fit into one sprite, it is divided into two sprites. +// healthboxLeft or healthboxMain is the left part that is used as the 'main' sprite. +// healthboxRight or healthboxOther is the right part of the healthbox. +// There's also the third sprite under name of healthbarSprite that refers to the healthbar visible on the healtbox. -u8 CreateBattlerHealthboxSprites(u8 battler) +// data fields for healthboxMain +// oam.affineParam holds healthboxRight spriteId +#define hMain_HealthBarSpriteId data[5] +#define hMain_Battler data[6] +#define hMain_Data7 data[7] + +// data fields for healthboxRight +#define hOther_HealthBoxSpriteId data[5] + +// data fields for healthbar +#define hBar_HealthBoxSpriteId data[5] +#define hBar_Data6 data[6] + +u8 CreateBattlerHealthboxSprites(u8 battlerId) { s16 data6 = 0; - u8 healthboxSpriteId_1, healthboxSpriteId_2; - u8 unkSpriteId; - struct Sprite *unkSpritePtr; + u8 healthboxLeftSpriteId, healthboxRightSpriteId; + u8 healthbarSpriteId; + struct Sprite *healthBarSpritePtr; if (!IsDoubleBattle()) { - if (GetBattlerSide(battler) == B_SIDE_PLAYER) + if (GetBattlerSide(battlerId) == B_SIDE_PLAYER) { - healthboxSpriteId_1 = CreateSprite(&sHealthboxPlayerSpriteTemplates[0], 240, 160, 1); - healthboxSpriteId_2 = CreateSpriteAtEnd(&sHealthboxPlayerSpriteTemplates[0], 240, 160, 1); + healthboxLeftSpriteId = CreateSprite(&sHealthboxPlayerSpriteTemplates[0], 240, 160, 1); + healthboxRightSpriteId = CreateSpriteAtEnd(&sHealthboxPlayerSpriteTemplates[0], 240, 160, 1); - gSprites[healthboxSpriteId_1].oam.shape = 0; + gSprites[healthboxLeftSpriteId].oam.shape = 0; - gSprites[healthboxSpriteId_2].oam.shape = 0; - gSprites[healthboxSpriteId_2].oam.tileNum += 64; + gSprites[healthboxRightSpriteId].oam.shape = 0; + gSprites[healthboxRightSpriteId].oam.tileNum += 64; } else { - healthboxSpriteId_1 = CreateSprite(&sHealthboxOpponentSpriteTemplates[0], 240, 160, 1); - healthboxSpriteId_2 = CreateSpriteAtEnd(&sHealthboxOpponentSpriteTemplates[0], 240, 160, 1); + healthboxLeftSpriteId = CreateSprite(&sHealthboxOpponentSpriteTemplates[0], 240, 160, 1); + healthboxRightSpriteId = CreateSpriteAtEnd(&sHealthboxOpponentSpriteTemplates[0], 240, 160, 1); - gSprites[healthboxSpriteId_2].oam.tileNum += 32; + gSprites[healthboxRightSpriteId].oam.tileNum += 32; data6 = 2; } - gSprites[healthboxSpriteId_1].oam.affineParam = healthboxSpriteId_2; - gSprites[healthboxSpriteId_2].data[5] = healthboxSpriteId_1; - gSprites[healthboxSpriteId_2].callback = sub_8072924; + gSprites[healthboxLeftSpriteId].oam.affineParam = healthboxRightSpriteId; + + gSprites[healthboxRightSpriteId].hOther_HealthBoxSpriteId = healthboxLeftSpriteId; + gSprites[healthboxRightSpriteId].callback = SpriteCB_HealthBoxOther; } else { - if (GetBattlerSide(battler) == B_SIDE_PLAYER) + if (GetBattlerSide(battlerId) == B_SIDE_PLAYER) { - healthboxSpriteId_1 = CreateSprite(&sHealthboxPlayerSpriteTemplates[GetBattlerPosition(battler) / 2], 240, 160, 1); - healthboxSpriteId_2 = CreateSpriteAtEnd(&sHealthboxPlayerSpriteTemplates[GetBattlerPosition(battler) / 2], 240, 160, 1); + healthboxLeftSpriteId = CreateSprite(&sHealthboxPlayerSpriteTemplates[GetBattlerPosition(battlerId) / 2], 240, 160, 1); + healthboxRightSpriteId = CreateSpriteAtEnd(&sHealthboxPlayerSpriteTemplates[GetBattlerPosition(battlerId) / 2], 240, 160, 1); - gSprites[healthboxSpriteId_1].oam.affineParam = healthboxSpriteId_2; + gSprites[healthboxLeftSpriteId].oam.affineParam = healthboxRightSpriteId; - gSprites[healthboxSpriteId_2].data[5] = healthboxSpriteId_1; - gSprites[healthboxSpriteId_2].oam.tileNum += 32; - gSprites[healthboxSpriteId_2].callback = sub_8072924; + gSprites[healthboxRightSpriteId].hOther_HealthBoxSpriteId = healthboxLeftSpriteId; + gSprites[healthboxRightSpriteId].oam.tileNum += 32; + gSprites[healthboxRightSpriteId].callback = SpriteCB_HealthBoxOther; data6 = 1; } else { - healthboxSpriteId_1 = CreateSprite(&sHealthboxOpponentSpriteTemplates[GetBattlerPosition(battler) / 2], 240, 160, 1); - healthboxSpriteId_2 = CreateSpriteAtEnd(&sHealthboxOpponentSpriteTemplates[GetBattlerPosition(battler) / 2], 240, 160, 1); + healthboxLeftSpriteId = CreateSprite(&sHealthboxOpponentSpriteTemplates[GetBattlerPosition(battlerId) / 2], 240, 160, 1); + healthboxRightSpriteId = CreateSpriteAtEnd(&sHealthboxOpponentSpriteTemplates[GetBattlerPosition(battlerId) / 2], 240, 160, 1); - gSprites[healthboxSpriteId_1].oam.affineParam = healthboxSpriteId_2; + gSprites[healthboxLeftSpriteId].oam.affineParam = healthboxRightSpriteId; - gSprites[healthboxSpriteId_2].data[5] = healthboxSpriteId_1; - gSprites[healthboxSpriteId_2].oam.tileNum += 32; - gSprites[healthboxSpriteId_2].callback = sub_8072924; + gSprites[healthboxRightSpriteId].hOther_HealthBoxSpriteId = healthboxLeftSpriteId; + gSprites[healthboxRightSpriteId].oam.tileNum += 32; + gSprites[healthboxRightSpriteId].callback = SpriteCB_HealthBoxOther; data6 = 2; } } - unkSpriteId = CreateSpriteAtEnd(&sUnknown_0832C1C0[gBattlerPositions[battler]], 140, 60, 0); - unkSpritePtr = &gSprites[unkSpriteId]; - SetSubspriteTables(unkSpritePtr, &sUnknown_0832C28C[GetBattlerSide(battler)]); - unkSpritePtr->subspriteMode = 2; - unkSpritePtr->oam.priority = 1; + healthbarSpriteId = CreateSpriteAtEnd(&sHealthbarSpriteTemplates[gBattlerPositions[battlerId]], 140, 60, 0); + healthBarSpritePtr = &gSprites[healthbarSpriteId]; + SetSubspriteTables(healthBarSpritePtr, &sUnknown_0832C28C[GetBattlerSide(battlerId)]); + healthBarSpritePtr->subspriteMode = 2; + healthBarSpritePtr->oam.priority = 1; - CpuCopy32(GetHealthboxElementGfxPtr(HEALTHBOX_GFX_1), (void*)(OBJ_VRAM0 + unkSpritePtr->oam.tileNum * 32), 64); + CpuCopy32(GetHealthboxElementGfxPtr(HEALTHBOX_GFX_1), (void*)(OBJ_VRAM0 + healthBarSpritePtr->oam.tileNum * 32), 64); - gSprites[healthboxSpriteId_1].data[5] = unkSpriteId; - gSprites[healthboxSpriteId_1].data[6] = battler; - gSprites[healthboxSpriteId_1].invisible = 1; + gSprites[healthboxLeftSpriteId].hMain_HealthBarSpriteId = healthbarSpriteId; + gSprites[healthboxLeftSpriteId].hMain_Battler = battlerId; + gSprites[healthboxLeftSpriteId].invisible = 1; - gSprites[healthboxSpriteId_2].invisible = 1; + gSprites[healthboxRightSpriteId].invisible = 1; - unkSpritePtr->data[5] = healthboxSpriteId_1; - unkSpritePtr->data[6] = data6; - unkSpritePtr->invisible = 1; + healthBarSpritePtr->hBar_HealthBoxSpriteId = healthboxLeftSpriteId; + healthBarSpritePtr->hBar_Data6 = data6; + healthBarSpritePtr->invisible = 1; - return healthboxSpriteId_1; + return healthboxLeftSpriteId; } u8 CreateSafariPlayerHealthboxSprites(void) { - u8 healthboxSpriteId_1, healthboxSpriteId_2; + u8 healthboxLeftSpriteId, healthboxRightSpriteId; - healthboxSpriteId_1 = CreateSprite(&sHealthboxSafariSpriteTemplate, 240, 160, 1); - healthboxSpriteId_2 = CreateSpriteAtEnd(&sHealthboxSafariSpriteTemplate, 240, 160, 1); + healthboxLeftSpriteId = CreateSprite(&sHealthboxSafariSpriteTemplate, 240, 160, 1); + healthboxRightSpriteId = CreateSpriteAtEnd(&sHealthboxSafariSpriteTemplate, 240, 160, 1); - gSprites[healthboxSpriteId_1].oam.shape = 0; - gSprites[healthboxSpriteId_2].oam.shape = 0; + gSprites[healthboxLeftSpriteId].oam.shape = 0; + gSprites[healthboxRightSpriteId].oam.shape = 0; - gSprites[healthboxSpriteId_2].oam.tileNum += 64; + gSprites[healthboxRightSpriteId].oam.tileNum += 64; - gSprites[healthboxSpriteId_1].oam.affineParam = healthboxSpriteId_2; - gSprites[healthboxSpriteId_2].data[5] = healthboxSpriteId_1; + gSprites[healthboxLeftSpriteId].oam.affineParam = healthboxRightSpriteId; + gSprites[healthboxRightSpriteId].hOther_HealthBoxSpriteId = healthboxLeftSpriteId; - gSprites[healthboxSpriteId_2].callback = sub_8072924; + gSprites[healthboxRightSpriteId].callback = SpriteCB_HealthBoxOther; - return healthboxSpriteId_1; + return healthboxLeftSpriteId; } static const u8 *GetHealthboxElementGfxPtr(u8 elementId) @@ -996,62 +1010,63 @@ static const u8 *GetHealthboxElementGfxPtr(u8 elementId) return gHealthboxElementsGfxTable[elementId]; } -static void sub_80728B4(struct Sprite *sprite) +// Syncs the position of healthbar accordingly with the healthbox. +static void SpriteCB_HealthBar(struct Sprite *sprite) { - u8 var = sprite->data[5]; + u8 healthboxSpriteId = sprite->hBar_HealthBoxSpriteId; - switch (sprite->data[6]) + switch (sprite->hBar_Data6) { case 0: - sprite->pos1.x = gSprites[var].pos1.x + 16; - sprite->pos1.y = gSprites[var].pos1.y; + sprite->pos1.x = gSprites[healthboxSpriteId].pos1.x + 16; + sprite->pos1.y = gSprites[healthboxSpriteId].pos1.y; break; case 1: - sprite->pos1.x = gSprites[var].pos1.x + 16; - sprite->pos1.y = gSprites[var].pos1.y; + sprite->pos1.x = gSprites[healthboxSpriteId].pos1.x + 16; + sprite->pos1.y = gSprites[healthboxSpriteId].pos1.y; break; case 2: default: - sprite->pos1.x = gSprites[var].pos1.x + 8; - sprite->pos1.y = gSprites[var].pos1.y; + sprite->pos1.x = gSprites[healthboxSpriteId].pos1.x + 8; + sprite->pos1.y = gSprites[healthboxSpriteId].pos1.y; break; } - sprite->pos2.x = gSprites[var].pos2.x; - sprite->pos2.y = gSprites[var].pos2.y; + sprite->pos2.x = gSprites[healthboxSpriteId].pos2.x; + sprite->pos2.y = gSprites[healthboxSpriteId].pos2.y; } -static void sub_8072924(struct Sprite *sprite) +static void SpriteCB_HealthBoxOther(struct Sprite *sprite) { - u8 otherSpriteId = sprite->data[5]; + u8 healthboxMainSpriteId = sprite->hOther_HealthBoxSpriteId; - sprite->pos1.x = gSprites[otherSpriteId].pos1.x + 64; - sprite->pos1.y = gSprites[otherSpriteId].pos1.y; + sprite->pos1.x = gSprites[healthboxMainSpriteId].pos1.x + 64; + sprite->pos1.y = gSprites[healthboxMainSpriteId].pos1.y; - sprite->pos2.x = gSprites[otherSpriteId].pos2.x; - sprite->pos2.y = gSprites[otherSpriteId].pos2.y; + sprite->pos2.x = gSprites[healthboxMainSpriteId].pos2.x; + sprite->pos2.y = gSprites[healthboxMainSpriteId].pos2.y; } -void SetBattleBarStruct(u8 battlerId, u8 healthboxSpriteId, s32 maxVal, s32 currVal, s32 receivedValue) +void SetBattleBarStruct(u8 battlerId, u8 healthboxSpriteId, s32 maxVal, s32 oldVal, s32 receivedValue) { gBattleSpritesDataPtr->battleBars[battlerId].healthboxSpriteId = healthboxSpriteId; gBattleSpritesDataPtr->battleBars[battlerId].maxValue = maxVal; - gBattleSpritesDataPtr->battleBars[battlerId].currentValue = currVal; + gBattleSpritesDataPtr->battleBars[battlerId].oldValue = oldVal; gBattleSpritesDataPtr->battleBars[battlerId].receivedValue = receivedValue; - gBattleSpritesDataPtr->battleBars[battlerId].field_10 = -32768; + gBattleSpritesDataPtr->battleBars[battlerId].currValue = -32768; } void SetHealthboxSpriteInvisible(u8 healthboxSpriteId) { gSprites[healthboxSpriteId].invisible = 1; - gSprites[gSprites[healthboxSpriteId].data[5]].invisible = 1; + gSprites[gSprites[healthboxSpriteId].hMain_HealthBarSpriteId].invisible = 1; gSprites[gSprites[healthboxSpriteId].oam.affineParam].invisible = 1; } void SetHealthboxSpriteVisible(u8 healthboxSpriteId) { gSprites[healthboxSpriteId].invisible = 0; - gSprites[gSprites[healthboxSpriteId].data[5]].invisible = 0; + gSprites[gSprites[healthboxSpriteId].hMain_HealthBarSpriteId].invisible = 0; gSprites[gSprites[healthboxSpriteId].oam.affineParam].invisible = 0; } @@ -1064,11 +1079,11 @@ static void UpdateSpritePos(u8 spriteId, s16 x, s16 y) void DestoryHealthboxSprite(u8 healthboxSpriteId) { DestroySprite(&gSprites[gSprites[healthboxSpriteId].oam.affineParam]); - DestroySprite(&gSprites[gSprites[healthboxSpriteId].data[5]]); + DestroySprite(&gSprites[gSprites[healthboxSpriteId].hMain_HealthBarSpriteId]); DestroySprite(&gSprites[healthboxSpriteId]); } -void DummyBattleInterfaceFunc(u8 healthboxSpriteId, bool8 isDoubleBattleBankOnly) +void DummyBattleInterfaceFunc(u8 healthboxSpriteId, bool8 isDoubleBattleBattlerOnly) { } @@ -1079,13 +1094,13 @@ void UpdateOamPriorityInAllHealthboxes(u8 priority) for (i = 0; i < gBattlersCount; i++) { - u8 healthboxSpriteId_1 = gHealthboxSpriteIds[i]; - u8 healthboxSpriteId_2 = gSprites[gHealthboxSpriteIds[i]].oam.affineParam; - u8 healthboxSpriteId_3 = gSprites[gHealthboxSpriteIds[i]].data[5]; + u8 healthboxLeftSpriteId = gHealthboxSpriteIds[i]; + u8 healthboxRightSpriteId = gSprites[gHealthboxSpriteIds[i]].oam.affineParam; + u8 healthbarSpriteId = gSprites[gHealthboxSpriteIds[i]].hMain_HealthBarSpriteId; - gSprites[healthboxSpriteId_1].oam.priority = priority; - gSprites[healthboxSpriteId_2].oam.priority = priority; - gSprites[healthboxSpriteId_3].oam.priority = priority; + gSprites[healthboxLeftSpriteId].oam.priority = priority; + gSprites[healthboxRightSpriteId].oam.priority = priority; + gSprites[healthbarSpriteId].oam.priority = priority; } } @@ -1146,7 +1161,7 @@ static void UpdateLvlInHealthbox(u8 healthboxSpriteId, u8 lvl) windowTileData = AddTextPrinterAndCreateWindowOnHealthbox(text, xPos, 3, 2, &windowId); spriteTileNum = gSprites[healthboxSpriteId].oam.tileNum * 32; - if (GetBattlerSide(gSprites[healthboxSpriteId].data[6]) == B_SIDE_PLAYER) + if (GetBattlerSide(gSprites[healthboxSpriteId].hMain_Battler) == B_SIDE_PLAYER) { objVram = (void*)(OBJ_VRAM0); if (!IsDoubleBattle()) @@ -1159,7 +1174,7 @@ static void UpdateLvlInHealthbox(u8 healthboxSpriteId, u8 lvl) objVram = (void*)(OBJ_VRAM0); objVram += spriteTileNum + 0x400; } - sub_8075198(objVram, windowTileData, 3); + TextIntoHealthboxObject(objVram, windowTileData, 3); RemoveWindowOnHealthbox(windowId); } @@ -1170,7 +1185,7 @@ void UpdateHpTextInHealthbox(u8 healthboxSpriteId, s16 value, u8 maxOrCurrent) u8 text[32]; void *objVram; - if (GetBattlerSide(gSprites[healthboxSpriteId].data[6]) == B_SIDE_PLAYER && !IsDoubleBattle()) + if (GetBattlerSide(gSprites[healthboxSpriteId].hMain_Battler) == B_SIDE_PLAYER && !IsDoubleBattle()) { spriteTileNum = gSprites[healthboxSpriteId].oam.tileNum * 32; if (maxOrCurrent != HP_CURRENT) // singles, max @@ -1179,7 +1194,7 @@ void UpdateHpTextInHealthbox(u8 healthboxSpriteId, s16 value, u8 maxOrCurrent) windowTileData = AddTextPrinterAndCreateWindowOnHealthbox(text, 0, 5, 2, &windowId); objVram = (void*)(OBJ_VRAM0); objVram += spriteTileNum + 0xB40; - sub_8075170(objVram, windowTileData, 2); + HpTextIntoHealthboxObject(objVram, windowTileData, 2); RemoveWindowOnHealthbox(windowId); } else // singles, current @@ -1190,20 +1205,19 @@ void UpdateHpTextInHealthbox(u8 healthboxSpriteId, s16 value, u8 maxOrCurrent) windowTileData = AddTextPrinterAndCreateWindowOnHealthbox(text, 4, 5, 2, &windowId); objVram = (void*)(OBJ_VRAM0); objVram += spriteTileNum + 0x3E0; - sub_8075170(objVram, windowTileData, 1); + HpTextIntoHealthboxObject(objVram, windowTileData, 1); objVram = (void*)(OBJ_VRAM0); objVram += spriteTileNum + 0xB00; - sub_8075170(objVram, windowTileData + 0x20, 2); + HpTextIntoHealthboxObject(objVram, windowTileData + 0x20, 2); RemoveWindowOnHealthbox(windowId); } - } else { u8 battler; memcpy(text, sUnknown_0832C3C4, sizeof(sUnknown_0832C3C4)); - battler = gSprites[healthboxSpriteId].data[6]; + battler = gSprites[healthboxSpriteId].hMain_Battler; if (IsDoubleBattle() == TRUE || GetBattlerSide(battler) == B_SIDE_OPPONENT) { UpdateHpTextInHealthboxInDoubles(healthboxSpriteId, value, maxOrCurrent); @@ -1248,7 +1262,7 @@ static void UpdateHpTextInHealthboxInDoubles(u8 healthboxSpriteId, s16 value, u8 u8 text[32]; void *objVram; - if (GetBattlerSide(gSprites[healthboxSpriteId].data[6]) == B_SIDE_PLAYER) + if (GetBattlerSide(gSprites[healthboxSpriteId].hMain_Battler) == B_SIDE_PLAYER) { if (gBattleSpritesDataPtr->battlerData[gSprites[healthboxSpriteId].data[6]].hpNumbersNoBars) // don't print text if only bars are visible { @@ -1259,7 +1273,7 @@ static void UpdateHpTextInHealthboxInDoubles(u8 healthboxSpriteId, s16 value, u8 { ConvertIntToDecimalStringN(text, value, STR_CONV_MODE_RIGHT_ALIGN, 3); windowTileData = AddTextPrinterAndCreateWindowOnHealthbox(text, 0, 5, 0, &windowId); - sub_8075170((void*)(OBJ_VRAM0) + spriteTileNum + 0xC0, windowTileData, 2); + HpTextIntoHealthboxObject((void*)(OBJ_VRAM0) + spriteTileNum + 0xC0, windowTileData, 2); RemoveWindowOnHealthbox(windowId); CpuCopy32(GetHealthboxElementGfxPtr(HEALTHBOX_GFX_116), (void*)(OBJ_VRAM0 + 0x680) + (gSprites[healthboxSpriteId].oam.tileNum * 32), @@ -1271,8 +1285,8 @@ static void UpdateHpTextInHealthboxInDoubles(u8 healthboxSpriteId, s16 value, u8 text[3] = CHAR_SLASH; text[4] = EOS; windowTileData = AddTextPrinterAndCreateWindowOnHealthbox(text, 4, 5, 0, &windowId); - sub_807513C(objVram, 0, 3); - sub_8075170((void*)(OBJ_VRAM0 + 0x60) + spriteTileNum, windowTileData, 3); + FillHealthboxObject(objVram, 0, 3); // Erases HP bar leftover. + HpTextIntoHealthboxObject((void*)(OBJ_VRAM0 + 0x60) + spriteTileNum, windowTileData, 3); RemoveWindowOnHealthbox(windowId); } } @@ -1282,7 +1296,7 @@ static void UpdateHpTextInHealthboxInDoubles(u8 healthboxSpriteId, s16 value, u8 u8 battlerId; memcpy(text, sUnknown_0832C3D8, sizeof(sUnknown_0832C3D8)); - battlerId = gSprites[healthboxSpriteId].data[6]; + battlerId = gSprites[healthboxSpriteId].hMain_Battler; if (gBattleSpritesDataPtr->battlerData[battlerId].hpNumbersNoBars) // don't print text if only bars are visible { @@ -1325,7 +1339,7 @@ static void UpdateHpTextInHealthboxInDoubles(u8 healthboxSpriteId, s16 value, u8 } else { - if (GetBattlerSide(battlerId) == B_SIDE_PLAYER) // impossible to reach part, because the battlerId is from the opponent's side + if (GetBattlerSide(battlerId) == B_SIDE_PLAYER) // Impossible to reach part, because the battlerId is from the opponent's side. { CpuCopy32(GetHealthboxElementGfxPtr(HEALTHBOX_GFX_116), (void*)(OBJ_VRAM0) + ((gSprites[healthboxSpriteId].oam.tileNum + 52) * 32), @@ -1336,15 +1350,16 @@ static void UpdateHpTextInHealthboxInDoubles(u8 healthboxSpriteId, s16 value, u8 } } -static void sub_80730D4(u8 healthboxSpriteId, struct Pokemon *mon) +// Prints mon's nature and flee rate. Probably used to test pokeblock feeders. +static void PrintSafariMonInfo(u8 healthboxSpriteId, struct Pokemon *mon) { u8 text[20]; s32 j, var2; u8 *barFontGfx; - u8 i, var, nature, healthboxSpriteId_2; + u8 i, var, nature, healthBarSpriteId; memcpy(text, sUnknown_0832C3C4, sizeof(sUnknown_0832C3C4)); - barFontGfx = &gMonSpritesGfxPtr->barFontGfx[0x520 + (GetBattlerPosition(gSprites[healthboxSpriteId].data[6]) * 384)]; + barFontGfx = &gMonSpritesGfxPtr->barFontGfx[0x520 + (GetBattlerPosition(gSprites[healthboxSpriteId].hMain_Battler) * 384)]; var = 5; nature = GetNature(mon); StringCopy(text + 6, gNatureNamePointers[nature]); @@ -1375,26 +1390,26 @@ static void sub_80730D4(u8 healthboxSpriteId, struct Pokemon *mon) barFontGfx += 0x20; } - healthboxSpriteId_2 = gSprites[healthboxSpriteId].data[5]; + healthBarSpriteId = gSprites[healthboxSpriteId].hMain_HealthBarSpriteId; ConvertIntToDecimalStringN(text + 6, gBattleStruct->field_7C, STR_CONV_MODE_RIGHT_ALIGN, 2); ConvertIntToDecimalStringN(text + 9, gBattleStruct->field_7B, STR_CONV_MODE_RIGHT_ALIGN, 2); text[5] = CHAR_SPACE; text[8] = CHAR_SLASH; RenderTextFont9(gMonSpritesGfxPtr->barFontGfx, 9, text); - j = healthboxSpriteId_2; // needed to match for some reason + j = healthBarSpriteId; // Needed to match for some reason. for (j = 0; j < 5; j++) { if (j <= 1) { CpuCopy32(&gMonSpritesGfxPtr->barFontGfx[0x40 * j + 0x20], - (void*)(OBJ_VRAM0) + (gSprites[healthboxSpriteId_2].oam.tileNum + 2 + j) * 32, + (void*)(OBJ_VRAM0) + (gSprites[healthBarSpriteId].oam.tileNum + 2 + j) * 32, 32); } else { CpuCopy32(&gMonSpritesGfxPtr->barFontGfx[0x40 * j + 0x20], - (void*)(OBJ_VRAM0 + 0xC0) + (j + gSprites[healthboxSpriteId_2].oam.tileNum) * 32, + (void*)(OBJ_VRAM0 + 0xC0) + (j + gSprites[healthBarSpriteId].oam.tileNum) * 32, 32); } } @@ -1403,7 +1418,7 @@ static void sub_80730D4(u8 healthboxSpriteId, struct Pokemon *mon) void SwapHpBarsWithHpText(void) { s32 i; - u8 spriteId; + u8 healthBarSpriteId; for (i = 0; i < gBattlersCount; i++) { @@ -1424,9 +1439,9 @@ void SwapHpBarsWithHpText(void) if (noBars == TRUE) // bars to text { - spriteId = gSprites[gHealthboxSpriteIds[i]].data[5]; + healthBarSpriteId = gSprites[gHealthboxSpriteIds[i]].hMain_HealthBarSpriteId; - CpuFill32(0, (void*)(OBJ_VRAM0 + gSprites[spriteId].oam.tileNum * 32), 0x100); + CpuFill32(0, (void*)(OBJ_VRAM0 + gSprites[healthBarSpriteId].oam.tileNum * 32), 0x100); UpdateHpTextInHealthboxInDoubles(gHealthboxSpriteIds[i], GetMonData(&gPlayerParty[gBattlerPartyIndexes[i]], MON_DATA_HP), HP_CURRENT); UpdateHpTextInHealthboxInDoubles(gHealthboxSpriteIds[i], GetMonData(&gPlayerParty[gBattlerPartyIndexes[i]], MON_DATA_MAX_HP), HP_MAX); } @@ -1443,13 +1458,14 @@ void SwapHpBarsWithHpText(void) { if (gBattleTypeFlags & BATTLE_TYPE_SAFARI) { - sub_80730D4(gHealthboxSpriteIds[i], &gEnemyParty[gBattlerPartyIndexes[i]]); + // Most likely a debug function. + PrintSafariMonInfo(gHealthboxSpriteIds[i], &gEnemyParty[gBattlerPartyIndexes[i]]); } else { - spriteId = gSprites[gHealthboxSpriteIds[i]].data[5]; + healthBarSpriteId = gSprites[gHealthboxSpriteIds[i]].hMain_HealthBarSpriteId; - CpuFill32(0, (void *)(OBJ_VRAM0 + gSprites[spriteId].oam.tileNum * 32), 0x100); + CpuFill32(0, (void *)(OBJ_VRAM0 + gSprites[healthBarSpriteId].oam.tileNum * 32), 0x100); UpdateHpTextInHealthboxInDoubles(gHealthboxSpriteIds[i], GetMonData(&gEnemyParty[gBattlerPartyIndexes[i]], MON_DATA_HP), HP_CURRENT); UpdateHpTextInHealthboxInDoubles(gHealthboxSpriteIds[i], GetMonData(&gEnemyParty[gBattlerPartyIndexes[i]], MON_DATA_MAX_HP), HP_MAX); } @@ -1462,7 +1478,7 @@ void SwapHpBarsWithHpText(void) UpdateHealthboxAttribute(gHealthboxSpriteIds[i], &gEnemyParty[gBattlerPartyIndexes[i]], HEALTHBOX_NICK); } } - gSprites[gHealthboxSpriteIds[i]].data[7] ^= 1; + gSprites[gHealthboxSpriteIds[i]].hMain_Data7 ^= 1; } } } @@ -1473,7 +1489,7 @@ u8 CreatePartyStatusSummarySprites(u8 battlerId, struct HpAndStatus *partyInfo, s16 bar_X, bar_Y, bar_pos2_X, bar_data0; s32 i, j, var; u8 barSpriteId; - u8 ballIconSpritesIds[6]; + u8 ballIconSpritesIds[PARTY_SIZE]; u8 taskId; if (!arg2 || GetBattlerPosition(battlerId) != B_POSITION_OPPONENT_RIGHT) @@ -1561,7 +1577,7 @@ u8 CreatePartyStatusSummarySprites(u8 battlerId, struct HpAndStatus *partyInfo, { if (gBattleTypeFlags & BATTLE_TYPE_MULTI) { - for (i = 0; i < 6; i++) + for (i = 0; i < PARTY_SIZE; i++) { if (partyInfo[i].hp == 0xFFFF) // empty slot or an egg { @@ -1580,7 +1596,7 @@ u8 CreatePartyStatusSummarySprites(u8 battlerId, struct HpAndStatus *partyInfo, } else { - for (i = 0, var = 5, j = 0; j < 6; j++) + for (i = 0, var = 5, j = 0; j < PARTY_SIZE; j++) { if (partyInfo[j].hp == 0xFFFF) // empty slot or an egg { @@ -1609,7 +1625,7 @@ u8 CreatePartyStatusSummarySprites(u8 battlerId, struct HpAndStatus *partyInfo, { if (gBattleTypeFlags & (BATTLE_TYPE_MULTI | BATTLE_TYPE_TWO_OPPONENTS)) { - for (var = 5, i = 0; i < 6; i++) + for (var = 5, i = 0; i < PARTY_SIZE; i++) { if (partyInfo[i].hp == 0xFFFF) // empty slot or an egg { @@ -1629,7 +1645,7 @@ u8 CreatePartyStatusSummarySprites(u8 battlerId, struct HpAndStatus *partyInfo, } else { - for (var = 0, i = 0, j = 0; j < 6; j++) + for (var = 0, i = 0, j = 0; j < PARTY_SIZE; j++) { if (partyInfo[j].hp == 0xFFFF) // empty slot or an egg { @@ -1659,7 +1675,7 @@ u8 CreatePartyStatusSummarySprites(u8 battlerId, struct HpAndStatus *partyInfo, gTasks[taskId].data[0] = battlerId; gTasks[taskId].data[1] = barSpriteId; - for (i = 0; i < 6; i++) + for (i = 0; i < PARTY_SIZE; i++) gTasks[taskId].data[3 + i] = ballIconSpritesIds[i]; gTasks[taskId].data[10] = isBattleStart; @@ -1677,12 +1693,12 @@ void sub_8073C30(u8 taskId) { u8 sp[6]; u8 r7; - u8 r10; + u8 summaryBarSpriteId; u8 battlerId; s32 i; r7 = gTasks[taskId].data[10]; - r10 = gTasks[taskId].data[1]; + summaryBarSpriteId = gTasks[taskId].data[1]; battlerId = gTasks[taskId].data[0]; for (i = 0; i < 6; i++) @@ -1696,7 +1712,7 @@ void sub_8073C30(u8 taskId) for (i = 0; i < 6; i++) gSprites[sp[i]].oam.objMode = 1; - gSprites[r10].oam.objMode = 1; + gSprites[summaryBarSpriteId].oam.objMode = 1; if (r7 != 0) { @@ -1717,10 +1733,10 @@ void sub_8073C30(u8 taskId) gSprites[sp[i]].callback = sub_8074158; } } - gSprites[r10].data[0] /= 2; - gSprites[r10].data[1] = 0; - gSprites[r10].callback = sub_8074090; - SetSubspriteTables(&gSprites[r10], sUnknown_0832C2CC); + gSprites[summaryBarSpriteId].data[0] /= 2; + gSprites[summaryBarSpriteId].data[1] = 0; + gSprites[summaryBarSpriteId].callback = sub_8074090; + SetSubspriteTables(&gSprites[summaryBarSpriteId], sUnknown_0832C2CC); gTasks[taskId].func = sub_8073E08; } else @@ -1754,7 +1770,7 @@ static void sub_8073E64(u8 taskId) gTasks[taskId].data[15]--; if (gTasks[taskId].data[15] == -1) { - u8 var = gTasks[taskId].data[1]; + u8 summaryBarSpriteId = gTasks[taskId].data[1]; for (i = 0; i < 6; i++) sp[i] = gTasks[taskId].data[3 + i]; @@ -1762,13 +1778,13 @@ static void sub_8073E64(u8 taskId) gBattleSpritesDataPtr->animationData->field_9_x1C--; if (!gBattleSpritesDataPtr->animationData->field_9_x1C) { - DestroySpriteAndFreeResources(&gSprites[var]); + DestroySpriteAndFreeResources(&gSprites[summaryBarSpriteId]); DestroySpriteAndFreeResources(&gSprites[sp[0]]); } else { - FreeSpriteOamMatrix(&gSprites[var]); - DestroySprite(&gSprites[var]); + FreeSpriteOamMatrix(&gSprites[summaryBarSpriteId]); + DestroySprite(&gSprites[summaryBarSpriteId]); FreeSpriteOamMatrix(&gSprites[sp[0]]); DestroySprite(&gSprites[sp[0]]); } @@ -1798,12 +1814,12 @@ static void sub_8073F98(u8 taskId) } else if (gTasks[taskId].data[15] == -1) { - u8 var = gTasks[taskId].data[1]; + u8 summaryBarSpriteId = gTasks[taskId].data[1]; for (i = 0; i < 6; i++) sp[i] = gTasks[taskId].data[3 + i]; - DestroySpriteAndFreeResources(&gSprites[var]); + DestroySpriteAndFreeResources(&gSprites[summaryBarSpriteId]); DestroySpriteAndFreeResources(&gSprites[sp[0]]); for (i = 1; i < 6; i++) @@ -1956,17 +1972,17 @@ static void UpdateNickInHealthbox(u8 healthboxSpriteId, struct Pokemon *mon) if (GetBattlerSide(gSprites[healthboxSpriteId].data[6]) == B_SIDE_PLAYER) { - sub_8075198((void*)(0x6010040 + spriteTileNum), windowTileData, 6); + TextIntoHealthboxObject((void*)(VRAM + 0x10040 + spriteTileNum), windowTileData, 6); ptr = (void*)(OBJ_VRAM0); if (!IsDoubleBattle()) ptr += spriteTileNum + 0x800; else ptr += spriteTileNum + 0x400; - sub_8075198(ptr, windowTileData + 0xC0, 1); + TextIntoHealthboxObject(ptr, windowTileData + 0xC0, 1); } else { - sub_8075198((void*)(0x6010020 + spriteTileNum), windowTileData, 7); + TextIntoHealthboxObject((void*)(VRAM + 0x10020 + spriteTileNum), windowTileData, 7); } RemoveWindowOnHealthbox(windowId); @@ -1974,38 +1990,38 @@ static void UpdateNickInHealthbox(u8 healthboxSpriteId, struct Pokemon *mon) static void TryAddPokeballIconToHealthbox(u8 healthboxSpriteId, bool8 noStatus) { - u8 battlerId, healthboxSpriteId_2; + u8 battlerId, healthBarSpriteId; if (gBattleTypeFlags & BATTLE_TYPE_WALLY_TUTORIAL) return; if (gBattleTypeFlags & BATTLE_TYPE_TRAINER) return; - battlerId = gSprites[healthboxSpriteId].data[6]; + battlerId = gSprites[healthboxSpriteId].hMain_Battler; if (GetBattlerSide(battlerId) == B_SIDE_PLAYER) return; if (!GetSetPokedexFlag(SpeciesToNationalPokedexNum(GetMonData(&gEnemyParty[gBattlerPartyIndexes[battlerId]], MON_DATA_SPECIES)), FLAG_GET_CAUGHT)) return; - healthboxSpriteId_2 = gSprites[healthboxSpriteId].data[5]; + healthBarSpriteId = gSprites[healthboxSpriteId].hMain_HealthBarSpriteId; if (noStatus) - CpuCopy32(GetHealthboxElementGfxPtr(HEALTHBOX_GFX_70), (void*)(OBJ_VRAM0 + (gSprites[healthboxSpriteId_2].oam.tileNum + 8) * 32), 32); + CpuCopy32(GetHealthboxElementGfxPtr(HEALTHBOX_GFX_70), (void*)(OBJ_VRAM0 + (gSprites[healthBarSpriteId].oam.tileNum + 8) * 32), 32); else - CpuFill32(0, (void*)(OBJ_VRAM0 + (gSprites[healthboxSpriteId_2].oam.tileNum + 8) * 32), 32); + CpuFill32(0, (void*)(OBJ_VRAM0 + (gSprites[healthBarSpriteId].oam.tileNum + 8) * 32), 32); } static void UpdateStatusIconInHealthbox(u8 healthboxSpriteId) { s32 i; - u8 battlerId, healthboxSpriteId_2; + u8 battlerId, healthBarSpriteId; u32 status, pltAdder; const u8 *statusGfxPtr; s16 tileNumAdder; u8 statusPalId; - battlerId = gSprites[healthboxSpriteId].data[6]; - healthboxSpriteId_2 = gSprites[healthboxSpriteId].data[5]; + battlerId = gSprites[healthboxSpriteId].hMain_Battler; + healthBarSpriteId = gSprites[healthboxSpriteId].hMain_HealthBarSpriteId; if (GetBattlerSide(battlerId) == B_SIDE_PLAYER) { status = GetMonData(&gPlayerParty[gBattlerPartyIndexes[battlerId]], MON_DATA_STATUS); @@ -2022,27 +2038,27 @@ static void UpdateStatusIconInHealthbox(u8 healthboxSpriteId) if (status & STATUS1_SLEEP) { - statusGfxPtr = GetHealthboxElementGfxPtr(GetStatusIconForBankId(HEALTHBOX_GFX_STATUS_SLP_BANK0, battlerId)); + statusGfxPtr = GetHealthboxElementGfxPtr(GetStatusIconForBattlerId(HEALTHBOX_GFX_STATUS_SLP_BATTLER0, battlerId)); statusPalId = PAL_STATUS_SLP; } else if (status & STATUS1_PSN_ANY) { - statusGfxPtr = GetHealthboxElementGfxPtr(GetStatusIconForBankId(HEALTHBOX_GFX_STATUS_PSN_BANK0, battlerId)); + statusGfxPtr = GetHealthboxElementGfxPtr(GetStatusIconForBattlerId(HEALTHBOX_GFX_STATUS_PSN_BATTLER0, battlerId)); statusPalId = PAL_STATUS_PSN; } else if (status & STATUS1_BURN) { - statusGfxPtr = GetHealthboxElementGfxPtr(GetStatusIconForBankId(HEALTHBOX_GFX_STATUS_BRN_BANK0, battlerId)); + statusGfxPtr = GetHealthboxElementGfxPtr(GetStatusIconForBattlerId(HEALTHBOX_GFX_STATUS_BRN_BATTLER0, battlerId)); statusPalId = PAL_STATUS_BRN; } else if (status & STATUS1_FREEZE) { - statusGfxPtr = GetHealthboxElementGfxPtr(GetStatusIconForBankId(HEALTHBOX_GFX_STATUS_FRZ_BANK0, battlerId)); + statusGfxPtr = GetHealthboxElementGfxPtr(GetStatusIconForBattlerId(HEALTHBOX_GFX_STATUS_FRZ_BATTLER0, battlerId)); statusPalId = PAL_STATUS_FRZ; } else if (status & STATUS1_PARALYSIS) { - statusGfxPtr = GetHealthboxElementGfxPtr(GetStatusIconForBankId(HEALTHBOX_GFX_STATUS_PRZ_BANK0, battlerId)); + statusGfxPtr = GetHealthboxElementGfxPtr(GetStatusIconForBattlerId(HEALTHBOX_GFX_STATUS_PRZ_BATTLER0, battlerId)); statusPalId = PAL_STATUS_PAR; } else @@ -2053,7 +2069,7 @@ static void UpdateStatusIconInHealthbox(u8 healthboxSpriteId) CpuCopy32(statusGfxPtr, (void*)(OBJ_VRAM0 + (gSprites[healthboxSpriteId].oam.tileNum + tileNumAdder + i) * 32), 32); if (!gBattleSpritesDataPtr->battlerData[battlerId].hpNumbersNoBars) - CpuCopy32(GetHealthboxElementGfxPtr(HEALTHBOX_GFX_1), (void *)(OBJ_VRAM0 + gSprites[healthboxSpriteId_2].oam.tileNum * 32), 64); + CpuCopy32(GetHealthboxElementGfxPtr(HEALTHBOX_GFX_1), (void *)(OBJ_VRAM0 + gSprites[healthBarSpriteId].oam.tileNum * 32), 64); TryAddPokeballIconToHealthbox(healthboxSpriteId, TRUE); return; @@ -2069,68 +2085,68 @@ static void UpdateStatusIconInHealthbox(u8 healthboxSpriteId) { if (!gBattleSpritesDataPtr->battlerData[battlerId].hpNumbersNoBars) { - CpuCopy32(GetHealthboxElementGfxPtr(HEALTHBOX_GFX_0), (void*)(OBJ_VRAM0 + gSprites[healthboxSpriteId_2].oam.tileNum * 32), 32); - CpuCopy32(GetHealthboxElementGfxPtr(HEALTHBOX_GFX_65), (void*)(OBJ_VRAM0 + (gSprites[healthboxSpriteId_2].oam.tileNum + 1) * 32), 32); + CpuCopy32(GetHealthboxElementGfxPtr(HEALTHBOX_GFX_0), (void*)(OBJ_VRAM0 + gSprites[healthBarSpriteId].oam.tileNum * 32), 32); + CpuCopy32(GetHealthboxElementGfxPtr(HEALTHBOX_GFX_65), (void*)(OBJ_VRAM0 + (gSprites[healthBarSpriteId].oam.tileNum + 1) * 32), 32); } } TryAddPokeballIconToHealthbox(healthboxSpriteId, FALSE); } -static u8 GetStatusIconForBankId(u8 statusElementId, u8 battlerId) +static u8 GetStatusIconForBattlerId(u8 statusElementId, u8 battlerId) { u8 ret = statusElementId; switch (statusElementId) { - case HEALTHBOX_GFX_STATUS_PSN_BANK0: + case HEALTHBOX_GFX_STATUS_PSN_BATTLER0: if (battlerId == 0) - ret = HEALTHBOX_GFX_STATUS_PSN_BANK0; + ret = HEALTHBOX_GFX_STATUS_PSN_BATTLER0; else if (battlerId == 1) - ret = HEALTHBOX_GFX_STATUS_PSN_BANK1; + ret = HEALTHBOX_GFX_STATUS_PSN_BATTLER1; else if (battlerId == 2) - ret = HEALTHBOX_GFX_STATUS_PSN_BANK2; + ret = HEALTHBOX_GFX_STATUS_PSN_BATTLER2; else - ret = HEALTHBOX_GFX_STATUS_PSN_BANK3; + ret = HEALTHBOX_GFX_STATUS_PSN_BATTLER3; break; - case HEALTHBOX_GFX_STATUS_PRZ_BANK0: + case HEALTHBOX_GFX_STATUS_PRZ_BATTLER0: if (battlerId == 0) - ret = HEALTHBOX_GFX_STATUS_PRZ_BANK0; + ret = HEALTHBOX_GFX_STATUS_PRZ_BATTLER0; else if (battlerId == 1) - ret = HEALTHBOX_GFX_STATUS_PRZ_BANK1; + ret = HEALTHBOX_GFX_STATUS_PRZ_BATTLER1; else if (battlerId == 2) - ret = HEALTHBOX_GFX_STATUS_PRZ_BANK2; + ret = HEALTHBOX_GFX_STATUS_PRZ_BATTLER2; else - ret = HEALTHBOX_GFX_STATUS_PRZ_BANK3; + ret = HEALTHBOX_GFX_STATUS_PRZ_BATTLER3; break; - case HEALTHBOX_GFX_STATUS_SLP_BANK0: + case HEALTHBOX_GFX_STATUS_SLP_BATTLER0: if (battlerId == 0) - ret = HEALTHBOX_GFX_STATUS_SLP_BANK0; + ret = HEALTHBOX_GFX_STATUS_SLP_BATTLER0; else if (battlerId == 1) - ret = HEALTHBOX_GFX_STATUS_SLP_BANK1; + ret = HEALTHBOX_GFX_STATUS_SLP_BATTLER1; else if (battlerId == 2) - ret = HEALTHBOX_GFX_STATUS_SLP_BANK2; + ret = HEALTHBOX_GFX_STATUS_SLP_BATTLER2; else - ret = HEALTHBOX_GFX_STATUS_SLP_BANK3; + ret = HEALTHBOX_GFX_STATUS_SLP_BATTLER3; break; - case HEALTHBOX_GFX_STATUS_FRZ_BANK0: + case HEALTHBOX_GFX_STATUS_FRZ_BATTLER0: if (battlerId == 0) - ret = HEALTHBOX_GFX_STATUS_FRZ_BANK0; + ret = HEALTHBOX_GFX_STATUS_FRZ_BATTLER0; else if (battlerId == 1) - ret = HEALTHBOX_GFX_STATUS_FRZ_BANK1; + ret = HEALTHBOX_GFX_STATUS_FRZ_BATTLER1; else if (battlerId == 2) - ret = HEALTHBOX_GFX_STATUS_FRZ_BANK2; + ret = HEALTHBOX_GFX_STATUS_FRZ_BATTLER2; else - ret = HEALTHBOX_GFX_STATUS_FRZ_BANK3; + ret = HEALTHBOX_GFX_STATUS_FRZ_BATTLER3; break; - case HEALTHBOX_GFX_STATUS_BRN_BANK0: + case HEALTHBOX_GFX_STATUS_BRN_BATTLER0: if (battlerId == 0) - ret = HEALTHBOX_GFX_STATUS_BRN_BANK0; + ret = HEALTHBOX_GFX_STATUS_BRN_BATTLER0; else if (battlerId == 1) - ret = HEALTHBOX_GFX_STATUS_BRN_BANK1; + ret = HEALTHBOX_GFX_STATUS_BRN_BATTLER1; else if (battlerId == 2) - ret = HEALTHBOX_GFX_STATUS_BRN_BANK2; + ret = HEALTHBOX_GFX_STATUS_BRN_BATTLER2; else - ret = HEALTHBOX_GFX_STATUS_BRN_BANK3; + ret = HEALTHBOX_GFX_STATUS_BRN_BATTLER3; break; } return ret; @@ -2143,8 +2159,8 @@ static void UpdateSafariBallsTextOnHealthbox(u8 healthboxSpriteId) windowTileData = AddTextPrinterAndCreateWindowOnHealthbox(gText_SafariBalls, 0, 3, 2, &windowId); spriteTileNum = gSprites[healthboxSpriteId].oam.tileNum * 32; - sub_8075198((void*)(OBJ_VRAM0 + 0x40) + spriteTileNum, windowTileData, 6); - sub_8075198((void*)(OBJ_VRAM0 + 0x800) + spriteTileNum, windowTileData + 0xC0, 2); + TextIntoHealthboxObject((void*)(OBJ_VRAM0 + 0x40) + spriteTileNum, windowTileData, 6); + TextIntoHealthboxObject((void*)(OBJ_VRAM0 + 0x800) + spriteTileNum, windowTileData + 0xC0, 2); RemoveWindowOnHealthbox(windowId); } @@ -2160,20 +2176,20 @@ static void UpdateLeftNoOfBallsTextOnHealthbox(u8 healthboxSpriteId) windowTileData = AddTextPrinterAndCreateWindowOnHealthbox(text, GetStringRightAlignXOffset(0, text, 0x2F), 3, 2, &windowId); spriteTileNum = gSprites[healthboxSpriteId].oam.tileNum * 32; - sub_80751E4((void*)(OBJ_VRAM0 + 0x2C0) + spriteTileNum, windowTileData, 2); - sub_80751E4((void*)(OBJ_VRAM0 + 0xA00) + spriteTileNum, windowTileData + 0x40, 4); + SafariTextIntoHealthboxObject((void*)(OBJ_VRAM0 + 0x2C0) + spriteTileNum, windowTileData, 2); + SafariTextIntoHealthboxObject((void*)(OBJ_VRAM0 + 0xA00) + spriteTileNum, windowTileData + 0x40, 4); RemoveWindowOnHealthbox(windowId); } void UpdateHealthboxAttribute(u8 healthboxSpriteId, struct Pokemon *mon, u8 elementId) { s32 maxHp, currHp; - u8 battlerId = gSprites[healthboxSpriteId].data[6]; + u8 battlerId = gSprites[healthboxSpriteId].hMain_Battler; if (elementId == HEALTHBOX_ALL && !IsDoubleBattle()) - GetBattlerSide(battlerId); // pointless function call + GetBattlerSide(battlerId); // Pointless function call. - if (GetBattlerSide(gSprites[healthboxSpriteId].data[6]) == B_SIDE_PLAYER) + if (GetBattlerSide(gSprites[healthboxSpriteId].hMain_Battler) == B_SIDE_PLAYER) { u8 isDoubles; @@ -2189,7 +2205,7 @@ void UpdateHealthboxAttribute(u8 healthboxSpriteId, struct Pokemon *mon, u8 elem maxHp = GetMonData(mon, MON_DATA_MAX_HP); currHp = GetMonData(mon, MON_DATA_HP); SetBattleBarStruct(battlerId, healthboxSpriteId, maxHp, currHp, 0); - sub_8074AA0(battlerId, healthboxSpriteId, HEALTH_BAR, 0); + MoveBattleBar(battlerId, healthboxSpriteId, HEALTH_BAR, 0); } isDoubles = IsDoubleBattle(); if (!isDoubles && (elementId == HEALTHBOX_EXP_BAR || elementId == HEALTHBOX_ALL)) @@ -2207,7 +2223,7 @@ void UpdateHealthboxAttribute(u8 healthboxSpriteId, struct Pokemon *mon, u8 elem currExpBarValue = exp - currLevelExp; maxExpBarValue = gExperienceTables[gBaseStats[species].growthRate][level + 1] - currLevelExp; SetBattleBarStruct(battlerId, healthboxSpriteId, maxExpBarValue, currExpBarValue, isDoubles); - sub_8074AA0(battlerId, healthboxSpriteId, EXP_BAR, 0); + MoveBattleBar(battlerId, healthboxSpriteId, EXP_BAR, 0); } if (elementId == HEALTHBOX_NICK || elementId == HEALTHBOX_ALL) UpdateNickInHealthbox(healthboxSpriteId, mon); @@ -2228,7 +2244,7 @@ void UpdateHealthboxAttribute(u8 healthboxSpriteId, struct Pokemon *mon, u8 elem maxHp = GetMonData(mon, MON_DATA_MAX_HP); currHp = GetMonData(mon, MON_DATA_HP); SetBattleBarStruct(battlerId, healthboxSpriteId, maxHp, currHp, 0); - sub_8074AA0(battlerId, healthboxSpriteId, HEALTH_BAR, 0); + MoveBattleBar(battlerId, healthboxSpriteId, HEALTH_BAR, 0); } if (elementId == HEALTHBOX_NICK || elementId == HEALTHBOX_ALL) UpdateNickInHealthbox(healthboxSpriteId, mon); @@ -2237,82 +2253,86 @@ void UpdateHealthboxAttribute(u8 healthboxSpriteId, struct Pokemon *mon, u8 elem } } -s32 sub_8074AA0(u8 battlerId, u8 healthboxSpriteId, u8 whichBar, u8 arg3) +#define EXPBAR_PIXELS 64 +#define HEALTHBAR_PIXELS 48 + +s32 MoveBattleBar(u8 battlerId, u8 healthboxSpriteId, u8 whichBar, u8 unused) { - s32 var; + s32 currentBarValue; if (whichBar == HEALTH_BAR) // health bar { - var = sub_8074DB8(gBattleSpritesDataPtr->battleBars[battlerId].maxValue, - gBattleSpritesDataPtr->battleBars[battlerId].currentValue, + currentBarValue = CalcNewBarValue(gBattleSpritesDataPtr->battleBars[battlerId].maxValue, + gBattleSpritesDataPtr->battleBars[battlerId].oldValue, gBattleSpritesDataPtr->battleBars[battlerId].receivedValue, - &gBattleSpritesDataPtr->battleBars[battlerId].field_10, - 6, 1); + &gBattleSpritesDataPtr->battleBars[battlerId].currValue, + HEALTHBAR_PIXELS / 8, 1); } else // exp bar { - u16 expFraction = GetScaledExpFraction(gBattleSpritesDataPtr->battleBars[battlerId].currentValue, + u16 expFraction = GetScaledExpFraction(gBattleSpritesDataPtr->battleBars[battlerId].oldValue, gBattleSpritesDataPtr->battleBars[battlerId].receivedValue, gBattleSpritesDataPtr->battleBars[battlerId].maxValue, 8); if (expFraction == 0) expFraction = 1; expFraction = abs(gBattleSpritesDataPtr->battleBars[battlerId].receivedValue / expFraction); - var = sub_8074DB8(gBattleSpritesDataPtr->battleBars[battlerId].maxValue, - gBattleSpritesDataPtr->battleBars[battlerId].currentValue, + currentBarValue = CalcNewBarValue(gBattleSpritesDataPtr->battleBars[battlerId].maxValue, + gBattleSpritesDataPtr->battleBars[battlerId].oldValue, gBattleSpritesDataPtr->battleBars[battlerId].receivedValue, - &gBattleSpritesDataPtr->battleBars[battlerId].field_10, - 8, expFraction); + &gBattleSpritesDataPtr->battleBars[battlerId].currValue, + EXPBAR_PIXELS / 8, expFraction); } if (whichBar == EXP_BAR || (whichBar == HEALTH_BAR && !gBattleSpritesDataPtr->battlerData[battlerId].hpNumbersNoBars)) - sub_8074B9C(battlerId, whichBar); + MoveBattleBarGraphically(battlerId, whichBar); - if (var == -1) - gBattleSpritesDataPtr->battleBars[battlerId].field_10 = 0; + if (currentBarValue == -1) + gBattleSpritesDataPtr->battleBars[battlerId].currValue = 0; - return var; + return currentBarValue; } -static void sub_8074B9C(u8 battlerId, u8 whichBar) +static void MoveBattleBarGraphically(u8 battlerId, u8 whichBar) { u8 array[8]; - u8 subRet, level; + u8 filledPixelsCount, level; u8 barElementId; u8 i; switch (whichBar) { case HEALTH_BAR: - subRet = sub_8074E8C(gBattleSpritesDataPtr->battleBars[battlerId].maxValue, - gBattleSpritesDataPtr->battleBars[battlerId].currentValue, + filledPixelsCount = CalcBarFilledPixels(gBattleSpritesDataPtr->battleBars[battlerId].maxValue, + gBattleSpritesDataPtr->battleBars[battlerId].oldValue, gBattleSpritesDataPtr->battleBars[battlerId].receivedValue, - &gBattleSpritesDataPtr->battleBars[battlerId].field_10, - array, 6); - barElementId = 3; - if (subRet <= 0x18) - { - barElementId = 0x38; - if (subRet > 9) - barElementId = 0x2F; - } + &gBattleSpritesDataPtr->battleBars[battlerId].currValue, + array, HEALTHBAR_PIXELS / 8); + + if (filledPixelsCount > (HEALTHBAR_PIXELS * 50 / 100)) // more than 50 % hp + barElementId = HEALTHBOX_GFX_HP_BAR_GREEN; + else if (filledPixelsCount > (HEALTHBAR_PIXELS * 20 / 100)) // more than 20% hp + barElementId = HEALTHBOX_GFX_HP_BAR_YELLOW; + else + barElementId = HEALTHBOX_GFX_HP_BAR_RED; // 20 % or less + for (i = 0; i < 6; i++) { - u8 healthboxSpriteId_2 = gSprites[gBattleSpritesDataPtr->battleBars[battlerId].healthboxSpriteId].data[5]; + u8 healthbarSpriteId = gSprites[gBattleSpritesDataPtr->battleBars[battlerId].healthboxSpriteId].hMain_HealthBarSpriteId; if (i < 2) CpuCopy32(GetHealthboxElementGfxPtr(barElementId) + array[i] * 32, - (void*)(OBJ_VRAM0 + (gSprites[healthboxSpriteId_2].oam.tileNum + 2 + i) * 32), 32); + (void*)(OBJ_VRAM0 + (gSprites[healthbarSpriteId].oam.tileNum + 2 + i) * 32), 32); else CpuCopy32(GetHealthboxElementGfxPtr(barElementId) + array[i] * 32, - (void*)(OBJ_VRAM0 + 64 + (i + gSprites[healthboxSpriteId_2].oam.tileNum) * 32), 32); + (void*)(OBJ_VRAM0 + 64 + (i + gSprites[healthbarSpriteId].oam.tileNum) * 32), 32); } break; case EXP_BAR: - sub_8074E8C(gBattleSpritesDataPtr->battleBars[battlerId].maxValue, - gBattleSpritesDataPtr->battleBars[battlerId].currentValue, + CalcBarFilledPixels(gBattleSpritesDataPtr->battleBars[battlerId].maxValue, + gBattleSpritesDataPtr->battleBars[battlerId].oldValue, gBattleSpritesDataPtr->battleBars[battlerId].receivedValue, - &gBattleSpritesDataPtr->battleBars[battlerId].field_10, - array, 8); + &gBattleSpritesDataPtr->battleBars[battlerId].currValue, + array, EXPBAR_PIXELS / 8); level = GetMonData(&gPlayerParty[gBattlerPartyIndexes[battlerId]], MON_DATA_LEVEL); if (level == MAX_MON_LEVEL) { @@ -2332,149 +2352,145 @@ static void sub_8074B9C(u8 battlerId, u8 whichBar) } } -static s32 sub_8074DB8(s32 maxValue, s32 currValue, s32 receivedValue, s32 *arg3, u8 arg4, u16 arg5) +static s32 CalcNewBarValue(s32 maxValue, s32 oldValue, s32 receivedValue, s32 *currValue, u8 scale, u16 toAdd) { - s32 r6; - s32 ret; - arg4 <<= 3; + s32 ret, newValue; + scale *= 8; - if (*arg3 == -32768) + if (*currValue == -32768) // first function call { - if (maxValue < arg4) - *arg3 = currValue << 8; + if (maxValue < scale) + *currValue = oldValue << 8; else - *arg3 = currValue; + *currValue = oldValue; } - currValue -= receivedValue; - if (currValue < 0) - currValue = 0; - else if (currValue > maxValue) - currValue = maxValue; + newValue = oldValue - receivedValue; + if (newValue < 0) + newValue = 0; + else if (newValue > maxValue) + newValue = maxValue; - if (maxValue < arg4) + if (maxValue < scale) { - s32 var = *arg3 >> 8; + s32 var = *currValue >> 8; - r6 = *arg3; - if (currValue == var && (r6 & 0xFF) == 0) + if (newValue == var && (*currValue & 0xFF) == 0) return -1; } else { - r6 = *arg3; - if (currValue == r6) + if (newValue == *currValue) // we're done, the bar's value has been updated return -1; } - if (maxValue < arg4) + if (maxValue < scale) // handle cases of max var having less pixels than the whole bar { - s32 var = (maxValue << 8) / arg4; + s32 var = (maxValue << 8) / scale; - if (receivedValue < 0) + if (receivedValue < 0) // fill bar right { - *arg3 = r6 + var; - ret = *arg3 >> 8; - if (ret >= currValue) + *currValue += var; + ret = *currValue >> 8; + if (ret >= newValue) { - *arg3 = currValue << 8; - ret = currValue; + *currValue = newValue << 8; + ret = newValue; } } - else + else // move bar left { - *arg3 = r6 - var; - ret = *arg3 >> 8; - if ((*arg3 & 0xFF) > 0) + *currValue -= var; + ret = *currValue >> 8; + if ((*currValue & 0xFF) > 0) ret++; - if (ret <= currValue) + if (ret <= newValue) { - *arg3 = currValue << 8; - ret = currValue; + *currValue = newValue << 8; + ret = newValue; } } } else { - if (receivedValue < 0) + if (receivedValue < 0) // fill bar right { - *arg3 += arg5; - if (*arg3 > currValue) - *arg3 = currValue; - ret = *arg3; + *currValue += toAdd; + if (*currValue > newValue) + *currValue = newValue; + ret = *currValue; } - else + else // move bar left { - *arg3 -= arg5; - if (*arg3 < currValue) - *arg3 = currValue; - ret = *arg3; + *currValue -= toAdd; + if (*currValue < newValue) + *currValue = newValue; + ret = *currValue; } } return ret; } -static u8 sub_8074E8C(s32 maxValue, s32 currValue, s32 receivedValue, s32 *arg3, u8 *arg4, u8 arg5) +static u8 CalcBarFilledPixels(s32 maxValue, s32 oldValue, s32 receivedValue, s32 *currValue, u8 *arg4, u8 scale) { - s32 r5 = currValue - receivedValue; - u8 ret; + u8 pixels, filledPixels, totalPixels; u8 i; - u8 r2; - if (r5 < 0) - r5 = 0; - else if (r5 > maxValue) - r5 = maxValue; + s32 newValue = oldValue - receivedValue; + if (newValue < 0) + newValue = 0; + else if (newValue > maxValue) + newValue = maxValue; - ret = arg5 << 3; + totalPixels = scale * 8; - for (i = 0; i < arg5; i++) + for (i = 0; i < scale; i++) arg4[i] = 0; - if (maxValue < ret) - r2 = (*arg3 * ret / maxValue) >> 8; + if (maxValue < totalPixels) + pixels = (*currValue * totalPixels / maxValue) >> 8; else - r2 = *arg3 * ret / maxValue; + pixels = *currValue * totalPixels / maxValue; - ret = r2; + filledPixels = pixels; - if (ret == 0 && r5 > 0) + if (filledPixels == 0 && newValue > 0) { arg4[0] = 1; - ret = 1; + filledPixels = 1; } else { - for (i = 0; i < arg5; i++) + for (i = 0; i < scale; i++) { - if (r2 >= 8) + if (pixels >= 8) { arg4[i] = 8; } else { - arg4[i] = r2; + arg4[i] = pixels; break; } - r2 -= 8; + pixels -= 8; } } - return ret; + return filledPixels; } static s16 sub_8074F28(struct TestingBar *barInfo, s32 *arg1, u16 *arg2, s32 arg3) { s16 ret, var; - ret = sub_8074DB8(barInfo->maxValue, - barInfo->currValue, + ret = CalcNewBarValue(barInfo->maxValue, + barInfo->oldValue, barInfo->receivedValue, arg1, 6, 1); sub_8074F88(barInfo, arg1, arg2); - if (barInfo->maxValue < 0x30) + if (barInfo->maxValue < HEALTHBAR_PIXELS) var = *arg1 >> 8; else var = *arg1; @@ -2490,7 +2506,7 @@ static void sub_8074F88(struct TestingBar *barInfo, s32 *arg1, u16 *arg2) u16 sp10[6]; u8 i; - sub_8074E8C(barInfo->maxValue, barInfo->currValue, + CalcBarFilledPixels(barInfo->maxValue, barInfo->oldValue, barInfo->receivedValue, arg1, sp8, 6); for (i = 0; i < 6; i++) @@ -2499,22 +2515,22 @@ static void sub_8074F88(struct TestingBar *barInfo, s32 *arg1, u16 *arg2) CpuCopy16(sp10, arg2, sizeof(sp10)); } -static u8 GetScaledExpFraction(s32 currValue, s32 receivedValue, s32 maxValue, u8 scale) +static u8 GetScaledExpFraction(s32 oldValue, s32 receivedValue, s32 maxValue, u8 scale) { - s32 r5, result; - s8 r4, r0; + s32 newVal, result; + s8 oldToMax, newToMax; scale *= 8; - r5 = currValue - receivedValue; + newVal = oldValue - receivedValue; - if (r5 < 0) - r5 = 0; - else if (r5 > maxValue) - r5 = maxValue; + if (newVal < 0) + newVal = 0; + else if (newVal > maxValue) + newVal = maxValue; - r4 = currValue * scale / maxValue; - r0 = r5 * scale / maxValue; - result = r4 - r0; + oldToMax = oldValue * scale / maxValue; + newToMax = newVal * scale / maxValue; + result = oldToMax - newToMax; return abs(result); } @@ -2577,17 +2593,17 @@ static void RemoveWindowOnHealthbox(u32 windowId) RemoveWindow(windowId); } -static void sub_807513C(void *dest, u32 arg1, u32 arg2) +static void FillHealthboxObject(void *dest, u32 arg1, u32 arg2) { CpuFill32(0x11111111 * arg1, dest, arg2 * 32); } -static void sub_8075170(void *dest, u8 *windowTileData, u32 arg2) +static void HpTextIntoHealthboxObject(void *dest, u8 *windowTileData, u32 arg2) { CpuCopy32(windowTileData + 256, dest, arg2 * 32); } -static void sub_8075198(void *dest, u8 *windowTileData, s32 arg2) +static void TextIntoHealthboxObject(void *dest, u8 *windowTileData, s32 arg2) { CpuCopy32(windowTileData + 256, dest + 256, arg2 * 32); @@ -2596,13 +2612,13 @@ static void sub_8075198(void *dest, u8 *windowTileData, s32 arg2) do { CpuCopy32(windowTileData + 20, dest + 20, 12); - dest += 32, windowTileData+= 32; + dest += 32, windowTileData += 32; arg2--; } while (arg2 != 0); } } -static void sub_80751E4(void *dest, u8 *windowTileData, u32 arg2) +static void SafariTextIntoHealthboxObject(void *dest, u8 *windowTileData, u32 arg2) { CpuCopy32(windowTileData, dest, arg2 * 32); CpuCopy32(windowTileData + 256, dest + 256, arg2 * 32); diff --git a/src/pokeball.c b/src/pokeball.c index 8173c4a90..3dbbb2967 100644 --- a/src/pokeball.c +++ b/src/pokeball.c @@ -665,7 +665,7 @@ static void Task_PlayCryWhenReleasedFromBall(u8 taskId) gTasks[taskId].tCryTaskState = wantedCry + 1; break; case 1: - if (ShouldPlayNormalPokeCry(mon) == TRUE) + if (ShouldPlayNormalMonCry(mon) == TRUE) PlayCry3(species, pan, 0); else PlayCry3(species, pan, 11); @@ -680,7 +680,7 @@ static void Task_PlayCryWhenReleasedFromBall(u8 taskId) case 20: if (gTasks[taskId].tCryTaskFrames == 0) { - if (ShouldPlayNormalPokeCry(mon) == TRUE) + if (ShouldPlayNormalMonCry(mon) == TRUE) PlayCry4(species, pan, 1); else PlayCry4(species, pan, 12); @@ -719,7 +719,7 @@ static void Task_PlayCryWhenReleasedFromBall(u8 taskId) gTasks[taskId].tCryTaskFrames--; break; } - if (ShouldPlayNormalPokeCry(mon) == TRUE) + if (ShouldPlayNormalMonCry(mon) == TRUE) PlayCry4(species, pan, 0); else PlayCry4(species, pan, 11); From ab36efdaf4a7f64df9bbfae153eb88cd9c5b29b0 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Wed, 20 Jun 2018 23:07:51 +0200 Subject: [PATCH 03/15] document bounce effect --- include/battle.h | 106 ++++++------ include/battle_controllers.h | 8 +- include/battle_main.h | 12 +- include/global.h | 6 + src/battle_controller_link_opponent.c | 8 +- src/battle_controller_link_partner.c | 6 +- src/battle_controller_opponent.c | 8 +- src/battle_controller_player.c | 34 ++-- src/battle_controller_player_partner.c | 6 +- src/battle_controller_recorded_opponent.c | 8 +- src/battle_controller_recorded_player.c | 6 +- src/battle_controller_safari.c | 6 +- src/battle_controller_wally.c | 6 +- src/battle_controllers.c | 10 +- src/battle_interface.c | 197 +++++++++++---------- src/battle_main.c | 200 ++++++++++++---------- src/hall_of_fame.c | 2 +- 17 files changed, 330 insertions(+), 299 deletions(-) diff --git a/include/battle.h b/include/battle.h index 62caa2cfe..2651407fb 100644 --- a/include/battle.h +++ b/include/battle.h @@ -33,7 +33,7 @@ #define B_ACTION_SAFARI_GO_NEAR 7 #define B_ACTION_SAFARI_RUN 8 // The exact purposes of these are unclear -#define B_ACTION_UNKNOWN9 9 +#define B_ACTION_WALLY_THROW 9 #define B_ACTION_EXEC_SCRIPT 10 // when executing an action #define B_ACTION_CANCEL_PARTNER 12 // when choosing an action #define B_ACTION_FINISHED 12 // when executing an action @@ -150,29 +150,29 @@ struct DisableStruct /*0x08*/ u8 protectUses; /*0x09*/ u8 stockpileCounter; /*0x0A*/ u8 substituteHP; - /*0x0B*/ u8 disableTimer1 : 4; - /*0x0B*/ u8 disableTimer2 : 4; + /*0x0B*/ u8 disableTimer1:4; + /*0x0B*/ u8 disableTimer2:4; /*0x0C*/ u8 encoredMovePos; /*0x0D*/ u8 unkD; - /*0x0E*/ u8 encoreTimer1 : 4; - /*0x0E*/ u8 encoreTimer2 : 4; - /*0x0F*/ u8 perishSongTimer1 : 4; - /*0x0F*/ u8 perishSongTimer2 : 4; + /*0x0E*/ u8 encoreTimer1:4; + /*0x0E*/ u8 encoreTimer2:4; + /*0x0F*/ u8 perishSongTimer1:4; + /*0x0F*/ u8 perishSongTimer2:4; /*0x10*/ u8 furyCutterCounter; - /*0x11*/ u8 rolloutCounter1 : 4; - /*0x11*/ u8 rolloutCounter2 : 4; - /*0x12*/ u8 chargeTimer1 : 4; - /*0x12*/ u8 chargeTimer2 : 4; + /*0x11*/ u8 rolloutCounter1:4; + /*0x11*/ u8 rolloutCounter2:4; + /*0x12*/ u8 chargeTimer1:4; + /*0x12*/ u8 chargeTimer2:4; /*0x13*/ u8 tauntTimer1:4; /*0x13*/ u8 tauntTimer2:4; /*0x14*/ u8 battlerPreventingEscape; /*0x15*/ u8 battlerWithSureHit; /*0x16*/ u8 isFirstTurn; /*0x17*/ u8 unk17; - /*0x18*/ u8 truantCounter : 1; - /*0x18*/ u8 truantUnknownBit : 1; - /*0x18*/ u8 unk18_a_2 : 2; - /*0x18*/ u8 unk18_b : 4; + /*0x18*/ u8 truantCounter:1; + /*0x18*/ u8 truantUnknownBit:1; + /*0x18*/ u8 unk18_a_2:2; + /*0x18*/ u8 unk18_b:4; /*0x19*/ u8 rechargeCounter; /*0x1A*/ u8 unk1A[2]; }; @@ -201,12 +201,12 @@ struct ProtectStruct u32 flag2Unknown:1; // 0x2 u32 flinchImmobility:1; // 0x4 u32 notFirstStrike:1; // 0x8 - u32 flag_x10 : 1; // 0x10 - u32 flag_x20 : 1; // 0x20 - u32 flag_x40 : 1; // 0x40 - u32 flag_x80 : 1; // 0x80 + u32 flag_x10:1; // 0x10 + u32 flag_x20:1; // 0x20 + u32 flag_x40:1; // 0x40 + u32 flag_x80:1; // 0x80 /* field_3 */ - u32 field3 : 8; + u32 field3:8; /* field_4 */ u32 physicalDmg; /* field_8 */ u32 specialDmg; @@ -217,14 +217,14 @@ struct ProtectStruct struct SpecialStatus { - u8 statLowered : 1; // 0x1 - u8 lightningRodRedirected : 1; // 0x2 + u8 statLowered:1; // 0x1 + u8 lightningRodRedirected:1; // 0x2 u8 restoredBankSprite: 1; // 0x4 - u8 intimidatedPoke : 1; // 0x8 - u8 traced : 1; // 0x10 - u8 flag20 : 1; - u8 flag40 : 1; - u8 focusBanded : 1; + u8 intimidatedPoke:1; // 0x8 + u8 traced:1; // 0x10 + u8 flag20:1; + u8 flag40:1; + u8 focusBanded:1; u8 field1[3]; s32 dmg; s32 physicalDmg; @@ -629,11 +629,11 @@ u8 GetBattlerAtPosition(u8 bank); struct BattleSpriteInfo { - u16 invisible : 1; // 0x1 - u16 lowHpSong : 1; // 0x2 - u16 behindSubstitute : 1; // 0x4 - u16 flag_x8 : 1; // 0x8 - u16 hpNumbersNoBars : 1; // 0x10 + u16 invisible:1; // 0x1 + u16 lowHpSong:1; // 0x2 + u16 behindSubstitute:1; // 0x4 + u16 flag_x8:1; // 0x8 + u16 hpNumbersNoBars:1; // 0x10 u16 transformSpecies; }; @@ -647,12 +647,12 @@ struct BattleAnimationInfo u8 field_6; u8 field_7; u8 ballThrowCaseId; - u8 field_9_x1 : 1; - u8 field_9_x2 : 1; - u8 field_9_x1C : 3; - u8 field_9_x20 : 1; - u8 field_9_x40 : 1; - u8 field_9_x80 : 1; + u8 field_9_x1:1; + u8 field_9_x2:1; + u8 field_9_x1C:3; + u8 field_9_x20:1; + u8 field_9_x40:1; + u8 field_9_x80:1; u8 field_A; u8 field_B; u8 field_C; @@ -663,21 +663,21 @@ struct BattleAnimationInfo struct BattleHealthboxInfo { - u8 flag_x1 : 1; - u8 flag_x2 : 1; - u8 flag_x4 : 1; - u8 ballAnimActive : 1; // 0x8 - u8 statusAnimActive : 1; // x10 - u8 animFromTableActive : 1; // x20 - u8 specialAnimActive : 1; //x40 - u8 flag_x80 : 1; - u8 field_1_x1 : 1; - u8 field_1_x1E : 4; - u8 field_1_x20 : 1; - u8 field_1_x40 : 1; - u8 field_1_x80 : 1; - u8 field_2; - u8 field_3; + u8 flag_x1:1; + u8 healthboxIsBouncing:1; + u8 battlerIsBouncing:1; + u8 ballAnimActive:1; // 0x8 + u8 statusAnimActive:1; // x10 + u8 animFromTableActive:1; // x20 + u8 specialAnimActive:1; //x40 + u8 flag_x80:1; + u8 field_1_x1:1; + u8 field_1_x1E:4; + u8 field_1_x20:1; + u8 field_1_x40:1; + u8 field_1_x80:1; + u8 healthboxBounceSpriteId; + u8 battlerBounceSpriteId; u8 animationState; u8 field_5; u8 field_6; diff --git a/include/battle_controllers.h b/include/battle_controllers.h index a0fc41b52..c5f5f48d7 100644 --- a/include/battle_controllers.h +++ b/include/battle_controllers.h @@ -82,8 +82,8 @@ enum struct UnusedControllerStruct { - u8 field_0 : 7; - u8 flag_x80 : 1; + u8 field_0:7; + u8 flag_x80:1; }; struct HpAndStatus @@ -161,7 +161,7 @@ enum CONTROLLER_INTROTRAINERBALLTHROW, CONTROLLER_DRAWPARTYSTATUSSUMMARY, CONTROLLER_49, - CONTROLLER_50, + CONTROLLER_ENDBOUNCE, CONTROLLER_SPRITEINVISIBILITY, CONTROLLER_BATTLEANIMATION, CONTROLLER_LINKSTANDBYMSG, @@ -231,7 +231,7 @@ void BtlController_EmitIntroSlide(u8 bufferId, u8 terrainId); void BtlController_EmitIntroTrainerBallThrow(u8 bufferId); void BtlController_EmitDrawPartyStatusSummary(u8 bufferId, struct HpAndStatus* hpAndStatus, u8 arg2); void BtlController_EmitCmd49(u8 bufferId); -void BtlController_EmitCmd50(u8 bufferId); +void BtlController_EmitEndBounceEffect(u8 bufferId); void BtlController_EmitSpriteInvisibility(u8 bufferId, bool8 isInvisible); void BtlController_EmitBattleAnimation(u8 bufferId, u8 animationId, u16 argument); void BtlController_EmitLinkStandbyMsg(u8 bufferId, u8 arg1, bool32 arg2); diff --git a/include/battle_main.h b/include/battle_main.h index a725b631f..27e61c8fc 100644 --- a/include/battle_main.h +++ b/include/battle_main.h @@ -25,6 +25,10 @@ struct TrainerMoney #define TYPE_FORESIGHT 0xFE #define TYPE_ENDTABLE 0xFF +// defines for the 'DoBounceEffect' function +#define BOUNCE_MON 0x0 +#define BOUNCE_HEALTHBOX 0x1 + void CB2_InitBattle(void); void BattleMainCB2(void); void CB2_QuitRecordedBattle(void); @@ -38,15 +42,15 @@ u32 sub_80391E0(u8 arrayId, u8 caseId); u32 sub_80397C4(u32 setId, u32 tableId); void oac_poke_opponent(struct Sprite *sprite); void SpriteCallbackDummy_2(struct Sprite *sprite); -void sub_8039934(struct Sprite *sprite); +void SpriteCB_FaintOpponentMon(struct Sprite *sprite); void sub_8039AD8(struct Sprite *sprite); void sub_8039B2C(struct Sprite *sprite); void sub_8039B58(struct Sprite *sprite); void sub_8039BB4(struct Sprite *sprite); void sub_80105DC(struct Sprite *sprite); void sub_8039C00(struct Sprite *sprite); -void dp11b_obj_instanciate(u8 battlerId, u8 b, s8 c, s8 d); -void dp11b_obj_free(u8 battlerId, bool8 b); +void DoBounceEffect(u8 battlerId, u8 b, s8 c, s8 d); +void EndBounceEffect(u8 battlerId, bool8 b); void sub_8039E44(struct Sprite *sprite); void sub_8039E60(struct Sprite *sprite); void sub_8039E84(struct Sprite *sprite); @@ -80,6 +84,6 @@ extern const u8 gStatusConditionString_IceJpn[8]; extern const u8 gStatusConditionString_ConfusionJpn[8]; extern const u8 gStatusConditionString_LoveJpn[8]; -extern const u8 * const gStatusConditionStringsTable[7][2]; +extern const u8 *const gStatusConditionStringsTable[7][2]; #endif // GUARD_BATTLE_MAIN_H diff --git a/include/global.h b/include/global.h index d26184270..5a37cdc1b 100644 --- a/include/global.h +++ b/include/global.h @@ -35,12 +35,18 @@ // Converts a number to Q4.12 fixed-point format #define Q_4_12(n) ((s16)((n) * 4096)) +// Converts a number to Q24.8 fixed-point format +#define Q_24_8(n) ((s32)((n) * 256)) + // Converts a Q8.8 fixed-point format number to a regular integer #define Q_8_8_TO_INT(n) ((int)((n) / 256)) // Converts a Q4.12 fixed-point format number to a regular integer #define Q_4_12_TO_INT(n) ((int)((n) / 4096)) +// Converts a Q24.8 fixed-point format number to a regular integer +#define Q_24_8_TO_INT(n) ((int)((n) >> 8)) + #define PARTY_SIZE 6 #define POKEMON_SLOTS_NUMBER 412 diff --git a/src/battle_controller_link_opponent.c b/src/battle_controller_link_opponent.c index b2c05664b..0a53c2893 100644 --- a/src/battle_controller_link_opponent.c +++ b/src/battle_controller_link_opponent.c @@ -90,7 +90,7 @@ static void LinkOpponentHandleIntroSlide(void); static void LinkOpponentHandleIntroTrainerBallThrow(void); static void LinkOpponentHandleDrawPartyStatusSummary(void); static void LinkOpponentHandleCmd49(void); -static void LinkOpponentHandleCmd50(void); +static void LinkOpponentHandleEndBounceEffect(void); static void LinkOpponentHandleSpriteInvisibility(void); static void LinkOpponentHandleBattleAnimation(void); static void LinkOpponentHandleLinkStandbyMsg(void); @@ -162,7 +162,7 @@ static void (*const sLinkOpponentBufferCommands[CONTROLLER_CMDS_COUNT])(void) = LinkOpponentHandleIntroTrainerBallThrow, LinkOpponentHandleDrawPartyStatusSummary, LinkOpponentHandleCmd49, - LinkOpponentHandleCmd50, + LinkOpponentHandleEndBounceEffect, LinkOpponentHandleSpriteInvisibility, LinkOpponentHandleBattleAnimation, LinkOpponentHandleLinkStandbyMsg, @@ -1366,7 +1366,7 @@ static void LinkOpponentHandleFaintAnimation(void) { gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].animationState = 0; PlaySE12WithPanning(SE_POKE_DEAD, PAN_SIDE_OPPONENT); - gSprites[gBattlerSpriteIds[gActiveBattler]].callback = sub_8039934; + gSprites[gBattlerSpriteIds[gActiveBattler]].callback = SpriteCB_FaintOpponentMon; gBattlerControllerFuncs[gActiveBattler] = sub_8064C14; } } @@ -1803,7 +1803,7 @@ static void LinkOpponentHandleCmd49(void) LinkOpponentBufferExecCompleted(); } -static void LinkOpponentHandleCmd50(void) +static void LinkOpponentHandleEndBounceEffect(void) { LinkOpponentBufferExecCompleted(); } diff --git a/src/battle_controller_link_partner.c b/src/battle_controller_link_partner.c index f7abe589a..f5987c0ce 100644 --- a/src/battle_controller_link_partner.c +++ b/src/battle_controller_link_partner.c @@ -88,7 +88,7 @@ static void LinkPartnerHandleIntroSlide(void); static void LinkPartnerHandleIntroTrainerBallThrow(void); static void LinkPartnerHandleDrawPartyStatusSummary(void); static void LinkPartnerHandleCmd49(void); -static void LinkPartnerHandleCmd50(void); +static void LinkPartnerHandleEndBounceEffect(void); static void LinkPartnerHandleSpriteInvisibility(void); static void LinkPartnerHandleBattleAnimation(void); static void LinkPartnerHandleLinkStandbyMsg(void); @@ -159,7 +159,7 @@ static void (*const sLinkPartnerBufferCommands[CONTROLLER_CMDS_COUNT])(void) = LinkPartnerHandleIntroTrainerBallThrow, LinkPartnerHandleDrawPartyStatusSummary, LinkPartnerHandleCmd49, - LinkPartnerHandleCmd50, + LinkPartnerHandleEndBounceEffect, LinkPartnerHandleSpriteInvisibility, LinkPartnerHandleBattleAnimation, LinkPartnerHandleLinkStandbyMsg, @@ -1638,7 +1638,7 @@ static void LinkPartnerHandleCmd49(void) LinkPartnerBufferExecCompleted(); } -static void LinkPartnerHandleCmd50(void) +static void LinkPartnerHandleEndBounceEffect(void) { LinkPartnerBufferExecCompleted(); } diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index 21b45dabf..83dac5436 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -95,7 +95,7 @@ static void OpponentHandleIntroSlide(void); static void OpponentHandleIntroTrainerBallThrow(void); static void OpponentHandleDrawPartyStatusSummary(void); static void OpponentHandleCmd49(void); -static void OpponentHandleCmd50(void); +static void OpponentHandleEndBounceEffect(void); static void OpponentHandleSpriteInvisibility(void); static void OpponentHandleBattleAnimation(void); static void OpponentHandleLinkStandbyMsg(void); @@ -167,7 +167,7 @@ static void (*const sOpponentBufferCommands[CONTROLLER_CMDS_COUNT])(void) = OpponentHandleIntroTrainerBallThrow, OpponentHandleDrawPartyStatusSummary, OpponentHandleCmd49, - OpponentHandleCmd50, + OpponentHandleEndBounceEffect, OpponentHandleSpriteInvisibility, OpponentHandleBattleAnimation, OpponentHandleLinkStandbyMsg, @@ -1403,7 +1403,7 @@ static void OpponentHandleFaintAnimation(void) { gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].animationState = 0; PlaySE12WithPanning(SE_POKE_DEAD, PAN_SIDE_OPPONENT); - gSprites[gBattlerSpriteIds[gActiveBattler]].callback = sub_8039934; + gSprites[gBattlerSpriteIds[gActiveBattler]].callback = SpriteCB_FaintOpponentMon; gBattlerControllerFuncs[gActiveBattler] = sub_805FAC4; } } @@ -1957,7 +1957,7 @@ static void OpponentHandleCmd49(void) OpponentBufferExecCompleted(); } -static void OpponentHandleCmd50(void) +static void OpponentHandleEndBounceEffect(void) { OpponentBufferExecCompleted(); } diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index 599ebfee4..63dc989be 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -101,7 +101,7 @@ static void PlayerHandleIntroSlide(void); static void PlayerHandleIntroTrainerBallThrow(void); static void PlayerHandleDrawPartyStatusSummary(void); static void PlayerHandleCmd49(void); -static void PlayerHandleCmd50(void); +static void PlayerHandleEndBounceEffect(void); static void PlayerHandleSpriteInvisibility(void); static void PlayerHandleBattleAnimation(void); static void PlayerHandleLinkStandbyMsg(void); @@ -188,7 +188,7 @@ static void (*const sPlayerBufferCommands[CONTROLLER_CMDS_COUNT])(void) = PlayerHandleIntroTrainerBallThrow, PlayerHandleDrawPartyStatusSummary, PlayerHandleCmd49, - PlayerHandleCmd50, + PlayerHandleEndBounceEffect, PlayerHandleSpriteInvisibility, PlayerHandleBattleAnimation, PlayerHandleLinkStandbyMsg, @@ -250,8 +250,8 @@ static void HandleInputChooseAction(void) { u16 itemId = gBattleBufferA[gActiveBattler][2] | (gBattleBufferA[gActiveBattler][3] << 8); - dp11b_obj_instanciate(gActiveBattler, 1, 7, 1); - dp11b_obj_instanciate(gActiveBattler, 0, 7, 1); + DoBounceEffect(gActiveBattler, BOUNCE_HEALTHBOX, 7, 1); + DoBounceEffect(gActiveBattler, BOUNCE_MON, 7, 1); if (gMain.newAndRepeatedKeys & DPAD_ANY && gSaveBlock2Ptr->optionsButtonMode == 2) gPlayerDpadHoldFrames++; @@ -347,8 +347,8 @@ static void HandleInputChooseAction(void) static void sub_80577F0(void) // unused { - dp11b_obj_free(gActiveBattler, 1); - dp11b_obj_free(gActiveBattler, 0); + EndBounceEffect(gActiveBattler, BOUNCE_HEALTHBOX); + EndBounceEffect(gActiveBattler, BOUNCE_MON); gBattlerControllerFuncs[gActiveBattler] = HandleInputChooseTarget; } @@ -358,7 +358,7 @@ static void HandleInputChooseTarget(void) u8 identities[4]; memcpy(identities, sTargetIdentities, ARRAY_COUNT(sTargetIdentities)); - dp11b_obj_instanciate(gMultiUsePlayerCursor, 1, 0xF, 1); + DoBounceEffect(gMultiUsePlayerCursor, BOUNCE_HEALTHBOX, 15, 1); // what a weird loop i = 0; @@ -367,7 +367,7 @@ static void HandleInputChooseTarget(void) do { if (i != gMultiUsePlayerCursor) - dp11b_obj_free(i, 1); + EndBounceEffect(i, BOUNCE_HEALTHBOX); i++; } while (i < gBattlersCount); } @@ -382,7 +382,7 @@ static void HandleInputChooseTarget(void) PlaySE(SE_SELECT); gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = sub_8039B2C; BtlController_EmitTwoReturnValues(1, 10, gMoveSelectionCursor[gActiveBattler] | (gMultiUsePlayerCursor << 8)); - dp11b_obj_free(gMultiUsePlayerCursor, 1); + EndBounceEffect(gMultiUsePlayerCursor, BOUNCE_HEALTHBOX); PlayerBufferExecCompleted(); } else if (gMain.newKeys & B_BUTTON || gPlayerDpadHoldFrames > 59) @@ -390,9 +390,9 @@ static void HandleInputChooseTarget(void) PlaySE(SE_SELECT); gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = sub_8039B2C; gBattlerControllerFuncs[gActiveBattler] = HandleInputChooseMove; - dp11b_obj_instanciate(gActiveBattler, 1, 7, 1); - dp11b_obj_instanciate(gActiveBattler, 0, 7, 1); - dp11b_obj_free(gMultiUsePlayerCursor, 1); + DoBounceEffect(gActiveBattler, BOUNCE_HEALTHBOX, 7, 1); + DoBounceEffect(gActiveBattler, BOUNCE_MON, 7, 1); + EndBounceEffect(gMultiUsePlayerCursor, BOUNCE_HEALTHBOX); } else if (gMain.newKeys & (DPAD_LEFT | DPAD_UP)) { @@ -3030,10 +3030,10 @@ static void PlayerHandleCmd49(void) PlayerBufferExecCompleted(); } -static void PlayerHandleCmd50(void) +static void PlayerHandleEndBounceEffect(void) { - dp11b_obj_free(gActiveBattler, 1); - dp11b_obj_free(gActiveBattler, 0); + EndBounceEffect(gActiveBattler, BOUNCE_HEALTHBOX); + EndBounceEffect(gActiveBattler, BOUNCE_MON); PlayerBufferExecCompleted(); } @@ -3072,8 +3072,8 @@ static void PlayerHandleLinkStandbyMsg(void) PrintLinkStandbyMsg(); // fall through case 1: - dp11b_obj_free(gActiveBattler, 1); - dp11b_obj_free(gActiveBattler, 0); + EndBounceEffect(gActiveBattler, BOUNCE_HEALTHBOX); + EndBounceEffect(gActiveBattler, BOUNCE_MON); break; case 2: PrintLinkStandbyMsg(); diff --git a/src/battle_controller_player_partner.c b/src/battle_controller_player_partner.c index df075522e..17ed1c24f 100644 --- a/src/battle_controller_player_partner.c +++ b/src/battle_controller_player_partner.c @@ -88,7 +88,7 @@ static void PlayerPartnerHandleIntroSlide(void); static void PlayerPartnerHandleIntroTrainerBallThrow(void); static void PlayerPartnerHandleDrawPartyStatusSummary(void); static void PlayerPartnerHandleCmd49(void); -static void PlayerPartnerHandleCmd50(void); +static void PlayerPartnerHandleEndBounceEffect(void); static void PlayerPartnerHandleSpriteInvisibility(void); static void PlayerPartnerHandleBattleAnimation(void); static void PlayerPartnerHandleLinkStandbyMsg(void); @@ -165,7 +165,7 @@ static void (*const sPlayerPartnerBufferCommands[CONTROLLER_CMDS_COUNT])(void) = PlayerPartnerHandleIntroTrainerBallThrow, PlayerPartnerHandleDrawPartyStatusSummary, PlayerPartnerHandleCmd49, - PlayerPartnerHandleCmd50, + PlayerPartnerHandleEndBounceEffect, PlayerPartnerHandleSpriteInvisibility, PlayerPartnerHandleBattleAnimation, PlayerPartnerHandleLinkStandbyMsg, @@ -1884,7 +1884,7 @@ static void PlayerPartnerHandleCmd49(void) PlayerPartnerBufferExecCompleted(); } -static void PlayerPartnerHandleCmd50(void) +static void PlayerPartnerHandleEndBounceEffect(void) { PlayerPartnerBufferExecCompleted(); } diff --git a/src/battle_controller_recorded_opponent.c b/src/battle_controller_recorded_opponent.c index 69f93d7e2..9d213fc6b 100644 --- a/src/battle_controller_recorded_opponent.c +++ b/src/battle_controller_recorded_opponent.c @@ -91,7 +91,7 @@ static void RecordedOpponentHandleIntroSlide(void); static void RecordedOpponentHandleIntroTrainerBallThrow(void); static void RecordedOpponentHandleDrawPartyStatusSummary(void); static void RecordedOpponentHandleCmd49(void); -static void RecordedOpponentHandleCmd50(void); +static void RecordedOpponentHandleEndBounceEffect(void); static void RecordedOpponentHandleSpriteInvisibility(void); static void RecordedOpponentHandleBattleAnimation(void); static void RecordedOpponentHandleLinkStandbyMsg(void); @@ -163,7 +163,7 @@ static void (*const sRecordedOpponentBufferCommands[CONTROLLER_CMDS_COUNT])(void RecordedOpponentHandleIntroTrainerBallThrow, RecordedOpponentHandleDrawPartyStatusSummary, RecordedOpponentHandleCmd49, - RecordedOpponentHandleCmd50, + RecordedOpponentHandleEndBounceEffect, RecordedOpponentHandleSpriteInvisibility, RecordedOpponentHandleBattleAnimation, RecordedOpponentHandleLinkStandbyMsg, @@ -1296,7 +1296,7 @@ static void RecordedOpponentHandleFaintAnimation(void) { gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].animationState = 0; PlaySE12WithPanning(SE_POKE_DEAD, PAN_SIDE_OPPONENT); - gSprites[gBattlerSpriteIds[gActiveBattler]].callback = sub_8039934; + gSprites[gBattlerSpriteIds[gActiveBattler]].callback = SpriteCB_FaintOpponentMon; gBattlerControllerFuncs[gActiveBattler] = sub_8186D58; } } @@ -1745,7 +1745,7 @@ static void RecordedOpponentHandleCmd49(void) RecordedOpponentBufferExecCompleted(); } -static void RecordedOpponentHandleCmd50(void) +static void RecordedOpponentHandleEndBounceEffect(void) { RecordedOpponentBufferExecCompleted(); } diff --git a/src/battle_controller_recorded_player.c b/src/battle_controller_recorded_player.c index 54ca4578b..d1836c092 100644 --- a/src/battle_controller_recorded_player.c +++ b/src/battle_controller_recorded_player.c @@ -90,7 +90,7 @@ static void RecordedPlayerHandleIntroSlide(void); static void RecordedPlayerHandleIntroTrainerBallThrow(void); static void RecordedPlayerHandleDrawPartyStatusSummary(void); static void RecordedPlayerHandleCmd49(void); -static void RecordedPlayerHandleCmd50(void); +static void RecordedPlayerHandleEndBounceEffect(void); static void RecordedPlayerHandleSpriteInvisibility(void); static void RecordedPlayerHandleBattleAnimation(void); static void RecordedPlayerHandleLinkStandbyMsg(void); @@ -161,7 +161,7 @@ static void (*const sRecordedPlayerBufferCommands[CONTROLLER_CMDS_COUNT])(void) RecordedPlayerHandleIntroTrainerBallThrow, RecordedPlayerHandleDrawPartyStatusSummary, RecordedPlayerHandleCmd49, - RecordedPlayerHandleCmd50, + RecordedPlayerHandleEndBounceEffect, RecordedPlayerHandleSpriteInvisibility, RecordedPlayerHandleBattleAnimation, RecordedPlayerHandleLinkStandbyMsg, @@ -1767,7 +1767,7 @@ static void RecordedPlayerHandleCmd49(void) RecordedPlayerBufferExecCompleted(); } -static void RecordedPlayerHandleCmd50(void) +static void RecordedPlayerHandleEndBounceEffect(void) { RecordedPlayerBufferExecCompleted(); } diff --git a/src/battle_controller_safari.c b/src/battle_controller_safari.c index 245447d8d..3cdd952ef 100644 --- a/src/battle_controller_safari.c +++ b/src/battle_controller_safari.c @@ -81,7 +81,7 @@ static void SafariHandleIntroSlide(void); static void SafariHandleIntroTrainerBallThrow(void); static void SafariHandleDrawPartyStatusSummary(void); static void SafariHandleCmd49(void); -static void SafariHandleCmd50(void); +static void SafariHandleEndBounceEffect(void); static void SafariHandleSpriteInvisibility(void); static void SafariHandleBattleAnimation(void); static void SafariHandleLinkStandbyMsg(void); @@ -145,7 +145,7 @@ static void (*const sSafariBufferCommands[CONTROLLER_CMDS_COUNT])(void) = SafariHandleIntroTrainerBallThrow, SafariHandleDrawPartyStatusSummary, SafariHandleCmd49, - SafariHandleCmd50, + SafariHandleEndBounceEffect, SafariHandleSpriteInvisibility, SafariHandleBattleAnimation, SafariHandleLinkStandbyMsg, @@ -650,7 +650,7 @@ static void SafariHandleCmd49(void) SafariBufferExecCompleted(); } -static void SafariHandleCmd50(void) +static void SafariHandleEndBounceEffect(void) { SafariBufferExecCompleted(); } diff --git a/src/battle_controller_wally.c b/src/battle_controller_wally.c index 955799ee3..05c7b9e1f 100644 --- a/src/battle_controller_wally.c +++ b/src/battle_controller_wally.c @@ -91,7 +91,7 @@ static void WallyHandleIntroSlide(void); static void WallyHandleIntroTrainerBallThrow(void); static void WallyHandleDrawPartyStatusSummary(void); static void WallyHandleCmd49(void); -static void WallyHandleCmd50(void); +static void WallyHandleEndBounceEffect(void); static void WallyHandleSpriteInvisibility(void); static void WallyHandleBattleAnimation(void); static void WallyHandleLinkStandbyMsg(void); @@ -160,7 +160,7 @@ static void (*const sWallyBufferCommands[CONTROLLER_CMDS_COUNT])(void) = WallyHandleIntroTrainerBallThrow, WallyHandleDrawPartyStatusSummary, WallyHandleCmd49, - WallyHandleCmd50, + WallyHandleEndBounceEffect, WallyHandleSpriteInvisibility, WallyHandleBattleAnimation, WallyHandleLinkStandbyMsg, @@ -1522,7 +1522,7 @@ static void WallyHandleCmd49(void) WallyBufferExecCompleted(); } -static void WallyHandleCmd50(void) +static void WallyHandleEndBounceEffect(void) { WallyBufferExecCompleted(); } diff --git a/src/battle_controllers.c b/src/battle_controllers.c index 8a7ff7b5d..1c60e22ef 100644 --- a/src/battle_controllers.c +++ b/src/battle_controllers.c @@ -1463,12 +1463,12 @@ void BtlController_EmitCmd49(u8 bufferId) PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); } -void BtlController_EmitCmd50(u8 bufferId) +void BtlController_EmitEndBounceEffect(u8 bufferId) { - sBattleBuffersTransferData[0] = CONTROLLER_50; - sBattleBuffersTransferData[1] = CONTROLLER_50; - sBattleBuffersTransferData[2] = CONTROLLER_50; - sBattleBuffersTransferData[3] = CONTROLLER_50; + sBattleBuffersTransferData[0] = CONTROLLER_ENDBOUNCE; + sBattleBuffersTransferData[1] = CONTROLLER_ENDBOUNCE; + sBattleBuffersTransferData[2] = CONTROLLER_ENDBOUNCE; + sBattleBuffersTransferData[3] = CONTROLLER_ENDBOUNCE; PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); } diff --git a/src/battle_interface.c b/src/battle_interface.c index 94b5a2be9..f5e031cb9 100644 --- a/src/battle_interface.c +++ b/src/battle_interface.c @@ -1483,12 +1483,18 @@ void SwapHpBarsWithHpText(void) } } +#define tBattler data[0] +#define tSummaryBarSpriteId data[1] +#define tBallIconSpriteId(n) data[3 + n] +#define tIsBattleStart data[10] +#define tData15 data[15] + u8 CreatePartyStatusSummarySprites(u8 battlerId, struct HpAndStatus *partyInfo, u8 arg2, bool8 isBattleStart) { bool8 isOpponent; s16 bar_X, bar_Y, bar_pos2_X, bar_data0; s32 i, j, var; - u8 barSpriteId; + u8 summaryBarSpriteId; u8 ballIconSpritesIds[PARTY_SIZE]; u8 taskId; @@ -1527,19 +1533,19 @@ u8 CreatePartyStatusSummarySprites(u8 battlerId, struct HpAndStatus *partyInfo, LoadSpritePalette(&sStatusSummaryBarSpritePal); LoadSpritePalette(&sStatusSummaryBallsSpritePal); - barSpriteId = CreateSprite(&sStatusSummaryBarSpriteTemplates[isOpponent], bar_X, bar_Y, 10); - SetSubspriteTables(&gSprites[barSpriteId], sStatusSummaryBar_SubspriteTable); - gSprites[barSpriteId].pos2.x = bar_pos2_X; - gSprites[barSpriteId].data[0] = bar_data0; + summaryBarSpriteId = CreateSprite(&sStatusSummaryBarSpriteTemplates[isOpponent], bar_X, bar_Y, 10); + SetSubspriteTables(&gSprites[summaryBarSpriteId], sStatusSummaryBar_SubspriteTable); + gSprites[summaryBarSpriteId].pos2.x = bar_pos2_X; + gSprites[summaryBarSpriteId].data[0] = bar_data0; if (isOpponent) { - gSprites[barSpriteId].pos1.x -= 96; - gSprites[barSpriteId].oam.matrixNum = 8; + gSprites[summaryBarSpriteId].pos1.x -= 96; + gSprites[summaryBarSpriteId].oam.matrixNum = 8; } else { - gSprites[barSpriteId].pos1.x += 96; + gSprites[summaryBarSpriteId].pos1.x += 96; } for (i = 0; i < PARTY_SIZE; i++) @@ -1555,7 +1561,7 @@ u8 CreatePartyStatusSummarySprites(u8 battlerId, struct HpAndStatus *partyInfo, gSprites[ballIconSpritesIds[i]].pos2.y = 0; } - gSprites[ballIconSpritesIds[i]].data[0] = barSpriteId; + gSprites[ballIconSpritesIds[i]].data[0] = summaryBarSpriteId; if (!isOpponent) { @@ -1672,13 +1678,13 @@ u8 CreatePartyStatusSummarySprites(u8 battlerId, struct HpAndStatus *partyInfo, } taskId = CreateTask(TaskDummy, 5); - gTasks[taskId].data[0] = battlerId; - gTasks[taskId].data[1] = barSpriteId; + gTasks[taskId].tBattler = battlerId; + gTasks[taskId].tSummaryBarSpriteId = summaryBarSpriteId; for (i = 0; i < PARTY_SIZE; i++) - gTasks[taskId].data[3 + i] = ballIconSpritesIds[i]; + gTasks[taskId].tBallIconSpriteId(i) = ballIconSpritesIds[i]; - gTasks[taskId].data[10] = isBattleStart; + gTasks[taskId].tIsBattleStart = isBattleStart; if (isBattleStart) { @@ -1691,46 +1697,46 @@ u8 CreatePartyStatusSummarySprites(u8 battlerId, struct HpAndStatus *partyInfo, void sub_8073C30(u8 taskId) { - u8 sp[6]; - u8 r7; + u8 ballIconSpriteIds[PARTY_SIZE]; + bool8 isBattleStart; u8 summaryBarSpriteId; u8 battlerId; s32 i; - r7 = gTasks[taskId].data[10]; - summaryBarSpriteId = gTasks[taskId].data[1]; - battlerId = gTasks[taskId].data[0]; + isBattleStart = gTasks[taskId].tIsBattleStart; + summaryBarSpriteId = gTasks[taskId].tSummaryBarSpriteId; + battlerId = gTasks[taskId].tBattler; for (i = 0; i < 6; i++) - sp[i] = gTasks[taskId].data[3 + i]; + ballIconSpriteIds[i] = gTasks[taskId].tBallIconSpriteId(i); SetGpuReg(REG_OFFSET_BLDCNT, 0x3F40); SetGpuReg(REG_OFFSET_BLDALPHA, 0x10); - gTasks[taskId].data[15] = 16; + gTasks[taskId].tData15 = 16; - for (i = 0; i < 6; i++) - gSprites[sp[i]].oam.objMode = 1; + for (i = 0; i < PARTY_SIZE; i++) + gSprites[ballIconSpriteIds[i]].oam.objMode = 1; gSprites[summaryBarSpriteId].oam.objMode = 1; - if (r7 != 0) + if (isBattleStart) { - for (i = 0; i < 6; i++) + for (i = 0; i < PARTY_SIZE; i++) { if (GetBattlerSide(battlerId) != B_SIDE_PLAYER) { - gSprites[sp[5 - i]].data[1] = 7 * i; - gSprites[sp[5 - i]].data[3] = 0; - gSprites[sp[5 - i]].data[4] = 0; - gSprites[sp[5 - i]].callback = sub_8074158; + gSprites[ballIconSpriteIds[5 - i]].data[1] = 7 * i; + gSprites[ballIconSpriteIds[5 - i]].data[3] = 0; + gSprites[ballIconSpriteIds[5 - i]].data[4] = 0; + gSprites[ballIconSpriteIds[5 - i]].callback = sub_8074158; } else { - gSprites[sp[i]].data[1] = 7 * i; - gSprites[sp[i]].data[3] = 0; - gSprites[sp[i]].data[4] = 0; - gSprites[sp[i]].callback = sub_8074158; + gSprites[ballIconSpriteIds[i]].data[1] = 7 * i; + gSprites[ballIconSpriteIds[i]].data[3] = 0; + gSprites[ballIconSpriteIds[i]].data[4] = 0; + gSprites[ballIconSpriteIds[i]].callback = sub_8074158; } } gSprites[summaryBarSpriteId].data[0] /= 2; @@ -1747,12 +1753,9 @@ void sub_8073C30(u8 taskId) static void sub_8073E08(u8 taskId) { - u16 temp = gTasks[taskId].data[11]++; - - if (!(temp & 1)) + if ((gTasks[taskId].data[11]++ % 2) == 0) { - gTasks[taskId].data[15]--; - if (gTasks[taskId].data[15] < 0) + if (--gTasks[taskId].data[15] < 0) return; SetGpuReg(REG_OFFSET_BLDALPHA, (gTasks[taskId].data[15]) | ((16 - gTasks[taskId].data[15]) << 8)); @@ -1763,36 +1766,35 @@ static void sub_8073E08(u8 taskId) static void sub_8073E64(u8 taskId) { - u8 sp[6]; + u8 ballIconSpriteIds[PARTY_SIZE]; s32 i; - u8 battlerId = gTasks[taskId].data[0]; - gTasks[taskId].data[15]--; - if (gTasks[taskId].data[15] == -1) + u8 battlerId = gTasks[taskId].tBattler; + if (--gTasks[taskId].tData15 == -1) { - u8 summaryBarSpriteId = gTasks[taskId].data[1]; + u8 summaryBarSpriteId = gTasks[taskId].tSummaryBarSpriteId; - for (i = 0; i < 6; i++) - sp[i] = gTasks[taskId].data[3 + i]; + for (i = 0; i < PARTY_SIZE; i++) + ballIconSpriteIds[i] = gTasks[taskId].tBallIconSpriteId(i); gBattleSpritesDataPtr->animationData->field_9_x1C--; - if (!gBattleSpritesDataPtr->animationData->field_9_x1C) + if (gBattleSpritesDataPtr->animationData->field_9_x1C == 0) { DestroySpriteAndFreeResources(&gSprites[summaryBarSpriteId]); - DestroySpriteAndFreeResources(&gSprites[sp[0]]); + DestroySpriteAndFreeResources(&gSprites[ballIconSpriteIds[0]]); } else { FreeSpriteOamMatrix(&gSprites[summaryBarSpriteId]); DestroySprite(&gSprites[summaryBarSpriteId]); - FreeSpriteOamMatrix(&gSprites[sp[0]]); - DestroySprite(&gSprites[sp[0]]); + FreeSpriteOamMatrix(&gSprites[ballIconSpriteIds[0]]); + DestroySprite(&gSprites[ballIconSpriteIds[0]]); } - for (i = 1; i < 6; i++) - DestroySprite(&gSprites[sp[i]]); + for (i = 1; i < PARTY_SIZE; i++) + DestroySprite(&gSprites[ballIconSpriteIds[i]]); } - else if (gTasks[taskId].data[15] == -3) + else if (gTasks[taskId].tData15 == -3) { gBattleSpritesDataPtr->healthBoxesData[battlerId].flag_x1 = 0; SetGpuReg(REG_OFFSET_BLDCNT, 0); @@ -1803,29 +1805,28 @@ static void sub_8073E64(u8 taskId) static void sub_8073F98(u8 taskId) { - u8 sp[6]; + u8 ballIconSpriteIds[PARTY_SIZE]; s32 i; + u8 battlerId = gTasks[taskId].tBattler; - u8 battlerId = gTasks[taskId].data[0]; - gTasks[taskId].data[15]--; - if (gTasks[taskId].data[15] >= 0) + if (--gTasks[taskId].tData15 >= 0) { - SetGpuReg(REG_OFFSET_BLDALPHA, (gTasks[taskId].data[15]) | ((16 - gTasks[taskId].data[15]) << 8)); + SetGpuReg(REG_OFFSET_BLDALPHA, (gTasks[taskId].tData15) | ((16 - gTasks[taskId].tData15) << 8)); } - else if (gTasks[taskId].data[15] == -1) + else if (gTasks[taskId].tData15 == -1) { - u8 summaryBarSpriteId = gTasks[taskId].data[1]; + u8 summaryBarSpriteId = gTasks[taskId].tSummaryBarSpriteId; - for (i = 0; i < 6; i++) - sp[i] = gTasks[taskId].data[3 + i]; + for (i = 0; i < PARTY_SIZE; i++) + ballIconSpriteIds[i] = gTasks[taskId].tBallIconSpriteId(i); DestroySpriteAndFreeResources(&gSprites[summaryBarSpriteId]); - DestroySpriteAndFreeResources(&gSprites[sp[0]]); + DestroySpriteAndFreeResources(&gSprites[ballIconSpriteIds[0]]); - for (i = 1; i < 6; i++) - DestroySprite(&gSprites[sp[i]]); + for (i = 1; i < PARTY_SIZE; i++) + DestroySprite(&gSprites[ballIconSpriteIds[i]]); } - else if (gTasks[taskId].data[15] == -3) + else if (gTasks[taskId].tData15 == -3) { gBattleSpritesDataPtr->healthBoxesData[battlerId].flag_x1 = 0; SetGpuReg(REG_OFFSET_BLDCNT, 0); @@ -1834,6 +1835,12 @@ static void sub_8073F98(u8 taskId) } } +#undef tBattler +#undef tSummaryBarSpriteId +#undef tBallIconSpriteId +#undef tIsBattleStart +#undef tData15 + static void SpriteCB_StatusSummaryBar(struct Sprite *sprite) { if (sprite->pos2.x != 0) @@ -2253,8 +2260,8 @@ void UpdateHealthboxAttribute(u8 healthboxSpriteId, struct Pokemon *mon, u8 elem } } -#define EXPBAR_PIXELS 64 -#define HEALTHBAR_PIXELS 48 +#define B_EXPBAR_PIXELS 64 +#define B_HEALTHBAR_PIXELS 48 s32 MoveBattleBar(u8 battlerId, u8 healthboxSpriteId, u8 whichBar, u8 unused) { @@ -2266,7 +2273,7 @@ s32 MoveBattleBar(u8 battlerId, u8 healthboxSpriteId, u8 whichBar, u8 unused) gBattleSpritesDataPtr->battleBars[battlerId].oldValue, gBattleSpritesDataPtr->battleBars[battlerId].receivedValue, &gBattleSpritesDataPtr->battleBars[battlerId].currValue, - HEALTHBAR_PIXELS / 8, 1); + B_HEALTHBAR_PIXELS / 8, 1); } else // exp bar { @@ -2281,7 +2288,7 @@ s32 MoveBattleBar(u8 battlerId, u8 healthboxSpriteId, u8 whichBar, u8 unused) gBattleSpritesDataPtr->battleBars[battlerId].oldValue, gBattleSpritesDataPtr->battleBars[battlerId].receivedValue, &gBattleSpritesDataPtr->battleBars[battlerId].currValue, - EXPBAR_PIXELS / 8, expFraction); + B_EXPBAR_PIXELS / 8, expFraction); } if (whichBar == EXP_BAR || (whichBar == HEALTH_BAR && !gBattleSpritesDataPtr->battlerData[battlerId].hpNumbersNoBars)) @@ -2307,11 +2314,11 @@ static void MoveBattleBarGraphically(u8 battlerId, u8 whichBar) gBattleSpritesDataPtr->battleBars[battlerId].oldValue, gBattleSpritesDataPtr->battleBars[battlerId].receivedValue, &gBattleSpritesDataPtr->battleBars[battlerId].currValue, - array, HEALTHBAR_PIXELS / 8); + array, B_HEALTHBAR_PIXELS / 8); - if (filledPixelsCount > (HEALTHBAR_PIXELS * 50 / 100)) // more than 50 % hp + if (filledPixelsCount > (B_HEALTHBAR_PIXELS * 50 / 100)) // more than 50 % hp barElementId = HEALTHBOX_GFX_HP_BAR_GREEN; - else if (filledPixelsCount > (HEALTHBAR_PIXELS * 20 / 100)) // more than 20% hp + else if (filledPixelsCount > (B_HEALTHBAR_PIXELS * 20 / 100)) // more than 20% hp barElementId = HEALTHBOX_GFX_HP_BAR_YELLOW; else barElementId = HEALTHBOX_GFX_HP_BAR_RED; // 20 % or less @@ -2332,7 +2339,7 @@ static void MoveBattleBarGraphically(u8 battlerId, u8 whichBar) gBattleSpritesDataPtr->battleBars[battlerId].oldValue, gBattleSpritesDataPtr->battleBars[battlerId].receivedValue, &gBattleSpritesDataPtr->battleBars[battlerId].currValue, - array, EXPBAR_PIXELS / 8); + array, B_EXPBAR_PIXELS / 8); level = GetMonData(&gPlayerParty[gBattlerPartyIndexes[battlerId]], MON_DATA_LEVEL); if (level == MAX_MON_LEVEL) { @@ -2360,7 +2367,7 @@ static s32 CalcNewBarValue(s32 maxValue, s32 oldValue, s32 receivedValue, s32 *c if (*currValue == -32768) // first function call { if (maxValue < scale) - *currValue = oldValue << 8; + *currValue = Q_24_8(oldValue); else *currValue = oldValue; } @@ -2373,9 +2380,7 @@ static s32 CalcNewBarValue(s32 maxValue, s32 oldValue, s32 receivedValue, s32 *c if (maxValue < scale) { - s32 var = *currValue >> 8; - - if (newValue == var && (*currValue & 0xFF) == 0) + if (newValue == Q_24_8_TO_INT(*currValue) && (*currValue & 0xFF) == 0) return -1; } else @@ -2386,27 +2391,28 @@ static s32 CalcNewBarValue(s32 maxValue, s32 oldValue, s32 receivedValue, s32 *c if (maxValue < scale) // handle cases of max var having less pixels than the whole bar { - s32 var = (maxValue << 8) / scale; + s32 toAdd = Q_24_8(maxValue) / scale; if (receivedValue < 0) // fill bar right { - *currValue += var; - ret = *currValue >> 8; + *currValue += toAdd; + ret = Q_24_8_TO_INT(*currValue); if (ret >= newValue) { - *currValue = newValue << 8; + *currValue = Q_24_8(newValue); ret = newValue; } } else // move bar left { - *currValue -= var; - ret = *currValue >> 8; + *currValue -= toAdd; + ret = Q_24_8_TO_INT(*currValue); + // try round up if ((*currValue & 0xFF) > 0) ret++; if (ret <= newValue) { - *currValue = newValue << 8; + *currValue = Q_24_8(newValue); ret = newValue; } } @@ -2480,34 +2486,35 @@ static u8 CalcBarFilledPixels(s32 maxValue, s32 oldValue, s32 receivedValue, s32 return filledPixels; } -static s16 sub_8074F28(struct TestingBar *barInfo, s32 *arg1, u16 *arg2, s32 arg3) +// These two functions seem as if they were made for testing the health bar. +static s16 sub_8074F28(struct TestingBar *barInfo, s32 *currValue, u16 *arg2, s32 arg3) { s16 ret, var; ret = CalcNewBarValue(barInfo->maxValue, barInfo->oldValue, barInfo->receivedValue, - arg1, 6, 1); - sub_8074F88(barInfo, arg1, arg2); + currValue, B_HEALTHBAR_PIXELS / 8, 1); + sub_8074F88(barInfo, currValue, arg2); - if (barInfo->maxValue < HEALTHBAR_PIXELS) - var = *arg1 >> 8; + if (barInfo->maxValue < B_HEALTHBAR_PIXELS) + var = *currValue >> 8; else - var = *arg1; + var = *currValue; DummiedOutFunction(barInfo->maxValue, var, arg3); return ret; } -static void sub_8074F88(struct TestingBar *barInfo, s32 *arg1, u16 *arg2) +static void sub_8074F88(struct TestingBar *barInfo, s32 *currValue, u16 *arg2) { u8 sp8[6]; u16 sp10[6]; u8 i; CalcBarFilledPixels(barInfo->maxValue, barInfo->oldValue, - barInfo->receivedValue, arg1, sp8, 6); + barInfo->receivedValue, currValue, sp8, B_HEALTHBAR_PIXELS / 8); for (i = 0; i < 6; i++) sp10[i] = (barInfo->unkC_0 << 12) | (barInfo->unk10 + sp8[i]); @@ -2547,7 +2554,7 @@ u8 GetScaledHPFraction(s16 hp, s16 maxhp, u8 scale) u8 GetHPBarLevel(s16 hp, s16 maxhp) { - s32 result; + u8 result; if (hp == maxhp) { @@ -2555,10 +2562,10 @@ u8 GetHPBarLevel(s16 hp, s16 maxhp) } else { - u8 fraction = GetScaledHPFraction(hp, maxhp, 48); - if (fraction > 24) + u8 fraction = GetScaledHPFraction(hp, maxhp, B_HEALTHBAR_PIXELS); + if (fraction > (B_HEALTHBAR_PIXELS * 50 / 100)) // more than 50 % hp result = HP_BAR_GREEN; - else if (fraction > 9) + else if (fraction > (B_HEALTHBAR_PIXELS * 20 / 100)) // more than 20% hp result = HP_BAR_YELLOW; else if (fraction > 0) result = HP_BAR_RED; diff --git a/src/battle_main.c b/src/battle_main.c index 2d24d0dab..9afbc7f40 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -41,6 +41,7 @@ #include "pokedex.h" #include "constants/abilities.h" #include "constants/moves.h" +#include "constants/rgb.h" #include "evolution_scene.h" #include "roamer.h" #include "tv.h" @@ -137,13 +138,13 @@ static void sub_803980C(struct Sprite *sprite); static void sub_8039838(struct Sprite *sprite); static void sub_8039894(struct Sprite *sprite); static void sub_80398D0(struct Sprite *sprite); -static void sub_8039A48(struct Sprite *sprite); +static void SpriteCB_AnimFaintOpponent(struct Sprite *sprite); static void sub_8039AF4(struct Sprite *sprite); static void SpriteCallbackDummy_3(struct Sprite *sprite); static void oac_poke_ally_(struct Sprite *sprite); static void SpecialStatusesClear(void); static void TurnValuesCleanUp(bool8 var0); -static void SpriteCB_HealthBoxBounce(struct Sprite *sprite); +static void SpriteCB_BounceEffect(struct Sprite *sprite); static void BattleStartClearSetData(void); static void BattleIntroGetMonsData(void); static void BattleIntroPrepareBackgroundSlide(void); @@ -183,7 +184,7 @@ static void HandleAction_SafariZoneBallThrow(void); static void HandleAction_ThrowPokeblock(void); static void HandleAction_GoNear(void); static void HandleAction_SafriZoneRun(void); -static void HandleAction_Action9(void); +static void HandleAction_WallyBallThrow(void); static void HandleAction_Action11(void); static void HandleAction_NothingIsFainted(void); static void HandleAction_ActionFinished(void); @@ -515,7 +516,7 @@ static void (* const sTurnActionsFuncsTable[])(void) = HandleAction_ThrowPokeblock, // B_ACTION_SAFARI_POKEBLOCK HandleAction_GoNear, // B_ACTION_SAFARI_GO_NEAR HandleAction_SafriZoneRun, // B_ACTION_SAFARI_RUN - HandleAction_Action9, // B_ACTION_UNKNOWN9 + HandleAction_WallyBallThrow, // B_ACTION_WALLY_THROW HandleAction_RunBattleScript, // B_ACTION_EXEC_SCRIPT HandleAction_Action11, // not sure about this one HandleAction_ActionFinished, // B_ACTION_FINISHED @@ -532,7 +533,7 @@ static void (* const sEndTurnFuncsTable[])(void) = HandleEndTurn_FinishBattle, // B_OUTCOME_PLAYER_TELEPORTED HandleEndTurn_MonFled, // B_OUTCOME_MON_FLED HandleEndTurn_FinishBattle, // B_OUTCOME_CAUGHT - HandleEndTurn_FinishBattle, // battle outcome 8 + HandleEndTurn_FinishBattle, // B_OUTCOME_NO_SAFARI_BALLS HandleEndTurn_FinishBattle, // B_OUTCOME_FORFEITED HandleEndTurn_FinishBattle, // B_OUTCOME_MON_TELEPORTED }; @@ -678,7 +679,7 @@ static void CB2_InitBattleInternal(void) gMain.inBattle = TRUE; gSaveBlock2Ptr->field_CA9_b = 0; - for (i = 0; i < 6; i++) + for (i = 0; i < PARTY_SIZE; i++) AdjustFriendship(&gPlayerParty[i], 3); gBattleCommunication[MULTIUSE_STATE] = 0; @@ -739,7 +740,7 @@ static void SetPlayerBerryDataInBattleStruct(void) } else { - const struct Berry* berryData = GetBerryInfo(ItemIdToBerryType(ITEM_ENIGMA_BERRY)); + const struct Berry *berryData = GetBerryInfo(ItemIdToBerryType(ITEM_ENIGMA_BERRY)); for (i = 0; i < BERRY_NAME_COUNT - 1; i++) battleBerry->name[i] = berryData->name[i]; @@ -783,7 +784,7 @@ static void SetAllPlayersBerryData(void) } else { - const struct Berry* berryData = GetBerryInfo(ItemIdToBerryType(ITEM_ENIGMA_BERRY)); + const struct Berry *berryData = GetBerryInfo(ItemIdToBerryType(ITEM_ENIGMA_BERRY)); for (i = 0; i < BERRY_NAME_COUNT - 1; i++) { @@ -809,7 +810,7 @@ static void SetAllPlayersBerryData(void) { s32 numPlayers; struct BattleEnigmaBerry *src; - u8 r4; + u8 battlerId; if (gBattleTypeFlags & BATTLE_TYPE_MULTI) { @@ -821,17 +822,17 @@ static void SetAllPlayersBerryData(void) for (i = 0; i < numPlayers; i++) { src = (struct BattleEnigmaBerry *)(gBlockRecvBuffer[i] + 2); - r4 = gLinkPlayers[i].lp_field_18; + battlerId = gLinkPlayers[i].lp_field_18; for (j = 0; j < BERRY_NAME_COUNT - 1; j++) - gEnigmaBerries[r4].name[j] = src->name[j]; - gEnigmaBerries[r4].name[j] = EOS; + gEnigmaBerries[battlerId].name[j] = src->name[j]; + gEnigmaBerries[battlerId].name[j] = EOS; for (j = 0; j < BERRY_ITEM_EFFECT_COUNT; j++) - gEnigmaBerries[r4].itemEffect[j] = src->itemEffect[j]; + gEnigmaBerries[battlerId].itemEffect[j] = src->itemEffect[j]; - gEnigmaBerries[r4].holdEffect = src->holdEffect; - gEnigmaBerries[r4].holdEffectParam = src->holdEffectParam; + gEnigmaBerries[battlerId].holdEffect = src->holdEffect; + gEnigmaBerries[battlerId].holdEffectParam = src->holdEffectParam; } } else @@ -1382,7 +1383,7 @@ static void CB2_PreInitMultiBattle(void) u8 playerMultiplierId; s32 numPlayers = 4; u8 r4 = 0xF; - u32* savedBattleTypeFlags; + u32 *savedBattleTypeFlags; void (**savedCallback)(void); if (gBattleTypeFlags & BATTLE_TYPE_BATTLE_TOWER) @@ -1476,7 +1477,7 @@ static void CB2_PreInitMultiBattle(void) static void CB2_PreInitIngamePlayerPartnerBattle(void) { - u32* savedBattleTypeFlags; + u32 *savedBattleTypeFlags; void (**savedCallback)(void); savedCallback = &gBattleStruct->savedCallback; @@ -1819,7 +1820,7 @@ void BattleMainCB2(void) { gSpecialVar_Result = gBattleOutcome = B_OUTCOME_PLAYER_TELEPORTED; ResetPaletteFadeControl(); - BeginNormalPaletteFade(-1, 0, 0, 0x10, 0); + BeginNormalPaletteFade(-1, 0, 0, 0x10, RGB_BLACK); SetMainCallback2(CB2_QuitRecordedBattle); } } @@ -2026,7 +2027,7 @@ void sub_8038A04(void) // unused void VBlankCB_Battle(void) { - // change gRngSeed every vblank unless the battle could be recorded + // Change gRngSeed every vblank unless the battle could be recorded. if (!(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_FRONTIER | BATTLE_TYPE_RECORDED))) Random(); @@ -2192,7 +2193,7 @@ void sub_8038D64(void) } for (i = 80; i < 160; i++) { - asm(""::"r"(i)); // Needed to stop the compiler from optimizing out the loop counter + asm(""::"r"(i)); // Needed to stop the compiler from optimizing out the loop counter. gScanlineEffectRegBuffers[0][i] = 0xFF10; gScanlineEffectRegBuffers[1][i] = 0xFF10; } @@ -2255,7 +2256,7 @@ static void sub_8038F34(void) case 1: if (--gBattleCommunication[1] == 0) { - BeginNormalPaletteFade(-1, 0, 0, 0x10, 0); + BeginNormalPaletteFade(-1, 0, 0, 0x10, RGB_BLACK); gBattleCommunication[MULTIUSE_STATE]++; } break; @@ -2312,7 +2313,7 @@ static void sub_8038F34(void) for (i = 0; i < 2; i++) LoadChosenBattleElement(i); - BeginNormalPaletteFade(-1, 0, 0x10, 0, 0); + BeginNormalPaletteFade(-1, 0, 0x10, 0, RGB_BLACK); gBattleCommunication[MULTIUSE_STATE]++; break; case 4: @@ -2417,7 +2418,7 @@ static void sub_80392A8(void) gReservedSpritePaletteCount = 4; SetVBlankCallback(VBlankCB_Battle); SetMainCallback2(sub_803937C); - BeginNormalPaletteFade(-1, 0, 0x10, 0, 0); + BeginNormalPaletteFade(-1, 0, 0x10, 0, RGB_BLACK); gBattleCommunication[MULTIUSE_STATE] = 0; } @@ -2577,7 +2578,7 @@ static void sub_803939C(void) { if (sub_800A520() == TRUE) { - BeginNormalPaletteFade(-1, 0, 0, 0x10, 0); + BeginNormalPaletteFade(-1, 0, 0, 0x10, RGB_BLACK); gBattleCommunication[1] = 0x20; gBattleCommunication[MULTIUSE_STATE] = 8; } @@ -2585,7 +2586,7 @@ static void sub_803939C(void) } else { - BeginNormalPaletteFade(-1, 0, 0, 0x10, 0); + BeginNormalPaletteFade(-1, 0, 0, 0x10, RGB_BLACK); gBattleCommunication[1] = 0x20; gBattleCommunication[MULTIUSE_STATE] = 8; } @@ -2620,7 +2621,7 @@ void oac_poke_opponent(struct Sprite *sprite) { sprite->callback = sub_803980C; StartSpriteAnimIfDifferent(sprite, 0); - BeginNormalPaletteFade(0x20000, 0, 10, 10, 0x2108); + BeginNormalPaletteFade(0x20000, 0, 10, 10, RGB(8, 8, 8)); } static void sub_803980C(struct Sprite *sprite) @@ -2643,7 +2644,7 @@ static void sub_8039838(struct Sprite *sprite) SetHealthboxSpriteVisible(gHealthboxSpriteIds[sprite->sBattler]); sprite->callback = sub_8039894; StartSpriteAnimIfDifferent(sprite, 0); - BeginNormalPaletteFade(0x20000, 0, 10, 0, 0x2108); + BeginNormalPaletteFade(0x20000, 0, 10, 0, RGB(8, 8, 8)); } } @@ -2687,7 +2688,7 @@ static void sub_80398D0(struct Sprite *sprite) extern const struct MonCoords gMonFrontPicCoords[]; extern const struct MonCoords gCastformFrontSpriteCoords[]; -void sub_8039934(struct Sprite *sprite) +void SpriteCB_FaintOpponentMon(struct Sprite *sprite) { u8 battler = sprite->sBattler; u16 species; @@ -2698,7 +2699,7 @@ void sub_8039934(struct Sprite *sprite) else species = sprite->sSpeciesId; - GetMonData(&gEnemyParty[gBattlerPartyIndexes[battler]], MON_DATA_PERSONALITY); // Unused return value + GetMonData(&gEnemyParty[gBattlerPartyIndexes[battler]], MON_DATA_PERSONALITY); // Unused return value. if (species == SPECIES_UNOWN) { @@ -2707,9 +2708,9 @@ void sub_8039934(struct Sprite *sprite) u16 unownSpecies; if (unownForm == 0) - unownSpecies = SPECIES_UNOWN; // Use the A Unown form + unownSpecies = SPECIES_UNOWN; // Use the A Unown form. else - unownSpecies = NUM_SPECIES + unownForm; // Use one of the other Unown letters + unownSpecies = NUM_SPECIES + unownForm; // Use one of the other Unown letters. yOffset = gMonFrontPicCoords[unownSpecies].y_offset; } @@ -2728,25 +2729,23 @@ void sub_8039934(struct Sprite *sprite) sprite->data[3] = 8 - yOffset / 8; sprite->data[4] = 1; - sprite->callback = sub_8039A48; + sprite->callback = SpriteCB_AnimFaintOpponent; } -static void sub_8039A48(struct Sprite *sprite) +static void SpriteCB_AnimFaintOpponent(struct Sprite *sprite) { s32 i; - sprite->data[4]--; - if (sprite->data[4] == 0) + if (--sprite->data[4] == 0) { sprite->data[4] = 2; - sprite->pos2.y += 8; - sprite->data[3]--; - if (sprite->data[3] < 0) + sprite->pos2.y += 8; // Move the sprite down. + if (--sprite->data[3] < 0) { FreeSpriteOamMatrix(sprite); DestroySprite(sprite); } - else + else // Erase bottom part of the sprite to create a smooth illusion of mon falling down. { u8 *dst = (u8 *)gMonSpritesGfxPtr->sprites[GetBattlerPosition(sprite->sBattler)] + (gBattleMonForms[sprite->sBattler] << 11) + (sprite->data[3] << 8); @@ -2831,85 +2830,100 @@ void sub_8039C00(struct Sprite *sprite) } } -void dp11b_obj_instanciate(u8 battler, u8 b, s8 c, s8 d) +#define sSinIndex data[0] +#define sDelta data[1] +#define sAmplitude data[2] +#define sBouncerSpriteId data[3] +#define sWhich data[4] + +void DoBounceEffect(u8 battler, u8 which, s8 delta, s8 amplitude) { - u8 bounceHealthBoxSpriteId; - u8 spriteId2; + u8 invisibleSpriteId; + u8 bouncerSpriteId; - if (b) + switch (which) { - if (gBattleSpritesDataPtr->healthBoxesData[battler].flag_x2) + case BOUNCE_HEALTHBOX: + default: + if (gBattleSpritesDataPtr->healthBoxesData[battler].healthboxIsBouncing) return; + break; + case BOUNCE_MON: + if (gBattleSpritesDataPtr->healthBoxesData[battler].battlerIsBouncing) + return; + break; + } + + invisibleSpriteId = CreateInvisibleSpriteWithCallback(SpriteCB_BounceEffect); + if (which == BOUNCE_HEALTHBOX) + { + bouncerSpriteId = gHealthboxSpriteIds[battler]; + gBattleSpritesDataPtr->healthBoxesData[battler].healthboxBounceSpriteId = invisibleSpriteId; + gBattleSpritesDataPtr->healthBoxesData[battler].healthboxIsBouncing = 1; + gSprites[invisibleSpriteId].sSinIndex = 128; // 0 } else { - if (gBattleSpritesDataPtr->healthBoxesData[battler].flag_x4) - return; + bouncerSpriteId = gBattlerSpriteIds[battler]; + gBattleSpritesDataPtr->healthBoxesData[battler].battlerBounceSpriteId = invisibleSpriteId; + gBattleSpritesDataPtr->healthBoxesData[battler].battlerIsBouncing = 1; + gSprites[invisibleSpriteId].sSinIndex = 192; // -1 } - - bounceHealthBoxSpriteId = CreateInvisibleSpriteWithCallback(SpriteCB_HealthBoxBounce); - if (b == TRUE) - { - spriteId2 = gHealthboxSpriteIds[battler]; - gBattleSpritesDataPtr->healthBoxesData[battler].field_2 = bounceHealthBoxSpriteId; - gBattleSpritesDataPtr->healthBoxesData[battler].flag_x2 = 1; - gSprites[bounceHealthBoxSpriteId].data[0] = 0x80; - } - else - { - spriteId2 = gBattlerSpriteIds[battler]; - gBattleSpritesDataPtr->healthBoxesData[battler].field_3 = bounceHealthBoxSpriteId; - gBattleSpritesDataPtr->healthBoxesData[battler].flag_x4 = 1; - gSprites[bounceHealthBoxSpriteId].data[0] = 0xC0; - } - gSprites[bounceHealthBoxSpriteId].data[1] = c; - gSprites[bounceHealthBoxSpriteId].data[2] = d; - gSprites[bounceHealthBoxSpriteId].data[3] = spriteId2; - gSprites[bounceHealthBoxSpriteId].data[4] = b; - gSprites[spriteId2].pos2.x = 0; - gSprites[spriteId2].pos2.y = 0; + gSprites[invisibleSpriteId].sDelta = delta; + gSprites[invisibleSpriteId].sAmplitude = amplitude; + gSprites[invisibleSpriteId].sBouncerSpriteId = bouncerSpriteId; + gSprites[invisibleSpriteId].sWhich = which; + gSprites[bouncerSpriteId].pos2.x = 0; + gSprites[bouncerSpriteId].pos2.y = 0; } -void dp11b_obj_free(u8 battler, bool8 b) +void EndBounceEffect(u8 battler, u8 which) { - u8 r4; + u8 bouncerSpriteId; - if (b == TRUE) + if (which == BOUNCE_HEALTHBOX) { - if (!gBattleSpritesDataPtr->healthBoxesData[battler].flag_x2) + if (!gBattleSpritesDataPtr->healthBoxesData[battler].healthboxIsBouncing) return; - r4 = gSprites[gBattleSpritesDataPtr->healthBoxesData[battler].field_2].data[3]; - DestroySprite(&gSprites[gBattleSpritesDataPtr->healthBoxesData[battler].field_2]); - gBattleSpritesDataPtr->healthBoxesData[battler].flag_x2 = 0; + bouncerSpriteId = gSprites[gBattleSpritesDataPtr->healthBoxesData[battler].healthboxBounceSpriteId].sBouncerSpriteId; + DestroySprite(&gSprites[gBattleSpritesDataPtr->healthBoxesData[battler].healthboxBounceSpriteId]); + gBattleSpritesDataPtr->healthBoxesData[battler].healthboxIsBouncing = 0; } else { - if (!gBattleSpritesDataPtr->healthBoxesData[battler].flag_x4) + if (!gBattleSpritesDataPtr->healthBoxesData[battler].battlerIsBouncing) return; - r4 = gSprites[gBattleSpritesDataPtr->healthBoxesData[battler].field_3].data[3]; - DestroySprite(&gSprites[gBattleSpritesDataPtr->healthBoxesData[battler].field_3]); - gBattleSpritesDataPtr->healthBoxesData[battler].flag_x4 = 0; + bouncerSpriteId = gSprites[gBattleSpritesDataPtr->healthBoxesData[battler].battlerBounceSpriteId].sBouncerSpriteId; + DestroySprite(&gSprites[gBattleSpritesDataPtr->healthBoxesData[battler].battlerBounceSpriteId]); + gBattleSpritesDataPtr->healthBoxesData[battler].battlerIsBouncing = 0; } - gSprites[r4].pos2.x = 0; - gSprites[r4].pos2.y = 0; + + gSprites[bouncerSpriteId].pos2.x = 0; + gSprites[bouncerSpriteId].pos2.y = 0; } -static void SpriteCB_HealthBoxBounce(struct Sprite *sprite) +static void SpriteCB_BounceEffect(struct Sprite *sprite) { - u8 spriteId = sprite->data[3]; - s32 var; + u8 bouncerSpriteId = sprite->sBouncerSpriteId; + s32 index; - if (sprite->data[4] == 1) - var = sprite->data[0]; + if (sprite->sWhich == BOUNCE_HEALTHBOX) + index = sprite->sSinIndex; else - var = sprite->data[0]; + index = sprite->sSinIndex; - gSprites[spriteId].pos2.y = Sin(var, sprite->data[2]) + sprite->data[2]; - sprite->data[0] = (sprite->data[0] + sprite->data[1]) & 0xFF; + gSprites[bouncerSpriteId].pos2.y = Sin(index, sprite->sAmplitude) + sprite->sAmplitude; + sprite->sSinIndex = (sprite->sSinIndex + sprite->sDelta) & 0xFF; } +#undef sSinIndex +#undef sDelta +#undef sAmplitude +#undef sBouncerSpriteId +#undef sWhich + void sub_8039E44(struct Sprite *sprite) { if (sprite->affineAnimEnded) @@ -4272,7 +4286,7 @@ static void HandleTurnActionSelectionState(void) if (gBattleMons[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))].status2 & STATUS2_MULTIPLETURNS || gBattleMons[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))].status2 & STATUS2_RECHARGE) { - BtlController_EmitCmd50(0); + BtlController_EmitEndBounceEffect(0); MarkBattlerForControllerExec(gActiveBattler); return; } @@ -4300,7 +4314,7 @@ static void HandleTurnActionSelectionState(void) { RecordedBattle_ClearBattlerAction(GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler))), 3); } - BtlController_EmitCmd50(0); + BtlController_EmitEndBounceEffect(0); MarkBattlerForControllerExec(gActiveBattler); return; } @@ -4439,7 +4453,7 @@ static void HandleTurnActionSelectionState(void) gHitMarker |= HITMARKER_RUN; gBattleCommunication[gActiveBattler]++; break; - case B_ACTION_UNKNOWN9: + case B_ACTION_WALLY_THROW: gBattleCommunication[gActiveBattler]++; break; } @@ -5776,7 +5790,7 @@ static void HandleAction_SafriZoneRun(void) gBattleOutcome = B_OUTCOME_RAN; } -static void HandleAction_Action9(void) +static void HandleAction_WallyBallThrow(void) { gBattlerAttacker = gBattleTurnOrder[gCurrentTurnActionNumber]; gBattle_BG0_X = 0; diff --git a/src/hall_of_fame.c b/src/hall_of_fame.c index b0388e971..78b615407 100644 --- a/src/hall_of_fame.c +++ b/src/hall_of_fame.c @@ -38,7 +38,7 @@ struct HallofFameMon struct HallofFameTeam { - struct HallofFameMon mon[6]; + struct HallofFameMon mon[PARTY_SIZE]; }; struct HofGfx From 272b98da6c5174db3f7f2d05ed765fc4cdefc2c6 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Thu, 28 Jun 2018 21:06:32 +0200 Subject: [PATCH 04/15] document party status summary --- asm/macros/battle_script.inc | 2 +- asm/party_menu.s | 2 +- asm/pokemon_summary_screen.s | 2 +- data/battle_scripts_1.s | 8 +- data/battle_scripts_2.s | 10 +- include/battle.h | 18 +-- include/battle_controllers.h | 6 +- include/battle_interface.h | 2 +- src/battle_controller_link_opponent.c | 16 +-- src/battle_controller_link_partner.c | 16 +-- src/battle_controller_opponent.c | 16 +-- src/battle_controller_player.c | 20 ++-- src/battle_controller_player_partner.c | 16 +-- src/battle_controller_recorded_opponent.c | 16 +-- src/battle_controller_recorded_player.c | 16 +-- src/battle_controller_safari.c | 6 +- src/battle_controller_wally.c | 12 +- src/battle_controllers.c | 18 +-- src/battle_interface.c | 12 +- src/battle_main.c | 136 +++++++++++----------- src/battle_script_commands.c | 22 ++-- src/battle_util.c | 10 +- src/safari_zone.c | 10 +- 23 files changed, 196 insertions(+), 196 deletions(-) diff --git a/asm/macros/battle_script.inc b/asm/macros/battle_script.inc index 083107c08..73fcbeac1 100644 --- a/asm/macros/battle_script.inc +++ b/asm/macros/battle_script.inc @@ -525,7 +525,7 @@ .byte \bank .endm - .macro atk62 bank + .macro hidepartystatussummary bank .byte 0x62 .byte \bank .endm diff --git a/asm/party_menu.s b/asm/party_menu.s index 6e2b1e55a..782d8ae31 100644 --- a/asm/party_menu.s +++ b/asm/party_menu.s @@ -12158,7 +12158,7 @@ sub_81B672C: @ 81B672C bl sub_81B1B5C movs r0, 0x2 bl schedule_bg_copy_tilemap_to_vram - bl sub_805EAE8 + bl HandleBattleLowHpMusicChange ldr r1, =gTasks lsls r0, r5, 2 adds r0, r5 diff --git a/asm/pokemon_summary_screen.s b/asm/pokemon_summary_screen.s index 901669715..e52874f57 100644 --- a/asm/pokemon_summary_screen.s +++ b/asm/pokemon_summary_screen.s @@ -1116,7 +1116,7 @@ sub_81C4778: @ 81C4778 bne _081C47AE adds r0, r1, 0 adds r0, 0xC - bl ShouldPlayNormalPokeCry + bl ShouldPlayNormalMonCry cmp r0, 0x1 bne _081C47A4 ldrh r0, [r4, 0x2] diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 058833fa9..a9d305ec8 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -2899,7 +2899,7 @@ BattleScript_FaintedMonTryChooseAnother:: switchindataupdate BS_ATTACKER hpthresholds BS_ATTACKER printstring STRINGID_SWITCHINMON - atk62 BS_ATTACKER + hidepartystatussummary BS_ATTACKER switchinanim BS_ATTACKER, 0x0 waitstate switchineffects BS_ATTACKER @@ -2910,7 +2910,7 @@ BattleScript_FaintedMonChooseAnother:: switchindataupdate BS_FAINTED hpthresholds BS_FAINTED printstring STRINGID_SWITCHINMON - atk62 BS_FAINTED + hidepartystatussummary BS_FAINTED switchinanim BS_FAINTED, FALSE waitstate various7 BS_ATTACKER @@ -2933,7 +2933,7 @@ BattleScript_82DA908:: switchindataupdate BS_FAINTED hpthresholds BS_FAINTED printstring STRINGID_SWITCHINMON - atk62 BS_FAINTED + hidepartystatussummary BS_FAINTED switchinanim BS_FAINTED, FALSE waitstate switchineffects 5 @@ -3136,7 +3136,7 @@ BattleScript_DoSwitchOut:: switchindataupdate BS_ATTACKER hpthresholds BS_ATTACKER printstring STRINGID_SWITCHINMON - atk62 BS_ATTACKER + hidepartystatussummary BS_ATTACKER switchinanim BS_ATTACKER, FALSE waitstate switchineffects BS_ATTACKER diff --git a/data/battle_scripts_2.s b/data/battle_scripts_2.s index 8020d7c5c..1fbaa9536 100644 --- a/data/battle_scripts_2.s +++ b/data/battle_scripts_2.s @@ -44,7 +44,7 @@ gBattlescriptsForSafariActions:: @ 82DBD58 .4byte BattleScript_ActionWatchesCarefully .4byte BattleScript_ActionGetNear .4byte BattleScript_ActionThrowPokeblock - .4byte BattleScript_82DBEE3 + .4byte BattleScript_ActionWallyThrow BattleScript_BallThrow:: jumpifword CMP_COMMON_BITS, gBattleTypeFlags, BATTLE_TYPE_WALLY_TUTORIAL, BattleScript_BallThrowByWally @@ -176,17 +176,17 @@ BattleScript_RunByUsingItem:: setbyte gBattleOutcome, B_OUTCOME_RAN finishturn -BattleScript_ActionWatchesCarefully:: +BattleScript_ActionWatchesCarefully: printstring STRINGID_PKMNWATCHINGCAREFULLY waitmessage 0x40 end2 -BattleScript_ActionGetNear:: +BattleScript_ActionGetNear: printfromtable gSafariGetNearStringIds waitmessage 0x40 end2 -BattleScript_ActionThrowPokeblock:: +BattleScript_ActionThrowPokeblock: printstring STRINGID_THREWPOKEBLOCKATPKMN waitmessage 0x40 playanimation BS_ATTACKER, B_ANIM_x4, NULL @@ -194,7 +194,7 @@ BattleScript_ActionThrowPokeblock:: waitmessage 0x40 end2 -BattleScript_82DBEE3:: +BattleScript_ActionWallyThrow: printstring STRINGID_RETURNMON waitmessage 0x40 returnatktoball diff --git a/include/battle.h b/include/battle.h index 2651407fb..20a6cf1b8 100644 --- a/include/battle.h +++ b/include/battle.h @@ -336,20 +336,20 @@ struct BattleResults u8 unk5_0:1; // 0x5 u8 usedMasterBall:1; // 0x5 u8 caughtMonBall:4; // 0x5 - u8 unk5_6:1; // 0x5 + u8 shinyWildMon:1; // 0x5 u8 unk5_7:1; // 0x5 u16 playerMon1Species; // 0x6 - u8 playerMon1Name[11]; // 0x8 + u8 playerMon1Name[POKEMON_NAME_LENGTH + 1]; // 0x8 u8 battleTurnCounter; // 0x13 - u8 playerMon2Name[11]; // 0x14 - u8 field_1F; // 0x1F + u8 playerMon2Name[POKEMON_NAME_LENGTH + 1]; // 0x14 + u8 pokeblockThrows; // 0x1F u16 lastOpponentSpecies; // 0x20 u16 lastUsedMovePlayer; // 0x22 u16 lastUsedMoveOpponent; // 0x24 u16 playerMon2Species; // 0x26 u16 caughtMonSpecies; // 0x28 - u8 caughtMonNick[10]; // 0x2A - u8 filler34[2]; // 0x34 + u8 caughtMonNick[POKEMON_NAME_LENGTH + 1]; // 0x2A + u8 filler35[1]; // 0x35 u8 catchAttempts[11]; // 0x36 }; @@ -663,13 +663,13 @@ struct BattleAnimationInfo struct BattleHealthboxInfo { - u8 flag_x1:1; + u8 partyStatusSummaryShown:1; u8 healthboxIsBouncing:1; u8 battlerIsBouncing:1; u8 ballAnimActive:1; // 0x8 u8 statusAnimActive:1; // x10 u8 animFromTableActive:1; // x20 - u8 specialAnimActive:1; //x40 + u8 specialAnimActive:1; // x40 u8 flag_x80:1; u8 field_1_x1:1; u8 field_1_x1E:4; @@ -733,7 +733,7 @@ extern u8 gBattlersCount; extern u16 gBattlerPartyIndexes[MAX_BATTLERS_COUNT]; extern u8 gBattlerPositions[MAX_BATTLERS_COUNT]; extern u8 gActionsByTurnOrder[MAX_BATTLERS_COUNT]; -extern u8 gBattleTurnOrder[MAX_BATTLERS_COUNT]; +extern u8 gBattlerByTurnOrder[MAX_BATTLERS_COUNT]; extern u8 gCurrentTurnActionNumber; extern u8 gCurrentActionFuncId; extern struct BattlePokemon gBattleMons[MAX_BATTLERS_COUNT]; diff --git a/include/battle_controllers.h b/include/battle_controllers.h index c5f5f48d7..61e2935b7 100644 --- a/include/battle_controllers.h +++ b/include/battle_controllers.h @@ -160,7 +160,7 @@ enum CONTROLLER_INTROSLIDE, CONTROLLER_INTROTRAINERBALLTHROW, CONTROLLER_DRAWPARTYSTATUSSUMMARY, - CONTROLLER_49, + CONTROLLER_HIDEPARTYSTATUSSUMMARY, CONTROLLER_ENDBOUNCE, CONTROLLER_SPRITEINVISIBILITY, CONTROLLER_BATTLEANIMATION, @@ -230,13 +230,13 @@ void BtlController_EmitFaintingCry(u8 bufferId); void BtlController_EmitIntroSlide(u8 bufferId, u8 terrainId); void BtlController_EmitIntroTrainerBallThrow(u8 bufferId); void BtlController_EmitDrawPartyStatusSummary(u8 bufferId, struct HpAndStatus* hpAndStatus, u8 arg2); -void BtlController_EmitCmd49(u8 bufferId); +void BtlController_EmitHidePartyStatusSummary(u8 bufferId); void BtlController_EmitEndBounceEffect(u8 bufferId); void BtlController_EmitSpriteInvisibility(u8 bufferId, bool8 isInvisible); void BtlController_EmitBattleAnimation(u8 bufferId, u8 animationId, u16 argument); void BtlController_EmitLinkStandbyMsg(u8 bufferId, u8 arg1, bool32 arg2); void BtlController_EmitResetActionMoveSelection(u8 bufferId, u8 caseId); -void BtlController_EmitCmd55(u8 bufferId, u8 arg1); +void BtlController_EmitCmd55(u8 bufferId, u8 battleOutcome); // player controller void SetControllerToPlayer(void); diff --git a/include/battle_interface.h b/include/battle_interface.h index b917d2cb3..2d93811f1 100644 --- a/include/battle_interface.h +++ b/include/battle_interface.h @@ -72,7 +72,7 @@ void InitBattlerHealthboxCoords(u8 bank); void UpdateHpTextInHealthbox(u8 healthboxSpriteId, s16 value, u8 maxOrCurrent); void SwapHpBarsWithHpText(void); u8 CreatePartyStatusSummarySprites(u8 bank, struct HpAndStatus *partyInfo, u8 arg2, bool8 isBattleStart); -void sub_8073C30(u8 taskId); +void Task_HidePartyStatusSummary(u8 taskId); void UpdateHealthboxAttribute(u8 healthboxSpriteId, struct Pokemon *mon, u8 elementId); s32 MoveBattleBar(u8 bank, u8 healthboxSpriteId, u8 whichBar, u8 arg3); u8 GetScaledHPFraction(s16 hp, s16 maxhp, u8 scale); diff --git a/src/battle_controller_link_opponent.c b/src/battle_controller_link_opponent.c index 0a53c2893..aa98b179d 100644 --- a/src/battle_controller_link_opponent.c +++ b/src/battle_controller_link_opponent.c @@ -89,7 +89,7 @@ static void LinkOpponentHandleFaintingCry(void); static void LinkOpponentHandleIntroSlide(void); static void LinkOpponentHandleIntroTrainerBallThrow(void); static void LinkOpponentHandleDrawPartyStatusSummary(void); -static void LinkOpponentHandleCmd49(void); +static void LinkOpponentHandleHidePartyStatusSummary(void); static void LinkOpponentHandleEndBounceEffect(void); static void LinkOpponentHandleSpriteInvisibility(void); static void LinkOpponentHandleBattleAnimation(void); @@ -161,7 +161,7 @@ static void (*const sLinkOpponentBufferCommands[CONTROLLER_CMDS_COUNT])(void) = LinkOpponentHandleIntroSlide, LinkOpponentHandleIntroTrainerBallThrow, LinkOpponentHandleDrawPartyStatusSummary, - LinkOpponentHandleCmd49, + LinkOpponentHandleHidePartyStatusSummary, LinkOpponentHandleEndBounceEffect, LinkOpponentHandleSpriteInvisibility, LinkOpponentHandleBattleAnimation, @@ -1716,8 +1716,8 @@ static void LinkOpponentHandleIntroTrainerBallThrow(void) taskId = CreateTask(sub_8067618, 5); gTasks[taskId].data[0] = gActiveBattler; - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].flag_x1) - gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = sub_8073C30; + if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].partyStatusSummaryShown) + gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = Task_HidePartyStatusSummary; gBattleSpritesDataPtr->animationData->field_9_x1 = 1; gBattlerControllerFuncs[gActiveBattler] = nullsub_28; @@ -1762,7 +1762,7 @@ static void LinkOpponentHandleDrawPartyStatusSummary(void) } else { - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].flag_x1 = 1; + gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].partyStatusSummaryShown = 1; if (gBattleBufferA[gActiveBattler][2] != 0) { @@ -1796,10 +1796,10 @@ static void sub_806782C(void) } } -static void LinkOpponentHandleCmd49(void) +static void LinkOpponentHandleHidePartyStatusSummary(void) { - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].flag_x1) - gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = sub_8073C30; + if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].partyStatusSummaryShown) + gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = Task_HidePartyStatusSummary; LinkOpponentBufferExecCompleted(); } diff --git a/src/battle_controller_link_partner.c b/src/battle_controller_link_partner.c index f5987c0ce..be9609e62 100644 --- a/src/battle_controller_link_partner.c +++ b/src/battle_controller_link_partner.c @@ -87,7 +87,7 @@ static void LinkPartnerHandleFaintingCry(void); static void LinkPartnerHandleIntroSlide(void); static void LinkPartnerHandleIntroTrainerBallThrow(void); static void LinkPartnerHandleDrawPartyStatusSummary(void); -static void LinkPartnerHandleCmd49(void); +static void LinkPartnerHandleHidePartyStatusSummary(void); static void LinkPartnerHandleEndBounceEffect(void); static void LinkPartnerHandleSpriteInvisibility(void); static void LinkPartnerHandleBattleAnimation(void); @@ -158,7 +158,7 @@ static void (*const sLinkPartnerBufferCommands[CONTROLLER_CMDS_COUNT])(void) = LinkPartnerHandleIntroSlide, LinkPartnerHandleIntroTrainerBallThrow, LinkPartnerHandleDrawPartyStatusSummary, - LinkPartnerHandleCmd49, + LinkPartnerHandleHidePartyStatusSummary, LinkPartnerHandleEndBounceEffect, LinkPartnerHandleSpriteInvisibility, LinkPartnerHandleBattleAnimation, @@ -1564,8 +1564,8 @@ static void LinkPartnerHandleIntroTrainerBallThrow(void) taskId = CreateTask(sub_814DCCC, 5); gTasks[taskId].data[0] = gActiveBattler; - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].flag_x1) - gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = sub_8073C30; + if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].partyStatusSummaryShown) + gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = Task_HidePartyStatusSummary; gBattleSpritesDataPtr->animationData->field_9_x1 = 1; gBattlerControllerFuncs[gActiveBattler] = nullsub_112; @@ -1611,7 +1611,7 @@ static void LinkPartnerHandleDrawPartyStatusSummary(void) } else { - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].flag_x1 = 1; + gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].partyStatusSummaryShown = 1; gBattlerStatusSummaryTaskId[gActiveBattler] = CreatePartyStatusSummarySprites(gActiveBattler, (struct HpAndStatus *)&gBattleBufferA[gActiveBattler][4], gBattleBufferA[gActiveBattler][1], gBattleBufferA[gActiveBattler][2]); gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].field_5 = 0; @@ -1631,10 +1631,10 @@ static void sub_814DE9C(void) } } -static void LinkPartnerHandleCmd49(void) +static void LinkPartnerHandleHidePartyStatusSummary(void) { - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].flag_x1) - gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = sub_8073C30; + if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].partyStatusSummaryShown) + gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = Task_HidePartyStatusSummary; LinkPartnerBufferExecCompleted(); } diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index 83dac5436..414e084ee 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -94,7 +94,7 @@ static void OpponentHandleFaintingCry(void); static void OpponentHandleIntroSlide(void); static void OpponentHandleIntroTrainerBallThrow(void); static void OpponentHandleDrawPartyStatusSummary(void); -static void OpponentHandleCmd49(void); +static void OpponentHandleHidePartyStatusSummary(void); static void OpponentHandleEndBounceEffect(void); static void OpponentHandleSpriteInvisibility(void); static void OpponentHandleBattleAnimation(void); @@ -166,7 +166,7 @@ static void (*const sOpponentBufferCommands[CONTROLLER_CMDS_COUNT])(void) = OpponentHandleIntroSlide, OpponentHandleIntroTrainerBallThrow, OpponentHandleDrawPartyStatusSummary, - OpponentHandleCmd49, + OpponentHandleHidePartyStatusSummary, OpponentHandleEndBounceEffect, OpponentHandleSpriteInvisibility, OpponentHandleBattleAnimation, @@ -1865,8 +1865,8 @@ static void OpponentHandleIntroTrainerBallThrow(void) taskId = CreateTask(sub_8062828, 5); gTasks[taskId].data[0] = gActiveBattler; - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].flag_x1) - gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = sub_8073C30; + if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].partyStatusSummaryShown) + gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = Task_HidePartyStatusSummary; gBattleSpritesDataPtr->animationData->field_9_x1 = 1; gBattlerControllerFuncs[gActiveBattler] = nullsub_26; @@ -1916,7 +1916,7 @@ static void OpponentHandleDrawPartyStatusSummary(void) } else { - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].flag_x1 = 1; + gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].partyStatusSummaryShown = 1; if (gBattleBufferA[gActiveBattler][2] != 0) { @@ -1950,10 +1950,10 @@ static void sub_8062A2C(void) } } -static void OpponentHandleCmd49(void) +static void OpponentHandleHidePartyStatusSummary(void) { - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].flag_x1) - gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = sub_8073C30; + if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].partyStatusSummaryShown) + gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = Task_HidePartyStatusSummary; OpponentBufferExecCompleted(); } diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index 63dc989be..86775f50e 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -100,7 +100,7 @@ static void PlayerHandleFaintingCry(void); static void PlayerHandleIntroSlide(void); static void PlayerHandleIntroTrainerBallThrow(void); static void PlayerHandleDrawPartyStatusSummary(void); -static void PlayerHandleCmd49(void); +static void PlayerHandleHidePartyStatusSummary(void); static void PlayerHandleEndBounceEffect(void); static void PlayerHandleSpriteInvisibility(void); static void PlayerHandleBattleAnimation(void); @@ -187,7 +187,7 @@ static void (*const sPlayerBufferCommands[CONTROLLER_CMDS_COUNT])(void) = PlayerHandleIntroSlide, PlayerHandleIntroTrainerBallThrow, PlayerHandleDrawPartyStatusSummary, - PlayerHandleCmd49, + PlayerHandleHidePartyStatusSummary, PlayerHandleEndBounceEffect, PlayerHandleSpriteInvisibility, PlayerHandleBattleAnimation, @@ -253,7 +253,7 @@ static void HandleInputChooseAction(void) DoBounceEffect(gActiveBattler, BOUNCE_HEALTHBOX, 7, 1); DoBounceEffect(gActiveBattler, BOUNCE_MON, 7, 1); - if (gMain.newAndRepeatedKeys & DPAD_ANY && gSaveBlock2Ptr->optionsButtonMode == 2) + if (gMain.newAndRepeatedKeys & DPAD_ANY && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_L_EQUALS_A) gPlayerDpadHoldFrames++; else gPlayerDpadHoldFrames = 0; @@ -485,7 +485,7 @@ static void HandleInputChooseMove(void) bool32 canSelectTarget = FALSE; struct ChooseMoveStruct *moveInfo = (struct ChooseMoveStruct*)(&gBattleBufferA[gActiveBattler][4]); - if (gMain.heldKeys & DPAD_ANY && gSaveBlock2Ptr->optionsButtonMode == 2) + if (gMain.heldKeys & DPAD_ANY && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_L_EQUALS_A) gPlayerDpadHoldFrames++; else gPlayerDpadHoldFrames = 0; @@ -2945,8 +2945,8 @@ static void PlayerHandleIntroTrainerBallThrow(void) taskId = CreateTask(task05_08033660, 5); gTasks[taskId].data[0] = gActiveBattler; - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].flag_x1) - gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = sub_8073C30; + if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].partyStatusSummaryShown) + gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = Task_HidePartyStatusSummary; gBattleSpritesDataPtr->animationData->field_9_x1 = 1; gBattlerControllerFuncs[gActiveBattler] = nullsub_21; @@ -3003,7 +3003,7 @@ static void PlayerHandleDrawPartyStatusSummary(void) } else { - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].flag_x1 = 1; + gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].partyStatusSummaryShown = 1; gBattlerStatusSummaryTaskId[gActiveBattler] = CreatePartyStatusSummarySprites(gActiveBattler, (struct HpAndStatus *)&gBattleBufferA[gActiveBattler][4], gBattleBufferA[gActiveBattler][1], gBattleBufferA[gActiveBattler][2]); gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].field_5 = 0; @@ -3023,10 +3023,10 @@ static void sub_805CE38(void) } } -static void PlayerHandleCmd49(void) +static void PlayerHandleHidePartyStatusSummary(void) { - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].flag_x1) - gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = sub_8073C30; + if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].partyStatusSummaryShown) + gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = Task_HidePartyStatusSummary; PlayerBufferExecCompleted(); } diff --git a/src/battle_controller_player_partner.c b/src/battle_controller_player_partner.c index 17ed1c24f..6a70200b6 100644 --- a/src/battle_controller_player_partner.c +++ b/src/battle_controller_player_partner.c @@ -87,7 +87,7 @@ static void PlayerPartnerHandleFaintingCry(void); static void PlayerPartnerHandleIntroSlide(void); static void PlayerPartnerHandleIntroTrainerBallThrow(void); static void PlayerPartnerHandleDrawPartyStatusSummary(void); -static void PlayerPartnerHandleCmd49(void); +static void PlayerPartnerHandleHidePartyStatusSummary(void); static void PlayerPartnerHandleEndBounceEffect(void); static void PlayerPartnerHandleSpriteInvisibility(void); static void PlayerPartnerHandleBattleAnimation(void); @@ -164,7 +164,7 @@ static void (*const sPlayerPartnerBufferCommands[CONTROLLER_CMDS_COUNT])(void) = PlayerPartnerHandleIntroSlide, PlayerPartnerHandleIntroTrainerBallThrow, PlayerPartnerHandleDrawPartyStatusSummary, - PlayerPartnerHandleCmd49, + PlayerPartnerHandleHidePartyStatusSummary, PlayerPartnerHandleEndBounceEffect, PlayerPartnerHandleSpriteInvisibility, PlayerPartnerHandleBattleAnimation, @@ -1810,8 +1810,8 @@ static void PlayerPartnerHandleIntroTrainerBallThrow(void) taskId = CreateTask(sub_81BE2C8, 5); gTasks[taskId].data[0] = gActiveBattler; - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].flag_x1) - gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = sub_8073C30; + if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].partyStatusSummaryShown) + gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = Task_HidePartyStatusSummary; gBattleSpritesDataPtr->animationData->field_9_x1 = 1; gBattlerControllerFuncs[gActiveBattler] = nullsub_77; @@ -1857,7 +1857,7 @@ static void PlayerPartnerHandleDrawPartyStatusSummary(void) } else { - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].flag_x1 = 1; + gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].partyStatusSummaryShown = 1; gBattlerStatusSummaryTaskId[gActiveBattler] = CreatePartyStatusSummarySprites(gActiveBattler, (struct HpAndStatus *)&gBattleBufferA[gActiveBattler][4], gBattleBufferA[gActiveBattler][1], gBattleBufferA[gActiveBattler][2]); gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].field_5 = 0; @@ -1877,10 +1877,10 @@ static void sub_81BE498(void) } } -static void PlayerPartnerHandleCmd49(void) +static void PlayerPartnerHandleHidePartyStatusSummary(void) { - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].flag_x1) - gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = sub_8073C30; + if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].partyStatusSummaryShown) + gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = Task_HidePartyStatusSummary; PlayerPartnerBufferExecCompleted(); } diff --git a/src/battle_controller_recorded_opponent.c b/src/battle_controller_recorded_opponent.c index 9d213fc6b..4b44116dd 100644 --- a/src/battle_controller_recorded_opponent.c +++ b/src/battle_controller_recorded_opponent.c @@ -90,7 +90,7 @@ static void RecordedOpponentHandleFaintingCry(void); static void RecordedOpponentHandleIntroSlide(void); static void RecordedOpponentHandleIntroTrainerBallThrow(void); static void RecordedOpponentHandleDrawPartyStatusSummary(void); -static void RecordedOpponentHandleCmd49(void); +static void RecordedOpponentHandleHidePartyStatusSummary(void); static void RecordedOpponentHandleEndBounceEffect(void); static void RecordedOpponentHandleSpriteInvisibility(void); static void RecordedOpponentHandleBattleAnimation(void); @@ -162,7 +162,7 @@ static void (*const sRecordedOpponentBufferCommands[CONTROLLER_CMDS_COUNT])(void RecordedOpponentHandleIntroSlide, RecordedOpponentHandleIntroTrainerBallThrow, RecordedOpponentHandleDrawPartyStatusSummary, - RecordedOpponentHandleCmd49, + RecordedOpponentHandleHidePartyStatusSummary, RecordedOpponentHandleEndBounceEffect, RecordedOpponentHandleSpriteInvisibility, RecordedOpponentHandleBattleAnimation, @@ -1658,8 +1658,8 @@ static void RecordedOpponentHandleIntroTrainerBallThrow(void) taskId = CreateTask(sub_8189548, 5); gTasks[taskId].data[0] = gActiveBattler; - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].flag_x1) - gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = sub_8073C30; + if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].partyStatusSummaryShown) + gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = Task_HidePartyStatusSummary; gBattleSpritesDataPtr->animationData->field_9_x1 = 1; gBattlerControllerFuncs[gActiveBattler] = nullsub_70; @@ -1704,7 +1704,7 @@ static void RecordedOpponentHandleDrawPartyStatusSummary(void) } else { - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].flag_x1 = 1; + gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].partyStatusSummaryShown = 1; if (gBattleBufferA[gActiveBattler][2] != 0) { @@ -1738,10 +1738,10 @@ static void sub_818975C(void) } } -static void RecordedOpponentHandleCmd49(void) +static void RecordedOpponentHandleHidePartyStatusSummary(void) { - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].flag_x1) - gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = sub_8073C30; + if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].partyStatusSummaryShown) + gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = Task_HidePartyStatusSummary; RecordedOpponentBufferExecCompleted(); } diff --git a/src/battle_controller_recorded_player.c b/src/battle_controller_recorded_player.c index d1836c092..b6a96b6fd 100644 --- a/src/battle_controller_recorded_player.c +++ b/src/battle_controller_recorded_player.c @@ -89,7 +89,7 @@ static void RecordedPlayerHandleFaintingCry(void); static void RecordedPlayerHandleIntroSlide(void); static void RecordedPlayerHandleIntroTrainerBallThrow(void); static void RecordedPlayerHandleDrawPartyStatusSummary(void); -static void RecordedPlayerHandleCmd49(void); +static void RecordedPlayerHandleHidePartyStatusSummary(void); static void RecordedPlayerHandleEndBounceEffect(void); static void RecordedPlayerHandleSpriteInvisibility(void); static void RecordedPlayerHandleBattleAnimation(void); @@ -160,7 +160,7 @@ static void (*const sRecordedPlayerBufferCommands[CONTROLLER_CMDS_COUNT])(void) RecordedPlayerHandleIntroSlide, RecordedPlayerHandleIntroTrainerBallThrow, RecordedPlayerHandleDrawPartyStatusSummary, - RecordedPlayerHandleCmd49, + RecordedPlayerHandleHidePartyStatusSummary, RecordedPlayerHandleEndBounceEffect, RecordedPlayerHandleSpriteInvisibility, RecordedPlayerHandleBattleAnimation, @@ -1693,8 +1693,8 @@ static void RecordedPlayerHandleIntroTrainerBallThrow(void) taskId = CreateTask(sub_818CC24, 5); gTasks[taskId].data[0] = gActiveBattler; - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].flag_x1) - gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = sub_8073C30; + if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].partyStatusSummaryShown) + gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = Task_HidePartyStatusSummary; gBattleSpritesDataPtr->animationData->field_9_x1 = 1; gBattlerControllerFuncs[gActiveBattler] = nullsub_120; @@ -1740,7 +1740,7 @@ static void RecordedPlayerHandleDrawPartyStatusSummary(void) } else { - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].flag_x1 = 1; + gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].partyStatusSummaryShown = 1; gBattlerStatusSummaryTaskId[gActiveBattler] = CreatePartyStatusSummarySprites(gActiveBattler, (struct HpAndStatus *)&gBattleBufferA[gActiveBattler][4], gBattleBufferA[gActiveBattler][1], gBattleBufferA[gActiveBattler][2]); gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].field_5 = 0; @@ -1760,10 +1760,10 @@ static void sub_818CDF4(void) } } -static void RecordedPlayerHandleCmd49(void) +static void RecordedPlayerHandleHidePartyStatusSummary(void) { - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].flag_x1) - gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = sub_8073C30; + if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].partyStatusSummaryShown) + gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = Task_HidePartyStatusSummary; RecordedPlayerBufferExecCompleted(); } diff --git a/src/battle_controller_safari.c b/src/battle_controller_safari.c index 3cdd952ef..bc69e2624 100644 --- a/src/battle_controller_safari.c +++ b/src/battle_controller_safari.c @@ -80,7 +80,7 @@ static void SafariHandleFaintingCry(void); static void SafariHandleIntroSlide(void); static void SafariHandleIntroTrainerBallThrow(void); static void SafariHandleDrawPartyStatusSummary(void); -static void SafariHandleCmd49(void); +static void SafariHandleHidePartyStatusSummary(void); static void SafariHandleEndBounceEffect(void); static void SafariHandleSpriteInvisibility(void); static void SafariHandleBattleAnimation(void); @@ -144,7 +144,7 @@ static void (*const sSafariBufferCommands[CONTROLLER_CMDS_COUNT])(void) = SafariHandleIntroSlide, SafariHandleIntroTrainerBallThrow, SafariHandleDrawPartyStatusSummary, - SafariHandleCmd49, + SafariHandleHidePartyStatusSummary, SafariHandleEndBounceEffect, SafariHandleSpriteInvisibility, SafariHandleBattleAnimation, @@ -645,7 +645,7 @@ static void SafariHandleDrawPartyStatusSummary(void) SafariBufferExecCompleted(); } -static void SafariHandleCmd49(void) +static void SafariHandleHidePartyStatusSummary(void) { SafariBufferExecCompleted(); } diff --git a/src/battle_controller_wally.c b/src/battle_controller_wally.c index 05c7b9e1f..5399ccbf0 100644 --- a/src/battle_controller_wally.c +++ b/src/battle_controller_wally.c @@ -90,7 +90,7 @@ static void WallyHandleFaintingCry(void); static void WallyHandleIntroSlide(void); static void WallyHandleIntroTrainerBallThrow(void); static void WallyHandleDrawPartyStatusSummary(void); -static void WallyHandleCmd49(void); +static void WallyHandleHidePartyStatusSummary(void); static void WallyHandleEndBounceEffect(void); static void WallyHandleSpriteInvisibility(void); static void WallyHandleBattleAnimation(void); @@ -159,7 +159,7 @@ static void (*const sWallyBufferCommands[CONTROLLER_CMDS_COUNT])(void) = WallyHandleIntroSlide, WallyHandleIntroTrainerBallThrow, WallyHandleDrawPartyStatusSummary, - WallyHandleCmd49, + WallyHandleHidePartyStatusSummary, WallyHandleEndBounceEffect, WallyHandleSpriteInvisibility, WallyHandleBattleAnimation, @@ -1450,8 +1450,8 @@ static void WallyHandleIntroTrainerBallThrow(void) taskId = CreateTask(sub_816AC04, 5); gTasks[taskId].data[0] = gActiveBattler; - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].flag_x1) - gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = sub_8073C30; + if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].partyStatusSummaryShown) + gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = Task_HidePartyStatusSummary; gBattleSpritesDataPtr->animationData->field_9_x1 = 1; gBattlerControllerFuncs[gActiveBattler] = nullsub_21; @@ -1511,13 +1511,13 @@ static void WallyHandleDrawPartyStatusSummary(void) } else { - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].flag_x1 = 1; + gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].partyStatusSummaryShown = 1; gBattlerStatusSummaryTaskId[gActiveBattler] = CreatePartyStatusSummarySprites(gActiveBattler, (struct HpAndStatus *)&gBattleBufferA[gActiveBattler][4], gBattleBufferA[gActiveBattler][1], gBattleBufferA[gActiveBattler][2]); WallyBufferExecCompleted(); } } -static void WallyHandleCmd49(void) +static void WallyHandleHidePartyStatusSummary(void) { WallyBufferExecCompleted(); } diff --git a/src/battle_controllers.c b/src/battle_controllers.c index 1c60e22ef..4da941ab0 100644 --- a/src/battle_controllers.c +++ b/src/battle_controllers.c @@ -1449,17 +1449,17 @@ void BtlController_EmitDrawPartyStatusSummary(u8 bufferId, struct HpAndStatus* h sBattleBuffersTransferData[1] = arg2 & 0x7F; sBattleBuffersTransferData[2] = (arg2 & 0x80) >> 7; sBattleBuffersTransferData[3] = CONTROLLER_DRAWPARTYSTATUSSUMMARY; - for (i = 0; i < (s32)(sizeof(struct HpAndStatus) * 6); i++) + for (i = 0; i < (s32)(sizeof(struct HpAndStatus) * PARTY_SIZE); i++) sBattleBuffersTransferData[4 + i] = *(i + (u8*)(hpAndStatus)); - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, sizeof(struct HpAndStatus) * 6 + 4); + PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, sizeof(struct HpAndStatus) * PARTY_SIZE + 4); } -void BtlController_EmitCmd49(u8 bufferId) +void BtlController_EmitHidePartyStatusSummary(u8 bufferId) { - sBattleBuffersTransferData[0] = CONTROLLER_49; - sBattleBuffersTransferData[1] = CONTROLLER_49; - sBattleBuffersTransferData[2] = CONTROLLER_49; - sBattleBuffersTransferData[3] = CONTROLLER_49; + sBattleBuffersTransferData[0] = CONTROLLER_HIDEPARTYSTATUSSUMMARY; + sBattleBuffersTransferData[1] = CONTROLLER_HIDEPARTYSTATUSSUMMARY; + sBattleBuffersTransferData[2] = CONTROLLER_HIDEPARTYSTATUSSUMMARY; + sBattleBuffersTransferData[3] = CONTROLLER_HIDEPARTYSTATUSSUMMARY; PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); } @@ -1511,10 +1511,10 @@ void BtlController_EmitResetActionMoveSelection(u8 bufferId, u8 caseId) PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 2); } -void BtlController_EmitCmd55(u8 bufferId, u8 arg1) +void BtlController_EmitCmd55(u8 bufferId, u8 battleOutcome) { sBattleBuffersTransferData[0] = CONTROLLER_55; - sBattleBuffersTransferData[1] = arg1; + sBattleBuffersTransferData[1] = battleOutcome; sBattleBuffersTransferData[2] = gSaveBlock2Ptr->field_CA9_b; sBattleBuffersTransferData[3] = gSaveBlock2Ptr->field_CA9_b; sBattleBuffersTransferData[5] = sBattleBuffersTransferData[4] = sub_81850DC(&sBattleBuffersTransferData[6]); diff --git a/src/battle_interface.c b/src/battle_interface.c index f5e031cb9..6a30ed487 100644 --- a/src/battle_interface.c +++ b/src/battle_interface.c @@ -1695,7 +1695,7 @@ u8 CreatePartyStatusSummarySprites(u8 battlerId, struct HpAndStatus *partyInfo, return taskId; } -void sub_8073C30(u8 taskId) +void Task_HidePartyStatusSummary(u8 taskId) { u8 ballIconSpriteIds[PARTY_SIZE]; bool8 isBattleStart; @@ -1707,7 +1707,7 @@ void sub_8073C30(u8 taskId) summaryBarSpriteId = gTasks[taskId].tSummaryBarSpriteId; battlerId = gTasks[taskId].tBattler; - for (i = 0; i < 6; i++) + for (i = 0; i < PARTY_SIZE; i++) ballIconSpriteIds[i] = gTasks[taskId].tBallIconSpriteId(i); SetGpuReg(REG_OFFSET_BLDCNT, 0x3F40); @@ -1755,12 +1755,12 @@ static void sub_8073E08(u8 taskId) { if ((gTasks[taskId].data[11]++ % 2) == 0) { - if (--gTasks[taskId].data[15] < 0) + if (--gTasks[taskId].tData15 < 0) return; SetGpuReg(REG_OFFSET_BLDALPHA, (gTasks[taskId].data[15]) | ((16 - gTasks[taskId].data[15]) << 8)); } - if (gTasks[taskId].data[15] == 0) + if (gTasks[taskId].tData15 == 0) gTasks[taskId].func = sub_8073E64; } @@ -1796,7 +1796,7 @@ static void sub_8073E64(u8 taskId) } else if (gTasks[taskId].tData15 == -3) { - gBattleSpritesDataPtr->healthBoxesData[battlerId].flag_x1 = 0; + gBattleSpritesDataPtr->healthBoxesData[battlerId].partyStatusSummaryShown = 0; SetGpuReg(REG_OFFSET_BLDCNT, 0); SetGpuReg(REG_OFFSET_BLDALPHA, 0); DestroyTask(taskId); @@ -1828,7 +1828,7 @@ static void sub_8073F98(u8 taskId) } else if (gTasks[taskId].tData15 == -3) { - gBattleSpritesDataPtr->healthBoxesData[battlerId].flag_x1 = 0; + gBattleSpritesDataPtr->healthBoxesData[battlerId].partyStatusSummaryShown = 0; SetGpuReg(REG_OFFSET_BLDCNT, 0); SetGpuReg(REG_OFFSET_BLDALPHA, 0); DestroyTask(taskId); diff --git a/src/battle_main.c b/src/battle_main.c index 9afbc7f40..a0d812a94 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -82,15 +82,15 @@ extern struct MusicPlayerInfo gMPlayInfo_SE1; extern struct MusicPlayerInfo gMPlayInfo_SE2; extern u8 gUnknown_0203CF00[]; -extern const u16 gBattleTextboxPalette[]; // battle textbox palette +extern const u16 gBattleTextboxPalette[]; extern const struct BgTemplate gBattleBgTemplates[]; -extern const struct WindowTemplate * const gBattleWindowTemplates[]; +extern const struct WindowTemplate *const gBattleWindowTemplates[]; extern const u8 gUnknown_0831ACE0[]; -extern const u8 * const gBattleScriptsForMoveEffects[]; -extern const u8 * const gBattlescriptsForBallThrow[]; -extern const u8 * const gBattlescriptsForRunningByItem[]; -extern const u8 * const gBattlescriptsForUsingItem[]; -extern const u8 * const gBattlescriptsForSafariActions[]; +extern const u8 *const gBattleScriptsForMoveEffects[]; +extern const u8 *const gBattlescriptsForBallThrow[]; +extern const u8 *const gBattlescriptsForRunningByItem[]; +extern const u8 *const gBattlescriptsForUsingItem[]; +extern const u8 *const gBattlescriptsForSafariActions[]; extern const struct ScanlineEffectParams gUnknown_0831AC70; // strings @@ -206,7 +206,7 @@ EWRAM_DATA u8 gBattlersCount = 0; EWRAM_DATA u16 gBattlerPartyIndexes[MAX_BATTLERS_COUNT] = {0}; EWRAM_DATA u8 gBattlerPositions[MAX_BATTLERS_COUNT] = {0}; EWRAM_DATA u8 gActionsByTurnOrder[MAX_BATTLERS_COUNT] = {0}; -EWRAM_DATA u8 gBattleTurnOrder[MAX_BATTLERS_COUNT] = {0}; +EWRAM_DATA u8 gBattlerByTurnOrder[MAX_BATTLERS_COUNT] = {0}; EWRAM_DATA u8 gCurrentTurnActionNumber = 0; EWRAM_DATA u8 gCurrentActionFuncId = 0; EWRAM_DATA struct BattlePokemon gBattleMons[MAX_BATTLERS_COUNT] = {0}; @@ -3067,7 +3067,7 @@ static void BattleStartClearSetData(void) for (i = 0; i < MAX_BATTLERS_COUNT; i++) { - *(gBattleStruct->AI_monToSwitchIntoId + i) = 6; + *(gBattleStruct->AI_monToSwitchIntoId + i) = PARTY_SIZE; } gBattleStruct->field_DF = 0; @@ -3079,7 +3079,7 @@ static void BattleStartClearSetData(void) for (i = 0; i < sizeof(struct BattleResults); i++) dataPtr[i] = 0; - gBattleResults.unk5_6 = IsMonShiny(&gEnemyParty[0]); + gBattleResults.shinyWildMon = IsMonShiny(&gEnemyParty[0]); gBattleStruct->field_2A0 = 0; gBattleStruct->field_2A1 = 0; @@ -3427,7 +3427,7 @@ static void BattleIntroDrawTrainersOrMonsSprites(void) static void BattleIntroDrawPartySummaryScreens(void) { s32 i; - struct HpAndStatus hpStatus[6]; + struct HpAndStatus hpStatus[PARTY_SIZE]; if (gBattleControllerExecFlags) return; @@ -3478,7 +3478,7 @@ static void BattleIntroDrawPartySummaryScreens(void) // wild battles don't show the party summary. // Still, there's no point in having dead code. - for (i = 0; i < 6; i++) + for (i = 0; i < PARTY_SIZE; i++) { if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2) == SPECIES_NONE || GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2) == SPECIES_EGG) @@ -3848,12 +3848,12 @@ static void TryDoEventsBeforeFirstTurn(void) if (gBattleStruct->switchInAbilitiesCounter == 0) { for (i = 0; i < gBattlersCount; i++) - gBattleTurnOrder[i] = i; + gBattlerByTurnOrder[i] = i; for (i = 0; i < gBattlersCount - 1; i++) { for (j = i + 1; j < gBattlersCount; j++) { - if (GetWhoStrikesFirst(gBattleTurnOrder[i], gBattleTurnOrder[j], TRUE) != 0) + if (GetWhoStrikesFirst(gBattlerByTurnOrder[i], gBattlerByTurnOrder[j], TRUE) != 0) SwapTurnOrder(i, j); } } @@ -3864,10 +3864,10 @@ static void TryDoEventsBeforeFirstTurn(void) gBattleStruct->overworldWeatherDone = TRUE; return; } - // check all switch in abilities happening from the fastest mon to slowest + // Check all switch in abilities happening from the fastest mon to slowest. while (gBattleStruct->switchInAbilitiesCounter < gBattlersCount) { - if (AbilityBattleEffects(ABILITYEFFECT_ON_SWITCHIN, gBattleTurnOrder[gBattleStruct->switchInAbilitiesCounter], 0, 0, 0) != 0) + if (AbilityBattleEffects(ABILITYEFFECT_ON_SWITCHIN, gBattlerByTurnOrder[gBattleStruct->switchInAbilitiesCounter], 0, 0, 0) != 0) effect++; gBattleStruct->switchInAbilitiesCounter++; @@ -3879,10 +3879,10 @@ static void TryDoEventsBeforeFirstTurn(void) return; if (AbilityBattleEffects(ABILITYEFFECT_TRACE, 0, 0, 0, 0) != 0) return; - // check all switch in items having effect from the fastest mon to slowest + // Check all switch in items having effect from the fastest mon to slowest. while (gBattleStruct->switchInItemsCounter < gBattlersCount) { - if (ItemBattleEffects(ITEMEFFECT_ON_SWITCH_IN, gBattleTurnOrder[gBattleStruct->switchInItemsCounter], 0) != 0) + if (ItemBattleEffects(ITEMEFFECT_ON_SWITCH_IN, gBattlerByTurnOrder[gBattleStruct->switchInItemsCounter], 0) != 0) effect++; gBattleStruct->switchInItemsCounter++; @@ -3892,7 +3892,7 @@ static void TryDoEventsBeforeFirstTurn(void) } for (i = 0; i < MAX_BATTLERS_COUNT; i++) { - *(gBattleStruct->monToSwitchIntoId + i) = 6; + *(gBattleStruct->monToSwitchIntoId + i) = PARTY_SIZE; gChosenActionByBattler[i] = B_ACTION_NONE; gChosenMoveByBattler[i] = MOVE_NONE; } @@ -3958,15 +3958,15 @@ void BattleTurnPassed(void) TurnValuesCleanUp(TRUE); if (gBattleOutcome == 0) { - if (UpdateTurnCounters() != 0) + if (UpdateTurnCounters()) return; - if (TurnBasedEffects() != 0) + if (TurnBasedEffects()) return; } - if (HandleFaintedMonActions() != 0) + if (HandleFaintedMonActions()) return; gBattleStruct->faintedActionsState = 0; - if (HandleWishPerishSongOnTurnEnd() != 0) + if (HandleWishPerishSongOnTurnEnd()) return; TurnValuesCleanUp(FALSE); @@ -4003,7 +4003,7 @@ void BattleTurnPassed(void) } for (i = 0; i < 4; i++) - *(gBattleStruct->monToSwitchIntoId + i) = 6; + *(gBattleStruct->monToSwitchIntoId + i) = PARTY_SIZE; *(&gBattleStruct->field_91) = gAbsentBattlerFlags; BattlePutTextOnWindow(gText_EmptyString3, 0); @@ -4141,11 +4141,11 @@ static void HandleTurnActionSelectionState(void) gBattleCommunication[gActiveBattler] = STATE_BEFORE_ACTION_CHOSEN; break; case STATE_BEFORE_ACTION_CHOSEN: // choose an action - *(gBattleStruct->monToSwitchIntoId + gActiveBattler) = 6; + *(gBattleStruct->monToSwitchIntoId + gActiveBattler) = PARTY_SIZE; if (gBattleTypeFlags & BATTLE_TYPE_MULTI - || !(position & BIT_FLANK) + || (position & BIT_FLANK) == B_FLANK_LEFT || gBattleStruct->field_91 & gBitTable[GetBattlerAtPosition(BATTLE_PARTNER(position))] - || gBattleCommunication[GetBattlerAtPosition(BATTLE_PARTNER(position))] == 5) + || gBattleCommunication[GetBattlerAtPosition(BATTLE_PARTNER(position))] == STATE_WAIT_ACTION_CONFIRMED) { if (gBattleStruct->field_91 & gBitTable[gActiveBattler]) { @@ -4415,7 +4415,7 @@ static void HandleTurnActionSelectionState(void) } break; case B_ACTION_SWITCH: - if (gBattleBufferB[gActiveBattler][1] == 6) + if (gBattleBufferB[gActiveBattler][1] == PARTY_SIZE) { gBattleCommunication[gActiveBattler] = 1; RecordedBattle_ClearBattlerAction(gActiveBattler, 1); @@ -4591,9 +4591,9 @@ void SwapTurnOrder(u8 id1, u8 id2) gActionsByTurnOrder[id1] = gActionsByTurnOrder[id2]; gActionsByTurnOrder[id2] = temp; - temp = gBattleTurnOrder[id1]; - gBattleTurnOrder[id1] = gBattleTurnOrder[id2]; - gBattleTurnOrder[id2] = temp; + temp = gBattlerByTurnOrder[id1]; + gBattlerByTurnOrder[id1] = gBattlerByTurnOrder[id2]; + gBattlerByTurnOrder[id2] = temp; } u8 GetWhoStrikesFirst(u8 battler1, u8 battler2, bool8 ignoreChosenMoves) @@ -4753,16 +4753,16 @@ u8 GetWhoStrikesFirst(u8 battler1, u8 battler2, bool8 ignoreChosenMoves) static void SetActionsAndBattlersTurnOrder(void) { - s32 var = 0; + s32 turnOrderId = 0; s32 i, j; if (gBattleTypeFlags & BATTLE_TYPE_SAFARI) { for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) { - gActionsByTurnOrder[var] = gChosenActionByBattler[gActiveBattler]; - gBattleTurnOrder[var] = gActiveBattler; - var++; + gActionsByTurnOrder[turnOrderId] = gChosenActionByBattler[gActiveBattler]; + gBattlerByTurnOrder[turnOrderId] = gActiveBattler; + turnOrderId++; } } else @@ -4773,7 +4773,7 @@ static void SetActionsAndBattlersTurnOrder(void) { if (gChosenActionByBattler[gActiveBattler] == B_ACTION_RUN) { - var = 5; + turnOrderId = 5; break; } } @@ -4783,27 +4783,27 @@ static void SetActionsAndBattlersTurnOrder(void) if (gChosenActionByBattler[0] == B_ACTION_RUN) { gActiveBattler = 0; - var = 5; + turnOrderId = 5; } if (gChosenActionByBattler[2] == B_ACTION_RUN) { gActiveBattler = 2; - var = 5; + turnOrderId = 5; } } - if (var == 5) + if (turnOrderId == 5) // One of battlers wants to run. { gActionsByTurnOrder[0] = gChosenActionByBattler[gActiveBattler]; - gBattleTurnOrder[0] = gActiveBattler; - var = 1; + gBattlerByTurnOrder[0] = gActiveBattler; + turnOrderId = 1; for (i = 0; i < gBattlersCount; i++) { if (i != gActiveBattler) { - gActionsByTurnOrder[var] = gChosenActionByBattler[i]; - gBattleTurnOrder[var] = i; - var++; + gActionsByTurnOrder[turnOrderId] = gChosenActionByBattler[i]; + gBattlerByTurnOrder[turnOrderId] = i; + turnOrderId++; } } gBattleMainFunc = CheckFocusPunch_ClearVarsBeforeTurnStarts; @@ -4816,26 +4816,26 @@ static void SetActionsAndBattlersTurnOrder(void) { if (gChosenActionByBattler[gActiveBattler] == B_ACTION_USE_ITEM || gChosenActionByBattler[gActiveBattler] == B_ACTION_SWITCH) { - gActionsByTurnOrder[var] = gChosenActionByBattler[gActiveBattler]; - gBattleTurnOrder[var] = gActiveBattler; - var++; + gActionsByTurnOrder[turnOrderId] = gChosenActionByBattler[gActiveBattler]; + gBattlerByTurnOrder[turnOrderId] = gActiveBattler; + turnOrderId++; } } for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) { if (gChosenActionByBattler[gActiveBattler] != B_ACTION_USE_ITEM && gChosenActionByBattler[gActiveBattler] != B_ACTION_SWITCH) { - gActionsByTurnOrder[var] = gChosenActionByBattler[gActiveBattler]; - gBattleTurnOrder[var] = gActiveBattler; - var++; + gActionsByTurnOrder[turnOrderId] = gChosenActionByBattler[gActiveBattler]; + gBattlerByTurnOrder[turnOrderId] = gActiveBattler; + turnOrderId++; } } for (i = 0; i < gBattlersCount - 1; i++) { for (j = i + 1; j < gBattlersCount; j++) { - u8 battler1 = gBattleTurnOrder[i]; - u8 battler2 = gBattleTurnOrder[j]; + u8 battler1 = gBattlerByTurnOrder[i]; + u8 battler2 = gBattlerByTurnOrder[j]; if (gActionsByTurnOrder[i] != B_ACTION_USE_ITEM && gActionsByTurnOrder[j] != B_ACTION_USE_ITEM && gActionsByTurnOrder[i] != B_ACTION_SWITCH @@ -4882,7 +4882,7 @@ static void TurnValuesCleanUp(bool8 var0) } if (gDisableStructs[gActiveBattler].substituteHP == 0) - gBattleMons[gActiveBattler].status2 &= ~(STATUS2_SUBSTITUTE); + gBattleMons[gActiveBattler].status2 &= ~(STATUS2_SUBSTITUTE); } gSideTimers[0].followmeTimer = 0; @@ -5136,7 +5136,7 @@ static void HandleEndTurn_FinishBattle(void) | BATTLE_TYPE_FRONTIER | BATTLE_TYPE_EREADER_TRAINER | BATTLE_TYPE_WALLY_TUTORIAL)) - && gBattleResults.unk5_6) + && gBattleResults.shinyWildMon) { sub_80EE184(); } @@ -5268,7 +5268,7 @@ static void HandleAction_UseMove(void) u8 side; u8 var = 4; - gBattlerAttacker = gBattleTurnOrder[gCurrentTurnActionNumber]; + gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; if (*(&gBattleStruct->field_91) & gBitTable[gBattlerAttacker]) { @@ -5400,7 +5400,7 @@ static void HandleAction_UseMove(void) } else { - gActiveBattler = gBattleTurnOrder[var]; + gActiveBattler = gBattlerByTurnOrder[var]; RecordAbilityBattle(gActiveBattler, gBattleMons[gActiveBattler].ability); gSpecialStatuses[gActiveBattler].lightningRodRedirected = 1; gBattlerTarget = gActiveBattler; @@ -5482,7 +5482,7 @@ static void HandleAction_UseMove(void) static void HandleAction_Switch(void) { - gBattlerAttacker = gBattleTurnOrder[gCurrentTurnActionNumber]; + gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; gBattle_BG0_X = 0; gBattle_BG0_Y = 0; gActionSelectionCursor[gBattlerAttacker] = 0; @@ -5500,7 +5500,7 @@ static void HandleAction_Switch(void) static void HandleAction_UseItem(void) { - gBattlerAttacker = gBattlerTarget = gBattleTurnOrder[gCurrentTurnActionNumber]; + gBattlerAttacker = gBattlerTarget = gBattlerByTurnOrder[gCurrentTurnActionNumber]; gBattle_BG0_X = 0; gBattle_BG0_Y = 0; ClearFuryCutterDestinyBondGrudge(gBattlerAttacker); @@ -5659,7 +5659,7 @@ bool8 TryRunFromBattle(u8 battler) static void HandleAction_Run(void) { - gBattlerAttacker = gBattleTurnOrder[gCurrentTurnActionNumber]; + gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000)) { @@ -5713,7 +5713,7 @@ static void HandleAction_Run(void) static void HandleAction_WatchesCarefully(void) { - gBattlerAttacker = gBattleTurnOrder[gCurrentTurnActionNumber]; + gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; gBattle_BG0_X = 0; gBattle_BG0_Y = 0; gBattlescriptCurrInstr = gBattlescriptsForSafariActions[0]; @@ -5722,7 +5722,7 @@ static void HandleAction_WatchesCarefully(void) static void HandleAction_SafariZoneBallThrow(void) { - gBattlerAttacker = gBattleTurnOrder[gCurrentTurnActionNumber]; + gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; gBattle_BG0_X = 0; gBattle_BG0_Y = 0; gNumSafariBalls--; @@ -5733,14 +5733,14 @@ static void HandleAction_SafariZoneBallThrow(void) static void HandleAction_ThrowPokeblock(void) { - gBattlerAttacker = gBattleTurnOrder[gCurrentTurnActionNumber]; + gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; gBattle_BG0_X = 0; gBattle_BG0_Y = 0; gBattleCommunication[MULTISTRING_CHOOSER] = gBattleBufferB[gBattlerAttacker][1] - 1; gLastUsedItem = gBattleBufferB[gBattlerAttacker][2]; - if (gBattleResults.field_1F < 0xFF) - gBattleResults.field_1F++; + if (gBattleResults.pokeblockThrows < 0xFF) + gBattleResults.pokeblockThrows++; if (gBattleStruct->field_7A < 3) gBattleStruct->field_7A++; if (gBattleStruct->field_7B > 1) @@ -5757,7 +5757,7 @@ static void HandleAction_ThrowPokeblock(void) static void HandleAction_GoNear(void) { - gBattlerAttacker = gBattleTurnOrder[gCurrentTurnActionNumber]; + gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; gBattle_BG0_X = 0; gBattle_BG0_Y = 0; @@ -5784,7 +5784,7 @@ static void HandleAction_GoNear(void) static void HandleAction_SafriZoneRun(void) { - gBattlerAttacker = gBattleTurnOrder[gCurrentTurnActionNumber]; + gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; PlaySE(SE_NIGERU); gCurrentTurnActionNumber = gBattlersCount; gBattleOutcome = B_OUTCOME_RAN; @@ -5792,7 +5792,7 @@ static void HandleAction_SafriZoneRun(void) static void HandleAction_WallyBallThrow(void) { - gBattlerAttacker = gBattleTurnOrder[gCurrentTurnActionNumber]; + gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; gBattle_BG0_X = 0; gBattle_BG0_Y = 0; @@ -5825,7 +5825,7 @@ static void HandleAction_NothingIsFainted(void) static void HandleAction_ActionFinished(void) { - *(gBattleStruct->monToSwitchIntoId + gBattleTurnOrder[gCurrentTurnActionNumber]) = 6; + *(gBattleStruct->monToSwitchIntoId + gBattlerByTurnOrder[gCurrentTurnActionNumber]) = 6; gCurrentTurnActionNumber++; gCurrentActionFuncId = gActionsByTurnOrder[gCurrentTurnActionNumber]; SpecialStatusesClear(); diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index c26e5ac11..fb77ab4c4 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -188,7 +188,7 @@ static void atk5E(void); static void atk5F(void); static void atk60_incrementgamestat(void); static void atk61_drawpartystatussummary(void); -static void atk62(void); +static void atk62_hidepartystatussummary(void); static void atk63_jumptorandomattack(void); static void atk64_statusanimation(void); static void atk65_status2animation(void); @@ -440,7 +440,7 @@ void (* const gBattleScriptingCommandsTable[])(void) = atk5F, atk60_incrementgamestat, atk61_drawpartystatussummary, - atk62, + atk62_hidepartystatussummary, atk63_jumptorandomattack, atk64_statusanimation, atk65_status2animation, @@ -989,11 +989,11 @@ static void atk00_attackcanceler(void) for (i = 0; i < gBattlersCount; i++) { - if ((gProtectStructs[gBattleTurnOrder[i]].stealMove) && gBattleMoves[gCurrentMove].flags & FLAG_SNATCH_AFFECTED) + if ((gProtectStructs[gBattlerByTurnOrder[i]].stealMove) && gBattleMoves[gCurrentMove].flags & FLAG_SNATCH_AFFECTED) { - PressurePPLose(gBattlerAttacker, gBattleTurnOrder[i], MOVE_SNATCH); - gProtectStructs[gBattleTurnOrder[i]].stealMove = 0; - gBattleScripting.battler = gBattleTurnOrder[i]; + PressurePPLose(gBattlerAttacker, gBattlerByTurnOrder[i], MOVE_SNATCH); + gProtectStructs[gBattlerByTurnOrder[i]].stealMove = 0; + gBattleScripting.battler = gBattlerByTurnOrder[i]; BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_SnatchedMove; return; @@ -2216,7 +2216,7 @@ u8 GetBattlerTurnOrderNum(u8 battlerId) s32 i; for (i = 0; i < gBattlersCount; i++) { - if (gBattleTurnOrder[i] == battlerId) + if (gBattlerByTurnOrder[i] == battlerId) break; } return i; @@ -5556,7 +5556,7 @@ static void atk52_switchineffects(void) for (i = 0; i < gBattlersCount; i++) { - if (gBattleTurnOrder[i] == gActiveBattler) + if (gBattlerByTurnOrder[i] == gActiveBattler) gActionsByTurnOrder[i] = B_ACTION_CANCEL_PARTNER; } @@ -6021,10 +6021,10 @@ static void atk61_drawpartystatussummary(void) gBattlescriptCurrInstr += 2; } -static void atk62(void) +static void atk62_hidepartystatussummary(void) { gActiveBattler = GetBattlerForBattleScript(gBattlescriptCurrInstr[1]); - BtlController_EmitCmd49(0); + BtlController_EmitHidePartyStatusSummary(0); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr += 2; @@ -8957,7 +8957,7 @@ static void atkBA_jumpifnopursuitswitchdmg(void) for (i = 0; i < gBattlersCount; i++) { - if (gBattleTurnOrder[i] == gBattlerTarget) + if (gBattlerByTurnOrder[i] == gBattlerTarget) gActionsByTurnOrder[i] = 11; } diff --git a/src/battle_util.c b/src/battle_util.c index 172ec6659..b9a7f546a 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -511,14 +511,14 @@ u8 UpdateTurnCounters(void) case 0: for (i = 0; i < gBattlersCount; i++) { - gBattleTurnOrder[i] = i; + gBattlerByTurnOrder[i] = i; } for (i = 0; i < gBattlersCount - 1; i++) { s32 j; for (j = i + 1; j < gBattlersCount; j++) { - if (GetWhoStrikesFirst(gBattleTurnOrder[i], gBattleTurnOrder[j], 0)) + if (GetWhoStrikesFirst(gBattlerByTurnOrder[i], gBattlerByTurnOrder[j], 0)) SwapTurnOrder(i, j); } } @@ -632,7 +632,7 @@ u8 UpdateTurnCounters(void) case 5: while (gBattleStruct->turnSideTracker < gBattlersCount) { - gActiveBattler = gBattleTurnOrder[gBattleStruct->turnSideTracker]; + gActiveBattler = gBattlerByTurnOrder[gBattleStruct->turnSideTracker]; if (gWishFutureKnock.wishCounter[gActiveBattler] != 0 && --gWishFutureKnock.wishCounter[gActiveBattler] == 0 && gBattleMons[gActiveBattler].hp != 0) @@ -755,7 +755,7 @@ u8 TurnBasedEffects(void) gHitMarker |= (HITMARKER_GRUDGE | HITMARKER_x20); while (gBattleStruct->turnEffectsBattlerId < gBattlersCount && gBattleStruct->turnEffectsTracker <= TURNBASED_MAX_CASE) { - gActiveBattler = gBattlerAttacker = gBattleTurnOrder[gBattleStruct->turnEffectsBattlerId]; + gActiveBattler = gBattlerAttacker = gBattlerByTurnOrder[gBattleStruct->turnEffectsBattlerId]; if (gAbsentBattlerFlags & gBitTable[gActiveBattler]) { gBattleStruct->turnEffectsBattlerId++; @@ -1121,7 +1121,7 @@ bool8 HandleWishPerishSongOnTurnEnd(void) case 1: while (gBattleStruct->wishPerishSongBattlerId < gBattlersCount) { - gActiveBattler = gBattlerAttacker = gBattleTurnOrder[gBattleStruct->wishPerishSongBattlerId]; + gActiveBattler = gBattlerAttacker = gBattlerByTurnOrder[gBattleStruct->wishPerishSongBattlerId]; if (gAbsentBattlerFlags & gBitTable[gActiveBattler]) { gBattleStruct->wishPerishSongBattlerId++; diff --git a/src/safari_zone.c b/src/safari_zone.c index ab5c38f3a..c0c098b38 100644 --- a/src/safari_zone.c +++ b/src/safari_zone.c @@ -42,7 +42,7 @@ extern void PlayerGetDestCoords(s16* x, s16* y); EWRAM_DATA u8 gNumSafariBalls = 0; EWRAM_DATA static u16 sSafariZoneStepCounter = 0; EWRAM_DATA static u8 sSafariZoneCaughtMons = 0; -EWRAM_DATA static u8 sSafariZoneFleedMons = 0; +EWRAM_DATA static u8 sSafariZonePkblkUses = 0; EWRAM_DATA static struct PokeblockFeeder sPokeblockFeeders[NUM_POKEBLOCK_FEEDERS] = {0}; static void ClearAllPokeblockFeeders(void); @@ -71,12 +71,12 @@ void EnterSafariMode(void) gNumSafariBalls = 30; sSafariZoneStepCounter = 500; sSafariZoneCaughtMons = 0; - sSafariZoneFleedMons = 0; + sSafariZonePkblkUses = 0; } void ExitSafariMode(void) { - sub_80EE44C(sSafariZoneCaughtMons, sSafariZoneFleedMons); + sub_80EE44C(sSafariZoneCaughtMons, sSafariZonePkblkUses); ResetSafariZoneFlag(); ClearAllPokeblockFeeders(); gNumSafariBalls = 0; @@ -107,7 +107,7 @@ void SafariZoneRetirePrompt(void) void CB2_EndSafariBattle(void) { - sSafariZoneFleedMons += gBattleResults.field_1F; + sSafariZonePkblkUses += gBattleResults.pokeblockThrows; if (gBattleOutcome == B_OUTCOME_CAUGHT) sSafariZoneCaughtMons++; if (gNumSafariBalls != 0) @@ -172,7 +172,7 @@ void GetPokeblockFeederWithinRange(void) { if (gSaveBlock1Ptr->location.mapNum == sPokeblockFeeders[i].mapNum) { - //Get absolute value of x and y distance from Pokeblock feeder on current map + // Get absolute value of x and y distance from Pokeblock feeder on current map. x -= sPokeblockFeeders[i].x; y -= sPokeblockFeeders[i].y; if (x < 0) From 30c85a5128b2b68049ce7b62d8beb64adad26b64 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sat, 30 Jun 2018 14:12:17 +0200 Subject: [PATCH 05/15] more battle documentation --- asm/macros/battle_script.inc | 4 +-- data/battle_scripts_1.s | 14 +++++----- include/constants/battle.h | 2 +- src/battle_main.c | 1 + src/battle_message.c | 51 ++++++++++++++++++------------------ src/battle_script_commands.c | 39 ++++++++++++++------------- 6 files changed, 56 insertions(+), 55 deletions(-) diff --git a/asm/macros/battle_script.inc b/asm/macros/battle_script.inc index 73fcbeac1..c03d78df7 100644 --- a/asm/macros/battle_script.inc +++ b/asm/macros/battle_script.inc @@ -511,7 +511,7 @@ .byte \bank .endm - .macro atk5F + .macro swapattackerwithtarget .byte 0x5f .endm @@ -1163,7 +1163,7 @@ .4byte \param0 .endm - .macro snatchsetbanks + .macro snatchsetbattlers .byte 0xed .endm diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index a9d305ec8..4956ffc13 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -2873,7 +2873,7 @@ BattleScript_FaintedMonTryChooseAnother:: jumpifnotbattletype BATTLE_TYPE_TRAINER, BattleScript_FaintedMonChooseAnother jumpifbattletype BATTLE_TYPE_LINK, BattleScript_FaintedMonChooseAnother jumpifbattletype BATTLE_TYPE_x2000000, BattleScript_FaintedMonChooseAnother - jumpifbattletype BATTLE_TYPE_BATTLE_TOWER | BATTLE_TYPE_DOME | BATTLE_TYPE_PALACE | BATTLE_TYPE_ARENA | BATTLE_TYPE_FACTORY | BATTLE_TYPE_PIKE | BATTLE_TYPE_PYRAMID, BattleScript_FaintedMonChooseAnother + jumpifbattletype BATTLE_TYPE_FRONTIER, BattleScript_FaintedMonChooseAnother jumpifbattletype BATTLE_TYPE_DOUBLE, BattleScript_FaintedMonChooseAnother jumpifword CMP_COMMON_BITS, gHitMarker, HITMARKER_x400000, BattleScript_FaintedMonChooseAnother jumpifbyte CMP_EQUAL, sBATTLE_STYLE, 0x1, BattleScript_FaintedMonChooseAnother @@ -2968,7 +2968,7 @@ BattleScript_PayDayMoneyAndPickUpItems:: BattleScript_LocalBattleLost:: jumpifbattletype BATTLE_TYPE_DOME, BattleScript_CheckDomeDrew - jumpifbattletype BATTLE_TYPE_BATTLE_TOWER | BATTLE_TYPE_DOME | BATTLE_TYPE_PALACE | BATTLE_TYPE_ARENA | BATTLE_TYPE_FACTORY | BATTLE_TYPE_PIKE | BATTLE_TYPE_PYRAMID, BattleScript_LocalBattleLostPrintTrainersWinText + jumpifbattletype BATTLE_TYPE_FRONTIER, BattleScript_LocalBattleLostPrintTrainersWinText jumpifbattletype BATTLE_TYPE_x4000000, BattleScript_LocalBattleLostPrintTrainersWinText jumpifbattletype BATTLE_TYPE_EREADER_TRAINER, BattleScript_LocalBattleLostEnd jumpifhalfword CMP_EQUAL, gTrainerBattleOpponent_A, 0x400, BattleScript_LocalBattleLostEnd @@ -3120,10 +3120,10 @@ BattleScript_PursuitSwitchDmgSetMultihit:: setmultihit 0x2 BattleScript_PursuitSwitchDmgLoop:: jumpifnopursuitswitchdmg BattleScript_DoSwitchOut - atk5F + swapattackerwithtarget trysetdestinybondtohappen call BattleScript_PursuitDmgOnSwitchOut - atk5F + swapattackerwithtarget BattleScript_DoSwitchOut:: decrementmultihit BattleScript_PursuitSwitchDmgLoop switchoutabilities BS_ATTACKER @@ -3230,7 +3230,7 @@ BattleScript_DamagingWeatherContinues:: playanimation2 BS_ATTACKER, sB_ANIM_ARG1, NULL setbyte gBattleCommunication, 0x0 BattleScript_DamagingWeatherLoop:: - copyarraywithindex gBattlerAttacker, gBattleTurnOrder, gBattleCommunication, 0x1 + copyarraywithindex gBattlerAttacker, gBattlerByTurnOrder, gBattleCommunication, 0x1 weatherdamage jumpifword CMP_EQUAL, gBattleMoveDamage, 0x0, BattleScript_DamagingWeatherLoopIncrement printfromtable gSandStormHailDmgStringIds @@ -3710,12 +3710,12 @@ BattleScript_MagicCoatBounce:: BattleScript_SnatchedMove:: attackstring ppreduce - snatchsetbanks + snatchsetbattlers playanimation BS_TARGET, B_ANIM_SNATCH_MOVE, NULL printstring STRINGID_PKMNSNATCHEDMOVE waitmessage 0x40 orword gHitMarker, HITMARKER_ATTACKSTRING_PRINTED | HITMARKER_NO_PPDEDUCT | HITMARKER_x800000 - atk5F + swapattackerwithtarget return BattleScript_EnduredMsg:: diff --git a/include/constants/battle.h b/include/constants/battle.h index f3d7a8e0e..5a09067ad 100644 --- a/include/constants/battle.h +++ b/include/constants/battle.h @@ -159,7 +159,7 @@ #define HITMARKER_NO_ATTACKSTRING 0x00000200 #define HITMARKER_ATTACKSTRING_PRINTED 0x00000400 #define HITMARKER_NO_PPDEDUCT 0x00000800 -#define HITMARKER_PURSUIT_TRAP 0x00001000 +#define HITMARKER_SWAP_ATTACKER_TARGET 0x00001000 #define HITMARKER_IGNORE_SAFEGUARD 0x00002000 #define HITMARKER_SYNCHRONISE_EFFECT 0x00004000 #define HITMARKER_RUN 0x00008000 diff --git a/src/battle_main.c b/src/battle_main.c index a0d812a94..a846f5769 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -561,6 +561,7 @@ static const u8 sUnknown_0831BCE0[][3] = {{0, 0, 0}, {3, 5, 0}, {2, 3, 0}, {1, 2 static const u8 sUnknown_0831BCEF[] = {4, 3, 2, 1}; static const u8 sUnknown_0831BCF3[] = {4, 4, 4, 4}; +// code void CB2_InitBattle(void) { MoveSaveBlocks_ResetHeap(); diff --git a/src/battle_message.c b/src/battle_message.c index 896b2197e..41b36ae13 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -45,7 +45,6 @@ extern const u8 gText_PkmnBoxLanettesPCFull[]; extern const u8 gText_PkmnTransferredSomeonesPC[]; extern const u8 gText_PkmnTransferredLanettesPC[]; -extern u16 sub_8068BB0(void); // pokemon_1 extern u8 sub_81A4D00(void); // battle_frontier_2 extern u8 GetFrontierOpponentClass(u16 trainerId); // battle_tower extern u8 sub_81D5530(u16 trainerId); // pokenav @@ -58,8 +57,8 @@ extern void sub_81D572C(u8 arg0, u16 trainerId); // pokenav extern void GetFrontierTrainerName(u8 *dst, u16 trainerId); // this file's functions -static void sub_814F8F8(u8 *textPtr); -static void sub_814F950(u8 *dst); +static void ChooseMoveUsedParticle(u8 *textPtr); +static void ChooseTypeOfMoveUsedString(u8 *dst); static void ExpandBattleTextBuffPlaceholders(const u8 *src, u8 *dst); // ewram variables @@ -1322,8 +1321,8 @@ static const u8 sText_LinkTrainerWantsToBattlePause[] = _("{B_20}\nwants to batt static const u8 sText_TwoLinkTrainersWantToBattlePause[] = _("{B_20} and {B_21}\nwant to battle!{PAUSE 49}"); // This is four lists of moves which use a different attack string in Japanese -// to the default. See the documentation for sub_814F950 for more detail. -static const u16 sUnknownMoveTable[] = +// to the default. See the documentation for ChooseTypeOfMoveUsedString for more detail. +static const u16 sGrammarMoveUsedTable[] = { MOVE_SWORDS_DANCE, MOVE_STRENGTH, MOVE_GROWTH, MOVE_HARDEN, MOVE_MINIMIZE, MOVE_SMOKESCREEN, @@ -2142,14 +2141,14 @@ void BufferStringBattle(u16 stringID) } break; case STRINGID_USEDMOVE: // pokemon used a move msg - sub_814F8F8(gBattleTextBuff1); // buff1 doesn't appear in the string, leftover from japanese move names? + ChooseMoveUsedParticle(gBattleTextBuff1); // buff1 doesn't appear in the string, leftover from japanese move names if (gStringInfo->currentMove > LAST_MOVE_INDEX) StringCopy(gBattleTextBuff2, sATypeMove_Table[*(&gBattleStruct->stringMoveType)]); else StringCopy(gBattleTextBuff2, gMoveNames[gStringInfo->currentMove]); - sub_814F950(gBattleTextBuff2); + ChooseTypeOfMoveUsedString(gBattleTextBuff2); stringPtr = sText_AttackerUsedX; break; case STRINGID_BATTLEEND: // battle end @@ -2740,10 +2739,6 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst) return dstID; } -// TODO: move these to a general header like util.h -#define ByteRead16(ptr) ((ptr)[0] | ((ptr)[1] << 8)) -#define ByteRead32(ptr) ((ptr)[0] | (ptr)[1] << 8 | (ptr)[2] << 16 | (ptr)[3] << 24) - static void ExpandBattleTextBuffPlaceholders(const u8 *src, u8 *dst) { u32 srcID = 1; @@ -2757,7 +2752,7 @@ static void ExpandBattleTextBuffPlaceholders(const u8 *src, u8 *dst) switch (src[srcID]) { case B_BUFF_STRING: // battle string - hword = ByteRead16(&src[srcID + 1]); + hword = T1_READ_16(&src[srcID + 1]); StringAppend(dst, gBattleStringsTable[hword - BATTLESTRINGS_ID_ADDER]); srcID += 3; break; @@ -2768,17 +2763,17 @@ static void ExpandBattleTextBuffPlaceholders(const u8 *src, u8 *dst) value = src[srcID + 3]; break; case 2: - value = ByteRead16(&src[srcID + 3]); + value = T1_READ_16(&src[srcID + 3]); break; case 4: - value = ByteRead32(&src[srcID + 3]); + value = T1_READ_32(&src[srcID + 3]); break; } ConvertIntToDecimalStringN(dst, value, 0, src[srcID + 2]); srcID += src[srcID + 1] + 3; break; case B_BUFF_MOVE: // move name - StringAppend(dst, gMoveNames[ByteRead16(&src[srcID + 1])]); + StringAppend(dst, gMoveNames[T1_READ_16(&src[srcID + 1])]); srcID += 3; break; case B_BUFF_TYPE: // type name @@ -2808,7 +2803,7 @@ static void ExpandBattleTextBuffPlaceholders(const u8 *src, u8 *dst) srcID += 2; break; case B_BUFF_SPECIES: // species name - GetSpeciesName(dst, ByteRead16(&src[srcID + 1])); + GetSpeciesName(dst, T1_READ_16(&src[srcID + 1])); srcID += 3; break; case B_BUFF_MON_NICK: // poke nick without prefix @@ -2828,7 +2823,7 @@ static void ExpandBattleTextBuffPlaceholders(const u8 *src, u8 *dst) srcID += 2; break; case B_BUFF_ITEM: // item name - hword = ByteRead16(&src[srcID + 1]); + hword = T1_READ_16(&src[srcID + 1]); if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000)) { if (hword == ITEM_ENIGMA_BERRY) @@ -2839,13 +2834,19 @@ static void ExpandBattleTextBuffPlaceholders(const u8 *src, u8 *dst) StringAppend(dst, sText_BerrySuffix); } else + { StringAppend(dst, sText_EnigmaBerry); + } } else + { CopyItemName(hword, dst); + } } else + { CopyItemName(hword, dst); + } srcID += 3; break; } @@ -2854,18 +2855,18 @@ static void ExpandBattleTextBuffPlaceholders(const u8 *src, u8 *dst) // Loads one of two text strings into the provided buffer. This is functionally // unused, since the value loaded into the buffer is not read; it loaded one of -// two particles (either "は" or "の") which works in tandem with sub_814F950 +// two particles (either "は" or "の") which works in tandem with ChooseTypeOfMoveUsedString // below to effect changes in the meaning of the line. -static void sub_814F8F8(u8* textBuff) +static void ChooseMoveUsedParticle(u8* textBuff) { s32 counter = 0; u32 i = 0; while (counter != 4) { - if (sUnknownMoveTable[i] == 0) + if (sGrammarMoveUsedTable[i] == 0) counter++; - if (sUnknownMoveTable[i++] == gStringInfo->currentMove) + if (sGrammarMoveUsedTable[i++] == gStringInfo->currentMove) break; } @@ -2879,7 +2880,7 @@ static void sub_814F8F8(u8* textBuff) } // Appends "!" to the text buffer `dst`. In the original Japanese this looked -// into the table of moves at sUnknownMoveTable and varied the line accordingly. +// into the table of moves at sGrammarMoveUsedTable and varied the line accordingly. // // sText_ExclamationMark was a plain "!", used for any attack not on the list. // It resulted in the translation "'s !". @@ -2896,7 +2897,7 @@ static void sub_814F8F8(u8* textBuff) // // sText_ExclamationMark5 was " こうげき!" This resulted in a translation of // "'s attack!". -static void sub_814F950(u8* dst) +static void ChooseTypeOfMoveUsedString(u8* dst) { s32 counter = 0; s32 i = 0; @@ -2906,9 +2907,9 @@ static void sub_814F950(u8* dst) while (counter != 4) { - if (sUnknownMoveTable[i] == MOVE_NONE) + if (sGrammarMoveUsedTable[i] == MOVE_NONE) counter++; - if (sUnknownMoveTable[i++] == gStringInfo->currentMove) + if (sGrammarMoveUsedTable[i++] == gStringInfo->currentMove) break; } diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index fb77ab4c4..ecba9f934 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -67,7 +67,6 @@ extern bool8 sub_81B1250(void); // ? extern bool8 InBattlePike(void); extern bool8 InBattlePyramid(void); extern u16 GetBattlePyramidPickupItemId(void); -extern u8 Overworld_GetMapTypeOfSaveblockLocation(void); extern u8 sub_813B21C(void); extern u16 get_unknown_box_id(void); @@ -185,7 +184,7 @@ static void atk5B_yesnoboxstoplearningmove(void); static void atk5C_hitanimation(void); static void atk5D_getmoneyreward(void); static void atk5E(void); -static void atk5F(void); +static void atk5F_swapattackerwithtarget(void); static void atk60_incrementgamestat(void); static void atk61_drawpartystatussummary(void); static void atk62_hidepartystatussummary(void); @@ -327,7 +326,7 @@ static void atkE9_setweatherballtype(void); static void atkEA_tryrecycleitem(void); static void atkEB_settypetoterrain(void); static void atkEC_pursuitrelated(void); -static void atkEF_snatchsetbanks(void); +static void atkEF_snatchsetbattlers(void); static void atkEE_removelightscreenreflect(void); static void atkEF_handleballthrow(void); static void atkF0_givecaughtmon(void); @@ -437,7 +436,7 @@ void (* const gBattleScriptingCommandsTable[])(void) = atk5C_hitanimation, atk5D_getmoneyreward, atk5E, - atk5F, + atk5F_swapattackerwithtarget, atk60_incrementgamestat, atk61_drawpartystatussummary, atk62_hidepartystatussummary, @@ -579,7 +578,7 @@ void (* const gBattleScriptingCommandsTable[])(void) = atkEA_tryrecycleitem, atkEB_settypetoterrain, atkEC_pursuitrelated, - atkEF_snatchsetbanks, + atkEF_snatchsetbattlers, atkEE_removelightscreenreflect, atkEF_handleballthrow, atkF0_givecaughtmon, @@ -1172,7 +1171,7 @@ static void atk01_accuracycheck(void) calc = (calc * 130) / 100; // 1.3 compound eyes boost if (WEATHER_HAS_EFFECT && gBattleMons[gBattlerTarget].ability == ABILITY_SAND_VEIL && gBattleWeather & WEATHER_SANDSTORM_ANY) calc = (calc * 80) / 100; // 1.2 sand veil loss - if (gBattleMons[gBattlerAttacker].ability == ABILITY_HUSTLE && type < 9) + if (gBattleMons[gBattlerAttacker].ability == ABILITY_HUSTLE && IS_MOVE_PHYSICAL(type)) calc = (calc * 80) / 100; // 1.2 hustle loss if (gBattleMons[gBattlerTarget].item == ITEM_ENIGMA_BERRY) @@ -4676,12 +4675,12 @@ static void atk49_moveend(void) gBattleScripting.atk49_state++; break; case 14: // This case looks interesting, although I am not certain what it does. Probably fine tunes edge cases. - if (gHitMarker & HITMARKER_PURSUIT_TRAP) + if (gHitMarker & HITMARKER_SWAP_ATTACKER_TARGET) { gActiveBattler = gBattlerAttacker; gBattlerAttacker = gBattlerTarget; gBattlerTarget = gActiveBattler; - gHitMarker &= ~(HITMARKER_PURSUIT_TRAP); + gHitMarker &= ~(HITMARKER_SWAP_ATTACKER_TARGET); } if (gHitMarker & HITMARKER_ATTACKSTRING_PRINTED) { @@ -5950,7 +5949,7 @@ static void atk5E(void) if (gBattleControllerExecFlags == 0) { s32 i; - struct BattlePokemon* bufferPoke = (struct BattlePokemon*) &gBattleBufferB[gActiveBattler][4]; + struct BattlePokemon *bufferPoke = (struct BattlePokemon*) &gBattleBufferB[gActiveBattler][4]; for (i = 0; i < 4; i++) { gBattleMons[gActiveBattler].moves[i] = bufferPoke->moves[i]; @@ -5962,16 +5961,16 @@ static void atk5E(void) } } -static void atk5F(void) +static void atk5F_swapattackerwithtarget(void) { gActiveBattler = gBattlerAttacker; gBattlerAttacker = gBattlerTarget; gBattlerTarget = gActiveBattler; - if (gHitMarker & HITMARKER_PURSUIT_TRAP) - gHitMarker &= ~(HITMARKER_PURSUIT_TRAP); + if (gHitMarker & HITMARKER_SWAP_ATTACKER_TARGET) + gHitMarker &= ~(HITMARKER_SWAP_ATTACKER_TARGET); else - gHitMarker |= HITMARKER_PURSUIT_TRAP; + gHitMarker |= HITMARKER_SWAP_ATTACKER_TARGET; gBattlescriptCurrInstr++; } @@ -5987,8 +5986,8 @@ static void atk60_incrementgamestat(void) static void atk61_drawpartystatussummary(void) { s32 i; - struct Pokemon* party; - struct HpAndStatus hpStatuses[6]; + struct Pokemon *party; + struct HpAndStatus hpStatuses[PARTY_SIZE]; if (gBattleControllerExecFlags) return; @@ -6000,7 +5999,7 @@ static void atk61_drawpartystatussummary(void) else party = gEnemyParty; - for (i = 0; i < 6; i++) + for (i = 0; i < PARTY_SIZE; i++) { if (GetMonData(&party[i], MON_DATA_SPECIES2) == SPECIES_NONE || GetMonData(&party[i], MON_DATA_SPECIES2) == SPECIES_EGG) @@ -8595,7 +8594,7 @@ static void atkAE_healpartystatus(void) if (gCurrentMove == MOVE_HEAL_BELL) { - struct Pokemon* party; + struct Pokemon *party; s32 i; gBattleCommunication[MULTISTRING_CHOOSER] = 0; @@ -8633,7 +8632,7 @@ static void atkAE_healpartystatus(void) } } - for (i = 0; i < 6; i++) + for (i = 0; i < PARTY_SIZE; i++) { u16 species = GetMonData(&party[i], MON_DATA_SPECIES2); u8 abilityBit = GetMonData(&party[i], MON_DATA_ALT_ABILITY); @@ -10053,7 +10052,7 @@ static void atkEC_pursuitrelated(void) } } -static void atkEF_snatchsetbanks(void) +static void atkEF_snatchsetbattlers(void) { gEffectBattler = gBattlerAttacker; @@ -10131,7 +10130,7 @@ static void atkEF_handleballthrow(void) ballMultiplier = 10; break; case ITEM_DIVE_BALL: - if (Overworld_GetMapTypeOfSaveblockLocation() == 5) + if (Overworld_GetMapTypeOfSaveblockLocation() == MAP_TYPE_UNDERWATER) ballMultiplier = 35; else ballMultiplier = 10; From bfc64c9689d4518c64ba15cd7d52b9a6149fd218 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sat, 30 Jun 2018 15:35:54 +0200 Subject: [PATCH 06/15] C vars sym ewram --- include/battle.h | 7 ++++- include/battle_message.h | 18 +++++-------- src/battle_main.c | 4 +++ src/battle_message.c | 58 +++++++++++++++++++--------------------- src/battle_setup.c | 28 +++++++++---------- src/battle_tv.c | 10 +++---- src/braille_puzzles.c | 14 +++++----- src/hall_of_fame.c | 18 ++++++------- sym_ewram.txt | 21 ++------------- 9 files changed, 80 insertions(+), 98 deletions(-) diff --git a/include/battle.h b/include/battle.h index 20a6cf1b8..0169dde7c 100644 --- a/include/battle.h +++ b/include/battle.h @@ -4,6 +4,7 @@ // should they be included here or included individually by every file? #include "constants/battle.h" #include "battle_main.h" +#include "battle_message.h" #include "battle_util.h" #include "battle_script_commands.h" #include "battle_ai_switch_items.h" @@ -719,7 +720,11 @@ struct MonSpritesGfx void *field_17C; }; -// all battle variables are declared in battle_main.c +// All battle variables are declared in battle_main.c +extern u8 gDisplayedStringBattle[300]; +extern u8 gBattleTextBuff1[TEXT_BUFF_ARRAY_COUNT]; +extern u8 gBattleTextBuff2[TEXT_BUFF_ARRAY_COUNT]; +extern u8 gBattleTextBuff3[TEXT_BUFF_ARRAY_COUNT]; extern u32 gBattleTypeFlags; extern u8 gBattleTerrain; extern u32 gUnknown_02022FF4; diff --git a/include/battle_message.h b/include/battle_message.h index f792ff7b0..cccbae841 100644 --- a/include/battle_message.h +++ b/include/battle_message.h @@ -1,8 +1,9 @@ #ifndef GUARD_BATTLE_MESSAGE_H #define GUARD_BATTLE_MESSAGE_H -// for 0xFD +#define TEXT_BUFF_ARRAY_COUNT 16 +// for 0xFD #define B_TXT_BUFF1 0x0 #define B_TXT_BUFF2 0x1 #define B_TXT_COPY_VAR_1 0x2 @@ -194,7 +195,7 @@ textVar[4] = B_BUFF_EOS; \ } -struct StringInfoBattle +struct BattleMsgData { u16 currentMove; u16 originallyUsedMove; @@ -203,10 +204,10 @@ struct StringInfoBattle u8 scrActive; u8 unk1605E; u8 hpScale; - u8 StringBank; + u8 itemEffectBattler; u8 moveType; - u8 abilities[4]; - u8 textBuffs[3][0x10]; + u8 abilities[MAX_BATTLERS_COUNT]; + u8 textBuffs[3][TEXT_BUFF_ARRAY_COUNT]; }; void BufferStringBattle(u16 stringID); @@ -216,12 +217,7 @@ void BattlePutTextOnWindow(const u8* text, u8 arg1); void SetPpNumbersPaletteInMoveSelection(void); u8 GetCurrentPpToMaxPpState(u8 currentPp, u8 maxPp); -#define TEXT_BUFF_ARRAY_COUNT 16 - -extern u8 gDisplayedStringBattle[300]; -extern u8 gBattleTextBuff1[TEXT_BUFF_ARRAY_COUNT]; -extern u8 gBattleTextBuff2[TEXT_BUFF_ARRAY_COUNT]; -extern u8 gBattleTextBuff3[TEXT_BUFF_ARRAY_COUNT]; +extern struct BattleMsgData *gBattleMsgDataPtr; extern const u8* const gBattleStringsTable[]; extern const u8* const gStatNamesTable[]; diff --git a/src/battle_main.c b/src/battle_main.c index a846f5769..487e11993 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -190,6 +190,10 @@ static void HandleAction_NothingIsFainted(void); static void HandleAction_ActionFinished(void); // EWRAM vars +EWRAM_DATA u8 gDisplayedStringBattle[300] = {0}; +EWRAM_DATA u8 gBattleTextBuff1[TEXT_BUFF_ARRAY_COUNT] = {0}; +EWRAM_DATA u8 gBattleTextBuff2[TEXT_BUFF_ARRAY_COUNT] = {0}; +EWRAM_DATA u8 gBattleTextBuff3[TEXT_BUFF_ARRAY_COUNT] = {0}; EWRAM_DATA static u32 sUnusedUnknownArray[25] = {0}; EWRAM_DATA u32 gBattleTypeFlags = 0; EWRAM_DATA u8 gBattleTerrain = 0; diff --git a/src/battle_message.c b/src/battle_message.c index 41b36ae13..9dcd4aaf1 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -31,9 +31,7 @@ struct BattleWindowText u8 shadowColor; }; -extern u8 gBattlerAbilities[MAX_BATTLERS_COUNT]; extern u8 gUnknown_0203C7B4; -extern struct StringInfoBattle *gStringInfo; extern const u8 gMoveNames[LAST_MOVE_INDEX + 1][13]; extern const u8 gTrainerClassNames[][13]; @@ -61,11 +59,9 @@ static void ChooseMoveUsedParticle(u8 *textPtr); static void ChooseTypeOfMoveUsedString(u8 *dst); static void ExpandBattleTextBuffPlaceholders(const u8 *src, u8 *dst); -// ewram variables -EWRAM_DATA u8 gDisplayedStringBattle[300] = {0}; -EWRAM_DATA u8 gBattleTextBuff1[TEXT_BUFF_ARRAY_COUNT] = {0}; -EWRAM_DATA u8 gBattleTextBuff2[TEXT_BUFF_ARRAY_COUNT] = {0}; -EWRAM_DATA u8 gBattleTextBuff3[TEXT_BUFF_ARRAY_COUNT] = {0}; +// EWRAM vars +static EWRAM_DATA u8 sBattlerAbilities[MAX_BATTLERS_COUNT] = {0}; +EWRAM_DATA struct BattleMsgData *gBattleMsgDataPtr = NULL; // const rom data // todo: make some of those names less vague: attacker/target vs pkmn, etc. @@ -1949,24 +1945,24 @@ void BufferStringBattle(u16 stringID) s32 i; const u8 *stringPtr = NULL; - gStringInfo = (struct StringInfoBattle*)(&gBattleBufferA[gActiveBattler][4]); - gLastUsedItem = gStringInfo->lastItem; - gLastUsedAbility = gStringInfo->lastAbility; - gBattleScripting.battler = gStringInfo->scrActive; - *(&gBattleStruct->field_52) = gStringInfo->unk1605E; - *(&gBattleStruct->hpScale) = gStringInfo->hpScale; - gPotentialItemEffectBattler = gStringInfo->StringBank; - *(&gBattleStruct->stringMoveType) = gStringInfo->moveType; + gBattleMsgDataPtr = (struct BattleMsgData*)(&gBattleBufferA[gActiveBattler][4]); + gLastUsedItem = gBattleMsgDataPtr->lastItem; + gLastUsedAbility = gBattleMsgDataPtr->lastAbility; + gBattleScripting.battler = gBattleMsgDataPtr->scrActive; + *(&gBattleStruct->field_52) = gBattleMsgDataPtr->unk1605E; + *(&gBattleStruct->hpScale) = gBattleMsgDataPtr->hpScale; + gPotentialItemEffectBattler = gBattleMsgDataPtr->itemEffectBattler; + *(&gBattleStruct->stringMoveType) = gBattleMsgDataPtr->moveType; for (i = 0; i < MAX_BATTLERS_COUNT; i++) { - gBattlerAbilities[i] = gStringInfo->abilities[i]; + sBattlerAbilities[i] = gBattleMsgDataPtr->abilities[i]; } for (i = 0; i < TEXT_BUFF_ARRAY_COUNT; i++) { - gBattleTextBuff1[i] = gStringInfo->textBuffs[0][i]; - gBattleTextBuff2[i] = gStringInfo->textBuffs[1][i]; - gBattleTextBuff3[i] = gStringInfo->textBuffs[2][i]; + gBattleTextBuff1[i] = gBattleMsgDataPtr->textBuffs[0][i]; + gBattleTextBuff2[i] = gBattleMsgDataPtr->textBuffs[1][i]; + gBattleTextBuff3[i] = gBattleMsgDataPtr->textBuffs[2][i]; } switch (stringID) @@ -2143,10 +2139,10 @@ void BufferStringBattle(u16 stringID) case STRINGID_USEDMOVE: // pokemon used a move msg ChooseMoveUsedParticle(gBattleTextBuff1); // buff1 doesn't appear in the string, leftover from japanese move names - if (gStringInfo->currentMove > LAST_MOVE_INDEX) + if (gBattleMsgDataPtr->currentMove > LAST_MOVE_INDEX) StringCopy(gBattleTextBuff2, sATypeMove_Table[*(&gBattleStruct->stringMoveType)]); else - StringCopy(gBattleTextBuff2, gMoveNames[gStringInfo->currentMove]); + StringCopy(gBattleTextBuff2, gMoveNames[gBattleMsgDataPtr->currentMove]); ChooseTypeOfMoveUsedString(gBattleTextBuff2); stringPtr = sText_AttackerUsedX; @@ -2431,16 +2427,16 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst) HANDLE_NICKNAME_STRING_CASE(gBattleScripting.battler, gBattlerPartyIndexes[gBattleScripting.battler]) break; case B_TXT_CURRENT_MOVE: // current move name - if (gStringInfo->currentMove > LAST_MOVE_INDEX) + if (gBattleMsgDataPtr->currentMove > LAST_MOVE_INDEX) toCpy = sATypeMove_Table[gBattleStruct->stringMoveType]; else - toCpy = gMoveNames[gStringInfo->currentMove]; + toCpy = gMoveNames[gBattleMsgDataPtr->currentMove]; break; case B_TXT_LAST_MOVE: // originally used move name - if (gStringInfo->originallyUsedMove > LAST_MOVE_INDEX) + if (gBattleMsgDataPtr->originallyUsedMove > LAST_MOVE_INDEX) toCpy = sATypeMove_Table[gBattleStruct->stringMoveType]; else - toCpy = gMoveNames[gStringInfo->originallyUsedMove]; + toCpy = gMoveNames[gBattleMsgDataPtr->originallyUsedMove]; break; case B_TXT_LAST_ITEM: // last used item if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000)) @@ -2489,16 +2485,16 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst) toCpy = gAbilityNames[gLastUsedAbility]; break; case B_TXT_ATK_ABILITY: // attacker ability - toCpy = gAbilityNames[gBattlerAbilities[gBattlerAttacker]]; + toCpy = gAbilityNames[sBattlerAbilities[gBattlerAttacker]]; break; case B_TXT_DEF_ABILITY: // target ability - toCpy = gAbilityNames[gBattlerAbilities[gBattlerTarget]]; + toCpy = gAbilityNames[sBattlerAbilities[gBattlerTarget]]; break; case B_TXT_SCR_ACTIVE_ABILITY: // scripting active ability - toCpy = gAbilityNames[gBattlerAbilities[gBattleScripting.battler]]; + toCpy = gAbilityNames[sBattlerAbilities[gBattleScripting.battler]]; break; case B_TXT_EFF_ABILITY: // effect battlerId ability - toCpy = gAbilityNames[gBattlerAbilities[gEffectBattler]]; + toCpy = gAbilityNames[sBattlerAbilities[gEffectBattler]]; break; case B_TXT_TRAINER1_CLASS: // trainer class name if (gBattleTypeFlags & BATTLE_TYPE_SECRET_BASE) @@ -2866,7 +2862,7 @@ static void ChooseMoveUsedParticle(u8* textBuff) { if (sGrammarMoveUsedTable[i] == 0) counter++; - if (sGrammarMoveUsedTable[i++] == gStringInfo->currentMove) + if (sGrammarMoveUsedTable[i++] == gBattleMsgDataPtr->currentMove) break; } @@ -2909,7 +2905,7 @@ static void ChooseTypeOfMoveUsedString(u8* dst) { if (sGrammarMoveUsedTable[i] == MOVE_NONE) counter++; - if (sGrammarMoveUsedTable[i++] == gStringInfo->currentMove) + if (sGrammarMoveUsedTable[i++] == gBattleMsgDataPtr->currentMove) break; } diff --git a/src/battle_setup.c b/src/battle_setup.c index ccc36b7c2..b11083929 100644 --- a/src/battle_setup.c +++ b/src/battle_setup.c @@ -1088,14 +1088,14 @@ const u8 *BattleSetup_ConfigureTrainerBattle(const u8 *data) switch (sTrainerBattleMode) { - case 3: + case TRAINER_BATTLE_NORMAL_NO_INTRO_TEXT: TrainerBattleLoadArgs(sOrdinaryNoIntroBattleParams, data); return EventScript_2713C2; - case 4: + case TRAINER_BATTLE_DOUBLE: TrainerBattleLoadArgs(sDoubleBattleParams, data); SetMapVarsToTrainer(); return EventScript_TryDoDoubleTrainerBattle; - case 2: + case TRAINER_BATTLE_CONTINUE_SCRIPT: if (gApproachingTrainerId == 0) { TrainerBattleLoadArgs(sContinueScriptBattleParams, data); @@ -1106,26 +1106,26 @@ const u8 *BattleSetup_ConfigureTrainerBattle(const u8 *data) TrainerBattleLoadArgs(sTrainerBContinueScriptBattleParams, data); } return EventScript_271362; - case 1: + case TRAINER_BATTLE_CONTINUE_SCRIPT_NO_MUSIC: TrainerBattleLoadArgs(sContinueScriptBattleParams, data); SetMapVarsToTrainer(); return EventScript_271362; - case 6: - case 8: + case TRAINER_BATTLE_CONTINUE_SCRIPT_DOUBLE: + case TRAINER_BATTLE_CONTINUE_SCRIPT_DOUBLE_NO_MUSIC: TrainerBattleLoadArgs(sContinueScriptDoubleBattleParams, data); SetMapVarsToTrainer(); return EventScript_TryDoDoubleTrainerBattle; - case 7: + case TRAINER_BATTLE_REMATCH_DOUBLE: TrainerBattleLoadArgs(sDoubleBattleParams, data); SetMapVarsToTrainer(); gTrainerBattleOpponent_A = GetRematchTrainerId(gTrainerBattleOpponent_A); return EventScript_TryDoDoubleRematchBattle; - case 5: + case TRAINER_BATTLE_REMATCH: TrainerBattleLoadArgs(sOrdinaryBattleParams, data); SetMapVarsToTrainer(); gTrainerBattleOpponent_A = GetRematchTrainerId(gTrainerBattleOpponent_A); return EventScript_2713D1; - case 9: + case TRAINER_BATTLE_9: if (gApproachingTrainerId == 0) { TrainerBattleLoadArgs(sOrdinaryBattleParams, data); @@ -1138,13 +1138,13 @@ const u8 *BattleSetup_ConfigureTrainerBattle(const u8 *data) gTrainerBattleOpponent_B = sub_81A9AA8(gSpecialVar_LastTalked); } return EventScript_271362; - case 10: + case TRAINER_BATTLE_SET_TRAINER_A: TrainerBattleLoadArgs(sOrdinaryBattleParams, data); return NULL; - case 11: + case TRAINER_BATTLE_SET_TRAINER_B: TrainerBattleLoadArgs(sTrainerBOrdinaryBattleParams, data); return NULL; - case 12: + case TRAINER_BATTLE_12: if (gApproachingTrainerId == 0) { TrainerBattleLoadArgs(sOrdinaryBattleParams, data); @@ -1591,11 +1591,11 @@ static bool32 UpdateRandomTrainerRematches(const struct RematchTrainer *table, u { if (gSaveBlock1Ptr->trainerRematches[i] != 0) { - // Trainer already wants a rematch. Don't bother updating it + // Trainer already wants a rematch. Don't bother updating it. ret = TRUE; } else if (FlagGet(FLAG_MATCH_CALL_REGISTERED + i) - && (Random() % 100) <= 30) // 31% chance of getting a rematch + && (Random() % 100) <= 30) // 31% chance of getting a rematch. { SetRematchIdForTrainer(table, i); ret = TRUE; diff --git a/src/battle_tv.c b/src/battle_tv.c index e5d97be30..cd0490a1b 100644 --- a/src/battle_tv.c +++ b/src/battle_tv.c @@ -9,8 +9,6 @@ #include "battle_message.h" #include "tv.h" -extern struct StringInfoBattle *gStringInfo; - // this file's functions static bool8 sub_817E0B8(u16 stringId); static void AddMovePoints(u8 caseId, u16 arg1, u8 arg2, u8 arg3); @@ -223,7 +221,7 @@ void BattleTv_SetDataBasedOnString(u16 stringId) atkSide = GetBattlerSide(gBattlerAttacker); defSide = GetBattlerSide(gBattlerTarget); effSide = GetBattlerSide(gEffectBattler); - scriptingSide = GetBattlerSide(gStringInfo->scrActive); + scriptingSide = GetBattlerSide(gBattleMsgDataPtr->scrActive); if (atkSide == B_SIDE_PLAYER) atkMon = &gPlayerParty[gBattlerPartyIndexes[gBattlerAttacker]]; @@ -235,7 +233,7 @@ void BattleTv_SetDataBasedOnString(u16 stringId) else defMon = &gEnemyParty[gBattlerPartyIndexes[gBattlerTarget]]; - moveSlot = GetBattlerMoveSlotId(gBattlerAttacker, gStringInfo->currentMove); + moveSlot = GetBattlerMoveSlotId(gBattlerAttacker, gBattleMsgDataPtr->currentMove); if (moveSlot >= 4 && sub_817E0B8(stringId) && stringId > BATTLESTRINGS_ID_ADDER) { @@ -480,8 +478,8 @@ void BattleTv_SetDataBasedOnString(u16 stringId) break; case STRINGID_PKMNFASTASLEEP: if (tvPtr->mon[atkSide][gBattlerPartyIndexes[gBattlerAttacker]].slpMonId != 0 - && gStringInfo->currentMove != MOVE_SNORE - && gStringInfo->currentMove != MOVE_SLEEP_TALK) + && gBattleMsgDataPtr->currentMove != MOVE_SNORE + && gBattleMsgDataPtr->currentMove != MOVE_SLEEP_TALK) AddMovePoints(9, 3, tvPtr->mon[atkSide][gBattlerPartyIndexes[gBattlerAttacker]].slpMonId - 1, tvPtr->mon[atkSide][gBattlerPartyIndexes[gBattlerAttacker]].slpMoveSlot); break; case STRINGID_PKMNWASFROZEN: diff --git a/src/braille_puzzles.c b/src/braille_puzzles.c index 35277fe87..91fcf8c46 100644 --- a/src/braille_puzzles.c +++ b/src/braille_puzzles.c @@ -14,7 +14,6 @@ extern void SetCameraPanningCallback(void ( *callback)()); // field_camera extern void InstallCameraPanAheadCallback(void); extern void SetCameraPanning(s16 x, s16 y); extern u8 GetCursorSelectionMonId(void); -extern void FieldEffectActiveListRemove(u8 id); // field_effect extern u8 oei_task_add(void); // why do this, GF? @@ -24,7 +23,8 @@ enum FLY_PUZZLE }; -extern u8 gBraillePuzzleCallbackFlag; +EWRAM_DATA static u8 sBraillePuzzleCallbackFlag = 0; + extern const u8 gUnknown_085EFE74[][2]; void SealedChamberShakingEffect(u8); @@ -208,11 +208,11 @@ bool8 ShouldDoBrailleStrengthEffect(void) if (!FlagGet(FLAG_SYS_BRAILLE_STRENGTH) && (gSaveBlock1Ptr->location.mapGroup == 0x18 && gSaveBlock1Ptr->location.mapNum == 0x06)) { if (gSaveBlock1Ptr->pos.x == 6 && gSaveBlock1Ptr->pos.y == 23) - { gBraillePuzzleCallbackFlag = STRENGTH_PUZZLE; return TRUE; } + { sBraillePuzzleCallbackFlag = STRENGTH_PUZZLE; return TRUE; } else if (gSaveBlock1Ptr->pos.x == 5 && gSaveBlock1Ptr->pos.y == 23) - { gBraillePuzzleCallbackFlag = STRENGTH_PUZZLE; return TRUE; } + { sBraillePuzzleCallbackFlag = STRENGTH_PUZZLE; return TRUE; } else if (gSaveBlock1Ptr->pos.x == 7 && gSaveBlock1Ptr->pos.y == 23) - { gBraillePuzzleCallbackFlag = STRENGTH_PUZZLE; return TRUE; } + { sBraillePuzzleCallbackFlag = STRENGTH_PUZZLE; return TRUE; } } return FALSE; @@ -249,7 +249,7 @@ bool8 ShouldDoBrailleFlyEffect(void) if (!FlagGet(FLAG_SYS_BRAILLE_FLY) && (gSaveBlock1Ptr->location.mapGroup == 0x18 && gSaveBlock1Ptr->location.mapNum == 0x44)) { if (gSaveBlock1Ptr->pos.x == 8 && gSaveBlock1Ptr->pos.y == 25) - { gBraillePuzzleCallbackFlag = FLY_PUZZLE; return TRUE; } + { sBraillePuzzleCallbackFlag = FLY_PUZZLE; return TRUE; } } return FALSE; } @@ -362,7 +362,7 @@ bool8 FldEff_UsePuzzleEffect(void) { u8 taskId = oei_task_add(); - if (gBraillePuzzleCallbackFlag == FLY_PUZZLE) + if (sBraillePuzzleCallbackFlag == FLY_PUZZLE) { gTasks[taskId].data[8] = (u32)UseFlyAncientTomb_Callback >> 16; gTasks[taskId].data[9] = (u32)UseFlyAncientTomb_Callback; diff --git a/src/hall_of_fame.c b/src/hall_of_fame.c index 78b615407..0ed22c1e1 100644 --- a/src/hall_of_fame.c +++ b/src/hall_of_fame.c @@ -33,7 +33,7 @@ struct HallofFameMon u32 personality; u16 species:9; u16 lvl:7; - u8 nick[10]; + u8 nick[POKEMON_NAME_LENGTH]; }; struct HallofFameTeam @@ -49,11 +49,11 @@ struct HofGfx u8 tilemap2[0x1000]; }; +static EWRAM_DATA u32 sUnknown_0203BCD4 = 0; static EWRAM_DATA struct HallofFameTeam *sHofMonPtr = NULL; static EWRAM_DATA struct HofGfx *sHofGfxPtr = NULL; extern bool8 gHasHallOfFameRecords; -extern u32 gUnknown_0203BCD4; extern struct MusicPlayerInfo gMPlayInfo_BGM; extern MainCallback gGameContinueCallback; extern u32 gDamagedSaveSectors; @@ -490,7 +490,7 @@ static void Task_Hof_InitMonData(u8 taskId) } } - gUnknown_0203BCD4 = 0; + sUnknown_0203BCD4 = 0; gTasks[taskId].tDisplayedMonId = 0; gTasks[taskId].tPlayerSpriteID = 0xFF; @@ -648,11 +648,11 @@ static void Task_Hof_TryDisplayAnotherMon(u8 taskId) } else { - gUnknown_0203BCD4 |= (0x10000 << gSprites[gTasks[taskId].tMonSpriteId(currPokeID)].oam.paletteNum); + sUnknown_0203BCD4 |= (0x10000 << gSprites[gTasks[taskId].tMonSpriteId(currPokeID)].oam.paletteNum); if (gTasks[taskId].tDisplayedMonId <= 4 && currMon[1].species != SPECIES_NONE) // there is another pokemon to display { gTasks[taskId].tDisplayedMonId++; - BeginNormalPaletteFade(gUnknown_0203BCD4, 0, 12, 12, 0x63B0); + BeginNormalPaletteFade(sUnknown_0203BCD4, 0, 12, 12, 0x63B0); gSprites[gTasks[taskId].tMonSpriteId(currPokeID)].oam.priority = 1; gTasks[taskId].func = Task_Hof_DisplayMon; } @@ -696,7 +696,7 @@ static void sub_8173DC0(u8 taskId) if (gTasks[taskId].tMonSpriteId(i) != 0xFF) gSprites[gTasks[taskId].tMonSpriteId(i)].oam.priority = 1; } - BeginNormalPaletteFade(gUnknown_0203BCD4, 0, 12, 12, 0x63B0); + BeginNormalPaletteFade(sUnknown_0203BCD4, 0, 12, 12, 0x63B0); FillWindowPixelBuffer(0, 0); CopyWindowToVram(0, 3); gTasks[taskId].tFrameCount = 7; @@ -923,7 +923,7 @@ static void Task_HofPC_DrawSpritesPrintText(u8 taskId) savedTeams++; currMon = &savedTeams->mon[0]; - gUnknown_0203BCD4 = 0; + sUnknown_0203BCD4 = 0; gTasks[taskId].tCurrMonId = 0; gTasks[taskId].tMonNo = 0; @@ -998,8 +998,8 @@ static void Task_HofPC_PrintMonInfo(u8 taskId) currMonID = gTasks[taskId].tMonSpriteId(gTasks[taskId].tCurrMonId); gSprites[currMonID].oam.priority = 0; - gUnknown_0203BCD4 = (0x10000 << gSprites[currMonID].oam.paletteNum) ^ 0xFFFF0000; - BlendPalettesUnfaded(gUnknown_0203BCD4, 0xC, 0x63B0); + sUnknown_0203BCD4 = (0x10000 << gSprites[currMonID].oam.paletteNum) ^ 0xFFFF0000; + BlendPalettesUnfaded(sUnknown_0203BCD4, 0xC, 0x63B0); currMon = &savedTeams->mon[gTasks[taskId].tCurrMonId]; if (currMon->species != SPECIES_EGG) diff --git a/sym_ewram.txt b/sym_ewram.txt index 7ea9bef79..4dff894f8 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -174,9 +174,7 @@ gBattle_WIN1H: @ 2022E28 gBattle_WIN1V: @ 2022E2A .space 0x2 - .include "src/battle_message.o" .include "src/battle_main.o" - .include "src/pokemon.o" .include "src/random.o" .include "src/daycare.o" @@ -288,9 +286,6 @@ gUnknown_02038BC6: @ 2038BC6 .include "src/field_effect.o" .include "src/scanline_effect.o" .include "src/option_menu.o" - - .align 2 - .include "src/pokedex.o" gTrainerCards: @ 2039B58 @@ -684,12 +679,7 @@ gUnknown_0203AB98: @ 203AB98 .include "src/coins.o" .include "src/battle_transition.o" - -gBattlerAbilities: @ 203ABA4 - .space 0x4 - -gStringInfo: @ 203ABA8 - .space 0x4 + .include "src/battle_message.o" gUnknown_0203ABAC: @ 203ABAC .space 0x4 @@ -740,10 +730,6 @@ gUnknown_0203BC8C: @ 203BC8C .include "src/player_pc.o" .include "src/intro.o" .include "src/field_region_map.o" - -gUnknown_0203BCD4: @ 203BCD4 - .space 0x4 - .include "src/hall_of_fame.o" .include "src/credits.o" .include "src/lottery_corner.o" @@ -751,10 +737,7 @@ gUnknown_0203BCD4: @ 203BCD4 .include "src/berry_tag_screen.o" .include "src/mystery_event_menu.o" .include "src/save_failed_screen.o" - -gBraillePuzzleCallbackFlag: @ 203BD14 - .space 0x4 - + .include "src/braille_puzzles.o" .include "src/pokeblock_feed.o" .include "src/intro_credits_graphics.o" .include "src/recorded_battle.o" From 2d0be91217e0ea16f298bb823e954a4d6f6ff63b Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sat, 30 Jun 2018 18:55:34 +0200 Subject: [PATCH 07/15] Move all trainer defines to trainers.h and identify frontier brain trainer id --- asm/battle_frontier_2.s | 26 ++++++++++---------- asm/battle_tower.s | 4 ++-- data/battle_frontier_2.s | 7 ++++-- src/battle_bg.c | 2 +- src/battle_controller_opponent.c | 4 ++-- src/battle_controller_player.c | 19 ++++++++------- src/battle_controller_player_partner.c | 11 +++++---- src/battle_controller_wally.c | 15 ++++++------ src/battle_main.c | 6 ++--- src/battle_message.c | 20 ++++++++-------- src/battle_script_commands.c | 6 ++--- src/battle_setup.c | 8 +++---- src/pokemon.c | 12 +++++----- src/recorded_battle.c | 14 +++++------ src/reshow_battle_screen.c | 33 +++++++++++++------------- 15 files changed, 97 insertions(+), 90 deletions(-) diff --git a/asm/battle_frontier_2.s b/asm/battle_frontier_2.s index 02bfe8b3b..e377c1b2b 100644 --- a/asm/battle_frontier_2.s +++ b/asm/battle_frontier_2.s @@ -19881,7 +19881,7 @@ sub_81A4CB0: @ 81A4CB0 ands r0, r1 cmp r0, 0 beq _081A4CD0 - bl sub_8185EA0 + bl GetRecordedBattleFrontierFacility lsls r0, 24 lsrs r0, 24 b _081A4CDA @@ -19893,7 +19893,7 @@ _081A4CD0: lsrs r0, 16 _081A4CDA: ldr r2, =gTrainers - ldr r1, =gUnknown_08611D30 + ldr r1, =gFacilityToBrainTrainerId lsls r0, 1 adds r0, r1 ldrh r1, [r0] @@ -19907,8 +19907,8 @@ _081A4CDA: .pool thumb_func_end sub_81A4CB0 - thumb_func_start sub_81A4D00 -sub_81A4D00: @ 81A4D00 + thumb_func_start GetFrontierBrainTrainerClass +GetFrontierBrainTrainerClass: @ 81A4D00 push {lr} ldr r0, =gBattleTypeFlags ldr r0, [r0] @@ -19917,7 +19917,7 @@ sub_81A4D00: @ 81A4D00 ands r0, r1 cmp r0, 0 beq _081A4D20 - bl sub_8185EA0 + bl GetRecordedBattleFrontierFacility lsls r0, 24 lsrs r0, 24 b _081A4D2A @@ -19929,7 +19929,7 @@ _081A4D20: lsrs r0, 16 _081A4D2A: ldr r2, =gTrainers - ldr r1, =gUnknown_08611D30 + ldr r1, =gFacilityToBrainTrainerId lsls r0, 1 adds r0, r1 ldrh r1, [r0] @@ -19941,10 +19941,10 @@ _081A4D2A: pop {r1} bx r1 .pool - thumb_func_end sub_81A4D00 + thumb_func_end GetFrontierBrainTrainerClass - thumb_func_start sub_81A4D50 -sub_81A4D50: @ 81A4D50 + thumb_func_start CopyFrontierBrainTrainerName +CopyFrontierBrainTrainerName: @ 81A4D50 push {r4,lr} adds r4, r0, 0 ldr r0, =gBattleTypeFlags @@ -19954,7 +19954,7 @@ sub_81A4D50: @ 81A4D50 ands r0, r1 cmp r0, 0 beq _081A4D70 - bl sub_8185EA0 + bl GetRecordedBattleFrontierFacility lsls r0, 24 lsrs r0, 24 b _081A4D7A @@ -19968,7 +19968,7 @@ _081A4D7A: movs r3, 0 lsls r0, 1 ldr r2, =gTrainers - ldr r1, =gUnknown_08611D30 + ldr r1, =gFacilityToBrainTrainerId adds r0, r1 ldrh r1, [r0] lsls r0, r1, 2 @@ -19991,7 +19991,7 @@ _081A4D90: pop {r0} bx r0 .pool - thumb_func_end sub_81A4D50 + thumb_func_end CopyFrontierBrainTrainerName thumb_func_start sub_81A4DB8 sub_81A4DB8: @ 81A4DB8 @@ -20483,7 +20483,7 @@ sub_81A51A8: @ 81A51A8 ands r0, r1 cmp r0, 0 beq _081A51D4 - bl sub_8185EA0 + bl GetRecordedBattleFrontierFacility lsls r0, 24 lsrs r4, r0, 24 bl sub_8185EAC diff --git a/asm/battle_tower.s b/asm/battle_tower.s index 788061f2b..c3b82a836 100644 --- a/asm/battle_tower.s +++ b/asm/battle_tower.s @@ -1479,7 +1479,7 @@ _08162C08: ldr r0, =0x000003fe cmp r4, r0 bne _08162C1C - bl sub_81A4D00 + bl GetFrontierBrainTrainerClass lsls r0, 24 lsrs r0, 24 b _08162D1E @@ -1729,7 +1729,7 @@ _08162E54: cmp r5, r0 bne _08162E68 adds r0, r6, 0 - bl sub_81A4D50 + bl CopyFrontierBrainTrainerName b _08162F62 .pool _08162E68: diff --git a/data/battle_frontier_2.s b/data/battle_frontier_2.s index ce2490579..1fbf2a2e1 100644 --- a/data/battle_frontier_2.s +++ b/data/battle_frontier_2.s @@ -1,5 +1,6 @@ #include "constants/moves.h" #include "constants/species.h" +#include "constants/trainers.h" .include "asm/macros.inc" .include "constants/constants.inc" @@ -1049,8 +1050,10 @@ gUnknown_08611D08:: @ 8611D08 .4byte gUnknown_085EE3C4 .align 1 -gUnknown_08611D30:: @ 8611D30 - .2byte 0x0325, 0x0326, 0x0327, 0x0328, 0x0329, 0x032a, 0x032b, 0x0000 +gFacilityToBrainTrainerId:: @ 8611D30 + .2byte TRAINER_ANABEL, TRAINER_TUCKER, TRAINER_SPENSER + .2byte TRAINER_GRETA, TRAINER_NOLAND, TRAINER_LUCY + .2byte TRAINER_BRANDON .align 2 gUnknown_08611D40:: @ 8611D40 diff --git a/src/battle_bg.c b/src/battle_bg.c index 4895e9643..c5dd727f4 100644 --- a/src/battle_bg.c +++ b/src/battle_bg.c @@ -478,7 +478,7 @@ void DrawBattleEntryBackground(void) } else if (gBattleTypeFlags & (BATTLE_TYPE_FRONTIER | BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000 | BATTLE_TYPE_EREADER_TRAINER)) { - if (!(gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) || gPartnerTrainerId == STEVEN_PARTNER_ID) + if (!(gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) || gPartnerTrainerId == TRAINER_STEVEN_PARTNER) { LZDecompressVram(gBattleTerrainAnimTiles_Building, (void*)(VRAM + 0x4000)); LZDecompressVram(gBattleTerrainAnimTilemap_Building, (void*)(VRAM + 0xE000)); diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index 414e084ee..c37423a72 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -1232,7 +1232,7 @@ static void OpponentHandleDrawTrainerPic(void) { trainerPicId = GetSecretBaseTrainerPicIndex(); } - else if (gTrainerBattleOpponent_A == TRAINER_OPPONENT_3FE) + else if (gTrainerBattleOpponent_A == TRAINER_FRONTIER_BRAIN) { trainerPicId = sub_81A4CB0(); } @@ -1316,7 +1316,7 @@ static void OpponentHandleTrainerSlide(void) { trainerPicId = GetSecretBaseTrainerPicIndex(); } - else if (gTrainerBattleOpponent_A == TRAINER_OPPONENT_3FE) + else if (gTrainerBattleOpponent_A == TRAINER_FRONTIER_BRAIN) { trainerPicId = sub_81A4CB0(); } diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index 86775f50e..d30d34930 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -15,6 +15,7 @@ #include "constants/songs.h" #include "sound.h" #include "constants/moves.h" +#include "constants/trainers.h" #include "window.h" #include "m4a.h" #include "palette.h" @@ -2259,9 +2260,9 @@ static void DoSwitchOutAnimation(void) } } -// some explanation here -// in emerald it's possible to have a tag battle in the battle frontier facilities with AI -// which use the front sprite for both the player and the partner as opposed to any other battles (including the one with Steven) that use the back pic as well as animate it +// In emerald it's possible to have a tag battle in the battle frontier facilities with AI +// which use the front sprite for both the player and the partner as opposed to any other battles (including the one with Steven) +// that use an animated back pic. static void PlayerHandleDrawTrainerPic(void) { s16 xPos, yPos; @@ -2272,12 +2273,12 @@ static void PlayerHandleDrawTrainerPic(void) if ((gLinkPlayers[GetMultiplayerId()].version & 0xFF) == VERSION_FIRE_RED || (gLinkPlayers[GetMultiplayerId()].version & 0xFF) == VERSION_LEAF_GREEN) { - trainerPicId = gLinkPlayers[GetMultiplayerId()].gender + BACK_PIC_RED; + trainerPicId = gLinkPlayers[GetMultiplayerId()].gender + TRAINER_BACK_PIC_RED; } else if ((gLinkPlayers[GetMultiplayerId()].version & 0xFF) == VERSION_RUBY || (gLinkPlayers[GetMultiplayerId()].version & 0xFF) == VERSION_SAPPHIRE) { - trainerPicId = gLinkPlayers[GetMultiplayerId()].gender + BACK_PIC_RS_BRENDAN; + trainerPicId = gLinkPlayers[GetMultiplayerId()].gender + TRAINER_BACK_PIC_RUBY_SAPPHIRE_BRENDAN; } else { @@ -2296,7 +2297,7 @@ static void PlayerHandleDrawTrainerPic(void) else // first mon xPos = 32; - if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && gPartnerTrainerId != STEVEN_PARTNER_ID) + if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && gPartnerTrainerId != TRAINER_STEVEN_PARTNER) { xPos = 90; yPos = (8 - gTrainerFrontPicCoords[trainerPicId].coords) * 4 + 80; @@ -2314,7 +2315,7 @@ static void PlayerHandleDrawTrainerPic(void) } // Use front pic table for any tag battles unless your partner is Steven. - if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && gPartnerTrainerId != STEVEN_PARTNER_ID) + if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && gPartnerTrainerId != TRAINER_STEVEN_PARTNER) { trainerPicId = PlayerGenderToFrontTrainerPicId(gSaveBlock2Ptr->playerGender); DecompressTrainerFrontPic(trainerPicId, gActiveBattler); @@ -2354,12 +2355,12 @@ static void PlayerHandleTrainerSlide(void) if ((gLinkPlayers[GetMultiplayerId()].version & 0xFF) == VERSION_FIRE_RED || (gLinkPlayers[GetMultiplayerId()].version & 0xFF) == VERSION_LEAF_GREEN) { - trainerPicId = gLinkPlayers[GetMultiplayerId()].gender + BACK_PIC_RED; + trainerPicId = gLinkPlayers[GetMultiplayerId()].gender + TRAINER_BACK_PIC_RED; } else if ((gLinkPlayers[GetMultiplayerId()].version & 0xFF) == VERSION_RUBY || (gLinkPlayers[GetMultiplayerId()].version & 0xFF) == VERSION_SAPPHIRE) { - trainerPicId = gLinkPlayers[GetMultiplayerId()].gender + BACK_PIC_RS_BRENDAN; + trainerPicId = gLinkPlayers[GetMultiplayerId()].gender + TRAINER_BACK_PIC_RUBY_SAPPHIRE_BRENDAN; } else { diff --git a/src/battle_controller_player_partner.c b/src/battle_controller_player_partner.c index 6a70200b6..d7878678a 100644 --- a/src/battle_controller_player_partner.c +++ b/src/battle_controller_player_partner.c @@ -11,6 +11,7 @@ #include "util.h" #include "main.h" #include "constants/songs.h" +#include "constants/trainers.h" #include "sound.h" #include "window.h" #include "m4a.h" @@ -1308,9 +1309,9 @@ static void PlayerPartnerHandleDrawTrainerPic(void) s16 xPos, yPos; u32 trainerPicId; - if (gPartnerTrainerId == STEVEN_PARTNER_ID) + if (gPartnerTrainerId == TRAINER_STEVEN_PARTNER) { - trainerPicId = BACK_PIC_STEVEN; + trainerPicId = TRAINER_BACK_PIC_STEVEN; xPos = 90; yPos = (8 - gTrainerBackPicCoords[trainerPicId].coords) * 4 + 80; } @@ -1322,7 +1323,7 @@ static void PlayerPartnerHandleDrawTrainerPic(void) } // Use back pic only if the partner is Steven - if (gPartnerTrainerId == STEVEN_PARTNER_ID) + if (gPartnerTrainerId == TRAINER_STEVEN_PARTNER) { DecompressTrainerBackPic(trainerPicId, gActiveBattler); sub_806A12C(trainerPicId, GetBattlerPosition(gActiveBattler)); @@ -1793,9 +1794,9 @@ static void PlayerPartnerHandleIntroTrainerBallThrow(void) StartSpriteAnim(&gSprites[gBattlerSpriteIds[gActiveBattler]], 1); paletteNum = AllocSpritePalette(0xD6F9); - if (gPartnerTrainerId == STEVEN_PARTNER_ID) + if (gPartnerTrainerId == TRAINER_STEVEN_PARTNER) { - u8 spriteId = BACK_PIC_STEVEN; + u8 spriteId = TRAINER_BACK_PIC_STEVEN; LoadCompressedPalette(gTrainerBackPicPaletteTable[spriteId].data, 0x100 + paletteNum * 16, 32); } else diff --git a/src/battle_controller_wally.c b/src/battle_controller_wally.c index 5399ccbf0..f66a1d773 100644 --- a/src/battle_controller_wally.c +++ b/src/battle_controller_wally.c @@ -15,6 +15,7 @@ #include "constants/songs.h" #include "sound.h" #include "constants/moves.h" +#include "constants/trainers.h" #include "window.h" #include "m4a.h" #include "palette.h" @@ -1037,11 +1038,11 @@ static void WallyHandleReturnMonToBall(void) static void WallyHandleDrawTrainerPic(void) { - DecompressTrainerBackPic(BACK_PIC_WALLY, gActiveBattler); - sub_806A12C(BACK_PIC_WALLY, GetBattlerPosition(gActiveBattler)); + DecompressTrainerBackPic(TRAINER_BACK_PIC_WALLY, gActiveBattler); + sub_806A12C(TRAINER_BACK_PIC_WALLY, GetBattlerPosition(gActiveBattler)); gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gUnknown_0202499C, 80, - 80 + 4 * (8 - gTrainerBackPicCoords[BACK_PIC_WALLY].coords), + 80 + 4 * (8 - gTrainerBackPicCoords[TRAINER_BACK_PIC_WALLY].coords), 30); gSprites[gBattlerSpriteIds[gActiveBattler]].oam.paletteNum = gActiveBattler; gSprites[gBattlerSpriteIds[gActiveBattler]].pos2.x = 240; @@ -1052,11 +1053,11 @@ static void WallyHandleDrawTrainerPic(void) static void WallyHandleTrainerSlide(void) { - DecompressTrainerBackPic(BACK_PIC_WALLY, gActiveBattler); - sub_806A12C(BACK_PIC_WALLY, GetBattlerPosition(gActiveBattler)); + DecompressTrainerBackPic(TRAINER_BACK_PIC_WALLY, gActiveBattler); + sub_806A12C(TRAINER_BACK_PIC_WALLY, GetBattlerPosition(gActiveBattler)); gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gUnknown_0202499C, 80, - 80 + 4 * (8 - gTrainerBackPicCoords[BACK_PIC_WALLY].coords), + 80 + 4 * (8 - gTrainerBackPicCoords[TRAINER_BACK_PIC_WALLY].coords), 30); gSprites[gBattlerSpriteIds[gActiveBattler]].oam.paletteNum = gActiveBattler; gSprites[gBattlerSpriteIds[gActiveBattler]].pos2.x = -96; @@ -1444,7 +1445,7 @@ static void WallyHandleIntroTrainerBallThrow(void) StartSpriteAnim(&gSprites[gBattlerSpriteIds[gActiveBattler]], 1); paletteNum = AllocSpritePalette(0xD6F8); - LoadCompressedPalette(gTrainerBackPicPaletteTable[BACK_PIC_WALLY].data, 0x100 + paletteNum * 16, 32); + LoadCompressedPalette(gTrainerBackPicPaletteTable[TRAINER_BACK_PIC_WALLY].data, 0x100 + paletteNum * 16, 32); gSprites[gBattlerSpriteIds[gActiveBattler]].oam.paletteNum = paletteNum; taskId = CreateTask(sub_816AC04, 5); diff --git a/src/battle_main.c b/src/battle_main.c index 487e11993..dfe99e003 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -614,7 +614,7 @@ static void CB2_InitBattleInternal(void) gBattle_WIN0H = 240; - if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && gPartnerTrainerId != STEVEN_PARTNER_ID) + if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && gPartnerTrainerId != TRAINER_STEVEN_PARTNER) { gBattle_WIN0V = 159; gBattle_WIN1H = 240; @@ -1914,7 +1914,7 @@ static u8 CreateNPCTrainerParty(struct Pokemon *party, u16 trainerNum, bool8 fir s32 i, j; u8 monsCount; - if (trainerNum == SECRET_BASE_OPPONENT) + if (trainerNum == TRAINER_SECRET_BASE) return 0; if (gBattleTypeFlags & BATTLE_TYPE_TRAINER && !(gBattleTypeFlags & (BATTLE_TYPE_FRONTIER @@ -4982,7 +4982,7 @@ static void HandleEndTurn_BattleWon(void) BattleStopLowHpSound(); gBattlescriptCurrInstr = BattleScript_FrontierTrainerBattleWon; - if (gTrainerBattleOpponent_A == TRAINER_OPPONENT_3FE) + if (gTrainerBattleOpponent_A == TRAINER_FRONTIER_BRAIN) PlayBGM(MUS_KACHI3); else PlayBGM(MUS_KACHI1); diff --git a/src/battle_message.c b/src/battle_message.c index 9dcd4aaf1..d2ac6da8c 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -33,7 +33,7 @@ struct BattleWindowText extern u8 gUnknown_0203C7B4; -extern const u8 gMoveNames[LAST_MOVE_INDEX + 1][13]; +extern const u8 gMoveNames[MOVES_COUNT][13]; extern const u8 gTrainerClassNames[][13]; extern const u16 gUnknown_08D85620[]; @@ -43,11 +43,11 @@ extern const u8 gText_PkmnBoxLanettesPCFull[]; extern const u8 gText_PkmnTransferredSomeonesPC[]; extern const u8 gText_PkmnTransferredLanettesPC[]; -extern u8 sub_81A4D00(void); // battle_frontier_2 +extern u8 GetFrontierBrainTrainerClass(void); // battle_frontier_2 extern u8 GetFrontierOpponentClass(u16 trainerId); // battle_tower extern u8 sub_81D5530(u16 trainerId); // pokenav extern u8 GetEreaderTrainerClassId(void); // battle_tower -extern void sub_81A4D50(u8 *txtPtr); // battle_frontier_2 +extern void CopyFrontierBrainTrainerName(u8 *txtPtr); // battle_frontier_2 extern void sub_81D5554(u8 *txtPtr, u16 trainerId); // pokenav extern void GetEreaderTrainerName(u8 *txtPtr); extern void sub_81A36D0(u8 arg0, u16 trainerId); // battle_frontier_2 @@ -2139,7 +2139,7 @@ void BufferStringBattle(u16 stringID) case STRINGID_USEDMOVE: // pokemon used a move msg ChooseMoveUsedParticle(gBattleTextBuff1); // buff1 doesn't appear in the string, leftover from japanese move names - if (gBattleMsgDataPtr->currentMove > LAST_MOVE_INDEX) + if (gBattleMsgDataPtr->currentMove >= MOVES_COUNT) StringCopy(gBattleTextBuff2, sATypeMove_Table[*(&gBattleStruct->stringMoveType)]); else StringCopy(gBattleTextBuff2, gMoveNames[gBattleMsgDataPtr->currentMove]); @@ -2427,13 +2427,13 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst) HANDLE_NICKNAME_STRING_CASE(gBattleScripting.battler, gBattlerPartyIndexes[gBattleScripting.battler]) break; case B_TXT_CURRENT_MOVE: // current move name - if (gBattleMsgDataPtr->currentMove > LAST_MOVE_INDEX) + if (gBattleMsgDataPtr->currentMove >= MOVES_COUNT) toCpy = sATypeMove_Table[gBattleStruct->stringMoveType]; else toCpy = gMoveNames[gBattleMsgDataPtr->currentMove]; break; case B_TXT_LAST_MOVE: // originally used move name - if (gBattleMsgDataPtr->originallyUsedMove > LAST_MOVE_INDEX) + if (gBattleMsgDataPtr->originallyUsedMove >= MOVES_COUNT) toCpy = sATypeMove_Table[gBattleStruct->stringMoveType]; else toCpy = gMoveNames[gBattleMsgDataPtr->originallyUsedMove]; @@ -2501,8 +2501,8 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst) toCpy = gTrainerClassNames[GetSecretBaseTrainerClass()]; else if (gTrainerBattleOpponent_A == TRAINER_OPPONENT_C00) toCpy = gTrainerClassNames[sub_8068BB0()]; - else if (gTrainerBattleOpponent_A == TRAINER_OPPONENT_3FE) - toCpy = gTrainerClassNames[sub_81A4D00()]; + else if (gTrainerBattleOpponent_A == TRAINER_FRONTIER_BRAIN) + toCpy = gTrainerClassNames[GetFrontierBrainTrainerClass()]; else if (gBattleTypeFlags & BATTLE_TYPE_FRONTIER) toCpy = gTrainerClassNames[GetFrontierOpponentClass(gTrainerBattleOpponent_A)]; else if (gBattleTypeFlags & BATTLE_TYPE_x4000000) @@ -2525,9 +2525,9 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst) { toCpy = gLinkPlayers[multiplayerID ^ BIT_SIDE].name; } - else if (gTrainerBattleOpponent_A == TRAINER_OPPONENT_3FE) + else if (gTrainerBattleOpponent_A == TRAINER_FRONTIER_BRAIN) { - sub_81A4D50(text); + CopyFrontierBrainTrainerName(text); toCpy = text; } else if (gBattleTypeFlags & BATTLE_TYPE_FRONTIER) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index ecba9f934..9c48b083c 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -3533,7 +3533,7 @@ static void atk24(void) if (gBattleControllerExecFlags) return; - if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && gPartnerTrainerId == STEVEN_PARTNER_ID) + if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && gPartnerTrainerId == TRAINER_STEVEN_PARTNER) { for (i = 0; i < 3; i++) { @@ -5870,7 +5870,7 @@ static u32 GetTrainerMoneyToGive(u16 trainerId) u32 lastMonLevel = 0; u32 moneyReward = 0; - if (trainerId == SECRET_BASE_OPPONENT) + if (trainerId == TRAINER_SECRET_BASE) { moneyReward = 20 * gBattleResources->secretBase->party.levels[0] * gBattleStruct->moneyMultiplier; } @@ -8124,7 +8124,7 @@ static void atk9E_metronome(void) s32 i; gCurrentMove = (Random() & 0x1FF) + 1; - if (gCurrentMove > LAST_MOVE_INDEX) + if (gCurrentMove >= MOVES_COUNT) continue; for (i = 0; i < 4; i++); // ? diff --git a/src/battle_setup.c b/src/battle_setup.c index b11083929..b2655f731 100644 --- a/src/battle_setup.c +++ b/src/battle_setup.c @@ -798,7 +798,7 @@ static u8 GetTrainerBattleTransition(void) u8 enemyLevel; u8 playerLevel; - if (gTrainerBattleOpponent_A == SECRET_BASE_OPPONENT) + if (gTrainerBattleOpponent_A == TRAINER_SECRET_BASE) return B_TRANSITION_CHAMPION; if (gTrainers[gTrainerBattleOpponent_A].trainerClass == TRAINER_CLASS_ELITE_FOUR) @@ -1305,7 +1305,7 @@ void BattleSetup_StartTrainerBattle(void) static void CB2_EndTrainerBattle(void) { - if (gTrainerBattleOpponent_A == SECRET_BASE_OPPONENT) + if (gTrainerBattleOpponent_A == TRAINER_SECRET_BASE) { SetMainCallback2(CB2_ReturnToFieldContinueScript); } @@ -1329,7 +1329,7 @@ static void CB2_EndTrainerBattle(void) static void CB2_EndRematchBattle(void) { - if (gTrainerBattleOpponent_A == SECRET_BASE_OPPONENT) + if (gTrainerBattleOpponent_A == TRAINER_SECRET_BASE) { SetMainCallback2(CB2_ReturnToFieldContinueScript); } @@ -1497,7 +1497,7 @@ const u8 *GetTrainerALoseText(void) { const u8 *string; - if (gTrainerBattleOpponent_A == SECRET_BASE_OPPONENT) + if (gTrainerBattleOpponent_A == TRAINER_SECRET_BASE) string = GetSecretBaseTrainerLoseText(); else string = sTrainerADefeatSpeech; diff --git a/src/pokemon.c b/src/pokemon.c index 800b7c0cd..a4d62feca 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -2488,7 +2488,7 @@ static bool8 ShouldGetStatBadgeBoost(u16 badgeFlag, u8 battlerId) return FALSE; if (GetBattlerSide(battlerId) != B_SIDE_PLAYER) return FALSE; - if (gBattleTypeFlags & BATTLE_TYPE_TRAINER && gTrainerBattleOpponent_A == SECRET_BASE_OPPONENT) + if (gBattleTypeFlags & BATTLE_TYPE_TRAINER && gTrainerBattleOpponent_A == TRAINER_SECRET_BASE) return FALSE; if (FlagGet(badgeFlag)) return TRUE; @@ -5678,7 +5678,7 @@ const u8 *GetTrainerPartnerName(void) { if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) { - if (gPartnerTrainerId == STEVEN_PARTNER_ID) + if (gPartnerTrainerId == TRAINER_STEVEN_PARTNER) { return gTrainers[TRAINER_STEVEN].trainerName; } @@ -5891,15 +5891,15 @@ void HandleSetPokedexFlag(u16 nationalNum, u8 caseId, u32 personality) const u8 *GetTrainerClassNameFromId(u16 trainerId) { - if (trainerId > NO_OF_TRAINERS) - trainerId = 0; + if (trainerId >= TRAINERS_COUNT) + trainerId = TRAINER_NONE; return gTrainerClassNames[gTrainers[trainerId].trainerClass]; } const u8 *GetTrainerNameFromId(u16 trainerId) { - if (trainerId > NO_OF_TRAINERS) - trainerId = 0; + if (trainerId >= TRAINERS_COUNT) + trainerId = TRAINER_NONE; return gTrainers[trainerId].trainerName; } diff --git a/src/recorded_battle.c b/src/recorded_battle.c index eb48ab15a..3a4265895 100644 --- a/src/recorded_battle.c +++ b/src/recorded_battle.c @@ -79,7 +79,7 @@ EWRAM_DATA static u16 sUnknown_0203C79C[4] = {0}; EWRAM_DATA static u16 sUnknown_0203C7A4[4] = {0}; EWRAM_DATA static u8 sUnknown_0203C7AC = 0; EWRAM_DATA static u8 sUnknown_0203C7AD = 0; -EWRAM_DATA static u8 sUnknown_0203C7AE = 0; +EWRAM_DATA static u8 sRecordedBattle_FrontierFacility = 0; EWRAM_DATA static u8 sUnknown_0203C7AF = 0; EWRAM_DATA static MainCallback sCallback2_AfterRecordedBattle = NULL; EWRAM_DATA u8 gUnknown_0203C7B4 = 0; @@ -139,7 +139,7 @@ void sub_8184E58(void) if (sUnknown_0203C7AC == 1) { gRecordedBattleRngSeed = gRngValue; - sUnknown_0203C7AE = VarGet(VAR_FRONTIER_FACILITY); + sRecordedBattle_FrontierFacility = VarGet(VAR_FRONTIER_FACILITY); sUnknown_0203C7AF = sub_81A513C(); } else if (sUnknown_0203C7AC == 2) @@ -391,7 +391,7 @@ u32 MoveRecordedBattleToSaveData(void) battleSave->partnerId = gPartnerTrainerId; battleSave->field_4FA = gUnknown_0203C7B4; battleSave->field_4FC = gSaveBlock2Ptr->field_CA9_b; - battleSave->field_4FD = sUnknown_0203C7AE; + battleSave->field_4FD = sRecordedBattle_FrontierFacility; battleSave->field_4FE = sUnknown_0203C7AF; battleSave->battleStyle = gSaveBlock2Ptr->optionsBattleStyle; battleSave->textSpeed = gSaveBlock2Ptr->optionsTextSpeed; @@ -700,7 +700,7 @@ _081854E2:\n\ ldr r5, =0x000004fc\n\ adds r1, r7, r5\n\ strb r0, [r1]\n\ - ldr r0, =sUnknown_0203C7AE\n\ + ldr r0, =sRecordedBattle_FrontierFacility\n\ ldrb r1, [r0]\n\ adds r2, 0x3\n\ adds r0, r7, r2\n\ @@ -1354,7 +1354,7 @@ static void SetRecordedBattleVarsFromSave(struct RecordedBattleSave *src) gPartnerTrainerId = src->partnerId; gUnknown_0203C7B4 = src->field_4FA; sUnknown_0203C7AD = gSaveBlock2Ptr->frontierChosenLvl; - sUnknown_0203C7AE = src->field_4FD; + sRecordedBattle_FrontierFacility = src->field_4FD; sUnknown_0203C7AF = src->field_4FE; sRecordedBattle_BattleStyle = src->battleStyle; sRecordedBattle_TextSpeed = src->textSpeed; @@ -1415,9 +1415,9 @@ static void CB2_RecordedBattle(void) RunTasks(); } -u8 sub_8185EA0(void) +u8 GetRecordedBattleFrontierFacility(void) { - return sUnknown_0203C7AE; + return sRecordedBattle_FrontierFacility; } u8 sub_8185EAC(void) diff --git a/src/reshow_battle_screen.c b/src/reshow_battle_screen.c index 4456e450c..4d5240bc7 100644 --- a/src/reshow_battle_screen.c +++ b/src/reshow_battle_screen.c @@ -11,6 +11,7 @@ #include "link.h" #include "sprite.h" #include "constants/species.h" +#include "constants/trainers.h" #include "battle_interface.h" #include "battle_anim.h" #include "data2.h" @@ -144,20 +145,20 @@ static void CB2_ReshowBattleScreenAfterMenu(void) break; case 19: { - u8 opponentBank; + u8 opponentBattler; u16 species; LoadAndCreateEnemyShadowSprites(); - opponentBank = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); - species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[opponentBank]], MON_DATA_SPECIES); - SetBattlerShadowSpriteCallback(opponentBank, species); + opponentBattler = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); + species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[opponentBattler]], MON_DATA_SPECIES); + SetBattlerShadowSpriteCallback(opponentBattler, species); if (IsDoubleBattle()) { - opponentBank = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT); - species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[opponentBank]], MON_DATA_SPECIES); - SetBattlerShadowSpriteCallback(opponentBank, species); + opponentBattler = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT); + species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[opponentBattler]], MON_DATA_SPECIES); + SetBattlerShadowSpriteCallback(opponentBattler, species); } ActionSelectionCreateCursorAt(gActionSelectionCursor[gBattlerInMenuId], 0); @@ -204,10 +205,10 @@ static bool8 LoadBattlerSpriteGfx(u8 battler) else BattleLoadSubstituteOrMonSpriteGfx(battler, FALSE); } - else if (gBattleTypeFlags & BATTLE_TYPE_SAFARI && battler == 0) + else if (gBattleTypeFlags & BATTLE_TYPE_SAFARI && battler == B_POSITION_PLAYER_LEFT) // Should be checking position, not battler. DecompressTrainerBackPic(gSaveBlock2Ptr->playerGender, battler); - else if (gBattleTypeFlags & BATTLE_TYPE_WALLY_TUTORIAL && battler == 0) - DecompressTrainerBackPic(BACK_PIC_WALLY, battler); + else if (gBattleTypeFlags & BATTLE_TYPE_WALLY_TUTORIAL && battler == B_POSITION_PLAYER_LEFT) // Should be checking position, not battler. + DecompressTrainerBackPic(TRAINER_BACK_PIC_WALLY, battler); else if (!gBattleSpritesDataPtr->battlerData[battler].behindSubstitute) BattleLoadPlayerMonSpriteGfx(&gPlayerParty[gBattlerPartyIndexes[battler]], battler); else @@ -245,7 +246,7 @@ static void CreateBattlerSprite(u8 battler) if (gBattleSpritesDataPtr->battlerData[battler].transformSpecies == SPECIES_CASTFORM) gSprites[gBattlerSpriteIds[battler]].anims = gMonAnimationsSpriteAnimsPtrTable[SPECIES_CASTFORM]; } - else if (gBattleTypeFlags & BATTLE_TYPE_SAFARI && battler == 0) + else if (gBattleTypeFlags & BATTLE_TYPE_SAFARI && battler == B_POSITION_PLAYER_LEFT) { sub_806A12C(gSaveBlock2Ptr->playerGender, GetBattlerPosition(B_POSITION_PLAYER_LEFT)); gBattlerSpriteIds[battler] = CreateSprite(&gUnknown_0202499C, 0x50, @@ -255,11 +256,11 @@ static void CreateBattlerSprite(u8 battler) gSprites[gBattlerSpriteIds[battler]].callback = SpriteCallbackDummy; gSprites[gBattlerSpriteIds[battler]].data[0] = battler; } - else if (gBattleTypeFlags & BATTLE_TYPE_WALLY_TUTORIAL && battler == 0) + else if (gBattleTypeFlags & BATTLE_TYPE_WALLY_TUTORIAL && battler == B_POSITION_PLAYER_LEFT) { - sub_806A12C(BACK_PIC_WALLY, GetBattlerPosition(0)); + sub_806A12C(TRAINER_BACK_PIC_WALLY, GetBattlerPosition(0)); gBattlerSpriteIds[battler] = CreateSprite(&gUnknown_0202499C, 0x50, - (8 - gTrainerBackPicCoords[BACK_PIC_WALLY].coords) * 4 + 80, + (8 - gTrainerBackPicCoords[TRAINER_BACK_PIC_WALLY].coords) * 4 + 80, sub_80A82E4(0)); gSprites[gBattlerSpriteIds[battler]].oam.paletteNum = battler; gSprites[gBattlerSpriteIds[battler]].callback = SpriteCallbackDummy; @@ -292,9 +293,9 @@ static void CreateHealthboxSprite(u8 battler) { u8 healthboxSpriteId; - if (gBattleTypeFlags & BATTLE_TYPE_SAFARI && battler == 0) + if (gBattleTypeFlags & BATTLE_TYPE_SAFARI && battler == B_POSITION_PLAYER_LEFT) healthboxSpriteId = CreateSafariPlayerHealthboxSprites(); - else if (gBattleTypeFlags & BATTLE_TYPE_WALLY_TUTORIAL && battler == 0) + else if (gBattleTypeFlags & BATTLE_TYPE_WALLY_TUTORIAL && battler == B_POSITION_PLAYER_LEFT) return; else healthboxSpriteId = CreateBattlerHealthboxSprites(battler); From d2e47323fe988e430af782c2c10b8e41e7a131b3 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 1 Jul 2018 11:15:42 +0200 Subject: [PATCH 08/15] document frontier related --- asm/battle_frontier_2.s | 6 +- asm/battle_tower.s | 2 +- data/battle_ai_scripts.s | 6 +- data/data2b.s | 4 - include/battle.h | 30 +-- include/battle_util.h | 53 ++-- include/constants/abilities.h | 2 + include/constants/battle.h | 2 +- include/constants/battle_frontier.h | 13 + include/constants/battle_script_commands.h | 2 +- include/constants/moves.h | 2 +- include/constants/trainers.h | 18 +- include/data/battle_moves.h | 2 +- include/data/text/abilities.h | 4 +- include/pokemon.h | 2 +- include/recorded_battle.h | 2 +- src/battle_ai_script_commands.c | 2 +- src/battle_controller_link_partner.c | 9 +- src/battle_controller_opponent.c | 7 +- src/battle_controller_recorded_opponent.c | 1 + src/battle_controllers.c | 14 +- src/battle_gfx_sfx_util.c | 77 +++--- src/battle_interface.c | 6 +- src/battle_main.c | 50 ++-- src/battle_message.c | 3 +- src/battle_script_commands.c | 30 +-- src/battle_tv.c | 8 +- src/battle_util.c | 283 +++++++++++---------- src/pokemon.c | 22 +- src/recorded_battle.c | 116 ++++----- 30 files changed, 402 insertions(+), 376 deletions(-) create mode 100644 include/constants/battle_frontier.h diff --git a/asm/battle_frontier_2.s b/asm/battle_frontier_2.s index e377c1b2b..586cc8f05 100644 --- a/asm/battle_frontier_2.s +++ b/asm/battle_frontier_2.s @@ -19871,8 +19871,8 @@ _081A4C84: .pool thumb_func_end sub_81A4C30 - thumb_func_start sub_81A4CB0 -sub_81A4CB0: @ 81A4CB0 + thumb_func_start GetFrontierBrainTrainerPicIndex +GetFrontierBrainTrainerPicIndex: @ 81A4CB0 push {lr} ldr r0, =gBattleTypeFlags ldr r0, [r0] @@ -19905,7 +19905,7 @@ _081A4CDA: pop {r1} bx r1 .pool - thumb_func_end sub_81A4CB0 + thumb_func_end GetFrontierBrainTrainerPicIndex thumb_func_start GetFrontierBrainTrainerClass GetFrontierBrainTrainerClass: @ 81A4D00 diff --git a/asm/battle_tower.s b/asm/battle_tower.s index c3b82a836..1e07bdb9c 100644 --- a/asm/battle_tower.s +++ b/asm/battle_tower.s @@ -1353,7 +1353,7 @@ _08162AD0: ldr r0, =0x000003fe cmp r4, r0 bne _08162AE4 - bl sub_81A4CB0 + bl GetFrontierBrainTrainerPicIndex lsls r0, 24 lsrs r0, 24 b _08162BCA diff --git a/data/battle_ai_scripts.s b/data/battle_ai_scripts.s index 1b4863046..2db1c5728 100644 --- a/data/battle_ai_scripts.s +++ b/data/battle_ai_scripts.s @@ -3382,11 +3382,11 @@ AI_Safari_Flee: flee AI_FirstBattle: - if_hp_equal AI_TARGET, 20, BattleAIScript_82DE34D - if_hp_less_than AI_TARGET, 20, BattleAIScript_82DE34D + if_hp_equal AI_TARGET, 20, AI_FirstBattle_Flee + if_hp_less_than AI_TARGET, 20, AI_FirstBattle_Flee end -BattleAIScript_82DE34D: +AI_FirstBattle_Flee: flee AI_Ret: diff --git a/data/data2b.s b/data/data2b.s index 17a44ecbc..de32e9775 100644 --- a/data/data2b.s +++ b/data/data2b.s @@ -4862,7 +4862,3 @@ gUnknown_0831ACC4:: @ 831ACC4 .align 2 gUnknown_0831ACDC:: @ 831ACDC .4byte gUnknown_0831ACC4 - - .align 2 -gUnknown_0831ACE0:: @ 831ACE0 - .byte 0xe0, 0xf0, 0xf0, 0xe0, 0xe0, 0x00, 0x00, 0x00 diff --git a/include/battle.h b/include/battle.h index 0169dde7c..6e941191f 100644 --- a/include/battle.h +++ b/include/battle.h @@ -16,12 +16,6 @@ #define GET_BATTLER_SIDE(battler) (GetBattlerPosition(battler) & BIT_SIDE) #define GET_BATTLER_SIDE2(battler) (GET_BATTLER_POSITION(battler) & BIT_SIDE) -#define TRAINER_OPPONENT_3FE 0x3FE -#define TRAINER_OPPONENT_C00 0xC00 -#define TRAINER_OPPONENT_800 0x800 -#define STEVEN_PARTNER_ID 0xC03 -#define SECRET_BASE_OPPONENT 0x400 - // Battle Actions // These determine what each battler will do in a turn #define B_ACTION_USE_MOVE 0 @@ -429,7 +423,7 @@ struct BattleTv_Mon struct BattleTv { - struct BattleTv_Mon mon[2][6]; // [side][partyId] + struct BattleTv_Mon mon[2][PARTY_SIZE]; // [side][partyId] struct BattleTv_Position pos[2][2]; // [side][flank] struct BattleTv_Side side[2]; // [side] }; @@ -479,10 +473,10 @@ struct BattleStruct u8 runTries; u8 caughtMonNick[11]; u8 field_78; - u8 field_79; - u8 field_7A; - u8 field_7B; - u8 field_7C; + u8 safariGoNearCounter; + u8 safariPkblThrowCounter; + u8 safariEscapeFactor; + u8 safariCatchFactor; u8 field_7D; u8 field_7E; u8 formToChangeInto; @@ -526,7 +520,7 @@ struct BattleStruct u8 AI_itemFlags[2]; u16 choicedMove[MAX_BATTLERS_COUNT]; u16 changedItems[MAX_BATTLERS_COUNT]; - u8 intimidateBank; + u8 intimidateBattler; u8 switchInItemsCounter; u8 field_DA; u8 turnSideTracker; @@ -611,18 +605,6 @@ struct BattleScripting u8 multiplayerId; }; -enum -{ - BACK_PIC_BRENDAN, - BACK_PIC_MAY, - BACK_PIC_RED, - BACK_PIC_LEAF, - BACK_PIC_RS_BRENDAN, - BACK_PIC_RS_MAY, - BACK_PIC_WALLY, - BACK_PIC_STEVEN -}; - // rom_80A5C6C u8 GetBattlerSide(u8 battler); u8 GetBattlerPosition(u8 bank); diff --git a/include/battle_util.h b/include/battle_util.h index 0b5590011..0531966df 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -8,27 +8,27 @@ #define MOVE_LIMITATION_TAUNT (1 << 4) #define MOVE_LIMITATION_IMPRISION (1 << 5) -#define ABILITYEFFECT_ON_SWITCHIN 0x0 -#define ABILITYEFFECT_ENDTURN 0x1 -#define ABILITYEFFECT_MOVES_BLOCK 0x2 -#define ABILITYEFFECT_ABSORBING 0x3 -#define ABILITYEFFECT_CONTACT 0x4 -#define ABILITYEFFECT_IMMUNITY 0x5 -#define ABILITYEFFECT_FORECAST 0x6 -#define ABILITYEFFECT_SYNCHRONIZE 0x7 -#define ABILITYEFFECT_ATK_SYNCHRONIZE 0x8 -#define ABILITYEFFECT_INTIMIDATE1 0x9 -#define ABILITYEFFECT_INTIMIDATE2 0xA -#define ABILITYEFFECT_TRACE 0xB -#define ABILITYEFFECT_CHECK_OTHER_SIDE 0xC -#define ABILITYEFFECT_CHECK_BANK_SIDE 0xD -#define ABILITYEFFECT_FIELD_SPORT 0xE -#define ABILITYEFFECT_CHECK_FIELD_EXCEPT_BANK 0xF -#define ABILITYEFFECT_COUNT_OTHER_SIDE 0x10 -#define ABILITYEFFECT_COUNT_BANK_SIDE 0x11 -#define ABILITYEFFECT_COUNT_ON_FIELD 0x12 -#define ABILITYEFFECT_CHECK_ON_FIELD 0x13 -#define ABILITYEFFECT_SWITCH_IN_WEATHER 0xFF +#define ABILITYEFFECT_ON_SWITCHIN 0x0 +#define ABILITYEFFECT_ENDTURN 0x1 +#define ABILITYEFFECT_MOVES_BLOCK 0x2 +#define ABILITYEFFECT_ABSORBING 0x3 +#define ABILITYEFFECT_CONTACT 0x4 +#define ABILITYEFFECT_IMMUNITY 0x5 +#define ABILITYEFFECT_FORECAST 0x6 +#define ABILITYEFFECT_SYNCHRONIZE 0x7 +#define ABILITYEFFECT_ATK_SYNCHRONIZE 0x8 +#define ABILITYEFFECT_INTIMIDATE1 0x9 +#define ABILITYEFFECT_INTIMIDATE2 0xA +#define ABILITYEFFECT_TRACE 0xB +#define ABILITYEFFECT_CHECK_OTHER_SIDE 0xC +#define ABILITYEFFECT_CHECK_BATTLER_SIDE 0xD +#define ABILITYEFFECT_FIELD_SPORT 0xE +#define ABILITYEFFECT_CHECK_FIELD_EXCEPT_BATTLER 0xF +#define ABILITYEFFECT_COUNT_OTHER_SIDE 0x10 +#define ABILITYEFFECT_COUNT_BATTLER_SIDE 0x11 +#define ABILITYEFFECT_COUNT_ON_FIELD 0x12 +#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)) @@ -39,15 +39,6 @@ #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 -#define BS_GET_EFFECT_BANK 2 -#define BS_GET_SCRIPTING_BANK 10 -#define BS_GET_PLAYER1 11 -#define BS_GET_OPPONENT1 12 -#define BS_GET_PLAYER2 13 -#define BS_GET_OPPONENT2 14 - u8 GetBattlerForBattleScript(u8 caseId); void PressurePPLose(u8 bankDef, u8 bankAtk, u16 move); void PressurePPLoseOnUsingPerishSong(u8 bankAtk); @@ -74,7 +65,7 @@ bool8 HandleWishPerishSongOnTurnEnd(void); bool8 HandleFaintedMonActions(void); void TryClearRageStatuses(void); u8 AtkCanceller_UnableToUseMove(void); -bool8 sub_80423F4(u8 battlerId, u8 r1, u8 r2); +bool8 HasNoMonsToSwitch(u8 battlerId, u8 r1, u8 r2); u8 CastformDataTypeChange(u8 battlerId); u8 AbilityBattleEffects(u8 caseID, u8 battlerId, u8 ability, u8 special, u16 moveArg); void BattleScriptExecute(const u8* BS_ptr); diff --git a/include/constants/abilities.h b/include/constants/abilities.h index 4e2c4056c..4ad54c86f 100644 --- a/include/constants/abilities.h +++ b/include/constants/abilities.h @@ -80,4 +80,6 @@ #define ABILITY_CACOPHONY 76 #define ABILITY_AIR_LOCK 77 +#define ABILITIES_COUNT 78 + #endif // GUARD_CONSTANTS_ABILITIES_H diff --git a/include/constants/battle.h b/include/constants/battle.h index 5a09067ad..b3f9d919a 100644 --- a/include/constants/battle.h +++ b/include/constants/battle.h @@ -130,7 +130,7 @@ #define STATUS2_TORMENT 0x80000000 // Seems like per-battler statuses. Not quite sure how to categorize these -#define STATUS3_LEECHSEED_BANK 0x3 +#define STATUS3_LEECHSEED_BATTLER 0x3 #define STATUS3_LEECHSEED 0x4 #define STATUS3_ALWAYS_HITS 0x18 // two bits #define STATUS3_PERISH_SONG 0x20 diff --git a/include/constants/battle_frontier.h b/include/constants/battle_frontier.h new file mode 100644 index 000000000..4145805c4 --- /dev/null +++ b/include/constants/battle_frontier.h @@ -0,0 +1,13 @@ +#ifndef GUARD_CONSTANTS_BATTLE_FRONTIER_H +#define GUARD_CONSTANTS_BATTLE_FRONTIER_H + +// Battle Frontier facility ids. +#define FRONTIER_FACILITY_TOWER 0 +#define FRONTIER_FACILITY_DOME 1 +#define FRONTIER_FACILITY_PALACE 2 +#define FRONTIER_FACILITY_ARENA 3 +#define FRONTIER_FACILITY_FACTORY 4 +#define FRONTIER_FACILITY_PIKE 5 +#define FRONTIER_FACILITY_PYRAMID 6 + +#endif // GUARD_CONSTANTS_BATTLE_FRONTIER_H diff --git a/include/constants/battle_script_commands.h b/include/constants/battle_script_commands.h index a1a4ed50a..c820a1114 100644 --- a/include/constants/battle_script_commands.h +++ b/include/constants/battle_script_commands.h @@ -37,7 +37,7 @@ #define BS_ATTACKER 1 #define BS_EFFECT_BATTLER 2 #define BS_FAINTED 3 -#define BS_BANK_0 7 +#define BS_BATTLER_0 7 #define BS_ATTACKER_WITH_PARTNER 4 // for atk98_status_icon_update #define BS_ATTACKER_SIDE 8 // for atk1E_jumpifability #define BS_NOT_ATTACKER_SIDE 9 // for atk1E_jumpifability diff --git a/include/constants/moves.h b/include/constants/moves.h index f3a3acb90..85c02e3da 100644 --- a/include/constants/moves.h +++ b/include/constants/moves.h @@ -357,6 +357,6 @@ #define MOVE_DOOM_DESIRE 353 #define MOVE_PSYCHO_BOOST 354 -#define LAST_MOVE_INDEX MOVE_PSYCHO_BOOST +#define MOVES_COUNT 355 #endif // GUARD_CONSTANTS_MOVES_H diff --git a/include/constants/trainers.h b/include/constants/trainers.h index a017b6975..eb695e4ab 100644 --- a/include/constants/trainers.h +++ b/include/constants/trainers.h @@ -857,7 +857,14 @@ #define TRAINER_BRENDAN_16 853 #define TRAINER_MAY_16 854 -#define NO_OF_TRAINERS 854 +#define TRAINERS_COUNT 855 + +// Special Trainer Ids. +#define TRAINER_FRONTIER_BRAIN 1022 +#define TRAINER_SECRET_BASE 1024 +#define TRAINER_LINK_OPPONENT 0x800 +#define TRAINER_OPPONENT_C00 0xC00 +#define TRAINER_STEVEN_PARTNER 0xC03 #define TRAINER_PIC_HIKER 0 #define TRAINER_PIC_AQUA_GRUNT_M 1 @@ -953,6 +960,15 @@ #define TRAINER_PIC_RUBY_SAPPHIRE_BRENDAN 91 #define TRAINER_PIC_RUBY_SAPPHIRE_MAY 92 +#define TRAINER_BACK_PIC_BRENDAN 0 +#define TRAINER_BACK_PIC_MAY 1 +#define TRAINER_BACK_PIC_RED 2 +#define TRAINER_BACK_PIC_LEAF 3 +#define TRAINER_BACK_PIC_RUBY_SAPPHIRE_BRENDAN 4 +#define TRAINER_BACK_PIC_RUBY_SAPPHIRE_MAY 5 +#define TRAINER_BACK_PIC_WALLY 6 +#define TRAINER_BACK_PIC_STEVEN 7 + #define FACILITY_CLASS_HIKER 0x0 #define FACILITY_CLASS_TEAM_AQUA_1 0x1 #define FACILITY_CLASS_PKMN_BREEDER_1 0x2 diff --git a/include/data/battle_moves.h b/include/data/battle_moves.h index 6489fe07f..00a6f7fdb 100644 --- a/include/data/battle_moves.h +++ b/include/data/battle_moves.h @@ -1,7 +1,7 @@ #ifndef GUARD_DATA_BATTLE_MOVES #define GUARD_DATA_BATTLE_MOVES -const struct BattleMove gBattleMoves[LAST_MOVE_INDEX + 1] = +const struct BattleMove gBattleMoves[MOVES_COUNT] = { { // MOVE_NONE .effect = EFFECT_HIT, diff --git a/include/data/text/abilities.h b/include/data/text/abilities.h index 2efd76afc..3a1e989d2 100644 --- a/include/data/text/abilities.h +++ b/include/data/text/abilities.h @@ -80,7 +80,7 @@ static const u8 gShellArmorAbilityDescription[] = _("Blocks critical hits."); static const u8 gCacophonyAbilityDescription[] = _("Avoids sound-based moves."); static const u8 gAirLockAbilityDescription[] = _("Negates weather effects."); -const u8 gAbilityNames[][ABILITY_NAME_LENGTH + 1] = +const u8 gAbilityNames[ABILITIES_COUNT][ABILITY_NAME_LENGTH + 1] = { _("-------"), _("STENCH"), @@ -162,7 +162,7 @@ const u8 gAbilityNames[][ABILITY_NAME_LENGTH + 1] = _("AIR LOCK"), }; -const u8 *const gAbilityDescriptionPointers[] = +const u8 *const gAbilityDescriptionPointers[ABILITIES_COUNT] = { gNoneAbilityDescription, gStenchAbilityDescription, diff --git a/include/pokemon.h b/include/pokemon.h index 37028821a..f928243d0 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -556,7 +556,7 @@ void sub_806D544(u16 species, u32 personality, u8 *dest); void DrawSpindaSpots(u16 species, u32 personality, u8 *dest, u8 a4); void EvolutionRenameMon(struct Pokemon *mon, u16 oldSpecies, u16 newSpecies); bool8 sub_806D7EC(void); -bool16 sub_806D82C(u8 id); +bool16 GetLinkTrainerFlankId(u8 id); s32 GetBattlerMultiplayerId(u16 a1); u8 GetTrainerEncounterMusicId(u16 trainerOpponentId); u16 ModifyStatByNature(u8 nature, u16 n, u8 statIndex); diff --git a/include/recorded_battle.h b/include/recorded_battle.h index 8b1fa258d..81c88a15e 100644 --- a/include/recorded_battle.h +++ b/include/recorded_battle.h @@ -16,7 +16,7 @@ void sub_81851A8(u8 *arg0); bool32 CanCopyRecordedBattleSaveData(void); u32 MoveRecordedBattleToSaveData(void); void PlayRecordedBattle(void (*CB2_After)(void)); -u8 sub_8185EA0(void); +u8 GetRecordedBattleFrontierFacility(void); u8 sub_8185EAC(void); void RecordedBattle_SaveParties(void); u8 GetActiveBattlerLinkPlayerGender(void); diff --git a/src/battle_ai_script_commands.c b/src/battle_ai_script_commands.c index 131598985..e82d22576 100644 --- a/src/battle_ai_script_commands.c +++ b/src/battle_ai_script_commands.c @@ -1969,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->safariEscapeFactor * 5; // Safari flee rate, from 0-20. if ((u8)(Random() % 100) < safariFleeRate) gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 1); diff --git a/src/battle_controller_link_partner.c b/src/battle_controller_link_partner.c index be9609e62..a88c4a076 100644 --- a/src/battle_controller_link_partner.c +++ b/src/battle_controller_link_partner.c @@ -12,6 +12,7 @@ #include "util.h" #include "main.h" #include "constants/songs.h" +#include "constants/trainers.h" #include "sound.h" #include "window.h" #include "m4a.h" @@ -1133,12 +1134,12 @@ static void LinkPartnerHandleDrawTrainerPic(void) if ((gLinkPlayers[GetBattlerMultiplayerId(gActiveBattler)].version & 0xFF) == VERSION_FIRE_RED || (gLinkPlayers[GetBattlerMultiplayerId(gActiveBattler)].version & 0xFF) == VERSION_LEAF_GREEN) { - trainerPicId = gLinkPlayers[GetBattlerMultiplayerId(gActiveBattler)].gender + BACK_PIC_RED; + trainerPicId = gLinkPlayers[GetBattlerMultiplayerId(gActiveBattler)].gender + TRAINER_BACK_PIC_RED; } else if ((gLinkPlayers[GetBattlerMultiplayerId(gActiveBattler)].version & 0xFF) == VERSION_RUBY || (gLinkPlayers[GetBattlerMultiplayerId(gActiveBattler)].version & 0xFF) == VERSION_SAPPHIRE) { - trainerPicId = gLinkPlayers[GetBattlerMultiplayerId(gActiveBattler)].gender + BACK_PIC_RS_BRENDAN; + trainerPicId = gLinkPlayers[GetBattlerMultiplayerId(gActiveBattler)].gender + TRAINER_BACK_PIC_RUBY_SAPPHIRE_BRENDAN; } else { @@ -1545,12 +1546,12 @@ static void LinkPartnerHandleIntroTrainerBallThrow(void) if ((gLinkPlayers[GetBattlerMultiplayerId(gActiveBattler)].version & 0xFF) == VERSION_FIRE_RED || (gLinkPlayers[GetBattlerMultiplayerId(gActiveBattler)].version & 0xFF) == VERSION_LEAF_GREEN) { - trainerPicId = gLinkPlayers[GetBattlerMultiplayerId(gActiveBattler)].gender + BACK_PIC_RED; + trainerPicId = gLinkPlayers[GetBattlerMultiplayerId(gActiveBattler)].gender + TRAINER_BACK_PIC_RED; } else if ((gLinkPlayers[GetBattlerMultiplayerId(gActiveBattler)].version & 0xFF) == VERSION_RUBY || (gLinkPlayers[GetBattlerMultiplayerId(gActiveBattler)].version & 0xFF) == VERSION_SAPPHIRE) { - trainerPicId = gLinkPlayers[GetBattlerMultiplayerId(gActiveBattler)].gender + BACK_PIC_RS_BRENDAN; + trainerPicId = gLinkPlayers[GetBattlerMultiplayerId(gActiveBattler)].gender + TRAINER_BACK_PIC_RUBY_SAPPHIRE_BRENDAN; } else { diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index c37423a72..2af17d32e 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -16,6 +16,7 @@ #include "constants/songs.h" #include "sound.h" #include "constants/moves.h" +#include "constants/trainers.h" #include "window.h" #include "m4a.h" #include "palette.h" @@ -39,7 +40,7 @@ extern const struct CompressedSpritePalette gTrainerFrontPicPaletteTable[]; extern void sub_8172EF0(u8 battlerId, struct Pokemon *mon); extern void sub_806A068(u16, u8); extern void sub_81A57E4(u8 battlerId, u16 stringId); -extern u8 sub_81A4CB0(void); +extern u8 GetFrontierBrainTrainerPicIndex(void); extern u8 sub_81D5588(u16 trainerId); extern u8 GetFrontierTrainerFrontSpriteId(u16 trainerId); extern u8 GetEreaderTrainerFrontSpriteId(void); @@ -1234,7 +1235,7 @@ static void OpponentHandleDrawTrainerPic(void) } else if (gTrainerBattleOpponent_A == TRAINER_FRONTIER_BRAIN) { - trainerPicId = sub_81A4CB0(); + trainerPicId = GetFrontierBrainTrainerPicIndex(); } else if (gBattleTypeFlags & BATTLE_TYPE_x4000000) { @@ -1318,7 +1319,7 @@ static void OpponentHandleTrainerSlide(void) } else if (gTrainerBattleOpponent_A == TRAINER_FRONTIER_BRAIN) { - trainerPicId = sub_81A4CB0(); + trainerPicId = GetFrontierBrainTrainerPicIndex(); } else if (gBattleTypeFlags & BATTLE_TYPE_x4000000) { diff --git a/src/battle_controller_recorded_opponent.c b/src/battle_controller_recorded_opponent.c index 4b44116dd..1fd1deebf 100644 --- a/src/battle_controller_recorded_opponent.c +++ b/src/battle_controller_recorded_opponent.c @@ -13,6 +13,7 @@ #include "util.h" #include "main.h" #include "constants/songs.h" +#include "constants/trainers.h" #include "sound.h" #include "window.h" #include "m4a.h" diff --git a/src/battle_controllers.c b/src/battle_controllers.c index 4da941ab0..01ad750db 100644 --- a/src/battle_controllers.c +++ b/src/battle_controllers.c @@ -1082,14 +1082,14 @@ void BtlController_EmitMoveAnimation(u8 bufferId, u16 move, u8 turnOfMove, u16 m void BtlController_EmitPrintString(u8 bufferId, u16 stringID) { s32 i; - struct StringInfoBattle* stringInfo; + struct BattleMsgData* stringInfo; sBattleBuffersTransferData[0] = CONTROLLER_PRINTSTRING; sBattleBuffersTransferData[1] = gBattleOutcome; sBattleBuffersTransferData[2] = stringID; sBattleBuffersTransferData[3] = (stringID & 0xFF00) >> 8; - stringInfo = (struct StringInfoBattle*)(&sBattleBuffersTransferData[4]); + stringInfo = (struct BattleMsgData*)(&sBattleBuffersTransferData[4]); stringInfo->currentMove = gCurrentMove; stringInfo->originallyUsedMove = gChosenMove; stringInfo->lastItem = gLastUsedItem; @@ -1097,7 +1097,7 @@ void BtlController_EmitPrintString(u8 bufferId, u16 stringID) stringInfo->scrActive = gBattleScripting.battler; stringInfo->unk1605E = gBattleStruct->field_52; stringInfo->hpScale = gBattleStruct->hpScale; - stringInfo->StringBank = gPotentialItemEffectBattler; + stringInfo->itemEffectBattler = gPotentialItemEffectBattler; stringInfo->moveType = gBattleMoves[gCurrentMove].type; for (i = 0; i < MAX_BATTLERS_COUNT; i++) @@ -1108,20 +1108,20 @@ void BtlController_EmitPrintString(u8 bufferId, u16 stringID) stringInfo->textBuffs[1][i] = gBattleTextBuff2[i]; stringInfo->textBuffs[2][i] = gBattleTextBuff3[i]; } - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, sizeof(struct StringInfoBattle) + 4); + PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, sizeof(struct BattleMsgData) + 4); } void BtlController_EmitPrintSelectionString(u8 bufferId, u16 stringID) { s32 i; - struct StringInfoBattle *stringInfo; + struct BattleMsgData *stringInfo; sBattleBuffersTransferData[0] = CONTROLLER_PRINTSTRINGPLAYERONLY; sBattleBuffersTransferData[1] = CONTROLLER_PRINTSTRINGPLAYERONLY; sBattleBuffersTransferData[2] = stringID; sBattleBuffersTransferData[3] = (stringID & 0xFF00) >> 8; - stringInfo = (struct StringInfoBattle*)(&sBattleBuffersTransferData[4]); + stringInfo = (struct BattleMsgData*)(&sBattleBuffersTransferData[4]); stringInfo->currentMove = gCurrentMove; stringInfo->originallyUsedMove = gChosenMove; stringInfo->lastItem = gLastUsedItem; @@ -1137,7 +1137,7 @@ void BtlController_EmitPrintSelectionString(u8 bufferId, u16 stringID) stringInfo->textBuffs[1][i] = gBattleTextBuff2[i]; stringInfo->textBuffs[2][i] = gBattleTextBuff3[i]; } - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, sizeof(struct StringInfoBattle) + 4); + PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, sizeof(struct BattleMsgData) + 4); } void BtlController_EmitChooseAction(u8 bufferId, u8 arg1, u16 arg2) diff --git a/src/battle_gfx_sfx_util.c b/src/battle_gfx_sfx_util.c index 47af1b9dd..8f17d488e 100644 --- a/src/battle_gfx_sfx_util.c +++ b/src/battle_gfx_sfx_util.c @@ -70,45 +70,45 @@ static void Task_ClearBitWhenSpecialAnimDone(u8 taskId); static void ClearSpritesBattlerHealthboxAnimData(void); // const rom data -static const struct CompressedSpriteSheet gUnknown_0832C0D0 = +static const struct CompressedSpriteSheet sSpriteSheet_SinglesPlayerHealthbox = { gUnknown_08C1F1C8, 0x1000, TAG_HEALTHBOX_PLAYER1_TILE }; -static const struct CompressedSpriteSheet gUnknown_0832C0D8 = +static const struct CompressedSpriteSheet sSpriteSheet_SinglesOpponentHealthbox = { gUnknown_08C1F46C, 0x1000, TAG_HEALTHBOX_OPPONENT1_TILE }; -static const struct CompressedSpriteSheet gUnknown_0832C0E0[2] = +static const struct CompressedSpriteSheet sSpriteSheets_DoublesPlayerHealthbox[2] = { {gUnknown_08C1F5E8, 0x800, TAG_HEALTHBOX_PLAYER1_TILE}, {gUnknown_08C1F5E8, 0x800, TAG_HEALTHBOX_PLAYER2_TILE} }; -static const struct CompressedSpriteSheet gUnknown_0832C0F0[2] = +static const struct CompressedSpriteSheet sSpriteSheets_DoublesOpponentHealthbox[2] = { {gUnknown_08C1F76C, 0x800, TAG_HEALTHBOX_OPPONENT1_TILE}, {gUnknown_08C1F76C, 0x800, TAG_HEALTHBOX_OPPONENT2_TILE} }; -static const struct CompressedSpriteSheet gUnknown_0832C100 = +static const struct CompressedSpriteSheet sSpriteSheet_SafariHealthbox = { gUnknown_08C1F8E8, 0x1000, TAG_HEALTHBOX_SAFARI_TILE }; -static const struct CompressedSpriteSheet gUnknown_0832C108[MAX_BATTLERS_COUNT] = +static const struct CompressedSpriteSheet sSpriteSheets_HealthBar[MAX_BATTLERS_COUNT] = { - {gBlankGfxCompressed, 0x0100, 0xd704}, - {gBlankGfxCompressed, 0x0120, 0xd705}, - {gBlankGfxCompressed, 0x0100, 0xd706}, - {gBlankGfxCompressed, 0x0120, 0xd707} + {gBlankGfxCompressed, 0x0100, TAG_HEALTHBAR_PLAYER1_TILE}, + {gBlankGfxCompressed, 0x0120, TAG_HEALTHBAR_OPPONENT1_TILE}, + {gBlankGfxCompressed, 0x0100, TAG_HEALTHBAR_PLAYER2_TILE}, + {gBlankGfxCompressed, 0x0120, TAG_HEALTHBAR_OPPONENT2_TILE} }; -static const struct SpritePalette gUnknown_0832C128[2] = +static const struct SpritePalette sSpritePalettes_HealthBoxHealthBar[2] = { {gBattleInterface_BallStatusBarPal, TAG_HEALTHBOX_PAL}, - {gBattleInterface_BallDisplayPal, 0xd704} + {gBattleInterface_BallDisplayPal, TAG_HEALTHBAR_PAL} }; // code @@ -499,7 +499,7 @@ static void Task_ClearBitWhenSpecialAnimDone(u8 taskId) #undef tBattlerId -// great function to include newly added moves that don't have animation yet +// Great function to include newly added moves that don't have animation yet. bool8 IsMoveWithoutAnimation(u16 moveId, u8 animationTurn) { return FALSE; @@ -679,29 +679,30 @@ void FreeTrainerFrontPicPalette(u16 frontPicId) FreeSpritePaletteByTag(gTrainerFrontPicPaletteTable[frontPicId].tag); } -void sub_805DFFC(void) +// Unused. +void BattleLoadAllHealthBoxesGfxAtOnce(void) { u8 numberOfBattlers = 0; u8 i; - LoadSpritePalette(&gUnknown_0832C128[0]); - LoadSpritePalette(&gUnknown_0832C128[1]); + LoadSpritePalette(&sSpritePalettes_HealthBoxHealthBar[0]); + LoadSpritePalette(&sSpritePalettes_HealthBoxHealthBar[1]); if (!IsDoubleBattle()) { - LoadCompressedObjectPic(&gUnknown_0832C0D0); - LoadCompressedObjectPic(&gUnknown_0832C0D8); + LoadCompressedObjectPic(&sSpriteSheet_SinglesPlayerHealthbox); + LoadCompressedObjectPic(&sSpriteSheet_SinglesOpponentHealthbox); numberOfBattlers = 2; } else { - LoadCompressedObjectPic(&gUnknown_0832C0E0[0]); - LoadCompressedObjectPic(&gUnknown_0832C0E0[1]); - LoadCompressedObjectPic(&gUnknown_0832C0F0[0]); - LoadCompressedObjectPic(&gUnknown_0832C0F0[1]); + LoadCompressedObjectPic(&sSpriteSheets_DoublesPlayerHealthbox[0]); + LoadCompressedObjectPic(&sSpriteSheets_DoublesPlayerHealthbox[1]); + LoadCompressedObjectPic(&sSpriteSheets_DoublesOpponentHealthbox[0]); + LoadCompressedObjectPic(&sSpriteSheets_DoublesOpponentHealthbox[1]); numberOfBattlers = 4; } for (i = 0; i < numberOfBattlers; i++) - LoadCompressedObjectPic(&gUnknown_0832C108[gBattlerPositions[i]]); + LoadCompressedObjectPic(&sSpriteSheets_HealthBar[gBattlerPositions[i]]); } bool8 BattleLoadAllHealthBoxesGfx(u8 state) @@ -712,45 +713,45 @@ bool8 BattleLoadAllHealthBoxesGfx(u8 state) { if (state == 1) { - LoadSpritePalette(&gUnknown_0832C128[0]); - LoadSpritePalette(&gUnknown_0832C128[1]); + LoadSpritePalette(&sSpritePalettes_HealthBoxHealthBar[0]); + LoadSpritePalette(&sSpritePalettes_HealthBoxHealthBar[1]); } else if (!IsDoubleBattle()) { if (state == 2) { if (gBattleTypeFlags & BATTLE_TYPE_SAFARI) - LoadCompressedObjectPic(&gUnknown_0832C100); + LoadCompressedObjectPic(&sSpriteSheet_SafariHealthbox); else - LoadCompressedObjectPic(&gUnknown_0832C0D0); + LoadCompressedObjectPic(&sSpriteSheet_SinglesPlayerHealthbox); } else if (state == 3) - LoadCompressedObjectPic(&gUnknown_0832C0D8); + LoadCompressedObjectPic(&sSpriteSheet_SinglesOpponentHealthbox); else if (state == 4) - LoadCompressedObjectPic(&gUnknown_0832C108[gBattlerPositions[0]]); + LoadCompressedObjectPic(&sSpriteSheets_HealthBar[gBattlerPositions[0]]); else if (state == 5) - LoadCompressedObjectPic(&gUnknown_0832C108[gBattlerPositions[1]]); + LoadCompressedObjectPic(&sSpriteSheets_HealthBar[gBattlerPositions[1]]); else retVal = TRUE; } else { if (state == 2) - LoadCompressedObjectPic(&gUnknown_0832C0E0[0]); + LoadCompressedObjectPic(&sSpriteSheets_DoublesPlayerHealthbox[0]); else if (state == 3) - LoadCompressedObjectPic(&gUnknown_0832C0E0[1]); + LoadCompressedObjectPic(&sSpriteSheets_DoublesPlayerHealthbox[1]); else if (state == 4) - LoadCompressedObjectPic(&gUnknown_0832C0F0[0]); + LoadCompressedObjectPic(&sSpriteSheets_DoublesOpponentHealthbox[0]); else if (state == 5) - LoadCompressedObjectPic(&gUnknown_0832C0F0[1]); + LoadCompressedObjectPic(&sSpriteSheets_DoublesOpponentHealthbox[1]); else if (state == 6) - LoadCompressedObjectPic(&gUnknown_0832C108[gBattlerPositions[0]]); + LoadCompressedObjectPic(&sSpriteSheets_HealthBar[gBattlerPositions[0]]); else if (state == 7) - LoadCompressedObjectPic(&gUnknown_0832C108[gBattlerPositions[1]]); + LoadCompressedObjectPic(&sSpriteSheets_HealthBar[gBattlerPositions[1]]); else if (state == 8) - LoadCompressedObjectPic(&gUnknown_0832C108[gBattlerPositions[2]]); + LoadCompressedObjectPic(&sSpriteSheets_HealthBar[gBattlerPositions[2]]); else if (state == 9) - LoadCompressedObjectPic(&gUnknown_0832C108[gBattlerPositions[3]]); + LoadCompressedObjectPic(&sSpriteSheets_HealthBar[gBattlerPositions[3]]); else retVal = TRUE; } diff --git a/src/battle_interface.c b/src/battle_interface.c index 6a30ed487..a6032adc3 100644 --- a/src/battle_interface.c +++ b/src/battle_interface.c @@ -1350,7 +1350,7 @@ static void UpdateHpTextInHealthboxInDoubles(u8 healthboxSpriteId, s16 value, u8 } } -// Prints mon's nature and flee rate. Probably used to test pokeblock feeders. +// Prints mon's nature, catch and flee rate. Probably used to test pokeblock-related features. static void PrintSafariMonInfo(u8 healthboxSpriteId, struct Pokemon *mon) { u8 text[20]; @@ -1391,8 +1391,8 @@ static void PrintSafariMonInfo(u8 healthboxSpriteId, struct Pokemon *mon) } healthBarSpriteId = gSprites[healthboxSpriteId].hMain_HealthBarSpriteId; - ConvertIntToDecimalStringN(text + 6, gBattleStruct->field_7C, STR_CONV_MODE_RIGHT_ALIGN, 2); - ConvertIntToDecimalStringN(text + 9, gBattleStruct->field_7B, STR_CONV_MODE_RIGHT_ALIGN, 2); + ConvertIntToDecimalStringN(text + 6, gBattleStruct->safariCatchFactor, STR_CONV_MODE_RIGHT_ALIGN, 2); + ConvertIntToDecimalStringN(text + 9, gBattleStruct->safariEscapeFactor, STR_CONV_MODE_RIGHT_ALIGN, 2); text[5] = CHAR_SPACE; text[8] = CHAR_SLASH; RenderTextFont9(gMonSpritesGfxPtr->barFontGfx, 9, text); diff --git a/src/battle_main.c b/src/battle_main.c index dfe99e003..34558ab38 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -85,7 +85,6 @@ extern u8 gUnknown_0203CF00[]; extern const u16 gBattleTextboxPalette[]; 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[]; extern const u8 *const gBattlescriptsForRunningByItem[]; @@ -308,6 +307,9 @@ u8 gUnknown_03005D7C[MAX_BATTLERS_COUNT]; // 10 is ×1.0 TYPE_MUL_NORMAL // 05 is ×0.5 TYPE_MUL_NOT_EFFECTIVE // 00 is ×0.0 TYPE_MUL_NO_EFFECT + +static const s8 gUnknown_0831ACE0[] ={-32, -16, -16, -32, -32, 0, 0, 0}; + const u8 gTypeEffectiveness[336] = { TYPE_NORMAL, TYPE_ROCK, TYPE_MUL_NOT_EFFECTIVE, @@ -561,9 +563,9 @@ const u8 * const gStatusConditionStringsTable[7][2] = {gStatusConditionString_LoveJpn, gText_Love} }; -static const u8 sUnknown_0831BCE0[][3] = {{0, 0, 0}, {3, 5, 0}, {2, 3, 0}, {1, 2, 0}, {1, 1, 0}}; -static const u8 sUnknown_0831BCEF[] = {4, 3, 2, 1}; -static const u8 sUnknown_0831BCF3[] = {4, 4, 4, 4}; +static const u8 sPkblToEscapeFactor[][3] = {{0, 0, 0}, {3, 5, 0}, {2, 3, 0}, {1, 2, 0}, {1, 1, 0}}; +static const u8 sGoNearCounterToCatchFactor[] = {4, 3, 2, 1}; +static const u8 sGoNearCounterToEscapeFactor[] = {4, 4, 4, 4}; // code void CB2_InitBattle(void) @@ -1805,7 +1807,7 @@ static void CB2_HandleStartMultiBattle(void) SetMainCallback2(BattleMainCB2); if (gBattleTypeFlags & BATTLE_TYPE_LINK) { - gTrainerBattleOpponent_A = TRAINER_OPPONENT_800; + gTrainerBattleOpponent_A = TRAINER_LINK_OPPONENT; gBattleTypeFlags |= BATTLE_TYPE_20; } } @@ -3051,10 +3053,10 @@ static void BattleStartClearSetData(void) gLeveledUpInBattle = 0; gAbsentBattlerFlags = 0; gBattleStruct->runTries = 0; - gBattleStruct->field_79 = 0; - gBattleStruct->field_7A = 0; - *(&gBattleStruct->field_7C) = gBaseStats[GetMonData(&gEnemyParty[0], MON_DATA_SPECIES)].catchRate * 100 / 1275; - gBattleStruct->field_7B = 3; + gBattleStruct->safariGoNearCounter = 0; + gBattleStruct->safariPkblThrowCounter = 0; + *(&gBattleStruct->safariCatchFactor) = gBaseStats[GetMonData(&gEnemyParty[0], MON_DATA_SPECIES)].catchRate * 100 / 1275; + gBattleStruct->safariEscapeFactor = 3; gBattleStruct->wildVictorySong = 0; gBattleStruct->moneyMultiplier = 1; @@ -5746,14 +5748,14 @@ static void HandleAction_ThrowPokeblock(void) if (gBattleResults.pokeblockThrows < 0xFF) gBattleResults.pokeblockThrows++; - if (gBattleStruct->field_7A < 3) - gBattleStruct->field_7A++; - if (gBattleStruct->field_7B > 1) + if (gBattleStruct->safariPkblThrowCounter < 3) + gBattleStruct->safariPkblThrowCounter++; + if (gBattleStruct->safariEscapeFactor > 1) { - if (gBattleStruct->field_7B < sUnknown_0831BCE0[gBattleStruct->field_7A][gBattleCommunication[MULTISTRING_CHOOSER]]) - gBattleStruct->field_7B = 1; + if (gBattleStruct->safariEscapeFactor < sPkblToEscapeFactor[gBattleStruct->safariPkblThrowCounter][gBattleCommunication[MULTISTRING_CHOOSER]]) + gBattleStruct->safariEscapeFactor = 1; else - gBattleStruct->field_7B -= sUnknown_0831BCE0[gBattleStruct->field_7A][gBattleCommunication[MULTISTRING_CHOOSER]]; + gBattleStruct->safariEscapeFactor -= sPkblToEscapeFactor[gBattleStruct->safariPkblThrowCounter][gBattleCommunication[MULTISTRING_CHOOSER]]; } gBattlescriptCurrInstr = gBattlescriptsForSafariActions[2]; @@ -5766,22 +5768,22 @@ static void HandleAction_GoNear(void) gBattle_BG0_X = 0; gBattle_BG0_Y = 0; - gBattleStruct->field_7C += sUnknown_0831BCEF[gBattleStruct->field_79]; - if (gBattleStruct->field_7C > 20) - gBattleStruct->field_7C = 20; + gBattleStruct->safariCatchFactor += sGoNearCounterToCatchFactor[gBattleStruct->safariGoNearCounter]; + if (gBattleStruct->safariCatchFactor > 20) + gBattleStruct->safariCatchFactor = 20; - gBattleStruct->field_7B +=sUnknown_0831BCF3[gBattleStruct->field_79]; - if (gBattleStruct->field_7B > 20) - gBattleStruct->field_7B = 20; + gBattleStruct->safariEscapeFactor += sGoNearCounterToEscapeFactor[gBattleStruct->safariGoNearCounter]; + if (gBattleStruct->safariEscapeFactor > 20) + gBattleStruct->safariEscapeFactor = 20; - if (gBattleStruct->field_79 < 3) + if (gBattleStruct->safariGoNearCounter < 3) { - gBattleStruct->field_79++; + gBattleStruct->safariGoNearCounter++; gBattleCommunication[MULTISTRING_CHOOSER] = 0; } else { - gBattleCommunication[MULTISTRING_CHOOSER] = 1; + gBattleCommunication[MULTISTRING_CHOOSER] = 1; // Can't get closer. } gBattlescriptCurrInstr = gBattlescriptsForSafariActions[1]; gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; diff --git a/src/battle_message.c b/src/battle_message.c index d2ac6da8c..7d442ea98 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -6,6 +6,7 @@ #include "text.h" #include "string_util.h" #include "constants/items.h" +#include "constants/trainers.h" #include "event_data.h" #include "link.h" #include "item.h" @@ -2074,7 +2075,7 @@ void BufferStringBattle(u16 stringID) } else { - if (gTrainerBattleOpponent_A == TRAINER_OPPONENT_800 || gBattleTypeFlags & BATTLE_TYPE_x2000000) + if (gTrainerBattleOpponent_A == TRAINER_LINK_OPPONENT || gBattleTypeFlags & BATTLE_TYPE_x2000000) { if (gBattleTypeFlags & BATTLE_TYPE_MULTI) stringPtr = sText_LinkTrainer2WithdrewPkmn; diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 9c48b083c..bacaf2bac 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -3111,7 +3111,7 @@ static void atk1E_jumpifability(void) if (gBattlescriptCurrInstr[1] == BS_ATTACKER_SIDE) { - battlerId = AbilityBattleEffects(ABILITYEFFECT_CHECK_BANK_SIDE, gBattlerAttacker, ability, 0, 0); + battlerId = AbilityBattleEffects(ABILITYEFFECT_CHECK_BATTLER_SIDE, gBattlerAttacker, ability, 0, 0); if (battlerId) { gLastUsedAbility = ability; @@ -5033,7 +5033,7 @@ static void atk4F_jumpifcantswitch(void) party = gPlayerParty; i = 0; - if (sub_806D82C(GetBattlerMultiplayerId(gActiveBattler)) == TRUE) + if (GetLinkTrainerFlankId(GetBattlerMultiplayerId(gActiveBattler)) == TRUE) i = 3; } else @@ -5054,7 +5054,7 @@ static void atk4F_jumpifcantswitch(void) party = gPlayerParty; i = 0; - if (sub_806D82C(GetBattlerMultiplayerId(gActiveBattler)) == TRUE) + if (GetLinkTrainerFlankId(GetBattlerMultiplayerId(gActiveBattler)) == TRUE) i = 3; } @@ -5166,7 +5166,7 @@ static void atk50_openpartyscreen(void) { if (gHitMarker & HITMARKER_FAINTED(gActiveBattler)) { - if (sub_80423F4(gActiveBattler, 6, 6)) + if (HasNoMonsToSwitch(gActiveBattler, 6, 6)) { gAbsentBattlerFlags |= gBitTable[gActiveBattler]; gHitMarker &= ~(HITMARKER_FAINTED(gActiveBattler)); @@ -5195,7 +5195,7 @@ static void atk50_openpartyscreen(void) if (gBitTable[0] & hitmarkerFaintBits) { gActiveBattler = 0; - if (sub_80423F4(0, 6, 6)) + if (HasNoMonsToSwitch(0, 6, 6)) { gAbsentBattlerFlags |= gBitTable[gActiveBattler]; gHitMarker &= ~(HITMARKER_FAINTED(gActiveBattler)); @@ -5217,7 +5217,7 @@ static void atk50_openpartyscreen(void) if (gBitTable[2] & hitmarkerFaintBits && !(gBitTable[0] & hitmarkerFaintBits)) { gActiveBattler = 2; - if (sub_80423F4(2, 6, 6)) + if (HasNoMonsToSwitch(2, 6, 6)) { gAbsentBattlerFlags |= gBitTable[gActiveBattler]; gHitMarker &= ~(HITMARKER_FAINTED(gActiveBattler)); @@ -5238,7 +5238,7 @@ static void atk50_openpartyscreen(void) if (gBitTable[1] & hitmarkerFaintBits) { gActiveBattler = 1; - if (sub_80423F4(1, 6, 6)) + if (HasNoMonsToSwitch(1, 6, 6)) { gAbsentBattlerFlags |= gBitTable[gActiveBattler]; gHitMarker &= ~(HITMARKER_FAINTED(gActiveBattler)); @@ -5260,7 +5260,7 @@ static void atk50_openpartyscreen(void) if (gBitTable[3] & hitmarkerFaintBits && !(gBitTable[1] & hitmarkerFaintBits)) { gActiveBattler = 3; - if (sub_80423F4(3, 6, 6)) + if (HasNoMonsToSwitch(3, 6, 6)) { gAbsentBattlerFlags |= gBitTable[gActiveBattler]; gHitMarker &= ~(HITMARKER_FAINTED(gActiveBattler)); @@ -5323,7 +5323,7 @@ static void atk50_openpartyscreen(void) if (gBitTable[2] & hitmarkerFaintBits && gBitTable[0] & hitmarkerFaintBits) { gActiveBattler = 2; - if (sub_80423F4(2, gBattleBufferB[0][1], 6)) + if (HasNoMonsToSwitch(2, gBattleBufferB[0][1], 6)) { gAbsentBattlerFlags |= gBitTable[gActiveBattler]; gHitMarker &= ~(HITMARKER_FAINTED(gActiveBattler)); @@ -5339,7 +5339,7 @@ static void atk50_openpartyscreen(void) if (gBitTable[3] & hitmarkerFaintBits && hitmarkerFaintBits & gBitTable[1]) { gActiveBattler = 3; - if (sub_80423F4(3, gBattleBufferB[1][1], 6)) + if (HasNoMonsToSwitch(3, gBattleBufferB[1][1], 6)) { gAbsentBattlerFlags |= gBitTable[gActiveBattler]; gHitMarker &= ~(HITMARKER_FAINTED(gActiveBattler)); @@ -5391,7 +5391,7 @@ static void atk50_openpartyscreen(void) { gBattlescriptCurrInstr += 6; } - else if (sub_80423F4(battlerId, 6, 6)) + else if (HasNoMonsToSwitch(battlerId, 6, 6)) { gActiveBattler = battlerId; gAbsentBattlerFlags |= gBitTable[gActiveBattler]; @@ -7506,7 +7506,7 @@ static void atk8F_forcerandomswitch(void) else if ((gBattleTypeFlags & BATTLE_TYPE_MULTI && gBattleTypeFlags & BATTLE_TYPE_LINK) || (gBattleTypeFlags & BATTLE_TYPE_MULTI && gBattleTypeFlags & BATTLE_TYPE_x2000000)) { - if (sub_806D82C(GetBattlerMultiplayerId(gBattlerTarget)) == 1) + if (GetLinkTrainerFlankId(GetBattlerMultiplayerId(gBattlerTarget)) == 1) { firstMonId = 3; lastMonId = 6; @@ -9044,7 +9044,7 @@ static void atkBE_rapidspinfree(void) else if (gStatuses3[gBattlerAttacker] & STATUS3_LEECHSEED) { gStatuses3[gBattlerAttacker] &= ~(STATUS3_LEECHSEED); - gStatuses3[gBattlerAttacker] &= ~(STATUS3_LEECHSEED_BANK); + gStatuses3[gBattlerAttacker] &= ~(STATUS3_LEECHSEED_BATTLER); BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_LeechSeedFree; } @@ -9760,7 +9760,7 @@ static void atkE1_trygetintimidatetarget(void) { u8 side; - gBattleScripting.battler = gBattleStruct->intimidateBank; + gBattleScripting.battler = gBattleStruct->intimidateBattler; side = GetBattlerSide(gBattleScripting.battler); PREPARE_ABILITY_BUFFER(gBattleTextBuff1, gBattleMons[gBattleScripting.battler].ability) @@ -10115,7 +10115,7 @@ static void atkEF_handleballthrow(void) u8 catchRate; if (gLastUsedItem == ITEM_SAFARI_BALL) - catchRate = gBattleStruct->field_7C * 1275 / 100; + catchRate = gBattleStruct->safariCatchFactor * 1275 / 100; else catchRate = gBaseStats[gBattleMons[gBattlerTarget].species].catchRate; diff --git a/src/battle_tv.c b/src/battle_tv.c index cd0490a1b..6f9ee414e 100644 --- a/src/battle_tv.c +++ b/src/battle_tv.c @@ -796,8 +796,8 @@ void TryPutLinkBattleTvShowOnAir(void) if (gBattleTypeFlags & BATTLE_TYPE_MULTI) { - if ((playerBestMonId < 3 && !sub_806D82C(gBattleScripting.multiplayerId)) - || (playerBestMonId >= 3 && sub_806D82C(gBattleScripting.multiplayerId))) + if ((playerBestMonId < 3 && !GetLinkTrainerFlankId(gBattleScripting.multiplayerId)) + || (playerBestMonId >= 3 && GetLinkTrainerFlankId(gBattleScripting.multiplayerId))) { j = (opponentBestMonId < 3) ? 0 : 1; PutBattleUpdateOnTheAir(sub_806EF84(j, gBattleScripting.multiplayerId), moveId, playerBestSpecies, opponentBestSpecies); @@ -1078,7 +1078,7 @@ _0817E5C8:\n\ ldr r0, =gBattleScripting\n\ adds r0, 0x25\n\ ldrb r0, [r0]\n\ - bl sub_806D82C\n\ + bl GetLinkTrainerFlankId\n\ lsls r0, 16\n\ cmp r0, 0\n\ beq _0817E630\n\ @@ -1088,7 +1088,7 @@ _0817E620:\n\ ldr r0, =gBattleScripting\n\ adds r0, 0x25\n\ ldrb r0, [r0]\n\ - bl sub_806D82C\n\ + bl GetLinkTrainerFlankId\n\ lsls r0, 16\n\ cmp r0, 0\n\ beq _0817E670\n\ diff --git a/src/battle_util.c b/src/battle_util.c index b9a7f546a..5d2ec62a9 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -46,7 +46,7 @@ u8 GetBattlerForBattleScript(u8 caseId) case BS_EFFECT_BATTLER: ret = gEffectBattler; break; - case BS_BANK_0: + case BS_BATTLER_0: ret = 0; break; case BS_SCRIPTING: @@ -292,7 +292,7 @@ void sub_803FA70(u8 battler) } } -void BattleScriptPush(const u8* bsPtr) +void BattleScriptPush(const u8 *bsPtr) { gBattleResources->battleScriptsStack->ptr[gBattleResources->battleScriptsStack->size++] = bsPtr; } @@ -453,7 +453,7 @@ bool8 AreAllMovesUnusable(void) u8 unusable; unusable = CheckMoveLimitations(gActiveBattler, 0, 0xFF); - if (unusable == 0xF) // all moves are unusable + if (unusable == 0xF) // All moves are unusable. { gProtectStructs[gActiveBattler].onlyStruggle = 1; gSelectionBattleScripts[gActiveBattler] = BattleScript_NoMovesLeft; @@ -470,11 +470,11 @@ u8 GetImprisonedMovesCount(u8 battlerId, u16 move) { s32 i; u8 imprisionedMoves = 0; - u8 bankSide = GetBattlerSide(battlerId); + u8 BattlerSide = GetBattlerSide(battlerId); for (i = 0; i < gBattlersCount; i++) { - if (bankSide != GetBattlerSide(i) && gStatuses3[i] & STATUS3_IMPRISONED_OTHERS) + if (BattlerSide != GetBattlerSide(i) && gStatuses3[i] & STATUS3_IMPRISONED_OTHERS) { s32 j; for (j = 0; j < 4; j++) @@ -504,7 +504,7 @@ u8 UpdateTurnCounters(void) do { - u8 sideBank; + u8 side; switch (gBattleStruct->turnCountersTracker) { @@ -533,13 +533,13 @@ u8 UpdateTurnCounters(void) case 1: while (gBattleStruct->turnSideTracker < 2) { - sideBank = gBattleStruct->turnSideTracker; - gActiveBattler = gBattlerAttacker = gSideTimers[sideBank].reflectBattlerId; - if (gSideStatuses[sideBank] & SIDE_STATUS_REFLECT) + side = gBattleStruct->turnSideTracker; + gActiveBattler = gBattlerAttacker = gSideTimers[side].reflectBattlerId; + if (gSideStatuses[side] & SIDE_STATUS_REFLECT) { - if (--gSideTimers[sideBank].reflectTimer == 0) + if (--gSideTimers[side].reflectTimer == 0) { - gSideStatuses[sideBank] &= ~SIDE_STATUS_REFLECT; + gSideStatuses[side] &= ~SIDE_STATUS_REFLECT; BattleScriptExecute(BattleScript_SideStatusWoreOff); PREPARE_MOVE_BUFFER(gBattleTextBuff1, MOVE_REFLECT); effect++; @@ -558,15 +558,15 @@ u8 UpdateTurnCounters(void) case 2: while (gBattleStruct->turnSideTracker < 2) { - sideBank = gBattleStruct->turnSideTracker; - gActiveBattler = gBattlerAttacker = gSideTimers[sideBank].lightscreenBattlerId; - if (gSideStatuses[sideBank] & SIDE_STATUS_LIGHTSCREEN) + side = gBattleStruct->turnSideTracker; + gActiveBattler = gBattlerAttacker = gSideTimers[side].lightscreenBattlerId; + if (gSideStatuses[side] & SIDE_STATUS_LIGHTSCREEN) { - if (--gSideTimers[sideBank].lightscreenTimer == 0) + if (--gSideTimers[side].lightscreenTimer == 0) { - gSideStatuses[sideBank] &= ~SIDE_STATUS_LIGHTSCREEN; + gSideStatuses[side] &= ~SIDE_STATUS_LIGHTSCREEN; BattleScriptExecute(BattleScript_SideStatusWoreOff); - gBattleCommunication[MULTISTRING_CHOOSER] = sideBank; + gBattleCommunication[MULTISTRING_CHOOSER] = side; PREPARE_MOVE_BUFFER(gBattleTextBuff1, MOVE_LIGHT_SCREEN); effect++; } @@ -584,14 +584,14 @@ u8 UpdateTurnCounters(void) case 3: while (gBattleStruct->turnSideTracker < 2) { - sideBank = gBattleStruct->turnSideTracker; - gActiveBattler = gBattlerAttacker = gSideTimers[sideBank].mistBattlerId; - if (gSideTimers[sideBank].mistTimer != 0 - && --gSideTimers[sideBank].mistTimer == 0) + side = gBattleStruct->turnSideTracker; + gActiveBattler = gBattlerAttacker = gSideTimers[side].mistBattlerId; + if (gSideTimers[side].mistTimer != 0 + && --gSideTimers[side].mistTimer == 0) { - gSideStatuses[sideBank] &= ~SIDE_STATUS_MIST; + gSideStatuses[side] &= ~SIDE_STATUS_MIST; BattleScriptExecute(BattleScript_SideStatusWoreOff); - gBattleCommunication[MULTISTRING_CHOOSER] = sideBank; + gBattleCommunication[MULTISTRING_CHOOSER] = side; PREPARE_MOVE_BUFFER(gBattleTextBuff1, MOVE_MIST); effect++; } @@ -608,13 +608,13 @@ u8 UpdateTurnCounters(void) case 4: while (gBattleStruct->turnSideTracker < 2) { - sideBank = gBattleStruct->turnSideTracker; - gActiveBattler = gBattlerAttacker = gSideTimers[sideBank].safeguardBattlerId; - if (gSideStatuses[sideBank] & SIDE_STATUS_SAFEGUARD) + side = gBattleStruct->turnSideTracker; + gActiveBattler = gBattlerAttacker = gSideTimers[side].safeguardBattlerId; + if (gSideStatuses[side] & SIDE_STATUS_SAFEGUARD) { - if (--gSideTimers[sideBank].safeguardTimer == 0) + if (--gSideTimers[side].safeguardTimer == 0) { - gSideStatuses[sideBank] &= ~SIDE_STATUS_SAFEGUARD; + gSideStatuses[side] &= ~SIDE_STATUS_SAFEGUARD; BattleScriptExecute(BattleScript_SafeguardEnds); effect++; } @@ -795,10 +795,10 @@ u8 TurnBasedEffects(void) break; case 3: // leech seed if ((gStatuses3[gActiveBattler] & STATUS3_LEECHSEED) - && gBattleMons[gStatuses3[gActiveBattler] & STATUS3_LEECHSEED_BANK].hp != 0 + && gBattleMons[gStatuses3[gActiveBattler] & STATUS3_LEECHSEED_BATTLER].hp != 0 && gBattleMons[gActiveBattler].hp != 0) { - gBattlerTarget = gStatuses3[gActiveBattler] & STATUS3_LEECHSEED_BANK; //funny how the 'target' is actually the battlerId that receives HP + gBattlerTarget = gStatuses3[gActiveBattler] & STATUS3_LEECHSEED_BATTLER; // Notice gBattlerTarget is actually the HP receiver. gBattleMoveDamage = gBattleMons[gActiveBattler].maxHP / 8; if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; @@ -848,8 +848,8 @@ u8 TurnBasedEffects(void) case 7: // spooky nightmares if ((gBattleMons[gActiveBattler].status2 & STATUS2_NIGHTMARE) && gBattleMons[gActiveBattler].hp != 0) { - // R/S does not perform this sleep check, which causes the nighmare effect to - // persist even after the affected Pokemon has been awakened by Shed Skin + // R/S does not perform this sleep check, which causes the nightmare effect to + // persist even after the affected Pokemon has been awakened by Shed Skin. if (gBattleMons[gActiveBattler].status1 & STATUS1_SLEEP) { gBattleMoveDamage = gBattleMons[gActiveBattler].maxHP / 4; @@ -983,7 +983,7 @@ u8 TurnBasedEffects(void) case 12: // disable if (gDisableStructs[gActiveBattler].disableTimer1 != 0) { - int i; + s32 i; for (i = 0; i < 4; i++) { if (gDisableStructs[gActiveBattler].disabledMove == gBattleMons[gActiveBattler].moves[i]) @@ -1184,7 +1184,7 @@ bool8 HandleFaintedMonActions(void) return FALSE; do { - int i; + s32 i; switch (gBattleStruct->faintedActionsState) { case 0: @@ -1192,7 +1192,7 @@ bool8 HandleFaintedMonActions(void) gBattleStruct->faintedActionsState++; for (i = 0; i < gBattlersCount; i++) { - if (gAbsentBattlerFlags & gBitTable[i] && !sub_80423F4(i, 6, 6)) + if (gAbsentBattlerFlags & gBitTable[i] && !HasNoMonsToSwitch(i, 6, 6)) gAbsentBattlerFlags &= ~(gBitTable[i]); } // fall through @@ -1256,7 +1256,7 @@ bool8 HandleFaintedMonActions(void) void TryClearRageStatuses(void) { - int i; + s32 i; for (i = 0; i < gBattlersCount; i++) { if ((gBattleMons[i].status2 & STATUS2_RAGE) && gChosenMoveByBattler[i] != MOVE_RAGE) @@ -1467,7 +1467,9 @@ u8 AtkCanceller_UnableToUseMove(void) { gBattleScripting.battler = CountTrailingZeroBits((gBattleMons[gBattlerAttacker].status2 & STATUS2_INFATUATION) >> 0x10); if (Random() & 1) + { BattleScriptPushCursor(); + } else { BattleScriptPush(BattleScript_MoveUsedIsParalyzedCantAttack); @@ -1485,7 +1487,9 @@ u8 AtkCanceller_UnableToUseMove(void) { gBattleMons[gBattlerAttacker].status2 -= 0x100; if (gBattleMons[gBattlerAttacker].status2 & STATUS2_BIDE) + { gBattlescriptCurrInstr = BattleScript_BideStoringEnergy; + } else { // This is removed in Emerald for some reason @@ -1500,7 +1504,9 @@ u8 AtkCanceller_UnableToUseMove(void) gBattlescriptCurrInstr = BattleScript_BideAttack; } else + { gBattlescriptCurrInstr = BattleScript_BideNoEnergyToAttack; + } } effect = 1; } @@ -1535,29 +1541,31 @@ u8 AtkCanceller_UnableToUseMove(void) return effect; } -bool8 sub_80423F4(u8 battler, u8 r1, u8 r2) +bool8 HasNoMonsToSwitch(u8 battler, u8 partyIdBattlerOn1, u8 partyIdBattlerOn2) { - struct Pokemon* party; - u8 r7; - u8 r6; + struct Pokemon *party; + u8 id1, id2; s32 i; + if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) return FALSE; + if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) { if (GetBattlerSide(battler) == B_SIDE_PLAYER) party = gPlayerParty; else party = gEnemyParty; - r6 = ((battler & 2) / 2); - for (i = r6 * 3; i < r6 * 3 + 3; i++) + + id1 = ((battler & BIT_FLANK) / 2); + for (i = id1 * 3; i < id1 * 3 + 3; i++) { if (GetMonData(&party[i], MON_DATA_HP) != 0 - && GetMonData(&party[i], MON_DATA_SPECIES2) != 0 + && GetMonData(&party[i], MON_DATA_SPECIES2) != SPECIES_NONE && GetMonData(&party[i], MON_DATA_SPECIES2) != SPECIES_EGG) break; } - return (i == r6 * 3 + 3); + return (i == id1 * 3 + 3); } else if (gBattleTypeFlags & BATTLE_TYPE_MULTI) { @@ -1566,86 +1574,95 @@ bool8 sub_80423F4(u8 battler, u8 r1, u8 r2) if (GetBattlerSide(battler) == B_SIDE_PLAYER) { party = gPlayerParty; - r7 = GetBattlerMultiplayerId(battler); - r6 = sub_806D82C(r7); + id2 = GetBattlerMultiplayerId(battler); + id1 = GetLinkTrainerFlankId(id2); } else { - // FIXME: Compiler insists on moving r4 into r1 before doing the eor + // FIXME: Compiler insists on moving r4 into r1 before doing the eor. #ifndef NONMATCHING - register u32 var asm("r1"); + register u32 var asm("r1"); #else - u32 var; + u32 var; #endif // NONMATCHING party = gEnemyParty; - var = battler ^ 1; - r6 = (var != 0) ? 1 : 0; + var = battler ^ BIT_SIDE; + if (var == 0) + id1 = 0; + else + id1 = 1; } } else { - r7 = GetBattlerMultiplayerId(battler); + id2 = GetBattlerMultiplayerId(battler); + if (GetBattlerSide(battler) == B_SIDE_PLAYER) party = gPlayerParty; else party = gEnemyParty; - r6 = sub_806D82C(r7); + + id1 = GetLinkTrainerFlankId(id2); } - for (i = r6 * 3; i < r6 * 3 + 3; i++) + + for (i = id1 * 3; i < id1 * 3 + 3; i++) { if (GetMonData(&party[i], MON_DATA_HP) != 0 - && GetMonData(&party[i], MON_DATA_SPECIES2) != 0 + && GetMonData(&party[i], MON_DATA_SPECIES2) != SPECIES_NONE && GetMonData(&party[i], MON_DATA_SPECIES2) != SPECIES_EGG) break; } - return (i == r6 * 3 + 3); + return (i == id1 * 3 + 3); } else if ((gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS) && GetBattlerSide(battler) == B_SIDE_OPPONENT) { party = gEnemyParty; if (battler == 1) - r6 = 0; + id1 = 0; else - r6 = 3; - for (i = r6; i < r6 + 3; i++) + id1 = 3; + + for (i = id1; i < id1 + 3; i++) { if (GetMonData(&party[i], MON_DATA_HP) != 0 - && GetMonData(&party[i], MON_DATA_SPECIES2) != 0 + && GetMonData(&party[i], MON_DATA_SPECIES2) != SPECIES_NONE && GetMonData(&party[i], MON_DATA_SPECIES2) != SPECIES_EGG) break; } - return (i == r6 + 3); + return (i == id1 + 3); } else { if (GetBattlerSide(battler) == B_SIDE_OPPONENT) { - r7 = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); - r6 = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT); + id2 = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); + id1 = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT); party = gEnemyParty; } else { - r7 = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); - r6 = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT); + id2 = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); + id1 = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT); party = gPlayerParty; } - if (r1 == 6) - r1 = gBattlerPartyIndexes[r7]; - if (r2 == 6) - r2 = gBattlerPartyIndexes[r6]; - for (i = 0; i < 6; i++) + + if (partyIdBattlerOn1 == PARTY_SIZE) + partyIdBattlerOn1 = gBattlerPartyIndexes[id2]; + if (partyIdBattlerOn2 == PARTY_SIZE) + partyIdBattlerOn2 = gBattlerPartyIndexes[id1]; + + for (i = 0; i < PARTY_SIZE; i++) { if (GetMonData(&party[i], MON_DATA_HP) != 0 - && GetMonData(&party[i], MON_DATA_SPECIES2) != 0 + && GetMonData(&party[i], MON_DATA_SPECIES2) != SPECIES_NONE && GetMonData(&party[i], MON_DATA_SPECIES2) != SPECIES_EGG - // FIXME: Using index[array] instead of array[index] is BAD! - && i != r1 && i != r2 && i != r7[gBattleStruct->monToSwitchIntoId] && i != r6[gBattleStruct->monToSwitchIntoId]) + && i != partyIdBattlerOn1 && i != partyIdBattlerOn2 + && i != *(gBattleStruct->monToSwitchIntoId + id2) && i != id1[gBattleStruct->monToSwitchIntoId]) break; } - return (i == 6); + return (i == PARTY_SIZE); } } @@ -1706,6 +1723,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u8 ability, u8 special, u16 moveA if (gBattlerAttacker >= gBattlersCount) gBattlerAttacker = battler; + if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) pokeAtk = &gPlayerParty[gBattlerPartyIndexes[gBattlerAttacker]]; else @@ -1713,6 +1731,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u8 ability, u8 special, u16 moveA if (gBattlerTarget >= gBattlersCount) gBattlerTarget = battler; + if (GetBattlerSide(gBattlerTarget) == B_SIDE_PLAYER) pokeDef = &gPlayerParty[gBattlerPartyIndexes[gBattlerTarget]]; else @@ -1724,7 +1743,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u8 ability, u8 special, u16 moveA speciesDef = GetMonData(pokeDef, MON_DATA_SPECIES); pidDef = GetMonData(pokeDef, MON_DATA_PERSONALITY); - if (!(gBattleTypeFlags & BATTLE_TYPE_SAFARI)) // why isn't that check done at the beginning? + if (!(gBattleTypeFlags & BATTLE_TYPE_SAFARI)) // Why isn't that check done at the beginning? { u8 moveType; s32 i; @@ -2271,7 +2290,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u8 ability, u8 special, u16 moveA gLastUsedAbility = ABILITY_INTIMIDATE; gStatuses3[i] &= ~(STATUS3_INTIMIDATE_POKES); BattleScriptPushCursorAndCallback(BattleScript_82DB4B8); - gBattleStruct->intimidateBank = i; + gBattleStruct->intimidateBattler = i; effect++; break; } @@ -2343,7 +2362,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u8 ability, u8 special, u16 moveA gStatuses3[i] &= ~(STATUS3_INTIMIDATE_POKES); BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_82DB4C1; - gBattleStruct->intimidateBank = i; + gBattleStruct->intimidateBattler = i; effect++; break; } @@ -2360,7 +2379,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u8 ability, u8 special, u16 moveA } } break; - case ABILITYEFFECT_CHECK_BANK_SIDE: // 13 + case ABILITYEFFECT_CHECK_BATTLER_SIDE: // 13 side = GetBattlerSide(battler); for (i = 0; i < gBattlersCount; i++) { @@ -2410,7 +2429,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u8 ability, u8 special, u16 moveA } } break; - case ABILITYEFFECT_CHECK_FIELD_EXCEPT_BANK: // 15 + case ABILITYEFFECT_CHECK_FIELD_EXCEPT_BATTLER: // 15 for (i = 0; i < gBattlersCount; i++) { if (gBattleMons[i].ability == ability && i != battler) @@ -2431,7 +2450,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u8 ability, u8 special, u16 moveA } } break; - case ABILITYEFFECT_COUNT_BANK_SIDE: // 17 + case ABILITYEFFECT_COUNT_BATTLER_SIDE: // 17 side = GetBattlerSide(battler); for (i = 0; i < gBattlersCount; i++) { @@ -2492,20 +2511,20 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) int i = 0; u8 effect = ITEM_NO_EFFECT; u8 changedPP = 0; - u8 bankHoldEffect, atkHoldEffect, defHoldEffect; - u8 bankQuality, atkQuality, defQuality; + u8 BattlerHoldEffect, atkHoldEffect, defHoldEffect; + u8 BattlerQuality, atkQuality, defQuality; u16 atkItem, defItem; gLastUsedItem = gBattleMons[battlerId].item; if (gLastUsedItem == ITEM_ENIGMA_BERRY) { - bankHoldEffect = gEnigmaBerries[battlerId].holdEffect; - bankQuality = gEnigmaBerries[battlerId].holdEffectParam; + BattlerHoldEffect = gEnigmaBerries[battlerId].holdEffect; + BattlerQuality = gEnigmaBerries[battlerId].holdEffectParam; } else { - bankHoldEffect = ItemId_GetHoldEffect(gLastUsedItem); - bankQuality = ItemId_GetHoldEffectParam(gLastUsedItem); + BattlerHoldEffect = ItemId_GetHoldEffect(gLastUsedItem); + BattlerQuality = ItemId_GetHoldEffectParam(gLastUsedItem); } atkItem = gBattleMons[gBattlerAttacker].item; @@ -2536,7 +2555,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) switch (caseID) { case ITEMEFFECT_ON_SWITCH_IN: - switch (bankHoldEffect) + switch (BattlerHoldEffect) { case HOLD_EFFECT_DOUBLE_PRIZE: if (GetBattlerSide(battlerId) == B_SIDE_PLAYER) @@ -2564,13 +2583,13 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) case 1: if (gBattleMons[battlerId].hp) { - switch (bankHoldEffect) + switch (BattlerHoldEffect) { case HOLD_EFFECT_RESTORE_HP: if (gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / 2 && !moveTurn) { - gBattleMoveDamage = bankQuality; - if (gBattleMons[battlerId].hp + bankQuality > gBattleMons[battlerId].maxHP) + gBattleMoveDamage = BattlerQuality; + if (gBattleMons[battlerId].hp + BattlerQuality > gBattleMons[battlerId].maxHP) gBattleMoveDamage = gBattleMons[battlerId].maxHP - gBattleMons[battlerId].hp; gBattleMoveDamage *= -1; BattleScriptExecute(BattleScript_ItemHealHP_RemoveItem); @@ -2599,10 +2618,10 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) if (i != 4) { u8 maxPP = CalculatePPWithBonus(move, ppBonuses, i); - if (changedPP + bankQuality > maxPP) + if (changedPP + BattlerQuality > maxPP) changedPP = maxPP; else - changedPP = changedPP + bankQuality; + changedPP = changedPP + BattlerQuality; PREPARE_MOVE_BUFFER(gBattleTextBuff1, move); @@ -2641,7 +2660,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) gBattleMoveDamage *= -1; BattleScriptExecute(BattleScript_ItemHealHP_End2); effect = ITEM_HP_CHANGE; - RecordItemEffectBattle(battlerId, bankHoldEffect); + RecordItemEffectBattle(battlerId, BattlerHoldEffect); } break; // nice copy/paste there gamefreak, making a function for confuse berries was too much eh? @@ -2650,7 +2669,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) { PREPARE_FLAVOR_BUFFER(gBattleTextBuff1, FLAVOR_SPICY); - gBattleMoveDamage = gBattleMons[battlerId].maxHP / bankQuality; + gBattleMoveDamage = gBattleMons[battlerId].maxHP / BattlerQuality; if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; if (gBattleMons[battlerId].hp + gBattleMoveDamage > gBattleMons[battlerId].maxHP) @@ -2668,7 +2687,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) { PREPARE_FLAVOR_BUFFER(gBattleTextBuff1, FLAVOR_DRY); - gBattleMoveDamage = gBattleMons[battlerId].maxHP / bankQuality; + gBattleMoveDamage = gBattleMons[battlerId].maxHP / BattlerQuality; if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; if (gBattleMons[battlerId].hp + gBattleMoveDamage > gBattleMons[battlerId].maxHP) @@ -2686,7 +2705,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) { PREPARE_FLAVOR_BUFFER(gBattleTextBuff1, FLAVOR_SWEET); - gBattleMoveDamage = gBattleMons[battlerId].maxHP / bankQuality; + gBattleMoveDamage = gBattleMons[battlerId].maxHP / BattlerQuality; if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; if (gBattleMons[battlerId].hp + gBattleMoveDamage > gBattleMons[battlerId].maxHP) @@ -2704,7 +2723,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) { PREPARE_FLAVOR_BUFFER(gBattleTextBuff1, FLAVOR_BITTER); - gBattleMoveDamage = gBattleMons[battlerId].maxHP / bankQuality; + gBattleMoveDamage = gBattleMons[battlerId].maxHP / BattlerQuality; if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; if (gBattleMons[battlerId].hp + gBattleMoveDamage > gBattleMons[battlerId].maxHP) @@ -2722,7 +2741,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) { PREPARE_FLAVOR_BUFFER(gBattleTextBuff1, FLAVOR_SOUR); - gBattleMoveDamage = gBattleMons[battlerId].maxHP / bankQuality; + gBattleMoveDamage = gBattleMons[battlerId].maxHP / BattlerQuality; if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; if (gBattleMons[battlerId].hp + gBattleMoveDamage > gBattleMons[battlerId].maxHP) @@ -2737,7 +2756,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) break; // copy/paste again, smh case HOLD_EFFECT_ATTACK_UP: - if (gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / bankQuality && !moveTurn && gBattleMons[battlerId].statStages[STAT_ATK] < 0xC) + if (gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / BattlerQuality && !moveTurn && gBattleMons[battlerId].statStages[STAT_ATK] < 0xC) { PREPARE_STAT_BUFFER(gBattleTextBuff1, STAT_ATK); PREPARE_STRING_BUFFER(gBattleTextBuff2, STRINGID_STATROSE); @@ -2751,7 +2770,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) } break; case HOLD_EFFECT_DEFENSE_UP: - if (gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / bankQuality && !moveTurn && gBattleMons[battlerId].statStages[STAT_DEF] < 0xC) + if (gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / BattlerQuality && !moveTurn && gBattleMons[battlerId].statStages[STAT_DEF] < 0xC) { PREPARE_STAT_BUFFER(gBattleTextBuff1, STAT_DEF); @@ -2764,7 +2783,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) } break; case HOLD_EFFECT_SPEED_UP: - if (gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / bankQuality && !moveTurn && gBattleMons[battlerId].statStages[STAT_SPEED] < 0xC) + if (gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / BattlerQuality && !moveTurn && gBattleMons[battlerId].statStages[STAT_SPEED] < 0xC) { PREPARE_STAT_BUFFER(gBattleTextBuff1, STAT_SPEED); @@ -2777,7 +2796,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) } break; case HOLD_EFFECT_SP_ATTACK_UP: - if (gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / bankQuality && !moveTurn && gBattleMons[battlerId].statStages[STAT_SPATK] < 0xC) + if (gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / BattlerQuality && !moveTurn && gBattleMons[battlerId].statStages[STAT_SPATK] < 0xC) { PREPARE_STAT_BUFFER(gBattleTextBuff1, STAT_SPATK); @@ -2790,7 +2809,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) } break; case HOLD_EFFECT_SP_DEFENSE_UP: - if (gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / bankQuality && !moveTurn && gBattleMons[battlerId].statStages[STAT_SPDEF] < 0xC) + if (gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / BattlerQuality && !moveTurn && gBattleMons[battlerId].statStages[STAT_SPDEF] < 0xC) { PREPARE_STAT_BUFFER(gBattleTextBuff1, STAT_SPDEF); @@ -2803,7 +2822,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) } break; case HOLD_EFFECT_CRITICAL_UP: - if (gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / bankQuality && !moveTurn && !(gBattleMons[battlerId].status2 & STATUS2_FOCUS_ENERGY)) + if (gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / BattlerQuality && !moveTurn && !(gBattleMons[battlerId].status2 & STATUS2_FOCUS_ENERGY)) { gBattleMons[battlerId].status2 |= STATUS2_FOCUS_ENERGY; BattleScriptExecute(BattleScript_BerryFocusEnergyEnd2); @@ -2811,7 +2830,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) } break; case HOLD_EFFECT_RANDOM_STAT_UP: - if (!moveTurn && gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / bankQuality) + if (!moveTurn && gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / BattlerQuality) { for (i = 0; i < 5; i++) { @@ -2977,15 +2996,15 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) gLastUsedItem = gBattleMons[battlerId].item; if (gBattleMons[battlerId].item == ITEM_ENIGMA_BERRY) { - bankHoldEffect = gEnigmaBerries[battlerId].holdEffect; - bankQuality = gEnigmaBerries[battlerId].holdEffectParam; + BattlerHoldEffect = gEnigmaBerries[battlerId].holdEffect; + BattlerQuality = gEnigmaBerries[battlerId].holdEffectParam; } else { - bankHoldEffect = ItemId_GetHoldEffect(gLastUsedItem); - bankQuality = ItemId_GetHoldEffectParam(gLastUsedItem); + BattlerHoldEffect = ItemId_GetHoldEffect(gLastUsedItem); + BattlerQuality = ItemId_GetHoldEffectParam(gLastUsedItem); } - switch (bankHoldEffect) + switch (BattlerHoldEffect) { case HOLD_EFFECT_CURE_PAR: if (gBattleMons[battlerId].status1 & STATUS1_PARALYSIS) @@ -3180,7 +3199,7 @@ void HandleAction_RunBattleScript(void) // identical to RunBattleScriptCommands u8 GetMoveTarget(u16 move, u8 setTarget) { - u8 targetBank = 0; + u8 targetBattler = 0; u8 moveTarget; u8 side; @@ -3194,21 +3213,21 @@ u8 GetMoveTarget(u16 move, u8 setTarget) case MOVE_TARGET_SELECTED: side = GetBattlerSide(gBattlerAttacker) ^ BIT_SIDE; if (gSideTimers[side].followmeTimer && gBattleMons[gSideTimers[side].followmeTarget].hp) - targetBank = gSideTimers[side].followmeTarget; + targetBattler = gSideTimers[side].followmeTarget; else { side = GetBattlerSide(gBattlerAttacker); do { - targetBank = Random() % gBattlersCount; - } while (targetBank == gBattlerAttacker || side == GetBattlerSide(targetBank) || gAbsentBattlerFlags & gBitTable[targetBank]); + targetBattler = Random() % gBattlersCount; + } while (targetBattler == gBattlerAttacker || side == GetBattlerSide(targetBattler) || gAbsentBattlerFlags & gBitTable[targetBattler]); if (gBattleMoves[move].type == TYPE_ELECTRIC && AbilityBattleEffects(ABILITYEFFECT_COUNT_OTHER_SIDE, gBattlerAttacker, ABILITY_LIGHTNING_ROD, 0, 0) - && gBattleMons[targetBank].ability != ABILITY_LIGHTNING_ROD) + && gBattleMons[targetBattler].ability != ABILITY_LIGHTNING_ROD) { - targetBank ^= BIT_FLANK; - RecordAbilityBattle(targetBank, gBattleMons[targetBank].ability); - gSpecialStatuses[targetBank].lightningRodRedirected = 1; + targetBattler ^= BIT_FLANK; + RecordAbilityBattle(targetBattler, gBattleMons[targetBattler].ability); + gSpecialStatuses[targetBattler].lightningRodRedirected = 1; } } break; @@ -3216,45 +3235,45 @@ u8 GetMoveTarget(u16 move, u8 setTarget) case MOVE_TARGET_BOTH: case MOVE_TARGET_FOES_AND_ALLY: case MOVE_TARGET_OPPONENTS_FIELD: - targetBank = GetBattlerAtPosition((GetBattlerPosition(gBattlerAttacker) & BIT_SIDE) ^ BIT_SIDE); - if (gAbsentBattlerFlags & gBitTable[targetBank]) - targetBank ^= BIT_FLANK; + targetBattler = GetBattlerAtPosition((GetBattlerPosition(gBattlerAttacker) & BIT_SIDE) ^ BIT_SIDE); + if (gAbsentBattlerFlags & gBitTable[targetBattler]) + targetBattler ^= BIT_FLANK; break; case MOVE_TARGET_RANDOM: side = GetBattlerSide(gBattlerAttacker) ^ BIT_SIDE; if (gSideTimers[side].followmeTimer && gBattleMons[gSideTimers[side].followmeTarget].hp) - targetBank = gSideTimers[side].followmeTarget; + targetBattler = gSideTimers[side].followmeTarget; else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && moveTarget & MOVE_TARGET_RANDOM) { if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) { if (Random() & 1) - targetBank = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); + targetBattler = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); else - targetBank = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT); + targetBattler = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT); } else { if (Random() & 1) - targetBank = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); + targetBattler = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); else - targetBank = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT); + targetBattler = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT); } - if (gAbsentBattlerFlags & gBitTable[targetBank]) - targetBank ^= BIT_FLANK; + if (gAbsentBattlerFlags & gBitTable[targetBattler]) + targetBattler ^= BIT_FLANK; } else - targetBank = GetBattlerAtPosition((GetBattlerPosition(gBattlerAttacker) & BIT_SIDE) ^ BIT_SIDE); + targetBattler = GetBattlerAtPosition((GetBattlerPosition(gBattlerAttacker) & BIT_SIDE) ^ BIT_SIDE); break; case MOVE_TARGET_USER_OR_SELECTED: case MOVE_TARGET_USER: - targetBank = gBattlerAttacker; + targetBattler = gBattlerAttacker; break; } - *(gBattleStruct->moveTarget + gBattlerAttacker) = targetBank; + *(gBattleStruct->moveTarget + gBattlerAttacker) = targetBattler; - return targetBank; + return targetBattler; } static bool32 HasObedientBitSet(u8 battlerId) diff --git a/src/pokemon.c b/src/pokemon.c index a4d62feca..7d685062f 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -1964,11 +1964,11 @@ void CalculateMonStats(struct Pokemon *mon) SetMonData(mon, MON_DATA_MAX_HP, &newMaxHP); - CALC_STAT(baseAttack, attackIV, attackEV, 1, MON_DATA_ATK) - CALC_STAT(baseDefense, defenseIV, defenseEV, 2, MON_DATA_DEF) - CALC_STAT(baseSpeed, speedIV, speedEV, 3, MON_DATA_SPEED) - CALC_STAT(baseSpAttack, spAttackIV, spAttackEV, 4, MON_DATA_SPATK) - CALC_STAT(baseSpDefense, spDefenseIV, spDefenseEV, 5, MON_DATA_SPDEF) + CALC_STAT(baseAttack, attackIV, attackEV, STAT_ATK, MON_DATA_ATK) + CALC_STAT(baseDefense, defenseIV, defenseEV, STAT_DEF, MON_DATA_DEF) + CALC_STAT(baseSpeed, speedIV, speedEV, STAT_SPEED, MON_DATA_SPEED) + CALC_STAT(baseSpAttack, spAttackIV, spAttackEV, STAT_SPATK, MON_DATA_SPATK) + CALC_STAT(baseSpDefense, spDefenseIV, spDefenseEV, STAT_SPDEF, MON_DATA_SPDEF) if (species == SPECIES_SHEDINJA) { @@ -4819,21 +4819,21 @@ bool8 sub_806D7EC(void) return retVal; } -bool16 sub_806D82C(u8 id) +u16 GetLinkTrainerFlankId(u8 linkPlayerId) { - bool16 retVal = FALSE; - switch (gLinkPlayers[id].lp_field_18) + u16 flankId = 0; + switch (gLinkPlayers[linkPlayerId].lp_field_18) { case 0: case 3: - retVal = FALSE; + flankId = 0; break; case 1: case 2: - retVal = TRUE; + flankId = 1; break; } - return retVal; + return flankId; } s32 GetBattlerMultiplayerId(u16 a1) diff --git a/src/recorded_battle.c b/src/recorded_battle.c index 3a4265895..e36716feb 100644 --- a/src/recorded_battle.c +++ b/src/recorded_battle.c @@ -58,8 +58,8 @@ struct RecordedBattleSave u8 field_4FC; u8 field_4FD; u8 field_4FE; - u8 battleStyle : 1; - u8 textSpeed : 3; + u8 battleStyle:1; + u8 textSpeed:3; u32 AI_scripts; u8 field_504[8]; u8 field_50C; @@ -79,19 +79,19 @@ EWRAM_DATA static u16 sUnknown_0203C79C[4] = {0}; EWRAM_DATA static u16 sUnknown_0203C7A4[4] = {0}; EWRAM_DATA static u8 sUnknown_0203C7AC = 0; EWRAM_DATA static u8 sUnknown_0203C7AD = 0; -EWRAM_DATA static u8 sRecordedBattle_FrontierFacility = 0; +EWRAM_DATA static u8 sFrontierFacility = 0; EWRAM_DATA static u8 sUnknown_0203C7AF = 0; EWRAM_DATA static MainCallback sCallback2_AfterRecordedBattle = NULL; EWRAM_DATA u8 gUnknown_0203C7B4 = 0; EWRAM_DATA static u8 sUnknown_0203C7B5 = 0; -EWRAM_DATA static u8 sRecordedBattle_BattleStyle = 0; -EWRAM_DATA static u8 sRecordedBattle_TextSpeed = 0; -EWRAM_DATA static u32 sRecordedBattle_BattleFlags = 0; -EWRAM_DATA static u32 sRecordedBattle_AI_Scripts = 0; +EWRAM_DATA static u8 sBattleStyle = 0; +EWRAM_DATA static u8 sTextSpeed = 0; +EWRAM_DATA static u32 sBattleFlags = 0; +EWRAM_DATA static u32 sAI_Scripts = 0; EWRAM_DATA static struct Pokemon sSavedPlayerParty[PARTY_SIZE] = {0}; EWRAM_DATA static struct Pokemon sSavedOpponentParty[PARTY_SIZE] = {0}; -EWRAM_DATA static u16 sRecordedBattle_PlayerMonMoves[2][4] = {0}; -EWRAM_DATA static struct PlayerInfo sRecordedBattle_Players[MAX_BATTLERS_COUNT] = {0}; +EWRAM_DATA static u16 sPlayerMonMoves[2][4] = {0}; +EWRAM_DATA static struct PlayerInfo sPlayers[MAX_BATTLERS_COUNT] = {0}; EWRAM_DATA static u8 sUnknown_0203CCD0 = 0; EWRAM_DATA static u8 sUnknown_0203CCD1[8] = {0}; EWRAM_DATA static u8 sUnknown_0203CCD9 = 0; @@ -126,8 +126,8 @@ void sub_8184DA4(u8 arg0) { sBattleRecords[i][j] |= 0xFF; } - sRecordedBattle_BattleFlags = gBattleTypeFlags; - sRecordedBattle_AI_Scripts = gBattleResources->ai->aiFlags; + sBattleFlags = gBattleTypeFlags; + sAI_Scripts = gBattleResources->ai->aiFlags; } } } @@ -139,7 +139,7 @@ void sub_8184E58(void) if (sUnknown_0203C7AC == 1) { gRecordedBattleRngSeed = gRngValue; - sRecordedBattle_FrontierFacility = VarGet(VAR_FRONTIER_FACILITY); + sFrontierFacility = VarGet(VAR_FRONTIER_FACILITY); sUnknown_0203C7AF = sub_81A513C(); } else if (sUnknown_0203C7AC == 2) @@ -157,37 +157,37 @@ void sub_8184E58(void) for (i = 0; i < MAX_BATTLERS_COUNT; i++) { - sRecordedBattle_Players[i].trainerId = gLinkPlayers[i].trainerId; - sRecordedBattle_Players[i].gender = gLinkPlayers[i].gender; - sRecordedBattle_Players[i].battlerId = gLinkPlayers[i].lp_field_18; - sRecordedBattle_Players[i].language = gLinkPlayers[i].language; + sPlayers[i].trainerId = gLinkPlayers[i].trainerId; + sPlayers[i].gender = gLinkPlayers[i].gender; + sPlayers[i].battlerId = gLinkPlayers[i].lp_field_18; + sPlayers[i].language = gLinkPlayers[i].language; if (i < linkPlayersCount) { StringCopy(text, gLinkPlayers[i].name); StripExtCtrlCodes(text); - StringCopy(sRecordedBattle_Players[i].name, text); + StringCopy(sPlayers[i].name, text); } else { for (j = 0; j < PLAYER_NAME_LENGTH; j++) - sRecordedBattle_Players[i].name[j] = gLinkPlayers[i].name[j]; + sPlayers[i].name[j] = gLinkPlayers[i].name[j]; } } } else { - sRecordedBattle_Players[0].trainerId = (gSaveBlock2Ptr->playerTrainerId[0]) + sPlayers[0].trainerId = (gSaveBlock2Ptr->playerTrainerId[0]) | (gSaveBlock2Ptr->playerTrainerId[1] << 8) | (gSaveBlock2Ptr->playerTrainerId[2] << 16) | (gSaveBlock2Ptr->playerTrainerId[3] << 24); - sRecordedBattle_Players[0].gender = gSaveBlock2Ptr->playerGender; - sRecordedBattle_Players[0].battlerId = 0; - sRecordedBattle_Players[0].language = gGameLanguage; + sPlayers[0].gender = gSaveBlock2Ptr->playerGender; + sPlayers[0].battlerId = 0; + sPlayers[0].language = gGameLanguage; for (i = 0; i < PLAYER_NAME_LENGTH; i++) - sRecordedBattle_Players[0].name[i] = gSaveBlock2Ptr->playerName[i]; + sPlayers[0].name[i] = gSaveBlock2Ptr->playerName[i]; } } @@ -214,7 +214,7 @@ void RecordedBattle_ClearBattlerAction(u8 battlerId, u8 bytesToClear) u8 RecordedBattle_GetBattlerAction(u8 battlerId) { - // trying to read past array or invalid action byte, battle is over + // Trying to read past array or invalid action byte, battle is over. if (sRecordedBytesNo[battlerId] >= BATTLER_RECORD_SIZE || sBattleRecords[battlerId][sRecordedBytesNo[battlerId]] == 0xFF) { gSpecialVar_Result = gBattleOutcome = B_OUTCOME_PLAYER_TELEPORTED; // hah @@ -345,37 +345,37 @@ u32 MoveRecordedBattleToSaveData(void) { for (j = 0; j < PLAYER_NAME_LENGTH; j++) { - battleSave->playersName[i][j] = sRecordedBattle_Players[i].name[j]; + battleSave->playersName[i][j] = sPlayers[i].name[j]; } - battleSave->playersGender[i] = sRecordedBattle_Players[i].gender; - battleSave->playersLanguage[i] = sRecordedBattle_Players[i].language; - battleSave->playersBattlers[i] = sRecordedBattle_Players[i].battlerId; - battleSave->playersTrainerId[i] = sRecordedBattle_Players[i].trainerId; + battleSave->playersGender[i] = sPlayers[i].gender; + battleSave->playersLanguage[i] = sPlayers[i].language; + battleSave->playersBattlers[i] = sPlayers[i].battlerId; + battleSave->playersTrainerId[i] = sPlayers[i].trainerId; } battleSave->rngSeed = gRecordedBattleRngSeed; - if (sRecordedBattle_BattleFlags & BATTLE_TYPE_LINK) + if (sBattleFlags & BATTLE_TYPE_LINK) { - battleSave->battleFlags = (sRecordedBattle_BattleFlags & ~(BATTLE_TYPE_LINK | BATTLE_TYPE_20)); + battleSave->battleFlags = (sBattleFlags & ~(BATTLE_TYPE_LINK | BATTLE_TYPE_20)); battleSave->battleFlags |= BATTLE_TYPE_x2000000; - if (sRecordedBattle_BattleFlags & BATTLE_TYPE_WILD) + if (sBattleFlags & BATTLE_TYPE_WILD) { battleSave->battleFlags |= BATTLE_TYPE_x80000000; } - else if (sRecordedBattle_BattleFlags & BATTLE_TYPE_MULTI) + else if (sBattleFlags & BATTLE_TYPE_MULTI) { - switch (sRecordedBattle_Players[0].battlerId) + switch (sPlayers[0].battlerId) { case 0: case 2: - if (!(sRecordedBattle_Players[gUnknown_0203C7B4].battlerId & 1)) + if (!(sPlayers[gUnknown_0203C7B4].battlerId & 1)) battleSave->battleFlags |= BATTLE_TYPE_x80000000; break; case 1: case 3: - if ((sRecordedBattle_Players[gUnknown_0203C7B4].battlerId & 1)) + if ((sPlayers[gUnknown_0203C7B4].battlerId & 1)) battleSave->battleFlags |= BATTLE_TYPE_x80000000; break; } @@ -383,7 +383,7 @@ u32 MoveRecordedBattleToSaveData(void) } else { - battleSave->battleFlags = sRecordedBattle_BattleFlags; + battleSave->battleFlags = sBattleFlags; } battleSave->opponentA = gTrainerBattleOpponent_A; @@ -391,11 +391,11 @@ u32 MoveRecordedBattleToSaveData(void) battleSave->partnerId = gPartnerTrainerId; battleSave->field_4FA = gUnknown_0203C7B4; battleSave->field_4FC = gSaveBlock2Ptr->field_CA9_b; - battleSave->field_4FD = sRecordedBattle_FrontierFacility; + battleSave->field_4FD = sFrontierFacility; battleSave->field_4FE = sUnknown_0203C7AF; battleSave->battleStyle = gSaveBlock2Ptr->optionsBattleStyle; battleSave->textSpeed = gSaveBlock2Ptr->optionsTextSpeed; - battleSave->AI_scripts = sRecordedBattle_AI_Scripts; + battleSave->AI_scripts = sAI_Scripts; /* Can't match it without proper knowledge of the Saveblock 2. if (gTrainerBattleOpponent_A >= 300 && gTrainerBattleOpponent_A <= 399) @@ -525,7 +525,7 @@ _0818535E:\n\ lsls r3, 3\n\ adds r3, r7, r3\n\ str r3, [sp, 0x8]\n\ - ldr r5, =sRecordedBattle_Players\n\ + ldr r5, =sPlayers\n\ mov r8, r6\n\ mov r12, r6\n\ movs r4, 0x96\n\ @@ -536,7 +536,7 @@ _0818535E:\n\ adds r4, r7, r0\n\ _081853AC:\n\ lsls r1, r6, 3\n\ - ldr r0, =sRecordedBattle_Players\n\ + ldr r0, =sPlayers\n\ adds r0, 0x4\n\ mov r3, r8\n\ adds r2, r3, r0\n\ @@ -578,7 +578,7 @@ _081853BA:\n\ ldr r5, =gRecordedBattleRngSeed\n\ ldr r0, [r5]\n\ str r0, [r1]\n\ - ldr r0, =sRecordedBattle_BattleFlags\n\ + ldr r0, =sBattleFlags\n\ ldr r2, [r0]\n\ movs r0, 0x2\n\ ands r0, r2\n\ @@ -608,7 +608,7 @@ _08185454:\n\ ands r2, r0\n\ cmp r2, 0\n\ beq _081854E2\n\ - ldr r2, =sRecordedBattle_Players\n\ + ldr r2, =sPlayers\n\ ldrh r0, [r2, 0xE]\n\ cmp r0, 0x1\n\ beq _081854A8\n\ @@ -630,7 +630,7 @@ _0818547E:\n\ lsls r0, r1, 2\n\ adds r0, r1\n\ lsls r0, 2\n\ - ldr r4, =sRecordedBattle_Players\n\ + ldr r4, =sPlayers\n\ adds r0, r4\n\ ldrh r1, [r0, 0xE]\n\ movs r0, 0x1\n\ @@ -647,7 +647,7 @@ _081854A8:\n\ lsls r0, r1, 2\n\ adds r0, r1\n\ lsls r0, 2\n\ - ldr r1, =sRecordedBattle_Players\n\ + ldr r1, =sPlayers\n\ adds r0, r1\n\ ldrh r1, [r0, 0xE]\n\ movs r0, 0x1\n\ @@ -700,7 +700,7 @@ _081854E2:\n\ ldr r5, =0x000004fc\n\ adds r1, r7, r5\n\ strb r0, [r1]\n\ - ldr r0, =sRecordedBattle_FrontierFacility\n\ + ldr r0, =sFrontierFacility\n\ ldrb r1, [r0]\n\ adds r2, 0x3\n\ adds r0, r7, r2\n\ @@ -735,7 +735,7 @@ _081854E2:\n\ movs r2, 0xA0\n\ lsls r2, 3\n\ adds r1, r7, r2\n\ - ldr r3, =sRecordedBattle_AI_Scripts\n\ + ldr r3, =sAI_Scripts\n\ ldr r0, [r3]\n\ str r0, [r1]\n\ ldr r4, =0xfffffed4\n\ @@ -1354,11 +1354,11 @@ static void SetRecordedBattleVarsFromSave(struct RecordedBattleSave *src) gPartnerTrainerId = src->partnerId; gUnknown_0203C7B4 = src->field_4FA; sUnknown_0203C7AD = gSaveBlock2Ptr->frontierChosenLvl; - sRecordedBattle_FrontierFacility = src->field_4FD; + sFrontierFacility = src->field_4FD; sUnknown_0203C7AF = src->field_4FE; - sRecordedBattle_BattleStyle = src->battleStyle; - sRecordedBattle_TextSpeed = src->textSpeed; - sRecordedBattle_AI_Scripts = src->AI_scripts; + sBattleStyle = src->battleStyle; + sTextSpeed = src->textSpeed; + sAI_Scripts = src->AI_scripts; for (i = 0; i < 8; i++) { @@ -1417,7 +1417,7 @@ static void CB2_RecordedBattle(void) u8 GetRecordedBattleFrontierFacility(void) { - return sRecordedBattle_FrontierFacility; + return sFrontierFacility; } u8 sub_8185EAC(void) @@ -1480,12 +1480,12 @@ u8 sub_8185FAC(void) u8 GetBattleStyleInRecordedBattle(void) { - return sRecordedBattle_BattleStyle; + return sBattleStyle; } u8 GetTextSpeedInRecordedBattle(void) { - return sRecordedBattle_TextSpeed; + return sTextSpeed; } void RecordedBattle_CopyBattlerMoves(void) @@ -1501,7 +1501,7 @@ void RecordedBattle_CopyBattlerMoves(void) for (i = 0; i < 4; i++) { - sRecordedBattle_PlayerMonMoves[gActiveBattler / 2][i] = gBattleMons[gActiveBattler].moves[i]; + sPlayerMonMoves[gActiveBattler / 2][i] = gBattleMons[gActiveBattler].moves[i]; } } @@ -1522,7 +1522,7 @@ void sub_818603C(u8 arg0) { for (j = 0; j < 4; j++) { - if (gBattleMons[battlerId].moves[j] != sRecordedBattle_PlayerMonMoves[battlerId / 2][j]) + if (gBattleMons[battlerId].moves[j] != sPlayerMonMoves[battlerId / 2][j]) break; } if (j != 4) // player's mon's move has been changed @@ -1532,7 +1532,7 @@ void sub_818603C(u8 arg0) { for (k = 0; k < 4; k++) { - if (gBattleMons[battlerId].moves[j] == sRecordedBattle_PlayerMonMoves[battlerId / 2][k]) + if (gBattleMons[battlerId].moves[j] == sPlayerMonMoves[battlerId / 2][k]) { RecordedBattle_SetBattlerAction(battlerId, k); break; @@ -1612,7 +1612,7 @@ void sub_818603C(u8 arg0) u32 GetAiScriptsInRecordedBattle(void) { - return sRecordedBattle_AI_Scripts; + return sAI_Scripts; } void sub_8186444(void) From c556358e47f7af50ba9b04fc1d7b359512c25b03 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 1 Jul 2018 15:28:57 +0200 Subject: [PATCH 09/15] label multiuse sprite template functions --- asm/contest.s | 4 +- asm/contest_link_80F57C4.s | 4 +- asm/pokemon_summary_screen.s | 4 +- asm/script_pokemon_util_80F87D8.s | 4 +- asm/trade.s | 4 +- data/data2b.s | 2 +- include/pokemon.h | 8 +-- src/battle_controller_link_opponent.c | 21 +++--- src/battle_controller_link_partner.c | 17 +++-- src/battle_controller_opponent.c | 21 +++--- src/battle_controller_player.c | 35 +++++----- src/battle_controller_player_partner.c | 22 +++--- src/battle_controller_recorded_opponent.c | 17 +++-- src/battle_controller_recorded_player.c | 21 +++--- src/battle_controller_safari.c | 8 +-- src/battle_controller_wally.c | 17 +++-- src/battle_dome_cards.c | 13 ++-- src/battle_main.c | 6 +- src/egg_hatch.c | 6 +- src/evolution_scene.c | 31 ++++----- src/pokeblock_feed.c | 5 +- src/pokemon.c | 84 ++++++++++++----------- src/reshow_battle_screen.c | 19 +++-- 23 files changed, 183 insertions(+), 190 deletions(-) diff --git a/asm/contest.s b/asm/contest.s index 327a80d75..453ecb04c 100644 --- a/asm/contest.s +++ b/asm/contest.s @@ -6770,8 +6770,8 @@ _080DB1CC: bl LoadCompressedPalette adds r0, r5, 0 movs r1, 0 - bl sub_806A068 - ldr r4, =gUnknown_0202499C + bl SetMultiuseSpriteTemplateToPokemon + ldr r4, =gMultiuseSpriteTemplate movs r0, 0x2 adds r1, r5, 0 movs r2, 0 diff --git a/asm/contest_link_80F57C4.s b/asm/contest_link_80F57C4.s index 450a235d5..ba1fa1c29 100644 --- a/asm/contest_link_80F57C4.s +++ b/asm/contest_link_80F57C4.s @@ -1420,8 +1420,8 @@ _080F64F2: bl LoadCompressedObjectPalette adds r0, r6, 0 movs r1, 0x1 - bl sub_806A068 - ldr r0, =gUnknown_0202499C + bl SetMultiuseSpriteTemplateToPokemon + ldr r0, =gMultiuseSpriteTemplate ldrh r1, [r4, 0x4] strh r1, [r0, 0x2] movs r1, 0x88 diff --git a/asm/pokemon_summary_screen.s b/asm/pokemon_summary_screen.s index e52874f57..ff848df08 100644 --- a/asm/pokemon_summary_screen.s +++ b/asm/pokemon_summary_screen.s @@ -1092,7 +1092,7 @@ _081C4750: bl LoadCompressedObjectPalette ldrh r0, [r4, 0x4] movs r1, 0x1 - bl sub_806A068 + bl SetMultiuseSpriteTemplateToPokemon _081C4768: ldrh r0, [r6] adds r0, 0x1 @@ -1144,7 +1144,7 @@ sub_81C47B4: @ 81C47B4 ldr r0, =gUnknown_0203CF1C ldr r6, [r0] adds r6, 0x70 - ldr r0, =gUnknown_0202499C + ldr r0, =gMultiuseSpriteTemplate movs r1, 0x28 movs r2, 0x40 movs r3, 0x5 diff --git a/asm/script_pokemon_util_80F87D8.s b/asm/script_pokemon_util_80F87D8.s index 18a0cec88..1d4173c4c 100644 --- a/asm/script_pokemon_util_80F87D8.s +++ b/asm/script_pokemon_util_80F87D8.s @@ -737,8 +737,8 @@ _080F8DD8: bl LoadCompressedObjectPalette adds r0, r6, 0 movs r1, 0x1 - bl sub_806A068 - ldr r0, =gUnknown_0202499C + bl SetMultiuseSpriteTemplateToPokemon + ldr r0, =gMultiuseSpriteTemplate ldrh r1, [r4, 0x4] strh r1, [r0, 0x2] mov r1, r9 diff --git a/asm/trade.s b/asm/trade.s index 0d7353938..061e338cd 100644 --- a/asm/trade.s +++ b/asm/trade.s @@ -7174,8 +7174,8 @@ _0807ADE0: bl GetMonSpritePalStruct ldrh r0, [r0, 0x4] adds r1, r4, 0 - bl sub_806A068 - ldr r0, =gUnknown_0202499C + bl SetMultiuseSpriteTemplateToPokemon + ldr r0, =gMultiuseSpriteTemplate movs r1, 0x78 movs r2, 0x3C movs r3, 0x6 diff --git a/data/data2b.s b/data/data2b.s index de32e9775..87ca0b881 100644 --- a/data/data2b.s +++ b/data/data2b.s @@ -235,7 +235,7 @@ gUnknown_082FF704:: @ 82FF704 .2byte 0x0003, 0x0000, 0xffff, 0x0000 .align 2 -gUnknown_082FF70C:: @ 82FF70C +gPlayerMonSpriteAnimsTable:: @ 82FF70C .4byte gUnknown_082FF6EC .4byte gUnknown_082FF6F4 .4byte gUnknown_082FF6FC diff --git a/include/pokemon.h b/include/pokemon.h index f928243d0..f36284f12 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -438,7 +438,7 @@ extern u8 gPlayerPartyCount; extern struct Pokemon gPlayerParty[PARTY_SIZE]; extern u8 gEnemyPartyCount; extern struct Pokemon gEnemyParty[PARTY_SIZE]; -extern struct SpriteTemplate gUnknown_0202499C; +extern struct SpriteTemplate gMultiuseSpriteTemplate; extern struct PokemonStorage* gPokemonStoragePtr; extern const struct BattleMove gBattleMoves[]; @@ -505,9 +505,9 @@ u8 GetDefaultMoveTarget(u8 battlerId); u8 GetMonGender(struct Pokemon *mon); u8 GetBoxMonGender(struct BoxPokemon *boxMon); u8 GetGenderFromSpeciesAndPersonality(u16 species, u32 personality); -void sub_806A068(u16 species, u8 battlerPosition); -void sub_806A12C(u16 trainerSpriteId, u8 battlerPosition); -void sub_806A1C0(u16 arg0, u8 battlerPosition); +void SetMultiuseSpriteTemplateToPokemon(u16 species, u8 battlerPosition); +void SetMultiuseSpriteTemplateToTrainerBack(u16 trainerSpriteId, u8 battlerPosition); +void SetMultiuseSpriteTemplateToTrainerFront(u16 arg0, u8 battlerPosition); // These are full type signatures for GetMonData() and GetBoxMonData(), // but they are not used since some code erroneously omits the third arg. diff --git a/src/battle_controller_link_opponent.c b/src/battle_controller_link_opponent.c index 18963f955..d786dacd1 100644 --- a/src/battle_controller_link_opponent.c +++ b/src/battle_controller_link_opponent.c @@ -34,7 +34,6 @@ extern struct UnusedControllerStruct gUnknown_02022D0C; extern const struct CompressedSpritePalette gTrainerFrontPicPaletteTable[]; extern void sub_8172EF0(u8 battlerId, struct Pokemon *mon); -extern void sub_806A068(u16, u8); extern void sub_81851A8(u8 *); extern u16 sub_8068B48(void); extern u8 GetFrontierTrainerFrontSpriteId(u16 trainerId); @@ -191,7 +190,7 @@ static void LinkOpponentBufferRunCommand(void) } } -static void CompleteOnBankSpriteCallbackDummy(void) +static void CompleteOnBattlerSpriteCallbackDummy(void) { if (gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) LinkOpponentBufferExecCompleted(); @@ -1135,9 +1134,9 @@ static void LinkOpponentHandleLoadMonSprite(void) u16 species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_SPECIES); BattleLoadOpponentMonSpriteGfx(&gEnemyParty[gBattlerPartyIndexes[gActiveBattler]], gActiveBattler); - sub_806A068(species, GetBattlerPosition(gActiveBattler)); + SetMultiuseSpriteTemplateToPokemon(species, GetBattlerPosition(gActiveBattler)); - gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gUnknown_0202499C, + gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gMultiuseSpriteTemplate, GetBattlerSpriteCoord(gActiveBattler, 2), GetBattlerSpriteDefault_Y(gActiveBattler), sub_80A82E4(gActiveBattler)); @@ -1168,10 +1167,10 @@ static void sub_8066494(u8 battlerId, bool8 dontClearSubstituteBit) species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[battlerId]], MON_DATA_SPECIES); gUnknown_03005D7C[battlerId] = CreateInvisibleSpriteWithCallback(sub_805D714); BattleLoadOpponentMonSpriteGfx(&gEnemyParty[gBattlerPartyIndexes[battlerId]], battlerId); - sub_806A068(species, GetBattlerPosition(battlerId)); + SetMultiuseSpriteTemplateToPokemon(species, GetBattlerPosition(battlerId)); gBattlerSpriteIds[battlerId] = CreateSprite( - &gUnknown_0202499C, + &gMultiuseSpriteTemplate, GetBattlerSpriteCoord(battlerId, 2), GetBattlerSpriteDefault_Y(battlerId), sub_80A82E4(battlerId)); @@ -1302,8 +1301,8 @@ static void LinkOpponentHandleDrawTrainerPic(void) } DecompressTrainerFrontPic(trainerPicId, gActiveBattler); - sub_806A12C(trainerPicId, GetBattlerPosition(gActiveBattler)); - gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gUnknown_0202499C, + SetMultiuseSpriteTemplateToTrainerBack(trainerPicId, GetBattlerPosition(gActiveBattler)); + gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gMultiuseSpriteTemplate, xPos, (8 - gTrainerFrontPicCoords[trainerPicId].coords) * 4 + 40, sub_80A82E4(gActiveBattler)); @@ -1314,7 +1313,7 @@ static void LinkOpponentHandleDrawTrainerPic(void) gSprites[gBattlerSpriteIds[gActiveBattler]].oam.affineParam = trainerPicId; gSprites[gBattlerSpriteIds[gActiveBattler]].callback = sub_805D7AC; - gBattlerControllerFuncs[gActiveBattler] = CompleteOnBankSpriteCallbackDummy; + gBattlerControllerFuncs[gActiveBattler] = CompleteOnBattlerSpriteCallbackDummy; } static void LinkOpponentHandleTrainerSlide(void) @@ -1327,8 +1326,8 @@ static void LinkOpponentHandleTrainerSlide(void) trainerPicId = GetFrontierTrainerFrontSpriteId(gTrainerBattleOpponent_B); DecompressTrainerFrontPic(trainerPicId, gActiveBattler); - sub_806A12C(trainerPicId, GetBattlerPosition(gActiveBattler)); - gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gUnknown_0202499C, 176, (8 - gTrainerFrontPicCoords[trainerPicId].coords) * 4 + 40, 0x1E); + SetMultiuseSpriteTemplateToTrainerBack(trainerPicId, GetBattlerPosition(gActiveBattler)); + gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gMultiuseSpriteTemplate, 176, (8 - gTrainerFrontPicCoords[trainerPicId].coords) * 4 + 40, 0x1E); gSprites[gBattlerSpriteIds[gActiveBattler]].pos2.x = 96; gSprites[gBattlerSpriteIds[gActiveBattler]].pos1.x += 32; diff --git a/src/battle_controller_link_partner.c b/src/battle_controller_link_partner.c index b2cf62138..9867c14e4 100644 --- a/src/battle_controller_link_partner.c +++ b/src/battle_controller_link_partner.c @@ -34,7 +34,6 @@ extern const struct CompressedSpritePalette gTrainerFrontPicPaletteTable[]; extern const struct CompressedSpritePalette gTrainerBackPicPaletteTable[]; extern void sub_8172EF0(u8 battlerId, struct Pokemon *mon); -extern void sub_806A068(u16, u8); extern void sub_81851A8(u8 *); extern u8 GetFrontierTrainerFrontSpriteId(u16 trainerId); @@ -189,7 +188,7 @@ static void LinkPartnerBufferRunCommand(void) } } -static void CompleteOnBankSpriteCallbackDummy(void) +static void CompleteOnBattlerSpriteCallbackDummy(void) { if (gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) LinkPartnerBufferExecCompleted(); @@ -1024,9 +1023,9 @@ static void LinkPartnerHandleLoadMonSprite(void) BattleLoadPlayerMonSpriteGfx(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], gActiveBattler); species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_SPECIES); - sub_806A068(species, GetBattlerPosition(gActiveBattler)); + SetMultiuseSpriteTemplateToPokemon(species, GetBattlerPosition(gActiveBattler)); - gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gUnknown_0202499C, + gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gMultiuseSpriteTemplate, GetBattlerSpriteCoord(gActiveBattler, 2), GetBattlerSpriteDefault_Y(gActiveBattler), sub_80A82E4(gActiveBattler)); @@ -1054,10 +1053,10 @@ static void sub_814CC98(u8 battlerId, bool8 dontClearSubstituteBit) gBattlerPartyIndexes[battlerId] = gBattleBufferA[battlerId][1]; species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[battlerId]], MON_DATA_SPECIES); gUnknown_03005D7C[battlerId] = CreateInvisibleSpriteWithCallback(sub_805D714); - sub_806A068(species, GetBattlerPosition(battlerId)); + SetMultiuseSpriteTemplateToPokemon(species, GetBattlerPosition(battlerId)); gBattlerSpriteIds[battlerId] = CreateSprite( - &gUnknown_0202499C, + &gMultiuseSpriteTemplate, GetBattlerSpriteCoord(battlerId, 2), GetBattlerSpriteDefault_Y(battlerId), sub_80A82E4(battlerId)); @@ -1147,15 +1146,15 @@ static void LinkPartnerHandleDrawTrainerPic(void) } DecompressTrainerBackPic(trainerPicId, gActiveBattler); - sub_806A12C(trainerPicId, GetBattlerPosition(gActiveBattler)); - gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gUnknown_0202499C, xPos, (8 - gTrainerBackPicCoords[trainerPicId].coords) * 4 + 80, sub_80A82E4(gActiveBattler)); + SetMultiuseSpriteTemplateToTrainerBack(trainerPicId, GetBattlerPosition(gActiveBattler)); + gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gMultiuseSpriteTemplate, xPos, (8 - gTrainerBackPicCoords[trainerPicId].coords) * 4 + 80, sub_80A82E4(gActiveBattler)); gSprites[gBattlerSpriteIds[gActiveBattler]].oam.paletteNum = gActiveBattler; gSprites[gBattlerSpriteIds[gActiveBattler]].pos2.x = 240; gSprites[gBattlerSpriteIds[gActiveBattler]].data[0] = -2; gSprites[gBattlerSpriteIds[gActiveBattler]].callback = sub_805D7AC; - gBattlerControllerFuncs[gActiveBattler] = CompleteOnBankSpriteCallbackDummy; + gBattlerControllerFuncs[gActiveBattler] = CompleteOnBattlerSpriteCallbackDummy; } static void LinkPartnerHandleTrainerSlide(void) diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index 2af17d32e..1eaa9da18 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -38,7 +38,6 @@ extern struct UnusedControllerStruct gUnknown_02022D0C; extern const struct CompressedSpritePalette gTrainerFrontPicPaletteTable[]; extern void sub_8172EF0(u8 battlerId, struct Pokemon *mon); -extern void sub_806A068(u16, u8); extern void sub_81A57E4(u8 battlerId, u16 stringId); extern u8 GetFrontierBrainTrainerPicIndex(void); extern u8 sub_81D5588(u16 trainerId); @@ -200,7 +199,7 @@ static void OpponentBufferRunCommand(void) } } -static void CompleteOnBankSpriteCallbackDummy(void) +static void CompleteOnBattlerSpriteCallbackDummy(void) { if (gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) OpponentBufferExecCompleted(); @@ -1128,9 +1127,9 @@ static void OpponentHandleLoadMonSprite(void) u16 species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_SPECIES); BattleLoadOpponentMonSpriteGfx(&gEnemyParty[gBattlerPartyIndexes[gActiveBattler]], gActiveBattler); - sub_806A068(species, GetBattlerPosition(gActiveBattler)); + SetMultiuseSpriteTemplateToPokemon(species, GetBattlerPosition(gActiveBattler)); - gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gUnknown_0202499C, + gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gMultiuseSpriteTemplate, GetBattlerSpriteCoord(gActiveBattler, 2), GetBattlerSpriteDefault_Y(gActiveBattler), sub_80A82E4(gActiveBattler)); @@ -1163,9 +1162,9 @@ static void sub_80613DC(u8 battlerId, bool8 dontClearSubstituteBit) species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[battlerId]], MON_DATA_SPECIES); gUnknown_03005D7C[battlerId] = CreateInvisibleSpriteWithCallback(sub_805D714); BattleLoadOpponentMonSpriteGfx(&gEnemyParty[gBattlerPartyIndexes[battlerId]], battlerId); - sub_806A068(species, GetBattlerPosition(battlerId)); + SetMultiuseSpriteTemplateToPokemon(species, GetBattlerPosition(battlerId)); - gBattlerSpriteIds[battlerId] = CreateSprite(&gUnknown_0202499C, + gBattlerSpriteIds[battlerId] = CreateSprite(&gMultiuseSpriteTemplate, GetBattlerSpriteCoord(battlerId, 2), GetBattlerSpriteDefault_Y(battlerId), sub_80A82E4(battlerId)); @@ -1294,8 +1293,8 @@ static void OpponentHandleDrawTrainerPic(void) } DecompressTrainerFrontPic(trainerPicId, gActiveBattler); - sub_806A12C(trainerPicId, GetBattlerPosition(gActiveBattler)); - gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gUnknown_0202499C, + SetMultiuseSpriteTemplateToTrainerBack(trainerPicId, GetBattlerPosition(gActiveBattler)); + gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gMultiuseSpriteTemplate, xPos, (8 - gTrainerFrontPicCoords[trainerPicId].coords) * 4 + 40, sub_80A82E4(gActiveBattler)); @@ -1306,7 +1305,7 @@ static void OpponentHandleDrawTrainerPic(void) gSprites[gBattlerSpriteIds[gActiveBattler]].oam.affineParam = trainerPicId; gSprites[gBattlerSpriteIds[gActiveBattler]].callback = sub_805D7AC; - gBattlerControllerFuncs[gActiveBattler] = CompleteOnBankSpriteCallbackDummy; + gBattlerControllerFuncs[gActiveBattler] = CompleteOnBattlerSpriteCallbackDummy; } static void OpponentHandleTrainerSlide(void) @@ -1366,8 +1365,8 @@ static void OpponentHandleTrainerSlide(void) } DecompressTrainerFrontPic(trainerPicId, gActiveBattler); - sub_806A12C(trainerPicId, GetBattlerPosition(gActiveBattler)); - gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gUnknown_0202499C, 176, (8 - gTrainerFrontPicCoords[trainerPicId].coords) * 4 + 40, 0x1E); + SetMultiuseSpriteTemplateToTrainerBack(trainerPicId, GetBattlerPosition(gActiveBattler)); + gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gMultiuseSpriteTemplate, 176, (8 - gTrainerFrontPicCoords[trainerPicId].coords) * 4 + 40, 0x1E); gSprites[gBattlerSpriteIds[gActiveBattler]].pos2.x = 96; gSprites[gBattlerSpriteIds[gActiveBattler]].pos1.x += 32; diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index 26c2cae98..ef45b60cd 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -39,7 +39,7 @@ extern u16 gBattle_BG0_Y; extern s32 gUnknown_0203CD70; extern struct UnusedControllerStruct gUnknown_02022D0C; extern struct MusicPlayerInfo gMPlayInfo_BGM; -extern struct SpriteTemplate gUnknown_0202499C; +extern struct SpriteTemplate gMultiuseSpriteTemplate; extern const struct CompressedSpritePalette gTrainerFrontPicPaletteTable[]; extern const struct CompressedSpritePalette gTrainerBackPicPaletteTable[]; @@ -47,7 +47,6 @@ extern const struct CompressedSpritePalette gTrainerBackPicPaletteTable[]; extern void sub_8172EF0(u8 battlerId, struct Pokemon *mon); extern void sub_81B89AC(u8 arg0); extern void sub_81AABB0(void); -extern void sub_806A068(u16, u8); extern void sub_81A57E4(u8 battlerId, u16 stringId); extern void sub_81851A8(u8 *); @@ -917,7 +916,7 @@ void sub_80587B0(void) } } -static void CompleteOnBankSpriteCallbackDummy(void) +static void CompleteOnBattlerSpriteCallbackDummy(void) { if (gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) PlayerBufferExecCompleted(); @@ -2200,10 +2199,10 @@ static void sub_805B258(u8 battlerId, bool8 dontClearSubstituteBit) gBattlerPartyIndexes[battlerId] = gBattleBufferA[battlerId][1]; species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[battlerId]], MON_DATA_SPECIES); gUnknown_03005D7C[battlerId] = CreateInvisibleSpriteWithCallback(sub_805D714); - sub_806A068(species, GetBattlerPosition(battlerId)); + SetMultiuseSpriteTemplateToPokemon(species, GetBattlerPosition(battlerId)); gBattlerSpriteIds[battlerId] = CreateSprite( - &gUnknown_0202499C, + &gMultiuseSpriteTemplate, GetBattlerSpriteCoord(battlerId, 2), GetBattlerSpriteDefault_Y(battlerId), sub_80A82E4(battlerId)); @@ -2282,7 +2281,7 @@ static void PlayerHandleDrawTrainerPic(void) } else { - trainerPicId = gLinkPlayers[GetMultiplayerId()].gender; + trainerPicId = gLinkPlayers[GetMultiplayerId()].gender + TRAINER_BACK_PIC_BRENDAN; } } else @@ -2292,9 +2291,9 @@ static void PlayerHandleDrawTrainerPic(void) if (gBattleTypeFlags & BATTLE_TYPE_MULTI) { - if ((GetBattlerPosition(gActiveBattler) & BIT_FLANK) != 0) // second mon + if ((GetBattlerPosition(gActiveBattler) & BIT_FLANK) != B_FLANK_LEFT) // Second mon, on the right. xPos = 90; - else // first mon + else // First mon, on the left. xPos = 32; if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && gPartnerTrainerId != TRAINER_STEVEN_PARTNER) @@ -2319,8 +2318,8 @@ static void PlayerHandleDrawTrainerPic(void) { trainerPicId = PlayerGenderToFrontTrainerPicId(gSaveBlock2Ptr->playerGender); DecompressTrainerFrontPic(trainerPicId, gActiveBattler); - sub_806A1C0(trainerPicId, GetBattlerPosition(gActiveBattler)); - gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gUnknown_0202499C, xPos, yPos, sub_80A82E4(gActiveBattler)); + SetMultiuseSpriteTemplateToTrainerFront(trainerPicId, GetBattlerPosition(gActiveBattler)); + gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gMultiuseSpriteTemplate, xPos, yPos, sub_80A82E4(gActiveBattler)); gSprites[gBattlerSpriteIds[gActiveBattler]].oam.paletteNum = IndexOfSpritePaletteTag(gTrainerFrontPicPaletteTable[trainerPicId].tag); gSprites[gBattlerSpriteIds[gActiveBattler]].pos2.x = 240; @@ -2330,12 +2329,12 @@ static void PlayerHandleDrawTrainerPic(void) gSprites[gBattlerSpriteIds[gActiveBattler]].oam.affineMode = 0; gSprites[gBattlerSpriteIds[gActiveBattler]].hFlip = 1; } - // use the back pic in any other scenario + // Use the back pic in any other scenario. else { DecompressTrainerBackPic(trainerPicId, gActiveBattler); - sub_806A12C(trainerPicId, GetBattlerPosition(gActiveBattler)); - gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gUnknown_0202499C, xPos, yPos, sub_80A82E4(gActiveBattler)); + SetMultiuseSpriteTemplateToTrainerBack(trainerPicId, GetBattlerPosition(gActiveBattler)); + gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gMultiuseSpriteTemplate, xPos, yPos, sub_80A82E4(gActiveBattler)); gSprites[gBattlerSpriteIds[gActiveBattler]].oam.paletteNum = gActiveBattler; gSprites[gBattlerSpriteIds[gActiveBattler]].pos2.x = 240; @@ -2343,7 +2342,7 @@ static void PlayerHandleDrawTrainerPic(void) gSprites[gBattlerSpriteIds[gActiveBattler]].callback = sub_805D7AC; } - gBattlerControllerFuncs[gActiveBattler] = CompleteOnBankSpriteCallbackDummy; + gBattlerControllerFuncs[gActiveBattler] = CompleteOnBattlerSpriteCallbackDummy; } static void PlayerHandleTrainerSlide(void) @@ -2364,17 +2363,17 @@ static void PlayerHandleTrainerSlide(void) } else { - trainerPicId = gLinkPlayers[GetMultiplayerId()].gender; + trainerPicId = gLinkPlayers[GetMultiplayerId()].gender + TRAINER_BACK_PIC_BRENDAN; } } else { - trainerPicId = gSaveBlock2Ptr->playerGender; + trainerPicId = gSaveBlock2Ptr->playerGender + TRAINER_BACK_PIC_BRENDAN; } DecompressTrainerBackPic(trainerPicId, gActiveBattler); - sub_806A12C(trainerPicId, GetBattlerPosition(gActiveBattler)); - gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gUnknown_0202499C, 80, (8 - gTrainerBackPicCoords[trainerPicId].coords) * 4 + 80, 30); + SetMultiuseSpriteTemplateToTrainerBack(trainerPicId, GetBattlerPosition(gActiveBattler)); + gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gMultiuseSpriteTemplate, 80, (8 - gTrainerBackPicCoords[trainerPicId].coords) * 4 + 80, 30); gSprites[gBattlerSpriteIds[gActiveBattler]].oam.paletteNum = gActiveBattler; gSprites[gBattlerSpriteIds[gActiveBattler]].pos2.x = -96; diff --git a/src/battle_controller_player_partner.c b/src/battle_controller_player_partner.c index d7878678a..cd3a94692 100644 --- a/src/battle_controller_player_partner.c +++ b/src/battle_controller_player_partner.c @@ -35,7 +35,7 @@ extern const struct CompressedSpritePalette gTrainerBackPicPaletteTable[]; extern void sub_81358F4(void); extern void sub_8172EF0(u8 battlerId, struct Pokemon *mon); -extern void sub_806A068(u16, u8); +extern void SetMultiuseSpriteTemplateToPokemon(u16, u8); extern u8 GetFrontierTrainerFrontSpriteId(u16 trainerId); // this file's functions @@ -204,7 +204,7 @@ static void PlayerPartnerBufferRunCommand(void) } } -static void CompleteOnBankSpriteCallbackDummy(void) +static void CompleteOnBattlerSpriteCallbackDummy(void) { if (gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) PlayerPartnerBufferExecCompleted(); @@ -1211,9 +1211,9 @@ static void PlayerPartnerHandleLoadMonSprite(void) BattleLoadPlayerMonSpriteGfx(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], gActiveBattler); species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_SPECIES); - sub_806A068(species, GetBattlerPosition(gActiveBattler)); + SetMultiuseSpriteTemplateToPokemon(species, GetBattlerPosition(gActiveBattler)); - gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gUnknown_0202499C, + gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gMultiuseSpriteTemplate, GetBattlerSpriteCoord(gActiveBattler, 2), GetBattlerSpriteDefault_Y(gActiveBattler), sub_80A82E4(gActiveBattler)); @@ -1241,10 +1241,10 @@ static void sub_81BD0E4(u8 battlerId, bool8 dontClearSubstituteBit) gBattlerPartyIndexes[battlerId] = gBattleBufferA[battlerId][1]; species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[battlerId]], MON_DATA_SPECIES); gUnknown_03005D7C[battlerId] = CreateInvisibleSpriteWithCallback(sub_805D714); - sub_806A068(species, GetBattlerPosition(battlerId)); + SetMultiuseSpriteTemplateToPokemon(species, GetBattlerPosition(battlerId)); gBattlerSpriteIds[battlerId] = CreateSprite( - &gUnknown_0202499C, + &gMultiuseSpriteTemplate, GetBattlerSpriteCoord(battlerId, 2), GetBattlerSpriteDefault_Y(battlerId), sub_80A82E4(battlerId)); @@ -1326,8 +1326,8 @@ static void PlayerPartnerHandleDrawTrainerPic(void) if (gPartnerTrainerId == TRAINER_STEVEN_PARTNER) { DecompressTrainerBackPic(trainerPicId, gActiveBattler); - sub_806A12C(trainerPicId, GetBattlerPosition(gActiveBattler)); - gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gUnknown_0202499C, xPos, yPos, sub_80A82E4(gActiveBattler)); + SetMultiuseSpriteTemplateToTrainerBack(trainerPicId, GetBattlerPosition(gActiveBattler)); + gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gMultiuseSpriteTemplate, xPos, yPos, sub_80A82E4(gActiveBattler)); gSprites[gBattlerSpriteIds[gActiveBattler]].oam.paletteNum = gActiveBattler; gSprites[gBattlerSpriteIds[gActiveBattler]].pos2.x = 240; @@ -1337,8 +1337,8 @@ static void PlayerPartnerHandleDrawTrainerPic(void) else // otherwise use front sprite { DecompressTrainerFrontPic(trainerPicId, gActiveBattler); - sub_806A1C0(trainerPicId, GetBattlerPosition(gActiveBattler)); - gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gUnknown_0202499C, xPos, yPos, sub_80A82E4(gActiveBattler)); + SetMultiuseSpriteTemplateToTrainerFront(trainerPicId, GetBattlerPosition(gActiveBattler)); + gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gMultiuseSpriteTemplate, xPos, yPos, sub_80A82E4(gActiveBattler)); gSprites[gBattlerSpriteIds[gActiveBattler]].oam.paletteNum = IndexOfSpritePaletteTag(gTrainerFrontPicPaletteTable[trainerPicId].tag); gSprites[gBattlerSpriteIds[gActiveBattler]].pos2.x = 240; @@ -1349,7 +1349,7 @@ static void PlayerPartnerHandleDrawTrainerPic(void) gSprites[gBattlerSpriteIds[gActiveBattler]].hFlip = 1; } - gBattlerControllerFuncs[gActiveBattler] = CompleteOnBankSpriteCallbackDummy; + gBattlerControllerFuncs[gActiveBattler] = CompleteOnBattlerSpriteCallbackDummy; } static void PlayerPartnerHandleTrainerSlide(void) diff --git a/src/battle_controller_recorded_opponent.c b/src/battle_controller_recorded_opponent.c index 1fd1deebf..affcb09ab 100644 --- a/src/battle_controller_recorded_opponent.c +++ b/src/battle_controller_recorded_opponent.c @@ -37,7 +37,6 @@ extern u8 gUnknown_0203C7B4; extern const struct CompressedSpritePalette gTrainerFrontPicPaletteTable[]; extern void sub_8172EF0(u8 battlerId, struct Pokemon *mon); -extern void sub_806A068(u16, u8); extern u16 sub_8068B48(void); extern u8 GetFrontierTrainerFrontSpriteId(u16 trainerId); @@ -193,7 +192,7 @@ static void RecordedOpponentBufferRunCommand(void) } } -static void CompleteOnBankSpriteCallbackDummy(void) +static void CompleteOnBattlerSpriteCallbackDummy(void) { if (gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) RecordedOpponentBufferExecCompleted(); @@ -1119,9 +1118,9 @@ static void RecordedOpponentHandleLoadMonSprite(void) u16 species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_SPECIES); BattleLoadOpponentMonSpriteGfx(&gEnemyParty[gBattlerPartyIndexes[gActiveBattler]], gActiveBattler); - sub_806A068(species, GetBattlerPosition(gActiveBattler)); + SetMultiuseSpriteTemplateToPokemon(species, GetBattlerPosition(gActiveBattler)); - gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gUnknown_0202499C, + gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gMultiuseSpriteTemplate, GetBattlerSpriteCoord(gActiveBattler, 2), GetBattlerSpriteDefault_Y(gActiveBattler), sub_80A82E4(gActiveBattler)); @@ -1154,9 +1153,9 @@ static void sub_81885D8(u8 battlerId, bool8 dontClearSubstituteBit) species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[battlerId]], MON_DATA_SPECIES); gUnknown_03005D7C[battlerId] = CreateInvisibleSpriteWithCallback(sub_805D714); BattleLoadOpponentMonSpriteGfx(&gEnemyParty[gBattlerPartyIndexes[battlerId]], battlerId); - sub_806A068(species, GetBattlerPosition(battlerId)); + SetMultiuseSpriteTemplateToPokemon(species, GetBattlerPosition(battlerId)); - gBattlerSpriteIds[battlerId] = CreateSprite(&gUnknown_0202499C, + gBattlerSpriteIds[battlerId] = CreateSprite(&gMultiuseSpriteTemplate, GetBattlerSpriteCoord(battlerId, 2), GetBattlerSpriteDefault_Y(battlerId), sub_80A82E4(battlerId)); @@ -1252,8 +1251,8 @@ static void RecordedOpponentHandleDrawTrainerPic(void) } DecompressTrainerFrontPic(trainerPicId, gActiveBattler); - sub_806A12C(trainerPicId, GetBattlerPosition(gActiveBattler)); - gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gUnknown_0202499C, + SetMultiuseSpriteTemplateToTrainerBack(trainerPicId, GetBattlerPosition(gActiveBattler)); + gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gMultiuseSpriteTemplate, xPos, (8 - gTrainerFrontPicCoords[trainerPicId].coords) * 4 + 40, sub_80A82E4(gActiveBattler)); @@ -1264,7 +1263,7 @@ static void RecordedOpponentHandleDrawTrainerPic(void) gSprites[gBattlerSpriteIds[gActiveBattler]].oam.affineParam = trainerPicId; gSprites[gBattlerSpriteIds[gActiveBattler]].callback = sub_805D7AC; - gBattlerControllerFuncs[gActiveBattler] = CompleteOnBankSpriteCallbackDummy; + gBattlerControllerFuncs[gActiveBattler] = CompleteOnBattlerSpriteCallbackDummy; } static void RecordedOpponentHandleTrainerSlide(void) diff --git a/src/battle_controller_recorded_player.c b/src/battle_controller_recorded_player.c index b6a96b6fd..4f224bc67 100644 --- a/src/battle_controller_recorded_player.c +++ b/src/battle_controller_recorded_player.c @@ -36,7 +36,6 @@ extern const struct CompressedSpritePalette gTrainerFrontPicPaletteTable[]; extern const struct CompressedSpritePalette gTrainerBackPicPaletteTable[]; extern void sub_8172EF0(u8 battlerId, struct Pokemon *mon); -extern void sub_806A068(u16, u8); extern u8 GetFrontierTrainerFrontSpriteId(u16 trainerId); // this file's functions @@ -190,7 +189,7 @@ static void RecordedPlayerBufferRunCommand(void) } } -static void CompleteOnBankSpriteCallbackDummy(void) +static void CompleteOnBattlerSpriteCallbackDummy(void) { if (gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) RecordedPlayerBufferExecCompleted(); @@ -1107,9 +1106,9 @@ static void RecordedPlayerHandleLoadMonSprite(void) BattleLoadPlayerMonSpriteGfx(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], gActiveBattler); species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_SPECIES); - sub_806A068(species, GetBattlerPosition(gActiveBattler)); + SetMultiuseSpriteTemplateToPokemon(species, GetBattlerPosition(gActiveBattler)); - gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gUnknown_0202499C, + gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gMultiuseSpriteTemplate, GetBattlerSpriteCoord(gActiveBattler, 2), GetBattlerSpriteDefault_Y(gActiveBattler), sub_80A82E4(gActiveBattler)); @@ -1137,10 +1136,10 @@ static void sub_818BA6C(u8 battlerId, bool8 dontClearSubstituteBit) gBattlerPartyIndexes[battlerId] = gBattleBufferA[battlerId][1]; species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[battlerId]], MON_DATA_SPECIES); gUnknown_03005D7C[battlerId] = CreateInvisibleSpriteWithCallback(sub_805D714); - sub_806A068(species, GetBattlerPosition(battlerId)); + SetMultiuseSpriteTemplateToPokemon(species, GetBattlerPosition(battlerId)); gBattlerSpriteIds[battlerId] = CreateSprite( - &gUnknown_0202499C, + &gMultiuseSpriteTemplate, GetBattlerSpriteCoord(battlerId, 2), GetBattlerSpriteDefault_Y(battlerId), sub_80A82E4(battlerId)); @@ -1242,8 +1241,8 @@ static void RecordedPlayerHandleDrawTrainerPic(void) { trainerPicId = PlayerGenderToFrontTrainerPicId(gSaveBlock2Ptr->playerGender); DecompressTrainerFrontPic(trainerPicId, gActiveBattler); - sub_806A1C0(trainerPicId, GetBattlerPosition(gActiveBattler)); - gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gUnknown_0202499C, xPos, yPos, sub_80A82E4(gActiveBattler)); + SetMultiuseSpriteTemplateToTrainerFront(trainerPicId, GetBattlerPosition(gActiveBattler)); + gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gMultiuseSpriteTemplate, xPos, yPos, sub_80A82E4(gActiveBattler)); gSprites[gBattlerSpriteIds[gActiveBattler]].oam.paletteNum = IndexOfSpritePaletteTag(gTrainerFrontPicPaletteTable[trainerPicId].tag); gSprites[gBattlerSpriteIds[gActiveBattler]].pos2.x = 240; @@ -1256,8 +1255,8 @@ static void RecordedPlayerHandleDrawTrainerPic(void) else { DecompressTrainerBackPic(trainerPicId, gActiveBattler); - sub_806A12C(trainerPicId, GetBattlerPosition(gActiveBattler)); - gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gUnknown_0202499C, xPos, yPos, sub_80A82E4(gActiveBattler)); + SetMultiuseSpriteTemplateToTrainerBack(trainerPicId, GetBattlerPosition(gActiveBattler)); + gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gMultiuseSpriteTemplate, xPos, yPos, sub_80A82E4(gActiveBattler)); gSprites[gBattlerSpriteIds[gActiveBattler]].oam.paletteNum = gActiveBattler; gSprites[gBattlerSpriteIds[gActiveBattler]].pos2.x = 240; @@ -1265,7 +1264,7 @@ static void RecordedPlayerHandleDrawTrainerPic(void) gSprites[gBattlerSpriteIds[gActiveBattler]].callback = sub_805D7AC; } - gBattlerControllerFuncs[gActiveBattler] = CompleteOnBankSpriteCallbackDummy; + gBattlerControllerFuncs[gActiveBattler] = CompleteOnBattlerSpriteCallbackDummy; } static void RecordedPlayerHandleTrainerSlide(void) diff --git a/src/battle_controller_safari.c b/src/battle_controller_safari.c index bc69e2624..f7be76c9b 100644 --- a/src/battle_controller_safari.c +++ b/src/battle_controller_safari.c @@ -239,7 +239,7 @@ static void HandleInputChooseAction(void) } } -static void CompleteOnBankSpriteCallbackDummy(void) +static void CompleteOnBattlerSpriteCallbackDummy(void) { if (gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) SafariBufferExecCompleted(); @@ -358,9 +358,9 @@ static void SafariHandleReturnMonToBall(void) static void SafariHandleDrawTrainerPic(void) { DecompressTrainerBackPic(gSaveBlock2Ptr->playerGender, gActiveBattler); - sub_806A12C(gSaveBlock2Ptr->playerGender, GetBattlerPosition(gActiveBattler)); + SetMultiuseSpriteTemplateToTrainerBack(gSaveBlock2Ptr->playerGender, GetBattlerPosition(gActiveBattler)); gBattlerSpriteIds[gActiveBattler] = CreateSprite( - &gUnknown_0202499C, + &gMultiuseSpriteTemplate, 80, (8 - gTrainerBackPicCoords[gSaveBlock2Ptr->playerGender].coords) * 4 + 80, 30); @@ -368,7 +368,7 @@ static void SafariHandleDrawTrainerPic(void) gSprites[gBattlerSpriteIds[gActiveBattler]].pos2.x = 240; gSprites[gBattlerSpriteIds[gActiveBattler]].data[0] = -2; gSprites[gBattlerSpriteIds[gActiveBattler]].callback = sub_805D7AC; - gBattlerControllerFuncs[gActiveBattler] = CompleteOnBankSpriteCallbackDummy; + gBattlerControllerFuncs[gActiveBattler] = CompleteOnBattlerSpriteCallbackDummy; } static void SafariHandleTrainerSlide(void) diff --git a/src/battle_controller_wally.c b/src/battle_controller_wally.c index f66a1d773..f024c29c0 100644 --- a/src/battle_controller_wally.c +++ b/src/battle_controller_wally.c @@ -39,7 +39,6 @@ extern struct UnusedControllerStruct gUnknown_02022D0C; extern const struct CompressedSpritePalette gTrainerBackPicPaletteTable[]; extern void sub_8172EF0(u8 battlerId, struct Pokemon *mon); -extern void sub_806A068(u16, u8); // this file's functions static void WallyHandleGetMonData(void); @@ -254,7 +253,7 @@ static void WallyHandleActions(void) } } -static void CompleteOnBankSpriteCallbackDummy(void) +static void CompleteOnBattlerSpriteCallbackDummy(void) { if (gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) WallyBufferExecCompleted(); @@ -1039,8 +1038,8 @@ static void WallyHandleReturnMonToBall(void) static void WallyHandleDrawTrainerPic(void) { DecompressTrainerBackPic(TRAINER_BACK_PIC_WALLY, gActiveBattler); - sub_806A12C(TRAINER_BACK_PIC_WALLY, GetBattlerPosition(gActiveBattler)); - gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gUnknown_0202499C, + SetMultiuseSpriteTemplateToTrainerBack(TRAINER_BACK_PIC_WALLY, GetBattlerPosition(gActiveBattler)); + gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gMultiuseSpriteTemplate, 80, 80 + 4 * (8 - gTrainerBackPicCoords[TRAINER_BACK_PIC_WALLY].coords), 30); @@ -1048,14 +1047,14 @@ static void WallyHandleDrawTrainerPic(void) gSprites[gBattlerSpriteIds[gActiveBattler]].pos2.x = 240; gSprites[gBattlerSpriteIds[gActiveBattler]].data[0] = -2; gSprites[gBattlerSpriteIds[gActiveBattler]].callback = sub_805D7AC; - gBattlerControllerFuncs[gActiveBattler] = CompleteOnBankSpriteCallbackDummy; + gBattlerControllerFuncs[gActiveBattler] = CompleteOnBattlerSpriteCallbackDummy; } static void WallyHandleTrainerSlide(void) { DecompressTrainerBackPic(TRAINER_BACK_PIC_WALLY, gActiveBattler); - sub_806A12C(TRAINER_BACK_PIC_WALLY, GetBattlerPosition(gActiveBattler)); - gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gUnknown_0202499C, + SetMultiuseSpriteTemplateToTrainerBack(TRAINER_BACK_PIC_WALLY, GetBattlerPosition(gActiveBattler)); + gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gMultiuseSpriteTemplate, 80, 80 + 4 * (8 - gTrainerBackPicCoords[TRAINER_BACK_PIC_WALLY].coords), 30); @@ -1466,8 +1465,8 @@ static void sub_816AA80(u8 battlerId) gBattlerPartyIndexes[battlerId] = gBattleBufferA[battlerId][1]; species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[battlerId]], MON_DATA_SPECIES); gUnknown_03005D7C[battlerId] = CreateInvisibleSpriteWithCallback(sub_805D714); - sub_806A068(species, GetBattlerPosition(battlerId)); - gBattlerSpriteIds[battlerId] = CreateSprite(&gUnknown_0202499C, + SetMultiuseSpriteTemplateToPokemon(species, GetBattlerPosition(battlerId)); + gBattlerSpriteIds[battlerId] = CreateSprite(&gMultiuseSpriteTemplate, GetBattlerSpriteCoord(battlerId, 2), GetBattlerSpriteDefault_Y(battlerId), sub_80A82E4(battlerId)); diff --git a/src/battle_dome_cards.c b/src/battle_dome_cards.c index 076a4d342..5e659a2e8 100644 --- a/src/battle_dome_cards.c +++ b/src/battle_dome_cards.c @@ -16,14 +16,15 @@ extern const struct CompressedSpriteSheet gTrainerBackPicTable[]; extern const struct CompressedSpritePalette gTrainerFrontPicPaletteTable[]; extern const union AffineAnimCmd *const gUnknown_082FF618[]; extern const union AffineAnimCmd *const gUnknown_082FF694[]; -extern const union AnimCmd *const gUnknown_082FF70C[]; +extern const union AnimCmd *const gPlayerMonSpriteAnimsTable[]; extern const union AnimCmd *const *const gMonAnimationsSpriteAnimsPtrTable[NUM_SPECIES]; extern const union AnimCmd *const *const gUnknown_0830536C[]; extern const u8 gFacilityClassToPicIndex[]; // Static type declarations -struct BattleDomeCard { +struct BattleDomeCard +{ u8 *frames; struct SpriteFrameImage *images; u16 paletteTag; @@ -41,10 +42,12 @@ static EWRAM_DATA struct BattleDomeCard gUnknown_0203CD04[8] = {}; // .rodata static const struct BattleDomeCard gUnknown_0860B058 = {}; -static const struct OamData gUnknown_0860B064 = { +static const struct OamData gUnknown_0860B064 = +{ .size = 3 }; -static const struct OamData gUnknown_0860B06C = { +static const struct OamData gUnknown_0860B06C = +{ .affineMode = 1, .size = 3 }; @@ -158,7 +161,7 @@ static void uns_builder_assign_animtable1(bool8 isTrainer) { if (!isTrainer) { - gUnknown_0203CCEC.anims = gUnknown_082FF70C; + gUnknown_0203CCEC.anims = gPlayerMonSpriteAnimsTable; } else { diff --git a/src/battle_main.c b/src/battle_main.c index 9bec15750..591c299d7 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -300,6 +300,7 @@ u8 gNumberOfMovesToChoose; u8 gUnknown_03005D7C[MAX_BATTLERS_COUNT]; // rom const data +static const s8 gUnknown_0831ACE0[] ={-32, -16, -16, -32, -32, 0, 0, 0}; // format: attacking type, defending type, damage multiplier // the multiplier is a (decimal) fixed-point number: @@ -307,9 +308,6 @@ u8 gUnknown_03005D7C[MAX_BATTLERS_COUNT]; // 10 is ×1.0 TYPE_MUL_NORMAL // 05 is ×0.5 TYPE_MUL_NOT_EFFECTIVE // 00 is ×0.0 TYPE_MUL_NO_EFFECT - -static const s8 gUnknown_0831ACE0[] ={-32, -16, -16, -32, -32, 0, 0, 0}; - const u8 gTypeEffectiveness[336] = { TYPE_NORMAL, TYPE_ROCK, TYPE_MUL_NOT_EFFECTIVE, @@ -2808,7 +2806,7 @@ void sub_8039BB4(struct Sprite *sprite) static void oac_poke_ally_(struct Sprite *sprite) { - if ((gIntroSlideFlags & 1) == 0) + if (!(gIntroSlideFlags & 1)) { sprite->pos2.x -= 2; if (sprite->pos2.x == 0) diff --git a/src/egg_hatch.c b/src/egg_hatch.c index 00e6236fe..1e89650d3 100644 --- a/src/egg_hatch.c +++ b/src/egg_hatch.c @@ -57,12 +57,10 @@ extern const u8 gText_NickHatchPrompt[]; extern u8 sav1_map_get_name(void); extern void TVShowConvertInternationalString(u8* str1, u8* str2, u8); -extern void sub_806A068(u16, u8); extern void FadeScreen(u8, u8); extern void overworld_free_bg_tilemaps(void); extern void sub_80AF168(void); extern void ScanlineEffect_Stop(void); -extern void CB2_ReturnToField(void); extern void play_some_sound(void); extern void DoNamingScreen(u8, const u8*, u16, u8, u32, MainCallback); extern u16 sub_80D22D0(void); @@ -437,8 +435,8 @@ static u8 EggHatchCreateMonSprite(u8 a0, u8 switchID, u8 pokeID, u16* speciesLoc } break; case 1: - sub_806A068(GetMonSpritePalStruct(mon)->tag, r5); - spriteID = CreateSprite(&gUnknown_0202499C, 120, 75, 6); + SetMultiuseSpriteTemplateToPokemon(GetMonSpritePalStruct(mon)->tag, r5); + spriteID = CreateSprite(&gMultiuseSpriteTemplate, 120, 75, 6); gSprites[spriteID].invisible = 1; gSprites[spriteID].callback = SpriteCallbackDummy; break; diff --git a/src/evolution_scene.c b/src/evolution_scene.c index 84f00418c..7079375f8 100644 --- a/src/evolution_scene.c +++ b/src/evolution_scene.c @@ -62,7 +62,6 @@ extern const u8 gText_CommunicationStandby5[]; extern void sub_80356D0(void); extern void sub_807B154(void); -extern void sub_806A068(u16, u8); extern void sub_807F19C(void); extern void sub_807B140(void); extern void EvolutionRenameMon(struct Pokemon *mon, u16 oldSpecies, u16 newSpecies); @@ -280,9 +279,9 @@ void EvolutionScene(struct Pokemon* mon, u16 speciesToEvolve, bool8 canStopEvo, pokePal = GetMonSpritePalStructFromOtIdPersonality(currSpecies, trainerId, personality); LoadCompressedPalette(pokePal->data, 0x110, 0x20); - sub_806A068(currSpecies, 1); - gUnknown_0202499C.affineAnims = gDummySpriteAffineAnimTable; - sEvoStructPtr->preEvoSpriteID = ID = CreateSprite(&gUnknown_0202499C, 120, 64, 30); + SetMultiuseSpriteTemplateToPokemon(currSpecies, 1); + gMultiuseSpriteTemplate.affineAnims = gDummySpriteAffineAnimTable; + sEvoStructPtr->preEvoSpriteID = ID = CreateSprite(&gMultiuseSpriteTemplate, 120, 64, 30); gSprites[ID].callback = SpriteCallbackDummy_2; gSprites[ID].oam.paletteNum = 1; @@ -295,9 +294,9 @@ void EvolutionScene(struct Pokemon* mon, u16 speciesToEvolve, bool8 canStopEvo, pokePal = GetMonSpritePalStructFromOtIdPersonality(speciesToEvolve, trainerId, personality); LoadCompressedPalette(pokePal->data, 0x120, 0x20); - sub_806A068(speciesToEvolve, 3); - gUnknown_0202499C.affineAnims = gDummySpriteAffineAnimTable; - sEvoStructPtr->postEvoSpriteID = ID = CreateSprite(&gUnknown_0202499C, 120, 64, 30); + SetMultiuseSpriteTemplateToPokemon(speciesToEvolve, 3); + gMultiuseSpriteTemplate.affineAnims = gDummySpriteAffineAnimTable; + sEvoStructPtr->postEvoSpriteID = ID = CreateSprite(&gMultiuseSpriteTemplate, 120, 64, 30); gSprites[ID].callback = SpriteCallbackDummy_2; gSprites[ID].oam.paletteNum = 2; gSprites[ID].invisible = 1; @@ -373,9 +372,9 @@ static void CB2_EvolutionSceneLoadGraphics(void) LoadCompressedPalette(pokePal->data, 0x120, 0x20); - sub_806A068(postEvoSpecies, 3); - gUnknown_0202499C.affineAnims = gDummySpriteAffineAnimTable; - sEvoStructPtr->postEvoSpriteID = ID = CreateSprite(&gUnknown_0202499C, 120, 64, 30); + SetMultiuseSpriteTemplateToPokemon(postEvoSpecies, 3); + gMultiuseSpriteTemplate.affineAnims = gDummySpriteAffineAnimTable; + sEvoStructPtr->postEvoSpriteID = ID = CreateSprite(&gMultiuseSpriteTemplate, 120, 64, 30); gSprites[ID].callback = SpriteCallbackDummy_2; gSprites[ID].oam.paletteNum = 2; @@ -450,9 +449,9 @@ static void CB2_TradeEvolutionSceneLoadGraphics(void) { u8 ID; - sub_806A068(postEvoSpecies, 1); - gUnknown_0202499C.affineAnims = gDummySpriteAffineAnimTable; - sEvoStructPtr->postEvoSpriteID = ID = CreateSprite(&gUnknown_0202499C, 120, 64, 30); + SetMultiuseSpriteTemplateToPokemon(postEvoSpecies, 1); + gMultiuseSpriteTemplate.affineAnims = gDummySpriteAffineAnimTable; + sEvoStructPtr->postEvoSpriteID = ID = CreateSprite(&gMultiuseSpriteTemplate, 120, 64, 30); gSprites[ID].callback = SpriteCallbackDummy_2; gSprites[ID].oam.paletteNum = 2; @@ -509,9 +508,9 @@ void TradeEvolutionScene(struct Pokemon* mon, u16 speciesToEvolve, u8 preEvoSpri pokePal = GetMonSpritePalStructFromOtIdPersonality(speciesToEvolve, trainerId, personality); LoadCompressedPalette(pokePal->data, 0x120, 0x20); - sub_806A068(speciesToEvolve, 1); - gUnknown_0202499C.affineAnims = gDummySpriteAffineAnimTable; - sEvoStructPtr->postEvoSpriteID = ID = CreateSprite(&gUnknown_0202499C, 120, 64, 30); + SetMultiuseSpriteTemplateToPokemon(speciesToEvolve, 1); + gMultiuseSpriteTemplate.affineAnims = gDummySpriteAffineAnimTable; + sEvoStructPtr->postEvoSpriteID = ID = CreateSprite(&gMultiuseSpriteTemplate, 120, 64, 30); gSprites[ID].callback = SpriteCallbackDummy_2; gSprites[ID].oam.paletteNum = 2; diff --git a/src/pokeblock_feed.c b/src/pokeblock_feed.c index d3fdbd355..7ce7affcc 100644 --- a/src/pokeblock_feed.c +++ b/src/pokeblock_feed.c @@ -58,7 +58,6 @@ extern const struct CompressedSpriteSheet gMonFrontPicTable[]; extern const u16 gUnknown_0860F074[]; extern bool8 sub_81221EC(void); -extern void sub_806A068(u16, u8); extern void LoadSav2WindowGfx(u8, u16, u8); // this file's functions @@ -661,7 +660,7 @@ static bool8 LoadMonAndSceneGfx(struct Pokemon *mon) palette = GetMonSpritePalStructFromOtIdPersonality(species, trainerId, personality); LoadCompressedObjectPalette(palette); - sub_806A068(palette->tag, 1); + SetMultiuseSpriteTemplateToPokemon(palette->tag, 1); sPokeblockFeed->loadGfxState++; break; case 2: @@ -827,7 +826,7 @@ static void Task_PaletteFadeToReturn(u8 taskId) static u8 CreateMonSprite(struct Pokemon* mon) { u16 species = GetMonData(mon, MON_DATA_SPECIES2); - u8 spriteId = CreateSprite(&gUnknown_0202499C, 48, 80, 2); + u8 spriteId = CreateSprite(&gMultiuseSpriteTemplate, 48, 80, 2); sPokeblockFeed->species = species; sPokeblockFeed->monSpriteId_ = spriteId; diff --git a/src/pokemon.c b/src/pokemon.c index d06da3e9e..80c1ab784 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -63,7 +63,7 @@ extern const struct SpriteFrameImage gUnknown_082FF4F8[]; extern const struct SpriteFrameImage gUnknown_082FF518[]; extern const union AffineAnimCmd *const gUnknown_082FF618[]; extern const union AffineAnimCmd *const gUnknown_082FF694[]; -extern const union AnimCmd *gUnknown_082FF70C[]; +extern const union AnimCmd *gPlayerMonSpriteAnimsTable[]; extern const union AnimCmd *const *const gMonAnimationsSpriteAnimsPtrTable[]; extern const union AnimCmd *const *const gUnknown_08305D0C[]; extern const union AnimCmd *const *const gUnknown_0830536C[]; @@ -105,7 +105,7 @@ EWRAM_DATA u8 gPlayerPartyCount = 0; EWRAM_DATA u8 gEnemyPartyCount = 0; EWRAM_DATA struct Pokemon gPlayerParty[PARTY_SIZE] = {0}; EWRAM_DATA struct Pokemon gEnemyParty[PARTY_SIZE] = {0}; -EWRAM_DATA struct SpriteTemplate gUnknown_0202499C = {0}; +EWRAM_DATA struct SpriteTemplate gMultiuseSpriteTemplate = {0}; EWRAM_DATA struct Unknown_806F160_Struct *gUnknown_020249B4[2] = {NULL}; // const rom data @@ -2486,13 +2486,14 @@ static bool8 ShouldGetStatBadgeBoost(u16 badgeFlag, u8 battlerId) { if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_EREADER_TRAINER | BATTLE_TYPE_x2000000 | BATTLE_TYPE_FRONTIER)) return FALSE; - if (GetBattlerSide(battlerId) != B_SIDE_PLAYER) + else if (GetBattlerSide(battlerId) != B_SIDE_PLAYER) return FALSE; - if (gBattleTypeFlags & BATTLE_TYPE_TRAINER && gTrainerBattleOpponent_A == TRAINER_SECRET_BASE) + else if (gBattleTypeFlags & BATTLE_TYPE_TRAINER && gTrainerBattleOpponent_A == TRAINER_SECRET_BASE) return FALSE; - if (FlagGet(badgeFlag)) + else if (FlagGet(badgeFlag)) return TRUE; - return FALSE; + else + return FALSE; } u8 GetDefaultMoveTarget(u8 battlerId) @@ -2561,53 +2562,53 @@ u8 GetGenderFromSpeciesAndPersonality(u16 species, u32 personality) return MON_MALE; } -void sub_806A068(u16 species, u8 battlerPosition) +void SetMultiuseSpriteTemplateToPokemon(u16 species, u8 battlerPosition) { if (gMonSpritesGfxPtr != NULL) - gUnknown_0202499C = gMonSpritesGfxPtr->templates[battlerPosition]; + gMultiuseSpriteTemplate = gMonSpritesGfxPtr->templates[battlerPosition]; else if (gUnknown_020249B4[0]) - gUnknown_0202499C = gUnknown_020249B4[0]->templates[battlerPosition]; + gMultiuseSpriteTemplate = gUnknown_020249B4[0]->templates[battlerPosition]; else if (gUnknown_020249B4[1]) - gUnknown_0202499C = gUnknown_020249B4[1]->templates[battlerPosition]; + gMultiuseSpriteTemplate = gUnknown_020249B4[1]->templates[battlerPosition]; else - gUnknown_0202499C = gUnknown_08329D98[battlerPosition]; + gMultiuseSpriteTemplate = gUnknown_08329D98[battlerPosition]; - gUnknown_0202499C.paletteTag = species; - if (battlerPosition == 0 || battlerPosition == 2) - gUnknown_0202499C.anims = gUnknown_082FF70C; + gMultiuseSpriteTemplate.paletteTag = species; + if (battlerPosition == B_POSITION_PLAYER_LEFT || battlerPosition == B_POSITION_PLAYER_RIGHT) + gMultiuseSpriteTemplate.anims = gPlayerMonSpriteAnimsTable; else if (species > 500) - gUnknown_0202499C.anims = gMonAnimationsSpriteAnimsPtrTable[species - 500]; + gMultiuseSpriteTemplate.anims = gMonAnimationsSpriteAnimsPtrTable[species - 500]; else - gUnknown_0202499C.anims = gMonAnimationsSpriteAnimsPtrTable[species]; + gMultiuseSpriteTemplate.anims = gMonAnimationsSpriteAnimsPtrTable[species]; } -void sub_806A12C(u16 trainerSpriteId, u8 battlerPosition) +void SetMultiuseSpriteTemplateToTrainerBack(u16 trainerSpriteId, u8 battlerPosition) { - gUnknown_0202499C.paletteTag = trainerSpriteId; + gMultiuseSpriteTemplate.paletteTag = trainerSpriteId; if (battlerPosition == B_POSITION_PLAYER_LEFT || battlerPosition == B_POSITION_PLAYER_RIGHT) { - gUnknown_0202499C = gUnknown_08329DF8[trainerSpriteId]; - gUnknown_0202499C.anims = gUnknown_08305D0C[trainerSpriteId]; + gMultiuseSpriteTemplate = gUnknown_08329DF8[trainerSpriteId]; + gMultiuseSpriteTemplate.anims = gUnknown_08305D0C[trainerSpriteId]; } else { if (gMonSpritesGfxPtr != NULL) - gUnknown_0202499C = gMonSpritesGfxPtr->templates[battlerPosition]; + gMultiuseSpriteTemplate = gMonSpritesGfxPtr->templates[battlerPosition]; else - gUnknown_0202499C = gUnknown_08329D98[battlerPosition]; - gUnknown_0202499C.anims = gUnknown_0830536C[trainerSpriteId]; + gMultiuseSpriteTemplate = gUnknown_08329D98[battlerPosition]; + gMultiuseSpriteTemplate.anims = gUnknown_0830536C[trainerSpriteId]; } } -void sub_806A1C0(u16 arg0, u8 battlerPosition) +void SetMultiuseSpriteTemplateToTrainerFront(u16 arg0, u8 battlerPosition) { if (gMonSpritesGfxPtr != NULL) - gUnknown_0202499C = gMonSpritesGfxPtr->templates[battlerPosition]; + gMultiuseSpriteTemplate = gMonSpritesGfxPtr->templates[battlerPosition]; else - gUnknown_0202499C = gUnknown_08329D98[battlerPosition]; + gMultiuseSpriteTemplate = gUnknown_08329D98[battlerPosition]; - gUnknown_0202499C.paletteTag = arg0; - gUnknown_0202499C.anims = gUnknown_0830536C[arg0]; + gMultiuseSpriteTemplate.paletteTag = arg0; + gMultiuseSpriteTemplate.anims = gUnknown_0830536C[arg0]; } static void EncryptBoxMon(struct BoxPokemon *boxMon) @@ -3136,7 +3137,8 @@ u32 GetBoxMonData(struct BoxPokemon *boxMon, s32 field, u8 *data) void SetMonData(struct Pokemon *mon, s32 field, const void *dataArg) { - const u8* data = dataArg; + const u8 *data = dataArg; + switch (field) { case MON_DATA_STATUS: @@ -3179,7 +3181,7 @@ void SetMonData(struct Pokemon *mon, s32 field, const void *dataArg) void SetBoxMonData(struct BoxPokemon *boxMon, s32 field, const void *dataArg) { - const u8* data = dataArg; + const u8 *data = dataArg; struct PokemonSubstruct0 *substruct0 = NULL; struct PokemonSubstruct1 *substruct1 = NULL; @@ -4511,7 +4513,7 @@ u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 type, u16 evolutionItem) else holdEffect = ItemId_GetHoldEffect(heldItem); - if (holdEffect == 38 && type != 3) + if (holdEffect == HOLD_EFFECT_PREVENT_EVOLVE && type != 3) return 0; switch (type) @@ -4849,16 +4851,17 @@ u8 GetTrainerEncounterMusicId(u16 trainerOpponentId) { if (InBattlePyramid()) return GetTrainerEncounterMusicIdInBattlePyramind(trainerOpponentId); - if (sub_81D5C18()) + else if (sub_81D5C18()) return sub_81D63C8(trainerOpponentId); - return TRAINER_ENCOUNTER_MUSIC(trainerOpponentId); + else + return TRAINER_ENCOUNTER_MUSIC(trainerOpponentId); } u16 ModifyStatByNature(u8 nature, u16 n, u8 statIndex) { if (statIndex < 1 || statIndex > 5) { - // should just be "return n", but it wouldn't match without this + // Should just be "return n", but it wouldn't match without this. u16 retVal = n; retVal++; retVal--; @@ -5165,7 +5168,7 @@ void PartySpreadPokerus(struct Pokemon *party) { if (pokerus & 0xF) { - // spread to adjacent party members + // Spread to adjacent party members. if (i != 0 && !(GetMonData(&party[i - 1], MON_DATA_POKERUS, 0) & 0xF0)) SetMonData(&party[i - 1], MON_DATA_POKERUS, &curPokerus); if (i != (PARTY_SIZE - 1) && !(GetMonData(&party[i + 1], MON_DATA_POKERUS, 0) & 0xF0)) @@ -5365,11 +5368,11 @@ u16 GetBattleBGM(void) { if (gBattleTypeFlags & BATTLE_TYPE_KYOGRE_GROUDON) return MUS_BATTLE34; - if (gBattleTypeFlags & BATTLE_TYPE_REGI) + else if (gBattleTypeFlags & BATTLE_TYPE_REGI) return MUS_BATTLE36; - if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000)) + else if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000)) return MUS_BATTLE20; - if (gBattleTypeFlags & BATTLE_TYPE_TRAINER) + else if (gBattleTypeFlags & BATTLE_TYPE_TRAINER) { u8 trainerClass; @@ -5414,7 +5417,8 @@ u16 GetBattleBGM(void) return MUS_BATTLE20; } } - return MUS_BATTLE27; + else + return MUS_BATTLE27; } void PlayBattleBGM(void) @@ -5948,7 +5952,7 @@ static void sub_806F1FC(struct Unknown_806F160_Struct* structPtr) structPtr->frameImages[i * structPtr->field_0_0 + j].data = &structPtr->byteArrays[i][j * 0x800]; } structPtr->templates[i].images = &structPtr->frameImages[i * structPtr->field_0_0]; - structPtr->templates[i].anims = gUnknown_082FF70C; + structPtr->templates[i].anims = gPlayerMonSpriteAnimsTable; structPtr->templates[i].paletteTag = i; } } diff --git a/src/reshow_battle_screen.c b/src/reshow_battle_screen.c index 4d5240bc7..60580ef2d 100644 --- a/src/reshow_battle_screen.c +++ b/src/reshow_battle_screen.c @@ -27,8 +27,7 @@ extern u16 gBattle_BG3_Y; extern const union AnimCmd * const * const gMonAnimationsSpriteAnimsPtrTable[]; -extern void sub_806A068(u16 species, u8 battlerPosition); -extern void sub_806A12C(u16 backPicId, u8 battlerPosition); +extern void SetMultiuseSpriteTemplateToTrainerBack(u16 backPicId, u8 battlerPosition); // this file's functions static void CB2_ReshowBattleScreenAfterMenu(void); @@ -235,8 +234,8 @@ static void CreateBattlerSprite(u8 battler) if (GetMonData(&gEnemyParty[gBattlerPartyIndexes[battler]], MON_DATA_HP) == 0) return; - sub_806A068(GetMonData(&gEnemyParty[gBattlerPartyIndexes[battler]], MON_DATA_SPECIES), GetBattlerPosition(battler)); - gBattlerSpriteIds[battler] = CreateSprite(&gUnknown_0202499C, GetBattlerSpriteCoord(battler, 2), posY, sub_80A82E4(battler)); + SetMultiuseSpriteTemplateToPokemon(GetMonData(&gEnemyParty[gBattlerPartyIndexes[battler]], MON_DATA_SPECIES), GetBattlerPosition(battler)); + gBattlerSpriteIds[battler] = CreateSprite(&gMultiuseSpriteTemplate, GetBattlerSpriteCoord(battler, 2), posY, sub_80A82E4(battler)); gSprites[gBattlerSpriteIds[battler]].oam.paletteNum = battler; gSprites[gBattlerSpriteIds[battler]].callback = SpriteCallbackDummy; gSprites[gBattlerSpriteIds[battler]].data[0] = battler; @@ -248,8 +247,8 @@ static void CreateBattlerSprite(u8 battler) } else if (gBattleTypeFlags & BATTLE_TYPE_SAFARI && battler == B_POSITION_PLAYER_LEFT) { - sub_806A12C(gSaveBlock2Ptr->playerGender, GetBattlerPosition(B_POSITION_PLAYER_LEFT)); - gBattlerSpriteIds[battler] = CreateSprite(&gUnknown_0202499C, 0x50, + SetMultiuseSpriteTemplateToTrainerBack(gSaveBlock2Ptr->playerGender, GetBattlerPosition(B_POSITION_PLAYER_LEFT)); + gBattlerSpriteIds[battler] = CreateSprite(&gMultiuseSpriteTemplate, 0x50, (8 - gTrainerBackPicCoords[gSaveBlock2Ptr->playerGender].coords) * 4 + 80, sub_80A82E4(0)); gSprites[gBattlerSpriteIds[battler]].oam.paletteNum = battler; @@ -258,8 +257,8 @@ static void CreateBattlerSprite(u8 battler) } else if (gBattleTypeFlags & BATTLE_TYPE_WALLY_TUTORIAL && battler == B_POSITION_PLAYER_LEFT) { - sub_806A12C(TRAINER_BACK_PIC_WALLY, GetBattlerPosition(0)); - gBattlerSpriteIds[battler] = CreateSprite(&gUnknown_0202499C, 0x50, + SetMultiuseSpriteTemplateToTrainerBack(TRAINER_BACK_PIC_WALLY, GetBattlerPosition(0)); + gBattlerSpriteIds[battler] = CreateSprite(&gMultiuseSpriteTemplate, 0x50, (8 - gTrainerBackPicCoords[TRAINER_BACK_PIC_WALLY].coords) * 4 + 80, sub_80A82E4(0)); gSprites[gBattlerSpriteIds[battler]].oam.paletteNum = battler; @@ -271,8 +270,8 @@ static void CreateBattlerSprite(u8 battler) if (GetMonData(&gPlayerParty[gBattlerPartyIndexes[battler]], MON_DATA_HP) == 0) return; - sub_806A068(GetMonData(&gPlayerParty[gBattlerPartyIndexes[battler]], MON_DATA_SPECIES), GetBattlerPosition(battler)); - gBattlerSpriteIds[battler] = CreateSprite(&gUnknown_0202499C, GetBattlerSpriteCoord(battler, 2), posY, sub_80A82E4(battler)); + SetMultiuseSpriteTemplateToPokemon(GetMonData(&gPlayerParty[gBattlerPartyIndexes[battler]], MON_DATA_SPECIES), GetBattlerPosition(battler)); + gBattlerSpriteIds[battler] = CreateSprite(&gMultiuseSpriteTemplate, GetBattlerSpriteCoord(battler, 2), posY, sub_80A82E4(battler)); gSprites[gBattlerSpriteIds[battler]].oam.paletteNum = battler; gSprites[gBattlerSpriteIds[battler]].callback = SpriteCallbackDummy; gSprites[gBattlerSpriteIds[battler]].data[0] = battler; From e6d67c7c2299a0c6fa7ec79fa1427c4a1277a6f7 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 1 Jul 2018 15:45:47 +0200 Subject: [PATCH 10/15] give labels to player controller functions --- src/battle_controller_player.c | 66 +++++++++++++++++----------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index ef45b60cd..992d8656c 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -122,11 +122,11 @@ static void HandleMoveSwitchting(void); static void sub_8058FC0(void); static void sub_8059828(void); static void CompleteWhenChoseItem(void); -static void sub_8059544(u8 taskId); +static void Task_LaunchLvlUpAnim(u8 taskId); static void Task_PrepareToGiveExpWithExpBar(u8 taskId); static void DestroyExpTaskAndCompleteOnInactiveTextPrinter(u8 taskId); static void sub_8059400(u8 taskId); -static void sub_80595A4(u8 taskId); +static void Task_UpdateLvlInHealthbox(u8 taskId); static void PrintLinkStandbyMsg(void); static u32 CopyPlayerMonData(u8 monId, u8 *dst); static void SetPlayerMonData(u8 monId); @@ -1143,16 +1143,16 @@ static void CompleteOnInactiveTextPrinter(void) #define tExpTask_monId data[0] #define tExpTask_gainedExp data[1] -#define tExpTask_bank data[2] +#define tExpTask_battler data[2] #define tExpTask_frames data[10] static void Task_GiveExpToMon(u8 taskId) { u32 monId = (u8)(gTasks[taskId].tExpTask_monId); - u8 battlerId = gTasks[taskId].tExpTask_bank; + u8 battlerId = gTasks[taskId].tExpTask_battler; s16 gainedExp = gTasks[taskId].tExpTask_gainedExp; - if (IsDoubleBattle() == TRUE || monId != gBattlerPartyIndexes[battlerId]) // give exp without the expbar + if (IsDoubleBattle() == TRUE || monId != gBattlerPartyIndexes[battlerId]) // Give exp without moving the expbar. { struct Pokemon *mon = &gPlayerParty[monId]; u16 species = GetMonData(mon, MON_DATA_SPECIES); @@ -1162,19 +1162,19 @@ static void Task_GiveExpToMon(u8 taskId) if (currExp + gainedExp >= nextLvlExp) { - u8 savedActiveBank; + u8 savedActiveBattler; SetMonData(mon, MON_DATA_EXP, &nextLvlExp); CalculateMonStats(mon); gainedExp -= nextLvlExp - currExp; - savedActiveBank = gActiveBattler; + savedActiveBattler = gActiveBattler; gActiveBattler = battlerId; BtlController_EmitTwoReturnValues(1, RET_VALUE_LEVELLED_UP, gainedExp); - gActiveBattler = savedActiveBank; + gActiveBattler = savedActiveBattler; if (IsDoubleBattle() == TRUE && ((u16)(monId) == gBattlerPartyIndexes[battlerId] || (u16)(monId) == gBattlerPartyIndexes[battlerId ^ BIT_FLANK])) - gTasks[taskId].func = sub_8059544; + gTasks[taskId].func = Task_LaunchLvlUpAnim; else gTasks[taskId].func = DestroyExpTaskAndCompleteOnInactiveTextPrinter; } @@ -1196,7 +1196,7 @@ static void Task_PrepareToGiveExpWithExpBar(u8 taskId) { u8 monIndex = gTasks[taskId].tExpTask_monId; s32 gainedExp = gTasks[taskId].tExpTask_gainedExp; - u8 battlerId = gTasks[taskId].tExpTask_bank; + u8 battlerId = gTasks[taskId].tExpTask_battler; struct Pokemon *mon = &gPlayerParty[monIndex]; u8 level = GetMonData(mon, MON_DATA_LEVEL); u16 species = GetMonData(mon, MON_DATA_SPECIES); @@ -1221,12 +1221,12 @@ static void sub_8059400(u8 taskId) { u8 monId = gTasks[taskId].tExpTask_monId; s16 gainedExp = gTasks[taskId].tExpTask_gainedExp; - u8 battlerId = gTasks[taskId].tExpTask_bank; - s16 r4; + u8 battlerId = gTasks[taskId].tExpTask_battler; + s16 newExpPoints; - r4 = MoveBattleBar(battlerId, gHealthboxSpriteIds[battlerId], EXP_BAR, 0); + newExpPoints = MoveBattleBar(battlerId, gHealthboxSpriteIds[battlerId], EXP_BAR, 0); SetHealthboxSpriteVisible(gHealthboxSpriteIds[battlerId]); - if (r4 == -1) + if (newExpPoints == -1) // The bar has been filled with given exp points. { u8 level; s32 currExp; @@ -1241,16 +1241,16 @@ static void sub_8059400(u8 taskId) if (currExp + gainedExp >= expOnNextLvl) { - u8 savedActiveBank; + u8 savedActiveBattler; SetMonData(&gPlayerParty[monId], MON_DATA_EXP, &expOnNextLvl); CalculateMonStats(&gPlayerParty[monId]); gainedExp -= expOnNextLvl - currExp; - savedActiveBank = gActiveBattler; + savedActiveBattler = gActiveBattler; gActiveBattler = battlerId; BtlController_EmitTwoReturnValues(1, RET_VALUE_LEVELLED_UP, gainedExp); - gActiveBattler = savedActiveBank; - gTasks[taskId].func = sub_8059544; + gActiveBattler = savedActiveBattler; + gTasks[taskId].func = Task_LaunchLvlUpAnim; } else { @@ -1263,27 +1263,27 @@ static void sub_8059400(u8 taskId) } } -static void sub_8059544(u8 taskId) +static void Task_LaunchLvlUpAnim(u8 taskId) { - u8 battlerId = gTasks[taskId].tExpTask_bank; + u8 battlerId = gTasks[taskId].tExpTask_battler; u8 monIndex = gTasks[taskId].tExpTask_monId; if (IsDoubleBattle() == TRUE && monIndex == gBattlerPartyIndexes[battlerId ^ BIT_FLANK]) battlerId ^= BIT_FLANK; InitAndLaunchSpecialAnimation(battlerId, battlerId, battlerId, B_ANIM_LVL_UP); - gTasks[taskId].func = sub_80595A4; + gTasks[taskId].func = Task_UpdateLvlInHealthbox; } -static void sub_80595A4(u8 taskId) +static void Task_UpdateLvlInHealthbox(u8 taskId) { - u8 battlerId = gTasks[taskId].tExpTask_bank; + u8 battlerId = gTasks[taskId].tExpTask_battler; if (!gBattleSpritesDataPtr->healthBoxesData[battlerId].specialAnimActive) { u8 monIndex = gTasks[taskId].tExpTask_monId; - GetMonData(&gPlayerParty[monIndex], MON_DATA_LEVEL); // Unused return value + GetMonData(&gPlayerParty[monIndex], MON_DATA_LEVEL); // Unused return value. if (IsDoubleBattle() == TRUE && monIndex == gBattlerPartyIndexes[battlerId ^ BIT_FLANK]) UpdateHealthboxAttribute(gHealthboxSpriteIds[battlerId ^ BIT_FLANK], &gPlayerParty[monIndex], HEALTHBOX_ALL); @@ -1300,8 +1300,8 @@ static void DestroyExpTaskAndCompleteOnInactiveTextPrinter(u8 taskId) u8 battlerId; monIndex = gTasks[taskId].tExpTask_monId; - GetMonData(&gPlayerParty[monIndex], MON_DATA_LEVEL); // Unused return value - battlerId = gTasks[taskId].tExpTask_bank; + GetMonData(&gPlayerParty[monIndex], MON_DATA_LEVEL); // Unused return value. + battlerId = gTasks[taskId].tExpTask_battler; gBattlerControllerFuncs[battlerId] = CompleteOnInactiveTextPrinter; DestroyTask(taskId); } @@ -2466,7 +2466,7 @@ static void PlayerHandleMoveAnimation(void) gWeatherMoveAnim = gBattleBufferA[gActiveBattler][12] | (gBattleBufferA[gActiveBattler][13] << 8); gAnimDisableStructPtr = (struct DisableStruct *)&gBattleBufferA[gActiveBattler][16]; gTransformedPersonalities[gActiveBattler] = gAnimDisableStructPtr->transformedMonPersonality; - if (IsMoveWithoutAnimation(move, gAnimMoveTurn)) // always returns FALSE + if (IsMoveWithoutAnimation(move, gAnimMoveTurn)) // Always returns FALSE. { PlayerBufferExecCompleted(); } @@ -2722,19 +2722,19 @@ static void PlayerHandleExpUpdate(void) u8 taskId; LoadBattleBarGfx(1); - GetMonData(&gPlayerParty[monId], MON_DATA_SPECIES); // unused return value - expPointsToGive = gBattleBufferA[gActiveBattler][2] | (gBattleBufferA[gActiveBattler][3] << 8); + GetMonData(&gPlayerParty[monId], MON_DATA_SPECIES); // Unused return value. + expPointsToGive = T1_READ_16(&gBattleBufferA[gActiveBattler][2]); taskId = CreateTask(Task_GiveExpToMon, 10); gTasks[taskId].tExpTask_monId = monId; gTasks[taskId].tExpTask_gainedExp = expPointsToGive; - gTasks[taskId].tExpTask_bank = gActiveBattler; + gTasks[taskId].tExpTask_battler = gActiveBattler; gBattlerControllerFuncs[gActiveBattler] = nullsub_21; } } #undef tExpTask_monId #undef tExpTask_gainedExp -#undef tExpTask_bank +#undef tExpTask_battler #undef tExpTask_frames static void PlayerHandleStatusIconUpdate(void) @@ -2971,7 +2971,7 @@ static void task05_08033660(u8 taskId) } else { - u8 savedActiveBank = gActiveBattler; + u8 savedActiveBattler = gActiveBattler; gActiveBattler = gTasks[taskId].data[0]; if (!IsDoubleBattle() || (gBattleTypeFlags & BATTLE_TYPE_MULTI)) @@ -2990,7 +2990,7 @@ static void task05_08033660(u8 taskId) gActiveBattler ^= BIT_FLANK; } gBattlerControllerFuncs[gActiveBattler] = sub_8058B40; - gActiveBattler = savedActiveBank; + gActiveBattler = savedActiveBattler; DestroyTask(taskId); } } From 1c48e585747de0a2273c4b3eb4be114d5214b8a2 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sat, 7 Jul 2018 14:24:19 +0200 Subject: [PATCH 11/15] small fixes --- include/battle_message.h | 7 +++++++ include/constants/items.h | 4 ++-- include/text.h | 10 ++++++++++ src/battle_message.c | 9 ++++++++- src/fieldmap.c | 6 +++--- src/item.c | 2 +- src/item_icon.c | 2 +- 7 files changed, 32 insertions(+), 8 deletions(-) diff --git a/include/battle_message.h b/include/battle_message.h index cccbae841..147bfa501 100644 --- a/include/battle_message.h +++ b/include/battle_message.h @@ -248,6 +248,13 @@ extern const u8 gText_BattleSwitchWhich4[]; extern const u8 gText_BattleSwitchWhich5[]; extern const u8 gText_SafariBalls[]; extern const u8 gText_SafariBallLeft[]; +extern const u8 gText_Sleep[]; +extern const u8 gText_Poison[]; +extern const u8 gText_Burn[]; +extern const u8 gText_Paralysis[]; +extern const u8 gText_Ice[]; +extern const u8 gText_Confusion[]; +extern const u8 gText_Love[]; extern const u8 gText_SpaceAndSpace[]; extern const u8 gText_CommaSpace[]; extern const u8 gText_Space2[]; diff --git a/include/constants/items.h b/include/constants/items.h index 4ca5cb7df..294499c8b 100644 --- a/include/constants/items.h +++ b/include/constants/items.h @@ -462,8 +462,8 @@ #define ITEM_MAGMA_EMBLEM 375 #define ITEM_OLD_SEA_MAP 376 -#define ITEM_LAST_ID 376 -#define ITEM_FIELD_ARROW ITEM_LAST_ID + 1 +#define ITEMS_COUNT 377 +#define ITEM_FIELD_ARROW ITEMS_COUNT #define FIRST_BERRY_INDEX ITEM_CHERI_BERRY #define LAST_BERRY_INDEX ITEM_ENIGMA_BERRY diff --git a/include/text.h b/include/text.h index 2566b51b7..07a2017b4 100644 --- a/include/text.h +++ b/include/text.h @@ -2,7 +2,17 @@ #define GUARD_TEXT_H #define CHAR_SPACE 0x00 +#define CHAR_PLUS 0x2E #define CHAR_0 0xA1 +#define CHAR_1 0xA2 +#define CHAR_2 0xA3 +#define CHAR_3 0xA4 +#define CHAR_4 0xA5 +#define CHAR_5 0xA6 +#define CHAR_6 0xA7 +#define CHAR_7 0xA8 +#define CHAR_8 0xA9 +#define CHAR_9 0xAA #define CHAR_QUESTION_MARK 0xAC #define CHAR_PERIOD 0xAD #define CHAR_HYPHEN 0xAE diff --git a/src/battle_message.c b/src/battle_message.c index 7d442ea98..32097fd76 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -1197,7 +1197,14 @@ const u8 * const gStatNamesTable2[] = }; const u8 gText_SafariBalls[] = _("{HIGHLIGHT DARK_GREY}SAFARI BALLS"); -const u8 gText_SafariBallLeft[] = _("{HIGHLIGHT DARK_GREY}Left: $" "{HIGHLIGHT DARK_GREY}");const u8 gText_Sleep[] = _( "sleep");const u8 gText_Poison[] = _( "poison");const u8 gText_Burn[] = _( "burn");const u8 gText_Paralysis[] = _( "paralysis");const u8 gText_Ice[] = _( "ice");const u8 gText_Confusion[] = _( "confusion");const u8 gText_Love[] = _( "love"); +const u8 gText_SafariBallLeft[] = _("{HIGHLIGHT DARK_GREY}Left: $" "{HIGHLIGHT DARK_GREY}"); +const u8 gText_Sleep[] = _("sleep"); +const u8 gText_Poison[] = _("poison"); +const u8 gText_Burn[] = _("burn"); +const u8 gText_Paralysis[] = _("paralysis"); +const u8 gText_Ice[] = _("ice"); +const u8 gText_Confusion[] = _("confusion"); +const u8 gText_Love[] = _("love"); const u8 gText_SpaceAndSpace[] = _(" and "); const u8 gText_CommaSpace[] = _(", "); const u8 gText_Space2[] = _(" "); diff --git a/src/fieldmap.c b/src/fieldmap.c index 2561bceb7..f57c4b48f 100644 --- a/src/fieldmap.c +++ b/src/fieldmap.c @@ -380,7 +380,7 @@ u8 MapGridGetZCoordAt(int x, int y) { return 0; } - + return block >> 12; } @@ -559,7 +559,7 @@ void mapdata_from_sav2(void) a0 = 1; else a0 = -1; - + for (j = x; j < x + 15; j++) { if (!sub_8088BF0(&gUnknown_02032318[j + width * i], width, a0)) @@ -922,7 +922,7 @@ bool8 sub_8088BF0(u16* a0, u16 a1, u8 a2) { if (a2 == 0xFF) return FALSE; - + if (a2 == 0) a0 -= a1; else diff --git a/src/item.c b/src/item.c index 30710d08a..c94f29910 100644 --- a/src/item.c +++ b/src/item.c @@ -1024,7 +1024,7 @@ bool8 RemovePyramidBagItem(u16 itemId, u16 count) static u16 SanitizeItemId(u16 itemId) { - if (itemId >= ITEM_LAST_ID + 1) + if (itemId >= ITEMS_COUNT) return ITEM_NONE; else return itemId; diff --git a/src/item_icon.c b/src/item_icon.c index d6fedf892..68ec1daf0 100644 --- a/src/item_icon.c +++ b/src/item_icon.c @@ -162,7 +162,7 @@ const void *GetItemIconPicOrPalette(u16 itemId, u8 which) { if (itemId == 0xFFFF) itemId = ITEM_FIELD_ARROW; - else if (itemId > ITEM_LAST_ID) + else if (itemId >= ITEMS_COUNT) itemId = 0; return gItemIconTable[itemId][which]; From 008d961b2a3d2d145f9ff8e7515cfb4f5e04128c Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sat, 7 Jul 2018 19:57:09 +0200 Subject: [PATCH 12/15] add party menu defines --- asm/party_menu.s | 8 ++++---- include/battle.h | 6 +++--- include/battle_controllers.h | 7 +++++-- include/party_menu.h | 13 +++++++++++++ include/pokemon.h | 2 +- src/battle_controller_player.c | 26 +++++++++++++------------- src/battle_controllers.c | 4 ++-- src/battle_main.c | 31 ++++++++++++++++--------------- src/battle_script_commands.c | 7 ++++--- src/battle_util.c | 4 ++-- src/pokemon.c | 12 ++++++------ 11 files changed, 69 insertions(+), 51 deletions(-) diff --git a/asm/party_menu.s b/asm/party_menu.s index 6e90fa3c3..017f1dc54 100644 --- a/asm/party_menu.s +++ b/asm/party_menu.s @@ -16079,8 +16079,8 @@ _081B89A6: bx r1 thumb_func_end sub_81B8984 - thumb_func_start sub_81B89AC -sub_81B89AC: @ 81B89AC + thumb_func_start OpenPartyMenuInBattle +OpenPartyMenuInBattle: @ 81B89AC push {r4,lr} sub sp, 0xC adds r4, r0, 0 @@ -16107,7 +16107,7 @@ sub_81B89AC: @ 81B89AC pop {r0} bx r0 .pool - thumb_func_end sub_81B89AC + thumb_func_end OpenPartyMenuInBattle thumb_func_start sub_81B89F0 sub_81B89F0: @ 81B89F0 @@ -16288,7 +16288,7 @@ _081B8B94: ldrb r0, [r0, 0xB] cmp r0, 0x4 bne _081B8BA8 - bl sub_806E994 + bl SetMonPreventsSwitchingString b _081B8C46 .pool _081B8BA8: diff --git a/include/battle.h b/include/battle.h index 6e941191f..fba5fb460 100644 --- a/include/battle.h +++ b/include/battle.h @@ -177,7 +177,7 @@ struct ProtectStruct /* field_0 */ u32 protected:1; u32 endured:1; - u32 onlyStruggle:1; + u32 noValidMoves:1; u32 helpingHand:1; u32 bounceMove:1; u32 stealMove:1; @@ -456,7 +456,7 @@ struct BattleStruct u8 field_46; u8 field_47; u8 focusPunchBattlerId; - u8 field_49; + u8 battlerPreventingSwitchout; u8 moneyMultiplier; u8 savedTurnActionNumber; u8 switchInAbilitiesCounter; @@ -509,7 +509,7 @@ struct BattleStruct u8 field_A7; u16 hpOnSwitchout[2]; u32 savedBattleTypeFlags; - u8 field_B0; + u8 abilityPreventingSwitchout; u8 hpScale; u8 synchronizeMoveEffect; bool8 anyMonHasTransformed; diff --git a/include/battle_controllers.h b/include/battle_controllers.h index 61e2935b7..8ba45fad1 100644 --- a/include/battle_controllers.h +++ b/include/battle_controllers.h @@ -65,6 +65,8 @@ enum REQUEST_TOUGH_RIBBON_BATTLE, }; +// Special arguments for Battle Controller functions. + #define RESET_ACTION_MOVE_SELECTION 0 #define RESET_ACTION_SELECTION 1 #define RESET_MOVE_SELECTION 2 @@ -76,10 +78,11 @@ enum #define BALL_3_SHAKES_SUCCESS 4 #define BALL_TRAINER_BLOCK 5 -#define RET_VALUE_LEVELLED_UP 11 - #define INSTANT_HP_BAR_DROP 32767 +// Special return values in gBattleBufferB from Battle Controller functions. +#define RET_VALUE_LEVELLED_UP 11 + struct UnusedControllerStruct { u8 field_0:7; diff --git a/include/party_menu.h b/include/party_menu.h index 2cf17f1e4..fd52f8d4d 100644 --- a/include/party_menu.h +++ b/include/party_menu.h @@ -1,6 +1,8 @@ #ifndef GUARD_PARTY_MENU_H #define GUARD_PARTY_MENU_H + #include "task.h" + enum { AILMENT_NONE, @@ -11,6 +13,16 @@ enum AILMENT_BRN }; +enum +{ + PARTY_CHOOSE_MON, + PARTY_MUST_CHOOSE_MON, + PARTY_CANT_SWITCH, + PARTY_USE_ITEM_ON, + PARTY_ABILITY_PREVENTS, + PARTY_GIVE_ITEM, +}; + struct Struct203CEC8 { u8 filler[0x9]; @@ -38,5 +50,6 @@ void sub_81B1F18(u8 taskId, u8 pokemonIdx, s8 a, s16 hp, TaskFunc func); void sub_81B1B5C(void *a, u8 b); u8 sub_81B1BD4(); void sub_81B8448(); +void OpenPartyMenuInBattle(u8 caseId); #endif // GUARD_PARTY_MENU_H diff --git a/include/pokemon.h b/include/pokemon.h index f36284f12..a60ad66be 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -593,7 +593,7 @@ bool8 IsTradedMon(struct Pokemon *mon); bool8 IsOtherTrainer(u32 otId, u8 *otName); void MonRestorePP(struct Pokemon *mon); void BoxMonRestorePP(struct BoxPokemon *boxMon); -void sub_806E994(void); +void SetMonPreventsSwitchingString(void); void SetWildMonHeldItem(void); bool8 IsMonShiny(struct Pokemon *mon); bool8 IsShinyOtIdPersonality(u32 otId, u32 personality); diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index 992d8656c..8f69dab06 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -30,6 +30,7 @@ #include "battle_setup.h" #include "item_use.h" #include "recorded_battle.h" +#include "party_menu.h" extern u8 gUnknown_0203CEE8; extern u8 gUnknown_0203CEE9; @@ -45,7 +46,6 @@ extern const struct CompressedSpritePalette gTrainerFrontPicPaletteTable[]; extern const struct CompressedSpritePalette gTrainerBackPicPaletteTable[]; extern void sub_8172EF0(u8 battlerId, struct Pokemon *mon); -extern void sub_81B89AC(u8 arg0); extern void sub_81AABB0(void); extern void sub_81A57E4(u8 battlerId, u16 stringId); extern void sub_81851A8(u8 *); @@ -120,7 +120,7 @@ static void MoveSelectionDisplayMoveType(void); static void MoveSelectionDisplayMoveNames(void); static void HandleMoveSwitchting(void); static void sub_8058FC0(void); -static void sub_8059828(void); +static void WaitForMonSelection(void); static void CompleteWhenChoseItem(void); static void Task_LaunchLvlUpAnim(u8 taskId); static void Task_PrepareToGiveExpWithExpBar(u8 taskId); @@ -1337,21 +1337,21 @@ static void CompleteOnInactiveTextPrinter2(void) PlayerBufferExecCompleted(); } -static void sub_80597CC(void) +static void OpenPartyMenuToChooseMon(void) { if (!gPaletteFade.active) { - u8 r4; + u8 caseId; - gBattlerControllerFuncs[gActiveBattler] = sub_8059828; - r4 = gTasks[gUnknown_03005D7C[gActiveBattler]].data[0]; + gBattlerControllerFuncs[gActiveBattler] = WaitForMonSelection; + caseId = gTasks[gUnknown_03005D7C[gActiveBattler]].data[0]; DestroyTask(gUnknown_03005D7C[gActiveBattler]); FreeAllWindowBuffers(); - sub_81B89AC(r4); + OpenPartyMenuInBattle(caseId); } } -static void sub_8059828(void) +static void WaitForMonSelection(void) { if (gMain.callback2 == BattleMainCB2 && !gPaletteFade.active) { @@ -2655,7 +2655,7 @@ static void PlayerHandleChoosePokemon(void) for (i = 0; i < 3; i++) gUnknown_0203CF00[i] = gBattleBufferA[gActiveBattler][4 + i]; - if (gBattleTypeFlags & BATTLE_TYPE_ARENA && (gBattleBufferA[gActiveBattler][1] & 0xF) != 2) + if (gBattleTypeFlags & BATTLE_TYPE_ARENA && (gBattleBufferA[gActiveBattler][1] & 0xF) != PARTY_CANT_SWITCH) { BtlController_EmitChosenMonReturnValue(1, gBattlerPartyIndexes[gActiveBattler] + 1, gUnknown_0203CF00); PlayerBufferExecCompleted(); @@ -2664,11 +2664,11 @@ static void PlayerHandleChoosePokemon(void) { gUnknown_03005D7C[gActiveBattler] = CreateTask(TaskDummy, 0xFF); gTasks[gUnknown_03005D7C[gActiveBattler]].data[0] = gBattleBufferA[gActiveBattler][1] & 0xF; - *(&gBattleStruct->field_49) = gBattleBufferA[gActiveBattler][1] >> 4; + *(&gBattleStruct->battlerPreventingSwitchout) = gBattleBufferA[gActiveBattler][1] >> 4; *(&gBattleStruct->field_8B) = gBattleBufferA[gActiveBattler][2]; - *(&gBattleStruct->field_B0) = gBattleBufferA[gActiveBattler][3]; - BeginNormalPaletteFade(-1, 0, 0, 16, 0); - gBattlerControllerFuncs[gActiveBattler] = sub_80597CC; + *(&gBattleStruct->abilityPreventingSwitchout) = gBattleBufferA[gActiveBattler][3]; + BeginNormalPaletteFade(-1, 0, 0, 0x10, 0); + gBattlerControllerFuncs[gActiveBattler] = OpenPartyMenuToChooseMon; gBattlerInMenuId = gActiveBattler; } } diff --git a/src/battle_controllers.c b/src/battle_controllers.c index c841aaa03..1ce5d3099 100644 --- a/src/battle_controllers.c +++ b/src/battle_controllers.c @@ -1181,7 +1181,7 @@ void BtlController_EmitChooseItem(u8 bufferId, u8 *arg1) PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 4); } -void BtlController_EmitChoosePokemon(u8 bufferId, u8 caseId, u8 arg2, u8 abilityId, u8* arg4) +void BtlController_EmitChoosePokemon(u8 bufferId, u8 caseId, u8 arg2, u8 abilityId, u8 *arg4) { s32 i; @@ -1191,7 +1191,7 @@ void BtlController_EmitChoosePokemon(u8 bufferId, u8 caseId, u8 arg2, u8 ability sBattleBuffersTransferData[3] = abilityId; for (i = 0; i < 3; i++) sBattleBuffersTransferData[4 + i] = arg4[i]; - PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 8); // but only 7 bytes were written + PrepareBufferDataTransfer(bufferId, sBattleBuffersTransferData, 8); // Only 7 bytes were written. } void BtlController_EmitCmd23(u8 bufferId) diff --git a/src/battle_main.c b/src/battle_main.c index 591c299d7..fe6e62c5d 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -51,6 +51,7 @@ #include "decompress.h" #include "international_string_util.h" #include "pokeball.h" +#include "party_menu.h" struct UnknownPokemonStruct4 { @@ -3232,7 +3233,7 @@ void FaintClearSetData(void) gProtectStructs[gActiveBattler].protected = 0; gProtectStructs[gActiveBattler].endured = 0; - gProtectStructs[gActiveBattler].onlyStruggle = 0; + gProtectStructs[gActiveBattler].noValidMoves = 0; gProtectStructs[gActiveBattler].helpingHand = 0; gProtectStructs[gActiveBattler].bounceMove = 0; gProtectStructs[gActiveBattler].stealMove = 0; @@ -4141,11 +4142,11 @@ static void HandleTurnActionSelectionState(void) u8 position = GetBattlerPosition(gActiveBattler); switch (gBattleCommunication[gActiveBattler]) { - case STATE_TURN_START_RECORD: // recorded battle related on start of every turn + case STATE_TURN_START_RECORD: // Recorded battle related action on start of every turn. RecordedBattle_CopyBattlerMoves(); gBattleCommunication[gActiveBattler] = STATE_BEFORE_ACTION_CHOSEN; break; - case STATE_BEFORE_ACTION_CHOSEN: // choose an action + case STATE_BEFORE_ACTION_CHOSEN: // Choose an action. *(gBattleStruct->monToSwitchIntoId + gActiveBattler) = PARTY_SIZE; if (gBattleTypeFlags & BATTLE_TYPE_MULTI || (position & BIT_FLANK) == B_FLANK_LEFT @@ -4177,7 +4178,7 @@ static void HandleTurnActionSelectionState(void) } } break; - case STATE_WAIT_ACTION_CHOSEN: // try to perform an action + case STATE_WAIT_ACTION_CHOSEN: // Try to perform an action. if (!(gBattleControllerExecFlags & ((gBitTable[gActiveBattler]) | (0xF0000000) | (gBitTable[gActiveBattler] << 4) | (gBitTable[gActiveBattler] << 8) | (gBitTable[gActiveBattler] << 0xC)))) { RecordedBattle_SetBattlerAction(gActiveBattler, gBattleBufferB[gActiveBattler][1]); @@ -4248,7 +4249,7 @@ static void HandleTurnActionSelectionState(void) || gBattleTypeFlags & BATTLE_TYPE_ARENA || gStatuses3[gActiveBattler] & STATUS3_ROOTED) { - BtlController_EmitChoosePokemon(0, 2, 6, ABILITY_NONE, gBattleStruct->field_60[gActiveBattler]); + BtlController_EmitChoosePokemon(0, PARTY_CANT_SWITCH, 6, ABILITY_NONE, gBattleStruct->field_60[gActiveBattler]); } else if ((i = ABILITY_ON_OPPOSING_FIELD(gActiveBattler, ABILITY_SHADOW_TAG)) || ((i = ABILITY_ON_OPPOSING_FIELD(gActiveBattler, ABILITY_ARENA_TRAP)) @@ -4257,16 +4258,16 @@ static void HandleTurnActionSelectionState(void) || ((i = AbilityBattleEffects(ABILITYEFFECT_CHECK_FIELD_EXCEPT_BATTLER, gActiveBattler, ABILITY_MAGNET_PULL, 0, 0)) && IS_BATTLER_OF_TYPE(gActiveBattler, TYPE_STEEL))) { - BtlController_EmitChoosePokemon(0, ((i - 1) << 4) | 4, 6, gLastUsedAbility, gBattleStruct->field_60[gActiveBattler]); + BtlController_EmitChoosePokemon(0, ((i - 1) << 4) | PARTY_ABILITY_PREVENTS, 6, gLastUsedAbility, gBattleStruct->field_60[gActiveBattler]); } else { if (gActiveBattler == 2 && gChosenActionByBattler[0] == B_ACTION_SWITCH) - BtlController_EmitChoosePokemon(0, 0, *(gBattleStruct->monToSwitchIntoId + 0), ABILITY_NONE, gBattleStruct->field_60[gActiveBattler]); + BtlController_EmitChoosePokemon(0, PARTY_CHOOSE_MON, *(gBattleStruct->monToSwitchIntoId + 0), ABILITY_NONE, gBattleStruct->field_60[gActiveBattler]); else if (gActiveBattler == 3 && gChosenActionByBattler[1] == B_ACTION_SWITCH) - BtlController_EmitChoosePokemon(0, 0, *(gBattleStruct->monToSwitchIntoId + 1), ABILITY_NONE, gBattleStruct->field_60[gActiveBattler]); + BtlController_EmitChoosePokemon(0, PARTY_CHOOSE_MON, *(gBattleStruct->monToSwitchIntoId + 1), ABILITY_NONE, gBattleStruct->field_60[gActiveBattler]); else - BtlController_EmitChoosePokemon(0, 0, 6, ABILITY_NONE, gBattleStruct->field_60[gActiveBattler]); + BtlController_EmitChoosePokemon(0, PARTY_CHOOSE_MON, 6, ABILITY_NONE, gBattleStruct->field_60[gActiveBattler]); } MarkBattlerForControllerExec(gActiveBattler); break; @@ -4304,7 +4305,7 @@ static void HandleTurnActionSelectionState(void) RecordedBattle_ClearBattlerAction(GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler))), 1); } else if (gChosenActionByBattler[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))] == B_ACTION_USE_MOVE - && (gProtectStructs[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))].onlyStruggle + && (gProtectStructs[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))].noValidMoves || gDisableStructs[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))].encoredMove)) { RecordedBattle_ClearBattlerAction(GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler))), 1); @@ -4705,7 +4706,7 @@ u8 GetWhoStrikesFirst(u8 battler1, u8 battler2, bool8 ignoreChosenMoves) { if (gChosenActionByBattler[battler1] == B_ACTION_USE_MOVE) { - if (gProtectStructs[battler1].onlyStruggle) + if (gProtectStructs[battler1].noValidMoves) moveBattler1 = MOVE_STRUGGLE; else moveBattler1 = gBattleMons[battler1].moves[*(gBattleStruct->chosenMovePositions + battler1)]; @@ -4715,7 +4716,7 @@ u8 GetWhoStrikesFirst(u8 battler1, u8 battler2, bool8 ignoreChosenMoves) if (gChosenActionByBattler[battler2] == B_ACTION_USE_MOVE) { - if (gProtectStructs[battler2].onlyStruggle) + if (gProtectStructs[battler2].noValidMoves) moveBattler2 = MOVE_STRUGGLE; else moveBattler2 = gBattleMons[battler2].moves[*(gBattleStruct->chosenMovePositions + battler2)]; @@ -4917,7 +4918,7 @@ static void CheckFocusPunch_ClearVarsBeforeTurnStarts(void) if (gChosenMoveByBattler[gActiveBattler] == MOVE_FOCUS_PUNCH && !(gBattleMons[gActiveBattler].status1 & STATUS1_SLEEP) && !(gDisableStructs[gBattlerAttacker].truantCounter) - && !(gProtectStructs[gActiveBattler].onlyStruggle)) + && !(gProtectStructs[gActiveBattler].noValidMoves)) { BattleScriptExecute(BattleScript_FocusPunchSetUp); return; @@ -5290,9 +5291,9 @@ static void HandleAction_UseMove(void) gCurrMovePos = gChosenMovePos = *(gBattleStruct->chosenMovePositions + gBattlerAttacker); // choose move - if (gProtectStructs[gBattlerAttacker].onlyStruggle) + if (gProtectStructs[gBattlerAttacker].noValidMoves) { - gProtectStructs[gBattlerAttacker].onlyStruggle = 0; + gProtectStructs[gBattlerAttacker].noValidMoves = 0; gCurrentMove = gChosenMove = MOVE_STRUGGLE; gHitMarker |= HITMARKER_NO_PPDEDUCT; *(gBattleStruct->moveTarget + gBattlerAttacker) = GetMoveTarget(MOVE_STRUGGLE, 0); diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index bacaf2bac..eb6feb2a0 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -40,6 +40,7 @@ #include "constants/battle_string_ids.h" #include "battle_setup.h" #include "overworld.h" +#include "party_menu.h" extern u16 gBattle_BG1_X; extern u16 gBattle_BG1_Y; @@ -5143,7 +5144,7 @@ static void sub_804CF10(u8 arg0) *(gBattleStruct->monToSwitchIntoId + gActiveBattler) = 6; gBattleStruct->field_93 &= ~(gBitTable[gActiveBattler]); - BtlController_EmitChoosePokemon(0, 1, arg0, 0, gBattleStruct->field_60[gActiveBattler]); + BtlController_EmitChoosePokemon(0, PARTY_MUST_CHOOSE_MON, arg0, 0, gBattleStruct->field_60[gActiveBattler]); MarkBattlerForControllerExec(gActiveBattler); } @@ -5382,9 +5383,9 @@ static void atk50_openpartyscreen(void) else { if (gBattlescriptCurrInstr[1] & 0x80) - hitmarkerFaintBits = 0; // used here as the caseId for the EmitChoose function + hitmarkerFaintBits = PARTY_CHOOSE_MON; // Used here as the caseId for the EmitChoose function. else - hitmarkerFaintBits = 1; + hitmarkerFaintBits = PARTY_MUST_CHOOSE_MON; battlerId = GetBattlerForBattleScript(gBattlescriptCurrInstr[1] & ~(0x80)); if (gSpecialStatuses[battlerId].flag40) diff --git a/src/battle_util.c b/src/battle_util.c index 5d2ec62a9..6e3fc3e7f 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -455,12 +455,12 @@ bool8 AreAllMovesUnusable(void) if (unusable == 0xF) // All moves are unusable. { - gProtectStructs[gActiveBattler].onlyStruggle = 1; + gProtectStructs[gActiveBattler].noValidMoves = 1; gSelectionBattleScripts[gActiveBattler] = BattleScript_NoMovesLeft; } else { - gProtectStructs[gActiveBattler].onlyStruggle = 0; + gProtectStructs[gActiveBattler].noValidMoves = 0; } return (unusable == 0xF); diff --git a/src/pokemon.c b/src/pokemon.c index 80c1ab784..5406cfee9 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -5582,19 +5582,19 @@ void BoxMonRestorePP(struct BoxPokemon *boxMon) } } -void sub_806E994(void) +void SetMonPreventsSwitchingString(void) { - gLastUsedAbility = gBattleStruct->field_B0; + gLastUsedAbility = gBattleStruct->abilityPreventingSwitchout; gBattleTextBuff1[0] = B_BUFF_PLACEHOLDER_BEGIN; gBattleTextBuff1[1] = B_BUFF_MON_NICK_WITH_PREFIX; - gBattleTextBuff1[2] = gBattleStruct->field_49; + gBattleTextBuff1[2] = gBattleStruct->battlerPreventingSwitchout; gBattleTextBuff1[4] = B_BUFF_EOS; - if (!GetBattlerSide(gBattleStruct->field_49)) - gBattleTextBuff1[3] = pokemon_order_func(gBattlerPartyIndexes[gBattleStruct->field_49]); + if (GetBattlerSide(gBattleStruct->battlerPreventingSwitchout) == B_SIDE_PLAYER) + gBattleTextBuff1[3] = pokemon_order_func(gBattlerPartyIndexes[gBattleStruct->battlerPreventingSwitchout]); else - gBattleTextBuff1[3] = gBattlerPartyIndexes[gBattleStruct->field_49]; + gBattleTextBuff1[3] = gBattlerPartyIndexes[gBattleStruct->battlerPreventingSwitchout]; PREPARE_MON_NICK_WITH_PREFIX_BUFFER(gBattleTextBuff2, gBattlerInMenuId, pokemon_order_func(gBattlerPartyIndexes[gBattlerInMenuId])) From ee3d505b585c5d0a8b6a8a68b8ab787d04bdc33a Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sat, 7 Jul 2018 21:14:41 +0200 Subject: [PATCH 13/15] little touches for HandleTurnActionSelectionState --- src/battle_main.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/battle_main.c b/src/battle_main.c index fe6e62c5d..88422574f 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -163,7 +163,7 @@ static void HandleTurnActionSelectionState(void); static void RunTurnActionsFunctions(void); static void SetActionsAndBattlersTurnOrder(void); static void sub_803CDF8(void); -static bool8 sub_803CDB8(void); +static bool8 AllAtActionConfirmed(void); static void CheckFocusPunch_ClearVarsBeforeTurnStarts(void); static void FreeResetData_ReturnToOvOrDoEvolutions(void); static void ReturnFromBattleToOverworld(void); @@ -4286,8 +4286,8 @@ static void HandleTurnActionSelectionState(void) MarkBattlerForControllerExec(gActiveBattler); break; case B_ACTION_CANCEL_PARTNER: - gBattleCommunication[gActiveBattler] = 7; - gBattleCommunication[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))] = 1; + gBattleCommunication[gActiveBattler] = STATE_WAIT_SET_BEFORE_ACTION; + gBattleCommunication[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))] = STATE_BEFORE_ACTION_CHOSEN; RecordedBattle_ClearBattlerAction(gActiveBattler, 1); if (gBattleMons[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))].status2 & STATUS2_MULTIPLETURNS || gBattleMons[GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gActiveBattler)))].status2 & STATUS2_RECHARGE) @@ -4330,7 +4330,7 @@ static void HandleTurnActionSelectionState(void) && gBattleBufferB[gActiveBattler][1] == B_ACTION_RUN) { gSelectionBattleScripts[gActiveBattler] = BattleScript_AskIfWantsToForfeitMatch; - gBattleCommunication[gActiveBattler] = 8; + gBattleCommunication[gActiveBattler] = STATE_SELECTION_SCRIPT_MAY_RUN; *(gBattleStruct->selectionScriptFinished + gActiveBattler) = FALSE; *(gBattleStruct->stateIdAfterSelScript + gActiveBattler) = STATE_BEFORE_ACTION_CHOSEN; return; @@ -4340,7 +4340,7 @@ static void HandleTurnActionSelectionState(void) && gBattleBufferB[gActiveBattler][1] == B_ACTION_RUN) { BattleScriptExecute(BattleScript_PrintCantRunFromTrainer); - gBattleCommunication[gActiveBattler] = 1; + gBattleCommunication[gActiveBattler] = STATE_BEFORE_ACTION_CHOSEN; } else if (IsRunningFromBattleImpossible() && gBattleBufferB[gActiveBattler][1] == B_ACTION_RUN) @@ -4382,7 +4382,7 @@ static void HandleTurnActionSelectionState(void) sub_818603C(2); if ((gBattleBufferB[gActiveBattler][2] | (gBattleBufferB[gActiveBattler][3] << 8)) == 0xFFFF) { - gBattleCommunication[gActiveBattler] = 1; + gBattleCommunication[gActiveBattler] = STATE_BEFORE_ACTION_CHOSEN; RecordedBattle_ClearBattlerAction(gActiveBattler, 1); } else if (TrySetCantSelectMoveBattleScript()) @@ -4412,7 +4412,7 @@ static void HandleTurnActionSelectionState(void) case B_ACTION_USE_ITEM: if ((gBattleBufferB[gActiveBattler][1] | (gBattleBufferB[gActiveBattler][2] << 8)) == 0) { - gBattleCommunication[gActiveBattler] = 1; + gBattleCommunication[gActiveBattler] = STATE_BEFORE_ACTION_CHOSEN; } else { @@ -4423,7 +4423,7 @@ static void HandleTurnActionSelectionState(void) case B_ACTION_SWITCH: if (gBattleBufferB[gActiveBattler][1] == PARTY_SIZE) { - gBattleCommunication[gActiveBattler] = 1; + gBattleCommunication[gActiveBattler] = STATE_BEFORE_ACTION_CHOSEN; RecordedBattle_ClearBattlerAction(gActiveBattler, 1); } else @@ -4468,10 +4468,13 @@ static void HandleTurnActionSelectionState(void) case STATE_WAIT_ACTION_CONFIRMED_STANDBY: if (!(gBattleControllerExecFlags & ((gBitTable[gActiveBattler]) | (0xF0000000) | (gBitTable[gActiveBattler] << 4) | (gBitTable[gActiveBattler] << 8) | (gBitTable[gActiveBattler] << 0xC)))) { - i = (sub_803CDB8() != 0); + if (AllAtActionConfirmed()) + i = TRUE; + else + i = FALSE; if (((gBattleTypeFlags & (BATTLE_TYPE_MULTI | BATTLE_TYPE_DOUBLE)) != BATTLE_TYPE_DOUBLE) - || (position & BIT_FLANK) + || (position & BIT_FLANK) != B_FLANK_LEFT || (*(&gBattleStruct->field_91) & gBitTable[GetBattlerAtPosition(position ^ BIT_FLANK)])) { BtlController_EmitLinkStandbyMsg(0, 0, i); @@ -4509,7 +4512,7 @@ static void HandleTurnActionSelectionState(void) case STATE_WAIT_SET_BEFORE_ACTION: if (!(gBattleControllerExecFlags & ((gBitTable[gActiveBattler]) | (0xF0000000) | (gBitTable[gActiveBattler] << 4) | (gBitTable[gActiveBattler] << 8) | (gBitTable[gActiveBattler] << 0xC)))) { - gBattleCommunication[gActiveBattler] = 1; + gBattleCommunication[gActiveBattler] = STATE_BEFORE_ACTION_CHOSEN; } break; case STATE_SELECTION_SCRIPT_MAY_RUN: @@ -4541,7 +4544,7 @@ static void HandleTurnActionSelectionState(void) } } - // check if everyone chose actions + // Check if everyone chose actions. if (gBattleCommunication[ACTIONS_CONFIRMED_COUNT] == gBattlersCount) { sub_818603C(1); @@ -4558,17 +4561,17 @@ static void HandleTurnActionSelectionState(void) } } -static bool8 sub_803CDB8(void) +static bool8 AllAtActionConfirmed(void) { - s32 i, var; + s32 i, count; - for (var = 0, i = 0; i < gBattlersCount; i++) + for (count = 0, i = 0; i < gBattlersCount; i++) { - if (gBattleCommunication[i] == 5) - var++; + if (gBattleCommunication[i] == STATE_WAIT_ACTION_CONFIRMED) + count++; } - if (var + 1 == gBattlersCount) + if (count + 1 == gBattlersCount) return TRUE; else return FALSE; From bf0178238a179b298f465b64a4f23ff43db48fc9 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 16 Jul 2018 20:47:30 +0200 Subject: [PATCH 14/15] Battle files - review changes --- include/battle.h | 8 +-- include/battle_controllers.h | 2 +- include/constants/trainers.h | 6 +- include/gba/io_reg.h | 2 + src/battle_ai_script_commands.c | 10 ++-- src/battle_controller_player.c | 4 +- src/battle_controller_player_partner.c | 4 +- src/battle_interface.c | 4 +- src/battle_message.c | 8 +-- src/battle_script_commands.c | 8 +-- src/battle_util.c | 80 +++++++++++++------------- src/braille_puzzles.c | 20 +++++-- src/pokemon.c | 21 ++++--- 13 files changed, 95 insertions(+), 82 deletions(-) diff --git a/include/battle.h b/include/battle.h index fba5fb460..3843bc5e6 100644 --- a/include/battle.h +++ b/include/battle.h @@ -214,8 +214,8 @@ struct SpecialStatus { u8 statLowered:1; // 0x1 u8 lightningRodRedirected:1; // 0x2 - u8 restoredBankSprite: 1; // 0x4 - u8 intimidatedPoke:1; // 0x8 + u8 restoredBattlerSprite: 1; // 0x4 + u8 intimidatedMon:1; // 0x8 u8 traced:1; // 0x10 u8 flag20:1; u8 flag40:1; @@ -607,8 +607,8 @@ struct BattleScripting // rom_80A5C6C u8 GetBattlerSide(u8 battler); -u8 GetBattlerPosition(u8 bank); -u8 GetBattlerAtPosition(u8 bank); +u8 GetBattlerPosition(u8 battler); +u8 GetBattlerAtPosition(u8 battler); struct BattleSpriteInfo { diff --git a/include/battle_controllers.h b/include/battle_controllers.h index 8ba45fad1..ff5a629af 100644 --- a/include/battle_controllers.h +++ b/include/battle_controllers.h @@ -81,7 +81,7 @@ enum #define INSTANT_HP_BAR_DROP 32767 // Special return values in gBattleBufferB from Battle Controller functions. -#define RET_VALUE_LEVELLED_UP 11 +#define RET_VALUE_LEVELED_UP 11 struct UnusedControllerStruct { diff --git a/include/constants/trainers.h b/include/constants/trainers.h index eb695e4ab..43ea6d0b6 100644 --- a/include/constants/trainers.h +++ b/include/constants/trainers.h @@ -862,9 +862,9 @@ // Special Trainer Ids. #define TRAINER_FRONTIER_BRAIN 1022 #define TRAINER_SECRET_BASE 1024 -#define TRAINER_LINK_OPPONENT 0x800 -#define TRAINER_OPPONENT_C00 0xC00 -#define TRAINER_STEVEN_PARTNER 0xC03 +#define TRAINER_LINK_OPPONENT 2048 +#define TRAINER_OPPONENT_C00 3072 +#define TRAINER_STEVEN_PARTNER 3075 #define TRAINER_PIC_HIKER 0 #define TRAINER_PIC_AQUA_GRUNT_M 1 diff --git a/include/gba/io_reg.h b/include/gba/io_reg.h index 6498c6a99..01d8c311e 100644 --- a/include/gba/io_reg.h +++ b/include/gba/io_reg.h @@ -582,6 +582,7 @@ #define BLDCNT_TGT1_BG3 (1 << 3) #define BLDCNT_TGT1_OBJ (1 << 4) #define BLDCNT_TGT1_BD (1 << 5) +#define BLDCNT_TGT1_ALL (BLDCNT_TGT1_BG0 | BLDCNT_TGT1_BG1 | BLDCNT_TGT1_BG2 | BLDCNT_TGT1_BG3 | BLDCNT_TGT1_OBJ | BLDCNT_TGT1_BD) // Bits 6-7 select the special effect #define BLDCNT_EFFECT_NONE (0 << 6) // no special effect #define BLDCNT_EFFECT_BLEND (1 << 6) // 1st+2nd targets mixed (controlled by BLDALPHA) @@ -594,6 +595,7 @@ #define BLDCNT_TGT2_BG3 (1 << 11) #define BLDCNT_TGT2_OBJ (1 << 12) #define BLDCNT_TGT2_BD (1 << 13) +#define BLDCNT_TGT2_ALL (BLDCNT_TGT2_BG0 | BLDCNT_TGT2_BG1 | BLDCNT_TGT2_BG2 | BLDCNT_TGT2_BG3 | BLDCNT_TGT2_OBJ | BLDCNT_TGT2_BD) // BLDALPHA #define BLDALPHA_BLEND(target1, target2) (((target2) << 8) | (target1)) diff --git a/src/battle_ai_script_commands.c b/src/battle_ai_script_commands.c index e82d22576..74247f8a2 100644 --- a/src/battle_ai_script_commands.c +++ b/src/battle_ai_script_commands.c @@ -352,7 +352,7 @@ void BattleAI_SetupAIData(u8 defaultScoreMoves) if (gAbsentBattlerFlags & gBitTable[gBattlerTarget]) gBattlerTarget ^= BIT_FLANK; } - // There's only one choice in signle battles. + // There's only one choice in single battles. else { gBattlerTarget = sBattler_AI ^ BIT_SIDE; @@ -774,7 +774,7 @@ static void BattleAICmd_if_status(void) status = T1_READ_32(gAIScriptPtr + 2); - if ((gBattleMons[battlerId].status1 & status)) + if (gBattleMons[battlerId].status1 & status) gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 6); else gAIScriptPtr += 10; @@ -846,7 +846,7 @@ static void BattleAICmd_if_status3(void) status = T1_READ_32(gAIScriptPtr + 2); - if ((gStatuses3[battlerId] & status)) + if (gStatuses3[battlerId] & status) gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 6); else gAIScriptPtr += 10; @@ -883,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)) + if (gSideStatuses[side] & status) gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 6); else gAIScriptPtr += 10; @@ -1949,7 +1949,7 @@ static void BattleAICmd_if_curr_move_disabled_or_encored(void) gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 2); else gAIScriptPtr += 6; - break;; + break; case 1: if (gDisableStructs[gActiveBattler].encoredMove == AI_THINKING_STRUCT->moveConsidered) gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 2); diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index 843d241ce..6ab19e368 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -1169,7 +1169,7 @@ static void Task_GiveExpToMon(u8 taskId) gainedExp -= nextLvlExp - currExp; savedActiveBattler = gActiveBattler; gActiveBattler = battlerId; - BtlController_EmitTwoReturnValues(1, RET_VALUE_LEVELLED_UP, gainedExp); + BtlController_EmitTwoReturnValues(1, RET_VALUE_LEVELED_UP, gainedExp); gActiveBattler = savedActiveBattler; if (IsDoubleBattle() == TRUE @@ -1248,7 +1248,7 @@ static void sub_8059400(u8 taskId) gainedExp -= expOnNextLvl - currExp; savedActiveBattler = gActiveBattler; gActiveBattler = battlerId; - BtlController_EmitTwoReturnValues(1, RET_VALUE_LEVELLED_UP, gainedExp); + BtlController_EmitTwoReturnValues(1, RET_VALUE_LEVELED_UP, gainedExp); gActiveBattler = savedActiveBattler; gTasks[taskId].func = Task_LaunchLvlUpAnim; } diff --git a/src/battle_controller_player_partner.c b/src/battle_controller_player_partner.c index cd3a94692..601b8dcc1 100644 --- a/src/battle_controller_player_partner.c +++ b/src/battle_controller_player_partner.c @@ -345,7 +345,7 @@ static void Task_GiveExpToMon(u8 taskId) gainedExp -= nextLvlExp - currExp; savedActiveBank = gActiveBattler; gActiveBattler = battlerId; - BtlController_EmitTwoReturnValues(1, RET_VALUE_LEVELLED_UP, gainedExp); + BtlController_EmitTwoReturnValues(1, RET_VALUE_LEVELED_UP, gainedExp); gActiveBattler = savedActiveBank; if (IsDoubleBattle() == TRUE @@ -424,7 +424,7 @@ static void sub_81BB4E4(u8 taskId) gainedExp -= expOnNextLvl - currExp; savedActiveBank = gActiveBattler; gActiveBattler = battlerId; - BtlController_EmitTwoReturnValues(1, RET_VALUE_LEVELLED_UP, gainedExp); + BtlController_EmitTwoReturnValues(1, RET_VALUE_LEVELED_UP, gainedExp); gActiveBattler = savedActiveBank; gTasks[taskId].func = sub_81BB628; } diff --git a/src/battle_interface.c b/src/battle_interface.c index a6032adc3..278edb6f4 100644 --- a/src/battle_interface.c +++ b/src/battle_interface.c @@ -1710,8 +1710,8 @@ void Task_HidePartyStatusSummary(u8 taskId) for (i = 0; i < PARTY_SIZE; i++) ballIconSpriteIds[i] = gTasks[taskId].tBallIconSpriteId(i); - SetGpuReg(REG_OFFSET_BLDCNT, 0x3F40); - SetGpuReg(REG_OFFSET_BLDALPHA, 0x10); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT2_ALL | BLDCNT_EFFECT_BLEND); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(16, 0)); gTasks[taskId].tData15 = 16; diff --git a/src/battle_message.c b/src/battle_message.c index 32097fd76..4f5190dec 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -2940,19 +2940,19 @@ static void ChooseTypeOfMoveUsedString(u8* dst) void BattlePutTextOnWindow(const u8 *text, u8 windowId) { const struct BattleWindowText *textInfo = sBattleTextOnWindowsInfo[gBattleScripting.windowsType]; - bool32 toVram; + bool32 copyToVram; struct TextSubPrinter textSubPrinter; u8 speed; if (windowId & 0x80) { windowId &= ~(0x80); - toVram = FALSE; + copyToVram = FALSE; } else { FillWindowPixelBuffer(windowId, textInfo[windowId].fillValue); - toVram = TRUE; + copyToVram = TRUE; } textSubPrinter.current_text_offset = text; @@ -3005,7 +3005,7 @@ void BattlePutTextOnWindow(const u8 *text, u8 windowId) AddTextPrinter(&textSubPrinter, speed, NULL); - if (toVram) + if (copyToVram) { PutWindowTilemap(windowId); CopyWindowToVram(windowId, 3); diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index eb31c22dc..87244ff5a 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -3449,7 +3449,7 @@ static void atk23_getexp(void) if (gBattleControllerExecFlags == 0) { gActiveBattler = gBattleStruct->expGetterBattlerId; - if (gBattleBufferB[gActiveBattler][0] == CONTROLLER_TWORETURNVALUES && gBattleBufferB[gActiveBattler][1] == RET_VALUE_LEVELLED_UP) + if (gBattleBufferB[gActiveBattler][0] == CONTROLLER_TWORETURNVALUES && gBattleBufferB[gActiveBattler][1] == RET_VALUE_LEVELED_UP) { if (gBattleTypeFlags & BATTLE_TYPE_TRAINER && gBattlerPartyIndexes[gActiveBattler] == gBattleStruct->expGetterMonId) HandleLowHpMusicChange(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], gActiveBattler); @@ -4649,14 +4649,14 @@ static void atk49_moveend(void) BtlController_EmitSpriteInvisibility(0, FALSE); MarkBattlerForControllerExec(gActiveBattler); gStatuses3[gBattlerAttacker] &= ~(STATUS3_SEMI_INVULNERABLE); - gSpecialStatuses[gBattlerAttacker].restoredBankSprite = 1; + gSpecialStatuses[gBattlerAttacker].restoredBattlerSprite = 1; gBattleScripting.atk49_state++; return; } gBattleScripting.atk49_state++; break; case 10: // make target sprite visible - if (!gSpecialStatuses[gBattlerTarget].restoredBankSprite && gBattlerTarget < gBattlersCount + if (!gSpecialStatuses[gBattlerTarget].restoredBattlerSprite && gBattlerTarget < gBattlersCount && !(gStatuses3[gBattlerTarget] & STATUS3_SEMI_INVULNERABLE)) { gActiveBattler = gBattlerTarget; @@ -6632,7 +6632,7 @@ static void atk76_various(void) gBattleCommunication[0] = 0; break; case VARIOUS_RESET_INTIMIDATE_TRACE_BITS: - gSpecialStatuses[gActiveBattler].intimidatedPoke = 0; + gSpecialStatuses[gActiveBattler].intimidatedMon = 0; gSpecialStatuses[gActiveBattler].traced = 0; break; case VARIOUS_UPDATE_CHOICE_MOVE_ON_LVL_UP: diff --git a/src/battle_util.c b/src/battle_util.c index 6e3fc3e7f..c739c648c 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -470,11 +470,11 @@ u8 GetImprisonedMovesCount(u8 battlerId, u16 move) { s32 i; u8 imprisionedMoves = 0; - u8 BattlerSide = GetBattlerSide(battlerId); + u8 battlerSide = GetBattlerSide(battlerId); for (i = 0; i < gBattlersCount; i++) { - if (BattlerSide != GetBattlerSide(i) && gStatuses3[i] & STATUS3_IMPRISONED_OTHERS) + if (battlerSide != GetBattlerSide(i) && gStatuses3[i] & STATUS3_IMPRISONED_OTHERS) { s32 j; for (j = 0; j < 4; j++) @@ -1840,10 +1840,10 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u8 ability, u8 special, u16 moveA } break; case ABILITY_INTIMIDATE: - if (!(gSpecialStatuses[battler].intimidatedPoke)) + if (!(gSpecialStatuses[battler].intimidatedMon)) { gStatuses3[battler] |= STATUS3_INTIMIDATE_POKES; - gSpecialStatuses[battler].intimidatedPoke = 1; + gSpecialStatuses[battler].intimidatedMon = 1; } break; case ABILITY_FORECAST: @@ -2511,32 +2511,32 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) int i = 0; u8 effect = ITEM_NO_EFFECT; u8 changedPP = 0; - u8 BattlerHoldEffect, atkHoldEffect, defHoldEffect; - u8 BattlerQuality, atkQuality, defQuality; + u8 battlerHoldEffect, atkHoldEffect, defHoldEffect; + u8 battlerHoldEffectParam, atkHoldEffectParam, defHoldEffectParam; u16 atkItem, defItem; gLastUsedItem = gBattleMons[battlerId].item; if (gLastUsedItem == ITEM_ENIGMA_BERRY) { - BattlerHoldEffect = gEnigmaBerries[battlerId].holdEffect; - BattlerQuality = gEnigmaBerries[battlerId].holdEffectParam; + battlerHoldEffect = gEnigmaBerries[battlerId].holdEffect; + battlerHoldEffectParam = gEnigmaBerries[battlerId].holdEffectParam; } else { - BattlerHoldEffect = ItemId_GetHoldEffect(gLastUsedItem); - BattlerQuality = ItemId_GetHoldEffectParam(gLastUsedItem); + battlerHoldEffect = ItemId_GetHoldEffect(gLastUsedItem); + battlerHoldEffectParam = ItemId_GetHoldEffectParam(gLastUsedItem); } atkItem = gBattleMons[gBattlerAttacker].item; if (atkItem == ITEM_ENIGMA_BERRY) { atkHoldEffect = gEnigmaBerries[gBattlerAttacker].holdEffect; - atkQuality = gEnigmaBerries[gBattlerAttacker].holdEffectParam; + atkHoldEffectParam = gEnigmaBerries[gBattlerAttacker].holdEffectParam; } else { atkHoldEffect = ItemId_GetHoldEffect(atkItem); - atkQuality = ItemId_GetHoldEffectParam(atkItem); + atkHoldEffectParam = ItemId_GetHoldEffectParam(atkItem); } // def variables are unused @@ -2544,18 +2544,18 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) if (defItem == ITEM_ENIGMA_BERRY) { defHoldEffect = gEnigmaBerries[gBattlerTarget].holdEffect; - defQuality = gEnigmaBerries[gBattlerTarget].holdEffectParam; + defHoldEffectParam = gEnigmaBerries[gBattlerTarget].holdEffectParam; } else { defHoldEffect = ItemId_GetHoldEffect(defItem); - defQuality = ItemId_GetHoldEffectParam(defItem); + defHoldEffectParam = ItemId_GetHoldEffectParam(defItem); } switch (caseID) { case ITEMEFFECT_ON_SWITCH_IN: - switch (BattlerHoldEffect) + switch (battlerHoldEffect) { case HOLD_EFFECT_DOUBLE_PRIZE: if (GetBattlerSide(battlerId) == B_SIDE_PLAYER) @@ -2583,13 +2583,13 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) case 1: if (gBattleMons[battlerId].hp) { - switch (BattlerHoldEffect) + switch (battlerHoldEffect) { case HOLD_EFFECT_RESTORE_HP: if (gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / 2 && !moveTurn) { - gBattleMoveDamage = BattlerQuality; - if (gBattleMons[battlerId].hp + BattlerQuality > gBattleMons[battlerId].maxHP) + gBattleMoveDamage = battlerHoldEffectParam; + if (gBattleMons[battlerId].hp + battlerHoldEffectParam > gBattleMons[battlerId].maxHP) gBattleMoveDamage = gBattleMons[battlerId].maxHP - gBattleMons[battlerId].hp; gBattleMoveDamage *= -1; BattleScriptExecute(BattleScript_ItemHealHP_RemoveItem); @@ -2618,10 +2618,10 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) if (i != 4) { u8 maxPP = CalculatePPWithBonus(move, ppBonuses, i); - if (changedPP + BattlerQuality > maxPP) + if (changedPP + battlerHoldEffectParam > maxPP) changedPP = maxPP; else - changedPP = changedPP + BattlerQuality; + changedPP = changedPP + battlerHoldEffectParam; PREPARE_MOVE_BUFFER(gBattleTextBuff1, move); @@ -2660,7 +2660,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) gBattleMoveDamage *= -1; BattleScriptExecute(BattleScript_ItemHealHP_End2); effect = ITEM_HP_CHANGE; - RecordItemEffectBattle(battlerId, BattlerHoldEffect); + RecordItemEffectBattle(battlerId, battlerHoldEffect); } break; // nice copy/paste there gamefreak, making a function for confuse berries was too much eh? @@ -2669,7 +2669,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) { PREPARE_FLAVOR_BUFFER(gBattleTextBuff1, FLAVOR_SPICY); - gBattleMoveDamage = gBattleMons[battlerId].maxHP / BattlerQuality; + gBattleMoveDamage = gBattleMons[battlerId].maxHP / battlerHoldEffectParam; if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; if (gBattleMons[battlerId].hp + gBattleMoveDamage > gBattleMons[battlerId].maxHP) @@ -2687,7 +2687,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) { PREPARE_FLAVOR_BUFFER(gBattleTextBuff1, FLAVOR_DRY); - gBattleMoveDamage = gBattleMons[battlerId].maxHP / BattlerQuality; + gBattleMoveDamage = gBattleMons[battlerId].maxHP / battlerHoldEffectParam; if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; if (gBattleMons[battlerId].hp + gBattleMoveDamage > gBattleMons[battlerId].maxHP) @@ -2705,7 +2705,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) { PREPARE_FLAVOR_BUFFER(gBattleTextBuff1, FLAVOR_SWEET); - gBattleMoveDamage = gBattleMons[battlerId].maxHP / BattlerQuality; + gBattleMoveDamage = gBattleMons[battlerId].maxHP / battlerHoldEffectParam; if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; if (gBattleMons[battlerId].hp + gBattleMoveDamage > gBattleMons[battlerId].maxHP) @@ -2723,7 +2723,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) { PREPARE_FLAVOR_BUFFER(gBattleTextBuff1, FLAVOR_BITTER); - gBattleMoveDamage = gBattleMons[battlerId].maxHP / BattlerQuality; + gBattleMoveDamage = gBattleMons[battlerId].maxHP / battlerHoldEffectParam; if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; if (gBattleMons[battlerId].hp + gBattleMoveDamage > gBattleMons[battlerId].maxHP) @@ -2741,7 +2741,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) { PREPARE_FLAVOR_BUFFER(gBattleTextBuff1, FLAVOR_SOUR); - gBattleMoveDamage = gBattleMons[battlerId].maxHP / BattlerQuality; + gBattleMoveDamage = gBattleMons[battlerId].maxHP / battlerHoldEffectParam; if (gBattleMoveDamage == 0) gBattleMoveDamage = 1; if (gBattleMons[battlerId].hp + gBattleMoveDamage > gBattleMons[battlerId].maxHP) @@ -2756,7 +2756,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) break; // copy/paste again, smh case HOLD_EFFECT_ATTACK_UP: - if (gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / BattlerQuality && !moveTurn && gBattleMons[battlerId].statStages[STAT_ATK] < 0xC) + if (gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / battlerHoldEffectParam && !moveTurn && gBattleMons[battlerId].statStages[STAT_ATK] < 0xC) { PREPARE_STAT_BUFFER(gBattleTextBuff1, STAT_ATK); PREPARE_STRING_BUFFER(gBattleTextBuff2, STRINGID_STATROSE); @@ -2770,7 +2770,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) } break; case HOLD_EFFECT_DEFENSE_UP: - if (gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / BattlerQuality && !moveTurn && gBattleMons[battlerId].statStages[STAT_DEF] < 0xC) + if (gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / battlerHoldEffectParam && !moveTurn && gBattleMons[battlerId].statStages[STAT_DEF] < 0xC) { PREPARE_STAT_BUFFER(gBattleTextBuff1, STAT_DEF); @@ -2783,7 +2783,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) } break; case HOLD_EFFECT_SPEED_UP: - if (gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / BattlerQuality && !moveTurn && gBattleMons[battlerId].statStages[STAT_SPEED] < 0xC) + if (gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / battlerHoldEffectParam && !moveTurn && gBattleMons[battlerId].statStages[STAT_SPEED] < 0xC) { PREPARE_STAT_BUFFER(gBattleTextBuff1, STAT_SPEED); @@ -2796,7 +2796,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) } break; case HOLD_EFFECT_SP_ATTACK_UP: - if (gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / BattlerQuality && !moveTurn && gBattleMons[battlerId].statStages[STAT_SPATK] < 0xC) + if (gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / battlerHoldEffectParam && !moveTurn && gBattleMons[battlerId].statStages[STAT_SPATK] < 0xC) { PREPARE_STAT_BUFFER(gBattleTextBuff1, STAT_SPATK); @@ -2809,7 +2809,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) } break; case HOLD_EFFECT_SP_DEFENSE_UP: - if (gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / BattlerQuality && !moveTurn && gBattleMons[battlerId].statStages[STAT_SPDEF] < 0xC) + if (gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / battlerHoldEffectParam && !moveTurn && gBattleMons[battlerId].statStages[STAT_SPDEF] < 0xC) { PREPARE_STAT_BUFFER(gBattleTextBuff1, STAT_SPDEF); @@ -2822,7 +2822,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) } break; case HOLD_EFFECT_CRITICAL_UP: - if (gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / BattlerQuality && !moveTurn && !(gBattleMons[battlerId].status2 & STATUS2_FOCUS_ENERGY)) + if (gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / battlerHoldEffectParam && !moveTurn && !(gBattleMons[battlerId].status2 & STATUS2_FOCUS_ENERGY)) { gBattleMons[battlerId].status2 |= STATUS2_FOCUS_ENERGY; BattleScriptExecute(BattleScript_BerryFocusEnergyEnd2); @@ -2830,7 +2830,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) } break; case HOLD_EFFECT_RANDOM_STAT_UP: - if (!moveTurn && gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / BattlerQuality) + if (!moveTurn && gBattleMons[battlerId].hp <= gBattleMons[battlerId].maxHP / battlerHoldEffectParam) { for (i = 0; i < 5; i++) { @@ -2996,15 +2996,15 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) gLastUsedItem = gBattleMons[battlerId].item; if (gBattleMons[battlerId].item == ITEM_ENIGMA_BERRY) { - BattlerHoldEffect = gEnigmaBerries[battlerId].holdEffect; - BattlerQuality = gEnigmaBerries[battlerId].holdEffectParam; + battlerHoldEffect = gEnigmaBerries[battlerId].holdEffect; + battlerHoldEffectParam = gEnigmaBerries[battlerId].holdEffectParam; } else { - BattlerHoldEffect = ItemId_GetHoldEffect(gLastUsedItem); - BattlerQuality = ItemId_GetHoldEffectParam(gLastUsedItem); + battlerHoldEffect = ItemId_GetHoldEffect(gLastUsedItem); + battlerHoldEffectParam = ItemId_GetHoldEffectParam(gLastUsedItem); } - switch (BattlerHoldEffect) + switch (battlerHoldEffect) { case HOLD_EFFECT_CURE_PAR: if (gBattleMons[battlerId].status1 & STATUS1_PARALYSIS) @@ -3146,7 +3146,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) case HOLD_EFFECT_FLINCH: if (!(gMoveResultFlags & MOVE_RESULT_NO_EFFECT) && TARGET_TURN_DAMAGED - && (Random() % 100) < atkQuality + && (Random() % 100) < atkHoldEffectParam && gBattleMoves[gCurrentMove].flags & FLAG_KINGSROCK_AFFECTED && gBattleMons[gBattlerTarget].hp) { @@ -3167,7 +3167,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) gLastUsedItem = atkItem; gPotentialItemEffectBattler = gBattlerAttacker; gBattleScripting.battler = gBattlerAttacker; - gBattleMoveDamage = (gSpecialStatuses[gBattlerTarget].dmg / atkQuality) * -1; + gBattleMoveDamage = (gSpecialStatuses[gBattlerTarget].dmg / atkHoldEffectParam) * -1; if (gBattleMoveDamage == 0) gBattleMoveDamage = -1; gSpecialStatuses[gBattlerTarget].dmg = 0; diff --git a/src/braille_puzzles.c b/src/braille_puzzles.c index 91fcf8c46..b7ed1f713 100644 --- a/src/braille_puzzles.c +++ b/src/braille_puzzles.c @@ -7,6 +7,7 @@ #include "task.h" #include "field_effect.h" #include "constants/flags.h" +#include "constants/maps.h" extern void MapGridSetMetatileIdAt(s32 x, s32 y, u16 metatileId); // fieldmap extern void DrawWholeMapView(); // field_camera @@ -205,14 +206,25 @@ void SealedChamberShakingEffect(u8 taskId) // moved later in the function because it was rewritten. bool8 ShouldDoBrailleStrengthEffect(void) { - if (!FlagGet(FLAG_SYS_BRAILLE_STRENGTH) && (gSaveBlock1Ptr->location.mapGroup == 0x18 && gSaveBlock1Ptr->location.mapNum == 0x06)) + if (!FlagGet(FLAG_SYS_BRAILLE_STRENGTH) + && gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(DESERT_RUINS) + && gSaveBlock1Ptr->location.mapNum == MAP_NUM(DESERT_RUINS)) { if (gSaveBlock1Ptr->pos.x == 6 && gSaveBlock1Ptr->pos.y == 23) - { sBraillePuzzleCallbackFlag = STRENGTH_PUZZLE; return TRUE; } + { + sBraillePuzzleCallbackFlag = STRENGTH_PUZZLE; + return TRUE; + } else if (gSaveBlock1Ptr->pos.x == 5 && gSaveBlock1Ptr->pos.y == 23) - { sBraillePuzzleCallbackFlag = STRENGTH_PUZZLE; return TRUE; } + { + sBraillePuzzleCallbackFlag = STRENGTH_PUZZLE; + return TRUE; + } else if (gSaveBlock1Ptr->pos.x == 7 && gSaveBlock1Ptr->pos.y == 23) - { sBraillePuzzleCallbackFlag = STRENGTH_PUZZLE; return TRUE; } + { + sBraillePuzzleCallbackFlag = STRENGTH_PUZZLE; + return TRUE; + } } return FALSE; diff --git a/src/pokemon.c b/src/pokemon.c index 5406cfee9..bb2959eda 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -2265,7 +2265,7 @@ s32 CalculateBaseDamage(struct BattlePokemon *attacker, struct BattlePokemon *de if (attackerHoldEffect == sHoldEffectToType[i][0] && type == sHoldEffectToType[i][1]) { - if (type <= 8) + if (IS_MOVE_PHYSICAL(type)) attack = (attack * (attackerHoldEffectParam + 100)) / 100; else spAttack = (spAttack * (attackerHoldEffectParam + 100)) / 100; @@ -2293,9 +2293,9 @@ s32 CalculateBaseDamage(struct BattlePokemon *attacker, struct BattlePokemon *de spAttack /= 2; if (attacker->ability == ABILITY_HUSTLE) attack = (150 * attack) / 100; - if (attacker->ability == ABILITY_PLUS && AbilityBattleEffects(ABILITYEFFECT_FIELD_SPORT, 0, ABILITY_MINUS, 0, 0)) + if (attacker->ability == ABILITY_PLUS && ABILITY_ON_FIELD2(ABILITY_MINUS)) spAttack = (150 * spAttack) / 100; - if (attacker->ability == ABILITY_MINUS && AbilityBattleEffects(ABILITYEFFECT_FIELD_SPORT, 0, ABILITY_PLUS, 0, 0)) + if (attacker->ability == ABILITY_MINUS && ABILITY_ON_FIELD2(ABILITY_PLUS)) spAttack = (150 * spAttack) / 100; if (attacker->ability == ABILITY_GUTS && attacker->status1) attack = (150 * attack) / 100; @@ -2316,7 +2316,7 @@ s32 CalculateBaseDamage(struct BattlePokemon *attacker, struct BattlePokemon *de if (gBattleMoves[gCurrentMove].effect == EFFECT_EXPLOSION) defense /= 2; - if (type < TYPE_MYSTERY) // is physical + if (IS_MOVE_PHYSICAL(type) && type != TYPE_MYSTERY) { if (gCritMultiplier == 2) { @@ -2366,7 +2366,7 @@ s32 CalculateBaseDamage(struct BattlePokemon *attacker, struct BattlePokemon *de if (type == TYPE_MYSTERY) damage = 0; // is ??? type. does 0 damage. - if (type > TYPE_MYSTERY) // is special? + if (IS_MOVE_SPECIAL(type)) { if (gCritMultiplier == 2) { @@ -2406,8 +2406,7 @@ s32 CalculateBaseDamage(struct BattlePokemon *attacker, struct BattlePokemon *de damage /= 2; // are effects of weather negated with cloud nine or air lock - if (!AbilityBattleEffects(ABILITYEFFECT_FIELD_SPORT, 0, ABILITY_CLOUD_NINE, 0, 0) - && !AbilityBattleEffects(ABILITYEFFECT_FIELD_SPORT, 0, ABILITY_AIR_LOCK, 0, 0)) + if (WEATHER_HAS_EFFECT2) { if (gBattleWeather & WEATHER_RAIN_TEMPORARY) { @@ -4514,7 +4513,7 @@ u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 type, u16 evolutionItem) holdEffect = ItemId_GetHoldEffect(heldItem); if (holdEffect == HOLD_EFFECT_PREVENT_EVOLVE && type != 3) - return 0; + return SPECIES_NONE; switch (type) { @@ -4522,7 +4521,7 @@ u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 type, u16 evolutionItem) level = GetMonData(mon, MON_DATA_LEVEL, 0); friendship = GetMonData(mon, MON_DATA_FRIENDSHIP, 0); - for (i = 0; i < 5; i++) + for (i = 0; i < EVOS_PER_MON; i++) { switch (gEvolutionTable[species][i].method) { @@ -4579,7 +4578,7 @@ u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 type, u16 evolutionItem) } break; case 1: - for (i = 0; i < 5; i++) + for (i = 0; i < EVOS_PER_MON; i++) { switch (gEvolutionTable[species][i].method) { @@ -4599,7 +4598,7 @@ u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 type, u16 evolutionItem) break; case 2: case 3: - for (i = 0; i < 5; i++) + for (i = 0; i < EVOS_PER_MON; i++) { if (gEvolutionTable[species][i].method == EVO_ITEM && gEvolutionTable[species][i].param == evolutionItem) From 118fa3afcee68deb3eeb2bc876a9afd02a45677c Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 16 Jul 2018 22:00:27 +0200 Subject: [PATCH 15/15] IS_MOVE_PHYSICAL to IS_TYPE_PHYSIAL --- include/battle.h | 4 ++-- src/battle_script_commands.c | 6 +++--- src/pokemon.c | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/battle.h b/include/battle.h index 3843bc5e6..bd7ba4b35 100644 --- a/include/battle.h +++ b/include/battle.h @@ -555,8 +555,8 @@ struct BattleStruct typeArg = gBattleMoves[move].type; \ } -#define IS_MOVE_PHYSICAL(moveType)(moveType < TYPE_MYSTERY) -#define IS_MOVE_SPECIAL(moveType)(moveType > TYPE_MYSTERY) +#define IS_TYPE_PHYSICAL(moveType)(moveType < TYPE_MYSTERY) +#define IS_TYPE_SPECIAL(moveType)(moveType > TYPE_MYSTERY) #define TARGET_TURN_DAMAGED ((gSpecialStatuses[gBattlerTarget].physicalDmg != 0 || gSpecialStatuses[gBattlerTarget].specialDmg != 0)) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 87244ff5a..3af03a5e0 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -1173,7 +1173,7 @@ static void atk01_accuracycheck(void) calc = (calc * 130) / 100; // 1.3 compound eyes boost if (WEATHER_HAS_EFFECT && gBattleMons[gBattlerTarget].ability == ABILITY_SAND_VEIL && gBattleWeather & WEATHER_SANDSTORM_ANY) calc = (calc * 80) / 100; // 1.2 sand veil loss - if (gBattleMons[gBattlerAttacker].ability == ABILITY_HUSTLE && IS_MOVE_PHYSICAL(type)) + if (gBattleMons[gBattlerAttacker].ability == ABILITY_HUSTLE && IS_TYPE_PHYSICAL(type)) calc = (calc * 80) / 100; // 1.2 hustle loss if (gBattleMons[gBattlerTarget].item == ITEM_ENIGMA_BERRY) @@ -1945,7 +1945,7 @@ static void atk0C_datahpupdate(void) if (!gSpecialStatuses[gActiveBattler].dmg && !(gHitMarker & HITMARKER_x100000)) gSpecialStatuses[gActiveBattler].dmg = gHpDealt; - if (IS_MOVE_PHYSICAL(moveType) && !(gHitMarker & HITMARKER_x100000) && gCurrentMove != MOVE_PAIN_SPLIT) + if (IS_TYPE_PHYSICAL(moveType) && !(gHitMarker & HITMARKER_x100000) && gCurrentMove != MOVE_PAIN_SPLIT) { gProtectStructs[gActiveBattler].physicalDmg = gHpDealt; gSpecialStatuses[gActiveBattler].physicalDmg = gHpDealt; @@ -1960,7 +1960,7 @@ static void atk0C_datahpupdate(void) gSpecialStatuses[gActiveBattler].physicalBattlerId = gBattlerTarget; } } - else if (!IS_MOVE_PHYSICAL(moveType) && !(gHitMarker & HITMARKER_x100000)) + else if (!IS_TYPE_PHYSICAL(moveType) && !(gHitMarker & HITMARKER_x100000)) { gProtectStructs[gActiveBattler].specialDmg = gHpDealt; gSpecialStatuses[gActiveBattler].specialDmg = gHpDealt; diff --git a/src/pokemon.c b/src/pokemon.c index bb2959eda..c572ee10e 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -2265,7 +2265,7 @@ s32 CalculateBaseDamage(struct BattlePokemon *attacker, struct BattlePokemon *de if (attackerHoldEffect == sHoldEffectToType[i][0] && type == sHoldEffectToType[i][1]) { - if (IS_MOVE_PHYSICAL(type)) + if (IS_TYPE_PHYSICAL(type)) attack = (attack * (attackerHoldEffectParam + 100)) / 100; else spAttack = (spAttack * (attackerHoldEffectParam + 100)) / 100; @@ -2316,7 +2316,7 @@ s32 CalculateBaseDamage(struct BattlePokemon *attacker, struct BattlePokemon *de if (gBattleMoves[gCurrentMove].effect == EFFECT_EXPLOSION) defense /= 2; - if (IS_MOVE_PHYSICAL(type) && type != TYPE_MYSTERY) + if (IS_TYPE_PHYSICAL(type)) { if (gCritMultiplier == 2) { @@ -2366,7 +2366,7 @@ s32 CalculateBaseDamage(struct BattlePokemon *attacker, struct BattlePokemon *de if (type == TYPE_MYSTERY) damage = 0; // is ??? type. does 0 damage. - if (IS_MOVE_SPECIAL(type)) + if (IS_TYPE_SPECIAL(type)) { if (gCritMultiplier == 2) {