From 585c0dc428c603411a445e9c6944149daf1bebd6 Mon Sep 17 00:00:00 2001 From: Alex Bates Date: Fri, 24 Dec 2021 14:21:03 +0000 Subject: [PATCH] Name and document btl_init_menu_* funcs (#567) * btl_init_menu_* * https://c.tenor.com/D0mk5R5x1G8AAAAC/cat-fat-cat.gif --- include/common_structs.h | 8 +- include/enums.h | 30 +++ src/190B20.c | 171 ++++++++++++------ .../415D90/btl_state_update_partner_menu.s | 2 +- .../415D90/btl_state_update_player_menu.s | 8 +- ver/us/symbol_addrs.txt | 6 +- 6 files changed, 154 insertions(+), 71 deletions(-) diff --git a/include/common_structs.h b/include/common_structs.h index a7b6722c22..c9c92ae704 100644 --- a/include/common_structs.h +++ b/include/common_structs.h @@ -679,7 +679,7 @@ typedef struct BattleStatus { /* 0x07A */ u8 incrementStarPointDelay; /* related to star points, set to 0x28 when they are dropped */ /* 0x07B */ u8 damageTaken; /* 0x07C */ u8 changePartnerAllowed; - /* 0x07D */ char unk_7D[4]; + /* 0x07D */ s8 menuStatus[4]; ///< -1 = automatically pick the first move, 0 = disabled, 1 = enabled /* 0x081 */ s8 actionSuccess; /* 0x082 */ char unk_82; /* 0x083 */ s8 unk_83; @@ -736,7 +736,7 @@ typedef struct BattleStatus { /* 0x171 */ s8 numEnemyActors; /* 0x172 */ s16 currentTurnEnemyID; /* 0x174 */ struct Actor* currentTurnEnemy; - /* 0x178 */ s8 moveCategory; + /* 0x178 */ s8 moveCategory; ///< 0 = jump, 1 = hammer, 5 = partner, ... /* 0x179 */ char unk_179; /* 0x17A */ s16 selectedItemID; /* 0x17C */ s16 selectedMoveID; @@ -765,7 +765,7 @@ typedef struct BattleStatus { /* 0x1AA */ char unk_1AA[4]; /* 0x1AE */ s16 submenuIcons[24]; /* icon IDs */ /* 0x1DE */ u8 submenuMoves[24]; /* move IDs */ - /* 0x1F6 */ s8 submenuEnabled[24]; + /* 0x1F6 */ s8 submenuStatus[24]; ///< @see enum BattleSubmenuStatus /* 0x20E */ u8 submenuMoveCount; /* 0x20F */ char unk_20F; /* 0x210 */ s32 currentButtonsDown; @@ -810,7 +810,7 @@ typedef struct StaticMove { /* 0x04 */ s32 flags; /* 0x08 */ s32 worldDescID; /* 0x0C */ s32 menuDescID; - /* 0x10 */ s8 battleSubmenu; + /* 0x10 */ s8 battleSubmenu; ///< @see enum BattleSubmenu /* 0x11 */ s8 costFP; /* 0x12 */ s8 costBP; /* 0x13 */ u8 actionCommandID; diff --git a/include/enums.h b/include/enums.h index 1d331cfff2..d208300880 100644 --- a/include/enums.h +++ b/include/enums.h @@ -2043,54 +2043,72 @@ enum MoveIDs { MOVE_PEACH_BEAM = 0x00000080, MOVE_PEACH_FOCUS = 0x00000081, MOVE_TWINK_DASH = 0x00000082, + + // Goombario moves MOVE_HEADBONK1 = 0x00000083, MOVE_HEADBONK2 = 0x00000084, MOVE_HEADBONK3 = 0x00000085, MOVE_TATTLE = 0x00000086, MOVE_CHARGE = 0x00000087, MOVE_MULTIBONK = 0x00000088, + + // Kooper moves MOVE_SHELL_TOSS1 = 0x00000089, MOVE_SHELL_TOSS2 = 0x0000008A, MOVE_SHELL_TOSS3 = 0x0000008B, MOVE_POWER_SHELL = 0x0000008C, MOVE_DIZZY_SHELL = 0x0000008D, MOVE_FIRE_SHELL = 0x0000008E, + + // Bombette moves MOVE_BODY_SLAM1 = 0x0000008F, MOVE_BODY_SLAM2 = 0x00000090, MOVE_BODY_SLAM3 = 0x00000091, MOVE_BOMB = 0x00000092, MOVE_POWER_BOMB = 0x00000093, MOVE_MEGA_BOMB = 0x00000094, + + // Parakarry moves MOVE_SKY_DIVE1 = 0x00000095, MOVE_SKY_DIVE2 = 0x00000096, MOVE_SKY_DIVE3 = 0x00000097, MOVE_SHELL_SHOT = 0x00000098, MOVE_AIR_LIFT = 0x00000099, MOVE_AIR_RAID = 0x0000009A, + + // Goompa moves MOVE_UNUSED_LONE_FOOL1 = 0x0000009B, MOVE_UNUSED_LONE_FOOL2 = 0x0000009C, MOVE_UNUSED_LONE_FOOL3 = 0x0000009D, MOVE_UNUSED_MUMBLE = 0x0000009E, MOVE_UNUSED_PREACH = 0x0000009F, MOVE_UNUSED_AWAKENING = 0x000000A0, + + // Watt moves MOVE_ELECTRO_DASH1 = 0x000000A1, MOVE_ELECTRO_DASH2 = 0x000000A2, MOVE_ELECTRO_DASH3 = 0x000000A3, MOVE_POWER_SHOCK = 0x000000A4, MOVE_TURBO_CHARGE = 0x000000A5, MOVE_MEGA_SHOCK = 0x000000A6, + + // Sushie moves MOVE_BELLY_FLOP1 = 0x000000A7, MOVE_BELLY_FLOP2 = 0x000000A8, MOVE_BELLY_FLOP3 = 0x000000A9, MOVE_SQUIRT = 0x000000AA, MOVE_WATER_BLOCK = 0x000000AB, MOVE_TIDAL_WAVE = 0x000000AC, + + // Lakilester moves MOVE_SPINY_FLIP1 = 0x000000AD, MOVE_SPINY_FLIP2 = 0x000000AE, MOVE_SPINY_FLIP3 = 0x000000AF, MOVE_SPINY_SURGE = 0x000000B0, MOVE_CLOUD_NINE = 0x000000B1, MOVE_HURRICANE = 0x000000B2, + + // Bow moves MOVE_SMACK1 = 0x000000B3, MOVE_SMACK2 = 0x000000B4, MOVE_SMACK3 = 0x000000B5, @@ -2974,4 +2992,16 @@ enum FoldStateFlags { FOLD_STATE_FLAG_100000 = 0x00100000, }; +enum BattleSubmenu { + BATTLE_SUBMENU_HAMMER = 1, + BATTLE_SUBMENU_JUMP = 2, +}; + +enum BattleSubmenuStatus { + BATTLE_SUBMENU_STATUS_ENABLED = 1, + BATTLE_SUBMENU_STATUS_NOT_ENOUGH_FP = 0, + BATTLE_SUBMENU_STATUS_NO_TARGETS = -1, + BATTLE_SUBMENU_STATUS_NO_TARGETS_2 = -2, // TODO: determine difference, probably uses a different error message +}; + #endif diff --git a/src/190B20.c b/src/190B20.c index e304842527..6fda0ef91f 100644 --- a/src/190B20.c +++ b/src/190B20.c @@ -1137,48 +1137,55 @@ s32 btl_check_player_defeated(void) { return TRUE; } -void func_802634B8(void) { +void btl_init_menu_boots(void) { BattleStatus* battleStatus = &gBattleStatus; PlayerData* playerData = &gPlayerData; Actor* player = battleStatus->playerActor; StaticMove* move; s32 i; s32 moveCount; - s32 phi_s6; + s32 hasAnyBadgeMoves; s32 fpCost; + // If you don't have boots equipped, disable this menu if (playerData->bootsLevel == -1) { - battleStatus->unk_7D[1] = 0; + battleStatus->menuStatus[1] = 0; return; } for (i = 0; i < ARRAY_COUNT(battleStatus->submenuMoves); i++) { - battleStatus->submenuMoves[i] = 0; + battleStatus->submenuMoves[i] = MOVE_NONE; } + // Standard jump move moveCount = 1; - battleStatus->submenuMoves[0] = playerData->bootsLevel + 26; - battleStatus->submenuIcons[0] = 0x155; + battleStatus->submenuMoves[0] = playerData->bootsLevel + MOVE_JUMP1; + battleStatus->submenuIcons[0] = ITEM_PARTNER_ATTACK; + + // Jump badges do { for (i = 0; i < ARRAY_COUNT(playerData->equippedBadges); i++) { - s16 badges = playerData->equippedBadges[i]; - if (badges != 0) { + s16 badge = playerData->equippedBadges[i]; + if (badge != ITEM_NONE) { StaticMove* moveTable = gMoveTable; - u8 moveID = gItemTable[badges].moveID; + u8 moveID = gItemTable[badge].moveID; move = &moveTable[moveID]; - if ((s8) move->battleSubmenu == 2) { - battleStatus->submenuMoves[moveCount] = moveID; + if (move->battleSubmenu == BATTLE_SUBMENU_JUMP) { + battleStatus->submenuMoves[moveCount] = moveID; battleStatus->submenuIcons[moveCount] = playerData->equippedBadges[i]; moveCount++; } } } } while (0); + battleStatus->submenuMoveCount = moveCount; - phi_s6 = FALSE; + hasAnyBadgeMoves = FALSE; for (i = 0; i < battleStatus->submenuMoveCount; i++) { move = &gMoveTable[battleStatus->submenuMoves[i]]; + + // Calculate FP cost fpCost = move->costFP; if (fpCost != 0) { fpCost -= player_team_is_ability_active(player, ABILITY_FLOWER_SAVER); @@ -1187,45 +1194,56 @@ void func_802634B8(void) { fpCost = 1; } } + + // See if there are any targets for this move battleStatus->moveCategory = 0; battleStatus->selectedItemID = playerData->bootsLevel; - battleStatus->currentTargetListFlags = move->flags; + battleStatus->currentTargetListFlags = move->flags; // Controls target filters player_create_target_list(player); + + // If there are targets, enable the move if (player->targetListLength != 0) { - phi_s6 = TRUE; - battleStatus->submenuEnabled[i] = 1; + hasAnyBadgeMoves = TRUE; + battleStatus->submenuStatus[i] = BATTLE_SUBMENU_STATUS_ENABLED; } + // If you don't have enough FP, disable the move if (playerData->curFP < fpCost) { - battleStatus->submenuEnabled[i] = 0; + battleStatus->submenuStatus[i] = BATTLE_SUBMENU_STATUS_NOT_ENOUGH_FP; } + + // If there are no targets available, disable the move if (player->targetListLength == 0) { - battleStatus->submenuEnabled[i] = -2; + battleStatus->submenuStatus[i] = BATTLE_SUBMENU_STATUS_NO_TARGETS_2; } - if ((gBattleStatus.flags2 & BS_FLAGS2_NO_TARGET_AVAILABLE) != 0) { - battleStatus->submenuEnabled[moveCount] = -1; + if (gBattleStatus.flags2 & BS_FLAGS2_NO_TARGET_AVAILABLE) { + battleStatus->submenuStatus[moveCount] = BATTLE_SUBMENU_STATUS_NO_TARGETS; } } - if (!phi_s6) { - battleStatus->unk_7D[1] = -1; + if (!hasAnyBadgeMoves) { + // Only the standard jump is available - no badge moves. + // Selecting this submenu should immediately pick the standard jump move + battleStatus->menuStatus[1] = -1; } else { - battleStatus->unk_7D[1] = 1; + // Enable this submenu + battleStatus->menuStatus[1] = 1; } } -void func_802636E4(void) { +void btl_init_menu_hammer(void) { BattleStatus* battleStatus = &gBattleStatus; PlayerData* playerData = &gPlayerData; Actor* player = battleStatus->playerActor; StaticMove* move; s32 i; s32 moveCount; - s32 phi_s6; + s32 hasAnyBadgeMoves; s32 fpCost; + // If you don't have a hammer, disable this menu if (playerData->hammerLevel == -1) { - battleStatus->unk_7D[2] = 0; + battleStatus->menuStatus[2] = 0; return; } @@ -1233,29 +1251,35 @@ void func_802636E4(void) { battleStatus->submenuMoves[i] = 0; } + // Standard hammer move moveCount = 1; - battleStatus->submenuMoves[0] = playerData->hammerLevel + 3; - battleStatus->submenuIcons[0] = 0x155; + battleStatus->submenuMoves[0] = playerData->hammerLevel + MOVE_HAMMER1; + battleStatus->submenuIcons[0] = ITEM_PARTNER_ATTACK; + + // Hammer badges do { for (i = 0; i < ARRAY_COUNT(playerData->equippedBadges); i++) { - s16 badges = playerData->equippedBadges[i]; - if (badges != 0) { + s16 badge = playerData->equippedBadges[i]; + if (badge != MOVE_NONE) { StaticMove* moveTable = gMoveTable; - u8 moveID = gItemTable[badges].moveID; + u8 moveID = gItemTable[badge].moveID; move = &moveTable[moveID]; - if ((s8) move->battleSubmenu == 1) { - battleStatus->submenuMoves[moveCount] = moveID; + if (move->battleSubmenu == BATTLE_SUBMENU_HAMMER) { + battleStatus->submenuMoves[moveCount] = moveID; battleStatus->submenuIcons[moveCount] = playerData->equippedBadges[i]; moveCount++; } } } } while (0); + battleStatus->submenuMoveCount = moveCount; - phi_s6 = FALSE; + hasAnyBadgeMoves = FALSE; for (i = 0; i < battleStatus->submenuMoveCount; i++) { move = &gMoveTable[battleStatus->submenuMoves[i]]; + + // Calculate FP cost fpCost = move->costFP; if (fpCost != 0) { fpCost -= player_team_is_ability_active(player, ABILITY_FLOWER_SAVER); @@ -1264,57 +1288,87 @@ void func_802636E4(void) { fpCost = 1; } } + + // See if there are any targets for this move battleStatus->moveCategory = 1; battleStatus->selectedItemID = playerData->hammerLevel; battleStatus->currentTargetListFlags = move->flags; player_create_target_list(player); + + // If there are targets, enable the move if (player->targetListLength != 0) { - phi_s6 = TRUE; - battleStatus->submenuEnabled[i] = 1; + hasAnyBadgeMoves = TRUE; + battleStatus->submenuStatus[i] = 1; } + // If you don't have enough FP, disable the move if (playerData->curFP < fpCost) { - battleStatus->submenuEnabled[i] = 0; + battleStatus->submenuStatus[i] = 0; } + + // If there are no targets available, disable the move if (player->targetListLength == 0) { - battleStatus->submenuEnabled[i] = -2; + battleStatus->submenuStatus[i] = BATTLE_SUBMENU_STATUS_NO_TARGETS_2; } - if ((gBattleStatus.flags2 & BS_FLAGS2_NO_TARGET_AVAILABLE) != 0) { - battleStatus->submenuEnabled[moveCount] = -1; + if (gBattleStatus.flags2 & BS_FLAGS2_NO_TARGET_AVAILABLE) { + battleStatus->submenuStatus[moveCount] = BATTLE_SUBMENU_STATUS_NO_TARGETS; } } - if (!phi_s6) { - battleStatus->unk_7D[2] = -1; + if (!hasAnyBadgeMoves) { + // Only the standard hammer is available - no badge moves. + // Selecting this submenu should immediately pick the standard hammer move + battleStatus->menuStatus[2] = -1; } else { - battleStatus->unk_7D[2] = 1; + // Enable this submenu + battleStatus->menuStatus[2] = 1; } } -void func_80263914(void) { +void btl_init_menu_partner(void) { PlayerData* playerData = &gPlayerData; BattleStatus* battleStatus = &gBattleStatus; Actor* player = battleStatus->playerActor; Actor* partner = battleStatus->partnerActor; s32 fpCost; s32 i; - s32 phi_s6; + s32 hasAnyBadgeMoves; for (i = 0; i < ARRAY_COUNT(battleStatus->submenuMoves); i++) { battleStatus->submenuMoves[i] = 0; } - battleStatus->submenuMoveCount = partner->staticActorData->level + 2; - // First move is changed each level - battleStatus->submenuMoves[0] = playerData->currentPartner * 6 + 0x7D + partner->staticActorData->level; + // In the move table (enum MoveIDs), partners get move IDs set up like this: + // + // Move ID offset | Description | Goombario example + // ----------------+----------------------+------------------- + // 0 | No rank only | Headbonk + // 1 | Super rank only | Headbonk (2) + // 2 | Ultra rank only | Headbonk (3) + // 3 | Always unlocked | Tattle + // 4 | Unlocked after super | Charge + // 5 | Unlocked after ultra | Multibonk + battleStatus->submenuMoveCount = partner->staticActorData->level + 2; + + // Offsets 0,1,2 + battleStatus->submenuMoves[0] = + playerData->currentPartner * 6 + + (MOVE_HEADBONK1 - 6) + + partner->staticActorData->level; + + // Offsets 3,4,5 for (i = 1; i < battleStatus->submenuMoveCount; i++) { - battleStatus->submenuMoves[i] = playerData->currentPartner * 6 + 0x7F + i; + battleStatus->submenuMoves[i] = + playerData->currentPartner * 6 + + (MOVE_TATTLE - 6) + + (i - 1); } - phi_s6 = FALSE; + hasAnyBadgeMoves = FALSE; for (i = 0; i < battleStatus->submenuMoveCount; i++){ StaticMove* move = &gMoveTable[battleStatus->submenuMoves[i]]; + fpCost = move->costFP; if (fpCost != 0) { fpCost -= player_team_is_ability_active(player, ABILITY_FLOWER_SAVER); @@ -1327,31 +1381,30 @@ void func_80263914(void) { battleStatus->moveCategory = 5; battleStatus->selectedItemID = partner->staticActorData->level; battleStatus->currentTargetListFlags = move->flags; - player_create_target_list(partner); + if (partner->targetListLength != 0){ - phi_s6 = TRUE; - battleStatus->submenuEnabled[i] = 1; + hasAnyBadgeMoves = TRUE; + battleStatus->submenuStatus[i] = BATTLE_SUBMENU_STATUS_ENABLED; } if (partner->targetListLength == 0) { - battleStatus->submenuEnabled[i] = -2; + battleStatus->submenuStatus[i] = BATTLE_SUBMENU_STATUS_NO_TARGETS_2; } if (playerData->curFP < fpCost) { - battleStatus->submenuEnabled[i] = 0; + battleStatus->submenuStatus[i] = BATTLE_SUBMENU_STATUS_NOT_ENOUGH_FP; } - if (gBattleStatus.flags2 & BS_FLAGS2_NO_TARGET_AVAILABLE) { - battleStatus->submenuEnabled[i] = -1; + battleStatus->submenuStatus[i] = BATTLE_SUBMENU_STATUS_NO_TARGETS; } } - if (!phi_s6) { - battleStatus->unk_7D[3] = -1; + if (!hasAnyBadgeMoves) { + battleStatus->menuStatus[3] = -1; } else { - battleStatus->unk_7D[3] = 1; + battleStatus->menuStatus[3] = 1; } } diff --git a/ver/us/asm/nonmatchings/415D90/btl_state_update_partner_menu.s b/ver/us/asm/nonmatchings/415D90/btl_state_update_partner_menu.s index e9bd41bf7a..45ba04595b 100644 --- a/ver/us/asm/nonmatchings/415D90/btl_state_update_partner_menu.s +++ b/ver/us/asm/nonmatchings/415D90/btl_state_update_partner_menu.s @@ -231,7 +231,7 @@ glabel btl_state_update_partner_menu /* 41D2A4 802A8514 24020006 */ addiu $v0, $zero, 6 /* 41D2A8 802A8518 A282005C */ sb $v0, 0x5c($s4) .L802A851C: -/* 41D2AC 802A851C 0C098E45 */ jal func_80263914 +/* 41D2AC 802A851C 0C098E45 */ jal btl_init_menu_partner /* 41D2B0 802A8520 00000000 */ nop /* 41D2B4 802A8524 0C098C9A */ jal func_80263268 /* 41D2B8 802A8528 00000000 */ nop diff --git a/ver/us/asm/nonmatchings/415D90/btl_state_update_player_menu.s b/ver/us/asm/nonmatchings/415D90/btl_state_update_player_menu.s index 2b398b7227..4c0abfe021 100644 --- a/ver/us/asm/nonmatchings/415D90/btl_state_update_player_menu.s +++ b/ver/us/asm/nonmatchings/415D90/btl_state_update_player_menu.s @@ -217,9 +217,9 @@ glabel btl_state_update_player_menu /* 41AA2C 802A5C9C 00000000 */ nop /* 41AA30 802A5CA0 0C098CC0 */ jal func_80263300 /* 41AA34 802A5CA4 00000000 */ nop -/* 41AA38 802A5CA8 0C098D2E */ jal func_802634B8 +/* 41AA38 802A5CA8 0C098D2E */ jal btl_init_menu_boots /* 41AA3C 802A5CAC 00000000 */ nop -/* 41AA40 802A5CB0 0C098DB9 */ jal func_802636E4 +/* 41AA40 802A5CB0 0C098DB9 */ jal btl_init_menu_hammer /* 41AA44 802A5CB4 00000000 */ nop /* 41AA48 802A5CB8 02E0202D */ daddu $a0, $s7, $zero /* 41AA4C 802A5CBC 0C099CAB */ jal player_team_is_ability_active @@ -752,12 +752,12 @@ glabel btl_state_update_player_menu /* 41B1F0 802A6460 080A99AC */ j .L802A66B0 /* 41B1F4 802A6464 A2C0020E */ sb $zero, 0x20e($s6) .L802A6468: -/* 41B1F8 802A6468 0C098DB9 */ jal func_802636E4 +/* 41B1F8 802A6468 0C098DB9 */ jal btl_init_menu_hammer /* 41B1FC 802A646C 00000000 */ nop /* 41B200 802A6470 080A9920 */ j .L802A6480 /* 41B204 802A6474 00000000 */ nop .L802A6478: -/* 41B208 802A6478 0C098D2E */ jal func_802634B8 +/* 41B208 802A6478 0C098D2E */ jal btl_init_menu_boots /* 41B20C 802A647C 00000000 */ nop .L802A6480: /* 41B210 802A6480 92C2020E */ lbu $v0, 0x20e($s6) diff --git a/ver/us/symbol_addrs.txt b/ver/us/symbol_addrs.txt index 5257037c3d..c6a7b91136 100644 --- a/ver/us/symbol_addrs.txt +++ b/ver/us/symbol_addrs.txt @@ -4195,9 +4195,9 @@ func_80263300 = 0x80263300; // type:func rom:0x191BE0 btl_are_all_enemies_defeated = 0x802633E8; // type:func rom:0x191CC8 btl_check_enemies_defeated = 0x80263434; // type:func rom:0x191D14 btl_check_player_defeated = 0x80263464; // type:func rom:0x191D44 -func_802634B8 = 0x802634B8; // type:func rom:0x191D98 -func_802636E4 = 0x802636E4; // type:func rom:0x191FC4 -func_80263914 = 0x80263914; // type:func rom:0x1921F4 +btl_init_menu_boots = 0x802634B8; // type:func rom:0x191D98 +btl_init_menu_hammer = 0x802636E4; // type:func rom:0x191FC4 +btl_init_menu_partner = 0x80263914; // type:func rom:0x1921F4 count_power_plus = 0x80263B10; // type:func rom:0x1923F0 deduct_current_move_fp = 0x80263BC8; // type:func rom:0x1924A8 reset_actor_turn_info = 0x80263C60; // type:func rom:0x192540