diff --git a/include/item.h b/include/item.h index cf84848ae4..3b6e7497ba 100644 --- a/include/item.h +++ b/include/item.h @@ -58,7 +58,7 @@ u16 BagGetItemIdByPocketPosition(u8 pocketId, u16 pocketPos); u16 BagGetQuantityByPocketPosition(u8 pocketId, u16 pocketPos); void CompactItemsInBagPocket(struct BagPocket *bagPocket); void SortBerriesOrTMHMs(struct BagPocket *bagPocket); -void MoveItemSlotInList(struct ItemSlot *itemSlots_, u32 from, u32 to_); +void MoveItemSlotInList(struct ItemSlot *itemSlots, u32 from, u32 to); void ClearBag(void); u16 CountTotalItemQuantityInBag(u16 itemId); bool8 AddPyramidBagItem(u16 itemId, u16 count); diff --git a/src/item.c b/src/item.c index a22eaaec91..a3095c32d7 100644 --- a/src/item.c +++ b/src/item.c @@ -632,30 +632,29 @@ void SortBerriesOrTMHMs(struct BagPocket *bagPocket) } } -void MoveItemSlotInList(struct ItemSlot *itemSlots_, u32 from, u32 to_) +void MoveItemSlotInList(struct ItemSlot *itemSlots, u32 from, u32 to) { - // dumb assignments needed to match - struct ItemSlot *itemSlots = itemSlots_; - u32 to = to_; + struct ItemSlot firstSlot; + s16 i; - if (from != to) + if (from == to) + return; + + firstSlot = itemSlots[from]; + + if (to > from) { - 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; + to--; + for (i = (s16)from; i < (s16)to; i++) + itemSlots[i] = itemSlots[i + 1]; } + else + { + for (i = (s16)from; i > (s16)to; i--) + itemSlots[i] = itemSlots[i - 1]; + } + + itemSlots[to] = firstSlot; } void ClearBag(void)