1 Add Ability to Swap Bikes Whenever
voloved edited this page 2023-08-31 08:59:36 -04:00

By devolov Goal: Make it so the Mach and Acro bike can be swapped whenever.

bike

------------------------------- src/item_menu.c -------------------------------
index c2518cc20..a5f534b9d 100755
@@ -97,8 +97,9 @@ enum {
     ACTION_BY_AMOUNT,
     ACTION_BY_NUMBER,
     ACTION_REGISTER,
+    ACTION_SWAP,
     ACTION_DUMMY,
 };
 
 enum {
@@ -206,8 +207,9 @@ static void BagMenu_ItemPrintCallback(u8, u32, u8);
 static void ItemMenu_UseOutOfBattle(u8);
 static void ItemMenu_Toss(u8);
 static void ItemMenu_Register(u8);
+static void ItemMenu_Swap(u8);
 static void ItemMenu_Give(u8);
 static void ItemMenu_Cancel(u8);
 static void ItemMenu_UseInBattle(u8);
@@ -300,8 +302,9 @@ static const u8 sMenuText_ByAmount[] = _("Amount");
 static const u8 sMenuText_ByNumber[] = _("Number");
 static const u8 sText_NothingToSort[] = _("There's nothing to sort!");
 static const u8 sMenuText_Tap[] = _("Tap");
 static const u8 sMenuText_Hold[] = _("Hold");
+static const u8 sMenuText_Swap[] = _("SWAP");
 static const u8 sText_RegisterHow[] = _("Register this\nitem by tapping or\nholding SELECT?");
 static const struct MenuAction sItemMenuActions[] = {
     [ACTION_USE]               = {gMenuText_Use,      ItemMenu_UseOutOfBattle},
     [ACTION_TOSS]              = {gMenuText_Toss,     ItemMenu_Toss},
@@ -322,8 +325,9 @@ static const struct MenuAction sItemMenuActions[] = {
     [ACTION_BY_NUMBER]         = {sMenuText_ByNumber, ItemMenu_SortByID},
     [ACTION_BY_AMOUNT]         = {sMenuText_ByAmount, ItemMenu_SortByAmount},
     [ACTION_REGISTER]          = {sMenuText_Tap,      ItemMenu_Register},
+    [ACTION_SWAP]              = {sMenuText_Swap,     ItemMenu_Swap},
     [ACTION_DUMMY]             = {gText_EmptyString2, NULL}
 };
 
 // these are all 2D arrays with a width of 2 but are represented as 1D arrays
@@ -1722,8 +1726,9 @@ static void OpenContextMenu(u8 taskId)
                 if (gSaveBlock1Ptr->registeredItem == gSpecialVar_ItemId || gSaveBlock1Ptr->registeredLongItem == gSpecialVar_ItemId)
                     gBagMenu->contextMenuItemsBuffer[1] = ACTION_DESELECT;
                 if (gSpecialVar_ItemId == ITEM_MACH_BIKE || gSpecialVar_ItemId == ITEM_ACRO_BIKE)
                 {
+                    gBagMenu->contextMenuItemsBuffer[2] = ACTION_SWAP;
                     if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_MACH_BIKE | PLAYER_AVATAR_FLAG_ACRO_BIKE))
                         gBagMenu->contextMenuItemsBuffer[0] = ACTION_WALK;
                 }
                 break;
@@ -2045,8 +2050,35 @@ static void ItemMenu_Register(u8 taskId)
    tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos);
    ScheduleBgCopyTilemapToVram(0);
    ItemMenu_Cancel(taskId);
}
 
+static void ItemMenu_Swap(u8 taskId)
+{
+    s16 *data = gTasks[taskId].data;
+    u16 *scrollPos = &gBagPosition.scrollPosition[gBagPosition.pocket];
+    u16 *cursorPos = &gBagPosition.cursorPosition[gBagPosition.pocket];
+    u8 itemListPos = GetItemListPosition(gBagPosition.pocket);
+
+    if (gSpecialVar_ItemId == ITEM_MACH_BIKE)
+        gBagPockets[gBagPosition.pocket].itemSlots[itemListPos].itemId = ITEM_ACRO_BIKE;
+    else if (gSpecialVar_ItemId == ITEM_ACRO_BIKE)
+        gBagPockets[gBagPosition.pocket].itemSlots[itemListPos].itemId = ITEM_MACH_BIKE;
+    SwapRegisteredBike();
+    if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_MACH_BIKE))
+        SetPlayerAvatarTransitionFlags(PLAYER_AVATAR_FLAG_ACRO_BIKE);
+    else if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_ACRO_BIKE))
+        SetPlayerAvatarTransitionFlags(PLAYER_AVATAR_FLAG_MACH_BIKE);
+
+    BagDestroyPocketScrollArrowPair();
+    RemoveContextWindow();
+    DestroyListMenuTask(tListTaskId, scrollPos, cursorPos);
+    LoadBagItemListBuffers(gBagPosition.pocket);
+    tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos);
+    ScheduleBgCopyTilemapToVram(0);
+    ItemMenu_Cancel(taskId);
+
+}
+
static void Task_LoadRegisterOptions(u8 taskId)
{
    s16 *data = gTasks[taskId].data;
    if (gSaveBlock1Ptr->registeredItem == gSpecialVar_ItemId){