From 07fa82c911c5a22f0671a4ea798056b8de3c0a80 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 10 Oct 2019 03:50:51 -0400 Subject: [PATCH] Last non-anim trade.c doc --- include/constants/trade.h | 26 ++-- include/link.h | 6 +- include/trade.h | 8 +- src/cable_club.c | 4 +- src/data/trade.h | 36 ++--- src/evolution_scene.c | 4 +- src/link.c | 13 +- src/party_menu.c | 8 +- src/trade.c | 290 +++++++++++++++++--------------------- 9 files changed, 185 insertions(+), 210 deletions(-) diff --git a/include/constants/trade.h b/include/constants/trade.h index 8a2626c9a3..4fb8966d0c 100644 --- a/include/constants/trade.h +++ b/include/constants/trade.h @@ -12,10 +12,6 @@ #define INGAME_TRADE_HORSEA 2 #define INGAME_TRADE_MEOWTH 3 -#define PLAYER_MON_INVALID 0 -#define PLAYER_MON_VALID 1 -#define PARTNER_MON_INVALID 2 - // Flag IDs for sending link data #define INITIATE_TRADE 1 #define CANCEL_TRADE 2 @@ -24,7 +20,7 @@ #define READY_FINISH_TRADE 1 #define FINISH_TRADE 2 -// Return values for CanTradeSelectedMon +// Return values for CanTradeSelectedMon and CanTradeSelectedPartyMenuMon #define CAN_TRADE_MON 0 #define CANT_TRADE_LAST_MON 1 #define CANT_TRADE_NATIONAL 2 @@ -32,6 +28,16 @@ #define CANT_TRADE_INVALID_MON 4 #define CANT_TRADE_EGG2 5 +// Return values for CheckValidityOfTradeMons +#define PLAYER_MON_INVALID 0 +#define BOTH_MONS_VALID 1 +#define PARTNER_MON_INVALID 2 + +// Return values for GetGameProgressForLinkTrade +#define TRADE_BOTH_PLAYERS_READY 0 +#define TRADE_PLAYER_NOT_READY 1 +#define TRADE_PARTNER_NOT_READY 2 + // Indexes for sTradeActionTexts #define TRADE_TEXT_CANCEL 0 #define TRADE_TEXT_CHOOSE_MON 1 @@ -40,12 +46,7 @@ #define TRADE_TEXT_CANCEL_TRADE 4 #define TRADE_TEXT_JP_QUIT 5 -#define MENU_ACTION_SUMMARY 0 -#define MENU_ACTION_TRADE 1 -#define MENU_ACTION_CONFIRM_TRADE 0 -#define MENU_ACTION_CANCEL_TRADE 1 - -#define DRAW_PARTY_BEGIN 1 +// Checked to confirm DrawTradeMenuParty has reached final state #define DRAW_PARTY_FINISH 5 // Message indexes for sTradeMessages @@ -59,7 +60,7 @@ #define TRADE_MSG_EGG_CANT_BE_TRADED 7 #define TRADE_MSG_FRIENDS_MON_CANT_BE_TRADED 8 -// Queue actions +// IDs for QueueAction #define QUEUE_SEND_DATA 0 #define QUEUE_STANDBY 1 #define QUEUE_ONLY_MON1 2 @@ -70,7 +71,6 @@ #define QUEUE_EGG_CANT_BE_TRADED 7 #define QUEUE_FRIENDS_MON_CANT_BE_TRADED 8 -// Queue delays #define QUEUE_DELAY_MSG 3 #define QUEUE_DELAY_DATA 5 diff --git a/include/link.h b/include/link.h index f149f8a92e..04efc973c4 100644 --- a/include/link.h +++ b/include/link.h @@ -106,8 +106,8 @@ enum EXCHANGE_COMPLETE, EXCHANGE_TIMED_OUT, EXCHANGE_IN_PROGRESS, - EXCHANGE_STAT_4, - EXCHANGE_STAT_5, + EXCHANGE_PLAYER_NOT_READY, + EXCHANGE_PARTNER_NOT_READY, EXCHANGE_STAT_6, EXCHANGE_STAT_7 }; @@ -132,7 +132,7 @@ struct LinkPlayer /* 0x02 */ u16 lp_field_2; /* 0x04 */ u32 trainerId; /* 0x08 */ u8 name[PLAYER_NAME_LENGTH + 1]; - /* 0x10 */ u8 progressFlags; // 0x0F is hasClearedGame, 0xF0 is hasNationalDex + /* 0x10 */ u8 progressFlags; // (& 0x0F) is hasNationalDex, (& 0xF0) is hasClearedGame /* 0x11 */ u8 neverRead; /* 0x12 */ u8 progressFlagsCopy; /* 0x13 */ u8 gender; diff --git a/include/trade.h b/include/trade.h index a0385297ea..42bfc14827 100644 --- a/include/trade.h +++ b/include/trade.h @@ -13,14 +13,14 @@ extern u8 gSelectedTradeMonPositions[2]; // Exported ROM declarations extern const struct WindowTemplate gTradeEvolutionSceneYesNoWindowTemplate; -s32 sub_807A728(void); +s32 GetGameProgressForLinkTrade(void); void CB2_StartCreateTradeMenu(void); void CB2_LinkTrade(void); int CanRegisterMonForTradingBoard(struct UnkLinkRfuStruct_02022B14Substruct a0, u16, u16, u8); int GetUnionRoomTradeMessageId(struct UnkLinkRfuStruct_02022B14Substruct a0, struct UnkLinkRfuStruct_02022B14Substruct a1, u16 a2, u16 a3, u8 a4, u16 a5, u8 a6); -int sub_807A918(struct Pokemon*, u16); -void sub_807B140(void); -void sub_807B154(void); +int CanTradeSelectedPartyMenuMon(struct Pokemon*, u16); +void InitTradeSequenceBgGpuRegs(void); +void LinkTradeDrawWindow(void); void InitTradeBg(void); void DrawTextOnTradeWindow(u8, const u8 *, u8); diff --git a/src/cable_club.c b/src/cable_club.c index 22fc2d0c14..755e3575ec 100644 --- a/src/cable_club.c +++ b/src/cable_club.c @@ -123,9 +123,9 @@ static u32 sub_80B2478(u8 lower, u8 upper) return 1; case EXCHANGE_IN_PROGRESS: return 3; - case EXCHANGE_STAT_4: + case EXCHANGE_PLAYER_NOT_READY: return 7; - case EXCHANGE_STAT_5: + case EXCHANGE_PARTNER_NOT_READY: return 9; case EXCHANGE_STAT_6: ConvertIntToDecimalStringN(gStringVar1, GetLinkPlayerCount_2(), STR_CONV_MODE_LEFT_ALIGN, 1); diff --git a/src/data/trade.h b/src/data/trade.h index 81681985c2..7d3f7ba3ae 100644 --- a/src/data/trade.h +++ b/src/data/trade.h @@ -8,23 +8,23 @@ static const u32 sUnref_0832C6A8[] = 0x00000528 }; -static const u16 gTradeMovesBoxTilemap[] = INCBIN_U16("graphics/trade/moves_box_map.bin"); -static const u16 gTradePartyBoxTilemap[] = INCBIN_U16("graphics/trade/party_box_map.bin"); -static const u8 gTradeStripesBG2Tilemap[] = INCBIN_U8("graphics/trade/stripes_bg2_map.bin"); -static const u8 gTradeStripesBG3Tilemap[] = INCBIN_U8("graphics/trade/stripes_bg3_map.bin"); -static const u8 gText_EmptyString7[] = _(""); -static const u8 gText_ClrWhtHltTrspntShdwDrkGry[] = _("{COLOR WHITE}{HIGHLIGHT TRANSPARENT}{SHADOW DARK_GREY}"); +static const u16 sTradeMovesBoxTilemap[] = INCBIN_U16("graphics/trade/moves_box_map.bin"); +static const u16 sTradePartyBoxTilemap[] = INCBIN_U16("graphics/trade/party_box_map.bin"); +static const u8 sTradeStripesBG2Tilemap[] = INCBIN_U8("graphics/trade/stripes_bg2_map.bin"); +static const u8 sTradeStripesBG3Tilemap[] = INCBIN_U8("graphics/trade/stripes_bg3_map.bin"); +static const u8 sText_EmptyString7[] = _(""); +static const u8 sText_ClrWhtHltTrspntShdwDrkGry[] = _("{COLOR WHITE}{HIGHLIGHT TRANSPARENT}{SHADOW DARK_GREY}"); const u8 gText_MaleSymbol4[] = _("♂"); const u8 gText_FemaleSymbol4[] = _("♀"); const u8 gText_GenderlessSymbol[] = _(""); -static const u8 gText_SpaceMove[] = _(" MOVE"); -static const u8 gText_NewLine3[] = _("\n"); -static const u8 gText_Slash2[] = _("/"); -static const u8 gText_Lv2[] = _("Lv. "); -static const u8 gText_ThreeDashes2[] = _("---"); -static const u8 gText_FourQuestionMarks[] = _("????"); -static const u8 gText_832DAE4[] = _(""); -static const u8 gText_IsThisTradeOkay[] = _("Is this trade okay?"); +static const u8 sText_SpaceMove[] = _(" MOVE"); // unused +static const u8 sText_NewLine[] = _("\n"); +static const u8 sText_Slash[] = _("/"); +static const u8 sText_Lv[] = _("Lv. "); +static const u8 sText_ThreeDashes[] = _("---"); +static const u8 sText_FourQuestionMarks[] = _("????"); +static const u8 sText_832DAE4[] = _(""); +static const u8 sText_IsThisTradeOkay[] = _("Is this trade okay?"); static const u8 sText_Cancel[] = _("CANCEL"); static const u8 sText_ChooseAPkmn[] = _("Choose a POKéMON."); static const u8 sText_Summary[] = _("SUMMARY"); @@ -274,7 +274,7 @@ static const u8 gTradeMonSpriteCoords[(PARTY_SIZE * 2) + 1][2] = {23, 18} // CANCEL }; -static const u8 sTradeMonCoords[][PARTY_SIZE][2] = +static const u8 sTradeMonLevelCoords[][PARTY_SIZE][2] = { { // Your party @@ -296,7 +296,7 @@ static const u8 sTradeMonCoords[][PARTY_SIZE][2] = } }; -static const u8 sTradeMonBoxDimensions[][PARTY_SIZE][2] = +static const u8 sTradeMonBoxCoords[][PARTY_SIZE][2] = { { // Your party @@ -352,8 +352,8 @@ static const u8 *const sTradeActionTexts[] = static const struct MenuAction sSelectTradeMonActions[] = { - [MENU_ACTION_SUMMARY] = {sText_Summary2, sub_807A000}, - [MENU_ACTION_TRADE] = {sText_Trade2, sub_807A024} + {sText_Summary2, Task_DrawSelectionSummary}, + {sText_Trade2, Task_DrawSelectionTrade} }; static const u8 *const sTradeMessages[] = diff --git a/src/evolution_scene.c b/src/evolution_scene.c index 0b8d896580..af560bc40c 100644 --- a/src/evolution_scene.c +++ b/src/evolution_scene.c @@ -438,7 +438,7 @@ static void CB2_TradeEvolutionSceneLoadGraphics(void) gSprites[ID].callback = SpriteCallbackDummy_2; gSprites[ID].oam.paletteNum = 2; gMain.state++; - sub_807B154(); + LinkTradeDrawWindow(); } break; case 6: @@ -452,7 +452,7 @@ static void CB2_TradeEvolutionSceneLoadGraphics(void) break; case 7: BeginNormalPaletteFade(0xFFFFFFFF, 0, 0x10, 0, RGB_BLACK); - sub_807B140(); + InitTradeSequenceBgGpuRegs(); ShowBg(0); ShowBg(1); SetMainCallback2(CB2_TradeEvolutionSceneUpdate); diff --git a/src/link.c b/src/link.c index 9e35ad5c5b..e88dcb8613 100644 --- a/src/link.c +++ b/src/link.c @@ -28,6 +28,7 @@ #include "link.h" #include "link_rfu.h" #include "constants/rgb.h" +#include "constants/trade.h" extern u16 gHeldKeyCodeToSend; @@ -862,15 +863,15 @@ u8 GetLinkPlayerDataExchangeStatusTimed(int lower, int upper) { if (gLinkPlayers[0].linkType == 0x1133) { - switch (sub_807A728()) + switch (GetGameProgressForLinkTrade()) { - case 1: - sPlayerDataExchangeStatus = EXCHANGE_STAT_4; + case TRADE_PLAYER_NOT_READY: + sPlayerDataExchangeStatus = EXCHANGE_PLAYER_NOT_READY; break; - case 2: - sPlayerDataExchangeStatus = EXCHANGE_STAT_5; + case TRADE_PARTNER_NOT_READY: + sPlayerDataExchangeStatus = EXCHANGE_PARTNER_NOT_READY; break; - case 0: + case TRADE_BOTH_PLAYERS_READY: sPlayerDataExchangeStatus = EXCHANGE_COMPLETE; break; } diff --git a/src/party_menu.c b/src/party_menu.c index 94b9de68d1..86806b4539 100755 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -4685,15 +4685,15 @@ static void CursorCb_Trade2(u8 taskId) { PartyMenuRemoveWindow(&gUnknown_0203CEC4->windowId[0]); PartyMenuRemoveWindow(&gUnknown_0203CEC4->windowId[1]); - switch (sub_807A918(gPlayerParty, gUnknown_0203CEC8.slotId)) + switch (CanTradeSelectedPartyMenuMon(gPlayerParty, gUnknown_0203CEC8.slotId)) { - case 1: + case CANT_TRADE_LAST_MON: StringExpandPlaceholders(gStringVar4, gText_OnlyPkmnForBattle); break; - case 2: + case CANT_TRADE_NATIONAL: StringExpandPlaceholders(gStringVar4, gText_PkmnCantBeTradedNow); break; - case 3: + case CANT_TRADE_EGG: StringExpandPlaceholders(gStringVar4, gText_EggCantBeTradedNow); break; default: diff --git a/src/trade.c b/src/trade.c index ae8dc3d27d..3c76aec832 100644 --- a/src/trade.c +++ b/src/trade.c @@ -96,10 +96,10 @@ static EWRAM_DATA struct { /*0x005D*/ u8 hpBarLevels[2][PARTY_SIZE]; /*0x0069*/ u8 bufferState; /*0x006A*/ u8 filler_6A[0x6F - 0x6A]; - /*0x006F*/ u8 tradeMenuFunc; //switch var for CallTradeMenuFunc + /*0x006F*/ u8 tradeMenuFunc; /*0x0070*/ u8 neverRead_70; /*0x0071*/ u8 filler_71; - /*0x0072*/ u16 unk_72; //sheet + /*0x0072*/ u16 bottomTextTileStart; /*0x0074*/ u8 drawPartyState[2]; /*0x0076*/ u8 selectedMonIdx[2]; /*0x0078*/ u8 playerLinkFlagChoseAction; @@ -136,7 +136,7 @@ static EWRAM_DATA struct { /*0x90*/ u8 unk_90; //sprite id /*0x91*/ u8 unk_91; //sprite id /*0x92*/ u8 unk_92; //sprite id - /*0x93*/ u8 tradeFinished; + /*0x93*/ u8 sendTradeFinishState; /*0x94*/ u16 state; /*0x96*/ u8 filler_96[0xD2 - 0x96]; /*0xD2*/ u8 pokeballSpriteId; @@ -185,10 +185,10 @@ static void BufferTradeMonMoves(u8 *, u8, u8); static void PrintPartyNicknamesForTradeMenu(u8); static void DrawTradeMenuPartyMonInfo(u8, u8, u8, u8, u8, u8); static void DrawTradeMenuPartyInfo(u8); -static void sub_8079F74(void); +static void PrintNicknamesForTradeMenu(void); static void RedrawTradeMenuParty(u8); -static void sub_807A000(u8 taskId); -static void sub_807A024(u8 taskId); +static void Task_DrawSelectionSummary(u8 taskId); +static void Task_DrawSelectionTrade(u8 taskId); static void QueueAction(u16, u8); static u32 GetNumQueuedActions(void); static void DoQueuedActions(void); @@ -245,16 +245,16 @@ static bool8 SendLinkData(const void *linkData, u32 size) } } -static void sub_80771AC(u8 a0) // SKP +static void sub_80771AC(u8 a0) { sub_800A4D8(a0); } -static bool32 sub_80771BC(void) // SKP +static bool32 sub_80771BC(void) { if (gUnknown_02022C2C == 29) { - if (gUnknown_03007880[sub_800E87C(gUnknown_03004140.unk_00)]->unk_0 == 0) // SKP + if (gUnknown_03007880[sub_800E87C(gUnknown_03004140.unk_00)]->unk_0 == 0) return TRUE; else return FALSE; @@ -294,9 +294,9 @@ static bool32 IsWirelessTrade(void) return FALSE; } -static void sub_8077288(u8 unused) // SKP +static void sub_8077288(u8 unused) { - sub_800ADF8(); // SKP + sub_800ADF8(); } static bool32 _IsLinkTaskFinished(void) @@ -314,8 +314,8 @@ static void InitTradeMenu(void) gPaletteFade.bufferTransferDisabled = TRUE; SetVBlankCallback(VBlankCB_TradeMenu); - LoadPalette(gUnknown_0860F074, 0xF0, 20); // SKP, some interface gfx - LoadPalette(gUnknown_0860F074, 0xD0, 20); // SKP, some interface gfx + LoadPalette(gUnknown_0860F074, 0xF0, 20); + LoadPalette(gUnknown_0860F074, 0xD0, 20); ResetBgsAndClearDma3BusyFlags(0); InitBgsFromTemplates(0, sTradeMenuBgTemplates, ARRAY_COUNT(sTradeMenuBgTemplates)); SetBgTilemapBuffer(1, sTradeMenuData->tilemapBuffer); @@ -393,9 +393,9 @@ static void CB2_CreateTradeMenu(void) if (gWirelessCommType) { - sub_800B488(); // SKP + sub_800B488(); OpenLink(); - sub_8011BA4(); // SKP + sub_8011BA4(); } else { @@ -437,14 +437,14 @@ static void CB2_CreateTradeMenu(void) case 4: if (gReceivedRemoteLinkPlayers == TRUE && IsLinkPlayerDataExchangeComplete() == TRUE) { - sub_8011BD0(); // SKP + sub_8011BD0(); CalculatePlayerPartyCount(); gMain.state++; sTradeMenuData->timer = 0; if (gWirelessCommType) { - sub_801048C(TRUE); // SKP - sub_800ADF8(); // SKP + sub_801048C(TRUE); + sub_800ADF8(); } } break; @@ -824,7 +824,7 @@ static void LinkTradeWaitForFade(void) } else { - sub_800ABF4(32); // SKP + sub_800ABF4(32); sTradeMenuData->tradeMenuFunc = TRADEMENUFUNC_START_LINK_TRADE; } } @@ -888,10 +888,10 @@ static void LoadTradeBgGfx(u8 state) LoadPalette(gTradeMenu_Pal, 0, 0x60); LoadBgTiles(1, gTradeMenu_Gfx, 0x1280, 0); CopyToBgTilemapBufferRect_ChangePalette(1, gUnknown_08DDCF04, 0, 0, 32, 20, 0); - LoadBgTilemap(2, gTradeStripesBG2Tilemap, 0x800, 0); + LoadBgTilemap(2, sTradeStripesBG2Tilemap, 0x800, 0); break; case 1: - LoadBgTilemap(3, gTradeStripesBG3Tilemap, 0x800, 0); + LoadBgTilemap(3, sTradeStripesBG3Tilemap, 0x800, 0); DrawTradeMenuPartyInfo(TRADE_PLAYER); DrawTradeMenuPartyInfo(TRADE_PARTNER); CopyBgTilemapBufferToVram(1); @@ -966,7 +966,7 @@ static bool8 BufferTradeParties(void) sTradeMenuData->timer = 0; break; case 1: - if (sub_80771BC()) // SKP + if (sub_80771BC()) { if (_GetBlockReceivedStatus() == 0) { @@ -982,7 +982,7 @@ static bool8 BufferTradeParties(void) case 3: if (id == 0) { - sub_80771AC(1); // SKP + sub_80771AC(1); } sTradeMenuData->bufferState++; break; @@ -1001,7 +1001,7 @@ static bool8 BufferTradeParties(void) case 7: if (id == 0) { - sub_80771AC(1); // SKP + sub_80771AC(1); } sTradeMenuData->bufferState++; break; @@ -1020,7 +1020,7 @@ static bool8 BufferTradeParties(void) case 11: if (id == 0) { - sub_80771AC(1); // SKP + sub_80771AC(1); } sTradeMenuData->bufferState++; break; @@ -1039,7 +1039,7 @@ static bool8 BufferTradeParties(void) case 15: if (id == 0) { - sub_80771AC(3); // SKP + sub_80771AC(3); } sTradeMenuData->bufferState++; break; @@ -1058,7 +1058,7 @@ static bool8 BufferTradeParties(void) case 19: if (id == 0) { - sub_80771AC(4); // SKP + sub_80771AC(4); } sTradeMenuData->bufferState++; break; @@ -1108,7 +1108,7 @@ static bool8 BufferTradeParties(void) static void PrintAndBufferIsThisTradeOkay(void) { - DrawTextWindowAndBuffer6Bytes(gText_IsThisTradeOkay, (void *)(OBJ_VRAM0 + (sTradeMenuData->unk_72 * 32)), 24); + DrawTextWindowAndBuffer6Bytes(sText_IsThisTradeOkay, (void *)(OBJ_VRAM0 + (sTradeMenuData->bottomTextTileStart * 32)), 24); } // mpId is unused @@ -1395,17 +1395,17 @@ static void TradeMenuProcessInput(void) { CreateYesNoMenu(&sTradeYesNoWindowTemplate, 1, 14, 0); sTradeMenuData->tradeMenuFunc = TRADEMENUFUNC_CANCEL_TRADE_PROMPT; - DrawTextWindowAndBuffer6Bytes(sTradeActionTexts[TRADE_TEXT_CANCEL_TRADE], (void *)(OBJ_VRAM0 + sTradeMenuData->unk_72 * 32), 24); + DrawTextWindowAndBuffer6Bytes(sTradeActionTexts[TRADE_TEXT_CANCEL_TRADE], (void *)(OBJ_VRAM0 + sTradeMenuData->bottomTextTileStart * 32), 24); } } } static void TradeMenuChooseMon(void) { - sub_8079F74(); + PrintNicknamesForTradeMenu(); sTradeMenuData->tradeMenuFunc = TRADEMENUFUNC_MAIN_MENU; gSprites[sTradeMenuData->cursorSpriteIdx].invisible = FALSE; - DrawTextWindowAndBuffer6Bytes(sTradeActionTexts[TRADE_TEXT_CHOOSE_MON], (void *)(OBJ_VRAM0 + sTradeMenuData->unk_72 * 32), 24); + DrawTextWindowAndBuffer6Bytes(sTradeActionTexts[TRADE_TEXT_CHOOSE_MON], (void *)(OBJ_VRAM0 + sTradeMenuData->bottomTextTileStart * 32), 24); } static void TradeMenuProcessInput_SelectedMon(void) @@ -1418,11 +1418,11 @@ static void TradeMenuProcessInput_SelectedMon(void) break; case MENU_NOTHING_CHOSEN: break; - case MENU_ACTION_SUMMARY: + case 0: // Summary BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); sTradeMenuData->tradeMenuFunc = TRADEMENUFUNC_SHOW_MON_SUMMARY; break; - case MENU_ACTION_TRADE: + case 1: // Trade switch (CanTradeSelectedMon(gPlayerParty, gPlayerPartyCount, sTradeMenuData->cursorPosition)) { case CAN_TRADE_MON: @@ -1481,9 +1481,7 @@ static u8 CheckValidityOfTradeMons(u8 *aliveMons, u8 playerPartyCount, u8 player for (i = 0; i < playerPartyCount; i++) { if (playerMonIdx != i) - { hasLiveMon += aliveMons[i]; - } } partnerMonIdx %= PARTY_SIZE; species = GetMonData(&gEnemyParty[partnerMonIdx], MON_DATA_SPECIES); @@ -1492,26 +1490,20 @@ static u8 CheckValidityOfTradeMons(u8 *aliveMons, u8 playerPartyCount, u8 player if (species == SPECIES_DEOXYS || species == SPECIES_MEW) { if (!GetMonData(&gEnemyParty[partnerMonIdx], MON_DATA_OBEDIENCE)) - { return PARTNER_MON_INVALID; - } } // Partner cant trade Egg or non-Hoenn mon if player doesn't have National Dex if (!IsNationalPokedexEnabled()) { if (sTradeMenuData->isEgg[TRADE_PARTNER][partnerMonIdx] || !IsSpeciesInHoennDex(species)) - { return PARTNER_MON_INVALID; - } } if (hasLiveMon) - { - hasLiveMon = PLAYER_MON_VALID; - } + hasLiveMon = BOTH_MONS_VALID; - return hasLiveMon; //PLAYER_MON_INVALID or PLAYER_MON_VALID + return hasLiveMon; //PLAYER_MON_INVALID or BOTH_MONS_VALID } // Returns TRUE if the partner's selected mon is invalid, FALSE otherwise @@ -1531,7 +1523,7 @@ static bool32 QueueMonValidityMessage(void) QueueAction(QUEUE_DELAY_MSG, QUEUE_ONLY_MON2); SetLinkData(LINKCMD_SET_CANCEL_TRADE, 0); break; - case PLAYER_MON_VALID: + case BOTH_MONS_VALID: QueueAction(QUEUE_DELAY_MSG, QUEUE_STANDBY); SetLinkData(LINKCMD_INIT_BLOCK, 0); break; @@ -1547,7 +1539,7 @@ static void ConfirmOrCancelTrade(void) { switch (Menu_ProcessInputNoWrapClearOnChoose()) { - case MENU_ACTION_CONFIRM_TRADE: + case 0: // Confirm Trade if (!QueueMonValidityMessage()) { sTradeMenuData->tradeMenuFunc = TRADEMENUFUNC_STANDBY; @@ -1558,10 +1550,10 @@ static void ConfirmOrCancelTrade(void) } PutWindowTilemap(17); break; - case MENU_ACTION_CANCEL_TRADE: + case 1: // Cancel Trade case MENU_B_PRESSED: QueueAction(QUEUE_DELAY_MSG, QUEUE_STANDBY); - if (sub_80771BC()) // SKP + if (sub_80771BC()) SetLinkData(LINKCMD_SET_CANCEL_TRADE, 0); sTradeMenuData->tradeMenuFunc = TRADEMENUFUNC_STANDBY; PutWindowTilemap(17); @@ -1569,7 +1561,6 @@ static void ConfirmOrCancelTrade(void) } } -// TODO: static void sub_807929C(void) { int i; @@ -1662,11 +1653,11 @@ static void CancelTrade_1(void) { if (gWirelessCommType) { - sub_800ADF8(); // SKP + sub_800ADF8(); } else { - sub_800ABF4(12); // SKP + sub_800ABF4(12); } sTradeMenuData->tradeMenuFunc = TRADEMENUFUNC_CANCEL_TRADE_2; @@ -1677,7 +1668,7 @@ static void CancelTrade_2(void) { if (gWirelessCommType) { - if (sub_80771BC() && GetNumQueuedActions() == 0) // SKP + if (sub_80771BC() && GetNumQueuedActions() == 0) { Free(sMessageBoxAllocBuffer); Free(sTradeMenuData); @@ -1700,9 +1691,9 @@ static void CancelTrade_2(void) static void LinkTradeWaitForQueue(void) { - if (!sub_801048C(FALSE) && GetNumQueuedActions() == 0) // SKP + if (!sub_801048C(FALSE) && GetNumQueuedActions() == 0) { - sub_800ADF8(); // SKP + sub_800ADF8(); sTradeMenuData->tradeMenuFunc = TRADEMENUFUNC_START_LINK_TRADE; } } @@ -1782,7 +1773,7 @@ static void SetSelectedMon(u8 cursorPosition) if (sTradeMenuData->drawPartyState[whichParty] == 0) { - sTradeMenuData->drawPartyState[whichParty] = DRAW_PARTY_BEGIN; + sTradeMenuData->drawPartyState[whichParty] = 1; sTradeMenuData->selectedMonIdx[whichParty] = cursorPosition; } } @@ -1805,7 +1796,7 @@ static void DrawTradeMenuParty(u8 whichParty) switch (sTradeMenuData->drawPartyState[whichParty]) { - case DRAW_PARTY_BEGIN: + case 1: for (i = 0; i < sTradeMenuData->partyCounts[whichParty]; i++) { gSprites[sTradeMenuData->partySpriteIds[0][i + (selectedMonParty * PARTY_SIZE)]].invisible = TRUE; @@ -1823,19 +1814,19 @@ static void DrawTradeMenuParty(u8 whichParty) StoreSpriteCallbackInData6(&gSprites[sTradeMenuData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]], UpdateTradeMonIconFrame); sTradeMenuData->drawPartyState[whichParty]++; TradeMenuBouncePartySprites(&gSprites[sTradeMenuData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]]); - CopyToBgTilemapBufferRect_ChangePalette(1, gTradePartyBoxTilemap, whichParty * 15, 0, 15, 17, 0); + CopyToBgTilemapBufferRect_ChangePalette(1, sTradePartyBoxTilemap, whichParty * 15, 0, 15, 17, 0); CopyBgTilemapBufferToVram(1); CopyBgTilemapBufferToVram(0); if (selectedMonParty == TRADE_PLAYER) - sub_8079F74(); + PrintNicknamesForTradeMenu(); break; case 2: if (gSprites[sTradeMenuData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]].callback == UpdateTradeMonIconFrame) sTradeMenuData->drawPartyState[whichParty] = 3; break; case 3: - CopyToBgTilemapBufferRect_ChangePalette(1, gTradeMovesBoxTilemap, selectedMonParty * 15, 0, 15, 17, 0); + CopyToBgTilemapBufferRect_ChangePalette(1, sTradeMovesBoxTilemap, selectedMonParty * 15, 0, 15, 17, 0); CopyBgTilemapBufferToVram(1); gSprites[sTradeMenuData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]].pos1.x = (gTradeMonSpriteCoords[selectedMonParty * PARTY_SIZE][0] + gTradeMonSpriteCoords[selectedMonParty * PARTY_SIZE + 1][0]) / 2 * 8 + 14; gSprites[sTradeMenuData->partySpriteIds[0][partyIdx + (selectedMonParty * PARTY_SIZE)]].pos1.y = (gTradeMonSpriteCoords[selectedMonParty * PARTY_SIZE][1] * 8) - 12; @@ -1894,7 +1885,7 @@ static void BufferTradeMonMoves(u8 *str, u8 whichParty, u8 partyIdx) } } - StringCopy(str, gText_EmptyString7); + StringCopy(str, sText_EmptyString7); for (i = 0; i < MAX_MON_MOVES; i++) { @@ -1903,13 +1894,13 @@ static void BufferTradeMonMoves(u8 *str, u8 whichParty, u8 partyIdx) StringAppend(str, gMoveNames[moves[i]]); } - StringAppend(str, gText_NewLine3); + StringAppend(str, sText_NewLine); } } else { - StringCopy(str, gText_EmptyString7); - StringAppend(str, gText_FourQuestionMarks); + StringCopy(str, sText_EmptyString7); + StringAppend(str, sText_FourQuestionMarks); } } @@ -2008,10 +1999,10 @@ static void DrawTradeMenuPartyInfo(u8 whichParty) for (i = 0; i < sTradeMenuData->partyCounts[whichParty]; i++) { DrawTradeMenuPartyMonInfo(whichParty, i, - sTradeMonCoords[whichParty][i][0], - sTradeMonCoords[whichParty][i][1], - sTradeMonBoxDimensions[whichParty][i][0], - sTradeMonBoxDimensions[whichParty][i][1]); + sTradeMonLevelCoords[whichParty][i][0], + sTradeMonLevelCoords[whichParty][i][1], + sTradeMonBoxCoords[whichParty][i][0], + sTradeMonBoxCoords[whichParty][i][1]); } } #else @@ -2032,10 +2023,10 @@ static void DrawTradeMenuPartyInfo(u8 whichParty) bge _08079E94\n\ lsls r0, r6, 1\n\ adds r0, r6\n\ - ldr r1, =sTradeMonCoords\n\ + ldr r1, =sTradeMonLevelCoords\n\ lsls r0, 2\n\ adds r5, r0, r1\n\ - ldr r1, =sTradeMonBoxDimensions\n\ + ldr r1, =sTradeMonBoxCoords\n\ adds r4, r0, r1\n\ _08079E6A:\n\ lsls r1, r7, 24\n\ @@ -2081,33 +2072,31 @@ static void ResetTradeMenuPartyPositions(u8 whichParty) } } -// TODO: -static void sub_8079F74(void) +static void PrintNicknamesForTradeMenu(void) { rbox_fill_rectangle(1); + //PrintPartyNicknamesForTradeMenu(TRADE_PLAYER); ? PrintPartyNicknamesForTradeMenu(TRADE_PARTNER); } static void RedrawTradeMenuParty(u8 whichParty) { - CopyToBgTilemapBufferRect_ChangePalette(1, gTradePartyBoxTilemap, whichParty * 15, 0, 15, 17, 0); + CopyToBgTilemapBufferRect_ChangePalette(1, sTradePartyBoxTilemap, whichParty * 15, 0, 15, 17, 0); CopyBgTilemapBufferToVram(1); DrawTradeMenuPartyInfo(whichParty); PrintPartyNicknamesForTradeMenu(whichParty); ResetTradeMenuPartyPositions(whichParty); - DrawTextWindowAndBuffer6Bytes(sTradeActionTexts[TRADE_TEXT_CHOOSE_MON], (void *)(OBJ_VRAM0 + (sTradeMenuData->unk_72 * 32)), 24); + DrawTextWindowAndBuffer6Bytes(sTradeActionTexts[TRADE_TEXT_CHOOSE_MON], (void *)(OBJ_VRAM0 + (sTradeMenuData->bottomTextTileStart * 32)), 24); sTradeMenuData->drawPartyState[whichParty] = 0; } -// Unused -static void sub_807A000(u8 taskId) +static void Task_DrawSelectionSummary(u8 taskId) { FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 30, 20); CopyBgTilemapBufferToVram(0); } -// Unused -static void sub_807A024(u8 taskId) +static void Task_DrawSelectionTrade(u8 taskId) { FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 30, 20); CopyBgTilemapBufferToVram(0); @@ -2215,7 +2204,7 @@ static bool8 LoadTradeMenuSpriteSheetsAndPalettes(void) sTradeMenuData->timer++; break; case 8: - sTradeMenuData->unk_72 = LoadSpriteSheet(&sheet); + sTradeMenuData->bottomTextTileStart = LoadSpriteSheet(&sheet); sTradeMenuData->timer++; break; case 9 ... 13: @@ -2350,7 +2339,7 @@ static void SaveTradeGiftRibbons(void) static u32 CanTradeSelectedMon(struct Pokemon *playerParty, int partyCount, int monIdx) { - int i, numAliveMons; + int i, numMonsLeft; struct LinkPlayer *player; u32 species[PARTY_SIZE]; u32 species2[PARTY_SIZE]; @@ -2375,8 +2364,8 @@ static u32 CanTradeSelectedMon(struct Pokemon *playerParty, int partyCount, int if ((player->version & 0xFF) != VERSION_RUBY && (player->version & 0xFF) != VERSION_SAPPHIRE) { - // Has partner not cleared game - if ((player->progressFlagsCopy & 0xF) == 0) + // Does partner not have National Dex + if (!(player->progressFlagsCopy & 0xF)) { if (species2[monIdx] == SPECIES_EGG) return CANT_TRADE_EGG2; @@ -2392,6 +2381,7 @@ static u32 CanTradeSelectedMon(struct Pokemon *playerParty, int partyCount, int return CANT_TRADE_INVALID_MON; } + // Make Eggs not count for numMonsLeft for (i = 0; i < partyCount; i++) { if (species2[i] == SPECIES_EGG) @@ -2399,64 +2389,56 @@ static u32 CanTradeSelectedMon(struct Pokemon *playerParty, int partyCount, int } // Count alive mons in party, excluding selected trade mon - for (numAliveMons = 0, i = 0; i < partyCount; i++) + for (numMonsLeft = 0, i = 0; i < partyCount; i++) { if (i != monIdx) - numAliveMons += species2[i]; + numMonsLeft += species2[i]; } - if (numAliveMons != 0) + if (numMonsLeft != 0) return CAN_TRADE_MON; else return CANT_TRADE_LAST_MON; } -// Return values are used to determine exchange status in GetLinkPlayerDataExchangeStatusTimed -// 0: EXCHANGE_COMPLETE -// 1: EXCHANGE_STAT_4 -// 2: EXCHANGE_STAT_5 -//TODO: -s32 sub_807A728(void) +s32 GetGameProgressForLinkTrade(void) { - s32 val; + // isGameFrLg could have been a bool but they use 2 and > 0 instead + // possible other checks (for other game versions?) were planned/removed + s32 isGameFrLg; u16 version; if (gReceivedRemoteLinkPlayers != 0) { - val = 0; + isGameFrLg = 0; version = (gLinkPlayers[GetMultiplayerId() ^ 1].version & 0xFF); if (version == VERSION_RUBY || version == VERSION_SAPPHIRE || version == VERSION_EMERALD) - { - // this value could actually be anything 0 or less - val = 0; - } + isGameFrLg = 0; else if (version == VERSION_FIRE_RED || version == VERSION_LEAF_GREEN) - { - val = 2; - } + isGameFrLg = 2; - if (val > 0) + if (isGameFrLg > 0) { - // Does player have National Dex + // Is player champion if (gLinkPlayers[GetMultiplayerId()].progressFlagsCopy & 0xF0) { - if (val == 2) //unnecessary check, val always 2 here + if (isGameFrLg == 2) //unnecessary check, isGameFrLg always 2 here { - // Does partner have National Dex + // Is partner champion if (gLinkPlayers[GetMultiplayerId() ^ 1].progressFlagsCopy & 0xF0) - return 0; + return TRADE_BOTH_PLAYERS_READY; else - return 2; + return TRADE_PARTNER_NOT_READY; } } else { - return 1; + return TRADE_PLAYER_NOT_READY; } } } - return 0; + return TRADE_BOTH_PLAYERS_READY; } static bool32 IsDeoxysOrMewUntradable(u16 species, bool8 isObedientBitSet) @@ -2562,22 +2544,23 @@ int CanRegisterMonForTradingBoard(struct UnkLinkRfuStruct_02022B14Substruct a0, // r6/r7 flip. Ugh. #ifdef NONMATCHING -int sub_807A918(struct Pokemon *mon, u16 monIdx) +int CanTradeSelectedPartyMenuMon(struct Pokemon *mon, u16 monIdx) { - int i, version, versions, unk, unk2; + int i, version, versions, unk, numMonsLeft; int speciesArray[PARTY_SIZE]; + // Make Eggs not count for numMonsLeft for (i = 0; i < gPlayerPartyCount; i++) { speciesArray[i] = GetMonData(&mon[i], MON_DATA_SPECIES2); if (speciesArray[i] == SPECIES_EGG) { - speciesArray[i] = 0; + speciesArray[i] = SPECIES_NONE; } } - versions = 0; unk = 1; + versions = 0; for (i = 0; i < GetLinkPlayerCount(); i++) { version = gLinkPlayers[i].version & 0xFF; @@ -2596,8 +2579,8 @@ int sub_807A918(struct Pokemon *mon, u16 monIdx) { struct LinkPlayer *player = &gLinkPlayers[i]; - // Has player not cleared game - if ((player->progressFlags & 0xF) == 0) + // Does player not have National Dex + if (!(player->progressFlags & 0xF)) unk = 0; if (versions && (player->progressFlags / 16)) @@ -2607,37 +2590,29 @@ int sub_807A918(struct Pokemon *mon, u16 monIdx) if (unk == 0) { if (!IsSpeciesInHoennDex(speciesArray[monIdx])) - { - return 2; - } + return CANT_TRADE_NATIONAL; if (speciesArray[monIdx] == SPECIES_NONE) - { - return 3; - } + return CANT_TRADE_EGG; } - unk2 = 0; + numMonsLeft = 0; for (i = 0; i < gPlayerPartyCount; i++) { if (monIdx != i) { - unk2 += speciesArray[i]; + numMonsLeft += speciesArray[i]; } } - if (!unk2) - { - return 1; - } + if (!numMonsLeft) + return CANT_TRADE_LAST_MON; else - { - return 0; - } + return CAN_TRADE_MON; } #else NAKED -int sub_807A918(struct Pokemon *mon, u16 a1) +int CanTradeSelectedPartyMenuMon(struct Pokemon *mon, u16 a1) { asm_unified("push {r4-r7,lr}\n\ mov r7, r8\n\ @@ -3038,7 +3013,7 @@ void CB2_LinkTrade(void) case 5: sTradeData->playerLinkFlagFinishTrade = 0; sTradeData->partnerLinkFlagFinishTrade = 0; - sTradeData->tradeFinished = 0; + sTradeData->sendTradeFinishState = 0; LoadTradeMonPic(TRADE_PLAYER, 0); gMain.state++; break; @@ -3052,7 +3027,7 @@ void CB2_LinkTrade(void) break; case 8: LoadTradeMonPic(TRADE_PARTNER, 1); - sub_807B154(); + LinkTradeDrawWindow(); gMain.state++; break; case 9: @@ -3067,7 +3042,7 @@ void CB2_LinkTrade(void) gMain.state++; break; case 11: - sub_807B140(); + InitTradeSequenceBgGpuRegs(); BufferTradeSceneStrings(); gMain.state++; break; @@ -3090,14 +3065,13 @@ void CB2_LinkTrade(void) UpdatePaletteFade(); } -void sub_807B140(void) +void InitTradeSequenceBgGpuRegs(void) { SetTradeSequenceBgGpuRegs(5); SetTradeSequenceBgGpuRegs(0); } -// TODO: -void sub_807B154(void) +void LinkTradeDrawWindow(void) { FillWindowPixelBuffer(0, PIXEL_FILL(15)); PutWindowTilemap(0); @@ -3261,19 +3235,19 @@ static void TradeMons(u8 playerPartyIdx, u8 partnerPartyIdx) TryEnableNationalDexFromLinkPartner(); } -static void sub_807B5B8(void) +static void TrySendTradeFinishData(void) { - switch (sTradeData->tradeFinished) + switch (sTradeData->sendTradeFinishState) { case 1: if (IsLinkTaskFinished()) { Trade_SendData(sTradeData); - sTradeData->tradeFinished++; + sTradeData->sendTradeFinishState++; } // fallthrough case 2: - sTradeData->tradeFinished = 0; + sTradeData->sendTradeFinishState = 0; break; } } @@ -4733,11 +4707,11 @@ static void CB2_UpdateLinkTrade(void) if (!IsWirelessTrade()) { sTradeData->linkData[0] = LINKCMD_READY_FINISH_TRADE; - sTradeData->tradeFinished = 1; + sTradeData->sendTradeFinishState = 1; } SetMainCallback2(CB2_TryFinishTrade); } - sub_807B5B8(); + TrySendTradeFinishData(); UpdateTradeFinishFlags(); RunTasks(); RunTextPrinters(); @@ -4782,7 +4756,7 @@ static void CB2_SaveAndEndTrade(void) DrawTextOnTradeWindow(0, gStringVar4, 0); break; case 1: - sub_8077288(0); // SKP + sub_8077288(0); gMain.state = 100; sTradeData->timer = 0; break; @@ -4813,10 +4787,10 @@ static void CB2_SaveAndEndTrade(void) IncrementGameStat(GAME_STAT_POKEMON_TRADES); if (gWirelessCommType) { - sub_801B990(2, gLinkPlayers[GetMultiplayerId() ^ 1].trainerId); // SKP + sub_801B990(2, gLinkPlayers[GetMultiplayerId() ^ 1].trainerId); } SetContinueGameWarpStatusToDynamicWarp(); - sub_8153380(); //TODO: save func + sub_8153380(); gMain.state++; sTradeData->timer = 0; break; @@ -4827,7 +4801,7 @@ static void CB2_SaveAndEndTrade(void) } break; case 52: - if (sub_81533AC()) //TODO: save func + if (sub_81533AC()) { ClearContinueGameWarpStatus2(); gMain.state = 4; @@ -4839,7 +4813,7 @@ static void CB2_SaveAndEndTrade(void) } break; case 4: - sub_81533E0(); //TODO: save func + sub_81533E0(); gMain.state = 40; sTradeData->timer = 0; break; @@ -4860,7 +4834,7 @@ static void CB2_SaveAndEndTrade(void) case 41: if (sTradeData->timer == 0) { - sub_8077288(1); // SKP + sub_8077288(1); gMain.state = 42; } else @@ -4871,7 +4845,7 @@ static void CB2_SaveAndEndTrade(void) case 42: if (_IsLinkTaskFinished()) { - sub_8153408(); //TODO: save func + sub_8153408(); gMain.state = 5; } break; @@ -4879,7 +4853,7 @@ static void CB2_SaveAndEndTrade(void) if (++sTradeData->timer > 60) { gMain.state++; - sub_8077288(2); // SKP + sub_8077288(2); } break; case 6: @@ -4901,11 +4875,11 @@ static void CB2_SaveAndEndTrade(void) { if (gWirelessCommType && gMain.savedCallback == CB2_StartCreateTradeMenu) { - sub_8077288(3); // SKP + sub_8077288(3); } else { - sub_800AC34(); // SKP + sub_800AC34(); } gMain.state++; } @@ -5118,7 +5092,7 @@ static void CB2_SaveAndEndWirelessTrade(void) DrawTextOnTradeWindow(0, gStringVar4, 0); break; case 1: - sub_8077288(0); // SKP + sub_8077288(0); gMain.state = 2; sTradeData->timer = 0; break; @@ -5129,7 +5103,7 @@ static void CB2_SaveAndEndWirelessTrade(void) StringExpandPlaceholders(gStringVar4, gText_SavingDontTurnOffPower); DrawTextOnTradeWindow(0, gStringVar4, 0); IncrementGameStat(GAME_STAT_POKEMON_TRADES); - sub_8153380(); // TODO: save func + sub_8153380(); sTradeData->timer = 0; } break; @@ -5138,7 +5112,7 @@ static void CB2_SaveAndEndWirelessTrade(void) gMain.state = 4; break; case 4: - if (sub_81533AC()) // TODO: save func + if (sub_81533AC()) { gMain.state = 5; } @@ -5149,7 +5123,7 @@ static void CB2_SaveAndEndWirelessTrade(void) } break; case 5: - sub_81533E0(); //TODO: save func + sub_81533E0(); gMain.state = 6; sTradeData->timer = 0; break; @@ -5166,7 +5140,7 @@ static void CB2_SaveAndEndWirelessTrade(void) case 7: if (sTradeData->timer == 0) { - sub_8077288(1); // SKP + sub_8077288(1); gMain.state = 8; } else @@ -5177,7 +5151,7 @@ static void CB2_SaveAndEndWirelessTrade(void) case 8: if (_IsLinkTaskFinished()) { - sub_8153408(); //TODO: save func + sub_8153408(); gMain.state = 9; } break; @@ -5185,7 +5159,7 @@ static void CB2_SaveAndEndWirelessTrade(void) if (++sTradeData->timer > 60) { gMain.state++; - sub_8077288(2); // SKP + sub_8077288(2); } break; case 10: @@ -5199,7 +5173,7 @@ static void CB2_SaveAndEndWirelessTrade(void) case 11: if (!gPaletteFade.active && IsBGMStopped() == TRUE) { - sub_8077288(3); // SKP + sub_8077288(3); gMain.state = 12; } break;