From cae4461c3966e327b43ec42eff08e5650ee6bb08 Mon Sep 17 00:00:00 2001 From: Juliano Leal Goncalves Date: Sat, 20 Mar 2021 20:43:21 -0300 Subject: [PATCH] :recycle: Reuse existing functions in place of 'SpecialAutoPlace' --- Source/inv.cpp | 2 +- Source/inv.h | 1 + Source/stores.cpp | 12 ++++++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Source/inv.cpp b/Source/inv.cpp index ca4965110..872543304 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -634,7 +634,7 @@ bool CanBePlacedOnBelt(const ItemStruct &item) * @param persistItem Pass 'True' to actually place the item in the belt. The default is 'False'. * @return 'True' in case the item can be placed on the player's belt and 'False' otherwise. */ -bool AutoPlaceItemInBelt(int playerNumber, const ItemStruct &item, bool persistItem = false) +bool AutoPlaceItemInBelt(int playerNumber, const ItemStruct &item, bool persistItem) { if (!CanBePlacedOnBelt(item)) { return false; diff --git a/Source/inv.h b/Source/inv.h index c8e344991..f2e0b5734 100644 --- a/Source/inv.h +++ b/Source/inv.h @@ -43,6 +43,7 @@ void DrawInvBelt(CelOutputBuffer out); bool AutoEquipEnabled(const PlayerStruct &player, const ItemStruct &item); bool AutoEquip(int playerNumber, const ItemStruct &item, bool persistItem = true); bool AutoPlaceItemInInventorySlot(int playerNumber, int slotIndex, const ItemStruct &item, bool persistItem); +bool AutoPlaceItemInBelt(int playerNumber, const ItemStruct &item, bool persistItem = false); BOOL SpecialAutoPlace(int pnum, int ii, const ItemStruct &item); BOOL GoldAutoPlace(int pnum); void CheckInvSwap(int pnum, BYTE bLoc, int idx, WORD wCI, int seed, BOOL bId, uint32_t dwBuff); diff --git a/Source/stores.cpp b/Source/stores.cpp index 062763196..9f587c5b4 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -1705,7 +1705,11 @@ void S_WBuyEnter() } for (i = 0; i < NUM_INV_GRID_ELEM && !done; i++) { - done = SpecialAutoPlace(myplr, i, plr[myplr].HoldItem); + done = AutoPlaceItemInInventorySlot(myplr, i, plr[myplr].HoldItem, false); + } + + if (!done) { + done = AutoPlaceItemInBelt(myplr, plr[myplr].HoldItem, false); } if (done) @@ -2016,7 +2020,11 @@ void S_HBuyEnter() } for (i = 0; i < NUM_INV_GRID_ELEM && !done; i++) { - done = SpecialAutoPlace(myplr, i, plr[myplr].HoldItem); + done = AutoPlaceItemInInventorySlot(myplr, i, plr[myplr].HoldItem, false); + } + + if (!done) { + done = AutoPlaceItemInBelt(myplr, plr[myplr].HoldItem, false); } if (done)