mirror of
https://github.com/pret/pokefirered.git
synced 2026-05-12 23:31:53 -05:00
fix tmhm sorting
This commit is contained in:
parent
703ce7b2f2
commit
b3fdc97970
|
|
@ -70,7 +70,6 @@ void ClearPCItemSlots(void);
|
|||
void TrySetObtainedItemQuestLogEvent(u16 itemId);
|
||||
bool8 AddBagItem(u16 itemId, u16 amount);
|
||||
|
||||
void SortPocketAndPlaceHMsFirst(struct BagPocket * pocket);
|
||||
u16 BagGetItemIdByPocketPosition(u8 pocketId, u16 itemId);
|
||||
u16 BagGetQuantityByPocketPosition(u8 pocketId, u16 itemId);
|
||||
u16 BagGetQuantityByItemId(u16 item);
|
||||
|
|
@ -82,6 +81,7 @@ void SetBagPocketsPointers(void);
|
|||
void ItemPcCompaction(void);
|
||||
void RemovePCItem(u16 itemId, u16 quantity);
|
||||
void CompactItemsInBagPocket(struct BagPocket * pocket);
|
||||
void SortBerriesOrTMHMs(struct BagPocket *bagPocket);
|
||||
u8 CountItemsInPC(void);
|
||||
bool8 HasAtLeastOneBerry(void);
|
||||
bool8 HasAtLeastOnePokeBall(void);
|
||||
|
|
|
|||
63
src/item.c
63
src/item.c
|
|
@ -508,41 +508,6 @@ void BagPocketCompaction(struct ItemSlot * slots, u8 capacity)
|
|||
}
|
||||
}
|
||||
|
||||
void SortPocketAndPlaceHMsFirst(struct BagPocket * pocket)
|
||||
{
|
||||
u16 i;
|
||||
u16 j = 0;
|
||||
u16 k;
|
||||
struct ItemSlot * buff;
|
||||
|
||||
CompactItemsInBagPocket(pocket);
|
||||
|
||||
for (i = 0; i < pocket->capacity; i++)
|
||||
{
|
||||
if (pocket->itemSlots[i].itemId == ITEM_NONE && GetBagItemQuantity(&pocket->itemSlots[i].quantity) == 0)
|
||||
return;
|
||||
if (pocket->itemSlots[i].itemId >= ITEM_HM01 && GetBagItemQuantity(&pocket->itemSlots[i].quantity) != 0)
|
||||
{
|
||||
for (j = i + 1; j < pocket->capacity; j++)
|
||||
{
|
||||
if (pocket->itemSlots[j].itemId == ITEM_NONE && GetBagItemQuantity(&pocket->itemSlots[j].quantity) == 0)
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (k = 0; k < pocket->capacity; k++)
|
||||
pocket->itemSlots[k].quantity = GetBagItemQuantity(&pocket->itemSlots[k].quantity);
|
||||
buff = AllocZeroed(pocket->capacity * sizeof(struct ItemSlot));
|
||||
CpuCopy16(pocket->itemSlots + i, buff, (j - i) * sizeof(struct ItemSlot));
|
||||
CpuCopy16(pocket->itemSlots, buff + (j - i), i * sizeof(struct ItemSlot));
|
||||
CpuCopy16(buff, pocket->itemSlots, pocket->capacity * sizeof(struct ItemSlot));
|
||||
for (k = 0; k < pocket->capacity; k++)
|
||||
SetBagItemQuantity(&pocket->itemSlots[k].quantity, pocket->itemSlots[k].quantity);
|
||||
Free(buff);
|
||||
}
|
||||
|
||||
void CompactItemsInBagPocket(struct BagPocket *bagPocket)
|
||||
{
|
||||
u16 i, j;
|
||||
|
|
@ -557,6 +522,34 @@ void CompactItemsInBagPocket(struct BagPocket *bagPocket)
|
|||
}
|
||||
}
|
||||
|
||||
static u32 GetSortIndex(u32 itemId)
|
||||
{
|
||||
if (!IsItemHM(itemId))
|
||||
return itemId;
|
||||
|
||||
return (itemId - (NUM_TECHNICAL_MACHINES + NUM_HIDDEN_MACHINES));
|
||||
}
|
||||
|
||||
void SortBerriesOrTMHMs(struct BagPocket *bagPocket)
|
||||
{
|
||||
u16 i, j;
|
||||
|
||||
for (i = 0; i < bagPocket->capacity - 1; i++)
|
||||
{
|
||||
for (j = i + 1; j < bagPocket->capacity; j++)
|
||||
{
|
||||
if (GetBagItemQuantity(&bagPocket->itemSlots[i].quantity) != 0)
|
||||
{
|
||||
if (GetBagItemQuantity(&bagPocket->itemSlots[j].quantity) == 0)
|
||||
continue;
|
||||
if (GetSortIndex(bagPocket->itemSlots[i].itemId) <= GetSortIndex(bagPocket->itemSlots[j].itemId))
|
||||
continue;
|
||||
}
|
||||
SwapItemSlots(&bagPocket->itemSlots[i], &bagPocket->itemSlots[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
u16 BagGetItemIdByPocketPosition(u8 pocketId, u16 slotId)
|
||||
{
|
||||
return gBagPockets[pocketId - 1].itemSlots[slotId].itemId;
|
||||
|
|
|
|||
|
|
@ -507,7 +507,7 @@ static bool8 DoSetUpTMCaseUI(void)
|
|||
gMain.state++;
|
||||
break;
|
||||
case 9:
|
||||
SortPocketAndPlaceHMsFirst(&gBagPockets[POCKET_TM_HM - 1]);
|
||||
SortBerriesOrTMHMs(&gBagPockets[POCKET_TM_HM - 1]);
|
||||
gMain.state++;
|
||||
break;
|
||||
case 10:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user