mirror of
https://github.com/pret/pokefirered.git
synced 2026-05-11 22:45:18 -05:00
Expansion bag refactoring (#97)
This commit is contained in:
parent
0664e070b8
commit
cef34a103c
|
|
@ -210,6 +210,7 @@ bool8 CheckBagHasItem(u16 itemId, u16 count);
|
|||
bool8 CheckBagHasSpace(u16 itemId, u16 count);
|
||||
u32 GetFreeSpaceForItemInBag(u16 itemId);
|
||||
bool8 RemoveBagItem(u16 itemId, u16 count);
|
||||
void RemoveBagItemFromSlot(struct BagPocket *pocket, u16 slotId, u16 count);
|
||||
u8 GetPocketByItemId(u16 itemId);
|
||||
u8 CountUsedPCItemSlots(void);
|
||||
bool8 CheckPCHasItem(u16 itemId, u16 count);
|
||||
|
|
@ -241,7 +242,7 @@ u16 GetPCItemQuantity(u16 *);
|
|||
void SetBagItemsPointers(void);
|
||||
|
||||
void ItemPcCompaction(void);
|
||||
void RemovePCItem(u16 itemId, u16 quantity);
|
||||
void RemovePCItem(u8 index, u16 count);
|
||||
void CompactItemsInBagPocket(enum Pocket pocketId);
|
||||
u8 CountItemsInPC(void);
|
||||
bool32 HasAtLeastOneBerry(void);
|
||||
|
|
|
|||
416
src/item.c
416
src/item.c
|
|
@ -28,6 +28,7 @@ EWRAM_DATA struct BagPocket gBagPockets[POCKETS_COUNT] = {};
|
|||
|
||||
static const u8 *ItemId_GetPluralName(u16);
|
||||
static bool32 DoesItemHavePluralName(u16);
|
||||
static void NONNULL BagPocket_CompactItems(struct BagPocket *pocket);
|
||||
|
||||
// Item descriptions and data
|
||||
#include "constants/moves.h"
|
||||
|
|
@ -310,35 +311,99 @@ bool8 CheckBagHasSpace(u16 itemId, u16 count)
|
|||
return GetFreeSpaceForItemInBag(itemId) >= count;
|
||||
}
|
||||
|
||||
static u32 NONNULL BagPocket_GetFreeSpaceForItem(struct BagPocket *pocket, u16 itemId)
|
||||
{
|
||||
u32 spaceForItem = 0;
|
||||
struct ItemSlot tempItem;
|
||||
|
||||
// Check space in any existing item slots that already contain this item
|
||||
for (u32 i = 0; i < pocket->capacity; i++)
|
||||
{
|
||||
tempItem = BagPocket_GetSlotData(pocket, i);
|
||||
if (tempItem.itemId == ITEM_NONE || tempItem.itemId == itemId)
|
||||
spaceForItem += (tempItem.itemId ? (MAX_BAG_ITEM_CAPACITY - tempItem.quantity) : MAX_BAG_ITEM_CAPACITY);
|
||||
}
|
||||
|
||||
return spaceForItem;
|
||||
}
|
||||
|
||||
u32 GetFreeSpaceForItemInBag(u16 itemId)
|
||||
{
|
||||
u8 i;
|
||||
u8 pocket = GetItemPocket(itemId);
|
||||
u16 ownedCount;
|
||||
u32 spaceForItem = 0;
|
||||
|
||||
if (pocket >= POCKETS_COUNT)
|
||||
return 0;
|
||||
|
||||
// Check space in any existing item slots that already contain this item
|
||||
for (i = 0; i < gBagPockets[pocket].capacity; i++)
|
||||
return BagPocket_GetFreeSpaceForItem(&gBagPockets[GetItemPocket(itemId)], itemId);
|
||||
}
|
||||
|
||||
static inline bool32 NONNULL CheckSlotAndUpdateCount(struct BagPocket *pocket, u16 itemId, u32 pocketPos, u32 *nextPocketPos, u16 *count, u16 *tempPocketSlotQuantities)
|
||||
{
|
||||
struct ItemSlot tempItem = BagPocket_GetSlotData(pocket, pocketPos);
|
||||
if (tempItem.itemId == ITEM_NONE || tempItem.itemId == itemId)
|
||||
{
|
||||
if (gBagPockets[pocket].itemSlots[i].itemId == itemId)
|
||||
// The quantity already at the slot - zero if an empty slot
|
||||
if (tempItem.itemId == ITEM_NONE)
|
||||
tempItem.quantity = 0;
|
||||
|
||||
// Record slot quantity in tempPocketSlotQuantities, adjust count
|
||||
tempPocketSlotQuantities[pocketPos] = min(MAX_BAG_ITEM_CAPACITY, *count + tempItem.quantity);
|
||||
*count -= min(*count, MAX_BAG_ITEM_CAPACITY - tempItem.quantity);
|
||||
|
||||
// Set the starting index for the next loop to set items (shifted by one)
|
||||
if (!*nextPocketPos)
|
||||
*nextPocketPos = pocketPos + 1;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static bool32 NONNULL BagPocket_AddItem(struct BagPocket *pocket, u16 itemId, u16 count)
|
||||
{
|
||||
u32 itemLookupIndex, itemAddIndex = 0;
|
||||
|
||||
// First, check that there is a free slot for this item
|
||||
u16 *tempPocketSlotQuantities = AllocZeroed(sizeof(u16) * pocket->capacity);
|
||||
|
||||
switch (pocket->id)
|
||||
{
|
||||
case POCKET_TM_HM:
|
||||
case POCKET_BERRIES:
|
||||
for (itemLookupIndex = 0; itemLookupIndex < pocket->capacity && count > 0; itemLookupIndex++)
|
||||
{
|
||||
// Check if we found a slot to store the item but weren't able to reduce count to 0
|
||||
// This means that we have more than one stack's worth, which isn't allowed in these pockets
|
||||
if (CheckSlotAndUpdateCount(pocket, itemId, itemLookupIndex, &itemAddIndex, &count, tempPocketSlotQuantities) && count > 0)
|
||||
{
|
||||
Free(tempPocketSlotQuantities);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
for (itemLookupIndex = 0; itemLookupIndex < pocket->capacity && count > 0; itemLookupIndex++)
|
||||
CheckSlotAndUpdateCount(pocket, itemId, itemLookupIndex, &itemAddIndex, &count, tempPocketSlotQuantities);
|
||||
}
|
||||
|
||||
// If the count is still greater than zero, clearly we have not found enough slots for this...
|
||||
// Otherwise, we have found slots - update the actual pockets with the updated quantities
|
||||
if (count == 0)
|
||||
{
|
||||
for (--itemAddIndex; itemAddIndex < itemLookupIndex; itemAddIndex++)
|
||||
{
|
||||
ownedCount = GetBagItemQuantity(pocket, i);
|
||||
spaceForItem += max(0, MAX_BAG_ITEM_CAPACITY - ownedCount);
|
||||
}
|
||||
else if (gBagPockets[pocket].itemSlots[i].itemId == ITEM_NONE)
|
||||
{
|
||||
spaceForItem += MAX_BAG_ITEM_CAPACITY;
|
||||
if (tempPocketSlotQuantities[itemAddIndex] > 0)
|
||||
BagPocket_SetSlotItemIdAndCount(pocket, itemAddIndex, itemId, tempPocketSlotQuantities[itemAddIndex]);
|
||||
}
|
||||
}
|
||||
return spaceForItem;
|
||||
|
||||
Free(tempPocketSlotQuantities);
|
||||
return count == 0;
|
||||
}
|
||||
|
||||
bool8 AddBagItem(u16 itemId, u16 count)
|
||||
{
|
||||
u8 i;
|
||||
enum Pocket pocket = GetItemPocket(itemId);
|
||||
s8 idx;
|
||||
|
||||
|
|
@ -348,28 +413,6 @@ bool8 AddBagItem(u16 itemId, u16 count)
|
|||
if (pocket >= POCKETS_COUNT)
|
||||
return FALSE;
|
||||
|
||||
for (i = 0; i < gBagPockets[pocket].capacity; i++)
|
||||
{
|
||||
if (gBagPockets[pocket].itemSlots[i].itemId == itemId)
|
||||
{
|
||||
u16 quantity;
|
||||
// Does this stack have room for more??
|
||||
quantity = GetBagItemQuantity(pocket, i);
|
||||
if (quantity + count <= MAX_BAG_ITEM_CAPACITY)
|
||||
{
|
||||
quantity += count;
|
||||
SetBagItemQuantity(pocket, i, quantity);
|
||||
return TRUE;
|
||||
}
|
||||
// RS and Emerald check whether there is enough of the
|
||||
// item across all stacks.
|
||||
// For whatever reason, FR/LG assume there's only one
|
||||
// stack of the item.
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (pocket == POCKET_TM_HM && !CheckBagHasItem(ITEM_TM_CASE, 1))
|
||||
{
|
||||
idx = BagPocketGetFirstEmptySlot(POCKET_KEY_ITEMS);
|
||||
|
|
@ -392,18 +435,49 @@ bool8 AddBagItem(u16 itemId, u16 count)
|
|||
if (itemId == ITEM_BERRY_POUCH)
|
||||
FlagSet(FLAG_SYS_GOT_BERRY_POUCH);
|
||||
|
||||
idx = BagPocketGetFirstEmptySlot(pocket);
|
||||
if (idx == -1)
|
||||
return FALSE;
|
||||
return BagPocket_AddItem(&gBagPockets[GetItemPocket(itemId)], itemId, count);
|
||||
}
|
||||
|
||||
gBagPockets[pocket].itemSlots[idx].itemId = itemId;
|
||||
SetBagItemQuantity(pocket, idx, count);
|
||||
return TRUE;
|
||||
static bool32 NONNULL BagPocket_RemoveItem(struct BagPocket *pocket, u16 itemId, u16 count)
|
||||
{
|
||||
u32 itemLookupIndex, itemRemoveIndex = 0, totalQuantity = 0;
|
||||
struct ItemSlot tempItem;
|
||||
u16 *tempPocketSlotQuantities = AllocZeroed(sizeof(u16) * pocket->capacity);
|
||||
|
||||
for (itemLookupIndex = 0; itemLookupIndex < pocket->capacity && totalQuantity < count; itemLookupIndex++)
|
||||
{
|
||||
tempItem = BagPocket_GetSlotData(pocket, itemLookupIndex);
|
||||
if (tempItem.itemId == itemId)
|
||||
{
|
||||
// Index for the next loop - where we should start removing items
|
||||
if (!itemRemoveIndex)
|
||||
itemRemoveIndex = itemLookupIndex + 1;
|
||||
|
||||
// Gather quantities (+ 1 to tempPocketSlotQuantities so that even if setting to 0 we know which indices to target)
|
||||
totalQuantity += tempItem.quantity;
|
||||
tempPocketSlotQuantities[itemLookupIndex] = (tempItem.quantity <= count ? 0 : tempItem.quantity - count) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (totalQuantity >= count) // We have enough of the item
|
||||
{
|
||||
// Update the quantities correctly with the items removed
|
||||
for (--itemRemoveIndex; itemRemoveIndex < itemLookupIndex; itemRemoveIndex++)
|
||||
{
|
||||
if (tempPocketSlotQuantities[itemRemoveIndex] > 0)
|
||||
BagPocket_SetSlotItemIdAndCount(pocket, itemRemoveIndex, itemId, tempPocketSlotQuantities[itemRemoveIndex] - 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (totalQuantity == count)
|
||||
BagPocket_CompactItems(pocket);
|
||||
|
||||
Free(tempPocketSlotQuantities);
|
||||
return totalQuantity >= count;
|
||||
}
|
||||
|
||||
bool8 RemoveBagItem(u16 itemId, u16 count)
|
||||
{
|
||||
u8 i;
|
||||
enum Pocket pocket = GetItemPocket(itemId);
|
||||
|
||||
if (pocket >= POCKETS_COUNT)
|
||||
|
|
@ -412,31 +486,14 @@ bool8 RemoveBagItem(u16 itemId, u16 count)
|
|||
if (itemId == ITEM_NONE)
|
||||
return FALSE;
|
||||
|
||||
// Check for item slots that contain the item
|
||||
for (i = 0; i < gBagPockets[pocket].capacity; i++)
|
||||
{
|
||||
if (gBagPockets[pocket].itemSlots[i].itemId == itemId)
|
||||
{
|
||||
u16 quantity;
|
||||
// Does this item slot contain enough of the item?
|
||||
quantity = GetBagItemQuantity(pocket, i);
|
||||
if (quantity >= count)
|
||||
{
|
||||
quantity -= count;
|
||||
SetBagItemQuantity(pocket, i, quantity);
|
||||
if (quantity == 0)
|
||||
gBagPockets[pocket].itemSlots[i].itemId = ITEM_NONE;
|
||||
return TRUE;
|
||||
}
|
||||
// RS and Emerald check whether there is enough of the
|
||||
// item across all stacks.
|
||||
// For whatever reason, FR/LG assume there's only one
|
||||
// stack of the item.
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
return BagPocket_RemoveItem(&gBagPockets[pocket], itemId, count);
|
||||
}
|
||||
|
||||
// Unsafe function: Only use with functions that already check the slot and count are valid
|
||||
void RemoveBagItemFromSlot(struct BagPocket *pocket, u16 slotId, u16 count)
|
||||
{
|
||||
struct ItemSlot itemSlot = BagPocket_GetSlotData(pocket, slotId);
|
||||
BagPocket_SetSlotItemIdAndCount(pocket, slotId, itemSlot.itemId, itemSlot.quantity - count);
|
||||
}
|
||||
|
||||
u8 GetPocketByItemId(u16 itemId)
|
||||
|
|
@ -455,61 +512,40 @@ void ClearPCItemSlots(void)
|
|||
}
|
||||
}
|
||||
|
||||
void MoveItemSlotInPocket(enum Pocket pocketId, u32 from, u32 to)
|
||||
void CompactItemsInBagPocket(enum Pocket pocketId)
|
||||
{
|
||||
BagPocket_CompactItems(&gBagPockets[pocketId]);
|
||||
}
|
||||
|
||||
static inline void NONNULL BagPocket_MoveItemSlot(struct BagPocket *pocket, u32 from, u32 to)
|
||||
{
|
||||
if (from != to)
|
||||
{
|
||||
u32 i;
|
||||
s8 shift = -1;
|
||||
struct BagPocket *pocket = &gBagPockets[pocketId];
|
||||
s8 shift = (to > from) ? 1 : -1;
|
||||
if (to > from)
|
||||
to--;
|
||||
|
||||
// Record the values at "from"
|
||||
u16 fromItemId = GetBagItemIdPocket(pocket, from),
|
||||
fromQuantity = GetBagItemQuantityPocket(pocket, from);
|
||||
struct ItemSlot fromSlot = BagPocket_GetSlotData(pocket, from);
|
||||
|
||||
// Shuffle items between "to" and "from"
|
||||
if (to > from)
|
||||
{
|
||||
to--;
|
||||
shift = 1;
|
||||
}
|
||||
|
||||
for (i = from; i == to - shift; i += shift)
|
||||
{
|
||||
SetBagItemIdPocket(pocket, i, GetBagItemIdPocket(pocket, i + shift));
|
||||
SetBagItemQuantityPocket(pocket, i, GetBagItemQuantityPocket(pocket, i + shift));
|
||||
}
|
||||
for (u32 i = from; i != to; i += shift)
|
||||
BagPocket_SetSlotData(pocket, i, BagPocket_GetSlotData(pocket, i + shift));
|
||||
|
||||
// Move the saved "from" to "to"
|
||||
SetBagItemIdPocket(pocket, to, fromItemId);
|
||||
SetBagItemQuantityPocket(pocket, to, fromQuantity);
|
||||
BagPocket_SetSlotData(pocket, to, fromSlot);
|
||||
}
|
||||
}
|
||||
|
||||
void MoveItemSlotInPC(struct ItemSlot *itemSlots_, u32 from, u32 to_)
|
||||
void MoveItemSlotInPocket(enum Pocket pocketId, u32 from, u32 to)
|
||||
{
|
||||
// dumb assignments needed to match
|
||||
struct ItemSlot *itemSlots = itemSlots_;
|
||||
u32 to = to_;
|
||||
BagPocket_MoveItemSlot(&gBagPockets[pocketId], from, to);
|
||||
}
|
||||
|
||||
if (from != to)
|
||||
{
|
||||
s16 i, count;
|
||||
struct ItemSlot firstSlot = itemSlots[from];
|
||||
|
||||
if (to > from)
|
||||
{
|
||||
to--;
|
||||
for (i = from, count = to; i < count; i++)
|
||||
itemSlots[i] = itemSlots[i + 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = from, count = to; i > count; i--)
|
||||
itemSlots[i] = itemSlots[i - 1];
|
||||
}
|
||||
itemSlots[to] = firstSlot;
|
||||
}
|
||||
void MoveItemSlotInPC(struct ItemSlot *itemSlots, u32 from, u32 to)
|
||||
{
|
||||
struct BagPocket dummyPocket = DUMMY_PC_BAG_POCKET;
|
||||
return BagPocket_MoveItemSlot(&dummyPocket, from, to);
|
||||
}
|
||||
|
||||
void ClearBag(void)
|
||||
|
|
@ -530,109 +566,88 @@ s8 PCItemsGetFirstEmptySlot(void)
|
|||
return -1;
|
||||
}
|
||||
|
||||
static u8 NONNULL BagPocket_CountUsedItemSlots(struct BagPocket *pocket)
|
||||
{
|
||||
u8 usedSlots = 0;
|
||||
|
||||
for (u32 i = 0; i < pocket->capacity; i++)
|
||||
{
|
||||
if (BagPocket_GetSlotData(pocket, i).itemId != ITEM_NONE)
|
||||
usedSlots++;
|
||||
}
|
||||
return usedSlots;
|
||||
}
|
||||
|
||||
u8 CountItemsInPC(void)
|
||||
{
|
||||
u8 count = 0;
|
||||
u8 i;
|
||||
struct BagPocket dummyPocket = DUMMY_PC_BAG_POCKET;
|
||||
return BagPocket_CountUsedItemSlots(&dummyPocket);
|
||||
}
|
||||
|
||||
for (i = 0; i < PC_ITEMS_COUNT; i++)
|
||||
static bool32 NONNULL BagPocket_CheckPocketForItemCount(struct BagPocket *pocket, u16 itemId, u16 count)
|
||||
{
|
||||
struct ItemSlot tempItem;
|
||||
|
||||
for (u32 i = 0; i < pocket->capacity; i++)
|
||||
{
|
||||
if (gSaveBlock1Ptr->pcItems[i].itemId != ITEM_NONE)
|
||||
count++;
|
||||
tempItem = BagPocket_GetSlotData(pocket, i);
|
||||
if (tempItem.itemId == itemId && tempItem.quantity >= count)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return count;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool8 CheckPCHasItem(u16 itemId, u16 count)
|
||||
{
|
||||
u8 i;
|
||||
u16 quantity;
|
||||
|
||||
for (i = 0; i < PC_ITEMS_COUNT; i++)
|
||||
{
|
||||
if (gSaveBlock1Ptr->pcItems[i].itemId == itemId)
|
||||
{
|
||||
quantity = GetPCItemQuantity(&gSaveBlock1Ptr->pcItems[i].quantity);
|
||||
if (quantity >= count)
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
struct BagPocket dummyPocket = DUMMY_PC_BAG_POCKET;
|
||||
return BagPocket_CheckPocketForItemCount(&dummyPocket, itemId, count);
|
||||
}
|
||||
|
||||
bool8 AddPCItem(u16 itemId, u16 count)
|
||||
{
|
||||
u8 i;
|
||||
u16 quantity;
|
||||
s8 idx;
|
||||
|
||||
for (i = 0; i < PC_ITEMS_COUNT; i++)
|
||||
{
|
||||
if (gSaveBlock1Ptr->pcItems[i].itemId == itemId)
|
||||
{
|
||||
quantity = GetPCItemQuantity(&gSaveBlock1Ptr->pcItems[i].quantity);
|
||||
if (quantity + count <= MAX_PC_ITEM_CAPACITY)
|
||||
{
|
||||
quantity += count;
|
||||
SetPCItemQuantity(&gSaveBlock1Ptr->pcItems[i].quantity, quantity);
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
idx = PCItemsGetFirstEmptySlot();
|
||||
if (idx == -1)
|
||||
return FALSE;
|
||||
|
||||
gSaveBlock1Ptr->pcItems[idx].itemId = itemId;
|
||||
SetPCItemQuantity(&gSaveBlock1Ptr->pcItems[idx].quantity, count);
|
||||
return TRUE;
|
||||
struct BagPocket dummyPocket = DUMMY_PC_BAG_POCKET;
|
||||
return BagPocket_AddItem(&dummyPocket, itemId, count);
|
||||
}
|
||||
|
||||
void RemovePCItem(u16 itemId, u16 count)
|
||||
static void NONNULL BagPocket_CompactItems(struct BagPocket *pocket)
|
||||
{
|
||||
u32 i;
|
||||
u16 quantity;
|
||||
|
||||
if (itemId == ITEM_NONE)
|
||||
return;
|
||||
|
||||
for (i = 0; i < PC_ITEMS_COUNT; i++)
|
||||
struct ItemSlot tempItem;
|
||||
u32 slotCursor = 0;
|
||||
for (u32 i = 0; i < pocket->capacity; i++)
|
||||
{
|
||||
if (gSaveBlock1Ptr->pcItems[i].itemId == itemId)
|
||||
break;
|
||||
tempItem = BagPocket_GetSlotData(pocket, i);
|
||||
if (tempItem.itemId == ITEM_NONE)
|
||||
{
|
||||
if (!slotCursor)
|
||||
slotCursor = i + 1;
|
||||
}
|
||||
else if (slotCursor > 0)
|
||||
{
|
||||
BagPocket_SetSlotData(pocket, slotCursor++ - 1, tempItem);
|
||||
BagPocket_SetSlotItemIdAndCount(pocket, i, ITEM_NONE, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (i != PC_ITEMS_COUNT)
|
||||
{
|
||||
quantity = GetPCItemQuantity(&gSaveBlock1Ptr->pcItems[i].quantity) - count;
|
||||
SetPCItemQuantity(&gSaveBlock1Ptr->pcItems[i].quantity, quantity);
|
||||
if (quantity == 0)
|
||||
gSaveBlock1Ptr->pcItems[i].itemId = ITEM_NONE;
|
||||
}
|
||||
void RemovePCItem(u8 index, u16 count)
|
||||
{
|
||||
struct BagPocket dummyPocket = DUMMY_PC_BAG_POCKET;
|
||||
|
||||
// Get id, quantity at slot
|
||||
struct ItemSlot tempItem = BagPocket_GetSlotData(&dummyPocket, index);
|
||||
|
||||
// Remove quantity
|
||||
BagPocket_SetSlotItemIdAndCount(&dummyPocket, index, tempItem.itemId, tempItem.quantity - count);
|
||||
|
||||
// Compact if necessary
|
||||
if (tempItem.quantity == 0)
|
||||
BagPocket_CompactItems(&dummyPocket);
|
||||
}
|
||||
|
||||
void ItemPcCompaction(void)
|
||||
{
|
||||
u16 i, j;
|
||||
struct ItemSlot tmp;
|
||||
|
||||
for (i = 0; i < PC_ITEMS_COUNT - 1; i++)
|
||||
{
|
||||
for (j = i + 1; j < PC_ITEMS_COUNT; j++)
|
||||
{
|
||||
if (gSaveBlock1Ptr->pcItems[i].itemId == ITEM_NONE)
|
||||
{
|
||||
tmp = gSaveBlock1Ptr->pcItems[i];
|
||||
gSaveBlock1Ptr->pcItems[i] = gSaveBlock1Ptr->pcItems[j];
|
||||
gSaveBlock1Ptr->pcItems[j] = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
struct BagPocket dummyPocket = DUMMY_PC_BAG_POCKET;
|
||||
BagPocket_CompactItems(&dummyPocket);
|
||||
}
|
||||
|
||||
void RegisteredItemHandleBikeSwap(void)
|
||||
|
|
@ -648,29 +663,6 @@ void RegisteredItemHandleBikeSwap(void)
|
|||
}
|
||||
}
|
||||
|
||||
static void SwapItemSlots(enum Pocket pocketId, u32 pocketPosA, u16 pocketPosB)
|
||||
{
|
||||
struct ItemSlot *itemA = &gBagPockets[pocketId].itemSlots[pocketPosA],
|
||||
*itemB = &gBagPockets[pocketId].itemSlots[pocketPosB],
|
||||
temp;
|
||||
SWAP(*itemA, *itemB, temp);
|
||||
}
|
||||
|
||||
void CompactItemsInBagPocket(enum Pocket pocketId)
|
||||
{
|
||||
struct BagPocket *bagPocket = &gBagPockets[pocketId];
|
||||
u16 i, j;
|
||||
|
||||
for (i = 0; i < bagPocket->capacity - 1; i++)
|
||||
{
|
||||
for (j = i + 1; j < bagPocket->capacity; j++)
|
||||
{
|
||||
if (bagPocket->itemSlots[i].quantity == 0)
|
||||
SwapItemSlots(pocketId, i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
u16 CountTotalItemQuantityInBag(u16 itemId)
|
||||
{
|
||||
u16 i;
|
||||
|
|
|
|||
|
|
@ -728,7 +728,7 @@ void GoToBagMenu(u8 location, u8 pocket, MainCallback exitCallback)
|
|||
memset(gBagMenu->spriteIds, SPRITE_NONE, sizeof(gBagMenu->spriteIds));
|
||||
memset(gBagMenu->windowIds, WINDOW_NONE, sizeof(gBagMenu->windowIds));
|
||||
SetMainCallback2(CB2_Bag);
|
||||
|
||||
|
||||
gTextFlags.autoScroll = FALSE;
|
||||
gSpecialVar_ItemId = ITEM_NONE;
|
||||
}
|
||||
|
|
@ -1011,7 +1011,7 @@ static void BagListMenuGetItemNameColored(u8 *dest, u16 itemId)
|
|||
StringCopy(dest, sListItemTextColor_TmCase_BerryPouch);
|
||||
else
|
||||
StringCopy(dest, sListItemTextColor_RegularItem);
|
||||
|
||||
|
||||
end = StringAppend(dest, GetItemName(itemId));
|
||||
PrependFontIdToFit(dest, end, FONT_NARROW, 61);
|
||||
}
|
||||
|
|
@ -1072,7 +1072,7 @@ static void BagMenu_ItemPrintCallback(u8 windowId, u32 itemIndex, u8 y)
|
|||
static void PrintItemDescription(s32 itemIndex)
|
||||
{
|
||||
const u8 *str;
|
||||
|
||||
|
||||
if (itemIndex != LIST_CANCEL)
|
||||
str = GetItemDescription(GetBagItemId(gBagPosition.pocket, itemIndex));
|
||||
else
|
||||
|
|
@ -1503,7 +1503,7 @@ static void StartItemSwap(u8 taskId)
|
|||
static void Task_HandleSwappingItemsInput(u8 taskId)
|
||||
{
|
||||
s16 *data = gTasks[taskId].data;
|
||||
|
||||
|
||||
|
||||
if (IsActiveOverworldLinkBusy() == TRUE)
|
||||
return;
|
||||
|
|
@ -1810,6 +1810,29 @@ static void Task_ChooseHowManyToToss(u8 taskId)
|
|||
}
|
||||
}
|
||||
|
||||
static void Task_TossItemFromBag(u8 taskId)
|
||||
{
|
||||
s16 *data = gTasks[taskId].data;
|
||||
u16 *scrollPos = &gBagPosition.scrollPosition[gBagPosition.pocket];
|
||||
u16 *cursorPos = &gBagPosition.cursorPosition[gBagPosition.pocket];
|
||||
|
||||
if (JOY_NEW(A_BUTTON) || JOY_NEW(B_BUTTON))
|
||||
{
|
||||
PlaySE(SE_SELECT);
|
||||
RemoveBagItemFromSlot(&gBagPockets[gBagPosition.pocket], *scrollPos + *cursorPos, tItemCount);
|
||||
BagMenu_RemoveWindow(ITEMWIN_TOSSED);
|
||||
DestroyListMenuTask(tListTaskId, scrollPos, cursorPos);
|
||||
UpdatePocketItemList(gBagPosition.pocket);
|
||||
UpdatePocketListPosition(gBagPosition.pocket);
|
||||
LoadBagItemListBuffers(gBagPosition.pocket);
|
||||
tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos);
|
||||
PutWindowTilemap(WIN_DESCRIPTION);
|
||||
ScheduleBgCopyTilemapToVram(0);
|
||||
BagMenu_PrintCursor(tListTaskId, COLORID_BLACK_CURSOR);
|
||||
ReturnToItemList(taskId);
|
||||
}
|
||||
}
|
||||
|
||||
static void ConfirmToss(u8 taskId)
|
||||
{
|
||||
s16 *data = gTasks[taskId].data;
|
||||
|
|
@ -1819,7 +1842,7 @@ static void ConfirmToss(u8 taskId)
|
|||
ConvertIntToDecimalStringN(gStringVar2, tItemCount, STR_CONV_MODE_LEFT_ALIGN, MAX_ITEM_DIGITS);
|
||||
StringExpandPlaceholders(gStringVar4, gText_ThrewAwayStrVar2StrVar1s);
|
||||
BagMenu_Print(BagMenu_AddWindow(ITEMWIN_TOSSED), FONT_NORMAL, gStringVar4, 0, 2, 1, 0, 0, COLORID_BLACK_CURSOR);
|
||||
gTasks[taskId].func = Task_RemoveItemFromBag;
|
||||
gTasks[taskId].func = Task_TossItemFromBag;
|
||||
}
|
||||
|
||||
static void Task_RemoveItemFromBag(u8 taskId)
|
||||
|
|
@ -1937,7 +1960,7 @@ static void ItemMenu_UseInBattle(u8 taskId)
|
|||
BagMenu_RemoveWindow(ITEMWIN_SELECTIONTEXT);
|
||||
PutWindowTilemap(WIN_ITEM_LIST);
|
||||
PutWindowTilemap(WIN_DESCRIPTION);
|
||||
CopyWindowToVram(WIN_ITEM_LIST, COPYWIN_MAP);
|
||||
CopyWindowToVram(WIN_ITEM_LIST, COPYWIN_MAP);
|
||||
|
||||
if (type == ITEM_USE_BAG_MENU) {
|
||||
ItemUseInBattle_BagMenu(taskId);
|
||||
|
|
@ -2065,7 +2088,7 @@ static void Task_ItemContext_Sell(u8 taskId)
|
|||
|
||||
if (tQuantity > MAX_BAG_ITEM_CAPACITY)
|
||||
tQuantity = MAX_BAG_ITEM_CAPACITY;
|
||||
|
||||
|
||||
if (tQuantity > maxQuantity)
|
||||
tQuantity = maxQuantity;
|
||||
|
||||
|
|
@ -2107,7 +2130,7 @@ static void InitSellHowManyInput(u8 taskId)
|
|||
{
|
||||
s16 *data = gTasks[taskId].data;
|
||||
u8 windowId = BagMenu_AddWindow(ITEMWIN_QUANTITY_WIDE);
|
||||
|
||||
|
||||
PrintItemSoldAmount(windowId, 1, GetItemSellPrice(gSpecialVar_ItemId) * tItemCount);
|
||||
DisplayCurrentMoneyWindow();
|
||||
CreatePocketScrollArrowPair_SellQuantity();
|
||||
|
|
@ -2269,10 +2292,10 @@ static void TryDepositItem(u8 taskId)
|
|||
static bool32 IsTutorialBag(void)
|
||||
{
|
||||
if (
|
||||
gBagPosition.location == ITEMMENULOCATION_OLD_MAN
|
||||
|| gBagPosition.location == ITEMMENULOCATION_TTVSCR_CATCHING
|
||||
|| gBagPosition.location == ITEMMENULOCATION_TTVSCR_STATUS
|
||||
|| gBagPosition.location == ITEMMENULOCATION_TTVSCR_REGISTER
|
||||
gBagPosition.location == ITEMMENULOCATION_OLD_MAN
|
||||
|| gBagPosition.location == ITEMMENULOCATION_TTVSCR_CATCHING
|
||||
|| gBagPosition.location == ITEMMENULOCATION_TTVSCR_STATUS
|
||||
|| gBagPosition.location == ITEMMENULOCATION_TTVSCR_REGISTER
|
||||
|| gBagPosition.location == ITEMMENULOCATION_TTVSCR_TMS
|
||||
)
|
||||
return TRUE;
|
||||
|
|
@ -2680,7 +2703,7 @@ static u8 BagMenu_AddWindow(u8 windowType)
|
|||
void BagMenu_RemoveWindow(u8 whichWindow)
|
||||
{
|
||||
u8 *windowId = &gBagMenu->windowIds[whichWindow];
|
||||
|
||||
|
||||
if (*windowId != WINDOW_NONE)
|
||||
{
|
||||
ClearStdWindowAndFrameToTransparent(gBagMenu->windowIds[whichWindow], FALSE);
|
||||
|
|
@ -2775,7 +2798,6 @@ static const u8 sBagMenuSortPokeBalls[] =
|
|||
{
|
||||
ACTION_BY_NAME,
|
||||
ACTION_BY_AMOUNT,
|
||||
ACTION_DUMMY,
|
||||
ACTION_CANCEL,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -956,13 +956,11 @@ static void ItemPc_DoWithdraw(u8 taskId)
|
|||
static void Task_ItemPcWaitButtonAndFinishWithdrawMultiple(u8 taskId)
|
||||
{
|
||||
s16 * data = gTasks[taskId].data;
|
||||
u16 itemId;
|
||||
|
||||
if (JOY_NEW(A_BUTTON) || JOY_NEW(B_BUTTON))
|
||||
{
|
||||
PlaySE(SE_SELECT);
|
||||
itemId = ItemPc_GetItemIdBySlotId(tListPosition);
|
||||
RemovePCItem(itemId, tItemCount);
|
||||
RemovePCItem(sListMenuState.scroll + sListMenuState.row, tItemCount);
|
||||
ItemPcCompaction();
|
||||
Task_ItemPcCleanUpWithdraw(taskId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -365,7 +365,6 @@ static void UseSacredAsh(u8 taskId);
|
|||
static void CB2_ReturnToBerryPouchMenu(void);
|
||||
static void CB2_ReturnToTMCaseMenu(void);
|
||||
static void GiveItemOrMailToSelectedMon(u8 taskId);
|
||||
static void RemoveItemToGiveFromBag(u16 item);
|
||||
static void DisplayItemMustBeRemovedFirstMessage(u8 taskId);
|
||||
static void CB2_WriteMailToGiveMonFromBag(void);
|
||||
static void GiveItemToSelectedMon(u8 taskId);
|
||||
|
|
@ -6276,7 +6275,7 @@ static void GiveItemOrMailToSelectedMon(u8 taskId)
|
|||
{
|
||||
if (ItemIsMail(gPartyMenu.bagItem))
|
||||
{
|
||||
RemoveItemToGiveFromBag(gPartyMenu.bagItem);
|
||||
RemoveBagItem(gPartyMenu.bagItem, 1);
|
||||
sPartyMenuInternal->exitCallback = CB2_WriteMailToGiveMonFromBag;
|
||||
Task_ClosePartyMenu(taskId);
|
||||
}
|
||||
|
|
@ -6295,7 +6294,7 @@ static void GiveItemToSelectedMon(u8 taskId)
|
|||
item = gPartyMenu.bagItem;
|
||||
DisplayGaveHeldItemMessage(&gPlayerParty[gPartyMenu.slotId], item, FALSE, TRUE);
|
||||
GiveItemToMon(&gPlayerParty[gPartyMenu.slotId], item);
|
||||
RemoveItemToGiveFromBag(item);
|
||||
RemoveBagItem(item, 1);
|
||||
gTasks[taskId].func = Task_UpdateHeldItemSpriteAndClosePartyMenu;
|
||||
}
|
||||
}
|
||||
|
|
@ -6370,7 +6369,7 @@ static void Task_HandleSwitchItemsFromBagYesNoInput(u8 taskId)
|
|||
{
|
||||
case 0: // Yes, switch items
|
||||
item = gPartyMenu.bagItem;
|
||||
RemoveItemToGiveFromBag(item);
|
||||
RemoveBagItem(item, 1);
|
||||
if (AddBagItem(sPartyMenuItemId, 1) == FALSE)
|
||||
{
|
||||
ReturnGiveItemToBagOrPC(item);
|
||||
|
|
@ -6406,14 +6405,6 @@ static void DisplayItemMustBeRemovedFirstMessage(u8 taskId)
|
|||
gTasks[taskId].func = Task_UpdateHeldItemSpriteAndClosePartyMenu;
|
||||
}
|
||||
|
||||
static void RemoveItemToGiveFromBag(u16 item)
|
||||
{
|
||||
if (gPartyMenu.action == PARTY_ACTION_GIVE_PC_ITEM)
|
||||
RemovePCItem(item, 1);
|
||||
else
|
||||
RemoveBagItem(item, 1);
|
||||
}
|
||||
|
||||
// Returns FALSE if there was no space to return the item
|
||||
// but there always should be, and the return is ignored in all uses
|
||||
static bool8 ReturnGiveItemToBagOrPC(u16 item)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user