From 769ddf22c266c2bf41d3353c5972bca8fa49c085 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 24 Dec 2020 16:18:47 -0500 Subject: [PATCH] Label remaining subs in battle_tower.c --- asm/macros/battle_frontier/battle_tower.inc | 6 +- .../scripts.inc | 2 +- include/battle_tower.h | 2 +- include/constants/battle_tower.h | 2 +- include/pokemon.h | 4 +- include/recorded_battle.h | 2 +- src/battle_main.c | 2 +- src/battle_tower.c | 62 +++++++++++-------- src/pokemon.c | 23 ++++--- src/recorded_battle.c | 2 +- 10 files changed, 60 insertions(+), 47 deletions(-) diff --git a/asm/macros/battle_frontier/battle_tower.inc b/asm/macros/battle_frontier/battle_tower.inc index 71e795b1d1..ccc777c507 100644 --- a/asm/macros/battle_frontier/battle_tower.inc +++ b/asm/macros/battle_frontier/battle_tower.inc @@ -72,9 +72,9 @@ special CallBattleTowerFunc .endm - @ Unknown. Destroys some link task if using wireless link. Wait for link? - .macro tower_unklink - setvar VAR_0x8004, BATTLE_TOWER_FUNC_13 + @ Attempts to close link connection. Used when finishing a link multi challenge. + .macro tower_closelink + setvar VAR_0x8004, BATTLE_TOWER_FUNC_TRY_CLOSE_LINK special CallBattleTowerFunc .endm diff --git a/data/maps/BattleFrontier_BattleTowerBattleRoom/scripts.inc b/data/maps/BattleFrontier_BattleTowerBattleRoom/scripts.inc index 493588b4dd..cc623e2166 100644 --- a/data/maps/BattleFrontier_BattleTowerBattleRoom/scripts.inc +++ b/data/maps/BattleFrontier_BattleTowerBattleRoom/scripts.inc @@ -443,7 +443,7 @@ BattleFrontier_BattleTowerBattleRoom_EventScript_WarpToLobbyMultis:: @ 82421F2 end BattleFrontier_BattleTowerBattleRoom_EventScript_WarpToLobbyLinkMultis:: @ 82421FC - tower_unklink + tower_closelink warp MAP_BATTLE_FRONTIER_BATTLE_TOWER_LOBBY, 255, 18, 6 waitstate end diff --git a/include/battle_tower.h b/include/battle_tower.h index 30649719b4..a803145927 100644 --- a/include/battle_tower.h +++ b/include/battle_tower.h @@ -83,6 +83,6 @@ u8 GetFrontierEnemyMonLevel(u8 lvlMode); s32 GetHighestLevelInPlayerParty(void); u8 FacilityClassToGraphicsId(u8 facilityClass); bool32 ValidateBattleTowerRecord(u8 recordId); // unused -void sub_8166188(void); +void TrySetLinkBattleTowerEnemyPartyLevel(void); #endif //GUARD_BATTLE_TOWER_H diff --git a/include/constants/battle_tower.h b/include/constants/battle_tower.h index b372c3ad5c..f661ddc0bc 100644 --- a/include/constants/battle_tower.h +++ b/include/constants/battle_tower.h @@ -14,7 +14,7 @@ #define BATTLE_TOWER_FUNC_LOAD_PARTNERS 10 #define BATTLE_TOWER_FUNC_PARTNER_MSG 11 #define BATTLE_TOWER_FUNC_LOAD_LINK_OPPONENTS 12 -#define BATTLE_TOWER_FUNC_13 13 +#define BATTLE_TOWER_FUNC_TRY_CLOSE_LINK 13 #define BATTLE_TOWER_FUNC_SET_PARTNER_GFX 14 #define BATTLE_TOWER_FUNC_SET_INTERVIEW_DATA 15 diff --git a/include/pokemon.h b/include/pokemon.h index a956b9c406..497e8070b4 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -275,7 +275,7 @@ void CreateBattleTowerMon(struct Pokemon *mon, struct BattleTowerPokemon *src); void CreateBattleTowerMon2(struct Pokemon *mon, struct BattleTowerPokemon *src, bool8 lvl50); void CreateApprenticeMon(struct Pokemon *mon, const struct Apprentice *src, u8 monId); void CreateMonWithEVSpreadNatureOTID(struct Pokemon *mon, u16 species, u8 level, u8 nature, u8 fixedIV, u8 evSpread, u32 otId); -void sub_80686FC(struct Pokemon *mon, struct BattleTowerPokemon *dest); +void ConvertPokemonToBattleTowerPokemon(struct Pokemon *mon, struct BattleTowerPokemon *dest); void CreateObedientMon(struct Pokemon *mon, u16 species, u8 level, u8 fixedIV, u8 hasFixedPersonality, u32 fixedPersonality, u8 otIdType, u32 fixedOtId); bool8 sub_80688F8(u8 caseId, u8 battlerId); void SetDeoxysStats(void); @@ -381,7 +381,7 @@ void ClearBattleMonForms(void); u16 GetBattleBGM(void); void PlayBattleBGM(void); void PlayMapChosenOrBattleBGM(u16 songId); -void sub_806E694(u16 songId); +void CreateTask_PlayMapChosenOrBattleBGM(u16 songId); const u32 *GetMonFrontSpritePal(struct Pokemon *mon); const u32 *GetMonSpritePalFromSpeciesAndPersonality(u16 species, u32 otId, u32 personality); const struct CompressedSpritePalette *GetMonSpritePalStruct(struct Pokemon *mon); diff --git a/include/recorded_battle.h b/include/recorded_battle.h index 84c5c2ea29..252b25502f 100644 --- a/include/recorded_battle.h +++ b/include/recorded_battle.h @@ -30,7 +30,7 @@ void sub_818603C(u8 arg0); u32 GetAiScriptsInRecordedBattle(void); void sub_8186444(void); bool8 sub_8186450(void); -void sub_8186468(u8 *dst); +void GetRecordedBattleRecordMixFriendName(u8 *dst); u8 GetRecordedBattleRecordMixFriendClass(void); u8 GetRecordedBattleApprenticeId(void); u8 GetRecordedBattleRecordMixFriendLanguage(void); diff --git a/src/battle_main.c b/src/battle_main.c index 5bc80f61e8..29a8f560a1 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -1357,7 +1357,7 @@ static void CB2_HandleStartMultiPartnerBattle(void) case 16: if (BattleInitAllSprites(&gBattleCommunication[SPRITES_INIT_STATE1], &gBattleCommunication[SPRITES_INIT_STATE2])) { - sub_8166188(); + TrySetLinkBattleTowerEnemyPartyLevel(); gPreBattleCallback1 = gMain.callback1; gMain.callback1 = BattleMainCB1; SetMainCallback2(BattleMainCB2); diff --git a/src/battle_tower.c b/src/battle_tower.c index d7123f3d20..ee75feeb43 100644 --- a/src/battle_tower.c +++ b/src/battle_tower.c @@ -57,12 +57,12 @@ static void SetTowerBattleWon(void); static void AwardBattleTowerRibbons(void); static void SaveTowerChallenge(void); static void GetOpponentIntroSpeech(void); -static void nullsub_61(void); -static void nullsub_116(void); +static void BattleTowerNop1(void); +static void BattleTowerNop2(void); static void LoadMultiPartnerCandidatesData(void); static void ShowPartnerCandidateMessage(void); static void LoadLinkMultiOpponentsData(void); -static void sub_8164DCC(void); +static void TowerTryCloseLink(void); static void SetMultiPartnerGfx(void); static void SetTowerInterviewData(void); static void ValidateBattleTowerRecordChecksums(void); @@ -811,12 +811,12 @@ static void (* const sBattleTowerFuncs[])(void) = [BATTLE_TOWER_FUNC_GIVE_RIBBONS] = AwardBattleTowerRibbons, [BATTLE_TOWER_FUNC_SAVE] = SaveTowerChallenge, [BATTLE_TOWER_FUNC_GET_OPPONENT_INTRO] = GetOpponentIntroSpeech, - [BATTLE_TOWER_FUNC_NOP] = nullsub_61, - [BATTLE_TOWER_FUNC_NOP2] = nullsub_116, + [BATTLE_TOWER_FUNC_NOP] = BattleTowerNop1, + [BATTLE_TOWER_FUNC_NOP2] = BattleTowerNop2, [BATTLE_TOWER_FUNC_LOAD_PARTNERS] = LoadMultiPartnerCandidatesData, [BATTLE_TOWER_FUNC_PARTNER_MSG] = ShowPartnerCandidateMessage, [BATTLE_TOWER_FUNC_LOAD_LINK_OPPONENTS] = LoadLinkMultiOpponentsData, - [BATTLE_TOWER_FUNC_13] = sub_8164DCC, + [BATTLE_TOWER_FUNC_TRY_CLOSE_LINK] = TowerTryCloseLink, [BATTLE_TOWER_FUNC_SET_PARTNER_GFX] = SetMultiPartnerGfx, [BATTLE_TOWER_FUNC_SET_INTERVIEW_DATA] = SetTowerInterviewData, }; @@ -1547,7 +1547,7 @@ void GetFrontierTrainerName(u8 *dst, u16 trainerId) { if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) { - sub_8186468(dst); + GetRecordedBattleRecordMixFriendName(dst); return; } else @@ -2059,7 +2059,7 @@ void DoSpecialTrainerBattle(void) if (gTrainerBattleOpponent_A == TRAINER_FRONTIER_BRAIN) FillFrontierTrainerParty(DOME_BATTLE_PARTY_SIZE); CreateTask(Task_StartBattleAfterTransition, 1); - sub_806E694(0); + CreateTask_PlayMapChosenOrBattleBGM(0); BattleTransition_StartOnField(GetSpecialBattleTransition(3)); break; case SPECIAL_BATTLE_PALACE: @@ -2139,7 +2139,7 @@ static void SaveCurrentWinStreak(void) gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode] = winStreak; } -static void sub_8163EE4(void) +static void SaveBattleTowerRecord(void) { s32 i; u8 lvlMode, battleMode, class; @@ -2178,7 +2178,7 @@ static void sub_8163EE4(void) for (i = 0; i < MAX_FRONTIER_PARTY_SIZE; i++) { if (gSaveBlock2Ptr->frontier.selectedPartyMons[i] != 0) - sub_80686FC(&gPlayerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1], &playerRecord->party[i]); + ConvertPokemonToBattleTowerPokemon(&gPlayerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1], &playerRecord->party[i]); } playerRecord->language = gGameLanguage; @@ -2193,7 +2193,7 @@ static void SaveTowerChallenge(void) s32 challengeNum = (signed)(gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode] / 7); if (gSpecialVar_0x8005 == 0 && (challengeNum > 1 || gSaveBlock2Ptr->frontier.curChallengeBattleNum != 0)) - sub_8163EE4(); + SaveBattleTowerRecord(); gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005; VarSet(VAR_TEMP_0, 0); @@ -2201,12 +2201,12 @@ static void SaveTowerChallenge(void) SaveGameFrontier(); } -static void nullsub_61(void) +static void BattleTowerNop1(void) { } -static void nullsub_116(void) +static void BattleTowerNop2(void) { } @@ -2410,7 +2410,7 @@ static void LoadMultiPartnerCandidatesData(void) } } -static void sub_81646BC(u16 trainerId, u16 monId) +static void GetPotentialPartnerMoveAndSpecies(u16 trainerId, u16 monId) { u16 move = 0; u16 species = 0; @@ -2445,6 +2445,14 @@ static void sub_81646BC(u16 trainerId, u16 monId) StringCopy(gStringVar2, gSpeciesNames[species]); } +// For multi battles in the Battle Tower, the player may choose a partner by talking to them +// These partners can be an NPC or a former/record-mixed Apprentice +// When talked to, their response consists of: +// PARTNER_MSGID_INTRO - A greeting +// PARTNER_MSGID_MON1 - Naming one pokemon on their team, and a move it has +// PARTNER_MSGID_MON2_ASK - Naming a second pokemon on their team, a move it has, and asking if they'd like to be their partner +// PARTNER_MSGID_ACCEPT - If the player agrees to be their partner +// PARTNER_MSGID_REJECT - If the player declines to be their partner static void ShowPartnerCandidateMessage(void) { s32 i, j, partnerId; @@ -2487,11 +2495,11 @@ static void ShowPartnerCandidateMessage(void) break; case PARTNER_MSGID_MON1: monId = gSaveBlock2Ptr->frontier.trainerIds[8 + k * 2]; - sub_81646BC(trainerId, monId); + GetPotentialPartnerMoveAndSpecies(trainerId, monId); break; case PARTNER_MSGID_MON2_ASK: monId = gSaveBlock2Ptr->frontier.trainerIds[9 + k * 2]; - sub_81646BC(trainerId, monId); + GetPotentialPartnerMoveAndSpecies(trainerId, monId); break; case PARTNER_MSGID_ACCEPT: gPartnerTrainerId = trainerId; @@ -2643,7 +2651,7 @@ static void LoadLinkMultiOpponentsData(void) } } -static void sub_8164DCC(void) +static void TowerTryCloseLink(void) { if (gWirelessCommType != 0) SetCloseLinkCallback(); @@ -2838,7 +2846,7 @@ static void FillEReaderTrainerWithPlayerData(void) } for (i = 0; i < 3; i++) - sub_80686FC(&gPlayerParty[i], &ereaderTrainer->party[i]); + ConvertPokemonToBattleTowerPokemon(&gPlayerParty[i], &ereaderTrainer->party[i]); SetEReaderTrainerChecksum(ereaderTrainer); } @@ -3292,16 +3300,16 @@ static u8 GetFrontierTrainerFixedIvs(u16 trainerId) return fixedIv; } -static u16 sub_8165D40(void) +static u16 GetBattleTentTrainerId(void) { u32 facility = VarGet(VAR_FRONTIER_FACILITY); - if (facility == FRONTIER_FACILITY_PALACE) - return Random() % 30; - else if (facility == FRONTIER_FACILITY_ARENA) - return Random() % 30; - else if (facility == FRONTIER_FACILITY_FACTORY) - return Random() % 30; + if (facility == FRONTIER_FACILITY_PALACE) // Verdanturf Tent; uses Palace mechanics + return Random() % NUM_BATTLE_TENT_TRAINERS; + else if (facility == FRONTIER_FACILITY_ARENA) // Fallarbor Tent; uses Arena mechanics + return Random() % NUM_BATTLE_TENT_TRAINERS; + else if (facility == FRONTIER_FACILITY_FACTORY) // Slateport Tent; uses Factory mechanics + return Random() % NUM_BATTLE_TENT_TRAINERS; else if (facility == FRONTIER_FACILITY_TOWER) return 0; else @@ -3348,7 +3356,7 @@ static void SetNextBattleTentOpponent(void) do { - trainerId = sub_8165D40(); + trainerId = GetBattleTentTrainerId(); for (i = 0; i < gSaveBlock2Ptr->frontier.curChallengeBattleNum; i++) { if (gSaveBlock2Ptr->frontier.trainerIds[i] == trainerId) @@ -3511,7 +3519,7 @@ bool32 ValidateBattleTowerRecord(u8 recordId) // unused } } -void sub_8166188(void) +void TrySetLinkBattleTowerEnemyPartyLevel(void) { if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000)) { diff --git a/src/pokemon.c b/src/pokemon.c index 4753735503..b5eee16b23 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -57,7 +57,7 @@ static u16 CalculateBoxMonChecksum(struct BoxPokemon *boxMon); static union PokemonSubstruct *GetSubstruct(struct BoxPokemon *boxMon, u32 personality, u8 substructType); static void EncryptBoxMon(struct BoxPokemon *boxMon); static void DecryptBoxMon(struct BoxPokemon *boxMon); -static void sub_806E6CC(u8 taskId); +static void Task_PlayMapChosenOrBattleBGM(u8 taskId); static bool8 ShouldGetStatBadgeBoost(u16 flagId, u8 battlerId); static u16 GiveMoveToBoxMon(struct BoxPokemon *boxMon, u16 move); static bool8 ShouldSkipFriendshipChange(void); @@ -2578,7 +2578,7 @@ void CreateMonWithEVSpreadNatureOTID(struct Pokemon *mon, u16 species, u8 level, CalculateMonStats(mon); } -void sub_80686FC(struct Pokemon *mon, struct BattleTowerPokemon *dest) +void ConvertPokemonToBattleTowerPokemon(struct Pokemon *mon, struct BattleTowerPokemon *dest) { s32 i; u16 heldItem; @@ -2587,7 +2587,7 @@ void sub_80686FC(struct Pokemon *mon, struct BattleTowerPokemon *dest) heldItem = GetMonData(mon, MON_DATA_HELD_ITEM, NULL); if (heldItem == ITEM_ENIGMA_BERRY) - heldItem = 0; + heldItem = ITEM_NONE; dest->heldItem = heldItem; @@ -6334,26 +6334,31 @@ void PlayMapChosenOrBattleBGM(u16 songId) PlayNewMapMusic(GetBattleBGM()); } -void sub_806E694(u16 songId) +// Identical to PlayMapChosenOrBattleBGM, but uses a task instead +// Only used by Battle Dome +#define tSongId data[0] +void CreateTask_PlayMapChosenOrBattleBGM(u16 songId) { u8 taskId; ResetMapMusic(); m4aMPlayAllStop(); - taskId = CreateTask(sub_806E6CC, 0); - gTasks[taskId].data[0] = songId; + taskId = CreateTask(Task_PlayMapChosenOrBattleBGM, 0); + gTasks[taskId].tSongId = songId; } -static void sub_806E6CC(u8 taskId) +static void Task_PlayMapChosenOrBattleBGM(u8 taskId) { - if (gTasks[taskId].data[0]) - PlayNewMapMusic(gTasks[taskId].data[0]); + if (gTasks[taskId].tSongId) + PlayNewMapMusic(gTasks[taskId].tSongId); else PlayNewMapMusic(GetBattleBGM()); DestroyTask(taskId); } +#undef tSongId + const u32 *GetMonFrontSpritePal(struct Pokemon *mon) { u16 species = GetMonData(mon, MON_DATA_SPECIES2, 0); diff --git a/src/recorded_battle.c b/src/recorded_battle.c index 5a0579f709..881c2d3ec8 100644 --- a/src/recorded_battle.c +++ b/src/recorded_battle.c @@ -846,7 +846,7 @@ bool8 sub_8186450(void) return (sUnknown_0203CCD0 == 0); } -void sub_8186468(u8 *dst) +void GetRecordedBattleRecordMixFriendName(u8 *dst) { s32 i;