diff --git a/data/maps/BattleFrontier_BattleTowerMultiBattleRoom/scripts.inc b/data/maps/BattleFrontier_BattleTowerMultiBattleRoom/scripts.inc index f4de372322..dfce6d1550 100644 --- a/data/maps/BattleFrontier_BattleTowerMultiBattleRoom/scripts.inc +++ b/data/maps/BattleFrontier_BattleTowerMultiBattleRoom/scripts.inc @@ -143,7 +143,7 @@ BattleFrontier_BattleTowerMultiBattleRoom_EventScript_RestoreParty:: @ 8249121 special LoadPlayerParty frontier_setpartyorder FRONTIER_MULTI_PARTY_SIZE compare VAR_FRONTIER_BATTLE_MODE, FRONTIER_MODE_LINK_MULTIS - call_if_eq BattleFrontier_BattleTowerMultiBattleRoom_EventScript_249514 + call_if_eq BattleFrontier_BattleTowerMultiBattleRoom_EventScript_ReconnectLink playfanfare MUS_HEAL waitfanfare special HealPlayerParty @@ -383,9 +383,8 @@ BattleFrontier_BattleTowerMultiBattleRoom_EventScript_RetireChallengeLink:: @ 82 goto BattleFrontier_BattleTowerMultiBattleRoom_EventScript_WarpToLobbyLost end -@ Some link function. Sets battle type flags at least -BattleFrontier_BattleTowerMultiBattleRoom_EventScript_249514:: @ 8249514 - special sub_813B534 +BattleFrontier_BattleTowerMultiBattleRoom_EventScript_ReconnectLink:: @ 8249514 + special BattleTowerReconnectLink return BattleFrontier_BattleTowerMultiBattleRoom_Movement_PlayerEnterRoom: @ 8249518 diff --git a/data/specials.inc b/data/specials.inc index 97f6983791..620fae369b 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -514,7 +514,7 @@ gSpecials:: @ 81DBA64 def_special SetMewAboveGrass def_special ShouldDistributeEonTicket def_special LinkRetireStatusWithBattleTowerPartner - def_special sub_813B534 + def_special BattleTowerReconnectLink def_special CallTrainerHillFunction def_special Script_DoRayquazaScene @ Listed twice def_special LoopWingFlapSE diff --git a/include/cable_club.h b/include/cable_club.h index 7340742ea9..a5a6acfa47 100644 --- a/include/cable_club.h +++ b/include/cable_club.h @@ -7,7 +7,7 @@ void CreateTask_EnterCableClubSeat(TaskFunc taskFunc); u8 CreateTask_ReestablishCableClubLink(void); void CB2_ReturnFromCableClubBattle(void); bool32 AreBattleTowerLinkSpeciesSame(u16 *speciesList1, u16 *speciesList2); -void sub_80B3AF8(u8 taskId); +void Task_ReconnectWithLinkPlayers(u8 taskId); void Task_WaitForLinkPlayerConnection(u8 taskId); bool32 GetLinkTrainerCardColor(u8 linkPlayerIndex); diff --git a/include/constants/battle_tower.h b/include/constants/battle_tower.h index f661ddc0bc..002422d850 100644 --- a/include/constants/battle_tower.h +++ b/include/constants/battle_tower.h @@ -33,9 +33,9 @@ #define BATTLE_TOWER_LINK_CONTINUE 0 #define BATTLE_TOWER_LINK_RETIRE 1 -#define BATTLE_TOWER_LINKSTAT_CONTINUE 0 -#define BATTLE_TOWER_LINKSTAT_BOTH_RETIRE 1 -#define BATTLE_TOWER_LINKSTAT_PARTNER_RETIRE 2 -#define BATTLE_TOWER_LINKSTAT_PLAYER_RETIRE 3 +#define BATTLE_TOWER_LINKSTAT_CONTINUE 0 +#define BATTLE_TOWER_LINKSTAT_BOTH_RETIRE 1 +#define BATTLE_TOWER_LINKSTAT_MEMBER_RETIRE 2 +#define BATTLE_TOWER_LINKSTAT_LEADER_RETIRE 3 #endif //GUARD_CONSTANTS_BATTLE_TOWER_H diff --git a/src/battle_main.c b/src/battle_main.c index 75e74fe541..a1bc6ae7bf 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -2276,7 +2276,7 @@ static void EndLinkBattleInSteps(void) } else if (gReceivedRemoteLinkPlayers == 0) { - CreateTask(sub_80B3AF8, 5); + CreateTask(Task_ReconnectWithLinkPlayers, 5); gBattleCommunication[MULTIUSE_STATE]++; } else @@ -2307,7 +2307,7 @@ static void EndLinkBattleInSteps(void) gBattleCommunication[MULTIUSE_STATE]++; break; case 5: - if (!FuncIsActiveTask(sub_80B3AF8)) + if (!FuncIsActiveTask(Task_ReconnectWithLinkPlayers)) gBattleCommunication[MULTIUSE_STATE]++; break; case 6: @@ -2430,11 +2430,11 @@ static void sub_803939C(void) break; case 1: if (gMain.field_439_x4 && gReceivedRemoteLinkPlayers == 0) - CreateTask(sub_80B3AF8, 5); + CreateTask(Task_ReconnectWithLinkPlayers, 5); gBattleCommunication[MULTIUSE_STATE]++; break; case 2: - if (!FuncIsActiveTask(sub_80B3AF8)) + if (!FuncIsActiveTask(Task_ReconnectWithLinkPlayers)) gBattleCommunication[MULTIUSE_STATE]++; break; case 3: diff --git a/src/cable_club.c b/src/cable_club.c index 77cb0465c4..8b321d6703 100644 --- a/src/cable_club.c +++ b/src/cable_club.c @@ -1267,7 +1267,8 @@ static void sub_80B3AD0(u8 taskId) #define tTimer data[1] -void sub_80B3AF8(u8 taskId) +// Confirm that all cabled link players are connected +void Task_ReconnectWithLinkPlayers(u8 taskId) { s16 *data = gTasks[taskId].data; diff --git a/src/field_specials.c b/src/field_specials.c index 9e944a3847..86be21edac 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -3735,14 +3735,17 @@ bool32 ShouldDistributeEonTicket(void) return TRUE; } -void sub_813B534(void) +#define tState data[0] + +void BattleTowerReconnectLink(void) { + // Save battle type, restored at end + // of Task_LinkRetireStatusWithBattleTowerPartner sBattleTowerMultiBattleTypeFlags = gBattleTypeFlags; gBattleTypeFlags = 0; + if (!gReceivedRemoteLinkPlayers) - { - CreateTask(sub_80B3AF8, 5); - } + CreateTask(Task_ReconnectWithLinkPlayers, 5); } void LinkRetireStatusWithBattleTowerPartner(void) @@ -3750,137 +3753,145 @@ void LinkRetireStatusWithBattleTowerPartner(void) CreateTask(Task_LinkRetireStatusWithBattleTowerPartner, 5); } +// Communicate with a Battle Tower link partner to tell them +// whether or not the player chose to continue or retire, +// and determine what the partner chose to do +// gSpecialVar_0x8004: Player's choice +// gSpecialVar_0x8005: Partner's choice (read from gBlockRecvBuffer[1][0]) static void Task_LinkRetireStatusWithBattleTowerPartner(u8 taskId) { - switch (gTasks[taskId].data[0]) + switch (gTasks[taskId].tState) { - case 0: - if (!FuncIsActiveTask(sub_80B3AF8)) - { - gTasks[taskId].data[0]++; - } - break; - case 1: - if (IsLinkTaskFinished() == TRUE) - { - if (GetMultiplayerId() == 0) - { - gTasks[taskId].data[0]++; - } - else - { - SendBlock(bitmask_all_link_players_but_self(), &gSpecialVar_0x8004, 2); - gTasks[taskId].data[0]++; - } - } - break; - case 2: - if ((GetBlockReceivedStatus() & 2) != 0) - { - if (GetMultiplayerId() == 0) - { - gSpecialVar_0x8005 = gBlockRecvBuffer[1][0]; - ResetBlockReceivedFlag(1); - if (gSpecialVar_0x8004 == BATTLE_TOWER_LINK_RETIRE - && gSpecialVar_0x8005 == BATTLE_TOWER_LINK_RETIRE) - { - gSpecialVar_Result = BATTLE_TOWER_LINKSTAT_BOTH_RETIRE; - } - else if (gSpecialVar_0x8004 == BATTLE_TOWER_LINK_CONTINUE - && gSpecialVar_0x8005 == BATTLE_TOWER_LINK_RETIRE) - { - gSpecialVar_Result = BATTLE_TOWER_LINKSTAT_PARTNER_RETIRE; - } - else if (gSpecialVar_0x8004 == BATTLE_TOWER_LINK_RETIRE - && gSpecialVar_0x8005 == BATTLE_TOWER_LINK_CONTINUE) - { - gSpecialVar_Result = BATTLE_TOWER_LINKSTAT_PLAYER_RETIRE; - } - else - { - gSpecialVar_Result = BATTLE_TOWER_LINKSTAT_CONTINUE; - } - } - gTasks[taskId].data[0]++; - } - break; - case 3: - if (IsLinkTaskFinished() == TRUE) - { - if (GetMultiplayerId() != 0) - { - gTasks[taskId].data[0]++; - } - else - { - SendBlock(bitmask_all_link_players_but_self(), &gSpecialVar_Result, 2); - gTasks[taskId].data[0]++; - } - } - break; - case 4: - if ((GetBlockReceivedStatus() & 1) != 0) - { - if (GetMultiplayerId() != 0) - { - gSpecialVar_Result = gBlockRecvBuffer[0][0]; - ResetBlockReceivedFlag(0); - gTasks[taskId].data[0]++; - } - else - { - gTasks[taskId].data[0]++; - } - } - break; - case 5: + case 0: + if (!FuncIsActiveTask(Task_ReconnectWithLinkPlayers)) + { + gTasks[taskId].tState++; + } + break; + case 1: + if (IsLinkTaskFinished() == TRUE) + { if (GetMultiplayerId() == 0) { - if (gSpecialVar_Result == BATTLE_TOWER_LINKSTAT_PARTNER_RETIRE) - { - ShowFieldAutoScrollMessage(gText_YourPartnerHasRetired); - } + // Player is link leader, skip sending data + gTasks[taskId].tState++; } else { - if (gSpecialVar_Result == BATTLE_TOWER_LINKSTAT_PLAYER_RETIRE) + // Send value of gSpecialVar_0x8004 to leader + // Will either be BATTLE_TOWER_LINK_CONTINUE or BATTLE_TOWER_LINK_RETIRE + SendBlock(bitmask_all_link_players_but_self(), &gSpecialVar_0x8004, sizeof(gSpecialVar_0x8004)); + gTasks[taskId].tState++; + } + } + break; + case 2: + if (GetBlockReceivedStatus() & 2) + { + if (GetMultiplayerId() == 0) + { + // Player is leader, read partner's choice + // and determine if play should continue + gSpecialVar_0x8005 = gBlockRecvBuffer[1][0]; + ResetBlockReceivedFlag(1); + + if (gSpecialVar_0x8004 == BATTLE_TOWER_LINK_RETIRE + && gSpecialVar_0x8005 == BATTLE_TOWER_LINK_RETIRE) { - ShowFieldAutoScrollMessage(gText_YourPartnerHasRetired); + gSpecialVar_Result = BATTLE_TOWER_LINKSTAT_BOTH_RETIRE; + } + else if (gSpecialVar_0x8004 == BATTLE_TOWER_LINK_CONTINUE + && gSpecialVar_0x8005 == BATTLE_TOWER_LINK_RETIRE) + { + gSpecialVar_Result = BATTLE_TOWER_LINKSTAT_MEMBER_RETIRE; + } + else if (gSpecialVar_0x8004 == BATTLE_TOWER_LINK_RETIRE + && gSpecialVar_0x8005 == BATTLE_TOWER_LINK_CONTINUE) + { + gSpecialVar_Result = BATTLE_TOWER_LINKSTAT_LEADER_RETIRE; + } + else + { + gSpecialVar_Result = BATTLE_TOWER_LINKSTAT_CONTINUE; } } - gTasks[taskId].data[0]++; - break; - case 6: - if (!IsTextPrinterActive(0)) + gTasks[taskId].tState++; + } + break; + case 3: + if (IsLinkTaskFinished() == TRUE) + { + if (GetMultiplayerId() != 0) { - gTasks[taskId].data[0]++; + // Player is not link leader, wait for leader's response + gTasks[taskId].tState++; } - break; - case 7: - if (IsLinkTaskFinished() == 1) + else { - SetLinkStandbyCallback(); - gTasks[taskId].data[0]++; + // Send whether or not play should continue + SendBlock(bitmask_all_link_players_but_self(), &gSpecialVar_Result, sizeof(gSpecialVar_Result)); + gTasks[taskId].tState++; } - break; - case 8: - if (IsLinkTaskFinished() == 1) + } + break; + case 4: + if (GetBlockReceivedStatus() & 1) + { + if (GetMultiplayerId() != 0) { - gTasks[taskId].data[0]++; + // Player is not link leader, read leader's response + gSpecialVar_Result = gBlockRecvBuffer[0][0]; + ResetBlockReceivedFlag(0); + gTasks[taskId].tState++; } - break; - case 9: - if (gWirelessCommType == 0) + else { - SetCloseLinkCallback(); + gTasks[taskId].tState++; } - gBattleTypeFlags = sBattleTowerMultiBattleTypeFlags; - EnableBothScriptContexts(); - DestroyTask(taskId); - break; + } + break; + case 5: + // Print message if partner chose to retire (and player didn't) + if (GetMultiplayerId() == 0) + { + if (gSpecialVar_Result == BATTLE_TOWER_LINKSTAT_MEMBER_RETIRE) + ShowFieldAutoScrollMessage(gText_YourPartnerHasRetired); + } + else + { + if (gSpecialVar_Result == BATTLE_TOWER_LINKSTAT_LEADER_RETIRE) + ShowFieldAutoScrollMessage(gText_YourPartnerHasRetired); + } + gTasks[taskId].tState++; + break; + case 6: + if (!IsTextPrinterActive(0)) + gTasks[taskId].tState++; + break; + case 7: + if (IsLinkTaskFinished() == TRUE) + { + SetLinkStandbyCallback(); + gTasks[taskId].tState++; + } + break; + case 8: + if (IsLinkTaskFinished() == TRUE) + gTasks[taskId].tState++; + break; + case 9: + if (gWirelessCommType == 0) + SetCloseLinkCallback(); + + gBattleTypeFlags = sBattleTowerMultiBattleTypeFlags; + EnableBothScriptContexts(); + DestroyTask(taskId); + break; } } +#undef tState + void Script_DoRayquazaScene(void) { if (!gSpecialVar_0x8004)